home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / MacPerl Source ƒ / Perl5 / perl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-15  |  37.9 KB  |  1,588 lines  |  [TEXT/MPS ]

  1. /*    perl.h
  2.  *
  3.  *    Copyright (c) 1987-1994, 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.  */
  9. #ifndef H_PERL
  10. #define H_PERL 1
  11. #define OVERLOAD
  12.  
  13. #ifdef macintosh
  14. #include <stdio.h>
  15. #endif
  16.  
  17. #include "embed.h"
  18.  
  19. #define VOIDUSED 1
  20. #include "config.h"
  21.  
  22. #ifndef BYTEORDER
  23. #   define BYTEORDER 0x1234
  24. #endif
  25.  
  26. /* Overall memory policy? */
  27. #ifndef CONSERVATIVE
  28. #   define LIBERAL 1
  29. #endif
  30.  
  31. /*
  32.  * The following contortions are brought to you on behalf of all the
  33.  * standards, semi-standards, de facto standards, not-so-de-facto standards
  34.  * of the world, as well as all the other botches anyone ever thought of.
  35.  * The basic theory is that if we work hard enough here, the rest of the
  36.  * code can be a lot prettier.  Well, so much for theory.  Sorry, Henry...
  37.  */
  38.  
  39. #ifdef MYMALLOC
  40. #   ifdef HIDEMYMALLOC
  41. #    define malloc Mymalloc
  42. #    define realloc Myremalloc
  43. #    define free Myfree
  44. #   endif
  45. #   define safemalloc malloc
  46. #   define saferealloc realloc
  47. #   define safefree free
  48. #endif
  49.  
  50. /* work around some libPW problems */
  51. #ifdef DOINIT
  52. EXT char Error[1];
  53. #endif
  54.  
  55. /* define this once if either system, instead of cluttering up the src */
  56.  
  57. #ifdef MSDOS
  58. #define MSMAC    1
  59. #define DOSISH     1
  60. #define NIXUNIX    1
  61. #else
  62. #ifdef macintosh
  63. #define MSMAC    1
  64. #undef  DOSISH
  65. #define NIXUNIX    1
  66. #else
  67. #ifdef atarist
  68. #undef    MSMAC
  69. #define DOSISH    1
  70. #define NIXUNIX    1
  71. #else
  72. #undef MSMAC
  73. #undef DOSISH
  74. #undef NIXUNIX
  75. #endif
  76. #endif
  77. #endif
  78.  
  79. #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus) || defined(macintosh)
  80. # define STANDARD_C 1
  81. #endif
  82.  
  83. #if defined(HASVOLATILE) || defined(STANDARD_C)
  84. #   ifdef __cplusplus
  85. #    define VOL        // to temporarily suppress warnings
  86. #   else
  87. #    define VOL volatile
  88. #   endif
  89. #else
  90. #   define VOL
  91. #endif
  92.  
  93. #define TAINT_IF(c)    (tainted |= (c))
  94. #define TAINT_NOT    (tainted = 0)
  95. #define TAINT_PROPER(s)    if (tainting) taint_proper(no_security, s)
  96. #define TAINT_ENV()    if (tainting) taint_env()
  97.  
  98. #ifndef HAS_VFORK
  99. #   define vfork fork
  100. #endif
  101.  
  102. #ifdef HAS_GETPGRP2
  103. #   ifndef HAS_GETPGRP
  104. #    define HAS_GETPGRP
  105. #   endif
  106. #endif
  107.  
  108. #ifdef HAS_SETPGRP2
  109. #   ifndef HAS_SETPGRP
  110. #    define HAS_SETPGRP
  111. #   endif
  112. #endif
  113.  
  114. #include <stdio.h>
  115. #ifdef USE_NEXT_CTYPE 
  116. #include <appkit/NXCType.h>
  117. #else
  118. #include <ctype.h>
  119. #endif
  120.  
  121. #ifdef METHOD     /* Defined by OSF/1 v3.0 by ctype.h */
  122. #undef METHOD
  123. #endif
  124.  
  125. #include <setjmp.h>
  126.  
  127. #ifdef I_SYS_PARAM
  128. #   ifdef PARAM_NEEDS_TYPES
  129. #    include <sys/types.h>
  130. #   endif
  131. #   include <sys/param.h>
  132. #endif
  133.  
  134.  
  135. /* Use all the "standard" definitions? */
  136. #if defined(STANDARD_C) && defined(I_STDLIB)
  137. #   include <stdlib.h>
  138. #endif /* STANDARD_C */
  139.  
  140. #define MEM_SIZE Size_t
  141.  
  142. #if defined(I_STRING) || defined(__cplusplus)
  143. #   include <string.h>
  144. #else
  145. #   include <strings.h>
  146. #endif
  147.  
  148. #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
  149. #define strchr index
  150. #define strrchr rindex
  151. #endif
  152.  
  153. #if defined(mips) && defined(ultrix) && !defined(__STDC__)
  154. #   undef HAS_MEMCMP
  155. #endif
  156.  
  157. #ifdef HAS_MEMCPY
  158. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  159. #    ifndef memcpy
  160.         extern char * memcpy _((char*, char*, int));
  161. #    endif
  162. #  endif
  163. #else
  164. #   ifndef memcpy
  165. #    ifdef HAS_BCOPY
  166. #        define memcpy(d,s,l) bcopy(s,d,l)
  167. #    else
  168. #        define memcpy(d,s,l) my_bcopy(s,d,l)
  169. #    endif
  170. #   endif
  171. #endif /* HAS_MEMCPY */
  172.  
  173. #ifdef HAS_MEMSET
  174. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  175. #    ifndef memset
  176.     extern char *memset _((char*, int, int));
  177. #    endif
  178. #  endif
  179. #  define memzero(d,l) memset(d,0,l)
  180. #else
  181. #   ifndef memzero
  182. #    ifdef HAS_BZERO
  183. #        define memzero(d,l) bzero(d,l)
  184. #    else
  185. #        define memzero(d,l) my_bzero(d,l)
  186. #    endif
  187. #   endif
  188. #endif /* HAS_MEMSET */
  189.  
  190. #ifdef HAS_MEMCMP
  191. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  192. #    ifndef memcmp
  193.     extern int memcmp _((char*, char*, int));
  194. #    endif
  195. #  endif
  196. #else
  197. #   ifndef memcmp
  198. #    define memcmp(s1,s2,l) my_memcmp(s1,s2,l)
  199. #   endif
  200. #endif /* HAS_MEMCMP */
  201.  
  202. /* we prefer bcmp slightly for comparisons that don't care about ordering */
  203. #ifndef HAS_BCMP
  204. #   ifndef bcmp
  205. #    define bcmp(s1,s2,l) memcmp(s1,s2,l)
  206. #   endif
  207. #endif /* HAS_BCMP */
  208.  
  209. #if !defined(HAS_MEMMOVE) && !defined(memmove)
  210. #   if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
  211. #    define memmove(d,s,l) bcopy(s,d,l)
  212. #   else
  213. #    if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
  214. #        define memmove(d,s,l) memcpy(d,s,l)
  215. #    else
  216. #        define memmove(d,s,l) my_bcopy(s,d,l)
  217. #    endif
  218. #   endif
  219. #endif
  220.  
  221. #ifndef _TYPES_        /* If types.h defines this it's easy. */
  222. #   ifndef major        /* Does everyone's types.h define this? */
  223. #    include <sys/types.h>
  224. #   endif
  225. #endif
  226.  
  227. #ifdef I_NETINET_IN
  228. #   include <netinet/in.h>
  229. #endif
  230.  
  231. #include <sys/stat.h>
  232.  
  233. /* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
  234.    like UTekV) are broken, sometimes giving false positives.  Undefine
  235.    them here and let the code below set them to proper values.
  236.  
  237.    The ghs macro stands for GreenHills Software C-1.8.5 which
  238.    is the C compiler for sysV88 and the various derivatives.
  239.    This header file bug is corrected in gcc-2.5.8 and later versions.
  240.    --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94.  */
  241.  
  242. #if defined(uts) || (defined(m88k) && defined(ghs))
  243. #   undef S_ISDIR
  244. #   undef S_ISCHR
  245. #   undef S_ISBLK
  246. #   undef S_ISREG
  247. #   undef S_ISFIFO
  248. #   undef S_ISLNK
  249. #endif
  250.  
  251. #ifdef I_TIME
  252. #   include <time.h>
  253. #endif
  254.  
  255. #ifdef I_SYS_TIME
  256. #   ifdef I_SYS_TIME_KERNEL
  257. #    define KERNEL
  258. #   endif
  259. #   include <sys/time.h>
  260. #   ifdef I_SYS_TIME_KERNEL
  261. #    undef KERNEL
  262. #   endif
  263. #endif
  264.  
  265. #ifndef MSDOS
  266. #  if defined(HAS_TIMES) && defined(I_SYS_TIMES)
  267. #    include <sys/times.h>
  268. #  endif
  269. #endif
  270.  
  271. #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
  272. #   undef HAS_STRERROR
  273. #endif
  274.  
  275. #ifndef HAS_MKFIFO
  276. #  ifndef mkfifo
  277. #    define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
  278. #  endif
  279. #endif /* !HAS_MKFIFO */
  280.  
  281. #include <errno.h>
  282. #ifdef HAS_SOCKET
  283. #   ifdef I_NET_ERRNO
  284. #     include <net/errno.h>
  285. #   endif
  286. #endif
  287.  
  288. #ifndef MSDOS
  289. #   ifndef errno
  290.     extern int errno;     /* ANSI allows errno to be an lvalue expr */
  291. #   endif
  292. #endif
  293.  
  294. #ifdef HAS_STRERROR
  295. #       ifdef VMS
  296.     char *strerror _((int,...));
  297. #       else
  298.     char *strerror _((int));
  299. #       endif
  300. #       ifndef Strerror
  301. #           define Strerror strerror
  302. #       endif
  303. #else
  304. #    ifdef HAS_SYS_ERRLIST
  305.     extern int sys_nerr;
  306.     extern char *sys_errlist[];
  307. #       ifndef Strerror
  308. #           define Strerror(e) \
  309.         ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
  310. #       endif
  311. #   endif
  312. #endif
  313.  
  314. #ifdef I_SYS_IOCTL
  315. #   ifndef _IOCTL_
  316. #    include <sys/ioctl.h>
  317. #   endif
  318. #endif
  319.  
  320. #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
  321. #   ifdef HAS_SOCKETPAIR
  322. #    undef HAS_SOCKETPAIR
  323. #   endif
  324. #   ifdef I_NDBM
  325. #    undef I_NDBM
  326. #   endif
  327. #endif
  328.  
  329. #if INTSIZE == 2
  330. #   define htoni htons
  331. #   define ntohi ntohs
  332. #else
  333. #   define htoni htonl
  334. #   define ntohi ntohl
  335. #endif
  336.  
  337. /* Configure already sets Direntry_t */
  338. #if defined(I_DIRENT)
  339. #   include <dirent.h>
  340. #   if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
  341. #    include <sys/dir.h>
  342. #   endif
  343. #else
  344. #   ifdef I_SYS_NDIR
  345. #    include <sys/ndir.h>
  346. #   else
  347. #    ifdef I_SYS_DIR
  348. #        ifdef hp9000s500
  349. #        include <ndir.h>    /* may be wrong in the future */
  350. #        else
  351. #        include <sys/dir.h>
  352. #        endif
  353. #    endif
  354. #   endif
  355. #endif 
  356.  
  357. #ifdef FPUTS_BOTCH
  358. /* work around botch in SunOS 4.0.1 and 4.0.2 */
  359. #   ifndef fputs
  360. #    define fputs(sv,fp) fprintf(fp,"%s",sv)
  361. #   endif
  362. #endif
  363.  
  364. /*
  365.  * The following gobbledygook brought to you on behalf of __STDC__.
  366.  * (I could just use #ifndef __STDC__, but this is more bulletproof
  367.  * in the face of half-implementations.)
  368.  */
  369.  
  370. #ifndef S_IFMT
  371. #   ifdef _S_IFMT
  372. #    define S_IFMT _S_IFMT
  373. #   else
  374. #    define S_IFMT 0170000
  375. #   endif
  376. #endif
  377.  
  378. #ifndef S_ISDIR
  379. #   define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
  380. #endif
  381.  
  382. #ifndef S_ISCHR
  383. #   define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
  384. #endif
  385.  
  386. #ifndef S_ISBLK
  387. #   ifdef S_IFBLK
  388. #    define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
  389. #   else
  390. #    define S_ISBLK(m) (0)
  391. #   endif
  392. #endif
  393.  
  394. #ifndef S_ISREG
  395. #   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
  396. #endif
  397.  
  398. #ifndef S_ISFIFO
  399. #   ifdef S_IFIFO
  400. #    define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
  401. #   else
  402. #    define S_ISFIFO(m) (0)
  403. #   endif
  404. #endif
  405.  
  406. #ifndef S_ISLNK
  407. #   ifdef _S_ISLNK
  408. #    define S_ISLNK(m) _S_ISLNK(m)
  409. #   else
  410. #    ifdef _S_IFLNK
  411. #        define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
  412. #    else
  413. #        ifdef S_IFLNK
  414. #        define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
  415. #        else
  416. #        define S_ISLNK(m) (0)
  417. #        endif
  418. #    endif
  419. #   endif
  420. #endif
  421.  
  422. #ifndef S_ISSOCK
  423. #   ifdef _S_ISSOCK
  424. #    define S_ISSOCK(m) _S_ISSOCK(m)
  425. #   else
  426. #    ifdef _S_IFSOCK
  427. #        define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
  428. #    else
  429. #        ifdef S_IFSOCK
  430. #        define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
  431. #        else
  432. #        define S_ISSOCK(m) (0)
  433. #        endif
  434. #    endif
  435. #   endif
  436. #endif
  437.  
  438. #ifndef S_IRUSR
  439. #   ifdef S_IREAD
  440. #    define S_IRUSR S_IREAD
  441. #    define S_IWUSR S_IWRITE
  442. #    define S_IXUSR S_IEXEC
  443. #   else
  444. #    define S_IRUSR 0400
  445. #    define S_IWUSR 0200
  446. #    define S_IXUSR 0100
  447. #   endif
  448. #   define S_IRGRP (S_IRUSR>>3)
  449. #   define S_IWGRP (S_IWUSR>>3)
  450. #   define S_IXGRP (S_IXUSR>>3)
  451. #   define S_IROTH (S_IRUSR>>6)
  452. #   define S_IWOTH (S_IWUSR>>6)
  453. #   define S_IXOTH (S_IXUSR>>6)
  454. #endif
  455.  
  456. #ifndef S_ISUID
  457. #   define S_ISUID 04000
  458. #endif
  459.  
  460. #ifndef S_ISGID
  461. #   define S_ISGID 02000
  462. #endif
  463.  
  464. #ifdef ff_next
  465. #   undef ff_next
  466. #endif
  467.  
  468. #if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
  469. #   define SLOPPYDIVIDE
  470. #endif
  471.  
  472. #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
  473. #   define QUAD
  474. #endif
  475.  
  476. #ifdef QUAD
  477. #   ifdef cray
  478. #    define quad int
  479. #   else
  480. #    if defined(convex) || defined (uts)
  481. #        define quad long long
  482. #    else
  483. #        define quad long
  484. #    endif
  485. #   endif
  486. #endif
  487.  
  488. #ifdef VOIDSIG
  489. #   define VOIDRET void
  490. #else
  491. #   define VOIDRET int
  492. #endif
  493.  
  494. #ifdef macintosh
  495. #   include "macish.h"
  496. #else
  497. # ifdef DOSISH
  498. #   include "dosish.h"
  499. # else
  500. #  if defined(VMS)
  501. #   include "vmsish.h"
  502. #  else
  503. #   include "unixish.h"
  504. #  endif
  505. # endif
  506. #endif
  507.  
  508. #ifndef HAS_PAUSE
  509. #define pause() sleep((32767<<16)+32767)
  510. #endif
  511.  
  512. #ifndef IOCPARM_LEN
  513. #   ifdef IOCPARM_MASK
  514.     /* on BSDish systes we're safe */
  515. #    define IOCPARM_LEN(x)  (((x) >> 16) & IOCPARM_MASK)
  516. #   else
  517.     /* otherwise guess at what's safe */
  518. #    define IOCPARM_LEN(x)    256
  519. #   endif
  520. #endif
  521.  
  522. typedef MEM_SIZE STRLEN;
  523.  
  524. typedef struct op OP;
  525. typedef struct cop COP;
  526. typedef struct unop UNOP;
  527. typedef struct binop BINOP;
  528. typedef struct listop LISTOP;
  529. typedef struct logop LOGOP;
  530. typedef struct condop CONDOP;
  531. typedef struct pmop PMOP;
  532. typedef struct svop SVOP;
  533. typedef struct gvop GVOP;
  534. typedef struct pvop PVOP;
  535. typedef struct cvop CVOP;
  536. typedef struct loop LOOP;
  537.  
  538. typedef struct Outrec Outrec;
  539. typedef struct lstring Lstring;
  540. typedef struct interpreter PerlInterpreter;
  541. typedef struct ff FF;
  542. typedef struct sv SV;
  543. typedef struct av AV;
  544. typedef struct hv HV;
  545. typedef struct cv CV;
  546. typedef struct regexp REGEXP;
  547. typedef struct gp GP;
  548. typedef struct sv GV;
  549. typedef struct io IO;
  550. typedef struct context CONTEXT;
  551. typedef struct block BLOCK;
  552.  
  553. typedef struct magic MAGIC;
  554. typedef struct xrv XRV;
  555. typedef struct xpv XPV;
  556. typedef struct xpviv XPVIV;
  557. typedef struct xpvnv XPVNV;
  558. typedef struct xpvmg XPVMG;
  559. typedef struct xpvlv XPVLV;
  560. typedef struct xpvav XPVAV;
  561. typedef struct xpvhv XPVHV;
  562. typedef struct xpvgv XPVGV;
  563. typedef struct xpvcv XPVCV;
  564. typedef struct xpvbm XPVBM;
  565. typedef struct xpvfm XPVFM;
  566. typedef struct xpvio XPVIO;
  567. typedef struct mgvtbl MGVTBL;
  568. typedef union any ANY;
  569.  
  570. typedef FILE * (*cryptswitch_t) _((FILE *rfp));
  571.  
  572. #include "handy.h"
  573.  
  574. #ifdef QUAD
  575. typedef quad IV;
  576. #else
  577. typedef long IV;
  578. #endif
  579.  
  580. union any {
  581.     void*    any_ptr;
  582.     I32        any_i32;
  583.     IV        any_iv;
  584.     long    any_long;
  585.     void    (*any_dptr) _((void*));
  586. };
  587.  
  588. #include "regexp.h"
  589. #include "sv.h"
  590. #include "util.h"
  591. #include "form.h"
  592. #include "gv.h"
  593. #include "cv.h"
  594. #include "opcode.h"
  595. #include "op.h"
  596. #include "cop.h"
  597. #include "av.h"
  598. #include "hv.h"
  599. #include "mg.h"
  600. #include "scope.h"
  601.  
  602. #if defined(iAPX286) || defined(M_I286) || defined(I80286)
  603. #   define I286
  604. #endif
  605.  
  606. #ifndef    STANDARD_C
  607. #   ifdef CHARSPRINTF
  608.     char *sprintf _((char *, const char *, ...));
  609. #   else
  610.     int sprintf _((char *, const char *, ...));
  611. #   endif
  612. #endif
  613.  
  614. #if defined(htonl) && !defined(HAS_HTONL)
  615. #define HAS_HTONL
  616. #endif
  617. #if defined(htons) && !defined(HAS_HTONS)
  618. #define HAS_HTONS
  619. #endif
  620. #if defined(ntohl) && !defined(HAS_NTOHL)
  621. #define HAS_NTOHL
  622. #endif
  623. #if defined(ntohs) && !defined(HAS_NTOHS)
  624. #define HAS_NTOHS
  625. #endif
  626. #ifndef HAS_HTONL
  627. #if (BYTEORDER & 0xffff) != 0x4321
  628. #define HAS_HTONS
  629. #define HAS_HTONL
  630. #define HAS_NTOHS
  631. #define HAS_NTOHL
  632. #define MYSWAP
  633. #define htons my_swap
  634. #define htonl my_htonl
  635. #define ntohs my_swap
  636. #define ntohl my_ntohl
  637. #endif
  638. #else
  639. #if (BYTEORDER & 0xffff) == 0x4321
  640. #undef HAS_HTONS
  641. #undef HAS_HTONL
  642. #undef HAS_NTOHS
  643. #undef HAS_NTOHL
  644. #endif
  645. #endif
  646.  
  647. /*
  648.  * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
  649.  * -DWS
  650.  */
  651. #if BYTEORDER != 0x1234
  652. # define HAS_VTOHL
  653. # define HAS_VTOHS
  654. # define HAS_HTOVL
  655. # define HAS_HTOVS
  656. # if BYTEORDER == 0x4321
  657. #  define vtohl(x)    ((((x)&0xFF)<<24)    \
  658.             +(((x)>>24)&0xFF)    \
  659.             +(((x)&0x0000FF00)<<8)    \
  660.             +(((x)&0x00FF0000)>>8)    )
  661. #  define vtohs(x)    ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
  662. #  define htovl(x)    vtohl(x)
  663. #  define htovs(x)    vtohs(x)
  664. # endif
  665.     /* otherwise default to functions in util.c */
  666. #endif
  667.  
  668. #ifdef CASTNEGFLOAT
  669. #define U_S(what) ((U16)(what))
  670. #define U_I(what) ((unsigned int)(what))
  671. #define U_L(what) ((U32)(what))
  672. #else
  673. U32 cast_ulong _((double));
  674. #define U_S(what) ((U16)cast_ulong(what))
  675. #define U_I(what) ((unsigned int)cast_ulong(what))
  676. #define U_L(what) (cast_ulong(what))
  677. #endif
  678.  
  679. #ifdef CASTI32
  680. #define I_32(what) ((I32)(what))
  681. #define I_V(what) ((IV)(what))
  682. #else
  683. I32 cast_i32 _((double));
  684. #define I_32(what) (cast_i32(what))
  685. IV cast_iv _((double));
  686. #define I_V(what) (cast_iv(what))
  687. #endif
  688.  
  689. struct Outrec {
  690.     I32        o_lines;
  691.     char    *o_str;
  692.     U32        o_len;
  693. };
  694.  
  695. #ifndef MAXSYSFD
  696. #   define MAXSYSFD 2
  697. #endif
  698.  
  699. #ifdef DOSISH
  700. #define TMPPATH "plXXXXXX"
  701. #else
  702. #ifdef VMS
  703. #define TMPPATH "/sys$scratch/perl-eXXXXXX"
  704. #else
  705. #define TMPPATH "/tmp/perl-eXXXXXX"
  706. #ifdef macintosh
  707. #define mktemp tmpnam
  708. #endif
  709. #endif
  710. #endif
  711.  
  712. #ifndef __cplusplus
  713. Uid_t getuid _((void));
  714. Uid_t geteuid _((void));
  715. Gid_t getgid _((void));
  716. Gid_t getegid _((void));
  717. #endif
  718.  
  719. #ifdef DEBUGGING
  720. #define YYDEBUG 1
  721. #define DEB(a)                 a
  722. #define DEBUG(a)   if (debug)        a
  723. #define DEBUG_p(a) if (debug & 1)    a
  724. #define DEBUG_s(a) if (debug & 2)    a
  725. #define DEBUG_l(a) if (debug & 4)    a
  726. #define DEBUG_t(a) if (debug & 8)    a
  727. #define DEBUG_o(a) if (debug & 16)    a
  728. #define DEBUG_c(a) if (debug & 32)    a
  729. #define DEBUG_P(a) if (debug & 64)    a
  730. #ifdef macintosh
  731. #define DEBUG_m(a) if (curinterp && debug & 128)    a
  732. #else
  733. #define DEBUG_m(a) if (debug & 128)    a
  734. #endif
  735. #define DEBUG_f(a) if (debug & 256)    a
  736. #define DEBUG_r(a) if (debug & 512)    a
  737. #define DEBUG_x(a) if (debug & 1024)    a
  738. #define DEBUG_u(a) if (debug & 2048)    a
  739. #define DEBUG_L(a) if (debug & 4096)    a
  740. #define DEBUG_H(a) if (debug & 8192)    a
  741. #define DEBUG_X(a) if (debug & 16384)    a
  742. #define DEBUG_D(a) if (debug & 32768)    a
  743. #else
  744. #define DEB(a)
  745. #define DEBUG(a)
  746. #define DEBUG_p(a)
  747. #define DEBUG_s(a)
  748. #define DEBUG_l(a)
  749. #define DEBUG_t(a)
  750. #define DEBUG_o(a)
  751. #define DEBUG_c(a)
  752. #define DEBUG_P(a)
  753. #define DEBUG_m(a)
  754. #define DEBUG_f(a)
  755. #define DEBUG_r(a)
  756. #define DEBUG_x(a)
  757. #define DEBUG_u(a)
  758. #define DEBUG_L(a)
  759. #define DEBUG_H(a)
  760. #define DEBUG_X(a)
  761. #define DEBUG_D(a)
  762. #endif
  763. #define YYMAXDEPTH 300
  764.  
  765. #define assert(what)    DEB( {                        \
  766.     if (!(what)) {                            \
  767.         croak("Assertion failed: file \"%s\", line %d",        \
  768.         __FILE__, __LINE__);                    \
  769.         exit(1);                            \
  770.     }})
  771.  
  772. struct ufuncs {
  773.     I32 (*uf_val)_((IV, SV*));
  774.     I32 (*uf_set)_((IV, SV*));
  775.     IV uf_index;
  776. };
  777.  
  778. /* Fix these up for __STDC__ */
  779. #ifndef __cplusplus
  780. char *mktemp _((char*));
  781. double atof _((const char*));
  782. #endif
  783.  
  784. #ifndef STANDARD_C
  785. /* All of these are in stdlib.h or time.h for ANSI C */
  786. Time_t time();
  787. struct tm *gmtime(), *localtime();
  788. char *strchr(), *strrchr();
  789. char *strcpy(), *strcat();
  790. #endif /* ! STANDARD_C */
  791.  
  792.  
  793. #ifdef I_MATH
  794. #    include <math.h>
  795. #else
  796. #   ifdef __cplusplus
  797.     extern "C" {
  798. #   endif
  799.         double exp _((double));
  800.         double fmod _((double,double));
  801.         double log _((double));
  802.         double sqrt _((double));
  803.         double modf _((double,double*));
  804.         double sin _((double));
  805.         double cos _((double));
  806.         double atan2 _((double,double));
  807.         double pow _((double,double));
  808. #   ifdef __cplusplus
  809.     };
  810. #   endif
  811. #endif
  812.  
  813. #if !defined(HAS_FMOD) && defined(HAS_DREM)
  814. #define fmod(x,y) drem((x),(y))
  815. #endif
  816.  
  817. #ifndef __cplusplus
  818. char *crypt _((const char*, const char*));
  819. char *getenv _((const char*));
  820. Off_t lseek _((int,Off_t,int));
  821. char *getlogin _((void));
  822. #endif
  823.  
  824. #ifdef EUNICE
  825. #define UNLINK unlnk
  826. I32 unlnk _((char*));
  827. #else
  828. #define UNLINK unlink
  829. #endif
  830.  
  831. #ifndef HAS_SETREUID
  832. #  ifdef HAS_SETRESUID
  833. #    define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
  834. #    define HAS_SETREUID
  835. #  endif
  836. #endif
  837. #ifndef HAS_SETREGID
  838. #  ifdef HAS_SETRESGID
  839. #    define setregid(r,e) setresgid(r,e,(Gid_t)-1)
  840. #    define HAS_SETREGID
  841. #  endif
  842. #endif
  843.  
  844. #define SCAN_DEF 0
  845. #define SCAN_TR 1
  846. #define SCAN_REPL 2
  847.  
  848. #ifdef DEBUGGING
  849. # ifndef register 
  850. #  define register
  851. # endif
  852. # define PAD_SV(po) pad_sv(po)
  853. #else
  854. # define PAD_SV(po) curpad[po]
  855. #endif
  856.  
  857. /****************/
  858. /* Truly global */
  859. /****************/
  860.  
  861. /* global state */
  862. EXT PerlInterpreter *    curinterp;    /* currently running interpreter */
  863. #ifndef VMS  /* VMS doesn't use environ array */
  864. extern char **    environ;    /* environment variables supplied via exec */
  865. #endif
  866. EXT int        uid;        /* current real user id */
  867. EXT int        euid;        /* current effective user id */
  868. EXT int        gid;        /* current real group id */
  869. EXT int        egid;        /* current effective group id */
  870. EXT bool    nomemok;    /* let malloc context handle nomem */
  871. EXT U32        an;        /* malloc sequence number */
  872. EXT U32        cop_seqmax;    /* statement sequence number */
  873. EXT U32        op_seqmax;    /* op sequence number */
  874. EXT U32        evalseq;    /* eval sequence number */
  875. EXT U32        sub_generation;    /* inc to force methods to be looked up again */
  876. EXT char **    origenviron;
  877. EXT U32        origalen;
  878. EXT U32 *    profiledata;
  879.  
  880. EXT XPV*    xiv_arenaroot;    /* list of allocated xiv areas */
  881. EXT IV **    xiv_root;    /* free xiv list--shared by interpreters */
  882. EXT double *    xnv_root;    /* free xnv list--shared by interpreters */
  883. EXT XRV *    xrv_root;    /* free xrv list--shared by interpreters */
  884. EXT XPV *    xpv_root;    /* free xpv list--shared by interpreters */
  885.  
  886. /* Stack for currently executing thread--context switch must handle this.     */
  887. EXT SV **    stack_base;    /* stack->array_ary */
  888. EXT SV **    stack_sp;    /* stack pointer now */
  889. EXT SV **    stack_max;    /* stack->array_ary + stack->array_max */
  890.  
  891. /* likewise for these */
  892.  
  893. EXT OP *    op;        /* current op--oughta be in a global register */
  894.  
  895. EXT I32 *    scopestack;    /* blocks we've entered */
  896. EXT I32        scopestack_ix;
  897. EXT I32        scopestack_max;
  898.  
  899. EXT ANY*    savestack;    /* to save non-local values on */
  900. EXT I32        savestack_ix;
  901. EXT I32        savestack_max;
  902.  
  903. EXT OP **    retstack;    /* returns we've pushed */
  904. EXT I32        retstack_ix;
  905. EXT I32        retstack_max;
  906.  
  907. EXT I32 *    markstack;    /* stackmarks we're remembering */
  908. EXT I32 *    markstack_ptr;    /* stackmarks we're remembering */
  909. EXT I32 *    markstack_max;    /* stackmarks we're remembering */
  910.  
  911. EXT SV **    curpad;
  912.  
  913. /* temp space */
  914. EXT SV *    Sv;
  915. EXT XPV *    Xpv;
  916. EXT char    buf[1024];
  917. EXT char    tokenbuf[256];
  918. EXT struct stat    statbuf;
  919. #ifndef MSDOS
  920. EXT struct tms    timesbuf;
  921. #endif
  922. EXT STRLEN na;        /* for use in SvPV when length is Not Applicable */
  923.  
  924. /* for tmp use in stupid debuggers */
  925. EXT int *    di;
  926. EXT short *    ds;
  927. EXT char *    dc;
  928.  
  929. /* handy constants */
  930. EXT char *    Yes INIT("1");
  931. EXT char *    No INIT("");
  932. EXT char *    hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
  933. EXT char *    patleave INIT("\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}");
  934. EXT char *    vert INIT("|");
  935.  
  936. EXT char    warn_uninit[]
  937.   INIT("Use of uninitialized value");
  938. EXT char    warn_nosemi[]
  939.   INIT("Semicolon seems to be missing");
  940. EXT char    warn_reserved[]
  941.   INIT("Unquoted string \"%s\" may clash with future reserved word");
  942. EXT char    warn_nl[]
  943.   INIT("Unsuccessful %s on filename containing newline");
  944. EXT char    no_wrongref[]
  945.   INIT("Can't use %s ref as %s ref");
  946. EXT char    no_symref[]
  947.   INIT("Can't use a string as %s ref while \"strict refs\" in use");
  948. EXT char    no_usym[]
  949.   INIT("Can't use an undefined value as %s reference");
  950. EXT char    no_aelem[]
  951.   INIT("Modification of non-creatable array value attempted, subscript %d");
  952. EXT char    no_helem[]
  953.   INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
  954. EXT char    no_modify[]
  955.   INIT("Modification of a read-only value attempted");
  956. EXT char    no_mem[]
  957.   INIT("Out of memory!\n");
  958. EXT char    no_security[]
  959.   INIT("Insecure dependency in %s%s");
  960. EXT char    no_sock_func[]
  961.   INIT("Unsupported socket function \"%s\" called");
  962. EXT char    no_dir_func[]
  963.   INIT("Unsupported directory function \"%s\" called");
  964. EXT char    no_func[]
  965.   INIT("The %s function is unimplemented");
  966.  
  967. EXT SV        sv_undef;
  968. EXT SV        sv_no;
  969. EXT SV        sv_yes;
  970. #ifdef CSH
  971.     EXT char *    cshname INIT(CSH);
  972.     EXT I32    cshlen;
  973. #endif
  974.  
  975. #ifdef DOINIT
  976. EXT char *sig_name[] = {
  977.     SIG_NAME,0
  978. };
  979. #else
  980. EXT char *sig_name[];
  981. #endif
  982.  
  983. #ifdef DOINIT
  984. EXT unsigned char fold[] = {    /* fast case folding table */
  985.     0,    1,    2,    3,    4,    5,    6,    7,
  986.     8,    9,    10,    11,    12,    13,    14,    15,
  987.     16,    17,    18,    19,    20,    21,    22,    23,
  988.     24,    25,    26,    27,    28,    29,    30,    31,
  989.     32,    33,    34,    35,    36,    37,    38,    39,
  990.     40,    41,    42,    43,    44,    45,    46,    47,
  991.     48,    49,    50,    51,    52,    53,    54,    55,
  992.     56,    57,    58,    59,    60,    61,    62,    63,
  993.     64,    'a',    'b',    'c',    'd',    'e',    'f',    'g',
  994.     'h',    'i',    'j',    'k',    'l',    'm',    'n',    'o',
  995.     'p',    'q',    'r',    's',    't',    'u',    'v',    'w',
  996.     'x',    'y',    'z',    91,    92,    93,    94,    95,
  997.     96,    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  998.     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
  999.     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
  1000.     'X',    'Y',    'Z',    123,    124,    125,    126,    127,
  1001.     128,    129,    130,    131,    132,    133,    134,    135,
  1002.     136,    137,    138,    139,    140,    141,    142,    143,
  1003.     144,    145,    146,    147,    148,    149,    150,    151,
  1004.     152,    153,    154,    155,    156,    157,    158,    159,
  1005.     160,    161,    162,    163,    164,    165,    166,    167,
  1006.     168,    169,    170,    171,    172,    173,    174,    175,
  1007.     176,    177,    178,    179,    180,    181,    182,    183,
  1008.     184,    185,    186,    187,    188,    189,    190,    191,
  1009.     192,    193,    194,    195,    196,    197,    198,    199,
  1010.     200,    201,    202,    203,    204,    205,    206,    207,
  1011.     208,    209,    210,    211,    212,    213,    214,    215,
  1012.     216,    217,    218,    219,    220,    221,    222,    223,    
  1013.     224,    225,    226,    227,    228,    229,    230,    231,
  1014.     232,    233,    234,    235,    236,    237,    238,    239,
  1015.     240,    241,    242,    243,    244,    245,    246,    247,
  1016.     248,    249,    250,    251,    252,    253,    254,    255
  1017. };
  1018. #else
  1019. EXT unsigned char fold[];
  1020. #endif
  1021.  
  1022. #ifdef DOINIT
  1023. EXT unsigned char freq[] = {    /* letter frequencies for mixed English/C */
  1024.     1,    2,    84,    151,    154,    155,    156,    157,
  1025.     165,    246,    250,    3,    158,    7,    18,    29,
  1026.     40,    51,    62,    73,    85,    96,    107,    118,
  1027.     129,    140,    147,    148,    149,    150,    152,    153,
  1028.     255,    182,    224,    205,    174,    176,    180,    217,
  1029.     233,    232,    236,    187,    235,    228,    234,    226,
  1030.     222,    219,    211,    195,    188,    193,    185,    184,
  1031.     191,    183,    201,    229,    181,    220,    194,    162,
  1032.     163,    208,    186,    202,    200,    218,    198,    179,
  1033.     178,    214,    166,    170,    207,    199,    209,    206,
  1034.     204,    160,    212,    216,    215,    192,    175,    173,
  1035.     243,    172,    161,    190,    203,    189,    164,    230,
  1036.     167,    248,    227,    244,    242,    255,    241,    231,
  1037.     240,    253,    169,    210,    245,    237,    249,    247,
  1038.     239,    168,    252,    251,    254,    238,    223,    221,
  1039.     213,    225,    177,    197,    171,    196,    159,    4,
  1040.     5,    6,    8,    9,    10,    11,    12,    13,
  1041.     14,    15,    16,    17,    19,    20,    21,    22,
  1042.     23,    24,    25,    26,    27,    28,    30,    31,
  1043.     32,    33,    34,    35,    36,    37,    38,    39,
  1044.     41,    42,    43,    44,    45,    46,    47,    48,
  1045.     49,    50,    52,    53,    54,    55,    56,    57,
  1046.     58,    59,    60,    61,    63,    64,    65,    66,
  1047.     67,    68,    69,    70,    71,    72,    74,    75,
  1048.     76,    77,    78,    79,    80,    81,    82,    83,
  1049.     86,    87,    88,    89,    90,    91,    92,    93,
  1050.     94,    95,    97,    98,    99,    100,    101,    102,
  1051.     103,    104,    105,    106,    108,    109,    110,    111,
  1052.     112,    113,    114,    115,    116,    117,    119,    120,
  1053.     121,    122,    123,    124,    125,    126,    127,    128,
  1054.     130,    131,    132,    133,    134,    135,    136,    137,
  1055.     138,    139,    141,    142,    143,    144,    145,    146
  1056. };
  1057. #else
  1058. EXT unsigned char freq[];
  1059. #endif
  1060.  
  1061. #ifdef DEBUGGING
  1062. #ifdef DOINIT
  1063. EXT char* block_type[] = {
  1064.     "NULL",
  1065.     "SUB",
  1066.     "EVAL",
  1067.     "LOOP",
  1068.     "SUBST",
  1069.     "BLOCK",
  1070. };
  1071. #else
  1072. EXT char* block_type[];
  1073. #endif
  1074. #endif
  1075.  
  1076. /*****************************************************************************/
  1077. /* This lexer/parser stuff is currently global since yacc is hard to reenter */
  1078. /*****************************************************************************/
  1079. /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
  1080.  
  1081. #include "perly.h"
  1082.  
  1083. typedef enum {
  1084.     XOPERATOR,
  1085.     XTERM,
  1086.     XREF,
  1087.     XSTATE,
  1088.     XBLOCK,
  1089.     XTERMBLOCK
  1090. } expectation;
  1091.  
  1092. EXT U32        lex_state;    /* next token is determined */
  1093. EXT U32        lex_defer;    /* state after determined token */
  1094. EXT expectation    lex_expect;    /* expect after determined token */
  1095. EXT I32        lex_brackets;    /* bracket count */
  1096. EXT I32        lex_formbrack;    /* bracket count at outer format level */
  1097. EXT I32        lex_fakebrack;    /* outer bracket is mere delimiter */
  1098. EXT I32        lex_casemods;    /* casemod count */
  1099. EXT I32        lex_dojoin;    /* doing an array interpolation */
  1100. EXT I32        lex_starts;    /* how many interps done on level */
  1101. EXT SV *    lex_stuff;    /* runtime pattern from m// or s/// */
  1102. EXT SV *    lex_repl;    /* runtime replacement from s/// */
  1103. EXT OP *    lex_op;        /* extra info to pass back on op */
  1104. EXT OP *    lex_inpat;    /* in pattern $) and $| are special */
  1105. EXT I32        lex_inwhat;    /* what kind of quoting are we in */
  1106. EXT char *    lex_brackstack;    /* what kind of brackets to pop */
  1107. EXT char *    lex_casestack;    /* what kind of case mods in effect */
  1108.  
  1109. /* What we know when we're in LEX_KNOWNEXT state. */
  1110. EXT YYSTYPE    nextval[5];    /* value of next token, if any */
  1111. EXT I32        nexttype[5];    /* type of next token */
  1112. EXT I32        nexttoke;
  1113.  
  1114. EXT FILE * VOL    rsfp INIT(Nullfp);
  1115. EXT SV *    linestr;
  1116. EXT char *    bufptr;
  1117. EXT char *    oldbufptr;
  1118. EXT char *    oldoldbufptr;
  1119. EXT char *    bufend;
  1120. EXT expectation expect INIT(XSTATE);    /* how to interpret ambiguous tokens */
  1121. EXT char *    autoboot_preamble INIT(Nullch);
  1122.  
  1123. EXT I32        multi_start;    /* 1st line of multi-line string */
  1124. EXT I32        multi_end;    /* last line of multi-line string */
  1125. EXT I32        multi_open;    /* delimiter of said string */
  1126. EXT I32        multi_close;    /* delimiter of said string */
  1127.  
  1128. EXT GV *    scrgv;
  1129. EXT I32        error_count;    /* how many errors so far, max 10 */
  1130. EXT I32        subline;    /* line this subroutine began on */
  1131. EXT SV *    subname;    /* name of current subroutine */
  1132.  
  1133. EXT AV *    comppad;    /* storage for lexically scoped temporaries */
  1134. EXT AV *    comppad_name;    /* variable names for "my" variables */
  1135. EXT I32        comppad_name_fill;/* last "introduced" variable offset */
  1136. EXT I32        min_intro_pending;/* start of vars to introduce */
  1137. EXT I32        max_intro_pending;/* end of vars to introduce */
  1138. EXT I32        padix;        /* max used index in current "register" pad */
  1139. EXT I32        padix_floor;    /* how low may inner block reset padix */
  1140. EXT bool    pad_reset_pending; /* reset pad on next attempted alloc */
  1141. EXT COP        compiling;
  1142.  
  1143. EXT I32        thisexpr;    /* name id for nothing_in_common() */
  1144. EXT char *    last_uni;    /* position of last named-unary operator */
  1145. EXT char *    last_lop;    /* position of last list operator */
  1146. EXT OPCODE    last_lop_op;    /* last list operator */
  1147. EXT bool    in_my;        /* we're compiling a "my" declaration */
  1148. #ifdef FCRYPT
  1149. EXT I32        cryptseen;    /* has fast crypt() been initialized? */
  1150. #endif
  1151.  
  1152. EXT U32        hints;        /* various compilation flags */
  1153.  
  1154.                 /* Note: the lowest 8 bits are reserved for
  1155.                    stuffing into op->op_private */
  1156. #define HINT_INTEGER        0x00000001
  1157. #define HINT_STRICT_REFS    0x00000002
  1158.  
  1159. #define HINT_BLOCK_SCOPE    0x00000100
  1160. #define HINT_STRICT_SUBS    0x00000200
  1161. #define HINT_STRICT_VARS    0x00000400
  1162.  
  1163. /**************************************************************************/
  1164. /* This regexp stuff is global since it always happens within 1 expr eval */
  1165. /**************************************************************************/
  1166.  
  1167. EXT char *    regprecomp;    /* uncompiled string. */
  1168. EXT char *    regparse;    /* Input-scan pointer. */
  1169. EXT char *    regxend;    /* End of input for compile */
  1170. EXT I32        regnpar;    /* () count. */
  1171. EXT char *    regcode;    /* Code-emit pointer; ®dummy = don't. */
  1172. EXT I32        regsize;    /* Code size. */
  1173. EXT I32        regnaughty;    /* How bad is this pattern? */
  1174. EXT I32        regsawback;    /* Did we see \1, ...? */
  1175.  
  1176. EXT char *    reginput;    /* String-input pointer. */
  1177. EXT char *    regbol;        /* Beginning of input, for ^ check. */
  1178. EXT char *    regeol;        /* End of input, for $ check. */
  1179. EXT char **    regstartp;    /* Pointer to startp array. */
  1180. EXT char **    regendp;    /* Ditto for endp. */
  1181. EXT U32 *    reglastparen;    /* Similarly for lastparen. */
  1182. EXT char *    regtill;    /* How far we are required to go. */
  1183. EXT U16        regflags;    /* are we folding, multilining? */
  1184. EXT char    regprev;    /* char before regbol, \n if none */
  1185.  
  1186. /***********************************************/
  1187. /* Global only to current interpreter instance */
  1188. /***********************************************/
  1189.  
  1190. #ifdef MULTIPLICITY
  1191. #define IEXT
  1192. #define IINIT(x)
  1193. struct interpreter {
  1194. #else
  1195. #define IEXT EXT
  1196. #define IINIT(x) INIT(x)
  1197. #endif
  1198.  
  1199. /* pseudo environmental stuff */
  1200. IEXT int    Iorigargc;
  1201. IEXT char **    Iorigargv;
  1202. IEXT GV *    Ienvgv;
  1203. IEXT GV *    Isiggv;
  1204. IEXT GV *    Iincgv;
  1205. IEXT char *    Iorigfilename;
  1206.  
  1207. /* switches */
  1208. IEXT char *    Icddir;
  1209. IEXT bool    Iminus_c;
  1210. IEXT char    Ipatchlevel[6];
  1211. IEXT char *    Inrs IINIT("\n");
  1212. IEXT U32    Inrschar IINIT('\n');   /* final char of rs, or 0777 if none */
  1213. IEXT I32    Inrslen IINIT(1);
  1214. IEXT char *    Isplitstr IINIT(" ");
  1215. IEXT bool    Ipreprocess;
  1216. IEXT bool    Iminus_n;
  1217. IEXT bool    Iminus_p;
  1218. IEXT bool    Iminus_l;
  1219. IEXT bool    Iminus_a;
  1220. IEXT bool    Iminus_F;
  1221. IEXT bool    Idoswitches;
  1222. IEXT bool    Idowarn;
  1223. IEXT bool    Idoextract;
  1224. IEXT bool    Isawampersand;    /* must save all match strings */
  1225. IEXT bool    Isawstudy;    /* do fbm_instr on all strings */
  1226. IEXT bool    Isawi;        /* study must assume case insensitive */
  1227. IEXT bool    Isawvec;
  1228. IEXT bool    Iunsafe;
  1229. IEXT bool    Ido_undump;        /* -u or dump seen? */
  1230. IEXT char *    Iinplace;
  1231. IEXT char *    Ie_tmpname;
  1232. IEXT FILE *    Ie_fp;
  1233. IEXT VOL U32    Idebug;
  1234. IEXT U32    Iperldb;
  1235.  
  1236. /* magical thingies */
  1237. IEXT Time_t    Ibasetime;        /* $^T */
  1238. IEXT SV *    Iformfeed;        /* $^L */
  1239. IEXT char *    Ichopset IINIT(" \n-");    /* $: */
  1240. IEXT char *    Irs IINIT("\n");    /* $/ */
  1241. IEXT U32    Irschar IINIT('\n');    /* final char of rs, or 0777 if none */
  1242. IEXT STRLEN    Irslen IINIT(1);
  1243. IEXT bool    Irspara;
  1244. IEXT char *    Iofs;            /* $, */
  1245. IEXT STRLEN    Iofslen;
  1246. IEXT char *    Iors;            /* $\ */
  1247. IEXT STRLEN    Iorslen;
  1248. IEXT char *    Iofmt;            /* $# */
  1249. IEXT I32    Imaxsysfd IINIT(MAXSYSFD); /* top fd to pass to subprocesses */
  1250. IEXT int    Imultiline;      /* $*--do strings hold >1 line? */
  1251. IEXT U16    Istatusvalue;    /* $? */
  1252.  
  1253. IEXT struct stat Istatcache;        /* _ */
  1254. IEXT GV *    Istatgv;
  1255. IEXT SV *    Istatname IINIT(Nullsv);
  1256.  
  1257. /* shortcuts to various I/O objects */
  1258. IEXT GV *    Istdingv;
  1259. IEXT GV *    Ilast_in_gv;
  1260. IEXT GV *    Idefgv;
  1261. IEXT GV *    Iargvgv;
  1262. IEXT GV *    Idefoutgv;
  1263. IEXT GV *    Iargvoutgv;
  1264.  
  1265. /* shortcuts to regexp stuff */
  1266. IEXT GV *    Ileftgv;
  1267. IEXT GV *    Iampergv;
  1268. IEXT GV *    Irightgv;
  1269. IEXT PMOP *    Icurpm;        /* what to do \ interps from */
  1270. IEXT I32 *    Iscreamfirst;
  1271. IEXT I32 *    Iscreamnext;
  1272. IEXT I32    Imaxscream IINIT(-1);
  1273. IEXT SV *    Ilastscream;
  1274.  
  1275. /* shortcuts to debugging objects */
  1276. IEXT GV *    IDBgv;
  1277. IEXT GV *    IDBline;
  1278. IEXT GV *    IDBsub;
  1279. IEXT SV *    IDBsingle;
  1280. IEXT SV *    IDBtrace;
  1281. IEXT SV *    IDBsignal;
  1282. IEXT AV *    Ilineary;    /* lines of script for debugger */
  1283. IEXT AV *    Idbargs;    /* args to call listed by caller function */
  1284.  
  1285. /* symbol tables */
  1286. IEXT HV *    Idefstash;    /* main symbol table */
  1287. IEXT HV *    Icurstash;    /* symbol table for current package */
  1288. IEXT HV *    Idebstash;    /* symbol table for perldb package */
  1289. IEXT SV *    Icurstname;    /* name of current package */
  1290. IEXT AV *    Ibeginav;    /* names of BEGIN subroutines */
  1291. IEXT AV *    Iendav;        /* names of END subroutines */
  1292. IEXT AV *    Ipad;        /* storage for lexically scoped temporaries */
  1293. IEXT AV *    Ipadname;    /* variable names for "my" variables */
  1294.  
  1295. /* memory management */
  1296. IEXT SV **    Itmps_stack;
  1297. IEXT I32    Itmps_ix IINIT(-1);
  1298. IEXT I32    Itmps_floor IINIT(-1);
  1299. IEXT I32    Itmps_max;
  1300. IEXT I32    Isv_count;    /* how many SV* are currently allocated */
  1301. IEXT I32    Isv_objcount;    /* how many objects are currently allocated */
  1302. IEXT SV*    Isv_root;    /* storage for SVs belonging to interp */
  1303. IEXT SV*    Isv_arenaroot;    /* list of areas for garbage collection */
  1304.  
  1305. /* funky return mechanisms */
  1306. IEXT I32    Ilastspbase;
  1307. IEXT I32    Ilastsize;
  1308. IEXT int    Iforkprocess;    /* so do_open |- can return proc# */
  1309.  
  1310. /* subprocess state */
  1311. IEXT AV *    Ifdpid;        /* keep fd-to-pid mappings for my_popen */
  1312. IEXT HV *    Ipidstatus;    /* keep pid-to-status mappings for waitpid */
  1313.  
  1314. /* internal state */
  1315. IEXT VOL int    Iin_eval;    /* trap "fatal" errors? */
  1316. IEXT OP *    Irestartop;    /* Are we propagating an error from croak? */
  1317. IEXT int    Idelaymagic;    /* ($<,$>) = ... */
  1318. IEXT bool    Idirty;        /* In the middle of tearing things down? */
  1319. IEXT bool    Ilocalizing;    /* are we processing a local() list? */
  1320. IEXT bool    Itainted;    /* using variables controlled by $< */
  1321. IEXT bool    Itainting;    /* doing taint checks */
  1322.  
  1323. /* trace state */
  1324. IEXT I32    Idlevel;
  1325. IEXT I32    Idlmax IINIT(128);
  1326. IEXT char *    Idebname;
  1327. IEXT char *    Idebdelim;
  1328.  
  1329. /* current interpreter roots */
  1330. IEXT OP *    Imain_root;
  1331. IEXT OP *    Imain_start;
  1332. IEXT OP *    Ieval_root;
  1333. IEXT OP *    Ieval_start;
  1334.  
  1335. /* runtime control stuff */
  1336. IEXT COP * VOL    Icurcop IINIT(&compiling);
  1337. IEXT line_t    Icopline IINIT(NOLINE);
  1338. IEXT CONTEXT *    Icxstack;
  1339. IEXT I32    Icxstack_ix IINIT(-1);
  1340. IEXT I32    Icxstack_max IINIT(128);
  1341. IEXT jmp_buf    Itop_env;
  1342. IEXT I32    Irunlevel;
  1343.  
  1344. /* stack stuff */
  1345. IEXT AV *    Istack;        /* THE STACK */
  1346. IEXT AV *    Imainstack;    /* the stack when nothing funny is happening */
  1347. IEXT SV **    Imystack_base;    /* stack->array_ary */
  1348. IEXT SV **    Imystack_sp;    /* stack pointer now */
  1349. IEXT SV **    Imystack_max;    /* stack->array_ary + stack->array_max */
  1350.  
  1351. /* format accumulators */
  1352. IEXT SV *    Iformtarget;
  1353. IEXT SV *    Ibodytarget;
  1354. IEXT SV *    Itoptarget;
  1355.  
  1356. /* statics moved here for shared library purposes */
  1357. IEXT SV        Istrchop;    /* return value from chop */
  1358. IEXT int    Ifilemode;    /* so nextargv() can preserve mode */
  1359. IEXT int    Ilastfd;    /* what to preserve mode on */
  1360. IEXT char *    Ioldname;    /* what to preserve mode on */
  1361. IEXT char **    IArgv;        /* stuff to free from do_aexec, vfork safe */
  1362. IEXT char *    ICmd;        /* stuff to free from do_aexec, vfork safe */
  1363. IEXT OP *    Isortcop;    /* user defined sort routine */
  1364. IEXT HV *    Isortstash;    /* which is in some package or other */
  1365. IEXT GV *    Ifirstgv;    /* $a */
  1366. IEXT GV *    Isecondgv;    /* $b */
  1367. IEXT AV *    Isortstack;    /* temp stack during pp_sort() */
  1368. IEXT AV *    Isignalstack;    /* temp stack during sighandler() */
  1369. IEXT SV *    Imystrk;    /* temp key string for do_each() */
  1370. IEXT I32    Idumplvl;    /* indentation level on syntax tree dump */
  1371. IEXT PMOP *    Ioldlastpm;    /* for saving regexp context during debugger */
  1372. IEXT I32    Igensym;    /* next symbol for getsym() to define */
  1373. IEXT bool    Ipreambled;
  1374. IEXT int    Ilaststatval IINIT(-1);
  1375. IEXT I32    Ilaststype IINIT(OP_STAT);
  1376.  
  1377. #undef IEXT
  1378. #undef IINIT
  1379.  
  1380. #ifdef MULTIPLICITY
  1381. };
  1382. #else
  1383. struct interpreter {
  1384.     char broiled;
  1385. };
  1386. #endif
  1387.  
  1388. #include "pp.h"
  1389.  
  1390. #ifdef __cplusplus
  1391. extern "C" {
  1392. #endif
  1393.  
  1394. #ifdef __cplusplus
  1395. #  ifndef I_STDARG
  1396. #    define I_STDARG 1
  1397. #  endif
  1398. #endif
  1399.  
  1400. #ifdef I_STDARG
  1401. #  include <stdarg.h>
  1402. #else
  1403. #  ifdef I_VARARGS
  1404. #    include <varargs.h>
  1405. #  endif
  1406. #endif
  1407.  
  1408. #include "proto.h"
  1409.  
  1410. #ifdef EMBED
  1411. #define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
  1412. #define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
  1413. #else
  1414. #define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
  1415. #define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
  1416. #endif
  1417.  
  1418. #ifdef __cplusplus
  1419. };
  1420. #endif
  1421.  
  1422. /* The following must follow proto.h */
  1423.  
  1424. #ifdef DOINIT
  1425. MGVTBL vtbl_sv =    {magic_get,
  1426.                 magic_set,
  1427.                     magic_len,
  1428.                         0,    0};
  1429. MGVTBL vtbl_env =    {0,    0,    0,    0,    0};
  1430. MGVTBL vtbl_envelem =    {0,    magic_setenv,
  1431.                     0,    magic_clearenv,
  1432.                             0};
  1433. MGVTBL vtbl_sig =    {0,    0,         0, 0, 0};
  1434. MGVTBL vtbl_sigelem =    {0,    magic_setsig,
  1435.                     0,    0,    0};
  1436. MGVTBL vtbl_pack =    {0,    0,    0,    magic_wipepack,
  1437.                             0};
  1438. MGVTBL vtbl_packelem =    {magic_getpack,
  1439.                 magic_setpack,
  1440.                     0,    magic_clearpack,
  1441.                             0};
  1442. MGVTBL vtbl_dbline =    {0,    magic_setdbline,
  1443.                     0,    0,    0};
  1444. MGVTBL vtbl_isa =    {0,    magic_setisa,
  1445.                     0,    0,    0};
  1446. MGVTBL vtbl_isaelem =    {0,    magic_setisa,
  1447.                     0,    0,    0};
  1448. MGVTBL vtbl_arylen =    {magic_getarylen,
  1449.                 magic_setarylen,
  1450.                     0,    0,    0};
  1451. MGVTBL vtbl_glob =    {magic_getglob,
  1452.                 magic_setglob,
  1453.                     0,    0,    0};
  1454. MGVTBL vtbl_mglob =    {0,    magic_setmglob,
  1455.                     0,    0,    0};
  1456. MGVTBL vtbl_taint =    {magic_gettaint,magic_settaint,
  1457.                     0,    0,    0};
  1458. MGVTBL vtbl_substr =    {0,    magic_setsubstr,
  1459.                     0,    0,    0};
  1460. MGVTBL vtbl_vec =    {0,    magic_setvec,
  1461.                     0,    0,    0};
  1462. MGVTBL vtbl_pos =    {magic_getpos,
  1463.                 magic_setpos,
  1464.                     0,    0,    0};
  1465. MGVTBL vtbl_bm =    {0,    magic_setbm,
  1466.                     0,    0,    0};
  1467. MGVTBL vtbl_uvar =    {magic_getuvar,
  1468.                 magic_setuvar,
  1469.                     0,    0,    0};
  1470.  
  1471. #ifdef OVERLOAD
  1472. MGVTBL vtbl_amagic =       {0,     magic_setamagic,
  1473.                                         0,      0,      0};
  1474. MGVTBL vtbl_amagicelem =   {0,     magic_setamagic,
  1475.                                         0,      0,      0};
  1476. #endif /* OVERLOAD */
  1477.  
  1478. #else
  1479. EXT MGVTBL vtbl_sv;
  1480. EXT MGVTBL vtbl_env;
  1481. EXT MGVTBL vtbl_envelem;
  1482. EXT MGVTBL vtbl_sig;
  1483. EXT MGVTBL vtbl_sigelem;
  1484. EXT MGVTBL vtbl_pack;
  1485. EXT MGVTBL vtbl_packelem;
  1486. EXT MGVTBL vtbl_dbline;
  1487. EXT MGVTBL vtbl_isa;
  1488. EXT MGVTBL vtbl_isaelem;
  1489. EXT MGVTBL vtbl_arylen;
  1490. EXT MGVTBL vtbl_glob;
  1491. EXT MGVTBL vtbl_mglob;
  1492. EXT MGVTBL vtbl_taint;
  1493. EXT MGVTBL vtbl_substr;
  1494. EXT MGVTBL vtbl_vec;
  1495. EXT MGVTBL vtbl_pos;
  1496. EXT MGVTBL vtbl_bm;
  1497. EXT MGVTBL vtbl_uvar;
  1498.  
  1499. #ifdef OVERLOAD
  1500. EXT MGVTBL vtbl_amagic;
  1501. EXT MGVTBL vtbl_amagicelem;
  1502. #endif /* OVERLOAD */
  1503.  
  1504. #endif
  1505.  
  1506. #ifdef OVERLOAD
  1507. EXT long amagic_generation;
  1508.  
  1509. #define NofAMmeth 27
  1510. #ifdef DOINIT
  1511. EXT char * AMG_names[NofAMmeth][2] = {
  1512.   {"fallback","abs"},
  1513.   {"bool", "nomethod"},
  1514.   {"\"\"", "0+"},
  1515.   {"+","+="},
  1516.   {"-","-="},
  1517.   {"*", "*="},
  1518.   {"/", "/="},
  1519.   {"%", "%="},
  1520.   {"**", "**="},
  1521.   {"<<", "<<="},
  1522.   {">>", ">>="},
  1523.   {"<", "<="},
  1524.   {">", ">="},
  1525.   {"==", "!="},
  1526.   {"<=>", "cmp"},
  1527.   {"lt", "le"},
  1528.   {"gt", "ge"},
  1529.   {"eq", "ne"},
  1530.   {"&", "^"},
  1531.   {"|", "neg"},
  1532.   {"!", "~"},
  1533.   {"++", "--"},
  1534.   {"atan2", "cos"},
  1535.   {"sin", "exp"},
  1536.   {"log", "sqrt"},
  1537.   {"x","x="},
  1538.   {".",".="}
  1539. };
  1540. #else
  1541. EXT char * AMG_names[NofAMmeth][2];
  1542. #endif /* def INITAMAGIC */
  1543.  
  1544. struct  am_table        {
  1545.   long was_ok_sub;
  1546.   long was_ok_am;
  1547.   CV* table[NofAMmeth*2];
  1548.   long fallback;
  1549. };
  1550. typedef struct am_table AMT;
  1551.  
  1552. #define AMGfallNEVER    1
  1553. #define AMGfallNO    2
  1554. #define AMGfallYES    3
  1555.  
  1556. enum {
  1557.   fallback_amg,    abs_amg,
  1558.   bool__amg,    nomethod_amg,
  1559.   string_amg,    numer_amg,
  1560.   add_amg,    add_ass_amg,
  1561.   subtr_amg,    subtr_ass_amg,
  1562.   mult_amg,    mult_ass_amg,
  1563.   div_amg,    div_ass_amg,
  1564.   mod_amg,    mod_ass_amg,
  1565.   pow_amg,    pow_ass_amg,
  1566.   lshift_amg,    lshift_ass_amg,
  1567.   rshift_amg,    rshift_ass_amg,
  1568.   lt_amg,    le_amg,
  1569.   gt_amg,    ge_amg,
  1570.   eq_amg,    ne_amg,
  1571.   ncmp_amg,    scmp_amg,
  1572.   slt_amg,    sle_amg,
  1573.   sgt_amg,    sge_amg,
  1574.   seq_amg,    sne_amg,
  1575.   band_amg,    bxor_amg,
  1576.   bor_amg,    neg_amg,
  1577.   not_amg,    compl_amg,
  1578.   inc_amg,    dec_amg,
  1579.   atan2_amg,    cos_amg,
  1580.   sin_amg,    exp_amg,
  1581.   log_amg,    sqrt_amg,
  1582.   repeat_amg,   repeat_ass_amg,
  1583.   concat_amg,    concat_ass_amg
  1584. };
  1585. #endif /* OVERLOAD */
  1586.  
  1587. #endif /* Include guard */
  1588.