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