This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 4.0 patch 36: (combined patch)
[perl5.git] / perl.h
CommitLineData
ee0007ab 1/* $RCSfile: perl.h,v $$Revision: 4.0.1.6 $$Date: 92/06/08 14:55:10 $
a687059c 2 *
352d5a3a 3 * Copyright (c) 1991, Larry Wall
a687059c 4 *
352d5a3a
LW
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.
8d063cd8
LW
7 *
8 * $Log: perl.h,v $
ee0007ab
LW
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 *
988174c1
LW
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 *
45d8adaa
LW
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 *
1462b684
LW
26 * Revision 4.0.1.3 91/06/10 01:25:10 lwall
27 * patch10: certain pattern optimizations were botched
28 *
352d5a3a
LW
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 *
35c8bce7
LW
34 * Revision 4.0.1.1 91/04/11 17:49:51 lwall
35 * patch1: hopefully straightened out some of the Xenix mess
36 *
fe14fcc3
LW
37 * Revision 4.0 91/03/20 01:37:56 lwall
38 * 4.0 baseline.
8d063cd8
LW
39 *
40 */
41
35c8bce7 42#define VOIDWANT 1
ac58e20f
LW
43#include "config.h"
44
45d8adaa
LW
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
59char Error[1];
60#endif
61
ee0007ab
LW
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
fe14fcc3 68/* This stuff now in the MS-DOS config.h file. */
0f85fab0
LW
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 */
fe14fcc3
LW
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
0f85fab0
LW
88/*
89 * The following symbols are defined if your operating system supports
90 * password and group functions in general. All Unix systems do.
91 */
fe14fcc3
LW
92#define HAS_GROUP
93#define HAS_PASSWD
0f85fab0
LW
94
95#endif /* !MSDOS */
96
352d5a3a
LW
97#if defined(__STDC__) || defined(_AIX) || defined(__stdc__)
98# define STANDARD_C 1
99#endif
100
101#if defined(HASVOLATILE) || defined(STANDARD_C)
663a0e37 102#define VOLATILE volatile
663a0e37
LW
103#else
104#define VOLATILE
663a0e37
LW
105#endif
106
a687059c
LW
107#ifdef IAMSUID
108# ifndef TAINT
109# define TAINT
110# endif
111#endif
112
fe14fcc3 113#ifndef HAS_VFORK
03a14243
LW
114# define vfork fork
115#endif
116
fe14fcc3
LW
117#ifdef HAS_GETPGRP2
118# ifndef HAS_GETPGRP
119# define HAS_GETPGRP
663a0e37
LW
120# endif
121# define getpgrp getpgrp2
122#endif
123
fe14fcc3
LW
124#ifdef HAS_SETPGRP2
125# ifndef HAS_SETPGRP
126# define HAS_SETPGRP
663a0e37
LW
127# endif
128# define setpgrp setpgrp2
129#endif
130
fe14fcc3
LW
131#include <stdio.h>
132#include <ctype.h>
133#include <setjmp.h>
134#ifndef MSDOS
352d5a3a
LW
135#ifdef PARAM_NEEDS_TYPES
136#include <sys/types.h>
03a14243 137#endif
352d5a3a
LW
138#include <sys/param.h>
139#endif
140#ifdef STANDARD_C
fe14fcc3
LW
141/* Use all the "standard" definitions */
142#include <stdlib.h>
143#include <string.h>
ee0007ab
LW
144#define MEM_SIZE size_t
145#else
146typedef unsigned int MEM_SIZE;
352d5a3a 147#endif /* STANDARD_C */
03a14243 148
ee0007ab 149#if defined(HAS_MEMCMP) && defined(mips) && defined(ultrix)
fe14fcc3 150#undef HAS_MEMCMP
663a0e37 151#endif
fe14fcc3
LW
152
153#ifdef HAS_MEMCPY
352d5a3a 154# ifndef STANDARD_C
fe14fcc3 155# ifndef memcpy
ee0007ab
LW
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 */
fe14fcc3 168
ee0007ab
LW
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
352d5a3a 183# endif
ee0007ab
LW
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)
352d5a3a 195# endif
ee0007ab 196#endif /* HAS_MEMCMP */
8d063cd8 197
ee0007ab
LW
198/* we prefer bcmp slightly for comparisons that don't care about ordering */
199#ifndef HAS_BCMP
352d5a3a
LW
200# ifndef bcmp
201# define bcmp(s1,s2,l) memcmp(s1,s2,l)
202# endif
ee0007ab
LW
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
d9d8d8de 215#endif
378cc40b
LW
216
217#ifndef _TYPES_ /* If types.h defines this it's easy. */
218#ifndef major /* Does everyone's types.h define this? */
8d063cd8 219#include <sys/types.h>
378cc40b
LW
220#endif
221#endif
222
ae986130
LW
223#ifdef I_NETINET_IN
224#include <netinet/in.h>
225#endif
226
8d063cd8 227#include <sys/stat.h>
ee0007ab 228#if defined(uts) || defined(UTekV)
988174c1
LW
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)
ee0007ab 240#ifdef S_IFLNK
988174c1
LW
241#define S_ISLNK(P) (((P)&S_IFMT)==S_IFLNK)
242#endif
ee0007ab 243#endif
135863df 244
663a0e37
LW
245#ifdef I_TIME
246# include <time.h>
ffed7fef 247#endif
663a0e37 248
fe14fcc3 249#ifdef I_SYS_TIME
663a0e37
LW
250# ifdef SYSTIMEKERNEL
251# define KERNEL
252# endif
253# include <sys/time.h>
254# ifdef SYSTIMEKERNEL
255# undef KERNEL
256# endif
a687059c 257#endif
135863df 258
d9d8d8de 259#ifndef MSDOS
8d063cd8 260#include <sys/times.h>
d9d8d8de 261#endif
8d063cd8 262
fe14fcc3
LW
263#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
264#undef HAS_STRERROR
663a0e37
LW
265#endif
266
267#include <errno.h>
d9d8d8de 268#ifndef MSDOS
663a0e37
LW
269#ifndef errno
270extern int errno; /* ANSI allows errno to be an lvalue expr */
271#endif
d9d8d8de 272#endif
663a0e37 273
35c8bce7 274#ifndef strerror
fe14fcc3 275#ifdef HAS_STRERROR
663a0e37
LW
276char *strerror();
277#else
278extern int sys_nerr;
279extern char *sys_errlist[];
280#define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
281#endif
35c8bce7 282#endif
663a0e37 283
a687059c
LW
284#ifdef I_SYSIOCTL
285#ifndef _IOCTL_
286#include <sys/ioctl.h>
287#endif
288#endif
289
ee0007ab 290#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
fe14fcc3
LW
291#ifdef HAS_SOCKETPAIR
292#undef HAS_SOCKETPAIR
a687059c 293#endif
fe14fcc3
LW
294#ifdef HAS_NDBM
295#undef HAS_NDBM
a687059c
LW
296#endif
297#endif
298
45d8adaa
LW
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
fe14fcc3
LW
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
a687059c
LW
329#include <ndbm.h>
330#define SOME_DBM
fe14fcc3
LW
331#ifdef HAS_ODBM
332#undef HAS_ODBM
ae986130 333#endif
a687059c 334#else
fe14fcc3 335#ifdef HAS_ODBM
a687059c
LW
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()
fe14fcc3
LW
350#endif /* HAS_ODBM */
351#endif /* HAS_NDBM */
352#endif /* HAS_GDBM */
45d8adaa 353#endif /* WANT_DBZ */
a687059c
LW
354#ifdef SOME_DBM
355EXT char *dbmkey;
356EXT 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
35c8bce7 367#if defined(I_DIRENT)
663a0e37
LW
368# include <dirent.h>
369# define DIRENT dirent
ae986130 370#else
fe14fcc3 371# ifdef I_SYS_NDIR
79a0689e 372# include <sys/ndir.h>
663a0e37
LW
373# define DIRENT direct
374# else
fe14fcc3 375# ifdef I_SYS_DIR
79a0689e
LW
376# ifdef hp9000s500
377# include <ndir.h> /* may be wrong in the future */
378# else
379# include <sys/dir.h>
380# endif
663a0e37
LW
381# define DIRENT direct
382# endif
383# endif
a687059c
LW
384#endif
385
352d5a3a
LW
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
c623bd54
LW
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
fe14fcc3
LW
416# ifdef S_IFBLK
417# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
418# else
419# define S_ISBLK(m) (0)
420# endif
c623bd54
LW
421#endif
422
423#ifndef S_ISREG
424# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
425#endif
426
427#ifndef S_ISFIFO
fe14fcc3
LW
428# ifdef S_IFIFO
429# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
430# else
431# define S_ISFIFO(m) (0)
432# endif
c623bd54
LW
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
352d5a3a
LW
493#ifdef f_next
494#undef f_next
495#endif
496
ee0007ab 497#if defined(cray) || defined(gould) || defined(i860)
45d8adaa
LW
498# define SLOPPYDIVIDE
499#endif
500
988174c1 501#if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
45d8adaa
LW
502# define QUAD
503#endif
504
505#ifdef QUAD
506# ifdef cray
507# define quad int
508# else
988174c1 509# if defined(convex) || defined (uts)
45d8adaa
LW
510# define quad long long
511# else
512# define quad long
513# endif
514# endif
515#endif
516
ee0007ab 517typedef MEM_SIZE STRLEN;
450a55e4 518
8d063cd8
LW
519typedef struct arg ARG;
520typedef struct cmd CMD;
521typedef struct formcmd FCMD;
522typedef struct scanpat SPAT;
8d063cd8 523typedef struct stio STIO;
378cc40b 524typedef struct sub SUBR;
8d063cd8
LW
525typedef struct string STR;
526typedef struct atbl ARRAY;
527typedef struct htbl HASH;
378cc40b 528typedef struct regexp REGEXP;
a687059c
LW
529typedef struct stabptrs STBP;
530typedef struct stab STAB;
d9d8d8de 531typedef struct callsave CSV;
8d063cd8 532
378cc40b
LW
533#include "handy.h"
534#include "regexp.h"
8d063cd8 535#include "str.h"
378cc40b 536#include "util.h"
8d063cd8
LW
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
450a55e4 545#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
546# define I286
547#endif
548
352d5a3a 549#ifndef STANDARD_C
135863df
AB
550#ifdef CHARSPRINTF
551 char *sprintf();
552#else
553 int sprintf();
554#endif
a687059c 555#endif
135863df 556
8d063cd8
LW
557EXT char *Yes INIT("1");
558EXT char *No INIT("");
559
a687059c
LW
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
567int 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 */
8d063cd8 577
135863df 578#ifdef DEBUGGING
a687059c
LW
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 "" )))
135863df
AB
586#endif
587
a687059c
LW
588#ifdef CRIPPLED_CC
589char *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
8d063cd8 595#define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
a687059c
LW
596#endif /* TAINT */
597#endif /* CRIPPLED_CC */
598
599#ifdef CRIPPLED_CC
600double 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 */
8d063cd8
LW
609EXT STR *Str;
610
611#define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
612
ee0007ab 613#ifndef DOSISH
a687059c 614#define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len)
450a55e4
LW
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))
ee0007ab 621#endif /* DOSISH */
a687059c
LW
622
623#ifndef BYTEORDER
ffed7fef 624#define BYTEORDER 0x1234
a687059c
LW
625#endif
626
fe14fcc3
LW
627#if defined(htonl) && !defined(HAS_HTONL)
628#define HAS_HTONL
ae986130 629#endif
fe14fcc3
LW
630#if defined(htons) && !defined(HAS_HTONS)
631#define HAS_HTONS
ae986130 632#endif
fe14fcc3
LW
633#if defined(ntohl) && !defined(HAS_NTOHL)
634#define HAS_NTOHL
ae986130 635#endif
fe14fcc3
LW
636#if defined(ntohs) && !defined(HAS_NTOHS)
637#define HAS_NTOHS
ae986130 638#endif
fe14fcc3 639#ifndef HAS_HTONL
d9d8d8de 640#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
641#define HAS_HTONS
642#define HAS_HTONL
643#define HAS_NTOHS
644#define HAS_NTOHL
a687059c
LW
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
d9d8d8de 652#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
653#undef HAS_HTONS
654#undef HAS_HTONL
655#undef HAS_NTOHS
656#undef HAS_NTOHL
a687059c
LW
657#endif
658#endif
659
988174c1
LW
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
0f85fab0
LW
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
686unsigned 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
8d063cd8
LW
692CMD *add_label();
693CMD *block_head();
694CMD *append_line();
695CMD *make_acmd();
696CMD *make_ccmd();
a687059c 697CMD *make_icmd();
8d063cd8
LW
698CMD *invert();
699CMD *addcond();
700CMD *addloop();
701CMD *wopt();
378cc40b 702CMD *over();
8d063cd8 703
8d063cd8 704STAB *stabent();
378cc40b 705STAB *genstab();
8d063cd8 706
378cc40b 707ARG *stab2arg();
8d063cd8
LW
708ARG *op_new();
709ARG *make_op();
8d063cd8
LW
710ARG *make_match();
711ARG *make_split();
a687059c 712ARG *rcatmaybe();
378cc40b 713ARG *listish();
a687059c 714ARG *maybelistish();
378cc40b 715ARG *localize();
a687059c
LW
716ARG *fixeval();
717ARG *jmaybe();
378cc40b 718ARG *l();
a687059c 719ARG *fixl();
378cc40b
LW
720ARG *mod_match();
721ARG *make_list();
722ARG *cmd_to_arg();
723ARG *addflags();
724ARG *hide_ary();
725ARG *cval_to_arg();
8d063cd8 726
8d063cd8
LW
727STR *str_new();
728STR *stab_str();
a687059c 729
ee0007ab 730int apply();
a687059c
LW
731int do_each();
732int do_subr();
733int do_match();
734int do_unpack();
735int eval(); /* this evaluates expressions */
736int do_eval(); /* this evaluates eval operator */
737int do_assign();
378cc40b
LW
738
739SUBR *make_sub();
8d063cd8
LW
740
741FCMD *load_format();
742
743char *scanpat();
744char *scansubst();
745char *scantrans();
746char *scanstr();
fe14fcc3 747char *scanident();
8d063cd8
LW
748char *str_append_till();
749char *str_gets();
a687059c 750char *str_grow();
8d063cd8 751
8d063cd8
LW
752bool do_open();
753bool do_close();
754bool do_print();
378cc40b
LW
755bool do_aprint();
756bool do_exec();
757bool do_aexec();
8d063cd8
LW
758
759int do_subst();
378cc40b
LW
760int cando();
761int ingroup();
ee0007ab
LW
762int whichsig();
763int userinit();
764#ifdef CRYPTSCRIPT
765void cryptswitch();
766#endif
8d063cd8 767
378cc40b
LW
768void str_replace();
769void str_inc();
770void str_dec();
8d063cd8 771void str_free();
ee0007ab
LW
772void cmd_free();
773void arg_free();
774void spat_free();
775void regfree();
a687059c 776void stab_clear();
ee0007ab
LW
777void do_chop();
778void do_vop();
779void do_write();
378cc40b 780void do_join();
378cc40b 781void do_sprintf();
a687059c 782void do_accept();
ac58e20f 783void do_pipe();
a687059c 784void do_vecset();
fe14fcc3
LW
785void do_unshift();
786void do_execfree();
787void magicalize();
788void magicname();
a687059c
LW
789void savelist();
790void saveitem();
791void saveint();
792void savelong();
793void savesptr();
794void savehptr();
795void restorelist();
ac58e20f 796void repeatcpy();
ee0007ab
LW
797void make_form();
798void dehoist();
799void format();
800void my_unexec();
801void fatal();
802void warn();
803#ifdef DEBUGGING
804void dump_all();
805void dump_cmd();
806void dump_arg();
807void dump_flags();
808void dump_stab();
809void dump_spat();
810#endif
811#ifdef MSTATS
812void mstats();
813#endif
814
a687059c
LW
815HASH *savehash();
816ARRAY *saveary();
378cc40b 817
ac58e20f
LW
818EXT char **origargv;
819EXT int origargc;
fe14fcc3 820EXT char **origenviron;
35c8bce7
LW
821extern char **environ;
822
45d8adaa 823EXT long subline INIT(0);
a687059c 824EXT STR *subname INIT(Nullstr);
8d063cd8
LW
825EXT int arybase INIT(0);
826
827struct outrec {
d9d8d8de
LW
828 long o_lines;
829 char *o_str;
830 int o_len;
8d063cd8
LW
831};
832
833EXT struct outrec outrec;
834EXT struct outrec toprec;
835
a687059c 836EXT STAB *stdinstab INIT(Nullstab);
8d063cd8
LW
837EXT STAB *last_in_stab INIT(Nullstab);
838EXT STAB *defstab INIT(Nullstab);
839EXT STAB *argvstab INIT(Nullstab);
840EXT STAB *envstab INIT(Nullstab);
841EXT STAB *sigstab INIT(Nullstab);
842EXT STAB *defoutstab INIT(Nullstab);
843EXT STAB *curoutstab INIT(Nullstab);
844EXT STAB *argvoutstab INIT(Nullstab);
378cc40b 845EXT STAB *incstab INIT(Nullstab);
a687059c
LW
846EXT STAB *leftstab INIT(Nullstab);
847EXT STAB *amperstab INIT(Nullstab);
848EXT STAB *rightstab INIT(Nullstab);
849EXT STAB *DBstab INIT(Nullstab);
d9d8d8de 850EXT STAB *DBline INIT(Nullstab);
a687059c
LW
851EXT STAB *DBsub INIT(Nullstab);
852
853EXT HASH *defstash; /* main symbol table */
854EXT HASH *curstash; /* symbol table for current package */
855EXT HASH *debstash; /* symbol table for perldb package */
856
857EXT STR *curstname; /* name of current package */
8d063cd8
LW
858
859EXT STR *freestrroot INIT(Nullstr);
378cc40b 860EXT STR *lastretstr INIT(Nullstr);
a687059c 861EXT STR *DBsingle INIT(Nullstr);
d9d8d8de
LW
862EXT STR *DBtrace INIT(Nullstr);
863EXT STR *DBsignal INIT(Nullstr);
ee0007ab 864EXT STR *formfeed INIT(Nullstr);
a687059c
LW
865
866EXT int lastspbase;
867EXT int lastsize;
8d063cd8 868
45d8adaa 869EXT char *hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
378cc40b 870EXT char *origfilename;
e334a159 871EXT FILE * VOLATILE rsfp INIT(Nullfp);
8d063cd8 872EXT char buf[1024];
a687059c
LW
873EXT char *bufptr;
874EXT char *oldbufptr;
875EXT char *oldoldbufptr;
876EXT char *bufend;
8d063cd8
LW
877
878EXT STR *linestr INIT(Nullstr);
879
fe14fcc3
LW
880EXT char *rs INIT("\n");
881EXT int rschar INIT('\n'); /* final char of rs, or 0777 if none */
a687059c 882EXT int rslen INIT(1);
ee0007ab 883EXT bool rspara INIT(FALSE);
8d063cd8 884EXT char *ofs INIT(Nullch);
a687059c 885EXT int ofslen INIT(0);
8d063cd8 886EXT char *ors INIT(Nullch);
a687059c 887EXT int orslen INIT(0);
8d063cd8
LW
888EXT char *ofmt INIT(Nullch);
889EXT char *inplace INIT(Nullch);
a687059c 890EXT char *nointrp INIT("");
8d063cd8 891
378cc40b
LW
892EXT bool preprocess INIT(FALSE);
893EXT bool minus_n INIT(FALSE);
894EXT bool minus_p INIT(FALSE);
fe14fcc3 895EXT bool minus_l INIT(FALSE);
378cc40b
LW
896EXT bool minus_a INIT(FALSE);
897EXT bool doswitches INIT(FALSE);
898EXT bool dowarn INIT(FALSE);
450a55e4 899EXT bool doextract INIT(FALSE);
378cc40b
LW
900EXT bool allstabs INIT(FALSE); /* init all customary symbols in symbol table?*/
901EXT bool sawampersand INIT(FALSE); /* must save all match strings */
902EXT bool sawstudy INIT(FALSE); /* do fbminstr on all strings */
a687059c
LW
903EXT bool sawi INIT(FALSE); /* study must assume case insensitive */
904EXT bool sawvec INIT(FALSE);
ac58e20f 905EXT bool localizing INIT(FALSE); /* are we processing a local() list? */
a687059c 906
352d5a3a
LW
907#ifndef MAXSYSFD
908# define MAXSYSFD 2
909#endif
910EXT int maxsysfd INIT(MAXSYSFD); /* top fd to pass to subprocesses */
911
ae986130 912#ifdef CSH
ee0007ab
LW
913EXT char *cshname INIT(CSH);
914EXT int cshlen INIT(0);
ae986130 915#endif /* CSH */
a687059c
LW
916
917#ifdef TAINT
918EXT bool tainted INIT(FALSE); /* using variables controlled by $< */
ee0007ab 919EXT bool taintanyway INIT(FALSE); /* force taint checks when !set?id */
a687059c 920#endif
378cc40b 921
ee0007ab
LW
922EXT bool nomemok INIT(FALSE); /* let malloc context handle nomem */
923
924#ifndef DOSISH
378cc40b 925#define TMPPATH "/tmp/perl-eXXXXXX"
450a55e4 926#else
57ebbfd0 927#define TMPPATH "plXXXXXX"
450a55e4 928#endif /* MSDOS */
378cc40b
LW
929EXT char *e_tmpname;
930EXT FILE *e_fp INIT(Nullfp);
931
8d063cd8 932EXT char tokenbuf[256];
a687059c 933EXT int expectterm INIT(TRUE); /* how to interpret ambiguous tokens */
ac58e20f 934EXT VOLATILE int in_eval INIT(FALSE); /* trap fatal errors? */
a687059c
LW
935EXT int multiline INIT(0); /* $*--do strings hold >1 line? */
936EXT int forkprocess; /* so do_open |- can return proc# */
937EXT int do_undump INIT(0); /* -u or dump seen? */
938EXT int error_count INIT(0); /* how many errors so far, max 10 */
939EXT int multi_start INIT(0); /* 1st line of multi-line string */
940EXT int multi_end INIT(0); /* last line of multi-line string */
941EXT int multi_open INIT(0); /* delimiter of said string */
942EXT int multi_close INIT(0); /* delimiter of said string */
8d063cd8
LW
943
944FILE *popen();
945/* char *str_get(); */
946STR *interp();
947void free_arg();
948STIO *stio_new();
1462b684 949void hoistmust();
45d8adaa 950void scanconst();
8d063cd8
LW
951
952EXT struct stat statbuf;
a687059c 953EXT struct stat statcache;
ee0007ab 954EXT STAB *statstab INIT(Nullstab);
e334a159 955EXT STR *statname INIT(Nullstr);
d9d8d8de 956#ifndef MSDOS
8d063cd8 957EXT struct tms timesbuf;
d9d8d8de 958#endif
378cc40b
LW
959EXT int uid;
960EXT int euid;
a687059c
LW
961EXT int gid;
962EXT int egid;
378cc40b
LW
963UIDTYPE getuid();
964UIDTYPE geteuid();
965GIDTYPE getgid();
966GIDTYPE getegid();
967EXT int unsafe;
8d063cd8
LW
968
969#ifdef DEBUGGING
ac58e20f 970EXT VOLATILE int debug INIT(0);
8d063cd8 971EXT int dlevel INIT(0);
a687059c
LW
972EXT int dlmax INIT(128);
973EXT char *debname;
974EXT char *debdelim;
d96024cf 975#define YYDEBUG 1
8d063cd8 976#endif
a687059c 977EXT int perldb INIT(0);
fe14fcc3 978#define YYMAXDEPTH 300
8d063cd8 979
378cc40b
LW
980EXT line_t cmdline INIT(NOLINE);
981
a687059c 982EXT STR str_undef;
8d063cd8
LW
983EXT STR str_no;
984EXT STR str_yes;
985
986/* runtime control stuff */
987
988EXT struct loop {
a687059c
LW
989 char *loop_label; /* what the loop was called, if anything */
990 int loop_sp; /* stack pointer to copy stuff down to */
8d063cd8 991 jmp_buf loop_env;
a687059c 992} *loop_stack;
8d063cd8
LW
993
994EXT int loop_ptr INIT(-1);
a687059c 995EXT int loop_max INIT(128);
8d063cd8
LW
996
997EXT jmp_buf top_env;
998
ac58e20f 999EXT char * VOLATILE goto_targ INIT(Nullch); /* cmd_exec gets strange when set */
8d063cd8 1000
450a55e4
LW
1001struct ufuncs {
1002 int (*uf_val)();
1003 int (*uf_set)();
1004 int uf_index;
1005};
1006
a687059c
LW
1007EXT ARRAY *stack; /* THE STACK */
1008
ac58e20f 1009EXT ARRAY * VOLATILE savestack; /* to save non-local values on */
378cc40b
LW
1010
1011EXT ARRAY *tosave; /* strings to save on recursive subroutine */
1012
a687059c 1013EXT ARRAY *lineary; /* lines of script for debugger */
d9d8d8de 1014EXT ARRAY *dbargs; /* args to call listed by caller function */
a687059c 1015
d9d8d8de
LW
1016EXT ARRAY *fdpid; /* keep fd-to-pid mappings for mypopen */
1017EXT HASH *pidstatus; /* keep pid-to-status mappings for waitpid */
a687059c 1018
ac58e20f
LW
1019EXT int *di; /* for tmp use in debuggers */
1020EXT char *dc;
1021EXT short *ds;
1022
fe14fcc3 1023/* Fix these up for __STDC__ */
ee0007ab 1024EXT time_t basetime INIT(0);
fe14fcc3 1025char *mktemp();
352d5a3a 1026#ifndef STANDARD_C
fe14fcc3 1027/* All of these are in stdlib.h or time.h for ANSI C */
8d063cd8 1028double atof();
a687059c 1029long time();
8d063cd8 1030struct tm *gmtime(), *localtime();
378cc40b
LW
1031char *index(), *rindex();
1032char *strcpy(), *strcat();
352d5a3a 1033#endif /* ! STANDARD_C */
8d063cd8 1034
8d063cd8 1035#ifdef EUNICE
378cc40b
LW
1036#define UNLINK unlnk
1037int unlnk();
8d063cd8
LW
1038#else
1039#define UNLINK unlink
1040#endif
a687059c 1041
fe14fcc3
LW
1042#ifndef HAS_SETREUID
1043#ifdef HAS_SETRESUID
a687059c 1044#define setreuid(r,e) setresuid(r,e,-1)
fe14fcc3 1045#define HAS_SETREUID
a687059c
LW
1046#endif
1047#endif
fe14fcc3
LW
1048#ifndef HAS_SETREGID
1049#ifdef HAS_SETRESGID
a687059c 1050#define setregid(r,e) setresgid(r,e,-1)
fe14fcc3 1051#define HAS_SETREGID
a687059c
LW
1052#endif
1053#endif
ee0007ab
LW
1054
1055#define SCAN_DEF 0
1056#define SCAN_TR 1
1057#define SCAN_REPL 2