1 /* $Header: perl.h,v 3.0.1.11 91/01/11 18:10:57 lwall Locked $
3 * Copyright (c) 1989, Larry Wall
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
9 * Revision 3.0.1.11 91/01/11 18:10:57 lwall
10 * patch42: ANSIfied the stat mode checking
12 * Revision 3.0.1.10 90/11/10 01:44:13 lwall
13 * patch38: more msdos/os2 upgrades
15 * Revision 3.0.1.9 90/10/15 17:59:41 lwall
16 * patch29: some machines didn't like unsigned C preprocessor values
18 * Revision 3.0.1.8 90/08/09 04:10:53 lwall
19 * patch19: various MSDOS and OS/2 patches folded in
20 * patch19: did preliminary work toward debugging packages and evals
21 * patch19: added -x switch to extract script from input trash
23 * Revision 3.0.1.7 90/03/27 16:12:52 lwall
24 * patch16: MSDOS support
25 * patch16: support for machines that can't cast negative floats to unsigned ints
27 * Revision 3.0.1.6 90/03/12 16:40:43 lwall
28 * patch13: did some ndir straightening up for Xenix
30 * Revision 3.0.1.5 90/02/28 17:52:28 lwall
31 * patch9: Configure now determines whether volatile is supported
32 * patch9: volatilized some more variables for super-optimizing compilers
33 * patch9: unused VREG symbol deleted
34 * patch9: perl can now start up other interpreters scripts
35 * patch9: you may now undef $/ to have no input record separator
36 * patch9: nested evals clobbered their longjmp environment
38 * Revision 3.0.1.4 89/12/21 20:07:35 lwall
39 * patch7: arranged for certain registers to be restored after longjmp()
40 * patch7: Configure now compiles a test program to figure out time.h fiasco
41 * patch7: Configure now detects DG/UX thingies like [sg]etpgrp2 and utime.h
42 * patch7: memcpy() and memset() return void in __STDC__
43 * patch7: errno may now be a macro with an lvalue
44 * patch7: ANSI strerror() is now supported
45 * patch7: Xenix support for sys/ndir.h, cross compilation
47 * Revision 3.0.1.3 89/11/17 15:28:57 lwall
48 * patch5: byteorder now is a hex value
49 * patch5: Configure now looks for <time.h> including <sys/time.h>
51 * Revision 3.0.1.2 89/11/11 04:39:38 lwall
52 * patch2: Configure may now set -DDEBUGGING
53 * patch2: netinet/in.h needed sys/types.h some places
54 * patch2: more <sys/time.h> and <time.h> wrangling
55 * patch2: yydebug moved to where type doesn't matter
57 * Revision 3.0.1.1 89/10/26 23:17:08 lwall
58 * patch1: vfork now conditionally defined based on VFORK
59 * patch1: DEC risc machines have a buggy memcmp
60 * patch1: perl.h now includes <netinet/in.h> if it exists
62 * Revision 3.0 89/10/18 15:21:21 lwall
73 * This symbol is defined if you are the unfortunate owner of a buggy
74 * Microsoft C compiler and want to use intrinsic functions. Versions
75 * up to 5.1 are known conform to this definition. This is not needed
78 #define BUGGY_MSC /**/
81 * This symbol is defined if you run under an operating system that
82 * distinguishes between binary and text files. If so the function
83 * setmode will be used to set the file into binary mode. Unix
84 * doesn't distinguish.
93 * The following symbols are defined if your operating system supports
94 * functions by that name. All Unixes I know of support them, thus they
95 * are not checked by the configuration script, but are directly defined
109 * The following symbols are defined if your operating system supports
110 * password and group functions in general. All Unix systems do.
117 #if defined(HASVOLATILE) || defined(__STDC__)
118 #define VOLATILE volatile
137 # define getpgrp getpgrp2
144 # define setpgrp setpgrp2
147 #if defined(MEMCMP) && defined(mips) && BYTEORDER == 0x1234
153 #if defined(__STDC__ ) || defined(MSDOS)
154 extern void *memcpy(), *memset();
156 extern char *memcpy(), *memset();
160 #define bcopy(s1,s2,l) memcpy(s2,s1,l)
161 #define bzero(s,l) memset(s,0,l)
163 #ifndef BCMP /* prefer bcmp slightly 'cuz it doesn't order */
164 #define bcmp(s1,s2,l) memcmp(s1,s2,l)
171 #include <sys/param.h> /* if this needs types.h we're still wrong */
174 #ifndef _TYPES_ /* If types.h defines this it's easy. */
175 #ifndef major /* Does everyone's types.h define this? */
176 #include <sys/types.h>
181 #include <netinet/in.h>
184 #include <sys/stat.h>
191 # ifdef SYSTIMEKERNEL
194 # include <sys/time.h>
195 # ifdef SYSTIMEKERNEL
201 #include <sys/times.h>
204 #if defined(STRERROR) && (!defined(MKDIR) || !defined(RMDIR))
211 extern int errno; /* ANSI allows errno to be an lvalue expr */
219 extern char *sys_errlist[];
220 #define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
225 #include <sys/ioctl.h>
229 #if defined(mc300) || defined(mc500) || defined(mc700) /* MASSCOMP */
247 #undef NULL /* suppress redefinition message */
253 #define NULL 0 /* silly thing is, we don't even use this */
255 #define dbm_fetch(db,dkey) fetch(dkey)
256 #define dbm_delete(db,dkey) delete(dkey)
257 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
258 #define dbm_close(db) dbmclose()
259 #define dbm_firstkey(db) firstkey()
275 #if defined(I_DIRENT) && !defined(M_XENIX)
277 # define DIRENT dirent
280 # include <sys/ndir.h>
281 # define DIRENT direct
285 # include <ndir.h> /* may be wrong in the future */
287 # include <sys/dir.h>
289 # define DIRENT direct
295 * The following gobbledygook brought to you on behalf of __STDC__.
296 * (I could just use #ifndef __STDC__, but this is more bulletproof
297 * in the face of half-implementations.)
302 # define S_IFMT _S_IFMT
304 # define S_IFMT 0170000
309 # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
313 # define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
317 # define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
321 # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
325 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
330 # define S_ISLNK(m) _S_ISLNK(m)
333 # define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
336 # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
338 # define S_ISLNK(m) (0)
346 # define S_ISSOCK(m) _S_ISSOCK(m)
349 # define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
352 # define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
354 # define S_ISSOCK(m) (0)
362 # define S_IRUSR S_IREAD
363 # define S_IWUSR S_IWRITE
364 # define S_IXUSR S_IEXEC
366 # define S_IRUSR 0400
367 # define S_IWUSR 0200
368 # define S_IXUSR 0100
370 # define S_IRGRP (S_IRUSR>>3)
371 # define S_IWGRP (S_IWUSR>>3)
372 # define S_IXGRP (S_IXUSR>>3)
373 # define S_IROTH (S_IRUSR>>6)
374 # define S_IWOTH (S_IWUSR>>6)
375 # define S_IXOTH (S_IXUSR>>6)
379 # define S_ISUID 04000
383 # define S_ISGID 02000
386 typedef unsigned int STRLEN;
388 typedef struct arg ARG;
389 typedef struct cmd CMD;
390 typedef struct formcmd FCMD;
391 typedef struct scanpat SPAT;
392 typedef struct stio STIO;
393 typedef struct sub SUBR;
394 typedef struct string STR;
395 typedef struct atbl ARRAY;
396 typedef struct htbl HASH;
397 typedef struct regexp REGEXP;
398 typedef struct stabptrs STBP;
399 typedef struct stab STAB;
400 typedef struct callsave CSV;
414 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
426 EXT char *Yes INIT("1");
427 EXT char *No INIT("");
431 /* Note: cmd.c assumes that it can use && to produce one of these values! */
437 #else /* !CRIPPLED_CC */
438 #define str_true(str) (Str = (str), \
440 ((*Str->str_ptr > '0' || \
441 Str->str_cur > 1 || \
442 (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \
444 (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) ))
445 #endif /* CRIPPLED_CC */
448 #define str_peek(str) (Str = (str), \
452 (sprintf(tokenbuf,"num(%g)",Str->str_u.str_nval), \
461 #define str_get(str) (Str = (str), tainted |= Str->str_tainted, \
462 (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
464 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
466 #endif /* CRIPPLED_CC */
470 #else /* !CRIPPLED_CC */
472 #define str_gnum(str) (Str = (str), tainted |= Str->str_tainted, \
473 (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
475 #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
477 #endif /* CRIPPLED_CC */
480 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
483 #define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len)
484 #define Str_Grow str_grow
486 /* extra parentheses intentionally NOT placed around "len"! */
487 #define STR_GROW(str,len) if ((str)->str_len < (unsigned long)len) \
488 str_grow(str,(unsigned long)len)
489 #define Str_Grow(str,len) str_grow(str,(unsigned long)(len))
493 #define BYTEORDER 0x1234
496 #if defined(htonl) && !defined(HTONL)
499 #if defined(htons) && !defined(HTONS)
502 #if defined(ntohl) && !defined(NTOHL)
505 #if defined(ntohs) && !defined(NTOHS)
509 #if (BYTEORDER & 0xffff) != 0x4321
515 #define htons my_swap
516 #define htonl my_htonl
517 #define ntohs my_swap
518 #define ntohl my_ntohl
521 #if (BYTEORDER & 0xffff) == 0x4321
530 #define U_S(what) ((unsigned short)(what))
531 #define U_I(what) ((unsigned int)(what))
532 #define U_L(what) ((unsigned long)(what))
534 unsigned long castulong();
535 #define U_S(what) ((unsigned int)castulong(what))
536 #define U_I(what) ((unsigned int)castulong(what))
537 #define U_L(what) (castulong(what))
582 int eval(); /* this evaluates expressions */
583 int do_eval(); /* this evaluates eval operator */
595 char *str_append_till();
633 EXT line_t subline INIT(0);
634 EXT STR *subname INIT(Nullstr);
635 EXT int arybase INIT(0);
643 EXT struct outrec outrec;
644 EXT struct outrec toprec;
646 EXT STAB *stdinstab INIT(Nullstab);
647 EXT STAB *last_in_stab INIT(Nullstab);
648 EXT STAB *defstab INIT(Nullstab);
649 EXT STAB *argvstab INIT(Nullstab);
650 EXT STAB *envstab INIT(Nullstab);
651 EXT STAB *sigstab INIT(Nullstab);
652 EXT STAB *defoutstab INIT(Nullstab);
653 EXT STAB *curoutstab INIT(Nullstab);
654 EXT STAB *argvoutstab INIT(Nullstab);
655 EXT STAB *incstab INIT(Nullstab);
656 EXT STAB *leftstab INIT(Nullstab);
657 EXT STAB *amperstab INIT(Nullstab);
658 EXT STAB *rightstab INIT(Nullstab);
659 EXT STAB *DBstab INIT(Nullstab);
660 EXT STAB *DBline INIT(Nullstab);
661 EXT STAB *DBsub INIT(Nullstab);
663 EXT HASH *defstash; /* main symbol table */
664 EXT HASH *curstash; /* symbol table for current package */
665 EXT HASH *debstash; /* symbol table for perldb package */
667 EXT STR *curstname; /* name of current package */
669 EXT STR *freestrroot INIT(Nullstr);
670 EXT STR *lastretstr INIT(Nullstr);
671 EXT STR *DBsingle INIT(Nullstr);
672 EXT STR *DBtrace INIT(Nullstr);
673 EXT STR *DBsignal INIT(Nullstr);
678 EXT char *origfilename;
679 EXT FILE * VOLATILE rsfp;
683 EXT char *oldoldbufptr;
686 EXT STR *linestr INIT(Nullstr);
688 EXT int record_separator INIT('\n');
689 EXT int rslen INIT(1);
690 EXT char *ofs INIT(Nullch);
691 EXT int ofslen INIT(0);
692 EXT char *ors INIT(Nullch);
693 EXT int orslen INIT(0);
694 EXT char *ofmt INIT(Nullch);
695 EXT char *inplace INIT(Nullch);
696 EXT char *nointrp INIT("");
698 EXT bool preprocess INIT(FALSE);
699 EXT bool minus_n INIT(FALSE);
700 EXT bool minus_p INIT(FALSE);
701 EXT bool minus_a INIT(FALSE);
702 EXT bool doswitches INIT(FALSE);
703 EXT bool dowarn INIT(FALSE);
704 EXT bool doextract INIT(FALSE);
705 EXT bool allstabs INIT(FALSE); /* init all customary symbols in symbol table?*/
706 EXT bool sawampersand INIT(FALSE); /* must save all match strings */
707 EXT bool sawstudy INIT(FALSE); /* do fbminstr on all strings */
708 EXT bool sawi INIT(FALSE); /* study must assume case insensitive */
709 EXT bool sawvec INIT(FALSE);
710 EXT bool localizing INIT(FALSE); /* are we processing a local() list? */
713 char *cshname INIT(CSH);
718 EXT bool tainted INIT(FALSE); /* using variables controlled by $< */
722 #define TMPPATH "/tmp/perl-eXXXXXX"
724 #define TMPPATH "plXXXXXX"
727 EXT FILE *e_fp INIT(Nullfp);
729 EXT char tokenbuf[256];
730 EXT int expectterm INIT(TRUE); /* how to interpret ambiguous tokens */
731 EXT VOLATILE int in_eval INIT(FALSE); /* trap fatal errors? */
732 EXT int multiline INIT(0); /* $*--do strings hold >1 line? */
733 EXT int forkprocess; /* so do_open |- can return proc# */
734 EXT int do_undump INIT(0); /* -u or dump seen? */
735 EXT int error_count INIT(0); /* how many errors so far, max 10 */
736 EXT int multi_start INIT(0); /* 1st line of multi-line string */
737 EXT int multi_end INIT(0); /* last line of multi-line string */
738 EXT int multi_open INIT(0); /* delimiter of said string */
739 EXT int multi_close INIT(0); /* delimiter of said string */
742 /* char *str_get(); */
747 EXT struct stat statbuf;
748 EXT struct stat statcache;
749 STAB *statstab INIT(Nullstab);
752 EXT struct tms timesbuf;
765 EXT VOLATILE int debug INIT(0);
766 EXT int dlevel INIT(0);
767 EXT int dlmax INIT(128);
772 EXT int perldb INIT(0);
774 EXT line_t cmdline INIT(NOLINE);
780 /* runtime control stuff */
783 char *loop_label; /* what the loop was called, if anything */
784 int loop_sp; /* stack pointer to copy stuff down to */
788 EXT int loop_ptr INIT(-1);
789 EXT int loop_max INIT(128);
793 EXT char * VOLATILE goto_targ INIT(Nullch); /* cmd_exec gets strange when set */
801 EXT ARRAY *stack; /* THE STACK */
803 EXT ARRAY * VOLATILE savestack; /* to save non-local values on */
805 EXT ARRAY *tosave; /* strings to save on recursive subroutine */
807 EXT ARRAY *lineary; /* lines of script for debugger */
808 EXT ARRAY *dbargs; /* args to call listed by caller function */
810 EXT ARRAY *fdpid; /* keep fd-to-pid mappings for mypopen */
811 EXT HASH *pidstatus; /* keep pid-to-status mappings for waitpid */
813 EXT int *di; /* for tmp use in debuggers */
819 EXT long basetime INIT(0);
820 struct tm *gmtime(), *localtime();
822 char *index(), *rindex();
823 char *strcpy(), *strcat();
829 #define UNLINK unlink
834 #define setreuid(r,e) setresuid(r,e,-1)
840 #define setregid(r,e) setresgid(r,e,-1)