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