1 /* $RCSfile: perl.h,v $$Revision: 4.0.1.4 $$Date: 91/11/05 18:06: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.4 91/11/05 18:06:10 lwall
10 * patch11: various portability fixes
11 * patch11: added support for dbz
12 * patch11: added some support for 64-bit integers
13 * patch11: hex() didn't understand leading 0x
15 * Revision 4.0.1.3 91/06/10 01:25:10 lwall
16 * patch10: certain pattern optimizations were botched
18 * Revision 4.0.1.2 91/06/07 11:28:33 lwall
19 * patch4: new copyright notice
20 * patch4: made some allowances for "semi-standard" C
21 * patch4: many, many itty-bitty portability fixes
23 * Revision 4.0.1.1 91/04/11 17:49:51 lwall
24 * patch1: hopefully straightened out some of the Xenix mess
26 * Revision 4.0 91/03/20 01:37:56 lwall
36 # define malloc Mymalloc
37 # define realloc Myremalloc
40 # define safemalloc malloc
41 # define saferealloc realloc
42 # define safefree free
45 /* work around some libPW problems */
52 /* This stuff now in the MS-DOS config.h file. */
56 * The following symbols are defined if your operating system supports
57 * functions by that name. All Unixes I know of support them, thus they
58 * are not checked by the configuration script, but are directly defined
73 * The following symbols are defined if your operating system supports
74 * password and group functions in general. All Unix systems do.
81 #if defined(__STDC__) || defined(_AIX) || defined(__stdc__)
85 #if defined(HASVOLATILE) || defined(STANDARD_C)
86 #define VOLATILE volatile
105 # define getpgrp getpgrp2
112 # define setpgrp setpgrp2
119 #ifdef PARAM_NEEDS_TYPES
120 #include <sys/types.h>
122 #include <sys/param.h>
125 /* Use all the "standard" definitions */
128 #endif /* STANDARD_C */
130 #if defined(HAS_MEMCMP) && defined(mips) && BYTEORDER == 0x1234
138 extern char * memcpy(), *memset();
140 # endif /* ndef memcpy */
141 # endif /* ndef STANDARD_C */
144 # define bcopy(s1,s2,l) memcpy(s2,s1,l)
147 # define bzero(s,l) memset(s,0,l)
149 #endif /* HAS_MEMCPY */
151 #ifndef HAS_BCMP /* prefer bcmp slightly 'cuz it doesn't order */
153 # define bcmp(s1,s2,l) memcmp(s1,s2,l)
157 #ifndef _TYPES_ /* If types.h defines this it's easy. */
158 #ifndef major /* Does everyone's types.h define this? */
159 #include <sys/types.h>
164 #include <netinet/in.h>
167 #include <sys/stat.h>
174 # ifdef SYSTIMEKERNEL
177 # include <sys/time.h>
178 # ifdef SYSTIMEKERNEL
184 #include <sys/times.h>
187 #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
194 extern int errno; /* ANSI allows errno to be an lvalue expr */
203 extern char *sys_errlist[];
204 #define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
210 #include <sys/ioctl.h>
214 #if defined(mc300) || defined(mc500) || defined(mc700) /* MASSCOMP */
215 #ifdef HAS_SOCKETPAIR
216 #undef HAS_SOCKETPAIR
226 #define dbm_fetch(db,dkey) fetch(dkey)
227 #define dbm_delete(db,dkey) fatal("dbz doesn't implement delete")
228 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
229 #define dbm_close(db) dbmclose()
230 #define dbm_firstkey(db) (fatal("dbz doesn't implement traversal"),fetch())
231 #define nextkey() (fatal("dbz doesn't implement traversal"),fetch())
232 #define dbm_nextkey(db) (fatal("dbz doesn't implement traversal"),fetch())
261 #undef NULL /* suppress redefinition message */
267 #define NULL 0 /* silly thing is, we don't even use this */
269 #define dbm_fetch(db,dkey) fetch(dkey)
270 #define dbm_delete(db,dkey) delete(dkey)
271 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
272 #define dbm_close(db) dbmclose()
273 #define dbm_firstkey(db) firstkey()
274 #endif /* HAS_ODBM */
275 #endif /* HAS_NDBM */
276 #endif /* HAS_GDBM */
277 #endif /* WANT_DBZ */
291 #if defined(I_DIRENT)
293 # define DIRENT dirent
296 # include <sys/ndir.h>
297 # define DIRENT direct
301 # include <ndir.h> /* may be wrong in the future */
303 # include <sys/dir.h>
305 # define DIRENT direct
311 /* work around botch in SunOS 4.0.1 and 4.0.2 */
313 # define fputs(str,fp) fprintf(fp,"%s",str)
318 * The following gobbledygook brought to you on behalf of __STDC__.
319 * (I could just use #ifndef __STDC__, but this is more bulletproof
320 * in the face of half-implementations.)
325 # define S_IFMT _S_IFMT
327 # define S_IFMT 0170000
332 # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
336 # define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
341 # define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
343 # define S_ISBLK(m) (0)
347 #if S_ISBLK(060000) == 060000
348 XXX Your sys/stat.h appears to be buggy. Please fix it.
352 # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
357 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
359 # define S_ISFIFO(m) (0)
365 # define S_ISLNK(m) _S_ISLNK(m)
368 # define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
371 # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
373 # define S_ISLNK(m) (0)
381 # define S_ISSOCK(m) _S_ISSOCK(m)
384 # define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
387 # define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
389 # define S_ISSOCK(m) (0)
397 # define S_IRUSR S_IREAD
398 # define S_IWUSR S_IWRITE
399 # define S_IXUSR S_IEXEC
401 # define S_IRUSR 0400
402 # define S_IWUSR 0200
403 # define S_IXUSR 0100
405 # define S_IRGRP (S_IRUSR>>3)
406 # define S_IWGRP (S_IWUSR>>3)
407 # define S_IXGRP (S_IXUSR>>3)
408 # define S_IROTH (S_IRUSR>>6)
409 # define S_IWOTH (S_IWUSR>>6)
410 # define S_IXOTH (S_IXUSR>>6)
414 # define S_ISUID 04000
418 # define S_ISGID 02000
425 #if defined(cray) || defined(gould)
426 # define SLOPPYDIVIDE
429 #if defined(cray) || defined(convex) || BYTEORDER > 0xffff
438 # define quad long long
445 typedef unsigned int STRLEN;
447 typedef struct arg ARG;
448 typedef struct cmd CMD;
449 typedef struct formcmd FCMD;
450 typedef struct scanpat SPAT;
451 typedef struct stio STIO;
452 typedef struct sub SUBR;
453 typedef struct string STR;
454 typedef struct atbl ARRAY;
455 typedef struct htbl HASH;
456 typedef struct regexp REGEXP;
457 typedef struct stabptrs STBP;
458 typedef struct stab STAB;
459 typedef struct callsave CSV;
473 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
485 EXT char *Yes INIT("1");
486 EXT char *No INIT("");
490 /* Note: cmd.c assumes that it can use && to produce one of these values! */
496 #else /* !CRIPPLED_CC */
497 #define str_true(str) (Str = (str), \
499 ((*Str->str_ptr > '0' || \
500 Str->str_cur > 1 || \
501 (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \
503 (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) ))
504 #endif /* CRIPPLED_CC */
507 #define str_peek(str) (Str = (str), \
511 (sprintf(tokenbuf,"num(%g)",Str->str_u.str_nval), \
520 #define str_get(str) (Str = (str), tainted |= Str->str_tainted, \
521 (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
523 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
525 #endif /* CRIPPLED_CC */
529 #else /* !CRIPPLED_CC */
531 #define str_gnum(str) (Str = (str), tainted |= Str->str_tainted, \
532 (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
534 #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
536 #endif /* CRIPPLED_CC */
539 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
542 #define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len)
543 #define Str_Grow str_grow
545 /* extra parentheses intentionally NOT placed around "len"! */
546 #define STR_GROW(str,len) if ((str)->str_len < (unsigned long)len) \
547 str_grow(str,(unsigned long)len)
548 #define Str_Grow(str,len) str_grow(str,(unsigned long)(len))
552 #define BYTEORDER 0x1234
555 #if defined(htonl) && !defined(HAS_HTONL)
558 #if defined(htons) && !defined(HAS_HTONS)
561 #if defined(ntohl) && !defined(HAS_NTOHL)
564 #if defined(ntohs) && !defined(HAS_NTOHS)
568 #if (BYTEORDER & 0xffff) != 0x4321
574 #define htons my_swap
575 #define htonl my_htonl
576 #define ntohs my_swap
577 #define ntohl my_ntohl
580 #if (BYTEORDER & 0xffff) == 0x4321
589 #define U_S(what) ((unsigned short)(what))
590 #define U_I(what) ((unsigned int)(what))
591 #define U_L(what) ((unsigned long)(what))
593 unsigned long castulong();
594 #define U_S(what) ((unsigned int)castulong(what))
595 #define U_I(what) ((unsigned int)castulong(what))
596 #define U_L(what) (castulong(what))
641 int eval(); /* this evaluates expressions */
642 int do_eval(); /* this evaluates eval operator */
654 char *str_append_till();
696 EXT char **origenviron;
697 extern char **environ;
699 EXT long subline INIT(0);
700 EXT STR *subname INIT(Nullstr);
701 EXT int arybase INIT(0);
709 EXT struct outrec outrec;
710 EXT struct outrec toprec;
712 EXT STAB *stdinstab INIT(Nullstab);
713 EXT STAB *last_in_stab INIT(Nullstab);
714 EXT STAB *defstab INIT(Nullstab);
715 EXT STAB *argvstab INIT(Nullstab);
716 EXT STAB *envstab INIT(Nullstab);
717 EXT STAB *sigstab INIT(Nullstab);
718 EXT STAB *defoutstab INIT(Nullstab);
719 EXT STAB *curoutstab INIT(Nullstab);
720 EXT STAB *argvoutstab INIT(Nullstab);
721 EXT STAB *incstab INIT(Nullstab);
722 EXT STAB *leftstab INIT(Nullstab);
723 EXT STAB *amperstab INIT(Nullstab);
724 EXT STAB *rightstab INIT(Nullstab);
725 EXT STAB *DBstab INIT(Nullstab);
726 EXT STAB *DBline INIT(Nullstab);
727 EXT STAB *DBsub INIT(Nullstab);
729 EXT HASH *defstash; /* main symbol table */
730 EXT HASH *curstash; /* symbol table for current package */
731 EXT HASH *debstash; /* symbol table for perldb package */
733 EXT STR *curstname; /* name of current package */
735 EXT STR *freestrroot INIT(Nullstr);
736 EXT STR *lastretstr INIT(Nullstr);
737 EXT STR *DBsingle INIT(Nullstr);
738 EXT STR *DBtrace INIT(Nullstr);
739 EXT STR *DBsignal INIT(Nullstr);
744 EXT char *hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
745 EXT char *origfilename;
746 EXT FILE * VOLATILE rsfp;
750 EXT char *oldoldbufptr;
753 EXT STR *linestr INIT(Nullstr);
755 EXT char *rs INIT("\n");
756 EXT int rschar INIT('\n'); /* final char of rs, or 0777 if none */
757 EXT int rslen INIT(1);
758 EXT char *ofs INIT(Nullch);
759 EXT int ofslen INIT(0);
760 EXT char *ors INIT(Nullch);
761 EXT int orslen INIT(0);
762 EXT char *ofmt INIT(Nullch);
763 EXT char *inplace INIT(Nullch);
764 EXT char *nointrp INIT("");
766 EXT bool preprocess INIT(FALSE);
767 EXT bool minus_n INIT(FALSE);
768 EXT bool minus_p INIT(FALSE);
769 EXT bool minus_l INIT(FALSE);
770 EXT bool minus_a INIT(FALSE);
771 EXT bool doswitches INIT(FALSE);
772 EXT bool dowarn INIT(FALSE);
773 EXT bool doextract INIT(FALSE);
774 EXT bool allstabs INIT(FALSE); /* init all customary symbols in symbol table?*/
775 EXT bool sawampersand INIT(FALSE); /* must save all match strings */
776 EXT bool sawstudy INIT(FALSE); /* do fbminstr on all strings */
777 EXT bool sawi INIT(FALSE); /* study must assume case insensitive */
778 EXT bool sawvec INIT(FALSE);
779 EXT bool localizing INIT(FALSE); /* are we processing a local() list? */
784 EXT int maxsysfd INIT(MAXSYSFD); /* top fd to pass to subprocesses */
787 char *cshname INIT(CSH);
792 EXT bool tainted INIT(FALSE); /* using variables controlled by $< */
796 #define TMPPATH "/tmp/perl-eXXXXXX"
798 #define TMPPATH "plXXXXXX"
801 EXT FILE *e_fp INIT(Nullfp);
803 EXT char tokenbuf[256];
804 EXT int expectterm INIT(TRUE); /* how to interpret ambiguous tokens */
805 EXT VOLATILE int in_eval INIT(FALSE); /* trap fatal errors? */
806 EXT int multiline INIT(0); /* $*--do strings hold >1 line? */
807 EXT int forkprocess; /* so do_open |- can return proc# */
808 EXT int do_undump INIT(0); /* -u or dump seen? */
809 EXT int error_count INIT(0); /* how many errors so far, max 10 */
810 EXT int multi_start INIT(0); /* 1st line of multi-line string */
811 EXT int multi_end INIT(0); /* last line of multi-line string */
812 EXT int multi_open INIT(0); /* delimiter of said string */
813 EXT int multi_close INIT(0); /* delimiter of said string */
816 /* char *str_get(); */
823 EXT struct stat statbuf;
824 EXT struct stat statcache;
825 STAB *statstab INIT(Nullstab);
828 EXT struct tms timesbuf;
841 EXT VOLATILE int debug INIT(0);
842 EXT int dlevel INIT(0);
843 EXT int dlmax INIT(128);
848 EXT int perldb INIT(0);
849 #define YYMAXDEPTH 300
851 EXT line_t cmdline INIT(NOLINE);
857 /* runtime control stuff */
860 char *loop_label; /* what the loop was called, if anything */
861 int loop_sp; /* stack pointer to copy stuff down to */
865 EXT int loop_ptr INIT(-1);
866 EXT int loop_max INIT(128);
870 EXT char * VOLATILE goto_targ INIT(Nullch); /* cmd_exec gets strange when set */
878 EXT ARRAY *stack; /* THE STACK */
880 EXT ARRAY * VOLATILE savestack; /* to save non-local values on */
882 EXT ARRAY *tosave; /* strings to save on recursive subroutine */
884 EXT ARRAY *lineary; /* lines of script for debugger */
885 EXT ARRAY *dbargs; /* args to call listed by caller function */
887 EXT ARRAY *fdpid; /* keep fd-to-pid mappings for mypopen */
888 EXT HASH *pidstatus; /* keep pid-to-status mappings for waitpid */
890 EXT int *di; /* for tmp use in debuggers */
894 /* Fix these up for __STDC__ */
895 EXT long basetime INIT(0);
898 /* All of these are in stdlib.h or time.h for ANSI C */
901 struct tm *gmtime(), *localtime();
902 char *index(), *rindex();
903 char *strcpy(), *strcat();
904 #endif /* ! STANDARD_C */
910 #define UNLINK unlink
915 #define setreuid(r,e) setresuid(r,e,-1)
921 #define setregid(r,e) setresgid(r,e,-1)