Commit | Line | Data |
---|---|---|
79072805 | 1 | /* $RCSfile: perl.h,v $$Revision: 4.1 $$Date: 92/08/07 18:25:56 $ |
a687059c | 2 | * |
352d5a3a | 3 | * Copyright (c) 1991, Larry Wall |
a687059c | 4 | * |
352d5a3a LW |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. | |
8d063cd8 LW |
7 | * |
8 | * $Log: perl.h,v $ | |
79072805 LW |
9 | * Revision 4.1 92/08/07 18:25:56 lwall |
10 | * | |
ee0007ab LW |
11 | * Revision 4.0.1.6 92/06/08 14:55:10 lwall |
12 | * patch20: added Atari ST portability | |
13 | * patch20: bcopy() and memcpy() now tested for overlap safety | |
14 | * patch20: Perl now distinguishes overlapped copies from non-overlapped | |
15 | * patch20: removed implicit int declarations on functions | |
16 | * | |
988174c1 LW |
17 | * Revision 4.0.1.5 91/11/11 16:41:07 lwall |
18 | * patch19: uts wrongly defines S_ISDIR() et al | |
19 | * patch19: too many preprocessors can't expand a macro right in #if | |
20 | * patch19: added little-endian pack/unpack options | |
21 | * | |
45d8adaa LW |
22 | * Revision 4.0.1.4 91/11/05 18:06:10 lwall |
23 | * patch11: various portability fixes | |
24 | * patch11: added support for dbz | |
25 | * patch11: added some support for 64-bit integers | |
26 | * patch11: hex() didn't understand leading 0x | |
27 | * | |
1462b684 LW |
28 | * Revision 4.0.1.3 91/06/10 01:25:10 lwall |
29 | * patch10: certain pattern optimizations were botched | |
30 | * | |
352d5a3a LW |
31 | * Revision 4.0.1.2 91/06/07 11:28:33 lwall |
32 | * patch4: new copyright notice | |
33 | * patch4: made some allowances for "semi-standard" C | |
34 | * patch4: many, many itty-bitty portability fixes | |
35 | * | |
35c8bce7 LW |
36 | * Revision 4.0.1.1 91/04/11 17:49:51 lwall |
37 | * patch1: hopefully straightened out some of the Xenix mess | |
38 | * | |
fe14fcc3 LW |
39 | * Revision 4.0 91/03/20 01:37:56 lwall |
40 | * 4.0 baseline. | |
8d063cd8 LW |
41 | * |
42 | */ | |
43 | ||
79072805 LW |
44 | #include "embed.h" |
45 | ||
35c8bce7 | 46 | #define VOIDWANT 1 |
79072805 LW |
47 | #ifdef __cplusplus |
48 | #include "config_c++.h" | |
49 | #else | |
ac58e20f | 50 | #include "config.h" |
79072805 LW |
51 | #endif |
52 | ||
53 | #ifndef BYTEORDER | |
54 | # define BYTEORDER 0x1234 | |
55 | #endif | |
56 | ||
57 | /* Overall memory policy? */ | |
58 | #ifndef CONSERVATIVE | |
59 | # define LIBERAL 1 | |
60 | #endif | |
61 | ||
62 | /* | |
63 | * The following contortions are brought to you on behalf of all the | |
64 | * standards, semi-standards, de facto standards, not-so-de-facto standards | |
65 | * of the world, as well as all the other botches anyone ever thought of. | |
66 | * The basic theory is that if we work hard enough here, the rest of the | |
67 | * code can be a lot prettier. Well, so much for theory. Sorry, Henry... | |
68 | */ | |
ac58e20f | 69 | |
45d8adaa LW |
70 | #ifdef MYMALLOC |
71 | # ifdef HIDEMYMALLOC | |
72 | # define malloc Mymalloc | |
73 | # define realloc Myremalloc | |
74 | # define free Myfree | |
75 | # endif | |
76 | # define safemalloc malloc | |
77 | # define saferealloc realloc | |
78 | # define safefree free | |
79 | #endif | |
80 | ||
81 | /* work around some libPW problems */ | |
45d8adaa LW |
82 | #ifdef DOINIT |
83 | char Error[1]; | |
84 | #endif | |
85 | ||
ee0007ab LW |
86 | /* define this once if either system, instead of cluttering up the src */ |
87 | #if defined(MSDOS) || defined(atarist) | |
88 | #define DOSISH 1 | |
89 | #endif | |
90 | ||
79072805 | 91 | #if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus) |
352d5a3a LW |
92 | # define STANDARD_C 1 |
93 | #endif | |
94 | ||
79072805 LW |
95 | #if defined(STANDARD_C) |
96 | # define P(args) args | |
97 | #else | |
98 | # define P(args) () | |
99 | #endif | |
100 | ||
352d5a3a | 101 | #if defined(HASVOLATILE) || defined(STANDARD_C) |
79072805 LW |
102 | # ifdef __cplusplus |
103 | # define VOL // to temporarily suppress warnings | |
104 | # else | |
105 | # define VOL volatile | |
106 | # endif | |
663a0e37 | 107 | #else |
79072805 | 108 | # define VOL |
663a0e37 LW |
109 | #endif |
110 | ||
463ee0b2 LW |
111 | #define TAINT_IF(c) (tainted |= (c)) |
112 | #define TAINT_NOT (tainted = 0) | |
113 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
114 | #define TAINT_ENV() if (tainting) taint_env() | |
a687059c | 115 | |
fe14fcc3 | 116 | #ifndef HAS_VFORK |
03a14243 LW |
117 | # define vfork fork |
118 | #endif | |
119 | ||
fe14fcc3 LW |
120 | #ifdef HAS_GETPGRP2 |
121 | # ifndef HAS_GETPGRP | |
122 | # define HAS_GETPGRP | |
663a0e37 LW |
123 | # endif |
124 | # define getpgrp getpgrp2 | |
125 | #endif | |
126 | ||
fe14fcc3 LW |
127 | #ifdef HAS_SETPGRP2 |
128 | # ifndef HAS_SETPGRP | |
129 | # define HAS_SETPGRP | |
663a0e37 LW |
130 | # endif |
131 | # define setpgrp setpgrp2 | |
132 | #endif | |
133 | ||
fe14fcc3 LW |
134 | #include <stdio.h> |
135 | #include <ctype.h> | |
136 | #include <setjmp.h> | |
79072805 | 137 | |
fe14fcc3 | 138 | #ifndef MSDOS |
79072805 LW |
139 | # ifdef PARAM_NEEDS_TYPES |
140 | # include <sys/types.h> | |
141 | # endif | |
142 | # include <sys/param.h> | |
352d5a3a | 143 | #endif |
79072805 LW |
144 | |
145 | ||
146 | /* Use all the "standard" definitions? */ | |
352d5a3a | 147 | #ifdef STANDARD_C |
79072805 LW |
148 | # include <stdlib.h> |
149 | # include <string.h> | |
150 | # define MEM_SIZE size_t | |
ee0007ab | 151 | #else |
79072805 | 152 | typedef unsigned int MEM_SIZE; |
352d5a3a | 153 | #endif /* STANDARD_C */ |
03a14243 | 154 | |
ee0007ab | 155 | #if defined(HAS_MEMCMP) && defined(mips) && defined(ultrix) |
79072805 | 156 | # undef HAS_MEMCMP |
663a0e37 | 157 | #endif |
fe14fcc3 LW |
158 | |
159 | #ifdef HAS_MEMCPY | |
352d5a3a | 160 | # ifndef STANDARD_C |
fe14fcc3 | 161 | # ifndef memcpy |
79072805 | 162 | extern char * memcpy P((char*, char*, int)); |
ee0007ab LW |
163 | # endif |
164 | # endif | |
165 | #else | |
166 | # ifndef memcpy | |
167 | # ifdef HAS_BCOPY | |
168 | # define memcpy(d,s,l) bcopy(s,d,l) | |
169 | # else | |
170 | # define memcpy(d,s,l) my_bcopy(s,d,l) | |
171 | # endif | |
172 | # endif | |
173 | #endif /* HAS_MEMCPY */ | |
fe14fcc3 | 174 | |
ee0007ab LW |
175 | #ifdef HAS_MEMSET |
176 | # ifndef STANDARD_C | |
177 | # ifndef memset | |
79072805 | 178 | extern char *memset P((char*, int, int)); |
ee0007ab LW |
179 | # endif |
180 | # endif | |
181 | # define memzero(d,l) memset(d,0,l) | |
182 | #else | |
183 | # ifndef memzero | |
184 | # ifdef HAS_BZERO | |
185 | # define memzero(d,l) bzero(d,l) | |
186 | # else | |
187 | # define memzero(d,l) my_bzero(d,l) | |
188 | # endif | |
352d5a3a | 189 | # endif |
ee0007ab LW |
190 | #endif /* HAS_MEMSET */ |
191 | ||
192 | #ifdef HAS_MEMCMP | |
193 | # ifndef STANDARD_C | |
194 | # ifndef memcmp | |
79072805 | 195 | extern int memcmp P((char*, char*, int)); |
ee0007ab LW |
196 | # endif |
197 | # endif | |
198 | #else | |
199 | # ifndef memcmp | |
200 | # define memcmp(s1,s2,l) my_memcmp(s1,s2,l) | |
352d5a3a | 201 | # endif |
ee0007ab | 202 | #endif /* HAS_MEMCMP */ |
8d063cd8 | 203 | |
ee0007ab LW |
204 | /* we prefer bcmp slightly for comparisons that don't care about ordering */ |
205 | #ifndef HAS_BCMP | |
352d5a3a LW |
206 | # ifndef bcmp |
207 | # define bcmp(s1,s2,l) memcmp(s1,s2,l) | |
208 | # endif | |
ee0007ab LW |
209 | #endif /* HAS_BCMP */ |
210 | ||
211 | #ifndef HAS_MEMMOVE | |
79072805 LW |
212 | # if defined(HAS_BCOPY) && defined(SAFE_BCOPY) |
213 | # define memmove(d,s,l) bcopy(s,d,l) | |
214 | # else | |
215 | # if defined(HAS_MEMCPY) && defined(SAFE_MEMCPY) | |
216 | # define memmove(d,s,l) memcpy(d,s,l) | |
217 | # else | |
218 | # define memmove(d,s,l) my_bcopy(s,d,l) | |
219 | # endif | |
220 | # endif | |
d9d8d8de | 221 | #endif |
378cc40b LW |
222 | |
223 | #ifndef _TYPES_ /* If types.h defines this it's easy. */ | |
79072805 LW |
224 | # ifndef major /* Does everyone's types.h define this? */ |
225 | # include <sys/types.h> | |
226 | # endif | |
378cc40b LW |
227 | #endif |
228 | ||
ae986130 | 229 | #ifdef I_NETINET_IN |
79072805 | 230 | # include <netinet/in.h> |
ae986130 LW |
231 | #endif |
232 | ||
8d063cd8 | 233 | #include <sys/stat.h> |
79072805 | 234 | |
ee0007ab | 235 | #if defined(uts) || defined(UTekV) |
79072805 LW |
236 | # undef S_ISDIR |
237 | # undef S_ISCHR | |
238 | # undef S_ISBLK | |
239 | # undef S_ISREG | |
240 | # undef S_ISFIFO | |
241 | # undef S_ISLNK | |
242 | # define S_ISDIR(P) (((P)&S_IFMT)==S_IFDIR) | |
243 | # define S_ISCHR(P) (((P)&S_IFMT)==S_IFCHR) | |
244 | # define S_ISBLK(P) (((P)&S_IFMT)==S_IFBLK) | |
245 | # define S_ISREG(P) (((P)&S_IFMT)==S_IFREG) | |
246 | # define S_ISFIFO(P) (((P)&S_IFMT)==S_IFIFO) | |
247 | # ifdef S_IFLNK | |
248 | # define S_ISLNK(P) (((P)&S_IFMT)==S_IFLNK) | |
249 | # endif | |
ee0007ab | 250 | #endif |
135863df | 251 | |
663a0e37 LW |
252 | #ifdef I_TIME |
253 | # include <time.h> | |
ffed7fef | 254 | #endif |
663a0e37 | 255 | |
fe14fcc3 | 256 | #ifdef I_SYS_TIME |
663a0e37 LW |
257 | # ifdef SYSTIMEKERNEL |
258 | # define KERNEL | |
259 | # endif | |
260 | # include <sys/time.h> | |
261 | # ifdef SYSTIMEKERNEL | |
262 | # undef KERNEL | |
263 | # endif | |
a687059c | 264 | #endif |
135863df | 265 | |
d9d8d8de | 266 | #ifndef MSDOS |
8d063cd8 | 267 | #include <sys/times.h> |
d9d8d8de | 268 | #endif |
8d063cd8 | 269 | |
fe14fcc3 | 270 | #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR)) |
79072805 | 271 | # undef HAS_STRERROR |
663a0e37 LW |
272 | #endif |
273 | ||
274 | #include <errno.h> | |
d9d8d8de | 275 | #ifndef MSDOS |
79072805 LW |
276 | # ifndef errno |
277 | extern int errno; /* ANSI allows errno to be an lvalue expr */ | |
278 | # endif | |
d9d8d8de | 279 | #endif |
663a0e37 | 280 | |
35c8bce7 | 281 | #ifndef strerror |
79072805 LW |
282 | # ifdef HAS_STRERROR |
283 | char *strerror P((int)); | |
284 | # else | |
285 | extern int sys_nerr; | |
286 | extern char *sys_errlist[]; | |
287 | # define strerror(e) \ | |
288 | ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e]) | |
289 | # endif | |
35c8bce7 | 290 | #endif |
663a0e37 | 291 | |
a687059c | 292 | #ifdef I_SYSIOCTL |
79072805 LW |
293 | # ifndef _IOCTL_ |
294 | # include <sys/ioctl.h> | |
295 | # endif | |
a687059c LW |
296 | #endif |
297 | ||
ee0007ab | 298 | #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000) |
79072805 LW |
299 | # ifdef HAS_SOCKETPAIR |
300 | # undef HAS_SOCKETPAIR | |
301 | # endif | |
302 | # ifdef HAS_NDBM | |
303 | # undef HAS_NDBM | |
304 | # endif | |
a687059c LW |
305 | #endif |
306 | ||
a687059c | 307 | #if INTSIZE == 2 |
79072805 LW |
308 | # define htoni htons |
309 | # define ntohi ntohs | |
a687059c | 310 | #else |
79072805 LW |
311 | # define htoni htonl |
312 | # define ntohi ntohl | |
a687059c LW |
313 | #endif |
314 | ||
35c8bce7 | 315 | #if defined(I_DIRENT) |
663a0e37 LW |
316 | # include <dirent.h> |
317 | # define DIRENT dirent | |
ae986130 | 318 | #else |
fe14fcc3 | 319 | # ifdef I_SYS_NDIR |
79a0689e | 320 | # include <sys/ndir.h> |
663a0e37 LW |
321 | # define DIRENT direct |
322 | # else | |
fe14fcc3 | 323 | # ifdef I_SYS_DIR |
79a0689e LW |
324 | # ifdef hp9000s500 |
325 | # include <ndir.h> /* may be wrong in the future */ | |
326 | # else | |
327 | # include <sys/dir.h> | |
328 | # endif | |
663a0e37 LW |
329 | # define DIRENT direct |
330 | # endif | |
331 | # endif | |
a687059c LW |
332 | #endif |
333 | ||
352d5a3a LW |
334 | #ifdef FPUTS_BOTCH |
335 | /* work around botch in SunOS 4.0.1 and 4.0.2 */ | |
336 | # ifndef fputs | |
79072805 | 337 | # define fputs(sv,fp) fprintf(fp,"%s",sv) |
352d5a3a LW |
338 | # endif |
339 | #endif | |
340 | ||
c623bd54 LW |
341 | /* |
342 | * The following gobbledygook brought to you on behalf of __STDC__. | |
343 | * (I could just use #ifndef __STDC__, but this is more bulletproof | |
344 | * in the face of half-implementations.) | |
345 | */ | |
346 | ||
347 | #ifndef S_IFMT | |
348 | # ifdef _S_IFMT | |
349 | # define S_IFMT _S_IFMT | |
350 | # else | |
351 | # define S_IFMT 0170000 | |
352 | # endif | |
353 | #endif | |
354 | ||
355 | #ifndef S_ISDIR | |
356 | # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR) | |
357 | #endif | |
358 | ||
359 | #ifndef S_ISCHR | |
360 | # define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR) | |
361 | #endif | |
362 | ||
363 | #ifndef S_ISBLK | |
fe14fcc3 LW |
364 | # ifdef S_IFBLK |
365 | # define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK) | |
366 | # else | |
367 | # define S_ISBLK(m) (0) | |
368 | # endif | |
c623bd54 LW |
369 | #endif |
370 | ||
371 | #ifndef S_ISREG | |
372 | # define S_ISREG(m) ((m & S_IFMT) == S_IFREG) | |
373 | #endif | |
374 | ||
375 | #ifndef S_ISFIFO | |
fe14fcc3 LW |
376 | # ifdef S_IFIFO |
377 | # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO) | |
378 | # else | |
379 | # define S_ISFIFO(m) (0) | |
380 | # endif | |
c623bd54 LW |
381 | #endif |
382 | ||
383 | #ifndef S_ISLNK | |
384 | # ifdef _S_ISLNK | |
385 | # define S_ISLNK(m) _S_ISLNK(m) | |
386 | # else | |
387 | # ifdef _S_IFLNK | |
388 | # define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK) | |
389 | # else | |
390 | # ifdef S_IFLNK | |
391 | # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK) | |
392 | # else | |
393 | # define S_ISLNK(m) (0) | |
394 | # endif | |
395 | # endif | |
396 | # endif | |
397 | #endif | |
398 | ||
399 | #ifndef S_ISSOCK | |
400 | # ifdef _S_ISSOCK | |
401 | # define S_ISSOCK(m) _S_ISSOCK(m) | |
402 | # else | |
403 | # ifdef _S_IFSOCK | |
404 | # define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK) | |
405 | # else | |
406 | # ifdef S_IFSOCK | |
407 | # define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK) | |
408 | # else | |
409 | # define S_ISSOCK(m) (0) | |
410 | # endif | |
411 | # endif | |
412 | # endif | |
413 | #endif | |
414 | ||
415 | #ifndef S_IRUSR | |
416 | # ifdef S_IREAD | |
417 | # define S_IRUSR S_IREAD | |
418 | # define S_IWUSR S_IWRITE | |
419 | # define S_IXUSR S_IEXEC | |
420 | # else | |
421 | # define S_IRUSR 0400 | |
422 | # define S_IWUSR 0200 | |
423 | # define S_IXUSR 0100 | |
424 | # endif | |
425 | # define S_IRGRP (S_IRUSR>>3) | |
426 | # define S_IWGRP (S_IWUSR>>3) | |
427 | # define S_IXGRP (S_IXUSR>>3) | |
428 | # define S_IROTH (S_IRUSR>>6) | |
429 | # define S_IWOTH (S_IWUSR>>6) | |
430 | # define S_IXOTH (S_IXUSR>>6) | |
431 | #endif | |
432 | ||
433 | #ifndef S_ISUID | |
434 | # define S_ISUID 04000 | |
435 | #endif | |
436 | ||
437 | #ifndef S_ISGID | |
438 | # define S_ISGID 02000 | |
439 | #endif | |
440 | ||
79072805 LW |
441 | #ifdef ff_next |
442 | # undef ff_next | |
352d5a3a LW |
443 | #endif |
444 | ||
ee0007ab | 445 | #if defined(cray) || defined(gould) || defined(i860) |
45d8adaa LW |
446 | # define SLOPPYDIVIDE |
447 | #endif | |
448 | ||
988174c1 | 449 | #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff |
45d8adaa LW |
450 | # define QUAD |
451 | #endif | |
452 | ||
453 | #ifdef QUAD | |
454 | # ifdef cray | |
455 | # define quad int | |
456 | # else | |
988174c1 | 457 | # if defined(convex) || defined (uts) |
45d8adaa LW |
458 | # define quad long long |
459 | # else | |
460 | # define quad long | |
461 | # endif | |
462 | # endif | |
463 | #endif | |
464 | ||
79072805 LW |
465 | #ifdef VOIDSIG |
466 | # define VOIDRET void | |
467 | #else | |
468 | # define VOIDRET int | |
469 | #endif | |
470 | ||
471 | #ifdef DOSISH | |
472 | # include "dosish.h" | |
473 | #else | |
474 | # include "unixish.h" | |
475 | #endif | |
476 | ||
477 | #ifndef HAS_PAUSE | |
478 | #define pause() sleep((32767<<16)+32767) | |
479 | #endif | |
480 | ||
481 | #ifndef IOCPARM_LEN | |
482 | # ifdef IOCPARM_MASK | |
483 | /* on BSDish systes we're safe */ | |
484 | # define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK) | |
485 | # else | |
486 | /* otherwise guess at what's safe */ | |
487 | # define IOCPARM_LEN(x) 256 | |
488 | # endif | |
489 | #endif | |
490 | ||
ee0007ab | 491 | typedef MEM_SIZE STRLEN; |
450a55e4 | 492 | |
79072805 LW |
493 | typedef struct op OP; |
494 | typedef struct cop COP; | |
495 | typedef struct unop UNOP; | |
496 | typedef struct binop BINOP; | |
497 | typedef struct listop LISTOP; | |
498 | typedef struct logop LOGOP; | |
499 | typedef struct condop CONDOP; | |
500 | typedef struct pmop PMOP; | |
501 | typedef struct svop SVOP; | |
502 | typedef struct gvop GVOP; | |
503 | typedef struct pvop PVOP; | |
504 | typedef struct cvop CVOP; | |
505 | typedef struct loop LOOP; | |
506 | ||
507 | typedef struct Outrec Outrec; | |
508 | typedef struct lstring Lstring; | |
93a17b20 | 509 | typedef struct interpreter PerlInterpreter; |
79072805 LW |
510 | typedef struct ff FF; |
511 | typedef struct io IO; | |
512 | typedef struct sv SV; | |
513 | typedef struct av AV; | |
514 | typedef struct hv HV; | |
515 | typedef struct cv CV; | |
378cc40b | 516 | typedef struct regexp REGEXP; |
79072805 LW |
517 | typedef struct gp GP; |
518 | typedef struct sv GV; | |
519 | typedef struct context CONTEXT; | |
520 | typedef struct block BLOCK; | |
521 | ||
522 | typedef struct magic MAGIC; | |
523 | typedef struct xpv XPV; | |
524 | typedef struct xpviv XPVIV; | |
525 | typedef struct xpvnv XPVNV; | |
526 | typedef struct xpvmg XPVMG; | |
527 | typedef struct xpvlv XPVLV; | |
528 | typedef struct xpvav XPVAV; | |
529 | typedef struct xpvhv XPVHV; | |
530 | typedef struct xpvgv XPVGV; | |
531 | typedef struct xpvcv XPVCV; | |
532 | typedef struct xpvbm XPVBM; | |
533 | typedef struct xpvfm XPVFM; | |
534 | typedef struct mgvtbl MGVTBL; | |
535 | typedef union any ANY; | |
8d063cd8 | 536 | |
378cc40b | 537 | #include "handy.h" |
79072805 LW |
538 | union any { |
539 | void* any_ptr; | |
540 | I32 any_i32; | |
541 | }; | |
542 | ||
378cc40b | 543 | #include "regexp.h" |
79072805 | 544 | #include "sv.h" |
378cc40b | 545 | #include "util.h" |
8d063cd8 | 546 | #include "form.h" |
79072805 LW |
547 | #include "gv.h" |
548 | #include "cv.h" | |
549 | #include "opcode.h" | |
550 | #include "op.h" | |
551 | #include "cop.h" | |
552 | #include "av.h" | |
553 | #include "hv.h" | |
554 | #include "mg.h" | |
555 | #include "scope.h" | |
8d063cd8 | 556 | |
450a55e4 | 557 | #if defined(iAPX286) || defined(M_I286) || defined(I80286) |
a687059c LW |
558 | # define I286 |
559 | #endif | |
560 | ||
352d5a3a | 561 | #ifndef STANDARD_C |
79072805 LW |
562 | # ifdef CHARSPRINTF |
563 | char *sprintf P((char *, ...)); | |
564 | # else | |
565 | int sprintf P((char *, ...)); | |
566 | # endif | |
a687059c LW |
567 | #endif |
568 | ||
fe14fcc3 LW |
569 | #if defined(htonl) && !defined(HAS_HTONL) |
570 | #define HAS_HTONL | |
ae986130 | 571 | #endif |
fe14fcc3 LW |
572 | #if defined(htons) && !defined(HAS_HTONS) |
573 | #define HAS_HTONS | |
ae986130 | 574 | #endif |
fe14fcc3 LW |
575 | #if defined(ntohl) && !defined(HAS_NTOHL) |
576 | #define HAS_NTOHL | |
ae986130 | 577 | #endif |
fe14fcc3 LW |
578 | #if defined(ntohs) && !defined(HAS_NTOHS) |
579 | #define HAS_NTOHS | |
ae986130 | 580 | #endif |
fe14fcc3 | 581 | #ifndef HAS_HTONL |
d9d8d8de | 582 | #if (BYTEORDER & 0xffff) != 0x4321 |
fe14fcc3 LW |
583 | #define HAS_HTONS |
584 | #define HAS_HTONL | |
585 | #define HAS_NTOHS | |
586 | #define HAS_NTOHL | |
a687059c LW |
587 | #define MYSWAP |
588 | #define htons my_swap | |
589 | #define htonl my_htonl | |
590 | #define ntohs my_swap | |
591 | #define ntohl my_ntohl | |
592 | #endif | |
593 | #else | |
d9d8d8de | 594 | #if (BYTEORDER & 0xffff) == 0x4321 |
fe14fcc3 LW |
595 | #undef HAS_HTONS |
596 | #undef HAS_HTONL | |
597 | #undef HAS_NTOHS | |
598 | #undef HAS_NTOHL | |
a687059c LW |
599 | #endif |
600 | #endif | |
601 | ||
988174c1 LW |
602 | /* |
603 | * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'. | |
604 | * -DWS | |
605 | */ | |
606 | #if BYTEORDER != 0x1234 | |
607 | # define HAS_VTOHL | |
608 | # define HAS_VTOHS | |
609 | # define HAS_HTOVL | |
610 | # define HAS_HTOVS | |
611 | # if BYTEORDER == 0x4321 | |
612 | # define vtohl(x) ((((x)&0xFF)<<24) \ | |
613 | +(((x)>>24)&0xFF) \ | |
614 | +(((x)&0x0000FF00)<<8) \ | |
615 | +(((x)&0x00FF0000)>>8) ) | |
616 | # define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF)) | |
617 | # define htovl(x) vtohl(x) | |
618 | # define htovs(x) vtohs(x) | |
619 | # endif | |
620 | /* otherwise default to functions in util.c */ | |
621 | #endif | |
622 | ||
0f85fab0 | 623 | #ifdef CASTNEGFLOAT |
79072805 | 624 | #define U_S(what) ((U16)(what)) |
0f85fab0 | 625 | #define U_I(what) ((unsigned int)(what)) |
79072805 | 626 | #define U_L(what) ((U32)(what)) |
0f85fab0 | 627 | #else |
79072805 LW |
628 | U32 cast_ulong P((double)); |
629 | #define U_S(what) ((U16)cast_ulong(what)) | |
630 | #define U_I(what) ((unsigned int)cast_ulong(what)) | |
631 | #define U_L(what) (cast_ulong(what)) | |
ee0007ab LW |
632 | #endif |
633 | ||
79072805 LW |
634 | struct Outrec { |
635 | I32 o_lines; | |
d9d8d8de | 636 | char *o_str; |
79072805 | 637 | U32 o_len; |
8d063cd8 LW |
638 | }; |
639 | ||
352d5a3a LW |
640 | #ifndef MAXSYSFD |
641 | # define MAXSYSFD 2 | |
642 | #endif | |
ee0007ab LW |
643 | |
644 | #ifndef DOSISH | |
378cc40b | 645 | #define TMPPATH "/tmp/perl-eXXXXXX" |
450a55e4 | 646 | #else |
57ebbfd0 | 647 | #define TMPPATH "plXXXXXX" |
450a55e4 | 648 | #endif /* MSDOS */ |
79072805 LW |
649 | |
650 | #ifndef __cplusplus | |
651 | UIDTYPE getuid P(()); | |
652 | UIDTYPE geteuid P(()); | |
653 | GIDTYPE getgid P(()); | |
654 | GIDTYPE getegid P(()); | |
655 | #endif | |
8d063cd8 LW |
656 | |
657 | #ifdef DEBUGGING | |
d96024cf | 658 | #define YYDEBUG 1 |
79072805 LW |
659 | #define DEB(a) a |
660 | #define DEBUG(a) if (debug) a | |
661 | #define DEBUG_p(a) if (debug & 1) a | |
662 | #define DEBUG_s(a) if (debug & 2) a | |
663 | #define DEBUG_l(a) if (debug & 4) a | |
664 | #define DEBUG_t(a) if (debug & 8) a | |
665 | #define DEBUG_o(a) if (debug & 16) a | |
666 | #define DEBUG_c(a) if (debug & 32) a | |
667 | #define DEBUG_P(a) if (debug & 64) a | |
668 | #define DEBUG_m(a) if (debug & 128) a | |
669 | #define DEBUG_f(a) if (debug & 256) a | |
670 | #define DEBUG_r(a) if (debug & 512) a | |
671 | #define DEBUG_x(a) if (debug & 1024) a | |
672 | #define DEBUG_u(a) if (debug & 2048) a | |
673 | #define DEBUG_L(a) if (debug & 4096) a | |
674 | #define DEBUG_H(a) if (debug & 8192) a | |
675 | #define DEBUG_X(a) if (debug & 16384) a | |
676 | #else | |
677 | #define DEB(a) | |
678 | #define DEBUG(a) | |
679 | #define DEBUG_p(a) | |
680 | #define DEBUG_s(a) | |
681 | #define DEBUG_l(a) | |
682 | #define DEBUG_t(a) | |
683 | #define DEBUG_o(a) | |
684 | #define DEBUG_c(a) | |
685 | #define DEBUG_P(a) | |
686 | #define DEBUG_m(a) | |
687 | #define DEBUG_f(a) | |
688 | #define DEBUG_r(a) | |
689 | #define DEBUG_x(a) | |
690 | #define DEBUG_u(a) | |
691 | #define DEBUG_L(a) | |
692 | #define DEBUG_H(a) | |
693 | #define DEBUG_X(a) | |
8d063cd8 | 694 | #endif |
fe14fcc3 | 695 | #define YYMAXDEPTH 300 |
8d063cd8 | 696 | |
79072805 LW |
697 | #define assert(what) DEB( { \ |
698 | if (!(what)) { \ | |
463ee0b2 | 699 | croak("Assertion failed: file \"%s\", line %d", \ |
79072805 LW |
700 | __FILE__, __LINE__); \ |
701 | exit(1); \ | |
702 | }}) | |
8d063cd8 | 703 | |
450a55e4 | 704 | struct ufuncs { |
79072805 LW |
705 | I32 (*uf_val)P((I32, SV*)); |
706 | I32 (*uf_set)P((I32, SV*)); | |
707 | I32 uf_index; | |
450a55e4 LW |
708 | }; |
709 | ||
fe14fcc3 | 710 | /* Fix these up for __STDC__ */ |
79072805 LW |
711 | char *mktemp P((char*)); |
712 | double atof P((const char*)); | |
713 | ||
352d5a3a | 714 | #ifndef STANDARD_C |
fe14fcc3 | 715 | /* All of these are in stdlib.h or time.h for ANSI C */ |
a687059c | 716 | long time(); |
8d063cd8 | 717 | struct tm *gmtime(), *localtime(); |
93a17b20 | 718 | char *strchr(), *strrchr(); |
378cc40b | 719 | char *strcpy(), *strcat(); |
352d5a3a | 720 | #endif /* ! STANDARD_C */ |
8d063cd8 | 721 | |
79072805 LW |
722 | |
723 | #ifdef I_MATH | |
724 | # include <math.h> | |
725 | #else | |
726 | # ifdef __cplusplus | |
727 | extern "C" { | |
728 | # endif | |
729 | double exp P((double)); | |
730 | double log P((double)); | |
731 | double sqrt P((double)); | |
732 | double modf P((double,int*)); | |
733 | double sin P((double)); | |
734 | double cos P((double)); | |
735 | double atan2 P((double,double)); | |
736 | double pow P((double,double)); | |
737 | # ifdef __cplusplus | |
738 | }; | |
739 | # endif | |
740 | #endif | |
741 | ||
742 | ||
743 | char *crypt P((const char*, const char*)); | |
744 | char *getenv P((const char*)); | |
745 | long lseek P((int,int,int)); | |
746 | char *getlogin P((void)); | |
747 | ||
8d063cd8 | 748 | #ifdef EUNICE |
378cc40b | 749 | #define UNLINK unlnk |
79072805 | 750 | int unlnk P((char*)); |
8d063cd8 LW |
751 | #else |
752 | #define UNLINK unlink | |
753 | #endif | |
a687059c | 754 | |
fe14fcc3 LW |
755 | #ifndef HAS_SETREUID |
756 | #ifdef HAS_SETRESUID | |
a687059c | 757 | #define setreuid(r,e) setresuid(r,e,-1) |
fe14fcc3 | 758 | #define HAS_SETREUID |
a687059c LW |
759 | #endif |
760 | #endif | |
fe14fcc3 LW |
761 | #ifndef HAS_SETREGID |
762 | #ifdef HAS_SETRESGID | |
a687059c | 763 | #define setregid(r,e) setresgid(r,e,-1) |
fe14fcc3 | 764 | #define HAS_SETREGID |
a687059c LW |
765 | #endif |
766 | #endif | |
ee0007ab LW |
767 | |
768 | #define SCAN_DEF 0 | |
769 | #define SCAN_TR 1 | |
770 | #define SCAN_REPL 2 | |
79072805 LW |
771 | |
772 | #ifdef DEBUGGING | |
773 | #define PAD_SV(po) pad_sv(po) | |
774 | #else | |
775 | #define PAD_SV(po) curpad[po] | |
776 | #endif | |
777 | ||
778 | /****************/ | |
779 | /* Truly global */ | |
780 | /****************/ | |
781 | ||
782 | /* global state */ | |
93a17b20 | 783 | EXT PerlInterpreter *curinterp; /* currently running interpreter */ |
79072805 LW |
784 | extern char ** environ; /* environment variables supplied via exec */ |
785 | EXT int uid; /* current real user id */ | |
786 | EXT int euid; /* current effective user id */ | |
787 | EXT int gid; /* current real group id */ | |
788 | EXT int egid; /* current effective group id */ | |
789 | EXT bool nomemok; /* let malloc context handle nomem */ | |
790 | EXT U32 an; /* malloc sequence number */ | |
463ee0b2 LW |
791 | EXT U32 cop_seqmax; /* statement sequence number */ |
792 | EXT U32 op_seqmax; /* op sequence number */ | |
793 | EXT U32 sub_generation; /* inc to force methods to be looked up again */ | |
79072805 LW |
794 | EXT char ** origenviron; |
795 | EXT U32 origalen; | |
796 | ||
797 | /* Stack for currently executing thread--context switch must handle this. */ | |
798 | EXT SV ** stack_base; /* stack->array_ary */ | |
799 | EXT SV ** stack_sp; /* stack pointer now */ | |
800 | EXT SV ** stack_max; /* stack->array_ary + stack->array_max */ | |
801 | ||
802 | /* likewise for these */ | |
803 | ||
804 | EXT OP * op; /* current op--oughta be in a global register */ | |
805 | ||
806 | EXT I32 * scopestack; /* blocks we've entered */ | |
807 | EXT I32 scopestack_ix; | |
808 | EXT I32 scopestack_max; | |
809 | ||
810 | EXT ANY* savestack; /* to save non-local values on */ | |
811 | EXT I32 savestack_ix; | |
812 | EXT I32 savestack_max; | |
813 | ||
814 | EXT OP ** retstack; /* returns we've pushed */ | |
815 | EXT I32 retstack_ix; | |
816 | EXT I32 retstack_max; | |
817 | ||
818 | EXT I32 * markstack; /* stackmarks we're remembering */ | |
819 | EXT I32 * markstack_ptr; /* stackmarks we're remembering */ | |
820 | EXT I32 * markstack_max; /* stackmarks we're remembering */ | |
821 | ||
822 | EXT SV ** curpad; | |
823 | ||
824 | /* temp space */ | |
825 | EXT SV * Sv; | |
826 | EXT XPV * Xpv; | |
827 | EXT char buf[1024]; | |
828 | EXT char tokenbuf[256]; | |
829 | EXT struct stat statbuf; | |
830 | #ifndef MSDOS | |
831 | EXT struct tms timesbuf; | |
832 | #endif | |
463ee0b2 | 833 | EXT STRLEN na; /* for use in SvPV when length is Not Applicable */ |
79072805 LW |
834 | |
835 | /* for tmp use in stupid debuggers */ | |
836 | EXT int * di; | |
837 | EXT short * ds; | |
838 | EXT char * dc; | |
839 | ||
840 | /* handy constants */ | |
841 | EXT char * Yes INIT("1"); | |
842 | EXT char * No INIT(""); | |
843 | EXT char * hexdigit INIT("0123456789abcdef0123456789ABCDEFx"); | |
79072805 LW |
844 | EXT char * patleave INIT("\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}"); |
845 | EXT char * vert INIT("|"); | |
846 | ||
463ee0b2 LW |
847 | EXT char warn_nosemi[] |
848 | INIT("Semicolon seems to be missing"); | |
849 | EXT char warn_reserved[] | |
850 | INIT("Unquoted string \"%s\" may clash with future reserved word"); | |
851 | EXT char warn_nl[] | |
93a17b20 LW |
852 | INIT("Unsuccessful %s on filename containing newline"); |
853 | EXT char no_usym[] | |
854 | INIT("Can't use an undefined value to create a symbol"); | |
855 | EXT char no_aelem[] | |
856 | INIT("Modification of non-creatable array value attempted, subscript %d"); | |
857 | EXT char no_helem[] | |
858 | INIT("Modification of non-creatable hash value attempted, subscript \"%s\""); | |
859 | EXT char no_modify[] | |
860 | INIT("Modification of a read-only value attempted"); | |
861 | EXT char no_mem[] | |
862 | INIT("Out of memory!\n"); | |
863 | EXT char no_security[] | |
463ee0b2 | 864 | INIT("Insecure dependency in %s%s"); |
93a17b20 LW |
865 | EXT char no_sock_func[] |
866 | INIT("Unsupported socket function \"%s\" called"); | |
867 | EXT char no_dir_func[] | |
868 | INIT("Unsupported directory function \"%s\" called"); | |
869 | EXT char no_func[] | |
870 | INIT("The %s function is unimplemented"); | |
871 | ||
79072805 LW |
872 | EXT SV sv_undef; |
873 | EXT SV sv_no; | |
874 | EXT SV sv_yes; | |
875 | #ifdef CSH | |
876 | EXT char * cshname INIT(CSH); | |
877 | EXT I32 cshlen; | |
878 | #endif | |
879 | ||
880 | #ifdef DOINIT | |
881 | EXT char *sig_name[] = { | |
882 | SIG_NAME,0 | |
883 | }; | |
884 | #else | |
885 | EXT char *sig_name[]; | |
886 | #endif | |
887 | ||
888 | #ifdef DOINIT | |
79072805 LW |
889 | EXT unsigned char fold[] = { /* fast case folding table */ |
890 | 0, 1, 2, 3, 4, 5, 6, 7, | |
891 | 8, 9, 10, 11, 12, 13, 14, 15, | |
892 | 16, 17, 18, 19, 20, 21, 22, 23, | |
893 | 24, 25, 26, 27, 28, 29, 30, 31, | |
894 | 32, 33, 34, 35, 36, 37, 38, 39, | |
895 | 40, 41, 42, 43, 44, 45, 46, 47, | |
896 | 48, 49, 50, 51, 52, 53, 54, 55, | |
897 | 56, 57, 58, 59, 60, 61, 62, 63, | |
898 | 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g', | |
899 | 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', | |
900 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', | |
901 | 'x', 'y', 'z', 91, 92, 93, 94, 95, | |
902 | 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G', | |
903 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', | |
904 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', | |
905 | 'X', 'Y', 'Z', 123, 124, 125, 126, 127, | |
906 | 128, 129, 130, 131, 132, 133, 134, 135, | |
907 | 136, 137, 138, 139, 140, 141, 142, 143, | |
908 | 144, 145, 146, 147, 148, 149, 150, 151, | |
909 | 152, 153, 154, 155, 156, 157, 158, 159, | |
910 | 160, 161, 162, 163, 164, 165, 166, 167, | |
911 | 168, 169, 170, 171, 172, 173, 174, 175, | |
912 | 176, 177, 178, 179, 180, 181, 182, 183, | |
913 | 184, 185, 186, 187, 188, 189, 190, 191, | |
914 | 192, 193, 194, 195, 196, 197, 198, 199, | |
915 | 200, 201, 202, 203, 204, 205, 206, 207, | |
916 | 208, 209, 210, 211, 212, 213, 214, 215, | |
917 | 216, 217, 218, 219, 220, 221, 222, 223, | |
918 | 224, 225, 226, 227, 228, 229, 230, 231, | |
919 | 232, 233, 234, 235, 236, 237, 238, 239, | |
920 | 240, 241, 242, 243, 244, 245, 246, 247, | |
921 | 248, 249, 250, 251, 252, 253, 254, 255 | |
922 | }; | |
923 | #else | |
924 | EXT unsigned char fold[]; | |
925 | #endif | |
926 | ||
927 | #ifdef DOINIT | |
928 | EXT unsigned char freq[] = { /* letter frequencies for mixed English/C */ | |
929 | 1, 2, 84, 151, 154, 155, 156, 157, | |
930 | 165, 246, 250, 3, 158, 7, 18, 29, | |
931 | 40, 51, 62, 73, 85, 96, 107, 118, | |
932 | 129, 140, 147, 148, 149, 150, 152, 153, | |
933 | 255, 182, 224, 205, 174, 176, 180, 217, | |
934 | 233, 232, 236, 187, 235, 228, 234, 226, | |
935 | 222, 219, 211, 195, 188, 193, 185, 184, | |
936 | 191, 183, 201, 229, 181, 220, 194, 162, | |
937 | 163, 208, 186, 202, 200, 218, 198, 179, | |
938 | 178, 214, 166, 170, 207, 199, 209, 206, | |
939 | 204, 160, 212, 216, 215, 192, 175, 173, | |
940 | 243, 172, 161, 190, 203, 189, 164, 230, | |
941 | 167, 248, 227, 244, 242, 255, 241, 231, | |
942 | 240, 253, 169, 210, 245, 237, 249, 247, | |
943 | 239, 168, 252, 251, 254, 238, 223, 221, | |
944 | 213, 225, 177, 197, 171, 196, 159, 4, | |
945 | 5, 6, 8, 9, 10, 11, 12, 13, | |
946 | 14, 15, 16, 17, 19, 20, 21, 22, | |
947 | 23, 24, 25, 26, 27, 28, 30, 31, | |
948 | 32, 33, 34, 35, 36, 37, 38, 39, | |
949 | 41, 42, 43, 44, 45, 46, 47, 48, | |
950 | 49, 50, 52, 53, 54, 55, 56, 57, | |
951 | 58, 59, 60, 61, 63, 64, 65, 66, | |
952 | 67, 68, 69, 70, 71, 72, 74, 75, | |
953 | 76, 77, 78, 79, 80, 81, 82, 83, | |
954 | 86, 87, 88, 89, 90, 91, 92, 93, | |
955 | 94, 95, 97, 98, 99, 100, 101, 102, | |
956 | 103, 104, 105, 106, 108, 109, 110, 111, | |
957 | 112, 113, 114, 115, 116, 117, 119, 120, | |
958 | 121, 122, 123, 124, 125, 126, 127, 128, | |
959 | 130, 131, 132, 133, 134, 135, 136, 137, | |
960 | 138, 139, 141, 142, 143, 144, 145, 146 | |
961 | }; | |
962 | #else | |
963 | EXT unsigned char freq[]; | |
964 | #endif | |
965 | ||
966 | /*****************************************************************************/ | |
967 | /* This lexer/parser stuff is currently global since yacc is hard to reenter */ | |
968 | /*****************************************************************************/ | |
969 | ||
970 | typedef enum { | |
971 | XOPERATOR, | |
972 | XTERM, | |
973 | XBLOCK, | |
974 | XREF, | |
975 | } expectation; | |
976 | ||
977 | EXT FILE * VOL rsfp INIT(Nullfp); | |
978 | EXT SV * linestr; | |
979 | EXT char * bufptr; | |
980 | EXT char * oldbufptr; | |
981 | EXT char * oldoldbufptr; | |
982 | EXT char * bufend; | |
983 | EXT expectation expect INIT(XBLOCK); /* how to interpret ambiguous tokens */ | |
984 | ||
985 | EXT I32 multi_start; /* 1st line of multi-line string */ | |
986 | EXT I32 multi_end; /* last line of multi-line string */ | |
987 | EXT I32 multi_open; /* delimiter of said string */ | |
988 | EXT I32 multi_close; /* delimiter of said string */ | |
989 | ||
990 | EXT GV * scrgv; | |
991 | EXT I32 error_count; /* how many errors so far, max 10 */ | |
992 | EXT I32 subline; /* line this subroutine began on */ | |
993 | EXT SV * subname; /* name of current subroutine */ | |
994 | ||
93a17b20 LW |
995 | EXT AV * comppad; /* storage for lexically scoped temporaries */ |
996 | EXT AV * comppadname; /* variable names for "my" variables */ | |
997 | EXT I32 comppadnamefill;/* last "introduced" variable offset */ | |
79072805 LW |
998 | EXT I32 padix; /* max used index in current "register" pad */ |
999 | EXT COP compiling; | |
1000 | ||
1001 | EXT SV * evstr; /* op_fold_const() temp string cache */ | |
1002 | EXT I32 thisexpr; /* name id for nothing_in_common() */ | |
1003 | EXT char * last_uni; /* position of last named-unary operator */ | |
1004 | EXT char * last_lop; /* position of last list operator */ | |
1005 | EXT bool in_format; /* we're compiling a run_format */ | |
93a17b20 | 1006 | EXT bool in_my; /* we're compiling a "my" declaration */ |
463ee0b2 | 1007 | EXT I32 needblockscope INIT(TRUE); /* block overhead needed? */ |
79072805 LW |
1008 | #ifdef FCRYPT |
1009 | EXT I32 cryptseen; /* has fast crypt() been initialized? */ | |
1010 | #endif | |
1011 | ||
1012 | /**************************************************************************/ | |
1013 | /* This regexp stuff is global since it always happens within 1 expr eval */ | |
1014 | /**************************************************************************/ | |
1015 | ||
1016 | EXT char * regprecomp; /* uncompiled string. */ | |
1017 | EXT char * regparse; /* Input-scan pointer. */ | |
1018 | EXT char * regxend; /* End of input for compile */ | |
1019 | EXT I32 regnpar; /* () count. */ | |
1020 | EXT char * regcode; /* Code-emit pointer; ®dummy = don't. */ | |
1021 | EXT I32 regsize; /* Code size. */ | |
1022 | EXT I32 regfold; /* are we folding? */ | |
1023 | EXT I32 regsawbracket; /* Did we do {d,d} trick? */ | |
1024 | EXT I32 regsawback; /* Did we see \1, ...? */ | |
1025 | ||
1026 | EXT char * reginput; /* String-input pointer. */ | |
1027 | EXT char regprev; /* char before regbol, \n if none */ | |
1028 | EXT char * regbol; /* Beginning of input, for ^ check. */ | |
1029 | EXT char * regeol; /* End of input, for $ check. */ | |
1030 | EXT char ** regstartp; /* Pointer to startp array. */ | |
1031 | EXT char ** regendp; /* Ditto for endp. */ | |
1032 | EXT char * reglastparen; /* Similarly for lastparen. */ | |
1033 | EXT char * regtill; /* How far we are required to go. */ | |
1034 | EXT I32 regmyp_size; | |
1035 | EXT char ** regmystartp; | |
1036 | EXT char ** regmyendp; | |
1037 | ||
1038 | /***********************************************/ | |
1039 | /* Global only to current interpreter instance */ | |
1040 | /***********************************************/ | |
1041 | ||
1042 | #ifdef EMBEDDED | |
1043 | #define IEXT | |
1044 | #define IINIT(x) | |
1045 | struct interpreter { | |
1046 | #else | |
1047 | #define IEXT EXT | |
1048 | #define IINIT(x) INIT(x) | |
1049 | #endif | |
1050 | ||
1051 | /* pseudo environmental stuff */ | |
1052 | IEXT int Iorigargc; | |
1053 | IEXT char ** Iorigargv; | |
1054 | IEXT GV * Ienvgv; | |
1055 | IEXT GV * Isiggv; | |
1056 | IEXT GV * Iincgv; | |
1057 | IEXT char * Iorigfilename; | |
1058 | ||
1059 | /* switches */ | |
1060 | IEXT char * Icddir; | |
1061 | IEXT bool Iminus_c; | |
1062 | IEXT char Ipatchlevel[6]; | |
1063 | IEXT char * Inrs IINIT("\n"); | |
1064 | IEXT U32 Inrschar IINIT('\n'); /* final char of rs, or 0777 if none */ | |
1065 | IEXT I32 Inrslen IINIT(1); | |
1066 | IEXT bool Ipreprocess; | |
1067 | IEXT bool Iminus_n; | |
1068 | IEXT bool Iminus_p; | |
1069 | IEXT bool Iminus_l; | |
1070 | IEXT bool Iminus_a; | |
1071 | IEXT bool Idoswitches; | |
1072 | IEXT bool Idowarn; | |
1073 | IEXT bool Idoextract; | |
79072805 LW |
1074 | IEXT bool Isawampersand; /* must save all match strings */ |
1075 | IEXT bool Isawstudy; /* do fbm_instr on all strings */ | |
1076 | IEXT bool Isawi; /* study must assume case insensitive */ | |
1077 | IEXT bool Isawvec; | |
1078 | IEXT bool Iunsafe; | |
1079 | IEXT bool Ido_undump; /* -u or dump seen? */ | |
1080 | IEXT char * Iinplace; | |
1081 | IEXT char * Ie_tmpname; | |
1082 | IEXT FILE * Ie_fp; | |
1083 | IEXT VOL U32 Idebug; | |
1084 | IEXT U32 Iperldb; | |
1085 | ||
1086 | /* magical thingies */ | |
1087 | IEXT time_t Ibasetime; /* $^T */ | |
1088 | IEXT I32 Iarybase; /* $[ */ | |
1089 | IEXT SV * Iformfeed; /* $^L */ | |
1090 | IEXT char * Ichopset IINIT(" \n-"); /* $: */ | |
1091 | IEXT char * Irs IINIT("\n"); /* $/ */ | |
1092 | IEXT U32 Irschar IINIT('\n'); /* final char of rs, or 0777 if none */ | |
1093 | IEXT I32 Irslen IINIT(1); | |
1094 | IEXT bool Irspara; | |
1095 | IEXT char * Iofs; /* $, */ | |
1096 | IEXT I32 Iofslen; | |
1097 | IEXT char * Iors; /* $\ */ | |
1098 | IEXT I32 Iorslen; | |
1099 | IEXT char * Iofmt; /* $# */ | |
1100 | IEXT I32 Imaxsysfd IINIT(MAXSYSFD); /* top fd to pass to subprocesses */ | |
1101 | IEXT int Imultiline; /* $*--do strings hold >1 line? */ | |
1102 | IEXT U16 Istatusvalue; /* $? */ | |
1103 | ||
1104 | IEXT struct stat Istatcache; /* _ */ | |
1105 | IEXT GV * Istatgv; | |
1106 | IEXT SV * Istatname IINIT(Nullsv); | |
1107 | ||
1108 | /* shortcuts to various I/O objects */ | |
1109 | IEXT GV * Istdingv; | |
1110 | IEXT GV * Ilast_in_gv; | |
1111 | IEXT GV * Idefgv; | |
1112 | IEXT GV * Iargvgv; | |
1113 | IEXT GV * Idefoutgv; | |
1114 | IEXT GV * Icuroutgv; | |
1115 | IEXT GV * Iargvoutgv; | |
1116 | ||
1117 | /* shortcuts to regexp stuff */ | |
1118 | IEXT GV * Ileftgv; | |
1119 | IEXT GV * Iampergv; | |
1120 | IEXT GV * Irightgv; | |
1121 | IEXT PMOP * Icurpm; /* what to do \ interps from */ | |
79072805 LW |
1122 | IEXT I32 * Iscreamfirst; |
1123 | IEXT I32 * Iscreamnext; | |
1124 | IEXT I32 Imaxscream IINIT(-1); | |
1125 | IEXT SV * Ilastscream; | |
1126 | ||
1127 | /* shortcuts to debugging objects */ | |
1128 | IEXT GV * IDBgv; | |
1129 | IEXT GV * IDBline; | |
1130 | IEXT GV * IDBsub; | |
1131 | IEXT SV * IDBsingle; | |
1132 | IEXT SV * IDBtrace; | |
1133 | IEXT SV * IDBsignal; | |
1134 | IEXT AV * Ilineary; /* lines of script for debugger */ | |
1135 | IEXT AV * Idbargs; /* args to call listed by caller function */ | |
1136 | ||
1137 | /* symbol tables */ | |
1138 | IEXT HV * Idefstash; /* main symbol table */ | |
1139 | IEXT HV * Icurstash; /* symbol table for current package */ | |
1140 | IEXT HV * Idebstash; /* symbol table for perldb package */ | |
1141 | IEXT SV * Icurstname; /* name of current package */ | |
93a17b20 LW |
1142 | IEXT AV * Ibeginav; /* names of BEGIN subroutines */ |
1143 | IEXT AV * Iendav; /* names of END subroutines */ | |
1144 | IEXT AV * Ipad; /* storage for lexically scoped temporaries */ | |
1145 | IEXT AV * Ipadname; /* variable names for "my" variables */ | |
79072805 LW |
1146 | |
1147 | /* memory management */ | |
1148 | IEXT SV * Ifreestrroot; | |
1149 | IEXT SV ** Itmps_stack; | |
1150 | IEXT I32 Itmps_ix IINIT(-1); | |
1151 | IEXT I32 Itmps_floor IINIT(-1); | |
1152 | IEXT I32 Itmps_max IINIT(-1); | |
1153 | ||
1154 | /* funky return mechanisms */ | |
1155 | IEXT I32 Ilastspbase; | |
1156 | IEXT I32 Ilastsize; | |
1157 | IEXT int Iforkprocess; /* so do_open |- can return proc# */ | |
1158 | ||
1159 | /* subprocess state */ | |
1160 | IEXT AV * Ifdpid; /* keep fd-to-pid mappings for my_popen */ | |
1161 | IEXT HV * Ipidstatus; /* keep pid-to-status mappings for waitpid */ | |
1162 | ||
1163 | /* internal state */ | |
463ee0b2 LW |
1164 | IEXT VOL int Iin_eval; /* trap "fatal" errors? */ |
1165 | IEXT OP * Irestartop; /* Are we propagating an error from croak? */ | |
79072805 LW |
1166 | IEXT int Idelaymagic; /* ($<,$>) = ... */ |
1167 | IEXT bool Idirty; /* clean before rerunning */ | |
1168 | IEXT bool Ilocalizing; /* are we processing a local() list? */ | |
79072805 | 1169 | IEXT bool Itainted; /* using variables controlled by $< */ |
463ee0b2 | 1170 | IEXT bool Itainting; /* doing taint checks */ |
79072805 LW |
1171 | |
1172 | /* trace state */ | |
1173 | IEXT I32 Idlevel; | |
1174 | IEXT I32 Idlmax IINIT(128); | |
1175 | IEXT char * Idebname; | |
1176 | IEXT char * Idebdelim; | |
1177 | ||
1178 | /* current interpreter roots */ | |
463ee0b2 LW |
1179 | IEXT OP * Imain_root; |
1180 | IEXT OP * Imain_start; | |
1181 | IEXT OP * Ieval_root; | |
1182 | IEXT OP * Ieval_start; | |
79072805 LW |
1183 | |
1184 | /* runtime control stuff */ | |
1185 | IEXT COP * VOL Icurcop IINIT(&compiling); | |
1186 | IEXT line_t Icopline IINIT(NOLINE); | |
1187 | IEXT CONTEXT * Icxstack; | |
1188 | IEXT I32 Icxstack_ix IINIT(-1); | |
1189 | IEXT I32 Icxstack_max IINIT(128); | |
1190 | IEXT jmp_buf Itop_env; | |
1191 | ||
1192 | /* stack stuff */ | |
1193 | IEXT AV * Istack; /* THE STACK */ | |
1194 | IEXT AV * Imainstack; /* the stack when nothing funny is happening */ | |
1195 | IEXT SV ** Imystack_base; /* stack->array_ary */ | |
1196 | IEXT SV ** Imystack_sp; /* stack pointer now */ | |
1197 | IEXT SV ** Imystack_max; /* stack->array_ary + stack->array_max */ | |
1198 | ||
1199 | /* format accumulators */ | |
463ee0b2 LW |
1200 | IEXT SV * Iformtarget; |
1201 | IEXT SV * Ibodytarget; | |
1202 | IEXT SV * Itoptarget; | |
79072805 LW |
1203 | |
1204 | /* statics moved here for shared library purposes */ | |
93a17b20 | 1205 | IEXT SV Istrchop; /* return value from chop */ |
79072805 LW |
1206 | IEXT int Ifilemode; /* so nextargv() can preserve mode */ |
1207 | IEXT int Ilastfd; /* what to preserve mode on */ | |
1208 | IEXT char * Ioldname; /* what to preserve mode on */ | |
1209 | IEXT char ** IArgv; /* stuff to free from do_aexec, vfork safe */ | |
1210 | IEXT char * ICmd; /* stuff to free from do_aexec, vfork safe */ | |
1211 | IEXT OP * Isortcop; /* user defined sort routine */ | |
1212 | IEXT HV * Isortstash; /* which is in some package or other */ | |
1213 | IEXT GV * Ifirstgv; /* $a */ | |
1214 | IEXT GV * Isecondgv; /* $b */ | |
1215 | IEXT AV * Isortstack; /* temp stack during pp_sort() */ | |
1216 | IEXT AV * Isignalstack; /* temp stack during sighandler() */ | |
1217 | IEXT SV * Imystrk; /* temp key string for do_each() */ | |
1218 | IEXT I32 Idumplvl; /* indentation level on syntax tree dump */ | |
79072805 LW |
1219 | IEXT PMOP * Ioldlastpm; /* for saving regexp context during debugger */ |
1220 | IEXT I32 Igensym; /* next symbol for getsym() to define */ | |
1221 | IEXT bool Ipreambled; | |
1222 | IEXT int Ilaststatval IINIT(-1); | |
1223 | IEXT I32 Ilaststype IINIT(OP_STAT); | |
1224 | ||
1225 | #undef IEXT | |
1226 | #undef IINIT | |
1227 | ||
1228 | #ifdef EMBEDDED | |
1229 | }; | |
1230 | #else | |
1231 | struct interpreter { | |
1232 | char broiled; | |
1233 | }; | |
1234 | #endif | |
1235 | ||
1236 | #include "pp.h" | |
1237 | ||
1238 | #ifdef __cplusplus | |
1239 | extern "C" { | |
1240 | #endif | |
1241 | ||
1242 | #include "proto.h" | |
1243 | ||
1244 | #ifdef __cplusplus | |
1245 | }; | |
1246 | #endif | |
1247 | ||
93a17b20 | 1248 | /* The following must follow proto.h */ |
79072805 LW |
1249 | |
1250 | #ifdef DOINIT | |
463ee0b2 LW |
1251 | MGVTBL vtbl_sv = {magic_get, |
1252 | magic_set, | |
1253 | magic_len, | |
1254 | 0, 0}; | |
1255 | MGVTBL vtbl_env = {0, 0, 0, 0, 0}; | |
1256 | MGVTBL vtbl_envelem = {0, magic_setenv, | |
1257 | 0, 0, 0}; | |
1258 | MGVTBL vtbl_sig = {0, 0, 0, 0, 0}; | |
1259 | MGVTBL vtbl_sigelem = {0, magic_setsig, | |
1260 | 0, 0, 0}; | |
1261 | MGVTBL vtbl_pack = {0, 0, | |
1262 | 0, 0, 0}; | |
1263 | MGVTBL vtbl_packelem = {magic_getpack, | |
1264 | magic_setpack, | |
1265 | 0, magic_clearpack, | |
1266 | 0}; | |
1267 | MGVTBL vtbl_dbline = {0, magic_setdbline, | |
1268 | 0, 0, 0}; | |
1269 | MGVTBL vtbl_isa = {0, magic_setisa, | |
1270 | 0, 0, 0}; | |
1271 | MGVTBL vtbl_isaelem = {0, magic_setisa, | |
1272 | 0, 0, 0}; | |
1273 | MGVTBL vtbl_arylen = {magic_getarylen, | |
1274 | magic_setarylen, | |
1275 | 0, 0, 0}; | |
1276 | MGVTBL vtbl_glob = {magic_getglob, | |
1277 | magic_setglob, | |
1278 | 0, 0, 0}; | |
1279 | MGVTBL vtbl_mglob = {0, magic_setmglob, | |
1280 | 0, 0, 0}; | |
1281 | MGVTBL vtbl_taint = {magic_gettaint,magic_settaint, | |
1282 | 0, 0, 0}; | |
1283 | MGVTBL vtbl_substr = {0, magic_setsubstr, | |
1284 | 0, 0, 0}; | |
1285 | MGVTBL vtbl_vec = {0, magic_setvec, | |
1286 | 0, 0, 0}; | |
1287 | MGVTBL vtbl_bm = {0, magic_setbm, | |
1288 | 0, 0, 0}; | |
1289 | MGVTBL vtbl_uvar = {magic_getuvar, | |
1290 | magic_setuvar, | |
1291 | 0, 0, 0}; | |
79072805 LW |
1292 | #else |
1293 | EXT MGVTBL vtbl_sv; | |
1294 | EXT MGVTBL vtbl_env; | |
1295 | EXT MGVTBL vtbl_envelem; | |
1296 | EXT MGVTBL vtbl_sig; | |
1297 | EXT MGVTBL vtbl_sigelem; | |
463ee0b2 LW |
1298 | EXT MGVTBL vtbl_pack; |
1299 | EXT MGVTBL vtbl_packelem; | |
79072805 | 1300 | EXT MGVTBL vtbl_dbline; |
463ee0b2 LW |
1301 | EXT MGVTBL vtbl_isa; |
1302 | EXT MGVTBL vtbl_isaelem; | |
79072805 LW |
1303 | EXT MGVTBL vtbl_arylen; |
1304 | EXT MGVTBL vtbl_glob; | |
93a17b20 | 1305 | EXT MGVTBL vtbl_mglob; |
463ee0b2 | 1306 | EXT MGVTBL vtbl_taint; |
79072805 LW |
1307 | EXT MGVTBL vtbl_substr; |
1308 | EXT MGVTBL vtbl_vec; | |
1309 | EXT MGVTBL vtbl_bm; | |
1310 | EXT MGVTBL vtbl_uvar; | |
1311 | #endif |