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