Commit | Line | Data |
ae986130 |
1 | /* $Header: perl.h,v 3.0.1.2 89/11/11 04:39:38 lwall Locked $ |
a687059c |
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 |
7 | * |
8 | * $Log: perl.h,v $ |
ae986130 |
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 |
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 |
20 | * Revision 3.0 89/10/18 15:21:21 lwall |
21 | * 3.0 baseline |
8d063cd8 |
22 | * |
23 | */ |
24 | |
8d063cd8 |
25 | #define VOIDUSED 1 |
26 | #include "config.h" |
27 | |
a687059c |
28 | #ifdef IAMSUID |
29 | # ifndef TAINT |
30 | # define TAINT |
31 | # endif |
32 | #endif |
33 | |
03a14243 |
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 |
42 | #ifdef MEMCPY |
43 | extern char *memcpy(), *memset(); |
a687059c |
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 |
49 | #endif |
50 | |
51 | #include <stdio.h> |
52 | #include <ctype.h> |
53 | #include <setjmp.h> |
378cc40b |
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 |
59 | #endif |
60 | #endif |
61 | |
ae986130 |
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 |
73 | #else |
74 | #include <time.h> |
a687059c |
75 | #endif |
135863df |
76 | |
8d063cd8 |
77 | #include <sys/times.h> |
78 | |
a687059c |
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 |
97 | #ifdef ODBM |
98 | #undef ODBM |
99 | #endif |
a687059c |
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 |
119 | EXT char *dbmkey; |
120 | EXT 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 |
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 |
141 | #define DIRENT direct |
142 | #endif |
143 | #endif |
144 | |
8d063cd8 |
145 | typedef struct arg ARG; |
146 | typedef struct cmd CMD; |
147 | typedef struct formcmd FCMD; |
148 | typedef struct scanpat SPAT; |
8d063cd8 |
149 | typedef struct stio STIO; |
378cc40b |
150 | typedef struct sub SUBR; |
8d063cd8 |
151 | typedef struct string STR; |
152 | typedef struct atbl ARRAY; |
153 | typedef struct htbl HASH; |
378cc40b |
154 | typedef struct regexp REGEXP; |
a687059c |
155 | typedef struct stabptrs STBP; |
156 | typedef struct stab STAB; |
8d063cd8 |
157 | |
378cc40b |
158 | #include "handy.h" |
159 | #include "regexp.h" |
8d063cd8 |
160 | #include "str.h" |
378cc40b |
161 | #include "util.h" |
8d063cd8 |
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 |
170 | #if defined(iAPX286) || defined(M_I286) || defined(I80286) |
171 | # define I286 |
172 | #endif |
173 | |
174 | #ifndef __STDC__ |
135863df |
175 | #ifdef CHARSPRINTF |
176 | char *sprintf(); |
177 | #else |
178 | int sprintf(); |
179 | #endif |
a687059c |
180 | #endif |
135863df |
181 | |
8d063cd8 |
182 | EXT char *Yes INIT("1"); |
183 | EXT char *No INIT(""); |
184 | |
a687059c |
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 |
192 | int 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 |
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 |
211 | #endif |
212 | |
a687059c |
213 | #ifdef CRIPPLED_CC |
214 | char *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 |
221 | #endif /* TAINT */ |
222 | #endif /* CRIPPLED_CC */ |
223 | |
224 | #ifdef CRIPPLED_CC |
225 | double 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 |
234 | EXT STR *Str; |
235 | |
236 | #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len) |
237 | |
a687059c |
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 |
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 |
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 |
270 | #undef HTONS |
271 | #undef HTONL |
272 | #undef NTOHS |
273 | #undef NTOHL |
274 | #endif |
275 | #endif |
276 | |
8d063cd8 |
277 | CMD *add_label(); |
278 | CMD *block_head(); |
279 | CMD *append_line(); |
280 | CMD *make_acmd(); |
281 | CMD *make_ccmd(); |
a687059c |
282 | CMD *make_icmd(); |
8d063cd8 |
283 | CMD *invert(); |
284 | CMD *addcond(); |
285 | CMD *addloop(); |
286 | CMD *wopt(); |
378cc40b |
287 | CMD *over(); |
8d063cd8 |
288 | |
8d063cd8 |
289 | STAB *stabent(); |
378cc40b |
290 | STAB *genstab(); |
8d063cd8 |
291 | |
378cc40b |
292 | ARG *stab2arg(); |
8d063cd8 |
293 | ARG *op_new(); |
294 | ARG *make_op(); |
8d063cd8 |
295 | ARG *make_match(); |
296 | ARG *make_split(); |
a687059c |
297 | ARG *rcatmaybe(); |
378cc40b |
298 | ARG *listish(); |
a687059c |
299 | ARG *maybelistish(); |
378cc40b |
300 | ARG *localize(); |
a687059c |
301 | ARG *fixeval(); |
302 | ARG *jmaybe(); |
378cc40b |
303 | ARG *l(); |
a687059c |
304 | ARG *fixl(); |
378cc40b |
305 | ARG *mod_match(); |
306 | ARG *make_list(); |
307 | ARG *cmd_to_arg(); |
308 | ARG *addflags(); |
309 | ARG *hide_ary(); |
310 | ARG *cval_to_arg(); |
8d063cd8 |
311 | |
8d063cd8 |
312 | STR *str_new(); |
313 | STR *stab_str(); |
a687059c |
314 | |
315 | int do_each(); |
316 | int do_subr(); |
317 | int do_match(); |
318 | int do_unpack(); |
319 | int eval(); /* this evaluates expressions */ |
320 | int do_eval(); /* this evaluates eval operator */ |
321 | int do_assign(); |
378cc40b |
322 | |
323 | SUBR *make_sub(); |
8d063cd8 |
324 | |
325 | FCMD *load_format(); |
326 | |
327 | char *scanpat(); |
328 | char *scansubst(); |
329 | char *scantrans(); |
330 | char *scanstr(); |
331 | char *scanreg(); |
8d063cd8 |
332 | char *str_append_till(); |
333 | char *str_gets(); |
a687059c |
334 | char *str_grow(); |
8d063cd8 |
335 | |
8d063cd8 |
336 | bool do_open(); |
337 | bool do_close(); |
338 | bool do_print(); |
378cc40b |
339 | bool do_aprint(); |
340 | bool do_exec(); |
341 | bool do_aexec(); |
8d063cd8 |
342 | |
343 | int do_subst(); |
378cc40b |
344 | int cando(); |
345 | int ingroup(); |
8d063cd8 |
346 | |
378cc40b |
347 | void str_replace(); |
348 | void str_inc(); |
349 | void str_dec(); |
8d063cd8 |
350 | void str_free(); |
a687059c |
351 | void stab_clear(); |
378cc40b |
352 | void do_join(); |
378cc40b |
353 | void do_sprintf(); |
a687059c |
354 | void do_accept(); |
355 | void do_vecset(); |
356 | void savelist(); |
357 | void saveitem(); |
358 | void saveint(); |
359 | void savelong(); |
360 | void savesptr(); |
361 | void savehptr(); |
362 | void restorelist(); |
363 | HASH *savehash(); |
364 | ARRAY *saveary(); |
378cc40b |
365 | |
366 | EXT line_t line INIT(0); |
a687059c |
367 | EXT line_t subline INIT(0); |
368 | EXT STR *subname INIT(Nullstr); |
8d063cd8 |
369 | EXT int arybase INIT(0); |
370 | |
371 | struct outrec { |
378cc40b |
372 | line_t o_lines; |
373 | char *o_str; |
374 | int o_len; |
8d063cd8 |
375 | }; |
376 | |
377 | EXT struct outrec outrec; |
378 | EXT struct outrec toprec; |
379 | |
a687059c |
380 | EXT STAB *stdinstab INIT(Nullstab); |
8d063cd8 |
381 | EXT STAB *last_in_stab INIT(Nullstab); |
382 | EXT STAB *defstab INIT(Nullstab); |
383 | EXT STAB *argvstab INIT(Nullstab); |
384 | EXT STAB *envstab INIT(Nullstab); |
385 | EXT STAB *sigstab INIT(Nullstab); |
386 | EXT STAB *defoutstab INIT(Nullstab); |
387 | EXT STAB *curoutstab INIT(Nullstab); |
388 | EXT STAB *argvoutstab INIT(Nullstab); |
378cc40b |
389 | EXT STAB *incstab INIT(Nullstab); |
a687059c |
390 | EXT STAB *leftstab INIT(Nullstab); |
391 | EXT STAB *amperstab INIT(Nullstab); |
392 | EXT STAB *rightstab INIT(Nullstab); |
393 | EXT STAB *DBstab INIT(Nullstab); |
394 | EXT STAB *DBsub INIT(Nullstab); |
395 | |
396 | EXT HASH *defstash; /* main symbol table */ |
397 | EXT HASH *curstash; /* symbol table for current package */ |
398 | EXT HASH *debstash; /* symbol table for perldb package */ |
399 | |
400 | EXT STR *curstname; /* name of current package */ |
8d063cd8 |
401 | |
402 | EXT STR *freestrroot INIT(Nullstr); |
378cc40b |
403 | EXT STR *lastretstr INIT(Nullstr); |
a687059c |
404 | EXT STR *DBsingle INIT(Nullstr); |
405 | |
406 | EXT int lastspbase; |
407 | EXT int lastsize; |
8d063cd8 |
408 | |
378cc40b |
409 | EXT char *filename; |
410 | EXT char *origfilename; |
8d063cd8 |
411 | EXT FILE *rsfp; |
412 | EXT char buf[1024]; |
a687059c |
413 | EXT char *bufptr; |
414 | EXT char *oldbufptr; |
415 | EXT char *oldoldbufptr; |
416 | EXT char *bufend; |
8d063cd8 |
417 | |
418 | EXT STR *linestr INIT(Nullstr); |
419 | |
420 | EXT char record_separator INIT('\n'); |
a687059c |
421 | EXT int rslen INIT(1); |
8d063cd8 |
422 | EXT char *ofs INIT(Nullch); |
a687059c |
423 | EXT int ofslen INIT(0); |
8d063cd8 |
424 | EXT char *ors INIT(Nullch); |
a687059c |
425 | EXT int orslen INIT(0); |
8d063cd8 |
426 | EXT char *ofmt INIT(Nullch); |
427 | EXT char *inplace INIT(Nullch); |
a687059c |
428 | EXT char *nointrp INIT(""); |
8d063cd8 |
429 | |
378cc40b |
430 | EXT bool preprocess INIT(FALSE); |
431 | EXT bool minus_n INIT(FALSE); |
432 | EXT bool minus_p INIT(FALSE); |
433 | EXT bool minus_a INIT(FALSE); |
434 | EXT bool doswitches INIT(FALSE); |
435 | EXT bool dowarn INIT(FALSE); |
436 | EXT bool allstabs INIT(FALSE); /* init all customary symbols in symbol table?*/ |
437 | EXT bool sawampersand INIT(FALSE); /* must save all match strings */ |
438 | EXT bool sawstudy INIT(FALSE); /* do fbminstr on all strings */ |
a687059c |
439 | EXT bool sawi INIT(FALSE); /* study must assume case insensitive */ |
440 | EXT bool sawvec INIT(FALSE); |
441 | |
ae986130 |
442 | #ifdef CSH |
443 | char *cshname INIT(CSH); |
444 | int cshlen INIT(0); |
445 | #endif /* CSH */ |
a687059c |
446 | |
447 | #ifdef TAINT |
448 | EXT bool tainted INIT(FALSE); /* using variables controlled by $< */ |
449 | #endif |
378cc40b |
450 | |
451 | #define TMPPATH "/tmp/perl-eXXXXXX" |
452 | EXT char *e_tmpname; |
453 | EXT FILE *e_fp INIT(Nullfp); |
454 | |
8d063cd8 |
455 | EXT char tokenbuf[256]; |
a687059c |
456 | EXT int expectterm INIT(TRUE); /* how to interpret ambiguous tokens */ |
457 | EXT int in_eval INIT(FALSE); /* trap fatal errors? */ |
458 | EXT int multiline INIT(0); /* $*--do strings hold >1 line? */ |
459 | EXT int forkprocess; /* so do_open |- can return proc# */ |
460 | EXT int do_undump INIT(0); /* -u or dump seen? */ |
461 | EXT int error_count INIT(0); /* how many errors so far, max 10 */ |
462 | EXT int multi_start INIT(0); /* 1st line of multi-line string */ |
463 | EXT int multi_end INIT(0); /* last line of multi-line string */ |
464 | EXT int multi_open INIT(0); /* delimiter of said string */ |
465 | EXT int multi_close INIT(0); /* delimiter of said string */ |
8d063cd8 |
466 | |
467 | FILE *popen(); |
468 | /* char *str_get(); */ |
469 | STR *interp(); |
470 | void free_arg(); |
471 | STIO *stio_new(); |
472 | |
473 | EXT struct stat statbuf; |
a687059c |
474 | EXT struct stat statcache; |
475 | STAB *statstab INIT(Nullstab); |
476 | STR *statname; |
8d063cd8 |
477 | EXT struct tms timesbuf; |
378cc40b |
478 | EXT int uid; |
479 | EXT int euid; |
a687059c |
480 | EXT int gid; |
481 | EXT int egid; |
378cc40b |
482 | UIDTYPE getuid(); |
483 | UIDTYPE geteuid(); |
484 | GIDTYPE getgid(); |
485 | GIDTYPE getegid(); |
486 | EXT int unsafe; |
8d063cd8 |
487 | |
488 | #ifdef DEBUGGING |
489 | EXT int debug INIT(0); |
490 | EXT int dlevel INIT(0); |
a687059c |
491 | EXT int dlmax INIT(128); |
492 | EXT char *debname; |
493 | EXT char *debdelim; |
d96024cf |
494 | #define YYDEBUG 1 |
8d063cd8 |
495 | #endif |
a687059c |
496 | EXT int perldb INIT(0); |
8d063cd8 |
497 | |
378cc40b |
498 | EXT line_t cmdline INIT(NOLINE); |
499 | |
a687059c |
500 | EXT STR str_undef; |
8d063cd8 |
501 | EXT STR str_no; |
502 | EXT STR str_yes; |
503 | |
504 | /* runtime control stuff */ |
505 | |
506 | EXT struct loop { |
a687059c |
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 |
511 | |
512 | EXT int loop_ptr INIT(-1); |
a687059c |
513 | EXT int loop_max INIT(128); |
8d063cd8 |
514 | |
515 | EXT jmp_buf top_env; |
a559c259 |
516 | EXT jmp_buf eval_env; |
8d063cd8 |
517 | |
518 | EXT char *goto_targ INIT(Nullch); /* cmd_exec gets strange when set */ |
519 | |
a687059c |
520 | EXT ARRAY *stack; /* THE STACK */ |
521 | |
378cc40b |
522 | EXT ARRAY *savestack; /* to save non-local values on */ |
523 | |
524 | EXT ARRAY *tosave; /* strings to save on recursive subroutine */ |
525 | |
a687059c |
526 | EXT ARRAY *lineary; /* lines of script for debugger */ |
527 | |
528 | EXT ARRAY *pidstatary; /* keep pids and statuses by fd for mypopen */ |
529 | |
8d063cd8 |
530 | double atof(); |
a687059c |
531 | long time(); |
8d063cd8 |
532 | struct tm *gmtime(), *localtime(); |
378cc40b |
533 | char *mktemp(); |
534 | char *index(), *rindex(); |
535 | char *strcpy(), *strcat(); |
8d063cd8 |
536 | |
8d063cd8 |
537 | #ifdef EUNICE |
378cc40b |
538 | #define UNLINK unlnk |
539 | int unlnk(); |
8d063cd8 |
540 | #else |
541 | #define UNLINK unlink |
542 | #endif |
a687059c |
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 |