1 /* $RCSfile: perl.h,v $$Revision: 4.0.1.5 $$Date: 91/11/11 16:41:07 $
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.5 91/11/11 16:41:07 lwall
10 * patch19: uts wrongly defines S_ISDIR() et al
11 * patch19: too many preprocessors can't expand a macro right in #if
12 * patch19: added little-endian pack/unpack options
14 * Revision 4.0.1.4 91/11/05 18:06:10 lwall
15 * patch11: various portability fixes
16 * patch11: added support for dbz
17 * patch11: added some support for 64-bit integers
18 * patch11: hex() didn't understand leading 0x
20 * Revision 4.0.1.3 91/06/10 01:25:10 lwall
21 * patch10: certain pattern optimizations were botched
23 * Revision 4.0.1.2 91/06/07 11:28:33 lwall
24 * patch4: new copyright notice
25 * patch4: made some allowances for "semi-standard" C
26 * patch4: many, many itty-bitty portability fixes
28 * Revision 4.0.1.1 91/04/11 17:49:51 lwall
29 * patch1: hopefully straightened out some of the Xenix mess
31 * Revision 4.0 91/03/20 01:37:56 lwall
41 # define malloc Mymalloc
42 # define realloc Myremalloc
45 # define safemalloc malloc
46 # define saferealloc realloc
47 # define safefree free
50 /* work around some libPW problems */
57 /* This stuff now in the MS-DOS config.h file. */
61 * The following symbols are defined if your operating system supports
62 * functions by that name. All Unixes I know of support them, thus they
63 * are not checked by the configuration script, but are directly defined
78 * The following symbols are defined if your operating system supports
79 * password and group functions in general. All Unix systems do.
86 #if defined(__STDC__) || defined(_AIX) || defined(__stdc__)
90 #if defined(HASVOLATILE) || defined(STANDARD_C)
91 #define VOLATILE volatile
110 # define getpgrp getpgrp2
117 # define setpgrp setpgrp2
124 #ifdef PARAM_NEEDS_TYPES
125 #include <sys/types.h>
127 #include <sys/param.h>
130 /* Use all the "standard" definitions */
133 #endif /* STANDARD_C */
135 #if defined(HAS_MEMCMP) && defined(mips) && BYTEORDER == 0x1234
143 extern char * memcpy(), *memset();
145 # endif /* ndef memcpy */
146 # endif /* ndef STANDARD_C */
149 # define bcopy(s1,s2,l) memcpy(s2,s1,l)
152 # define bzero(s,l) memset(s,0,l)
154 #endif /* HAS_MEMCPY */
156 #ifndef HAS_BCMP /* prefer bcmp slightly 'cuz it doesn't order */
158 # define bcmp(s1,s2,l) memcmp(s1,s2,l)
162 #ifndef _TYPES_ /* If types.h defines this it's easy. */
163 #ifndef major /* Does everyone's types.h define this? */
164 #include <sys/types.h>
169 #include <netinet/in.h>
172 #include <sys/stat.h>
180 #define S_ISDIR(P) (((P)&S_IFMT)==S_IFDIR)
181 #define S_ISCHR(P) (((P)&S_IFMT)==S_IFCHR)
182 #define S_ISBLK(P) (((P)&S_IFMT)==S_IFBLK)
183 #define S_ISREG(P) (((P)&S_IFMT)==S_IFREG)
184 #define S_ISFIFO(P) (((P)&S_IFMT)==S_IFIFO)
185 #define S_ISLNK(P) (((P)&S_IFMT)==S_IFLNK)
193 # ifdef SYSTIMEKERNEL
196 # include <sys/time.h>
197 # ifdef SYSTIMEKERNEL
203 #include <sys/times.h>
206 #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
213 extern int errno; /* ANSI allows errno to be an lvalue expr */
222 extern char *sys_errlist[];
223 #define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
229 #include <sys/ioctl.h>
233 #if defined(mc300) || defined(mc500) || defined(mc700) /* MASSCOMP */
234 #ifdef HAS_SOCKETPAIR
235 #undef HAS_SOCKETPAIR
245 #define dbm_fetch(db,dkey) fetch(dkey)
246 #define dbm_delete(db,dkey) fatal("dbz doesn't implement delete")
247 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
248 #define dbm_close(db) dbmclose()
249 #define dbm_firstkey(db) (fatal("dbz doesn't implement traversal"),fetch())
250 #define nextkey() (fatal("dbz doesn't implement traversal"),fetch())
251 #define dbm_nextkey(db) (fatal("dbz doesn't implement traversal"),fetch())
280 #undef NULL /* suppress redefinition message */
286 #define NULL 0 /* silly thing is, we don't even use this */
288 #define dbm_fetch(db,dkey) fetch(dkey)
289 #define dbm_delete(db,dkey) delete(dkey)
290 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
291 #define dbm_close(db) dbmclose()
292 #define dbm_firstkey(db) firstkey()
293 #endif /* HAS_ODBM */
294 #endif /* HAS_NDBM */
295 #endif /* HAS_GDBM */
296 #endif /* WANT_DBZ */
310 #if defined(I_DIRENT)
312 # define DIRENT dirent
315 # include <sys/ndir.h>
316 # define DIRENT direct
320 # include <ndir.h> /* may be wrong in the future */
322 # include <sys/dir.h>
324 # define DIRENT direct
330 /* work around botch in SunOS 4.0.1 and 4.0.2 */
332 # define fputs(str,fp) fprintf(fp,"%s",str)
337 * The following gobbledygook brought to you on behalf of __STDC__.
338 * (I could just use #ifndef __STDC__, but this is more bulletproof
339 * in the face of half-implementations.)
344 # define S_IFMT _S_IFMT
346 # define S_IFMT 0170000
351 # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
355 # define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
360 # define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
362 # define S_ISBLK(m) (0)
367 # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
372 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
374 # define S_ISFIFO(m) (0)
380 # define S_ISLNK(m) _S_ISLNK(m)
383 # define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
386 # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
388 # define S_ISLNK(m) (0)
396 # define S_ISSOCK(m) _S_ISSOCK(m)
399 # define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
402 # define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
404 # define S_ISSOCK(m) (0)
412 # define S_IRUSR S_IREAD
413 # define S_IWUSR S_IWRITE
414 # define S_IXUSR S_IEXEC
416 # define S_IRUSR 0400
417 # define S_IWUSR 0200
418 # define S_IXUSR 0100
420 # define S_IRGRP (S_IRUSR>>3)
421 # define S_IWGRP (S_IWUSR>>3)
422 # define S_IXGRP (S_IXUSR>>3)
423 # define S_IROTH (S_IRUSR>>6)
424 # define S_IWOTH (S_IWUSR>>6)
425 # define S_IXOTH (S_IXUSR>>6)
429 # define S_ISUID 04000
433 # define S_ISGID 02000
440 #if defined(cray) || defined(gould)
441 # define SLOPPYDIVIDE
444 #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
452 # if defined(convex) || defined (uts)
453 # define quad long long
460 typedef unsigned int STRLEN;
462 typedef struct arg ARG;
463 typedef struct cmd CMD;
464 typedef struct formcmd FCMD;
465 typedef struct scanpat SPAT;
466 typedef struct stio STIO;
467 typedef struct sub SUBR;
468 typedef struct string STR;
469 typedef struct atbl ARRAY;
470 typedef struct htbl HASH;
471 typedef struct regexp REGEXP;
472 typedef struct stabptrs STBP;
473 typedef struct stab STAB;
474 typedef struct callsave CSV;
488 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
500 EXT char *Yes INIT("1");
501 EXT char *No INIT("");
505 /* Note: cmd.c assumes that it can use && to produce one of these values! */
511 #else /* !CRIPPLED_CC */
512 #define str_true(str) (Str = (str), \
514 ((*Str->str_ptr > '0' || \
515 Str->str_cur > 1 || \
516 (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \
518 (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) ))
519 #endif /* CRIPPLED_CC */
522 #define str_peek(str) (Str = (str), \
526 (sprintf(tokenbuf,"num(%g)",Str->str_u.str_nval), \
535 #define str_get(str) (Str = (str), tainted |= Str->str_tainted, \
536 (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
538 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
540 #endif /* CRIPPLED_CC */
544 #else /* !CRIPPLED_CC */
546 #define str_gnum(str) (Str = (str), tainted |= Str->str_tainted, \
547 (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
549 #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
551 #endif /* CRIPPLED_CC */
554 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
557 #define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len)
558 #define Str_Grow str_grow
560 /* extra parentheses intentionally NOT placed around "len"! */
561 #define STR_GROW(str,len) if ((str)->str_len < (unsigned long)len) \
562 str_grow(str,(unsigned long)len)
563 #define Str_Grow(str,len) str_grow(str,(unsigned long)(len))
567 #define BYTEORDER 0x1234
570 #if defined(htonl) && !defined(HAS_HTONL)
573 #if defined(htons) && !defined(HAS_HTONS)
576 #if defined(ntohl) && !defined(HAS_NTOHL)
579 #if defined(ntohs) && !defined(HAS_NTOHS)
583 #if (BYTEORDER & 0xffff) != 0x4321
589 #define htons my_swap
590 #define htonl my_htonl
591 #define ntohs my_swap
592 #define ntohl my_ntohl
595 #if (BYTEORDER & 0xffff) == 0x4321
604 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
607 #if BYTEORDER != 0x1234
612 # if BYTEORDER == 0x4321
613 # define vtohl(x) ((((x)&0xFF)<<24) \
615 +(((x)&0x0000FF00)<<8) \
616 +(((x)&0x00FF0000)>>8) )
617 # define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
618 # define htovl(x) vtohl(x)
619 # define htovs(x) vtohs(x)
621 /* otherwise default to functions in util.c */
625 #define U_S(what) ((unsigned short)(what))
626 #define U_I(what) ((unsigned int)(what))
627 #define U_L(what) ((unsigned long)(what))
629 unsigned long castulong();
630 #define U_S(what) ((unsigned int)castulong(what))
631 #define U_I(what) ((unsigned int)castulong(what))
632 #define U_L(what) (castulong(what))
677 int eval(); /* this evaluates expressions */
678 int do_eval(); /* this evaluates eval operator */
690 char *str_append_till();
732 EXT char **origenviron;
733 extern char **environ;
735 EXT long subline INIT(0);
736 EXT STR *subname INIT(Nullstr);
737 EXT int arybase INIT(0);
745 EXT struct outrec outrec;
746 EXT struct outrec toprec;
748 EXT STAB *stdinstab INIT(Nullstab);
749 EXT STAB *last_in_stab INIT(Nullstab);
750 EXT STAB *defstab INIT(Nullstab);
751 EXT STAB *argvstab INIT(Nullstab);
752 EXT STAB *envstab INIT(Nullstab);
753 EXT STAB *sigstab INIT(Nullstab);
754 EXT STAB *defoutstab INIT(Nullstab);
755 EXT STAB *curoutstab INIT(Nullstab);
756 EXT STAB *argvoutstab INIT(Nullstab);
757 EXT STAB *incstab INIT(Nullstab);
758 EXT STAB *leftstab INIT(Nullstab);
759 EXT STAB *amperstab INIT(Nullstab);
760 EXT STAB *rightstab INIT(Nullstab);
761 EXT STAB *DBstab INIT(Nullstab);
762 EXT STAB *DBline INIT(Nullstab);
763 EXT STAB *DBsub INIT(Nullstab);
765 EXT HASH *defstash; /* main symbol table */
766 EXT HASH *curstash; /* symbol table for current package */
767 EXT HASH *debstash; /* symbol table for perldb package */
769 EXT STR *curstname; /* name of current package */
771 EXT STR *freestrroot INIT(Nullstr);
772 EXT STR *lastretstr INIT(Nullstr);
773 EXT STR *DBsingle INIT(Nullstr);
774 EXT STR *DBtrace INIT(Nullstr);
775 EXT STR *DBsignal INIT(Nullstr);
780 EXT char *hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
781 EXT char *origfilename;
782 EXT FILE * VOLATILE rsfp;
786 EXT char *oldoldbufptr;
789 EXT STR *linestr INIT(Nullstr);
791 EXT char *rs INIT("\n");
792 EXT int rschar INIT('\n'); /* final char of rs, or 0777 if none */
793 EXT int rslen INIT(1);
794 EXT char *ofs INIT(Nullch);
795 EXT int ofslen INIT(0);
796 EXT char *ors INIT(Nullch);
797 EXT int orslen INIT(0);
798 EXT char *ofmt INIT(Nullch);
799 EXT char *inplace INIT(Nullch);
800 EXT char *nointrp INIT("");
802 EXT bool preprocess INIT(FALSE);
803 EXT bool minus_n INIT(FALSE);
804 EXT bool minus_p INIT(FALSE);
805 EXT bool minus_l INIT(FALSE);
806 EXT bool minus_a INIT(FALSE);
807 EXT bool doswitches INIT(FALSE);
808 EXT bool dowarn INIT(FALSE);
809 EXT bool doextract INIT(FALSE);
810 EXT bool allstabs INIT(FALSE); /* init all customary symbols in symbol table?*/
811 EXT bool sawampersand INIT(FALSE); /* must save all match strings */
812 EXT bool sawstudy INIT(FALSE); /* do fbminstr on all strings */
813 EXT bool sawi INIT(FALSE); /* study must assume case insensitive */
814 EXT bool sawvec INIT(FALSE);
815 EXT bool localizing INIT(FALSE); /* are we processing a local() list? */
820 EXT int maxsysfd INIT(MAXSYSFD); /* top fd to pass to subprocesses */
823 char *cshname INIT(CSH);
828 EXT bool tainted INIT(FALSE); /* using variables controlled by $< */
832 #define TMPPATH "/tmp/perl-eXXXXXX"
834 #define TMPPATH "plXXXXXX"
837 EXT FILE *e_fp INIT(Nullfp);
839 EXT char tokenbuf[256];
840 EXT int expectterm INIT(TRUE); /* how to interpret ambiguous tokens */
841 EXT VOLATILE int in_eval INIT(FALSE); /* trap fatal errors? */
842 EXT int multiline INIT(0); /* $*--do strings hold >1 line? */
843 EXT int forkprocess; /* so do_open |- can return proc# */
844 EXT int do_undump INIT(0); /* -u or dump seen? */
845 EXT int error_count INIT(0); /* how many errors so far, max 10 */
846 EXT int multi_start INIT(0); /* 1st line of multi-line string */
847 EXT int multi_end INIT(0); /* last line of multi-line string */
848 EXT int multi_open INIT(0); /* delimiter of said string */
849 EXT int multi_close INIT(0); /* delimiter of said string */
852 /* char *str_get(); */
859 EXT struct stat statbuf;
860 EXT struct stat statcache;
861 STAB *statstab INIT(Nullstab);
864 EXT struct tms timesbuf;
877 EXT VOLATILE int debug INIT(0);
878 EXT int dlevel INIT(0);
879 EXT int dlmax INIT(128);
884 EXT int perldb INIT(0);
885 #define YYMAXDEPTH 300
887 EXT line_t cmdline INIT(NOLINE);
893 /* runtime control stuff */
896 char *loop_label; /* what the loop was called, if anything */
897 int loop_sp; /* stack pointer to copy stuff down to */
901 EXT int loop_ptr INIT(-1);
902 EXT int loop_max INIT(128);
906 EXT char * VOLATILE goto_targ INIT(Nullch); /* cmd_exec gets strange when set */
914 EXT ARRAY *stack; /* THE STACK */
916 EXT ARRAY * VOLATILE savestack; /* to save non-local values on */
918 EXT ARRAY *tosave; /* strings to save on recursive subroutine */
920 EXT ARRAY *lineary; /* lines of script for debugger */
921 EXT ARRAY *dbargs; /* args to call listed by caller function */
923 EXT ARRAY *fdpid; /* keep fd-to-pid mappings for mypopen */
924 EXT HASH *pidstatus; /* keep pid-to-status mappings for waitpid */
926 EXT int *di; /* for tmp use in debuggers */
930 /* Fix these up for __STDC__ */
931 EXT long basetime INIT(0);
934 /* All of these are in stdlib.h or time.h for ANSI C */
937 struct tm *gmtime(), *localtime();
938 char *index(), *rindex();
939 char *strcpy(), *strcat();
940 #endif /* ! STANDARD_C */
946 #define UNLINK unlink
951 #define setreuid(r,e) setresuid(r,e,-1)
957 #define setregid(r,e) setresgid(r,e,-1)