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