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