perl 3.0 patch #26 patch #19, continued
[p5sagit/p5-mst-13.2.git] / perl.h
1 /* $Header: perl.h,v 3.0.1.8 90/08/09 04:10:53 lwall Locked $
2  *
3  *    Copyright (c) 1989, Larry Wall
4  *
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.
7  *
8  * $Log:        perl.h,v $
9  * Revision 3.0.1.8  90/08/09  04:10:53  lwall
10  * patch19: various MSDOS and OS/2 patches folded in
11  * patch19: did preliminary work toward debugging packages and evals
12  * patch19: added -x switch to extract script from input trash
13  * 
14  * Revision 3.0.1.7  90/03/27  16:12:52  lwall
15  * patch16: MSDOS support
16  * patch16: support for machines that can't cast negative floats to unsigned ints
17  * 
18  * Revision 3.0.1.6  90/03/12  16:40:43  lwall
19  * patch13: did some ndir straightening up for Xenix
20  * 
21  * Revision 3.0.1.5  90/02/28  17:52:28  lwall
22  * patch9: Configure now determines whether volatile is supported
23  * patch9: volatilized some more variables for super-optimizing compilers
24  * patch9: unused VREG symbol deleted
25  * patch9: perl can now start up other interpreters scripts  
26  * patch9: you may now undef $/ to have no input record separator
27  * patch9: nested evals clobbered their longjmp environment
28  * 
29  * Revision 3.0.1.4  89/12/21  20:07:35  lwall
30  * patch7: arranged for certain registers to be restored after longjmp()
31  * patch7: Configure now compiles a test program to figure out time.h fiasco
32  * patch7: Configure now detects DG/UX thingies like [sg]etpgrp2 and utime.h
33  * patch7: memcpy() and memset() return void in __STDC__
34  * patch7: errno may now be a macro with an lvalue
35  * patch7: ANSI strerror() is now supported
36  * patch7: Xenix support for sys/ndir.h, cross compilation
37  * 
38  * Revision 3.0.1.3  89/11/17  15:28:57  lwall
39  * patch5: byteorder now is a hex value
40  * patch5: Configure now looks for <time.h> including <sys/time.h>
41  * 
42  * Revision 3.0.1.2  89/11/11  04:39:38  lwall
43  * patch2: Configure may now set -DDEBUGGING
44  * patch2: netinet/in.h needed sys/types.h some places
45  * patch2: more <sys/time.h> and <time.h> wrangling
46  * patch2: yydebug moved to where type doesn't matter  
47  * 
48  * Revision 3.0.1.1  89/10/26  23:17:08  lwall
49  * patch1: vfork now conditionally defined based on VFORK
50  * patch1: DEC risc machines have a buggy memcmp
51  * patch1: perl.h now includes <netinet/in.h> if it exists
52  * 
53  * Revision 3.0  89/10/18  15:21:21  lwall
54  * 3.0 baseline
55  * 
56  */
57
58 #define VOIDUSED 1
59 #include "config.h"
60
61 #ifdef MSDOS
62 /*
63  * BUGGY_MSC:
64  *      This symbol is defined if you are the unfortunate owner of a buggy
65  *      Microsoft C compiler and want to use intrinsic functions.  Versions
66  *      up to 5.1 are known conform to this definition.  This is not needed
67  *      under Unix.
68  */
69 #define BUGGY_MSC                       /**/
70 /*
71  * BINARY:
72  *      This symbol is defined if you run under an operating system that
73  *      distinguishes between binary and text files.  If so the function
74  *      setmode will be used to set the file into binary mode.  Unix
75  *      doesn't distinguish.
76  */
77 #define BINARY                          /**/
78
79 #else /* !MSDOS */
80
81 /*
82  * The following symbols are defined if your operating system supports
83  * functions by that name.  All Unixes I know of support them, thus they
84  * are not checked by the configuration script, but are directly defined
85  * here.
86  */
87 #define CHOWN
88 #define CHROOT
89 #define FORK
90 #define GETLOGIN
91 #define GETPPID
92 #define KILL
93 #define LINK
94 #define PIPE
95 #define WAIT
96 #define UMASK
97 /*
98  * The following symbols are defined if your operating system supports
99  * password and group functions in general.  All Unix systems do.
100  */
101 #define GROUP
102 #define PASSWD
103
104 #endif /* !MSDOS */
105
106 #if defined(HASVOLATILE) || defined(__STDC__)
107 #define VOLATILE volatile
108 #else
109 #define VOLATILE
110 #endif
111
112 #ifdef IAMSUID
113 #   ifndef TAINT
114 #       define TAINT
115 #   endif
116 #endif
117
118 #ifndef VFORK
119 #   define vfork fork
120 #endif
121
122 #ifdef GETPGRP2
123 #   ifndef GETPGRP
124 #       define GETPGRP
125 #   endif
126 #   define getpgrp getpgrp2
127 #endif
128
129 #ifdef SETPGRP2
130 #   ifndef SETPGRP
131 #       define SETPGRP
132 #   endif
133 #   define setpgrp setpgrp2
134 #endif
135
136 #if defined(MEMCMP) && defined(mips) && BYTEORDER == 0x1234
137 #undef MEMCMP
138 #endif
139
140 #ifdef MEMCPY
141 #ifndef memcpy
142 #if defined(__STDC__ ) || defined(MSDOS)
143 extern void *memcpy(), *memset();
144 #else
145 extern char *memcpy(), *memset();
146 #endif
147 extern int memcmp();
148 #endif
149 #define bcopy(s1,s2,l) memcpy(s2,s1,l)
150 #define bzero(s,l) memset(s,0,l)
151 #endif
152 #ifndef BCMP            /* prefer bcmp slightly 'cuz it doesn't order */
153 #define bcmp(s1,s2,l) memcmp(s1,s2,l)
154 #endif
155
156 #include <stdio.h>
157 #include <ctype.h>
158 #include <setjmp.h>
159 #include <sys/param.h>  /* if this needs types.h we're still wrong */
160
161 #ifndef _TYPES_         /* If types.h defines this it's easy. */
162 #ifndef major           /* Does everyone's types.h define this? */
163 #include <sys/types.h>
164 #endif
165 #endif
166
167 #ifdef I_NETINET_IN
168 #include <netinet/in.h>
169 #endif
170
171 #include <sys/stat.h>
172
173 #ifdef I_TIME
174 #   include <time.h>
175 #endif
176
177 #ifdef I_SYSTIME
178 #   ifdef SYSTIMEKERNEL
179 #       define KERNEL
180 #   endif
181 #   include <sys/time.h>
182 #   ifdef SYSTIMEKERNEL
183 #       undef KERNEL
184 #   endif
185 #endif
186
187 #include <sys/times.h>
188
189 #if defined(STRERROR) && (!defined(MKDIR) || !defined(RMDIR))
190 #undef STRERROR
191 #endif
192
193 #include <errno.h>
194 #ifndef errno
195 extern int errno;     /* ANSI allows errno to be an lvalue expr */
196 #endif
197
198 #ifdef STRERROR
199 char *strerror();
200 #else
201 extern int sys_nerr;
202 extern char *sys_errlist[];
203 #define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
204 #endif
205
206 #ifdef I_SYSIOCTL
207 #ifndef _IOCTL_
208 #include <sys/ioctl.h>
209 #endif
210 #endif
211
212 #if defined(mc300) || defined(mc500) || defined(mc700)  /* MASSCOMP */
213 #ifdef SOCKETPAIR
214 #undef SOCKETPAIR
215 #endif
216 #ifdef NDBM
217 #undef NDBM
218 #endif
219 #endif
220
221 #ifdef NDBM
222 #include <ndbm.h>
223 #define SOME_DBM
224 #ifdef ODBM
225 #undef ODBM
226 #endif
227 #else
228 #ifdef ODBM
229 #ifdef NULL
230 #undef NULL             /* suppress redefinition message */
231 #endif
232 #include <dbm.h>
233 #ifdef NULL
234 #undef NULL
235 #endif
236 #define NULL 0          /* silly thing is, we don't even use this */
237 #define SOME_DBM
238 #define dbm_fetch(db,dkey) fetch(dkey)
239 #define dbm_delete(db,dkey) delete(dkey)
240 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
241 #define dbm_close(db) dbmclose()
242 #define dbm_firstkey(db) firstkey()
243 #endif /* ODBM */
244 #endif /* NDBM */
245 #ifdef SOME_DBM
246 EXT char *dbmkey;
247 EXT int dbmlen;
248 #endif
249
250 #if INTSIZE == 2
251 #define htoni htons
252 #define ntohi ntohs
253 #else
254 #define htoni htonl
255 #define ntohi ntohl
256 #endif
257
258 #if defined(I_DIRENT) && !defined(M_XENIX)
259 #   include <dirent.h>
260 #   define DIRENT dirent
261 #else
262 #   ifdef I_SYSNDIR
263 #       include <sys/ndir.h>
264 #       define DIRENT direct
265 #   else
266 #       ifdef I_SYSDIR
267 #           ifdef hp9000s500
268 #               include <ndir.h>        /* may be wrong in the future */
269 #           else
270 #               include <sys/dir.h>
271 #           endif
272 #           define DIRENT direct
273 #       endif
274 #   endif
275 #endif
276
277 typedef unsigned int STRLEN;
278
279 typedef struct arg ARG;
280 typedef struct cmd CMD;
281 typedef struct formcmd FCMD;
282 typedef struct scanpat SPAT;
283 typedef struct stio STIO;
284 typedef struct sub SUBR;
285 typedef struct string STR;
286 typedef struct atbl ARRAY;
287 typedef struct htbl HASH;
288 typedef struct regexp REGEXP;
289 typedef struct stabptrs STBP;
290 typedef struct stab STAB;
291
292 #include "handy.h"
293 #include "regexp.h"
294 #include "str.h"
295 #include "util.h"
296 #include "form.h"
297 #include "stab.h"
298 #include "spat.h"
299 #include "arg.h"
300 #include "cmd.h"
301 #include "array.h"
302 #include "hash.h"
303
304 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
305 #   define I286
306 #endif
307
308 #ifndef __STDC__
309 #ifdef CHARSPRINTF
310     char *sprintf();
311 #else
312     int sprintf();
313 #endif
314 #endif
315
316 EXT char *Yes INIT("1");
317 EXT char *No INIT("");
318
319 /* "gimme" values */
320
321 /* Note: cmd.c assumes that it can use && to produce one of these values! */
322 #define G_SCALAR 0
323 #define G_ARRAY 1
324
325 #ifdef CRIPPLED_CC
326 int str_true();
327 #else /* !CRIPPLED_CC */
328 #define str_true(str) (Str = (str), \
329         (Str->str_pok ? \
330             ((*Str->str_ptr > '0' || \
331               Str->str_cur > 1 || \
332               (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \
333         : \
334             (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) ))
335 #endif /* CRIPPLED_CC */
336
337 #ifdef DEBUGGING
338 #define str_peek(str) (Str = (str), \
339         (Str->str_pok ? \
340             Str->str_ptr : \
341             (Str->str_nok ? \
342                 (sprintf(tokenbuf,"num(%g)",Str->str_u.str_nval), \
343                     (char*)tokenbuf) : \
344                 "" )))
345 #endif
346
347 #ifdef CRIPPLED_CC
348 char *str_get();
349 #else
350 #ifdef TAINT
351 #define str_get(str) (Str = (str), tainted |= Str->str_tainted, \
352         (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
353 #else
354 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
355 #endif /* TAINT */
356 #endif /* CRIPPLED_CC */
357
358 #ifdef CRIPPLED_CC
359 double str_gnum();
360 #else /* !CRIPPLED_CC */
361 #ifdef TAINT
362 #define str_gnum(str) (Str = (str), tainted |= Str->str_tainted, \
363         (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
364 #else /* !TAINT */
365 #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
366 #endif /* TAINT*/
367 #endif /* CRIPPLED_CC */
368 EXT STR *Str;
369
370 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
371
372 #ifndef MSDOS
373 #define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len)
374 #define Str_Grow str_grow
375 #else
376 /* extra parentheses intentionally NOT placed around "len"! */
377 #define STR_GROW(str,len) if ((str)->str_len < (unsigned long)len) \
378                 str_grow(str,(unsigned long)len)
379 #define Str_Grow(str,len) str_grow(str,(unsigned long)(len))
380 #endif /* MSDOS */
381
382 #ifndef BYTEORDER
383 #define BYTEORDER 0x1234
384 #endif
385
386 #if defined(htonl) && !defined(HTONL)
387 #define HTONL
388 #endif
389 #if defined(htons) && !defined(HTONS)
390 #define HTONS
391 #endif
392 #if defined(ntohl) && !defined(NTOHL)
393 #define NTOHL
394 #endif
395 #if defined(ntohs) && !defined(NTOHS)
396 #define NTOHS
397 #endif
398 #ifndef HTONL
399 #if (BYTEORDER != 0x4321) && (BYTEORDER != 0x87654321)
400 #define HTONS
401 #define HTONL
402 #define NTOHS
403 #define NTOHL
404 #define MYSWAP
405 #define htons my_swap
406 #define htonl my_htonl
407 #define ntohs my_swap
408 #define ntohl my_ntohl
409 #endif
410 #else
411 #if (BYTEORDER == 0x4321) || (BYTEORDER == 0x87654321)
412 #undef HTONS
413 #undef HTONL
414 #undef NTOHS
415 #undef NTOHL
416 #endif
417 #endif
418
419 #ifdef CASTNEGFLOAT
420 #define U_S(what) ((unsigned short)(what))
421 #define U_I(what) ((unsigned int)(what))
422 #define U_L(what) ((unsigned long)(what))
423 #else
424 unsigned long castulong();
425 #define U_S(what) ((unsigned int)castulong(what))
426 #define U_I(what) ((unsigned int)castulong(what))
427 #define U_L(what) (castulong(what))
428 #endif
429
430 CMD *add_label();
431 CMD *block_head();
432 CMD *append_line();
433 CMD *make_acmd();
434 CMD *make_ccmd();
435 CMD *make_icmd();
436 CMD *invert();
437 CMD *addcond();
438 CMD *addloop();
439 CMD *wopt();
440 CMD *over();
441
442 STAB *stabent();
443 STAB *genstab();
444
445 ARG *stab2arg();
446 ARG *op_new();
447 ARG *make_op();
448 ARG *make_match();
449 ARG *make_split();
450 ARG *rcatmaybe();
451 ARG *listish();
452 ARG *maybelistish();
453 ARG *localize();
454 ARG *fixeval();
455 ARG *jmaybe();
456 ARG *l();
457 ARG *fixl();
458 ARG *mod_match();
459 ARG *make_list();
460 ARG *cmd_to_arg();
461 ARG *addflags();
462 ARG *hide_ary();
463 ARG *cval_to_arg();
464
465 STR *str_new();
466 STR *stab_str();
467
468 int do_each();
469 int do_subr();
470 int do_match();
471 int do_unpack();
472 int eval();             /* this evaluates expressions */
473 int do_eval();          /* this evaluates eval operator */
474 int do_assign();
475
476 SUBR *make_sub();
477
478 FCMD *load_format();
479
480 char *scanpat();
481 char *scansubst();
482 char *scantrans();
483 char *scanstr();
484 char *scanreg();
485 char *str_append_till();
486 char *str_gets();
487 char *str_grow();
488
489 bool do_open();
490 bool do_close();
491 bool do_print();
492 bool do_aprint();
493 bool do_exec();
494 bool do_aexec();
495
496 int do_subst();
497 int cando();
498 int ingroup();
499
500 void str_replace();
501 void str_inc();
502 void str_dec();
503 void str_free();
504 void stab_clear();
505 void do_join();
506 void do_sprintf();
507 void do_accept();
508 void do_pipe();
509 void do_vecset();
510 void savelist();
511 void saveitem();
512 void saveint();
513 void savelong();
514 void savesptr();
515 void savehptr();
516 void restorelist();
517 void repeatcpy();
518 HASH *savehash();
519 ARRAY *saveary();
520
521 EXT char **origargv;
522 EXT int origargc;
523 EXT line_t subline INIT(0);
524 EXT STR *subname INIT(Nullstr);
525 EXT int arybase INIT(0);
526
527 struct outrec {
528     line_t  o_lines;
529     char    *o_str;
530     int     o_len;
531 };
532
533 EXT struct outrec outrec;
534 EXT struct outrec toprec;
535
536 EXT STAB *stdinstab INIT(Nullstab);
537 EXT STAB *last_in_stab INIT(Nullstab);
538 EXT STAB *defstab INIT(Nullstab);
539 EXT STAB *argvstab INIT(Nullstab);
540 EXT STAB *envstab INIT(Nullstab);
541 EXT STAB *sigstab INIT(Nullstab);
542 EXT STAB *defoutstab INIT(Nullstab);
543 EXT STAB *curoutstab INIT(Nullstab);
544 EXT STAB *argvoutstab INIT(Nullstab);
545 EXT STAB *incstab INIT(Nullstab);
546 EXT STAB *leftstab INIT(Nullstab);
547 EXT STAB *amperstab INIT(Nullstab);
548 EXT STAB *rightstab INIT(Nullstab);
549 EXT STAB *DBstab INIT(Nullstab);
550 EXT STAB *DBsub INIT(Nullstab);
551
552 EXT HASH *defstash;             /* main symbol table */
553 EXT HASH *curstash;             /* symbol table for current package */
554 EXT HASH *debstash;             /* symbol table for perldb package */
555
556 EXT STR *curstname;             /* name of current package */
557
558 EXT STR *freestrroot INIT(Nullstr);
559 EXT STR *lastretstr INIT(Nullstr);
560 EXT STR *DBsingle INIT(Nullstr);
561
562 EXT int lastspbase;
563 EXT int lastsize;
564
565 EXT char *curpack;
566 EXT char *filename;
567 EXT char *origfilename;
568 EXT FILE * VOLATILE rsfp;
569 EXT char buf[1024];
570 EXT char *bufptr;
571 EXT char *oldbufptr;
572 EXT char *oldoldbufptr;
573 EXT char *bufend;
574
575 EXT STR *linestr INIT(Nullstr);
576
577 EXT int record_separator INIT('\n');
578 EXT int rslen INIT(1);
579 EXT char *ofs INIT(Nullch);
580 EXT int ofslen INIT(0);
581 EXT char *ors INIT(Nullch);
582 EXT int orslen INIT(0);
583 EXT char *ofmt INIT(Nullch);
584 EXT char *inplace INIT(Nullch);
585 EXT char *nointrp INIT("");
586
587 EXT bool preprocess INIT(FALSE);
588 EXT bool minus_n INIT(FALSE);
589 EXT bool minus_p INIT(FALSE);
590 EXT bool minus_a INIT(FALSE);
591 EXT bool doswitches INIT(FALSE);
592 EXT bool dowarn INIT(FALSE);
593 EXT bool doextract INIT(FALSE);
594 EXT bool allstabs INIT(FALSE);  /* init all customary symbols in symbol table?*/
595 EXT bool sawampersand INIT(FALSE);      /* must save all match strings */
596 EXT bool sawstudy INIT(FALSE);          /* do fbminstr on all strings */
597 EXT bool sawi INIT(FALSE);              /* study must assume case insensitive */
598 EXT bool sawvec INIT(FALSE);
599 EXT bool localizing INIT(FALSE);        /* are we processing a local() list? */
600
601 #ifdef CSH
602 char *cshname INIT(CSH);
603 int cshlen INIT(0);
604 #endif /* CSH */
605
606 #ifdef TAINT
607 EXT bool tainted INIT(FALSE);           /* using variables controlled by $< */
608 #endif
609
610 #ifndef MSDOS
611 #define TMPPATH "/tmp/perl-eXXXXXX"
612 #else
613 #define TMPPATH "/tmp/plXXXXXX"
614 #endif /* MSDOS */
615 EXT char *e_tmpname;
616 EXT FILE *e_fp INIT(Nullfp);
617
618 EXT char tokenbuf[256];
619 EXT int expectterm INIT(TRUE);          /* how to interpret ambiguous tokens */
620 EXT VOLATILE int in_eval INIT(FALSE);   /* trap fatal errors? */
621 EXT int multiline INIT(0);              /* $*--do strings hold >1 line? */
622 EXT int forkprocess;                    /* so do_open |- can return proc# */
623 EXT int do_undump INIT(0);              /* -u or dump seen? */
624 EXT int error_count INIT(0);            /* how many errors so far, max 10 */
625 EXT int multi_start INIT(0);            /* 1st line of multi-line string */
626 EXT int multi_end INIT(0);              /* last line of multi-line string */
627 EXT int multi_open INIT(0);             /* delimiter of said string */
628 EXT int multi_close INIT(0);            /* delimiter of said string */
629
630 FILE *popen();
631 /* char *str_get(); */
632 STR *interp();
633 void free_arg();
634 STIO *stio_new();
635
636 EXT struct stat statbuf;
637 EXT struct stat statcache;
638 STAB *statstab INIT(Nullstab);
639 STR *statname;
640 EXT struct tms timesbuf;
641 EXT int uid;
642 EXT int euid;
643 EXT int gid;
644 EXT int egid;
645 UIDTYPE getuid();
646 UIDTYPE geteuid();
647 GIDTYPE getgid();
648 GIDTYPE getegid();
649 EXT int unsafe;
650
651 #ifdef DEBUGGING
652 EXT VOLATILE int debug INIT(0);
653 EXT int dlevel INIT(0);
654 EXT int dlmax INIT(128);
655 EXT char *debname;
656 EXT char *debdelim;
657 #define YYDEBUG 1
658 #endif
659 EXT int perldb INIT(0);
660
661 EXT line_t cmdline INIT(NOLINE);
662
663 EXT STR str_undef;
664 EXT STR str_no;
665 EXT STR str_yes;
666
667 /* runtime control stuff */
668
669 EXT struct loop {
670     char *loop_label;           /* what the loop was called, if anything */
671     int loop_sp;                /* stack pointer to copy stuff down to */
672     jmp_buf loop_env;
673 } *loop_stack;
674
675 EXT int loop_ptr INIT(-1);
676 EXT int loop_max INIT(128);
677
678 EXT jmp_buf top_env;
679
680 EXT char * VOLATILE goto_targ INIT(Nullch); /* cmd_exec gets strange when set */
681
682 struct ufuncs {
683     int (*uf_val)();
684     int (*uf_set)();
685     int uf_index;
686 };
687
688 EXT ARRAY *stack;               /* THE STACK */
689
690 EXT ARRAY * VOLATILE savestack;         /* to save non-local values on */
691
692 EXT ARRAY *tosave;              /* strings to save on recursive subroutine */
693
694 EXT ARRAY *lineary;             /* lines of script for debugger */
695
696 EXT ARRAY *pidstatary;          /* keep pids and statuses by fd for mypopen */
697
698 EXT int *di;                    /* for tmp use in debuggers */
699 EXT char *dc;
700 EXT short *ds;
701
702 double atof();
703 long time();
704 struct tm *gmtime(), *localtime();
705 char *mktemp();
706 char *index(), *rindex();
707 char *strcpy(), *strcat();
708
709 #ifdef EUNICE
710 #define UNLINK unlnk
711 int unlnk();
712 #else
713 #define UNLINK unlink
714 #endif
715
716 #ifndef SETREUID
717 #ifdef SETRESUID
718 #define setreuid(r,e) setresuid(r,e,-1)
719 #define SETREUID
720 #endif
721 #endif
722 #ifndef SETREGID
723 #ifdef SETRESGID
724 #define setregid(r,e) setresgid(r,e,-1)
725 #define SETREGID
726 #endif
727 #endif