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