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