perl 3.0 patch #4 Patch #2 continued
[p5sagit/p5-mst-13.2.git] / perl.h
1 /* $Header: perl.h,v 3.0.1.2 89/11/11 04:39:38 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.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  * 
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  * 
20  * Revision 3.0  89/10/18  15:21:21  lwall
21  * 3.0 baseline
22  * 
23  */
24
25 #define VOIDUSED 1
26 #include "config.h"
27
28 #ifdef IAMSUID
29 #   ifndef TAINT
30 #       define TAINT
31 #   endif
32 #endif
33
34 #ifndef VFORK
35 #   define vfork fork
36 #endif
37
38 #if defined(MEMCMP) && defined(mips) && BYTEORDER == 01234
39 #undef MEMCMP
40 #endif
41
42 #ifdef MEMCPY
43 extern char *memcpy(), *memset();
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)
49 #endif
50
51 #include <stdio.h>
52 #include <ctype.h>
53 #include <setjmp.h>
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? */
58 #include <sys/types.h>
59 #endif
60 #endif
61
62 #ifdef I_NETINET_IN
63 #include <netinet/in.h>
64 #endif
65
66 #include <sys/stat.h>
67
68 #if defined(TMINSYS) || defined(I_SYSTIME)
69 #include <sys/time.h>
70 #ifdef TIMETOO
71 #include <time.h>
72 #endif
73 #else
74 #include <time.h>
75 #endif
76
77 #include <sys/times.h>
78
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
97 #ifdef ODBM
98 #undef ODBM
99 #endif
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
136 #ifdef hp9000s500
137 #include <ndir.h>       /* may be wrong in the future */
138 #else
139 #include <sys/dir.h>
140 #endif
141 #define DIRENT direct
142 #endif
143 #endif
144
145 typedef struct arg ARG;
146 typedef struct cmd CMD;
147 typedef struct formcmd FCMD;
148 typedef struct scanpat SPAT;
149 typedef struct stio STIO;
150 typedef struct sub SUBR;
151 typedef struct string STR;
152 typedef struct atbl ARRAY;
153 typedef struct htbl HASH;
154 typedef struct regexp REGEXP;
155 typedef struct stabptrs STBP;
156 typedef struct stab STAB;
157
158 #include "handy.h"
159 #include "regexp.h"
160 #include "str.h"
161 #include "util.h"
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
170 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
171 #   define I286
172 #endif
173
174 #ifndef __STDC__
175 #ifdef CHARSPRINTF
176     char *sprintf();
177 #else
178     int sprintf();
179 #endif
180 #endif
181
182 EXT char *Yes INIT("1");
183 EXT char *No INIT("");
184
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 */
202
203 #ifdef DEBUGGING
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                 "" )))
211 #endif
212
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
220 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
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 */
234 EXT STR *Str;
235
236 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
237
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
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
256 #ifndef HTONL
257 #if (BYTEORDER != 04321) && (BYTEORDER != 087654321)
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
269 #if (BYTEORDER == 04321) || (BYTEORDER == 087654321)
270 #undef HTONS
271 #undef HTONL
272 #undef NTOHS
273 #undef NTOHL
274 #endif
275 #endif
276
277 CMD *add_label();
278 CMD *block_head();
279 CMD *append_line();
280 CMD *make_acmd();
281 CMD *make_ccmd();
282 CMD *make_icmd();
283 CMD *invert();
284 CMD *addcond();
285 CMD *addloop();
286 CMD *wopt();
287 CMD *over();
288
289 STAB *stabent();
290 STAB *genstab();
291
292 ARG *stab2arg();
293 ARG *op_new();
294 ARG *make_op();
295 ARG *make_match();
296 ARG *make_split();
297 ARG *rcatmaybe();
298 ARG *listish();
299 ARG *maybelistish();
300 ARG *localize();
301 ARG *fixeval();
302 ARG *jmaybe();
303 ARG *l();
304 ARG *fixl();
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();
311
312 STR *str_new();
313 STR *stab_str();
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();
322
323 SUBR *make_sub();
324
325 FCMD *load_format();
326
327 char *scanpat();
328 char *scansubst();
329 char *scantrans();
330 char *scanstr();
331 char *scanreg();
332 char *str_append_till();
333 char *str_gets();
334 char *str_grow();
335
336 bool do_open();
337 bool do_close();
338 bool do_print();
339 bool do_aprint();
340 bool do_exec();
341 bool do_aexec();
342
343 int do_subst();
344 int cando();
345 int ingroup();
346
347 void str_replace();
348 void str_inc();
349 void str_dec();
350 void str_free();
351 void stab_clear();
352 void do_join();
353 void do_sprintf();
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();
365
366 EXT line_t line INIT(0);
367 EXT line_t subline INIT(0);
368 EXT STR *subname INIT(Nullstr);
369 EXT int arybase INIT(0);
370
371 struct outrec {
372     line_t  o_lines;
373     char    *o_str;
374     int     o_len;
375 };
376
377 EXT struct outrec outrec;
378 EXT struct outrec toprec;
379
380 EXT STAB *stdinstab INIT(Nullstab);
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);
389 EXT STAB *incstab INIT(Nullstab);
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 */
401
402 EXT STR *freestrroot INIT(Nullstr);
403 EXT STR *lastretstr INIT(Nullstr);
404 EXT STR *DBsingle INIT(Nullstr);
405
406 EXT int lastspbase;
407 EXT int lastsize;
408
409 EXT char *filename;
410 EXT char *origfilename;
411 EXT FILE *rsfp;
412 EXT char buf[1024];
413 EXT char *bufptr;
414 EXT char *oldbufptr;
415 EXT char *oldoldbufptr;
416 EXT char *bufend;
417
418 EXT STR *linestr INIT(Nullstr);
419
420 EXT char record_separator INIT('\n');
421 EXT int rslen INIT(1);
422 EXT char *ofs INIT(Nullch);
423 EXT int ofslen INIT(0);
424 EXT char *ors INIT(Nullch);
425 EXT int orslen INIT(0);
426 EXT char *ofmt INIT(Nullch);
427 EXT char *inplace INIT(Nullch);
428 EXT char *nointrp INIT("");
429
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 */
439 EXT bool sawi INIT(FALSE);              /* study must assume case insensitive */
440 EXT bool sawvec INIT(FALSE);
441
442 #ifdef CSH
443 char *cshname INIT(CSH);
444 int cshlen INIT(0);
445 #endif /* CSH */
446
447 #ifdef TAINT
448 EXT bool tainted INIT(FALSE);           /* using variables controlled by $< */
449 #endif
450
451 #define TMPPATH "/tmp/perl-eXXXXXX"
452 EXT char *e_tmpname;
453 EXT FILE *e_fp INIT(Nullfp);
454
455 EXT char tokenbuf[256];
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 */
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;
474 EXT struct stat statcache;
475 STAB *statstab INIT(Nullstab);
476 STR *statname;
477 EXT struct tms timesbuf;
478 EXT int uid;
479 EXT int euid;
480 EXT int gid;
481 EXT int egid;
482 UIDTYPE getuid();
483 UIDTYPE geteuid();
484 GIDTYPE getgid();
485 GIDTYPE getegid();
486 EXT int unsafe;
487
488 #ifdef DEBUGGING
489 EXT int debug INIT(0);
490 EXT int dlevel INIT(0);
491 EXT int dlmax INIT(128);
492 EXT char *debname;
493 EXT char *debdelim;
494 #define YYDEBUG 1
495 #endif
496 EXT int perldb INIT(0);
497
498 EXT line_t cmdline INIT(NOLINE);
499
500 EXT STR str_undef;
501 EXT STR str_no;
502 EXT STR str_yes;
503
504 /* runtime control stuff */
505
506 EXT struct loop {
507     char *loop_label;           /* what the loop was called, if anything */
508     int loop_sp;                /* stack pointer to copy stuff down to */
509     jmp_buf loop_env;
510 } *loop_stack;
511
512 EXT int loop_ptr INIT(-1);
513 EXT int loop_max INIT(128);
514
515 EXT jmp_buf top_env;
516 EXT jmp_buf eval_env;
517
518 EXT char *goto_targ INIT(Nullch);       /* cmd_exec gets strange when set */
519
520 EXT ARRAY *stack;               /* THE STACK */
521
522 EXT ARRAY *savestack;           /* to save non-local values on */
523
524 EXT ARRAY *tosave;              /* strings to save on recursive subroutine */
525
526 EXT ARRAY *lineary;             /* lines of script for debugger */
527
528 EXT ARRAY *pidstatary;          /* keep pids and statuses by fd for mypopen */
529
530 double atof();
531 long time();
532 struct tm *gmtime(), *localtime();
533 char *mktemp();
534 char *index(), *rindex();
535 char *strcpy(), *strcat();
536
537 #ifdef EUNICE
538 #define UNLINK unlnk
539 int unlnk();
540 #else
541 #define UNLINK unlink
542 #endif
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