1 /* $RCSfile: perl.h,v $$Revision: 4.0.1.6 $$Date: 92/06/08 14:55:10 $
3 * Copyright (c) 1991, Larry Wall
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.
9 * Revision 4.0.1.6 92/06/08 14:55:10 lwall
10 * patch20: added Atari ST portability
11 * patch20: bcopy() and memcpy() now tested for overlap safety
12 * patch20: Perl now distinguishes overlapped copies from non-overlapped
13 * patch20: removed implicit int declarations on functions
15 * Revision 4.0.1.5 91/11/11 16:41:07 lwall
16 * patch19: uts wrongly defines S_ISDIR() et al
17 * patch19: too many preprocessors can't expand a macro right in #if
18 * patch19: added little-endian pack/unpack options
20 * Revision 4.0.1.4 91/11/05 18:06:10 lwall
21 * patch11: various portability fixes
22 * patch11: added support for dbz
23 * patch11: added some support for 64-bit integers
24 * patch11: hex() didn't understand leading 0x
26 * Revision 4.0.1.3 91/06/10 01:25:10 lwall
27 * patch10: certain pattern optimizations were botched
29 * Revision 4.0.1.2 91/06/07 11:28:33 lwall
30 * patch4: new copyright notice
31 * patch4: made some allowances for "semi-standard" C
32 * patch4: many, many itty-bitty portability fixes
34 * Revision 4.0.1.1 91/04/11 17:49:51 lwall
35 * patch1: hopefully straightened out some of the Xenix mess
37 * Revision 4.0 91/03/20 01:37:56 lwall
47 # define malloc Mymalloc
48 # define realloc Myremalloc
51 # define safemalloc malloc
52 # define saferealloc realloc
53 # define safefree free
56 /* work around some libPW problems */
62 /* define this once if either system, instead of cluttering up the src */
63 #if defined(MSDOS) || defined(atarist)
68 /* This stuff now in the MS-DOS config.h file. */
72 * The following symbols are defined if your operating system supports
73 * functions by that name. All Unixes I know of support them, thus they
74 * are not checked by the configuration script, but are directly defined
89 * The following symbols are defined if your operating system supports
90 * password and group functions in general. All Unix systems do.
97 #if defined(__STDC__) || defined(_AIX) || defined(__stdc__)
101 #if defined(HASVOLATILE) || defined(STANDARD_C)
102 #define VOLATILE volatile
121 # define getpgrp getpgrp2
128 # define setpgrp setpgrp2
135 #ifdef PARAM_NEEDS_TYPES
136 #include <sys/types.h>
138 #include <sys/param.h>
141 /* Use all the "standard" definitions */
144 #define MEM_SIZE size_t
146 typedef unsigned int MEM_SIZE;
147 #endif /* STANDARD_C */
149 #if defined(HAS_MEMCMP) && defined(mips) && defined(ultrix)
156 extern char * memcpy();
162 # define memcpy(d,s,l) bcopy(s,d,l)
164 # define memcpy(d,s,l) my_bcopy(s,d,l)
167 #endif /* HAS_MEMCPY */
172 extern char *memset();
175 # define memzero(d,l) memset(d,0,l)
179 # define memzero(d,l) bzero(d,l)
181 # define memzero(d,l) my_bzero(d,l)
184 #endif /* HAS_MEMSET */
194 # define memcmp(s1,s2,l) my_memcmp(s1,s2,l)
196 #endif /* HAS_MEMCMP */
198 /* we prefer bcmp slightly for comparisons that don't care about ordering */
201 # define bcmp(s1,s2,l) memcmp(s1,s2,l)
203 #endif /* HAS_BCMP */
206 #if defined(HAS_BCOPY) && defined(SAFE_BCOPY)
207 #define memmove(d,s,l) bcopy(s,d,l)
209 #if defined(HAS_MEMCPY) && defined(SAFE_MEMCPY)
210 #define memmove(d,s,l) memcpy(d,s,l)
212 #define memmove(d,s,l) my_bcopy(s,d,l)
217 #ifndef _TYPES_ /* If types.h defines this it's easy. */
218 #ifndef major /* Does everyone's types.h define this? */
219 #include <sys/types.h>
224 #include <netinet/in.h>
227 #include <sys/stat.h>
228 #if defined(uts) || defined(UTekV)
235 #define S_ISDIR(P) (((P)&S_IFMT)==S_IFDIR)
236 #define S_ISCHR(P) (((P)&S_IFMT)==S_IFCHR)
237 #define S_ISBLK(P) (((P)&S_IFMT)==S_IFBLK)
238 #define S_ISREG(P) (((P)&S_IFMT)==S_IFREG)
239 #define S_ISFIFO(P) (((P)&S_IFMT)==S_IFIFO)
241 #define S_ISLNK(P) (((P)&S_IFMT)==S_IFLNK)
250 # ifdef SYSTIMEKERNEL
253 # include <sys/time.h>
254 # ifdef SYSTIMEKERNEL
260 #include <sys/times.h>
263 #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
270 extern int errno; /* ANSI allows errno to be an lvalue expr */
279 extern char *sys_errlist[];
280 #define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
286 #include <sys/ioctl.h>
290 #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
291 #ifdef HAS_SOCKETPAIR
292 #undef HAS_SOCKETPAIR
302 #define dbm_fetch(db,dkey) fetch(dkey)
303 #define dbm_delete(db,dkey) fatal("dbz doesn't implement delete")
304 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
305 #define dbm_close(db) dbmclose()
306 #define dbm_firstkey(db) (fatal("dbz doesn't implement traversal"),fetch())
307 #define nextkey() (fatal("dbz doesn't implement traversal"),fetch())
308 #define dbm_nextkey(db) (fatal("dbz doesn't implement traversal"),fetch())
337 #undef NULL /* suppress redefinition message */
343 #define NULL 0 /* silly thing is, we don't even use this */
345 #define dbm_fetch(db,dkey) fetch(dkey)
346 #define dbm_delete(db,dkey) delete(dkey)
347 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
348 #define dbm_close(db) dbmclose()
349 #define dbm_firstkey(db) firstkey()
350 #endif /* HAS_ODBM */
351 #endif /* HAS_NDBM */
352 #endif /* HAS_GDBM */
353 #endif /* WANT_DBZ */
367 #if defined(I_DIRENT)
369 # define DIRENT dirent
372 # include <sys/ndir.h>
373 # define DIRENT direct
377 # include <ndir.h> /* may be wrong in the future */
379 # include <sys/dir.h>
381 # define DIRENT direct
387 /* work around botch in SunOS 4.0.1 and 4.0.2 */
389 # define fputs(str,fp) fprintf(fp,"%s",str)
394 * The following gobbledygook brought to you on behalf of __STDC__.
395 * (I could just use #ifndef __STDC__, but this is more bulletproof
396 * in the face of half-implementations.)
401 # define S_IFMT _S_IFMT
403 # define S_IFMT 0170000
408 # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
412 # define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
417 # define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
419 # define S_ISBLK(m) (0)
424 # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
429 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
431 # define S_ISFIFO(m) (0)
437 # define S_ISLNK(m) _S_ISLNK(m)
440 # define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
443 # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
445 # define S_ISLNK(m) (0)
453 # define S_ISSOCK(m) _S_ISSOCK(m)
456 # define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
459 # define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
461 # define S_ISSOCK(m) (0)
469 # define S_IRUSR S_IREAD
470 # define S_IWUSR S_IWRITE
471 # define S_IXUSR S_IEXEC
473 # define S_IRUSR 0400
474 # define S_IWUSR 0200
475 # define S_IXUSR 0100
477 # define S_IRGRP (S_IRUSR>>3)
478 # define S_IWGRP (S_IWUSR>>3)
479 # define S_IXGRP (S_IXUSR>>3)
480 # define S_IROTH (S_IRUSR>>6)
481 # define S_IWOTH (S_IWUSR>>6)
482 # define S_IXOTH (S_IXUSR>>6)
486 # define S_ISUID 04000
490 # define S_ISGID 02000
497 #if defined(cray) || defined(gould) || defined(i860)
498 # define SLOPPYDIVIDE
501 #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
509 # if defined(convex) || defined (uts)
510 # define quad long long
517 typedef MEM_SIZE STRLEN;
519 typedef struct arg ARG;
520 typedef struct cmd CMD;
521 typedef struct formcmd FCMD;
522 typedef struct scanpat SPAT;
523 typedef struct stio STIO;
524 typedef struct sub SUBR;
525 typedef struct string STR;
526 typedef struct atbl ARRAY;
527 typedef struct htbl HASH;
528 typedef struct regexp REGEXP;
529 typedef struct stabptrs STBP;
530 typedef struct stab STAB;
531 typedef struct callsave CSV;
545 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
557 EXT char *Yes INIT("1");
558 EXT char *No INIT("");
562 /* Note: cmd.c assumes that it can use && to produce one of these values! */
568 #else /* !CRIPPLED_CC */
569 #define str_true(str) (Str = (str), \
571 ((*Str->str_ptr > '0' || \
572 Str->str_cur > 1 || \
573 (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \
575 (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) ))
576 #endif /* CRIPPLED_CC */
579 #define str_peek(str) (Str = (str), \
583 (sprintf(tokenbuf,"num(%g)",Str->str_u.str_nval), \
592 #define str_get(str) (Str = (str), tainted |= Str->str_tainted, \
593 (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
595 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
597 #endif /* CRIPPLED_CC */
601 #else /* !CRIPPLED_CC */
603 #define str_gnum(str) (Str = (str), tainted |= Str->str_tainted, \
604 (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
606 #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
608 #endif /* CRIPPLED_CC */
611 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
614 #define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len)
615 #define Str_Grow str_grow
617 /* extra parentheses intentionally NOT placed around "len"! */
618 #define STR_GROW(str,len) if ((str)->str_len < (unsigned long)len) \
619 str_grow(str,(unsigned long)len)
620 #define Str_Grow(str,len) str_grow(str,(unsigned long)(len))
624 #define BYTEORDER 0x1234
627 #if defined(htonl) && !defined(HAS_HTONL)
630 #if defined(htons) && !defined(HAS_HTONS)
633 #if defined(ntohl) && !defined(HAS_NTOHL)
636 #if defined(ntohs) && !defined(HAS_NTOHS)
640 #if (BYTEORDER & 0xffff) != 0x4321
646 #define htons my_swap
647 #define htonl my_htonl
648 #define ntohs my_swap
649 #define ntohl my_ntohl
652 #if (BYTEORDER & 0xffff) == 0x4321
661 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
664 #if BYTEORDER != 0x1234
669 # if BYTEORDER == 0x4321
670 # define vtohl(x) ((((x)&0xFF)<<24) \
672 +(((x)&0x0000FF00)<<8) \
673 +(((x)&0x00FF0000)>>8) )
674 # define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
675 # define htovl(x) vtohl(x)
676 # define htovs(x) vtohs(x)
678 /* otherwise default to functions in util.c */
682 #define U_S(what) ((unsigned short)(what))
683 #define U_I(what) ((unsigned int)(what))
684 #define U_L(what) ((unsigned long)(what))
686 unsigned long castulong();
687 #define U_S(what) ((unsigned int)castulong(what))
688 #define U_I(what) ((unsigned int)castulong(what))
689 #define U_L(what) (castulong(what))
735 int eval(); /* this evaluates expressions */
736 int do_eval(); /* this evaluates eval operator */
748 char *str_append_till();
820 EXT char **origenviron;
821 extern char **environ;
823 EXT long subline INIT(0);
824 EXT STR *subname INIT(Nullstr);
825 EXT int arybase INIT(0);
833 EXT struct outrec outrec;
834 EXT struct outrec toprec;
836 EXT STAB *stdinstab INIT(Nullstab);
837 EXT STAB *last_in_stab INIT(Nullstab);
838 EXT STAB *defstab INIT(Nullstab);
839 EXT STAB *argvstab INIT(Nullstab);
840 EXT STAB *envstab INIT(Nullstab);
841 EXT STAB *sigstab INIT(Nullstab);
842 EXT STAB *defoutstab INIT(Nullstab);
843 EXT STAB *curoutstab INIT(Nullstab);
844 EXT STAB *argvoutstab INIT(Nullstab);
845 EXT STAB *incstab INIT(Nullstab);
846 EXT STAB *leftstab INIT(Nullstab);
847 EXT STAB *amperstab INIT(Nullstab);
848 EXT STAB *rightstab INIT(Nullstab);
849 EXT STAB *DBstab INIT(Nullstab);
850 EXT STAB *DBline INIT(Nullstab);
851 EXT STAB *DBsub INIT(Nullstab);
853 EXT HASH *defstash; /* main symbol table */
854 EXT HASH *curstash; /* symbol table for current package */
855 EXT HASH *debstash; /* symbol table for perldb package */
857 EXT STR *curstname; /* name of current package */
859 EXT STR *freestrroot INIT(Nullstr);
860 EXT STR *lastretstr INIT(Nullstr);
861 EXT STR *DBsingle INIT(Nullstr);
862 EXT STR *DBtrace INIT(Nullstr);
863 EXT STR *DBsignal INIT(Nullstr);
864 EXT STR *formfeed INIT(Nullstr);
869 EXT char *hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
870 EXT char *origfilename;
871 EXT FILE * VOLATILE rsfp INIT(Nullfp);
875 EXT char *oldoldbufptr;
878 EXT STR *linestr INIT(Nullstr);
880 EXT char *rs INIT("\n");
881 EXT int rschar INIT('\n'); /* final char of rs, or 0777 if none */
882 EXT int rslen INIT(1);
883 EXT bool rspara INIT(FALSE);
884 EXT char *ofs INIT(Nullch);
885 EXT int ofslen INIT(0);
886 EXT char *ors INIT(Nullch);
887 EXT int orslen INIT(0);
888 EXT char *ofmt INIT(Nullch);
889 EXT char *inplace INIT(Nullch);
890 EXT char *nointrp INIT("");
892 EXT bool preprocess INIT(FALSE);
893 EXT bool minus_n INIT(FALSE);
894 EXT bool minus_p INIT(FALSE);
895 EXT bool minus_l INIT(FALSE);
896 EXT bool minus_a INIT(FALSE);
897 EXT bool doswitches INIT(FALSE);
898 EXT bool dowarn INIT(FALSE);
899 EXT bool doextract INIT(FALSE);
900 EXT bool allstabs INIT(FALSE); /* init all customary symbols in symbol table?*/
901 EXT bool sawampersand INIT(FALSE); /* must save all match strings */
902 EXT bool sawstudy INIT(FALSE); /* do fbminstr on all strings */
903 EXT bool sawi INIT(FALSE); /* study must assume case insensitive */
904 EXT bool sawvec INIT(FALSE);
905 EXT bool localizing INIT(FALSE); /* are we processing a local() list? */
910 EXT int maxsysfd INIT(MAXSYSFD); /* top fd to pass to subprocesses */
913 EXT char *cshname INIT(CSH);
914 EXT int cshlen INIT(0);
918 EXT bool tainted INIT(FALSE); /* using variables controlled by $< */
919 EXT bool taintanyway INIT(FALSE); /* force taint checks when !set?id */
922 EXT bool nomemok INIT(FALSE); /* let malloc context handle nomem */
925 #define TMPPATH "/tmp/perl-eXXXXXX"
927 #define TMPPATH "plXXXXXX"
930 EXT FILE *e_fp INIT(Nullfp);
932 EXT char tokenbuf[256];
933 EXT int expectterm INIT(TRUE); /* how to interpret ambiguous tokens */
934 EXT VOLATILE int in_eval INIT(FALSE); /* trap fatal errors? */
935 EXT int multiline INIT(0); /* $*--do strings hold >1 line? */
936 EXT int forkprocess; /* so do_open |- can return proc# */
937 EXT int do_undump INIT(0); /* -u or dump seen? */
938 EXT int error_count INIT(0); /* how many errors so far, max 10 */
939 EXT int multi_start INIT(0); /* 1st line of multi-line string */
940 EXT int multi_end INIT(0); /* last line of multi-line string */
941 EXT int multi_open INIT(0); /* delimiter of said string */
942 EXT int multi_close INIT(0); /* delimiter of said string */
945 /* char *str_get(); */
952 EXT struct stat statbuf;
953 EXT struct stat statcache;
954 EXT STAB *statstab INIT(Nullstab);
955 EXT STR *statname INIT(Nullstr);
957 EXT struct tms timesbuf;
970 EXT VOLATILE int debug INIT(0);
971 EXT int dlevel INIT(0);
972 EXT int dlmax INIT(128);
977 EXT int perldb INIT(0);
978 #define YYMAXDEPTH 300
980 EXT line_t cmdline INIT(NOLINE);
986 /* runtime control stuff */
989 char *loop_label; /* what the loop was called, if anything */
990 int loop_sp; /* stack pointer to copy stuff down to */
994 EXT int loop_ptr INIT(-1);
995 EXT int loop_max INIT(128);
999 EXT char * VOLATILE goto_targ INIT(Nullch); /* cmd_exec gets strange when set */
1007 EXT ARRAY *stack; /* THE STACK */
1009 EXT ARRAY * VOLATILE savestack; /* to save non-local values on */
1011 EXT ARRAY *tosave; /* strings to save on recursive subroutine */
1013 EXT ARRAY *lineary; /* lines of script for debugger */
1014 EXT ARRAY *dbargs; /* args to call listed by caller function */
1016 EXT ARRAY *fdpid; /* keep fd-to-pid mappings for mypopen */
1017 EXT HASH *pidstatus; /* keep pid-to-status mappings for waitpid */
1019 EXT int *di; /* for tmp use in debuggers */
1023 /* Fix these up for __STDC__ */
1024 EXT time_t basetime INIT(0);
1027 /* All of these are in stdlib.h or time.h for ANSI C */
1030 struct tm *gmtime(), *localtime();
1031 char *index(), *rindex();
1032 char *strcpy(), *strcat();
1033 #endif /* ! STANDARD_C */
1036 #define UNLINK unlnk
1039 #define UNLINK unlink
1042 #ifndef HAS_SETREUID
1043 #ifdef HAS_SETRESUID
1044 #define setreuid(r,e) setresuid(r,e,-1)
1045 #define HAS_SETREUID
1048 #ifndef HAS_SETREGID
1049 #ifdef HAS_SETRESGID
1050 #define setregid(r,e) setresgid(r,e,-1)
1051 #define HAS_SETREGID