1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
/*
* Copyright (c) 1999 Olaf Flebbe o.flebbe@gmx.de
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/unistd.h>
void
Perl_epoc_init(int *argcp, char ***argvp) {
int i;
int truecount=0;
char **lastcp = (*argvp);
char *ptr;
#if 0
epoc_spawn_posix_server();
#endif
for (i=0; i< *argcp; i++) {
if ((*argvp)[i]) {
if (*((*argvp)[i]) == '<') {
if (strlen((*argvp)[i]) > 1) {
ptr =((*argvp)[i])+1;
} else {
i++;
ptr = ((*argvp)[i]);
}
freopen( ptr, "r", stdin);
} else if (*((*argvp)[i]) == '>') {
if (strlen((*argvp)[i]) > 1) {
ptr =((*argvp)[i])+1;
} else {
i++;
ptr = ((*argvp)[i]);
}
freopen( ptr, "w", stdout);
} else if ((*((*argvp)[i]) == '2') && (*(((*argvp)[i])+1) == '>')) {
if (strcmp( (*argvp)[i], "2>&1") == 0) {
dup2( fileno( stdout), fileno( stderr));
} else {
if (strlen((*argvp)[i]) > 2) {
ptr =((*argvp)[i])+2;
} else {
i++;
ptr = ((*argvp)[i]);
}
freopen( ptr, "w", stderr);
}
} else {
*lastcp++ = (*argvp)[i];
truecount++;
}
}
}
*argcp=truecount;
}
#ifdef __MARM__
/* Symbian forgot to include __fixunsdfi into the MARM euser.lib */
/* This is from libgcc2.c , gcc-2.7.2.3 */
typedef unsigned int UQItype __attribute__ ((mode (QI)));
typedef int SItype __attribute__ ((mode (SI)));
typedef unsigned int USItype __attribute__ ((mode (SI)));
typedef int DItype __attribute__ ((mode (DI)));
typedef unsigned int UDItype __attribute__ ((mode (DI)));
typedef float SFtype __attribute__ ((mode (SF)));
typedef float DFtype __attribute__ ((mode (DF)));
extern DItype __fixunssfdi (SFtype a);
extern DItype __fixunsdfdi (DFtype a);
USItype
__fixunsdfsi (a)
DFtype a;
{
if (a >= - (DFtype) (- 2147483647L -1) )
return (SItype) (a + (- 2147483647L -1) ) - (- 2147483647L -1) ;
return (SItype) a;
}
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
int
do_spawn( char *cmd) {
dTHX;
char *argv0, *ptr;
char *cmdptr = cmd;
int ret;
argv0 = ptr = malloc( strlen(cmd) + 1);
while (*cmdptr && !isSPACE( *cmdptr)) {
*ptr = *cmdptr;
if (*ptr == '/') {
*ptr = '\\';
}
ptr++; cmdptr++;
}
while (*cmdptr && isSPACE( *cmdptr)) {
cmdptr++;
}
*ptr = '\0';
ret = epoc_spawn( argv0, cmdptr);
free( argv0);
return ret;
}
int
do_aspawn ( void *vreally, void **vmark, void **vsp) {
dTHX;
SV *really = (SV*)vreally;
SV **mark = (SV**)vmark;
SV **sp = (SV**)vsp;
char **argv;
char *str;
char *p2, **ptr;
char *cmd, *cmdline;
int rc;
int index = 0;
int len = 0;
if (sp<=mark)
return -1;
ptr = argv =(char**) malloc ((sp-mark+3)*sizeof (char*));
while (++mark <= sp) {
if (*mark && (str = SvPV_nolen(*mark)))
argv[index] = str;
else
argv[index] = "";
len += strlen(argv[ index++]) + 1;
}
argv[index++] = 0;
cmd = strdup((const char*)(really ? SvPV_nolen(really) : argv[0]));
for (p2=cmd; *p2 != '\0'; p2++) {
/* Change / to \ */
if ( *p2 == '/')
*p2 = '\\';
}
cmdline = (char * ) malloc( len + 1);
cmdline[ 0] = '\0';
while (*argv != NULL) {
strcat( cmdline, *ptr++);
strcat( cmdline, " ");
}
free( argv);
rc = epoc_spawn( cmd, cmdline);
free( cmdline);
free( cmd);
return rc;
}
static
XS(epoc_getcwd) /* more or less stolen from win32.c */
{
dXSARGS;
/* Make the host for current directory */
char *buffer;
int buflen = 256;
char *ptr;
buffer = (char *) malloc( buflen);
if (buffer == NULL) {
XSRETURN_UNDEF;
}
while ((NULL == ( ptr = getcwd( buffer, buflen))) && (errno == ERANGE)) {
buflen *= 2;
if (NULL == realloc( buffer, buflen)) {
XSRETURN_UNDEF;
}
}
/*
* If ptr != Nullch
* then it worked, set PV valid,
* else return 'undef'
*/
if (ptr) {
SV *sv = sv_newmortal();
char *tptr;
for (tptr = ptr; *tptr != '\0'; tptr++) {
if (*tptr == '\\') {
*tptr = '/';
}
}
sv_setpv(sv, ptr);
free( buffer);
EXTEND(SP,1);
SvPOK_on(sv);
ST(0) = sv;
#ifndef INCOMPLETE_TAINTS
SvTAINTED_on(ST(0));
#endif
XSRETURN(1);
}
free( buffer);
XSRETURN_UNDEF;
}
void
Perl_init_os_extras(void)
{
dTHX;
char *file = __FILE__;
newXS("EPOC::getcwd", epoc_getcwd, file);
}
void
Perl_my_setenv(pTHX_ char *nam,char *val) {
setenv( nam, val, 1);
}
|