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