perl 4.0 patch 31: patch #20, continued
[p5sagit/p5-mst-13.2.git] / perl.h
1 /* $RCSfile: perl.h,v $$Revision: 4.0.1.6 $$Date: 92/06/08 14:55:10 $
2  *
3  *    Copyright (c) 1991, Larry Wall
4  *
5  *    You may distribute under the terms of either the GNU General Public
6  *    License or the Artistic License, as specified in the README file.
7  *
8  * $Log:        perl.h,v $
9  * Revision 4.0.1.6  92/06/08  14:55:10  lwall
10  * patch20: added Atari ST portability
11  * patch20: bcopy() and memcpy() now tested for overlap safety
12  * patch20: Perl now distinguishes overlapped copies from non-overlapped
13  * patch20: removed implicit int declarations on functions
14  * 
15  * Revision 4.0.1.5  91/11/11  16:41:07  lwall
16  * patch19: uts wrongly defines S_ISDIR() et al
17  * patch19: too many preprocessors can't expand a macro right in #if
18  * patch19: added little-endian pack/unpack options
19  * 
20  * Revision 4.0.1.4  91/11/05  18:06:10  lwall
21  * patch11: various portability fixes
22  * patch11: added support for dbz
23  * patch11: added some support for 64-bit integers
24  * patch11: hex() didn't understand leading 0x
25  * 
26  * Revision 4.0.1.3  91/06/10  01:25:10  lwall
27  * patch10: certain pattern optimizations were botched
28  * 
29  * Revision 4.0.1.2  91/06/07  11:28:33  lwall
30  * patch4: new copyright notice
31  * patch4: made some allowances for "semi-standard" C
32  * patch4: many, many itty-bitty portability fixes
33  * 
34  * Revision 4.0.1.1  91/04/11  17:49:51  lwall
35  * patch1: hopefully straightened out some of the Xenix mess
36  * 
37  * Revision 4.0  91/03/20  01:37:56  lwall
38  * 4.0 baseline.
39  * 
40  */
41
42 #define VOIDWANT 1
43 #include "config.h"
44
45 #ifdef MYMALLOC
46 #   ifdef HIDEMYMALLOC
47 #       define malloc Mymalloc
48 #       define realloc Myremalloc
49 #       define free Myfree
50 #   endif
51 #   define safemalloc malloc
52 #   define saferealloc realloc
53 #   define safefree free
54 #endif
55
56 /* work around some libPW problems */
57 #define fatal Myfatal
58 #ifdef DOINIT
59 char Error[1];
60 #endif
61
62 /* define this once if either system, instead of cluttering up the src */
63 #if defined(MSDOS) || defined(atarist)
64 #define DOSISH 1
65 #endif
66
67 #ifdef DOSISH
68 /* This stuff now in the MS-DOS config.h file. */
69 #else /* !MSDOS */
70
71 /*
72  * The following symbols are defined if your operating system supports
73  * functions by that name.  All Unixes I know of support them, thus they
74  * are not checked by the configuration script, but are directly defined
75  * here.
76  */
77 #define HAS_ALARM
78 #define HAS_CHOWN
79 #define HAS_CHROOT
80 #define HAS_FORK
81 #define HAS_GETLOGIN
82 #define HAS_GETPPID
83 #define HAS_KILL
84 #define HAS_LINK
85 #define HAS_PIPE
86 #define HAS_WAIT
87 #define HAS_UMASK
88 /*
89  * The following symbols are defined if your operating system supports
90  * password and group functions in general.  All Unix systems do.
91  */
92 #define HAS_GROUP
93 #define HAS_PASSWD
94
95 #endif /* !MSDOS */
96
97 #if defined(__STDC__) || defined(_AIX) || defined(__stdc__)
98 # define STANDARD_C 1
99 #endif
100
101 #if defined(HASVOLATILE) || defined(STANDARD_C)
102 #define VOLATILE volatile
103 #else
104 #define VOLATILE
105 #endif
106
107 #ifdef IAMSUID
108 #   ifndef TAINT
109 #       define TAINT
110 #   endif
111 #endif
112
113 #ifndef HAS_VFORK
114 #   define vfork fork
115 #endif
116
117 #ifdef HAS_GETPGRP2
118 #   ifndef HAS_GETPGRP
119 #       define HAS_GETPGRP
120 #   endif
121 #   define getpgrp getpgrp2
122 #endif
123
124 #ifdef HAS_SETPGRP2
125 #   ifndef HAS_SETPGRP
126 #       define HAS_SETPGRP
127 #   endif
128 #   define setpgrp setpgrp2
129 #endif
130
131 #include <stdio.h>
132 #include <ctype.h>
133 #include <setjmp.h>
134 #ifndef MSDOS
135 #ifdef PARAM_NEEDS_TYPES
136 #include <sys/types.h>
137 #endif
138 #include <sys/param.h>
139 #endif
140 #ifdef STANDARD_C
141 /* Use all the "standard" definitions */
142 #include <stdlib.h>
143 #include <string.h>
144 #define MEM_SIZE size_t
145 #else
146 typedef unsigned int MEM_SIZE;
147 #endif /* STANDARD_C */
148
149 #if defined(HAS_MEMCMP) && defined(mips) && defined(ultrix)
150 #undef HAS_MEMCMP
151 #endif
152
153 #ifdef HAS_MEMCPY
154 #  ifndef STANDARD_C
155 #    ifndef memcpy
156         extern char * memcpy();
157 #    endif
158 #  endif
159 #else
160 #   ifndef memcpy
161 #       ifdef HAS_BCOPY
162 #           define memcpy(d,s,l) bcopy(s,d,l)
163 #       else
164 #           define memcpy(d,s,l) my_bcopy(s,d,l)
165 #       endif
166 #   endif
167 #endif /* HAS_MEMCPY */
168
169 #ifdef HAS_MEMSET
170 #  ifndef STANDARD_C
171 #    ifndef memset
172         extern char *memset();
173 #    endif
174 #  endif
175 #  define memzero(d,l) memset(d,0,l)
176 #else
177 #   ifndef memzero
178 #       ifdef HAS_BZERO
179 #           define memzero(d,l) bzero(d,l)
180 #       else
181 #           define memzero(d,l) my_bzero(d,l)
182 #       endif
183 #   endif
184 #endif /* HAS_MEMSET */
185
186 #ifdef HAS_MEMCMP
187 #  ifndef STANDARD_C
188 #    ifndef memcmp
189         extern int memcmp();
190 #    endif
191 #  endif
192 #else
193 #   ifndef memcmp
194 #       define memcmp(s1,s2,l) my_memcmp(s1,s2,l)
195 #   endif
196 #endif /* HAS_MEMCMP */
197
198 /* we prefer bcmp slightly for comparisons that don't care about ordering */
199 #ifndef HAS_BCMP
200 #   ifndef bcmp
201 #       define bcmp(s1,s2,l) memcmp(s1,s2,l)
202 #   endif
203 #endif /* HAS_BCMP */
204
205 #ifndef HAS_MEMMOVE
206 #if defined(HAS_BCOPY) && defined(SAFE_BCOPY)
207 #define memmove(d,s,l) bcopy(s,d,l)
208 #else
209 #if defined(HAS_MEMCPY) && defined(SAFE_MEMCPY)
210 #define memmove(d,s,l) memcpy(d,s,l)
211 #else
212 #define memmove(d,s,l) my_bcopy(s,d,l)
213 #endif
214 #endif
215 #endif
216
217 #ifndef _TYPES_         /* If types.h defines this it's easy. */
218 #ifndef major           /* Does everyone's types.h define this? */
219 #include <sys/types.h>
220 #endif
221 #endif
222
223 #ifdef I_NETINET_IN
224 #include <netinet/in.h>
225 #endif
226
227 #include <sys/stat.h>
228 #if defined(uts) || defined(UTekV)
229 #undef S_ISDIR
230 #undef S_ISCHR
231 #undef S_ISBLK
232 #undef S_ISREG
233 #undef S_ISFIFO
234 #undef S_ISLNK
235 #define S_ISDIR(P) (((P)&S_IFMT)==S_IFDIR)
236 #define S_ISCHR(P) (((P)&S_IFMT)==S_IFCHR)
237 #define S_ISBLK(P) (((P)&S_IFMT)==S_IFBLK)
238 #define S_ISREG(P) (((P)&S_IFMT)==S_IFREG)
239 #define S_ISFIFO(P) (((P)&S_IFMT)==S_IFIFO)
240 #ifdef S_IFLNK
241 #define S_ISLNK(P) (((P)&S_IFMT)==S_IFLNK)
242 #endif
243 #endif
244
245 #ifdef I_TIME
246 #   include <time.h>
247 #endif
248
249 #ifdef I_SYS_TIME
250 #   ifdef SYSTIMEKERNEL
251 #       define KERNEL
252 #   endif
253 #   include <sys/time.h>
254 #   ifdef SYSTIMEKERNEL
255 #       undef KERNEL
256 #   endif
257 #endif
258
259 #ifndef MSDOS
260 #include <sys/times.h>
261 #endif
262
263 #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
264 #undef HAS_STRERROR
265 #endif
266
267 #include <errno.h>
268 #ifndef MSDOS
269 #ifndef errno
270 extern int errno;     /* ANSI allows errno to be an lvalue expr */
271 #endif
272 #endif
273
274 #ifndef strerror
275 #ifdef HAS_STRERROR
276 char *strerror();
277 #else
278 extern int sys_nerr;
279 extern char *sys_errlist[];
280 #define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
281 #endif
282 #endif
283
284 #ifdef I_SYSIOCTL
285 #ifndef _IOCTL_
286 #include <sys/ioctl.h>
287 #endif
288 #endif
289
290 #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
291 #ifdef HAS_SOCKETPAIR
292 #undef HAS_SOCKETPAIR
293 #endif
294 #ifdef HAS_NDBM
295 #undef HAS_NDBM
296 #endif
297 #endif
298
299 #ifdef WANT_DBZ
300 #include <dbz.h>
301 #define SOME_DBM
302 #define dbm_fetch(db,dkey) fetch(dkey)
303 #define dbm_delete(db,dkey) fatal("dbz doesn't implement delete")
304 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
305 #define dbm_close(db) dbmclose()
306 #define dbm_firstkey(db) (fatal("dbz doesn't implement traversal"),fetch())
307 #define nextkey() (fatal("dbz doesn't implement traversal"),fetch())
308 #define dbm_nextkey(db) (fatal("dbz doesn't implement traversal"),fetch())
309 #ifdef HAS_NDBM
310 #undef HAS_NDBM
311 #endif
312 #ifndef HAS_ODBM
313 #define HAS_ODBM
314 #endif
315 #else
316 #ifdef HAS_GDBM
317 #ifdef I_GDBM
318 #include <gdbm.h>
319 #endif
320 #define SOME_DBM
321 #ifdef HAS_NDBM
322 #undef HAS_NDBM
323 #endif
324 #ifdef HAS_ODBM
325 #undef HAS_ODBM
326 #endif
327 #else
328 #ifdef HAS_NDBM
329 #include <ndbm.h>
330 #define SOME_DBM
331 #ifdef HAS_ODBM
332 #undef HAS_ODBM
333 #endif
334 #else
335 #ifdef HAS_ODBM
336 #ifdef NULL
337 #undef NULL             /* suppress redefinition message */
338 #endif
339 #include <dbm.h>
340 #ifdef NULL
341 #undef NULL
342 #endif
343 #define NULL 0          /* silly thing is, we don't even use this */
344 #define SOME_DBM
345 #define dbm_fetch(db,dkey) fetch(dkey)
346 #define dbm_delete(db,dkey) delete(dkey)
347 #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
348 #define dbm_close(db) dbmclose()
349 #define dbm_firstkey(db) firstkey()
350 #endif /* HAS_ODBM */
351 #endif /* HAS_NDBM */
352 #endif /* HAS_GDBM */
353 #endif /* WANT_DBZ */
354 #ifdef SOME_DBM
355 EXT char *dbmkey;
356 EXT int dbmlen;
357 #endif
358
359 #if INTSIZE == 2
360 #define htoni htons
361 #define ntohi ntohs
362 #else
363 #define htoni htonl
364 #define ntohi ntohl
365 #endif
366
367 #if defined(I_DIRENT)
368 #   include <dirent.h>
369 #   define DIRENT dirent
370 #else
371 #   ifdef I_SYS_NDIR
372 #       include <sys/ndir.h>
373 #       define DIRENT direct
374 #   else
375 #       ifdef I_SYS_DIR
376 #           ifdef hp9000s500
377 #               include <ndir.h>        /* may be wrong in the future */
378 #           else
379 #               include <sys/dir.h>
380 #           endif
381 #           define DIRENT direct
382 #       endif
383 #   endif
384 #endif
385
386 #ifdef FPUTS_BOTCH
387 /* work around botch in SunOS 4.0.1 and 4.0.2 */
388 #   ifndef fputs
389 #       define fputs(str,fp) fprintf(fp,"%s",str)
390 #   endif
391 #endif
392
393 /*
394  * The following gobbledygook brought to you on behalf of __STDC__.
395  * (I could just use #ifndef __STDC__, but this is more bulletproof
396  * in the face of half-implementations.)
397  */
398
399 #ifndef S_IFMT
400 #   ifdef _S_IFMT
401 #       define S_IFMT _S_IFMT
402 #   else
403 #       define S_IFMT 0170000
404 #   endif
405 #endif
406
407 #ifndef S_ISDIR
408 #   define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
409 #endif
410
411 #ifndef S_ISCHR
412 #   define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
413 #endif
414
415 #ifndef S_ISBLK
416 #   ifdef S_IFBLK
417 #       define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
418 #   else
419 #       define S_ISBLK(m) (0)
420 #   endif
421 #endif
422
423 #ifndef S_ISREG
424 #   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
425 #endif
426
427 #ifndef S_ISFIFO
428 #   ifdef S_IFIFO
429 #       define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
430 #   else
431 #       define S_ISFIFO(m) (0)
432 #   endif
433 #endif
434
435 #ifndef S_ISLNK
436 #   ifdef _S_ISLNK
437 #       define S_ISLNK(m) _S_ISLNK(m)
438 #   else
439 #       ifdef _S_IFLNK
440 #           define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
441 #       else
442 #           ifdef S_IFLNK
443 #               define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
444 #           else
445 #               define S_ISLNK(m) (0)
446 #           endif
447 #       endif
448 #   endif
449 #endif
450
451 #ifndef S_ISSOCK
452 #   ifdef _S_ISSOCK
453 #       define S_ISSOCK(m) _S_ISSOCK(m)
454 #   else
455 #       ifdef _S_IFSOCK
456 #           define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
457 #       else
458 #           ifdef S_IFSOCK
459 #               define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
460 #           else
461 #               define S_ISSOCK(m) (0)
462 #           endif
463 #       endif
464 #   endif
465 #endif
466
467 #ifndef S_IRUSR
468 #   ifdef S_IREAD
469 #       define S_IRUSR S_IREAD
470 #       define S_IWUSR S_IWRITE
471 #       define S_IXUSR S_IEXEC
472 #   else
473 #       define S_IRUSR 0400
474 #       define S_IWUSR 0200
475 #       define S_IXUSR 0100
476 #   endif
477 #   define S_IRGRP (S_IRUSR>>3)
478 #   define S_IWGRP (S_IWUSR>>3)
479 #   define S_IXGRP (S_IXUSR>>3)
480 #   define S_IROTH (S_IRUSR>>6)
481 #   define S_IWOTH (S_IWUSR>>6)
482 #   define S_IXOTH (S_IXUSR>>6)
483 #endif
484
485 #ifndef S_ISUID
486 #   define S_ISUID 04000
487 #endif
488
489 #ifndef S_ISGID
490 #   define S_ISGID 02000
491 #endif
492
493 #ifdef f_next
494 #undef f_next
495 #endif
496
497 #if defined(cray) || defined(gould) || defined(i860)
498 #   define SLOPPYDIVIDE
499 #endif
500
501 #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
502 #   define QUAD
503 #endif
504
505 #ifdef QUAD
506 #   ifdef cray
507 #       define quad int
508 #   else
509 #       if defined(convex) || defined (uts)
510 #           define quad long long
511 #       else
512 #           define quad long
513 #       endif
514 #   endif
515 #endif
516
517 typedef MEM_SIZE STRLEN;
518
519 typedef struct arg ARG;
520 typedef struct cmd CMD;
521 typedef struct formcmd FCMD;
522 typedef struct scanpat SPAT;
523 typedef struct stio STIO;
524 typedef struct sub SUBR;
525 typedef struct string STR;
526 typedef struct atbl ARRAY;
527 typedef struct htbl HASH;
528 typedef struct regexp REGEXP;
529 typedef struct stabptrs STBP;
530 typedef struct stab STAB;
531 typedef struct callsave CSV;
532
533 #include "handy.h"
534 #include "regexp.h"
535 #include "str.h"
536 #include "util.h"
537 #include "form.h"
538 #include "stab.h"
539 #include "spat.h"
540 #include "arg.h"
541 #include "cmd.h"
542 #include "array.h"
543 #include "hash.h"
544
545 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
546 #   define I286
547 #endif
548
549 #ifndef STANDARD_C
550 #ifdef CHARSPRINTF
551     char *sprintf();
552 #else
553     int sprintf();
554 #endif
555 #endif
556
557 EXT char *Yes INIT("1");
558 EXT char *No INIT("");
559
560 /* "gimme" values */
561
562 /* Note: cmd.c assumes that it can use && to produce one of these values! */
563 #define G_SCALAR 0
564 #define G_ARRAY 1
565
566 #ifdef CRIPPLED_CC
567 int str_true();
568 #else /* !CRIPPLED_CC */
569 #define str_true(str) (Str = (str), \
570         (Str->str_pok ? \
571             ((*Str->str_ptr > '0' || \
572               Str->str_cur > 1 || \
573               (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \
574         : \
575             (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) ))
576 #endif /* CRIPPLED_CC */
577
578 #ifdef DEBUGGING
579 #define str_peek(str) (Str = (str), \
580         (Str->str_pok ? \
581             Str->str_ptr : \
582             (Str->str_nok ? \
583                 (sprintf(tokenbuf,"num(%g)",Str->str_u.str_nval), \
584                     (char*)tokenbuf) : \
585                 "" )))
586 #endif
587
588 #ifdef CRIPPLED_CC
589 char *str_get();
590 #else
591 #ifdef TAINT
592 #define str_get(str) (Str = (str), tainted |= Str->str_tainted, \
593         (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
594 #else
595 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
596 #endif /* TAINT */
597 #endif /* CRIPPLED_CC */
598
599 #ifdef CRIPPLED_CC
600 double str_gnum();
601 #else /* !CRIPPLED_CC */
602 #ifdef TAINT
603 #define str_gnum(str) (Str = (str), tainted |= Str->str_tainted, \
604         (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
605 #else /* !TAINT */
606 #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
607 #endif /* TAINT*/
608 #endif /* CRIPPLED_CC */
609 EXT STR *Str;
610
611 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
612
613 #ifndef DOSISH
614 #define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len)
615 #define Str_Grow str_grow
616 #else
617 /* extra parentheses intentionally NOT placed around "len"! */
618 #define STR_GROW(str,len) if ((str)->str_len < (unsigned long)len) \
619                 str_grow(str,(unsigned long)len)
620 #define Str_Grow(str,len) str_grow(str,(unsigned long)(len))
621 #endif /* DOSISH */
622
623 #ifndef BYTEORDER
624 #define BYTEORDER 0x1234
625 #endif
626
627 #if defined(htonl) && !defined(HAS_HTONL)
628 #define HAS_HTONL
629 #endif
630 #if defined(htons) && !defined(HAS_HTONS)
631 #define HAS_HTONS
632 #endif
633 #if defined(ntohl) && !defined(HAS_NTOHL)
634 #define HAS_NTOHL
635 #endif
636 #if defined(ntohs) && !defined(HAS_NTOHS)
637 #define HAS_NTOHS
638 #endif
639 #ifndef HAS_HTONL
640 #if (BYTEORDER & 0xffff) != 0x4321
641 #define HAS_HTONS
642 #define HAS_HTONL
643 #define HAS_NTOHS
644 #define HAS_NTOHL
645 #define MYSWAP
646 #define htons my_swap
647 #define htonl my_htonl
648 #define ntohs my_swap
649 #define ntohl my_ntohl
650 #endif
651 #else
652 #if (BYTEORDER & 0xffff) == 0x4321
653 #undef HAS_HTONS
654 #undef HAS_HTONL
655 #undef HAS_NTOHS
656 #undef HAS_NTOHL
657 #endif
658 #endif
659
660 /*
661  * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
662  * -DWS
663  */
664 #if BYTEORDER != 0x1234
665 # define HAS_VTOHL
666 # define HAS_VTOHS
667 # define HAS_HTOVL
668 # define HAS_HTOVS
669 # if BYTEORDER == 0x4321
670 #  define vtohl(x)      ((((x)&0xFF)<<24)       \
671                         +(((x)>>24)&0xFF)       \
672                         +(((x)&0x0000FF00)<<8)  \
673                         +(((x)&0x00FF0000)>>8)  )
674 #  define vtohs(x)      ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
675 #  define htovl(x)      vtohl(x)
676 #  define htovs(x)      vtohs(x)
677 # endif
678         /* otherwise default to functions in util.c */
679 #endif
680
681 #ifdef CASTNEGFLOAT
682 #define U_S(what) ((unsigned short)(what))
683 #define U_I(what) ((unsigned int)(what))
684 #define U_L(what) ((unsigned long)(what))
685 #else
686 unsigned long castulong();
687 #define U_S(what) ((unsigned int)castulong(what))
688 #define U_I(what) ((unsigned int)castulong(what))
689 #define U_L(what) (castulong(what))
690 #endif
691
692 CMD *add_label();
693 CMD *block_head();
694 CMD *append_line();
695 CMD *make_acmd();
696 CMD *make_ccmd();
697 CMD *make_icmd();
698 CMD *invert();
699 CMD *addcond();
700 CMD *addloop();
701 CMD *wopt();
702 CMD *over();
703
704 STAB *stabent();
705 STAB *genstab();
706
707 ARG *stab2arg();
708 ARG *op_new();
709 ARG *make_op();
710 ARG *make_match();
711 ARG *make_split();
712 ARG *rcatmaybe();
713 ARG *listish();
714 ARG *maybelistish();
715 ARG *localize();
716 ARG *fixeval();
717 ARG *jmaybe();
718 ARG *l();
719 ARG *fixl();
720 ARG *mod_match();
721 ARG *make_list();
722 ARG *cmd_to_arg();
723 ARG *addflags();
724 ARG *hide_ary();
725 ARG *cval_to_arg();
726
727 STR *str_new();
728 STR *stab_str();
729
730 int apply();
731 int do_each();
732 int do_subr();
733 int do_match();
734 int do_unpack();
735 int eval();             /* this evaluates expressions */
736 int do_eval();          /* this evaluates eval operator */
737 int do_assign();
738
739 SUBR *make_sub();
740
741 FCMD *load_format();
742
743 char *scanpat();
744 char *scansubst();
745 char *scantrans();
746 char *scanstr();
747 char *scanident();
748 char *str_append_till();
749 char *str_gets();
750 char *str_grow();
751
752 bool do_open();
753 bool do_close();
754 bool do_print();
755 bool do_aprint();
756 bool do_exec();
757 bool do_aexec();
758
759 int do_subst();
760 int cando();
761 int ingroup();
762 int whichsig();
763 int userinit();
764 #ifdef CRYPTSCRIPT
765 void cryptswitch();
766 #endif
767
768 void str_replace();
769 void str_inc();
770 void str_dec();
771 void str_free();
772 void cmd_free();
773 void arg_free();
774 void spat_free();
775 void regfree();
776 void stab_clear();
777 void do_chop();
778 void do_vop();
779 void do_write();
780 void do_join();
781 void do_sprintf();
782 void do_accept();
783 void do_pipe();
784 void do_vecset();
785 void do_unshift();
786 void do_execfree();
787 void magicalize();
788 void magicname();
789 void savelist();
790 void saveitem();
791 void saveint();
792 void savelong();
793 void savesptr();
794 void savehptr();
795 void restorelist();
796 void repeatcpy();
797 void make_form();
798 void dehoist();
799 void format();
800 void my_unexec();
801 void fatal();
802 void warn();
803 #ifdef DEBUGGING
804 void dump_all();
805 void dump_cmd();
806 void dump_arg();
807 void dump_flags();
808 void dump_stab();
809 void dump_spat();
810 #endif
811 #ifdef MSTATS
812 void mstats();
813 #endif
814
815 HASH *savehash();
816 ARRAY *saveary();
817
818 EXT char **origargv;
819 EXT int origargc;
820 EXT char **origenviron;
821 extern char **environ;
822
823 EXT long subline INIT(0);
824 EXT STR *subname INIT(Nullstr);
825 EXT int arybase INIT(0);
826
827 struct outrec {
828     long        o_lines;
829     char        *o_str;
830     int         o_len;
831 };
832
833 EXT struct outrec outrec;
834 EXT struct outrec toprec;
835
836 EXT STAB *stdinstab INIT(Nullstab);
837 EXT STAB *last_in_stab INIT(Nullstab);
838 EXT STAB *defstab INIT(Nullstab);
839 EXT STAB *argvstab INIT(Nullstab);
840 EXT STAB *envstab INIT(Nullstab);
841 EXT STAB *sigstab INIT(Nullstab);
842 EXT STAB *defoutstab INIT(Nullstab);
843 EXT STAB *curoutstab INIT(Nullstab);
844 EXT STAB *argvoutstab INIT(Nullstab);
845 EXT STAB *incstab INIT(Nullstab);
846 EXT STAB *leftstab INIT(Nullstab);
847 EXT STAB *amperstab INIT(Nullstab);
848 EXT STAB *rightstab INIT(Nullstab);
849 EXT STAB *DBstab INIT(Nullstab);
850 EXT STAB *DBline INIT(Nullstab);
851 EXT STAB *DBsub INIT(Nullstab);
852
853 EXT HASH *defstash;             /* main symbol table */
854 EXT HASH *curstash;             /* symbol table for current package */
855 EXT HASH *debstash;             /* symbol table for perldb package */
856
857 EXT STR *curstname;             /* name of current package */
858
859 EXT STR *freestrroot INIT(Nullstr);
860 EXT STR *lastretstr INIT(Nullstr);
861 EXT STR *DBsingle INIT(Nullstr);
862 EXT STR *DBtrace INIT(Nullstr);
863 EXT STR *DBsignal INIT(Nullstr);
864 EXT STR *formfeed INIT(Nullstr);
865
866 EXT int lastspbase;
867 EXT int lastsize;
868
869 EXT char *hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
870 EXT char *origfilename;
871 EXT FILE * VOLATILE rsfp;
872 EXT char buf[1024];
873 EXT char *bufptr;
874 EXT char *oldbufptr;
875 EXT char *oldoldbufptr;
876 EXT char *bufend;
877
878 EXT STR *linestr INIT(Nullstr);
879
880 EXT char *rs INIT("\n");
881 EXT int rschar INIT('\n');      /* final char of rs, or 0777 if none */
882 EXT int rslen INIT(1);
883 EXT bool rspara INIT(FALSE);
884 EXT char *ofs INIT(Nullch);
885 EXT int ofslen INIT(0);
886 EXT char *ors INIT(Nullch);
887 EXT int orslen INIT(0);
888 EXT char *ofmt INIT(Nullch);
889 EXT char *inplace INIT(Nullch);
890 EXT char *nointrp INIT("");
891
892 EXT bool preprocess INIT(FALSE);
893 EXT bool minus_n INIT(FALSE);
894 EXT bool minus_p INIT(FALSE);
895 EXT bool minus_l INIT(FALSE);
896 EXT bool minus_a INIT(FALSE);
897 EXT bool doswitches INIT(FALSE);
898 EXT bool dowarn INIT(FALSE);
899 EXT bool doextract INIT(FALSE);
900 EXT bool allstabs INIT(FALSE);  /* init all customary symbols in symbol table?*/
901 EXT bool sawampersand INIT(FALSE);      /* must save all match strings */
902 EXT bool sawstudy INIT(FALSE);          /* do fbminstr on all strings */
903 EXT bool sawi INIT(FALSE);              /* study must assume case insensitive */
904 EXT bool sawvec INIT(FALSE);
905 EXT bool localizing INIT(FALSE);        /* are we processing a local() list? */
906
907 #ifndef MAXSYSFD
908 #   define MAXSYSFD 2
909 #endif
910 EXT int maxsysfd INIT(MAXSYSFD);        /* top fd to pass to subprocesses */
911
912 #ifdef CSH
913 EXT char *cshname INIT(CSH);
914 EXT int cshlen INIT(0);
915 #endif /* CSH */
916
917 #ifdef TAINT
918 EXT bool tainted INIT(FALSE);           /* using variables controlled by $< */
919 EXT bool taintanyway INIT(FALSE);       /* force taint checks when !set?id */
920 #endif
921
922 EXT bool nomemok INIT(FALSE);           /* let malloc context handle nomem */
923
924 #ifndef DOSISH
925 #define TMPPATH "/tmp/perl-eXXXXXX"
926 #else
927 #define TMPPATH "plXXXXXX"
928 #endif /* MSDOS */
929 EXT char *e_tmpname;
930 EXT FILE *e_fp INIT(Nullfp);
931
932 EXT char tokenbuf[256];
933 EXT int expectterm INIT(TRUE);          /* how to interpret ambiguous tokens */
934 EXT VOLATILE int in_eval INIT(FALSE);   /* trap fatal errors? */
935 EXT int multiline INIT(0);              /* $*--do strings hold >1 line? */
936 EXT int forkprocess;                    /* so do_open |- can return proc# */
937 EXT int do_undump INIT(0);              /* -u or dump seen? */
938 EXT int error_count INIT(0);            /* how many errors so far, max 10 */
939 EXT int multi_start INIT(0);            /* 1st line of multi-line string */
940 EXT int multi_end INIT(0);              /* last line of multi-line string */
941 EXT int multi_open INIT(0);             /* delimiter of said string */
942 EXT int multi_close INIT(0);            /* delimiter of said string */
943
944 FILE *popen();
945 /* char *str_get(); */
946 STR *interp();
947 void free_arg();
948 STIO *stio_new();
949 void hoistmust();
950 void scanconst();
951
952 EXT struct stat statbuf;
953 EXT struct stat statcache;
954 EXT STAB *statstab INIT(Nullstab);
955 EXT STR *statname;
956 #ifndef MSDOS
957 EXT struct tms timesbuf;
958 #endif
959 EXT int uid;
960 EXT int euid;
961 EXT int gid;
962 EXT int egid;
963 UIDTYPE getuid();
964 UIDTYPE geteuid();
965 GIDTYPE getgid();
966 GIDTYPE getegid();
967 EXT int unsafe;
968
969 #ifdef DEBUGGING
970 EXT VOLATILE int debug INIT(0);
971 EXT int dlevel INIT(0);
972 EXT int dlmax INIT(128);
973 EXT char *debname;
974 EXT char *debdelim;
975 #define YYDEBUG 1
976 #endif
977 EXT int perldb INIT(0);
978 #define YYMAXDEPTH 300
979
980 EXT line_t cmdline INIT(NOLINE);
981
982 EXT STR str_undef;
983 EXT STR str_no;
984 EXT STR str_yes;
985
986 /* runtime control stuff */
987
988 EXT struct loop {
989     char *loop_label;           /* what the loop was called, if anything */
990     int loop_sp;                /* stack pointer to copy stuff down to */
991     jmp_buf loop_env;
992 } *loop_stack;
993
994 EXT int loop_ptr INIT(-1);
995 EXT int loop_max INIT(128);
996
997 EXT jmp_buf top_env;
998
999 EXT char * VOLATILE goto_targ INIT(Nullch); /* cmd_exec gets strange when set */
1000
1001 struct ufuncs {
1002     int (*uf_val)();
1003     int (*uf_set)();
1004     int uf_index;
1005 };
1006
1007 EXT ARRAY *stack;               /* THE STACK */
1008
1009 EXT ARRAY * VOLATILE savestack;         /* to save non-local values on */
1010
1011 EXT ARRAY *tosave;              /* strings to save on recursive subroutine */
1012
1013 EXT ARRAY *lineary;             /* lines of script for debugger */
1014 EXT ARRAY *dbargs;              /* args to call listed by caller function */
1015
1016 EXT ARRAY *fdpid;               /* keep fd-to-pid mappings for mypopen */
1017 EXT HASH *pidstatus;            /* keep pid-to-status mappings for waitpid */
1018
1019 EXT int *di;                    /* for tmp use in debuggers */
1020 EXT char *dc;
1021 EXT short *ds;
1022
1023 /* Fix these up for __STDC__ */
1024 EXT time_t basetime INIT(0);
1025 char *mktemp();
1026 #ifndef STANDARD_C
1027 /* All of these are in stdlib.h or time.h for ANSI C */
1028 double atof();
1029 long time();
1030 struct tm *gmtime(), *localtime();
1031 char *index(), *rindex();
1032 char *strcpy(), *strcat();
1033 #endif /* ! STANDARD_C */
1034
1035 #ifdef EUNICE
1036 #define UNLINK unlnk
1037 int unlnk();
1038 #else
1039 #define UNLINK unlink
1040 #endif
1041
1042 #ifndef HAS_SETREUID
1043 #ifdef HAS_SETRESUID
1044 #define setreuid(r,e) setresuid(r,e,-1)
1045 #define HAS_SETREUID
1046 #endif
1047 #endif
1048 #ifndef HAS_SETREGID
1049 #ifdef HAS_SETRESGID
1050 #define setregid(r,e) setresgid(r,e,-1)
1051 #define HAS_SETREGID
1052 #endif
1053 #endif
1054
1055 #define SCAN_DEF 0
1056 #define SCAN_TR 1
1057 #define SCAN_REPL 2