perl 5.002gamma: hints/sco.sh
[p5sagit/p5-mst-13.2.git] / perl.h
1 /*    perl.h
2  *
3  *    Copyright (c) 1987-1994, Larry Wall
4  *
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.
7  *
8  */
9 #ifndef H_PERL
10 #define H_PERL 1
11 #define OVERLOAD
12
13 #include "embed.h"
14
15 #define VOIDUSED 1
16 #include "config.h"
17
18 #ifndef BYTEORDER
19 #   define BYTEORDER 0x1234
20 #endif
21
22 /* Overall memory policy? */
23 #ifndef CONSERVATIVE
24 #   define LIBERAL 1
25 #endif
26
27 /*
28  * The following contortions are brought to you on behalf of all the
29  * standards, semi-standards, de facto standards, not-so-de-facto standards
30  * of the world, as well as all the other botches anyone ever thought of.
31  * The basic theory is that if we work hard enough here, the rest of the
32  * code can be a lot prettier.  Well, so much for theory.  Sorry, Henry...
33  */
34
35 /* define this once if either system, instead of cluttering up the src */
36 #if defined(MSDOS) || defined(atarist)
37 #define DOSISH 1
38 #endif
39
40 #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
41 # define STANDARD_C 1
42 #endif
43
44 #if defined(HASVOLATILE) || defined(STANDARD_C)
45 #   ifdef __cplusplus
46 #       define VOL              // to temporarily suppress warnings
47 #   else
48 #       define VOL volatile
49 #   endif
50 #else
51 #   define VOL
52 #endif
53
54 #define TAINT_IF(c)     (tainted |= (c))
55 #define TAINT_NOT       (tainted = 0)
56 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
57 #define TAINT_ENV()     if (tainting) taint_env()
58
59 #if defined(HAS_GETPGRP2) && defined(HAS_SETPGRP2)
60 #   define getpgrp getpgrp2
61 #   define setpgrp setpgrp2
62 #   ifndef HAS_GETPGRP
63 #       define HAS_GETPGRP
64 #   endif
65 #   ifndef HAS_SETPGRP
66 #       define HAS_SETPGRP
67 #   endif
68 #   ifndef USE_BSDPGRP
69 #       define USE_BSDPGRP
70 #   endif
71 #else
72 #   if defined(HAS_GETPGRP2) || defined(HAS_SETPGRP2)
73         #include "Gack, you have one but not both of getpgrp2() and setpgrp2()."
74 #   endif
75 #endif
76
77 #include <stdio.h>
78 #ifdef USE_NEXT_CTYPE
79 #include <appkit/NXCType.h>
80 #else
81 #include <ctype.h>
82 #endif
83
84 #ifdef I_LOCALE
85 #include <locale.h>
86 #endif
87
88 #ifdef METHOD   /* Defined by OSF/1 v3.0 by ctype.h */
89 #undef METHOD
90 #endif
91
92 #include <setjmp.h>
93
94 #ifdef I_SYS_PARAM
95 #   ifdef PARAM_NEEDS_TYPES
96 #       include <sys/types.h>
97 #   endif
98 #   include <sys/param.h>
99 #endif
100
101
102 /* Use all the "standard" definitions? */
103 #if defined(STANDARD_C) && defined(I_STDLIB)
104 #   include <stdlib.h>
105 #endif /* STANDARD_C */
106
107 /* Maybe this comes after <stdlib.h> so we don't try to change 
108    the standard library prototypes?.  We'll use our own in 
109    proto.h instead.  I guess.  The patch had no explanation.
110 */
111 #ifdef MYMALLOC
112 #   ifdef HIDEMYMALLOC
113 #       define malloc Mymalloc
114 #       define realloc Myremalloc
115 #       define free Myfree
116 #   endif
117 #   define safemalloc malloc
118 #   define saferealloc realloc
119 #   define safefree free
120 #endif
121
122 #define MEM_SIZE Size_t
123
124 #if defined(I_STRING) || defined(__cplusplus)
125 #   include <string.h>
126 #else
127 #   include <strings.h>
128 #endif
129
130 #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
131 #define strchr index
132 #define strrchr rindex
133 #endif
134
135 #if defined(mips) && defined(ultrix) && !defined(__STDC__)
136 #   undef HAS_MEMCMP
137 #endif
138
139 #ifdef I_MEMORY
140 #  include <memory.h>
141 #endif
142
143 #ifdef HAS_MEMCPY
144 #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
145 #    ifndef memcpy
146         extern char * memcpy _((char*, char*, int));
147 #    endif
148 #  endif
149 #else
150 #   ifndef memcpy
151 #       ifdef HAS_BCOPY
152 #           define memcpy(d,s,l) bcopy(s,d,l)
153 #       else
154 #           define memcpy(d,s,l) my_bcopy(s,d,l)
155 #       endif
156 #   endif
157 #endif /* HAS_MEMCPY */
158
159 #ifdef HAS_MEMSET
160 #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
161 #    ifndef memset
162         extern char *memset _((char*, int, int));
163 #    endif
164 #  endif
165 #  define memzero(d,l) memset(d,0,l)
166 #else
167 #   ifndef memzero
168 #       ifdef HAS_BZERO
169 #           define memzero(d,l) bzero(d,l)
170 #       else
171 #           define memzero(d,l) my_bzero(d,l)
172 #       endif
173 #   endif
174 #endif /* HAS_MEMSET */
175
176 #ifdef HAS_MEMCMP
177 #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
178 #    ifndef memcmp
179         extern int memcmp _((char*, char*, int));
180 #    endif
181 #  endif
182 #else
183 #   ifndef memcmp
184 #       define memcmp   my_memcmp
185 #   endif
186 #endif /* HAS_MEMCMP */
187
188 /* we prefer bcmp slightly for comparisons that don't care about ordering */
189 #ifndef HAS_BCMP
190 #   ifndef bcmp
191 #       define bcmp(s1,s2,l) memcmp(s1,s2,l)
192 #   endif
193 #endif /* HAS_BCMP */
194
195 #if !defined(HAS_MEMMOVE) && !defined(memmove)
196 #   if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
197 #       define memmove(d,s,l) bcopy(s,d,l)
198 #   else
199 #       if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
200 #           define memmove(d,s,l) memcpy(d,s,l)
201 #       else
202 #           define memmove(d,s,l) my_bcopy(s,d,l)
203 #       endif
204 #   endif
205 #endif
206
207 #ifndef _TYPES_         /* If types.h defines this it's easy. */
208 #   ifndef major                /* Does everyone's types.h define this? */
209 #       include <sys/types.h>
210 #   endif
211 #endif
212
213 #ifdef I_NETINET_IN
214 #   include <netinet/in.h>
215 #endif
216
217 #ifdef I_SYS_STAT
218 #include <sys/stat.h>
219 #endif
220
221 /* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
222    like UTekV) are broken, sometimes giving false positives.  Undefine
223    them here and let the code below set them to proper values.
224
225    The ghs macro stands for GreenHills Software C-1.8.5 which
226    is the C compiler for sysV88 and the various derivatives.
227    This header file bug is corrected in gcc-2.5.8 and later versions.
228    --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94.  */
229
230 #if defined(uts) || (defined(m88k) && defined(ghs))
231 #   undef S_ISDIR
232 #   undef S_ISCHR
233 #   undef S_ISBLK
234 #   undef S_ISREG
235 #   undef S_ISFIFO
236 #   undef S_ISLNK
237 #endif
238
239 #ifdef I_TIME
240 #   include <time.h>
241 #endif
242
243 #ifdef I_SYS_TIME
244 #   ifdef I_SYS_TIME_KERNEL
245 #       define KERNEL
246 #   endif
247 #   include <sys/time.h>
248 #   ifdef I_SYS_TIME_KERNEL
249 #       undef KERNEL
250 #   endif
251 #endif
252
253 #ifndef MSDOS
254 #  if defined(HAS_TIMES) && defined(I_SYS_TIMES)
255 #    include <sys/times.h>
256 #  endif
257 #endif
258
259 #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
260 #   undef HAS_STRERROR
261 #endif
262
263 #ifndef HAS_MKFIFO
264 #  ifndef mkfifo
265 #    define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
266 #  endif
267 #endif /* !HAS_MKFIFO */
268
269 #include <errno.h>
270 #ifdef HAS_SOCKET
271 #   ifdef I_NET_ERRNO
272 #     include <net/errno.h>
273 #   endif
274 #endif
275 #ifndef VMS
276 #   define FIXSTATUS(sts)  (U_L((sts) & 0xffff))
277 #   define SHIFTSTATUS(sts) ((sts) >> 8)
278 #   define SETERRNO(errcode,vmserrcode) errno = (errcode)
279 #else
280 #   define FIXSTATUS(sts)  (U_L(sts))
281 #   define SHIFTSTATUS(sts) (sts)
282 #   define SETERRNO(errcode,vmserrcode) {set_errno(errcode); set_vaxc_errno(vmserrcode);}
283 #endif
284
285 #ifndef MSDOS
286 #   ifndef errno
287         extern int errno;     /* ANSI allows errno to be an lvalue expr */
288 #   endif
289 #endif
290
291 #ifdef HAS_STRERROR
292 #       ifdef VMS
293         char *strerror _((int,...));
294 #       else
295         char *strerror _((int));
296 #       endif
297 #       ifndef Strerror
298 #           define Strerror strerror
299 #       endif
300 #else
301 #    ifdef HAS_SYS_ERRLIST
302         extern int sys_nerr;
303         extern char *sys_errlist[];
304 #       ifndef Strerror
305 #           define Strerror(e) \
306                 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
307 #       endif
308 #   endif
309 #endif
310
311 #ifdef I_SYS_IOCTL
312 #   ifndef _IOCTL_
313 #       include <sys/ioctl.h>
314 #   endif
315 #endif
316
317 #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
318 #   ifdef HAS_SOCKETPAIR
319 #       undef HAS_SOCKETPAIR
320 #   endif
321 #   ifdef I_NDBM
322 #       undef I_NDBM
323 #   endif
324 #endif
325
326 #if INTSIZE == 2
327 #   define htoni htons
328 #   define ntohi ntohs
329 #else
330 #   define htoni htonl
331 #   define ntohi ntohl
332 #endif
333
334 /* Configure already sets Direntry_t */
335 #if defined(I_DIRENT)
336 #   include <dirent.h>
337 #   if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
338 #       include <sys/dir.h>
339 #   endif
340 #else
341 #   ifdef I_SYS_NDIR
342 #       include <sys/ndir.h>
343 #   else
344 #       ifdef I_SYS_DIR
345 #           ifdef hp9000s500
346 #               include <ndir.h>        /* may be wrong in the future */
347 #           else
348 #               include <sys/dir.h>
349 #           endif
350 #       endif
351 #   endif
352 #endif
353
354 #ifdef FPUTS_BOTCH
355 /* work around botch in SunOS 4.0.1 and 4.0.2 */
356 #   ifndef fputs
357 #       define fputs(sv,fp) fprintf(fp,"%s",sv)
358 #   endif
359 #endif
360
361 /*
362  * The following gobbledygook brought to you on behalf of __STDC__.
363  * (I could just use #ifndef __STDC__, but this is more bulletproof
364  * in the face of half-implementations.)
365  */
366
367 #ifndef S_IFMT
368 #   ifdef _S_IFMT
369 #       define S_IFMT _S_IFMT
370 #   else
371 #       define S_IFMT 0170000
372 #   endif
373 #endif
374
375 #ifndef S_ISDIR
376 #   define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
377 #endif
378
379 #ifndef S_ISCHR
380 #   define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
381 #endif
382
383 #ifndef S_ISBLK
384 #   ifdef S_IFBLK
385 #       define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
386 #   else
387 #       define S_ISBLK(m) (0)
388 #   endif
389 #endif
390
391 #ifndef S_ISREG
392 #   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
393 #endif
394
395 #ifndef S_ISFIFO
396 #   ifdef S_IFIFO
397 #       define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
398 #   else
399 #       define S_ISFIFO(m) (0)
400 #   endif
401 #endif
402
403 #ifndef S_ISLNK
404 #   ifdef _S_ISLNK
405 #       define S_ISLNK(m) _S_ISLNK(m)
406 #   else
407 #       ifdef _S_IFLNK
408 #           define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
409 #       else
410 #           ifdef S_IFLNK
411 #               define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
412 #           else
413 #               define S_ISLNK(m) (0)
414 #           endif
415 #       endif
416 #   endif
417 #endif
418
419 #ifndef S_ISSOCK
420 #   ifdef _S_ISSOCK
421 #       define S_ISSOCK(m) _S_ISSOCK(m)
422 #   else
423 #       ifdef _S_IFSOCK
424 #           define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
425 #       else
426 #           ifdef S_IFSOCK
427 #               define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
428 #           else
429 #               define S_ISSOCK(m) (0)
430 #           endif
431 #       endif
432 #   endif
433 #endif
434
435 #ifndef S_IRUSR
436 #   ifdef S_IREAD
437 #       define S_IRUSR S_IREAD
438 #       define S_IWUSR S_IWRITE
439 #       define S_IXUSR S_IEXEC
440 #   else
441 #       define S_IRUSR 0400
442 #       define S_IWUSR 0200
443 #       define S_IXUSR 0100
444 #   endif
445 #   define S_IRGRP (S_IRUSR>>3)
446 #   define S_IWGRP (S_IWUSR>>3)
447 #   define S_IXGRP (S_IXUSR>>3)
448 #   define S_IROTH (S_IRUSR>>6)
449 #   define S_IWOTH (S_IWUSR>>6)
450 #   define S_IXOTH (S_IXUSR>>6)
451 #endif
452
453 #ifndef S_ISUID
454 #   define S_ISUID 04000
455 #endif
456
457 #ifndef S_ISGID
458 #   define S_ISGID 02000
459 #endif
460
461 #ifdef ff_next
462 #   undef ff_next
463 #endif
464
465 #if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
466 #   define SLOPPYDIVIDE
467 #endif
468
469 #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
470 #   define HAS_QUAD
471 #endif
472
473 #ifdef UV
474 #undef UV
475 #endif
476
477 #ifdef HAS_QUAD
478 #   ifdef cray
479 #       define Quad_t int
480 #   else
481 #       if defined(convex) || defined (uts)
482 #           define Quad_t long long
483 #       else
484 #           define Quad_t long
485 #       endif
486 #   endif
487     typedef Quad_t IV;
488     typedef unsigned Quad_t UV;
489 #else
490     typedef long IV;
491     typedef unsigned long UV;
492 #endif
493
494 typedef MEM_SIZE STRLEN;
495
496 typedef struct op OP;
497 typedef struct cop COP;
498 typedef struct unop UNOP;
499 typedef struct binop BINOP;
500 typedef struct listop LISTOP;
501 typedef struct logop LOGOP;
502 typedef struct condop CONDOP;
503 typedef struct pmop PMOP;
504 typedef struct svop SVOP;
505 typedef struct gvop GVOP;
506 typedef struct pvop PVOP;
507 typedef struct loop LOOP;
508
509 typedef struct Outrec Outrec;
510 typedef struct interpreter PerlInterpreter;
511 typedef struct ff FF;
512 typedef struct sv SV;
513 typedef struct av AV;
514 typedef struct hv HV;
515 typedef struct cv CV;
516 typedef struct regexp REGEXP;
517 typedef struct gp GP;
518 typedef struct sv GV;
519 typedef struct io IO;
520 typedef struct context CONTEXT;
521 typedef struct block BLOCK;
522
523 typedef struct magic MAGIC;
524 typedef struct xrv XRV;
525 typedef struct xpv XPV;
526 typedef struct xpviv XPVIV;
527 typedef struct xpvnv XPVNV;
528 typedef struct xpvmg XPVMG;
529 typedef struct xpvlv XPVLV;
530 typedef struct xpvav XPVAV;
531 typedef struct xpvhv XPVHV;
532 typedef struct xpvgv XPVGV;
533 typedef struct xpvcv XPVCV;
534 typedef struct xpvbm XPVBM;
535 typedef struct xpvfm XPVFM;
536 typedef struct xpvio XPVIO;
537 typedef struct mgvtbl MGVTBL;
538 typedef union any ANY;
539
540 #include "handy.h"
541
542 typedef I32 (*filter_t) _((int, SV *, int));
543 #define FILTER_READ(idx, sv, len)  filter_read(idx, sv, len)
544 #define FILTER_DATA(idx)           (AvARRAY(rsfp_filters)[idx])
545 #define FILTER_ISREADER(idx)       (idx >= AvFILL(rsfp_filters))
546
547 #ifdef DOSISH
548 # if defined(OS2)
549 #   include "os2ish.h"
550 # else
551 #   include "dosish.h"
552 # endif
553 #else
554 # if defined(VMS)
555 #   include "vmsish.h"
556 # else
557 #   include "unixish.h"
558 # endif
559 #endif
560
561 #ifndef HAS_PAUSE
562 #define pause() sleep((32767<<16)+32767)
563 #endif
564
565 #ifndef IOCPARM_LEN
566 #   ifdef IOCPARM_MASK
567         /* on BSDish systes we're safe */
568 #       define IOCPARM_LEN(x)  (((x) >> 16) & IOCPARM_MASK)
569 #   else
570         /* otherwise guess at what's safe */
571 #       define IOCPARM_LEN(x)   256
572 #   endif
573 #endif
574
575 union any {
576     void*       any_ptr;
577     I32         any_i32;
578     IV          any_iv;
579     long        any_long;
580     void        (*any_dptr) _((void*));
581 };
582
583 #include "regexp.h"
584 #include "sv.h"
585 #include "util.h"
586 #include "form.h"
587 #include "gv.h"
588 #include "cv.h"
589 #include "opcode.h"
590 #include "op.h"
591 #include "cop.h"
592 #include "av.h"
593 #include "hv.h"
594 #include "mg.h"
595 #include "scope.h"
596
597 /* work around some libPW problems */
598 #ifdef DOINIT
599 EXT char Error[1];
600 #endif
601
602 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
603 #   define I286
604 #endif
605
606 #if defined(htonl) && !defined(HAS_HTONL)
607 #define HAS_HTONL
608 #endif
609 #if defined(htons) && !defined(HAS_HTONS)
610 #define HAS_HTONS
611 #endif
612 #if defined(ntohl) && !defined(HAS_NTOHL)
613 #define HAS_NTOHL
614 #endif
615 #if defined(ntohs) && !defined(HAS_NTOHS)
616 #define HAS_NTOHS
617 #endif
618 #ifndef HAS_HTONL
619 #if (BYTEORDER & 0xffff) != 0x4321
620 #define HAS_HTONS
621 #define HAS_HTONL
622 #define HAS_NTOHS
623 #define HAS_NTOHL
624 #define MYSWAP
625 #define htons my_swap
626 #define htonl my_htonl
627 #define ntohs my_swap
628 #define ntohl my_ntohl
629 #endif
630 #else
631 #if (BYTEORDER & 0xffff) == 0x4321
632 #undef HAS_HTONS
633 #undef HAS_HTONL
634 #undef HAS_NTOHS
635 #undef HAS_NTOHL
636 #endif
637 #endif
638
639 /*
640  * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
641  * -DWS
642  */
643 #if BYTEORDER != 0x1234
644 # define HAS_VTOHL
645 # define HAS_VTOHS
646 # define HAS_HTOVL
647 # define HAS_HTOVS
648 # if BYTEORDER == 0x4321
649 #  define vtohl(x)      ((((x)&0xFF)<<24)       \
650                         +(((x)>>24)&0xFF)       \
651                         +(((x)&0x0000FF00)<<8)  \
652                         +(((x)&0x00FF0000)>>8)  )
653 #  define vtohs(x)      ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
654 #  define htovl(x)      vtohl(x)
655 #  define htovs(x)      vtohs(x)
656 # endif
657         /* otherwise default to functions in util.c */
658 #endif
659
660 #ifdef CASTNEGFLOAT
661 #define U_S(what) ((U16)(what))
662 #define U_I(what) ((unsigned int)(what))
663 #define U_L(what) ((U32)(what))
664 #else
665 U32 cast_ulong _((double));
666 #define U_S(what) ((U16)cast_ulong((double)(what)))
667 #define U_I(what) ((unsigned int)cast_ulong((double)(what)))
668 #define U_L(what) (cast_ulong((double)(what)))
669 #endif
670
671 #ifdef CASTI32
672 #define I_32(what) ((I32)(what))
673 #define I_V(what) ((IV)(what))
674 #define U_V(what) ((UV)(what))
675 #else
676 I32 cast_i32 _((double));
677 #define I_32(what) (cast_i32((double)(what)))
678 IV cast_iv _((double));
679 #define I_V(what) (cast_iv((double)(what)))
680 UV cast_uv _((double));
681 #define U_V(what) (cast_uv((double)(what)))
682 #endif
683
684 struct Outrec {
685     I32         o_lines;
686     char        *o_str;
687     U32         o_len;
688 };
689
690 #ifndef MAXSYSFD
691 #   define MAXSYSFD 2
692 #endif
693
694 #ifdef DOSISH
695 #define TMPPATH "plXXXXXX"
696 #else
697 #ifdef VMS
698 #define TMPPATH "sys$scratch:perl-eXXXXXX"
699 #else
700 #define TMPPATH "/tmp/perl-eXXXXXX"
701 #endif
702 #endif
703
704 #ifndef __cplusplus
705 Uid_t getuid _((void));
706 Uid_t geteuid _((void));
707 Gid_t getgid _((void));
708 Gid_t getegid _((void));
709 #endif
710
711 #ifdef DEBUGGING
712 #define YYDEBUG 1
713 #define DEB(a)                          a
714 #define DEBUG(a)   if (debug)           a
715 #define DEBUG_p(a) if (debug & 1)       a
716 #define DEBUG_s(a) if (debug & 2)       a
717 #define DEBUG_l(a) if (debug & 4)       a
718 #define DEBUG_t(a) if (debug & 8)       a
719 #define DEBUG_o(a) if (debug & 16)      a
720 #define DEBUG_c(a) if (debug & 32)      a
721 #define DEBUG_P(a) if (debug & 64)      a
722 #define DEBUG_m(a) if (debug & 128)     a
723 #define DEBUG_f(a) if (debug & 256)     a
724 #define DEBUG_r(a) if (debug & 512)     a
725 #define DEBUG_x(a) if (debug & 1024)    a
726 #define DEBUG_u(a) if (debug & 2048)    a
727 #define DEBUG_L(a) if (debug & 4096)    a
728 #define DEBUG_H(a) if (debug & 8192)    a
729 #define DEBUG_X(a) if (debug & 16384)   a
730 #define DEBUG_D(a) if (debug & 32768)   a
731 #else
732 #define DEB(a)
733 #define DEBUG(a)
734 #define DEBUG_p(a)
735 #define DEBUG_s(a)
736 #define DEBUG_l(a)
737 #define DEBUG_t(a)
738 #define DEBUG_o(a)
739 #define DEBUG_c(a)
740 #define DEBUG_P(a)
741 #define DEBUG_m(a)
742 #define DEBUG_f(a)
743 #define DEBUG_r(a)
744 #define DEBUG_x(a)
745 #define DEBUG_u(a)
746 #define DEBUG_L(a)
747 #define DEBUG_H(a)
748 #define DEBUG_X(a)
749 #define DEBUG_D(a)
750 #endif
751 #define YYMAXDEPTH 300
752
753 #define assert(what)    DEB( {                                          \
754         if (!(what)) {                                                  \
755             croak("Assertion failed: file \"%s\", line %d",             \
756                 __FILE__, __LINE__);                                    \
757             exit(1);                                                    \
758         }})
759
760 struct ufuncs {
761     I32 (*uf_val)_((IV, SV*));
762     I32 (*uf_set)_((IV, SV*));
763     IV uf_index;
764 };
765
766 /* Fix these up for __STDC__ */
767 #ifndef __cplusplus
768 char *mktemp _((char*));
769 double atof _((const char*));
770 #endif
771
772 #ifndef STANDARD_C
773 /* All of these are in stdlib.h or time.h for ANSI C */
774 Time_t time();
775 struct tm *gmtime(), *localtime();
776 char *strchr(), *strrchr();
777 char *strcpy(), *strcat();
778 #endif /* ! STANDARD_C */
779
780
781 #ifdef I_MATH
782 #    include <math.h>
783 #else
784 #   ifdef __cplusplus
785         extern "C" {
786 #   endif
787             double exp _((double));
788             double log _((double));
789             double sqrt _((double));
790             double modf _((double,double*));
791             double sin _((double));
792             double cos _((double));
793             double atan2 _((double,double));
794             double pow _((double,double));
795 #   ifdef __cplusplus
796         };
797 #   endif
798 #endif
799
800 #ifndef __cplusplus
801 char *crypt _((const char*, const char*));
802 char *getenv _((const char*));
803 Off_t lseek _((int,Off_t,int));
804 char *getlogin _((void));
805 #endif
806
807 #ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
808 #define UNLINK unlnk
809 I32 unlnk _((char*));
810 #else
811 #define UNLINK unlink
812 #endif
813
814 #ifndef HAS_SETREUID
815 #  ifdef HAS_SETRESUID
816 #    define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
817 #    define HAS_SETREUID
818 #  endif
819 #endif
820 #ifndef HAS_SETREGID
821 #  ifdef HAS_SETRESGID
822 #    define setregid(r,e) setresgid(r,e,(Gid_t)-1)
823 #    define HAS_SETREGID
824 #  endif
825 #endif
826
827 #define SCAN_DEF 0
828 #define SCAN_TR 1
829 #define SCAN_REPL 2
830
831 #ifdef DEBUGGING
832 # ifndef register
833 #  define register
834 # endif
835 # ifdef MYMALLOC
836 # define DEBUGGING_MSTATS
837 # endif
838 # define PAD_SV(po) pad_sv(po)
839 #else
840 # define PAD_SV(po) curpad[po]
841 #endif
842
843 /****************/
844 /* Truly global */
845 /****************/
846
847 /* global state */
848 EXT PerlInterpreter *   curinterp;      /* currently running interpreter */
849 #ifndef VMS  /* VMS doesn't use environ array */
850 extern char **  environ;        /* environment variables supplied via exec */
851 #endif
852 EXT int         uid;            /* current real user id */
853 EXT int         euid;           /* current effective user id */
854 EXT int         gid;            /* current real group id */
855 EXT int         egid;           /* current effective group id */
856 EXT bool        nomemok;        /* let malloc context handle nomem */
857 EXT U32         an;             /* malloc sequence number */
858 EXT U32         cop_seqmax;     /* statement sequence number */
859 EXT U16         op_seqmax;      /* op sequence number */
860 EXT U32         evalseq;        /* eval sequence number */
861 EXT U32         sub_generation; /* inc to force methods to be looked up again */
862 EXT char **     origenviron;
863 EXT U32         origalen;
864 EXT U32 *       profiledata;
865 EXT int         maxo INIT(MAXO);/* Number of ops */
866
867 EXT XPV*        xiv_arenaroot;  /* list of allocated xiv areas */
868 EXT IV **       xiv_root;       /* free xiv list--shared by interpreters */
869 EXT double *    xnv_root;       /* free xnv list--shared by interpreters */
870 EXT XRV *       xrv_root;       /* free xrv list--shared by interpreters */
871 EXT XPV *       xpv_root;       /* free xpv list--shared by interpreters */
872 EXT HE *        he_root;        /* free he list--shared by interpreters */
873 EXT char *      nice_chunk;     /* a nice chunk of memory to reuse */
874 EXT U32         nice_chunk_size;/* how nice the chunk of memory is */
875
876 /* Stack for currently executing thread--context switch must handle this.     */
877 EXT SV **       stack_base;     /* stack->array_ary */
878 EXT SV **       stack_sp;       /* stack pointer now */
879 EXT SV **       stack_max;      /* stack->array_ary + stack->array_max */
880
881 /* likewise for these */
882
883 EXT OP *        op;             /* current op--oughta be in a global register */
884
885 EXT I32 *       scopestack;     /* blocks we've entered */
886 EXT I32         scopestack_ix;
887 EXT I32         scopestack_max;
888
889 EXT ANY*        savestack;      /* to save non-local values on */
890 EXT I32         savestack_ix;
891 EXT I32         savestack_max;
892
893 EXT OP **       retstack;       /* returns we've pushed */
894 EXT I32         retstack_ix;
895 EXT I32         retstack_max;
896
897 EXT I32 *       markstack;      /* stackmarks we're remembering */
898 EXT I32 *       markstack_ptr;  /* stackmarks we're remembering */
899 EXT I32 *       markstack_max;  /* stackmarks we're remembering */
900
901 EXT SV **       curpad;
902
903 /* temp space */
904 EXT SV *        Sv;
905 EXT XPV *       Xpv;
906 EXT char        buf[1024];
907 EXT char        tokenbuf[256];
908 EXT struct stat statbuf;
909 #ifdef HAS_TIMES
910 EXT struct tms  timesbuf;
911 #endif
912 EXT STRLEN na;          /* for use in SvPV when length is Not Applicable */
913
914 /* for tmp use in stupid debuggers */
915 EXT int *       di;
916 EXT short *     ds;
917 EXT char *      dc;
918
919 /* handy constants */
920 EXT char *      Yes INIT("1");
921 EXT char *      No INIT("");
922 EXT char *      hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
923 EXT char *      patleave INIT("\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}");
924 EXT char *      vert INIT("|");
925
926 EXT char        warn_uninit[]
927   INIT("Use of uninitialized value");
928 EXT char        warn_nosemi[]
929   INIT("Semicolon seems to be missing");
930 EXT char        warn_reserved[]
931   INIT("Unquoted string \"%s\" may clash with future reserved word");
932 EXT char        warn_nl[]
933   INIT("Unsuccessful %s on filename containing newline");
934 EXT char        no_wrongref[]
935   INIT("Can't use %s ref as %s ref");
936 EXT char        no_symref[]
937   INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
938 EXT char        no_usym[]
939   INIT("Can't use an undefined value as %s reference");
940 EXT char        no_aelem[]
941   INIT("Modification of non-creatable array value attempted, subscript %d");
942 EXT char        no_helem[]
943   INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
944 EXT char        no_modify[]
945   INIT("Modification of a read-only value attempted");
946 EXT char        no_mem[]
947   INIT("Out of memory!\n");
948 EXT char        no_security[]
949   INIT("Insecure dependency in %s%s");
950 EXT char        no_sock_func[]
951   INIT("Unsupported socket function \"%s\" called");
952 EXT char        no_dir_func[]
953   INIT("Unsupported directory function \"%s\" called");
954 EXT char        no_func[]
955   INIT("The %s function is unimplemented");
956 EXT char        no_myglob[]
957   INIT("\"my\" variable %s can't be in a package");
958
959 EXT SV          sv_undef;
960 EXT SV          sv_no;
961 EXT SV          sv_yes;
962 #ifdef CSH
963     EXT char *  cshname INIT(CSH);
964     EXT I32     cshlen;
965 #endif
966
967 #ifdef DOINIT
968 EXT char *sig_name[] = { SIG_NAME };
969 EXT int   sig_num[]  = { SIG_NUM };
970 #else
971 EXT char *sig_name[];
972 EXT int   sig_num[];
973 #endif
974
975 #ifdef DOINIT
976 EXT unsigned char fold[] = {    /* fast case folding table */
977         0,      1,      2,      3,      4,      5,      6,      7,
978         8,      9,      10,     11,     12,     13,     14,     15,
979         16,     17,     18,     19,     20,     21,     22,     23,
980         24,     25,     26,     27,     28,     29,     30,     31,
981         32,     33,     34,     35,     36,     37,     38,     39,
982         40,     41,     42,     43,     44,     45,     46,     47,
983         48,     49,     50,     51,     52,     53,     54,     55,
984         56,     57,     58,     59,     60,     61,     62,     63,
985         64,     'a',    'b',    'c',    'd',    'e',    'f',    'g',
986         'h',    'i',    'j',    'k',    'l',    'm',    'n',    'o',
987         'p',    'q',    'r',    's',    't',    'u',    'v',    'w',
988         'x',    'y',    'z',    91,     92,     93,     94,     95,
989         96,     'A',    'B',    'C',    'D',    'E',    'F',    'G',
990         'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
991         'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
992         'X',    'Y',    'Z',    123,    124,    125,    126,    127,
993         128,    129,    130,    131,    132,    133,    134,    135,
994         136,    137,    138,    139,    140,    141,    142,    143,
995         144,    145,    146,    147,    148,    149,    150,    151,
996         152,    153,    154,    155,    156,    157,    158,    159,
997         160,    161,    162,    163,    164,    165,    166,    167,
998         168,    169,    170,    171,    172,    173,    174,    175,
999         176,    177,    178,    179,    180,    181,    182,    183,
1000         184,    185,    186,    187,    188,    189,    190,    191,
1001         192,    193,    194,    195,    196,    197,    198,    199,
1002         200,    201,    202,    203,    204,    205,    206,    207,
1003         208,    209,    210,    211,    212,    213,    214,    215,
1004         216,    217,    218,    219,    220,    221,    222,    223,    
1005         224,    225,    226,    227,    228,    229,    230,    231,
1006         232,    233,    234,    235,    236,    237,    238,    239,
1007         240,    241,    242,    243,    244,    245,    246,    247,
1008         248,    249,    250,    251,    252,    253,    254,    255
1009 };
1010 #else
1011 EXT unsigned char fold[];
1012 #endif
1013
1014 #ifdef DOINIT
1015 EXT unsigned char freq[] = {    /* letter frequencies for mixed English/C */
1016         1,      2,      84,     151,    154,    155,    156,    157,
1017         165,    246,    250,    3,      158,    7,      18,     29,
1018         40,     51,     62,     73,     85,     96,     107,    118,
1019         129,    140,    147,    148,    149,    150,    152,    153,
1020         255,    182,    224,    205,    174,    176,    180,    217,
1021         233,    232,    236,    187,    235,    228,    234,    226,
1022         222,    219,    211,    195,    188,    193,    185,    184,
1023         191,    183,    201,    229,    181,    220,    194,    162,
1024         163,    208,    186,    202,    200,    218,    198,    179,
1025         178,    214,    166,    170,    207,    199,    209,    206,
1026         204,    160,    212,    216,    215,    192,    175,    173,
1027         243,    172,    161,    190,    203,    189,    164,    230,
1028         167,    248,    227,    244,    242,    255,    241,    231,
1029         240,    253,    169,    210,    245,    237,    249,    247,
1030         239,    168,    252,    251,    254,    238,    223,    221,
1031         213,    225,    177,    197,    171,    196,    159,    4,
1032         5,      6,      8,      9,      10,     11,     12,     13,
1033         14,     15,     16,     17,     19,     20,     21,     22,
1034         23,     24,     25,     26,     27,     28,     30,     31,
1035         32,     33,     34,     35,     36,     37,     38,     39,
1036         41,     42,     43,     44,     45,     46,     47,     48,
1037         49,     50,     52,     53,     54,     55,     56,     57,
1038         58,     59,     60,     61,     63,     64,     65,     66,
1039         67,     68,     69,     70,     71,     72,     74,     75,
1040         76,     77,     78,     79,     80,     81,     82,     83,
1041         86,     87,     88,     89,     90,     91,     92,     93,
1042         94,     95,     97,     98,     99,     100,    101,    102,
1043         103,    104,    105,    106,    108,    109,    110,    111,
1044         112,    113,    114,    115,    116,    117,    119,    120,
1045         121,    122,    123,    124,    125,    126,    127,    128,
1046         130,    131,    132,    133,    134,    135,    136,    137,
1047         138,    139,    141,    142,    143,    144,    145,    146
1048 };
1049 #else
1050 EXT unsigned char freq[];
1051 #endif
1052
1053 #ifdef DEBUGGING
1054 #ifdef DOINIT
1055 EXT char* block_type[] = {
1056         "NULL",
1057         "SUB",
1058         "EVAL",
1059         "LOOP",
1060         "SUBST",
1061         "BLOCK",
1062 };
1063 #else
1064 EXT char* block_type[];
1065 #endif
1066 #endif
1067
1068 /*****************************************************************************/
1069 /* This lexer/parser stuff is currently global since yacc is hard to reenter */
1070 /*****************************************************************************/
1071 /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
1072
1073 #include "perly.h"
1074
1075 typedef enum {
1076     XOPERATOR,
1077     XTERM,
1078     XREF,
1079     XSTATE,
1080     XBLOCK,
1081     XTERMBLOCK
1082 } expectation;
1083
1084 EXT U32         lex_state;      /* next token is determined */
1085 EXT U32         lex_defer;      /* state after determined token */
1086 EXT expectation lex_expect;     /* expect after determined token */
1087 EXT I32         lex_brackets;   /* bracket count */
1088 EXT I32         lex_formbrack;  /* bracket count at outer format level */
1089 EXT I32         lex_fakebrack;  /* outer bracket is mere delimiter */
1090 EXT I32         lex_casemods;   /* casemod count */
1091 EXT I32         lex_dojoin;     /* doing an array interpolation */
1092 EXT I32         lex_starts;     /* how many interps done on level */
1093 EXT SV *        lex_stuff;      /* runtime pattern from m// or s/// */
1094 EXT SV *        lex_repl;       /* runtime replacement from s/// */
1095 EXT OP *        lex_op;         /* extra info to pass back on op */
1096 EXT OP *        lex_inpat;      /* in pattern $) and $| are special */
1097 EXT I32         lex_inwhat;     /* what kind of quoting are we in */
1098 EXT char *      lex_brackstack; /* what kind of brackets to pop */
1099 EXT char *      lex_casestack;  /* what kind of case mods in effect */
1100
1101 /* What we know when we're in LEX_KNOWNEXT state. */
1102 EXT YYSTYPE     nextval[5];     /* value of next token, if any */
1103 EXT I32         nexttype[5];    /* type of next token */
1104 EXT I32         nexttoke;
1105
1106 EXT FILE * VOL  rsfp INIT(Nullfp);
1107 EXT SV *        linestr;
1108 EXT char *      bufptr;
1109 EXT char *      oldbufptr;
1110 EXT char *      oldoldbufptr;
1111 EXT char *      bufend;
1112 EXT expectation expect INIT(XSTATE);    /* how to interpret ambiguous tokens */
1113 EXT AV *        rsfp_filters;
1114
1115 EXT I32         multi_start;    /* 1st line of multi-line string */
1116 EXT I32         multi_end;      /* last line of multi-line string */
1117 EXT I32         multi_open;     /* delimiter of said string */
1118 EXT I32         multi_close;    /* delimiter of said string */
1119
1120 EXT GV *        scrgv;
1121 EXT I32         error_count;    /* how many errors so far, max 10 */
1122 EXT I32         subline;        /* line this subroutine began on */
1123 EXT SV *        subname;        /* name of current subroutine */
1124
1125 EXT CV *        compcv;         /* currently compiling subroutine */
1126 EXT AV *        comppad;        /* storage for lexically scoped temporaries */
1127 EXT AV *        comppad_name;   /* variable names for "my" variables */
1128 EXT I32         comppad_name_fill;/* last "introduced" variable offset */
1129 EXT I32         min_intro_pending;/* start of vars to introduce */
1130 EXT I32         max_intro_pending;/* end of vars to introduce */
1131 EXT I32         padix;          /* max used index in current "register" pad */
1132 EXT I32         padix_floor;    /* how low may inner block reset padix */
1133 EXT I32         pad_reset_pending; /* reset pad on next attempted alloc */
1134 EXT COP         compiling;
1135
1136 EXT I32         thisexpr;       /* name id for nothing_in_common() */
1137 EXT char *      last_uni;       /* position of last named-unary operator */
1138 EXT char *      last_lop;       /* position of last list operator */
1139 EXT OPCODE      last_lop_op;    /* last list operator */
1140 EXT bool        in_my;          /* we're compiling a "my" declaration */
1141 #ifdef FCRYPT
1142 EXT I32         cryptseen;      /* has fast crypt() been initialized? */
1143 #endif
1144
1145 EXT U32         hints;          /* various compilation flags */
1146
1147                                 /* Note: the lowest 8 bits are reserved for
1148                                    stuffing into op->op_private */
1149 #define HINT_INTEGER            0x00000001
1150 #define HINT_STRICT_REFS        0x00000002
1151
1152 #define HINT_BLOCK_SCOPE        0x00000100
1153 #define HINT_STRICT_SUBS        0x00000200
1154 #define HINT_STRICT_VARS        0x00000400
1155
1156 /**************************************************************************/
1157 /* This regexp stuff is global since it always happens within 1 expr eval */
1158 /**************************************************************************/
1159
1160 EXT char *      regprecomp;     /* uncompiled string. */
1161 EXT char *      regparse;       /* Input-scan pointer. */
1162 EXT char *      regxend;        /* End of input for compile */
1163 EXT I32         regnpar;        /* () count. */
1164 EXT char *      regcode;        /* Code-emit pointer; &regdummy = don't. */
1165 EXT I32         regsize;        /* Code size. */
1166 EXT I32         regnaughty;     /* How bad is this pattern? */
1167 EXT I32         regsawback;     /* Did we see \1, ...? */
1168
1169 EXT char *      reginput;       /* String-input pointer. */
1170 EXT char *      regbol;         /* Beginning of input, for ^ check. */
1171 EXT char *      regeol;         /* End of input, for $ check. */
1172 EXT char **     regstartp;      /* Pointer to startp array. */
1173 EXT char **     regendp;        /* Ditto for endp. */
1174 EXT U32 *       reglastparen;   /* Similarly for lastparen. */
1175 EXT char *      regtill;        /* How far we are required to go. */
1176 EXT U16         regflags;       /* are we folding, multilining? */
1177 EXT char        regprev;        /* char before regbol, \n if none */
1178
1179 /***********************************************/
1180 /* Global only to current interpreter instance */
1181 /***********************************************/
1182
1183 #ifdef MULTIPLICITY
1184 #define IEXT
1185 #define IINIT(x)
1186 struct interpreter {
1187 #else
1188 #define IEXT EXT
1189 #define IINIT(x) INIT(x)
1190 #endif
1191
1192 /* pseudo environmental stuff */
1193 IEXT int        Iorigargc;
1194 IEXT char **    Iorigargv;
1195 IEXT GV *       Ienvgv;
1196 IEXT GV *       Isiggv;
1197 IEXT GV *       Iincgv;
1198 IEXT char *     Iorigfilename;
1199 IEXT SV *       Idiehook;
1200 IEXT SV *       Iwarnhook;
1201 IEXT SV *       Iparsehook;
1202
1203 /* Various states of an input record separator SV (rs, nrs) */
1204 #define RsSNARF(sv)   (! SvOK(sv))
1205 #define RsSIMPLE(sv)  (SvOK(sv) && SvCUR(sv))
1206 #define RsPARA(sv)    (SvOK(sv) && ! SvCUR(sv))
1207
1208 /* switches */
1209 IEXT char *     Icddir;
1210 IEXT bool       Iminus_c;
1211 IEXT char       Ipatchlevel[6];
1212 IEXT SV *       Inrs;
1213 IEXT char *     Isplitstr IINIT(" ");
1214 IEXT bool       Ipreprocess;
1215 IEXT bool       Iminus_n;
1216 IEXT bool       Iminus_p;
1217 IEXT bool       Iminus_l;
1218 IEXT bool       Iminus_a;
1219 IEXT bool       Iminus_F;
1220 IEXT bool       Idoswitches;
1221 IEXT bool       Idowarn;
1222 IEXT bool       Idoextract;
1223 IEXT bool       Isawampersand;  /* must save all match strings */
1224 IEXT bool       Isawstudy;      /* do fbm_instr on all strings */
1225 IEXT bool       Isawi;          /* study must assume case insensitive */
1226 IEXT bool       Isawvec;
1227 IEXT bool       Iunsafe;
1228 IEXT bool       Ido_undump;             /* -u or dump seen? */
1229 IEXT char *     Iinplace;
1230 IEXT char *     Ie_tmpname;
1231 IEXT FILE *     Ie_fp;
1232 IEXT VOL U32    Idebug;
1233 IEXT U32        Iperldb;
1234         /* This value may be raised by extensions for testing purposes */
1235 IEXT int        Iperl_destruct_level;   /* 0=none, 1=full, 2=full with checks */
1236
1237 /* magical thingies */
1238 IEXT Time_t     Ibasetime;              /* $^T */
1239 IEXT SV *       Iformfeed;              /* $^L */
1240 IEXT char *     Ichopset IINIT(" \n-"); /* $: */
1241 IEXT SV *       Irs;                    /* $/ */
1242 IEXT char *     Iofs;                   /* $, */
1243 IEXT STRLEN     Iofslen;
1244 IEXT char *     Iors;                   /* $\ */
1245 IEXT STRLEN     Iorslen;
1246 IEXT char *     Iofmt;                  /* $# */
1247 IEXT I32        Imaxsysfd IINIT(MAXSYSFD); /* top fd to pass to subprocesses */
1248 IEXT int        Imultiline;       /* $*--do strings hold >1 line? */
1249 IEXT U32        Istatusvalue;   /* $? */
1250
1251 IEXT struct stat Istatcache;            /* _ */
1252 IEXT GV *       Istatgv;
1253 IEXT SV *       Istatname IINIT(Nullsv);
1254
1255 /* shortcuts to various I/O objects */
1256 IEXT GV *       Istdingv;
1257 IEXT GV *       Ilast_in_gv;
1258 IEXT GV *       Idefgv;
1259 IEXT GV *       Iargvgv;
1260 IEXT GV *       Idefoutgv;
1261 IEXT GV *       Iargvoutgv;
1262
1263 /* shortcuts to regexp stuff */
1264 IEXT GV *       Ileftgv;
1265 IEXT GV *       Iampergv;
1266 IEXT GV *       Irightgv;
1267 IEXT PMOP *     Icurpm;         /* what to do \ interps from */
1268 IEXT I32 *      Iscreamfirst;
1269 IEXT I32 *      Iscreamnext;
1270 IEXT I32        Imaxscream IINIT(-1);
1271 IEXT SV *       Ilastscream;
1272
1273 /* shortcuts to misc objects */
1274 IEXT GV *       Ierrgv;
1275
1276 /* shortcuts to debugging objects */
1277 IEXT GV *       IDBgv;
1278 IEXT GV *       IDBline;
1279 IEXT GV *       IDBsub;
1280 IEXT SV *       IDBsingle;
1281 IEXT SV *       IDBtrace;
1282 IEXT SV *       IDBsignal;
1283 IEXT AV *       Ilineary;       /* lines of script for debugger */
1284 IEXT AV *       Idbargs;        /* args to call listed by caller function */
1285
1286 /* symbol tables */
1287 IEXT HV *       Idefstash;      /* main symbol table */
1288 IEXT HV *       Icurstash;      /* symbol table for current package */
1289 IEXT HV *       Idebstash;      /* symbol table for perldb package */
1290 IEXT SV *       Icurstname;     /* name of current package */
1291 IEXT AV *       Ibeginav;       /* names of BEGIN subroutines */
1292 IEXT AV *       Iendav;         /* names of END subroutines */
1293 IEXT AV *       Ipad;           /* storage for lexically scoped temporaries */
1294 IEXT AV *       Ipadname;       /* variable names for "my" variables */
1295
1296 /* memory management */
1297 IEXT SV **      Itmps_stack;
1298 IEXT I32        Itmps_ix IINIT(-1);
1299 IEXT I32        Itmps_floor IINIT(-1);
1300 IEXT I32        Itmps_max;
1301 IEXT I32        Isv_count;      /* how many SV* are currently allocated */
1302 IEXT I32        Isv_objcount;   /* how many objects are currently allocated */
1303 IEXT SV*        Isv_root;       /* storage for SVs belonging to interp */
1304 IEXT SV*        Isv_arenaroot;  /* list of areas for garbage collection */
1305
1306 /* funky return mechanisms */
1307 IEXT I32        Ilastspbase;
1308 IEXT I32        Ilastsize;
1309 IEXT int        Iforkprocess;   /* so do_open |- can return proc# */
1310
1311 /* subprocess state */
1312 IEXT AV *       Ifdpid;         /* keep fd-to-pid mappings for my_popen */
1313 IEXT HV *       Ipidstatus;     /* keep pid-to-status mappings for waitpid */
1314
1315 /* internal state */
1316 IEXT VOL int    Iin_eval;       /* trap "fatal" errors? */
1317 IEXT OP *       Irestartop;     /* Are we propagating an error from croak? */
1318 IEXT int        Idelaymagic;    /* ($<,$>) = ... */
1319 IEXT bool       Idirty;         /* In the middle of tearing things down? */
1320 IEXT U8         Ilocalizing;    /* are we processing a local() list? */
1321 IEXT bool       Itainted;       /* using variables controlled by $< */
1322 IEXT bool       Itainting;      /* doing taint checks */
1323 IEXT char *     Iop_mask IINIT(NULL);   /* masked operations for safe evals */
1324
1325 /* trace state */
1326 IEXT I32        Idlevel;
1327 IEXT I32        Idlmax IINIT(128);
1328 IEXT char *     Idebname;
1329 IEXT char *     Idebdelim;
1330
1331 /* current interpreter roots */
1332 IEXT CV *       Imain_cv;
1333 IEXT OP *       Imain_root;
1334 IEXT OP *       Imain_start;
1335 IEXT OP *       Ieval_root;
1336 IEXT OP *       Ieval_start;
1337
1338 /* runtime control stuff */
1339 IEXT COP * VOL  Icurcop IINIT(&compiling);
1340 IEXT line_t     Icopline IINIT(NOLINE);
1341 IEXT CONTEXT *  Icxstack;
1342 IEXT I32        Icxstack_ix IINIT(-1);
1343 IEXT I32        Icxstack_max IINIT(128);
1344 IEXT jmp_buf    Itop_env;
1345 IEXT I32        Irunlevel;
1346
1347 /* stack stuff */
1348 IEXT AV *       Istack;         /* THE STACK */
1349 IEXT AV *       Imainstack;     /* the stack when nothing funny is happening */
1350 IEXT SV **      Imystack_base;  /* stack->array_ary */
1351 IEXT SV **      Imystack_sp;    /* stack pointer now */
1352 IEXT SV **      Imystack_max;   /* stack->array_ary + stack->array_max */
1353
1354 /* format accumulators */
1355 IEXT SV *       Iformtarget;
1356 IEXT SV *       Ibodytarget;
1357 IEXT SV *       Itoptarget;
1358
1359 /* statics moved here for shared library purposes */
1360 IEXT SV         Istrchop;       /* return value from chop */
1361 IEXT int        Ifilemode;      /* so nextargv() can preserve mode */
1362 IEXT int        Ilastfd;        /* what to preserve mode on */
1363 IEXT char *     Ioldname;       /* what to preserve mode on */
1364 IEXT char **    IArgv;          /* stuff to free from do_aexec, vfork safe */
1365 IEXT char *     ICmd;           /* stuff to free from do_aexec, vfork safe */
1366 IEXT OP *       Isortcop;       /* user defined sort routine */
1367 IEXT HV *       Isortstash;     /* which is in some package or other */
1368 IEXT GV *       Ifirstgv;       /* $a */
1369 IEXT GV *       Isecondgv;      /* $b */
1370 IEXT AV *       Isortstack;     /* temp stack during pp_sort() */
1371 IEXT AV *       Isignalstack;   /* temp stack during sighandler() */
1372 IEXT SV *       Imystrk;        /* temp key string for do_each() */
1373 IEXT I32        Idumplvl;       /* indentation level on syntax tree dump */
1374 IEXT PMOP *     Ioldlastpm;     /* for saving regexp context during debugger */
1375 IEXT I32        Igensym;        /* next symbol for getsym() to define */
1376 IEXT bool       Ipreambled;
1377 IEXT AV *       Ipreambleav;
1378 IEXT int        Ilaststatval IINIT(-1);
1379 IEXT I32        Ilaststype IINIT(OP_STAT);
1380
1381 #undef IEXT
1382 #undef IINIT
1383
1384 #ifdef MULTIPLICITY
1385 };
1386 #else
1387 struct interpreter {
1388     char broiled;
1389 };
1390 #endif
1391
1392 #include "pp.h"
1393
1394 #ifdef __cplusplus
1395 extern "C" {
1396 #endif
1397
1398 #ifdef __cplusplus
1399 #  ifndef I_STDARG
1400 #    define I_STDARG 1
1401 #  endif
1402 #endif
1403
1404 #ifdef I_STDARG
1405 #  include <stdarg.h>
1406 #else
1407 #  ifdef I_VARARGS
1408 #    include <varargs.h>
1409 #  endif
1410 #endif
1411
1412 #include "proto.h"
1413
1414 #ifdef EMBED
1415 #define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
1416 #define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
1417 #else
1418 #define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
1419 #define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
1420 #endif
1421
1422 #ifdef __cplusplus
1423 };
1424 #endif
1425
1426 /* The following must follow proto.h */
1427
1428 #ifdef DOINIT
1429 EXT MGVTBL vtbl_sv =    {magic_get,
1430                                 magic_set,
1431                                         magic_len,
1432                                                 0,      0};
1433 EXT MGVTBL vtbl_env =   {0,     0,      0,      0,      0};
1434 EXT MGVTBL vtbl_envelem =       {0,     magic_setenv,
1435                                         0,      magic_clearenv,
1436                                                         0};
1437 EXT MGVTBL vtbl_sig =   {0,     0,               0, 0, 0};
1438 EXT MGVTBL vtbl_sigelem =       {0,     magic_setsig,
1439                                         0,      0,      0};
1440 EXT MGVTBL vtbl_pack =  {0,     0,      0,      magic_wipepack,
1441                                                         0};
1442 EXT MGVTBL vtbl_packelem =      {magic_getpack,
1443                                 magic_setpack,
1444                                         0,      magic_clearpack,
1445                                                         0};
1446 EXT MGVTBL vtbl_dbline =        {0,     magic_setdbline,
1447                                         0,      0,      0};
1448 EXT MGVTBL vtbl_isa =   {0,     magic_setisa,
1449                                         0,      0,      0};
1450 EXT MGVTBL vtbl_isaelem =       {0,     magic_setisa,
1451                                         0,      0,      0};
1452 EXT MGVTBL vtbl_arylen =        {magic_getarylen,
1453                                 magic_setarylen,
1454                                         0,      0,      0};
1455 EXT MGVTBL vtbl_glob =  {magic_getglob,
1456                                 magic_setglob,
1457                                         0,      0,      0};
1458 EXT MGVTBL vtbl_mglob = {0,     magic_setmglob,
1459                                         0,      0,      0};
1460 EXT MGVTBL vtbl_taint = {magic_gettaint,magic_settaint,
1461                                         0,      0,      0};
1462 EXT MGVTBL vtbl_substr =        {0,     magic_setsubstr,
1463                                         0,      0,      0};
1464 EXT MGVTBL vtbl_vec =   {0,     magic_setvec,
1465                                         0,      0,      0};
1466 EXT MGVTBL vtbl_pos =   {magic_getpos,
1467                                 magic_setpos,
1468                                         0,      0,      0};
1469 EXT MGVTBL vtbl_bm =    {0,     magic_setbm,
1470                                         0,      0,      0};
1471 EXT MGVTBL vtbl_uvar =  {magic_getuvar,
1472                                 magic_setuvar,
1473                                         0,      0,      0};
1474
1475 #ifdef OVERLOAD
1476 EXT MGVTBL vtbl_amagic =       {0,     magic_setamagic,
1477                                         0,      0,      magic_setamagic};
1478 EXT MGVTBL vtbl_amagicelem =   {0,     magic_setamagic,
1479                                         0,      0,      magic_setamagic};
1480 #endif /* OVERLOAD */
1481
1482 #else
1483 EXT MGVTBL vtbl_sv;
1484 EXT MGVTBL vtbl_env;
1485 EXT MGVTBL vtbl_envelem;
1486 EXT MGVTBL vtbl_sig;
1487 EXT MGVTBL vtbl_sigelem;
1488 EXT MGVTBL vtbl_pack;
1489 EXT MGVTBL vtbl_packelem;
1490 EXT MGVTBL vtbl_dbline;
1491 EXT MGVTBL vtbl_isa;
1492 EXT MGVTBL vtbl_isaelem;
1493 EXT MGVTBL vtbl_arylen;
1494 EXT MGVTBL vtbl_glob;
1495 EXT MGVTBL vtbl_mglob;
1496 EXT MGVTBL vtbl_taint;
1497 EXT MGVTBL vtbl_substr;
1498 EXT MGVTBL vtbl_vec;
1499 EXT MGVTBL vtbl_pos;
1500 EXT MGVTBL vtbl_bm;
1501 EXT MGVTBL vtbl_uvar;
1502
1503 #ifdef OVERLOAD
1504 EXT MGVTBL vtbl_amagic;
1505 EXT MGVTBL vtbl_amagicelem;
1506 #endif /* OVERLOAD */
1507
1508 #endif
1509
1510 #ifdef OVERLOAD
1511 EXT long amagic_generation;
1512
1513 #define NofAMmeth 29
1514 #ifdef DOINIT
1515 EXT char * AMG_names[NofAMmeth][2] = {
1516   {"fallback","abs"},
1517   {"bool", "nomethod"},
1518   {"\"\"", "0+"},
1519   {"+","+="},
1520   {"-","-="},
1521   {"*", "*="},
1522   {"/", "/="},
1523   {"%", "%="},
1524   {"**", "**="},
1525   {"<<", "<<="},
1526   {">>", ">>="},
1527   {"&", "&="},
1528   {"|", "|="},
1529   {"^", "^="},
1530   {"<", "<="},
1531   {">", ">="},
1532   {"==", "!="},
1533   {"<=>", "cmp"},
1534   {"lt", "le"},
1535   {"gt", "ge"},
1536   {"eq", "ne"},
1537   {"!", "~"},
1538   {"++", "--"},
1539   {"atan2", "cos"},
1540   {"sin", "exp"},
1541   {"log", "sqrt"},
1542   {"x","x="},
1543   {".",".="},
1544   {"=","neg"}
1545 };
1546 #else
1547 EXT char * AMG_names[NofAMmeth][2];
1548 #endif /* def INITAMAGIC */
1549
1550 struct  am_table        {
1551   long was_ok_sub;
1552   long was_ok_am;
1553   CV* table[NofAMmeth*2];
1554   long fallback;
1555 };
1556 typedef struct am_table AMT;
1557
1558 #define AMGfallNEVER    1
1559 #define AMGfallNO       2
1560 #define AMGfallYES      3
1561
1562 enum {
1563   fallback_amg, abs_amg,
1564   bool__amg,    nomethod_amg,
1565   string_amg,   numer_amg,
1566   add_amg,      add_ass_amg,
1567   subtr_amg,    subtr_ass_amg,
1568   mult_amg,     mult_ass_amg,
1569   div_amg,      div_ass_amg,
1570   mod_amg,      mod_ass_amg,
1571   pow_amg,      pow_ass_amg,
1572   lshift_amg,   lshift_ass_amg,
1573   rshift_amg,   rshift_ass_amg,
1574   band_amg,     band_ass_amg,
1575   bor_amg,      bor_ass_amg,
1576   bxor_amg,     bxor_ass_amg,
1577   lt_amg,       le_amg,
1578   gt_amg,       ge_amg,
1579   eq_amg,       ne_amg,
1580   ncmp_amg,     scmp_amg,
1581   slt_amg,      sle_amg,
1582   sgt_amg,      sge_amg,
1583   seq_amg,      sne_amg,
1584   not_amg,      compl_amg,
1585   inc_amg,      dec_amg,
1586   atan2_amg,    cos_amg,
1587   sin_amg,      exp_amg,
1588   log_amg,      sqrt_amg,
1589   repeat_amg,   repeat_ass_amg,
1590   concat_amg,   concat_ass_amg,
1591   copy_amg,     neg_amg
1592 };
1593 #endif /* OVERLOAD */
1594
1595 #endif /* Include guard */