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