home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / perl-4.036.tar.gz / perl-4.036.tar / perl-4.036 / perl.h < prev    next >
C/C++ Source or Header  |  1993-02-08  |  23KB  |  1,061 lines

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