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