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