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