home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl560.zip / x2p / a2p.h < prev    next >
C/C++ Source or Header  |  2000-02-19  |  10KB  |  486 lines

  1. /* $RCSfile: a2p.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:09 $
  2.  *
  3.  *    Copyright (c) 1991-1997, 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:    a2p.h,v $
  9.  */
  10.  
  11. #define VOIDUSED 1
  12.  
  13. #ifdef WIN32
  14. #define _INC_WIN32_PERL5    /* kludge around win32 stdio layer */
  15. #endif
  16.  
  17. #ifdef VMS
  18. #  include "config.h"
  19. #else
  20. #  include "../config.h"
  21. #endif
  22.  
  23. #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
  24. # define STANDARD_C 1
  25. #endif
  26.  
  27. #ifdef WIN32
  28. #undef USE_STDIO_PTR        /* XXX fast gets won't work, must investigate */
  29. #  ifndef STANDARD_C
  30. #    define STANDARD_C
  31. #  endif
  32. #  if defined(__BORLANDC__)
  33. #    pragma warn -ccc
  34. #    pragma warn -rch
  35. #    pragma warn -sig
  36. #    pragma warn -pia
  37. #    pragma warn -par
  38. #    pragma warn -aus
  39. #    pragma warn -use
  40. #    pragma warn -csu
  41. #    pragma warn -pro
  42. #  elif defined(_MSC_VER)
  43. #  elif defined(__MINGW32__)
  44. #  endif
  45. #endif
  46.  
  47. /* Use all the "standard" definitions? */
  48. #if defined(STANDARD_C) && defined(I_STDLIB)
  49. #   include <stdlib.h>
  50. #endif /* STANDARD_C */
  51.  
  52. #include <stdio.h>
  53.  
  54. #ifdef I_MATH
  55. #include <math.h>
  56. #endif
  57.  
  58. #ifdef I_SYS_TYPES
  59. #  include <sys/types.h>
  60. #endif
  61.  
  62. #ifdef USE_NEXT_CTYPE
  63.  
  64. #if NX_CURRENT_COMPILER_RELEASE >= 400
  65. #include <objc/NXCType.h>
  66. #else /*  NX_CURRENT_COMPILER_RELEASE < 400 */
  67. #include <appkit/NXCType.h>
  68. #endif /*  NX_CURRENT_COMPILER_RELEASE >= 400 */
  69.  
  70. #else /* !USE_NEXT_CTYPE */
  71. #include <ctype.h>
  72. #endif /* USE_NEXT_CTYPE */
  73.  
  74. #define MEM_SIZE Size_t
  75.  
  76. #ifndef STANDARD_C
  77.     Malloc_t malloc (MEM_SIZE nbytes);
  78.     Malloc_t calloc (MEM_SIZE elements, MEM_SIZE size);
  79.     Malloc_t realloc (Malloc_t where, MEM_SIZE nbytes);
  80.     Free_t   free (Malloc_t where);
  81. #endif
  82.  
  83. #if defined(I_STRING) || defined(__cplusplus)
  84. #   include <string.h>
  85. #else
  86. #   include <strings.h>
  87. #endif
  88.  
  89. #if !defined(HAS_BCOPY) || defined(__cplusplus)
  90. #   define bcopy(s1,s2,l) memcpy(s2,s1,l)
  91. #endif
  92. #if !defined(HAS_BZERO) || defined(__cplusplus)
  93. #   define bzero(s,l) memset(s,0,l)
  94. #endif
  95.  
  96. #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
  97. #define strchr index
  98. #define strrchr rindex
  99. #endif
  100.  
  101.  
  102. #ifdef I_TIME
  103. #   include <time.h>
  104. #endif
  105.  
  106. #ifdef I_SYS_TIME
  107. #   ifdef I_SYS_TIME_KERNEL
  108. #    define KERNEL
  109. #   endif
  110. #   include <sys/time.h>
  111. #   ifdef I_SYS_TIME_KERNEL
  112. #    undef KERNEL
  113. #   endif
  114. #endif
  115.  
  116. #ifndef MSDOS
  117. #  if defined(HAS_TIMES) && defined(I_SYS_TIMES)
  118. #    include <sys/times.h>
  119. #  endif
  120. #endif
  121.  
  122. #ifdef DOSISH
  123. # if defined(OS2)
  124. #   include "../os2ish.h"
  125. # else
  126. #   include "../dosish.h"
  127. # endif
  128. #else
  129. # if defined(VMS)
  130. #   define NO_PERL_TYPEDEFS
  131. #   include "vmsish.h"
  132. # endif
  133. #endif
  134.  
  135. #ifndef STANDARD_C
  136. /* All of these are in stdlib.h or time.h for ANSI C */
  137. Time_t time();
  138. struct tm *gmtime(), *localtime();
  139. #if defined(OEMVS) || defined(__OPEN_VM)
  140. char *(strchr)(), *(strrchr)();
  141. char *(strcpy)(), *(strcat)();
  142. #else
  143. char *strchr(), *strrchr();
  144. char *strcpy(), *strcat();
  145. #endif
  146. #endif /* ! STANDARD_C */
  147.  
  148. #ifdef VMS
  149. #  include "handy.h"
  150. #else 
  151. #  include "../handy.h"
  152. #endif
  153.  
  154. #undef Nullfp
  155. #define Nullfp Null(FILE*)
  156.  
  157. #define Nullop 0
  158.  
  159. #define OPROG        1
  160. #define OJUNK        2
  161. #define OHUNKS        3
  162. #define ORANGE        4
  163. #define OPAT        5
  164. #define OHUNK        6
  165. #define OPPAREN        7
  166. #define OPANDAND    8
  167. #define OPOROR        9
  168. #define OPNOT        10
  169. #define OCPAREN        11
  170. #define OCANDAND    12
  171. #define OCOROR        13
  172. #define OCNOT        14
  173. #define ORELOP        15
  174. #define ORPAREN        16
  175. #define OMATCHOP    17
  176. #define OMPAREN        18
  177. #define OCONCAT        19
  178. #define OASSIGN        20
  179. #define OADD        21
  180. #define OSUBTRACT    22
  181. #define OMULT        23
  182. #define ODIV        24
  183. #define OMOD        25
  184. #define OPOSTINCR    26
  185. #define OPOSTDECR    27
  186. #define OPREINCR    28
  187. #define OPREDECR    29
  188. #define OUMINUS        30
  189. #define OUPLUS        31
  190. #define OPAREN        32
  191. #define OGETLINE    33
  192. #define OSPRINTF    34
  193. #define OSUBSTR        35
  194. #define OSTRING        36
  195. #define OSPLIT        37
  196. #define OSNEWLINE    38
  197. #define OINDEX        39
  198. #define ONUM        40
  199. #define OSTR        41
  200. #define OVAR        42
  201. #define OFLD        43
  202. #define ONEWLINE    44
  203. #define OCOMMENT    45
  204. #define OCOMMA        46
  205. #define OSEMICOLON    47
  206. #define OSCOMMENT    48
  207. #define OSTATES        49
  208. #define OSTATE        50
  209. #define OPRINT        51
  210. #define OPRINTF        52
  211. #define OBREAK        53
  212. #define ONEXT        54
  213. #define OEXIT        55
  214. #define OCONTINUE    56
  215. #define OREDIR        57
  216. #define OIF        58
  217. #define OWHILE        59
  218. #define OFOR        60
  219. #define OFORIN        61
  220. #define OVFLD        62
  221. #define OBLOCK        63
  222. #define OREGEX        64
  223. #define OLENGTH        65
  224. #define OLOG        66
  225. #define OEXP        67
  226. #define OSQRT        68
  227. #define OINT        69
  228. #define ODO        70
  229. #define OPOW        71
  230. #define OSUB        72
  231. #define OGSUB        73
  232. #define OMATCH        74
  233. #define OUSERFUN    75
  234. #define OUSERDEF    76
  235. #define OCLOSE        77
  236. #define OATAN2        78
  237. #define OSIN        79
  238. #define OCOS        80
  239. #define ORAND        81
  240. #define OSRAND        82
  241. #define ODELETE        83
  242. #define OSYSTEM        84
  243. #define OCOND        85
  244. #define ORETURN        86
  245. #define ODEFINED    87
  246. #define OSTAR        88
  247.  
  248. #ifdef DOINIT
  249. char *opname[] = {
  250.     "0",
  251.     "PROG",
  252.     "JUNK",
  253.     "HUNKS",
  254.     "RANGE",
  255.     "PAT",
  256.     "HUNK",
  257.     "PPAREN",
  258.     "PANDAND",
  259.     "POROR",
  260.     "PNOT",
  261.     "CPAREN",
  262.     "CANDAND",
  263.     "COROR",
  264.     "CNOT",
  265.     "RELOP",
  266.     "RPAREN",
  267.     "MATCHOP",
  268.     "MPAREN",
  269.     "CONCAT",
  270.     "ASSIGN",
  271.     "ADD",
  272.     "SUBTRACT",
  273.     "MULT",
  274.     "DIV",
  275.     "MOD",
  276.     "POSTINCR",
  277.     "POSTDECR",
  278.     "PREINCR",
  279.     "PREDECR",
  280.     "UMINUS",
  281.     "UPLUS",
  282.     "PAREN",
  283.     "GETLINE",
  284.     "SPRINTF",
  285.     "SUBSTR",
  286.     "STRING",
  287.     "SPLIT",
  288.     "SNEWLINE",
  289.     "INDEX",
  290.     "NUM",
  291.     "STR",
  292.     "VAR",
  293.     "FLD",
  294.     "NEWLINE",
  295.     "COMMENT",
  296.     "COMMA",
  297.     "SEMICOLON",
  298.     "SCOMMENT",
  299.     "STATES",
  300.     "STATE",
  301.     "PRINT",
  302.     "PRINTF",
  303.     "BREAK",
  304.     "NEXT",
  305.     "EXIT",
  306.     "CONTINUE",
  307.     "REDIR",
  308.     "IF",
  309.     "WHILE",
  310.     "FOR",
  311.     "FORIN",
  312.     "VFLD",
  313.     "BLOCK",
  314.     "REGEX",
  315.     "LENGTH",
  316.     "LOG",
  317.     "EXP",
  318.     "SQRT",
  319.     "INT",
  320.     "DO",
  321.     "POW",
  322.     "SUB",
  323.     "GSUB",
  324.     "MATCH",
  325.     "USERFUN",
  326.     "USERDEF",
  327.     "CLOSE",
  328.     "ATAN2",
  329.     "SIN",
  330.     "COS",
  331.     "RAND",
  332.     "SRAND",
  333.     "DELETE",
  334.     "SYSTEM",
  335.     "COND",
  336.     "RETURN",
  337.     "DEFINED",
  338.     "STAR",
  339.     "89"
  340. };
  341. #else
  342. extern char *opname[];
  343. #endif
  344.  
  345. EXT int mop INIT(1);
  346.  
  347. union u_ops {
  348.     int ival;
  349.     char *cval;
  350. };
  351. #if defined(iAPX286) || defined(M_I286) || defined(I80286)     /* 80286 hack */
  352. #define OPSMAX (64000/sizeof(union u_ops))    /* approx. max segment size */
  353. #else
  354. #define OPSMAX 50000
  355. #endif                             /* 80286 hack */
  356. EXT union u_ops ops[OPSMAX];
  357.  
  358. typedef struct string STR;
  359. typedef struct htbl HASH;
  360.  
  361. #include "str.h"
  362. #include "hash.h"
  363.  
  364.  
  365. /* A string is TRUE if not "" or "0". */
  366. #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
  367. EXT char *Yes INIT("1");
  368. EXT char *No INIT("");
  369.  
  370. #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
  371.  
  372. #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
  373. #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  374. #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
  375. EXT STR *Str;
  376.  
  377. #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  378.  
  379. /* Prototypes for things in a2p.c */
  380. int aryrefarg ( int arg );
  381. int bl ( int arg, int maybe );
  382. void dump ( int branch );
  383. int fixfargs ( int name, int arg, int prevargs );
  384. int fixrargs ( char *name, int arg, int prevargs );
  385. void fixup ( STR *str );
  386. int numary ( int arg );
  387. int oper0 ( int type );
  388. int oper1 ( int type, int arg1 );
  389. int oper2 ( int type, int arg1, int arg2 );
  390. int oper3 ( int type, int arg1, int arg2, int arg3 );
  391. int oper4 ( int type, int arg1, int arg2, int arg3, int arg4 );
  392. int oper5 ( int type, int arg1, int arg2, int arg3, int arg4, int arg5 );
  393. void putlines ( STR *str );
  394. void putone ( void );
  395. int rememberargs ( int arg );
  396. char * scannum ( char *s );
  397. char * scanpat ( char *s );
  398. int string ( char *ptr, int len );
  399. void yyerror ( char *s );
  400. int yylex ( void );
  401.  
  402. EXT int line INIT(0);
  403.  
  404. EXT FILE *rsfp;
  405. EXT char buf[2048];
  406. EXT char *bufptr INIT(buf);
  407.  
  408. EXT STR *linestr INIT(Nullstr);
  409.  
  410. EXT char tokenbuf[2048];
  411. EXT int expectterm INIT(TRUE);
  412.  
  413. #ifdef DEBUGGING
  414. EXT int debug INIT(0);
  415. EXT int dlevel INIT(0);
  416. #define YYDEBUG 1
  417. extern int yydebug;
  418. #else
  419. # ifndef YYDEBUG
  420. #  define YYDEBUG 0
  421. # endif
  422. #endif
  423.  
  424. EXT STR *freestrroot INIT(Nullstr);
  425.  
  426. EXT STR str_no;
  427. EXT STR str_yes;
  428.  
  429. EXT bool do_split INIT(FALSE);
  430. EXT bool split_to_array INIT(FALSE);
  431. EXT bool set_array_base INIT(FALSE);
  432. EXT bool saw_RS INIT(FALSE);
  433. EXT bool saw_OFS INIT(FALSE);
  434. EXT bool saw_ORS INIT(FALSE);
  435. EXT bool saw_line_op INIT(FALSE);
  436. EXT bool in_begin INIT(TRUE);
  437. EXT bool do_opens INIT(FALSE);
  438. EXT bool do_fancy_opens INIT(FALSE);
  439. EXT bool lval_field INIT(FALSE);
  440. EXT bool do_chop INIT(FALSE);
  441. EXT bool need_entire INIT(FALSE);
  442. EXT bool absmaxfld INIT(FALSE);
  443. EXT bool saw_altinput INIT(FALSE);
  444.  
  445. EXT bool nomemok INIT(FALSE);
  446.  
  447. EXT char const_FS INIT(0);
  448. EXT char *namelist INIT(Nullch);
  449. EXT char fswitch INIT(0);
  450. EXT bool old_awk INIT(0);
  451.  
  452. EXT int saw_FS INIT(0);
  453. EXT int maxfld INIT(0);
  454. EXT int arymax INIT(0);
  455. EXT char *nameary[100];
  456.  
  457. EXT STR *opens;
  458.  
  459. EXT HASH *symtab;
  460. EXT HASH *curarghash;
  461.  
  462. #define P_MIN        0
  463. #define P_LISTOP    5
  464. #define P_COMMA        10
  465. #define P_ASSIGN    15
  466. #define P_COND        20
  467. #define P_DOTDOT    25
  468. #define P_OROR        30
  469. #define P_ANDAND    35
  470. #define P_OR        40
  471. #define P_AND        45
  472. #define P_EQ        50
  473. #define P_REL        55
  474. #define P_UNI        60
  475. #define P_FILETEST    65
  476. #define P_SHIFT        70
  477. #define P_ADD        75
  478. #define P_MUL        80
  479. #define P_MATCH        85
  480. #define P_UNARY        90
  481. #define P_POW        95
  482. #define P_AUTO        100
  483. #define P_MAX        999
  484.  
  485. EXT int an;
  486.