home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perlkt40.zip / A2P.H < prev    next >
C/C++ Source or Header  |  1996-06-13  |  7KB  |  367 lines

  1. /* $RCSfile: a2p.h,v $$Revision: 4.0.1.2 $$Date: 92/06/08 16:12:23 $
  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:    a2p.h,v $
  9.  * Revision 4.0.1.2  92/06/08  16:12:23  lwall
  10.  * patch20: hash tables now split only if the memory is available to do so
  11.  * 
  12.  * Revision 4.0.1.1  91/06/07  12:12:27  lwall
  13.  * patch4: new copyright notice
  14.  * 
  15.  * Revision 4.0  91/03/20  01:57:07  lwall
  16.  * 4.0 baseline.
  17.  * 
  18.  */
  19.  
  20. #define VOIDUSED 1
  21. #include "config.h"
  22.  
  23. #ifndef HAS_BCOPY
  24. #   define bcopy(s1,s2,l) memcpy(s2,s1,l)
  25. #endif
  26. #ifndef HAS_BZERO
  27. #   define bzero(s,l) memset(s,0,l)
  28. #endif
  29.  
  30. #include "handy.h"
  31. #define Nullop 0
  32.  
  33. #define OPROG        1
  34. #define OJUNK        2
  35. #define OHUNKS        3
  36. #define ORANGE        4
  37. #define OPAT        5
  38. #define OHUNK        6
  39. #define OPPAREN        7
  40. #define OPANDAND    8
  41. #define OPOROR        9
  42. #define OPNOT        10
  43. #define OCPAREN        11
  44. #define OCANDAND    12
  45. #define OCOROR        13
  46. #define OCNOT        14
  47. #define ORELOP        15
  48. #define ORPAREN        16
  49. #define OMATCHOP    17
  50. #define OMPAREN        18
  51. #define OCONCAT        19
  52. #define OASSIGN        20
  53. #define OADD        21
  54. #define OSUBTRACT    22
  55. #define OMULT        23
  56. #define ODIV        24
  57. #define OMOD        25
  58. #define OPOSTINCR    26
  59. #define OPOSTDECR    27
  60. #define OPREINCR    28
  61. #define OPREDECR    29
  62. #define OUMINUS        30
  63. #define OUPLUS        31
  64. #define OPAREN        32
  65. #define OGETLINE    33
  66. #define OSPRINTF    34
  67. #define OSUBSTR        35
  68. #define OSTRING        36
  69. #define OSPLIT        37
  70. #define OSNEWLINE    38
  71. #define OINDEX        39
  72. #define ONUM        40
  73. #define OSTR        41
  74. #define OVAR        42
  75. #define OFLD        43
  76. #define ONEWLINE    44
  77. #define OCOMMENT    45
  78. #define OCOMMA        46
  79. #define OSEMICOLON    47
  80. #define OSCOMMENT    48
  81. #define OSTATES        49
  82. #define OSTATE        50
  83. #define OPRINT        51
  84. #define OPRINTF        52
  85. #define OBREAK        53
  86. #define ONEXT        54
  87. #define OEXIT        55
  88. #define OCONTINUE    56
  89. #define OREDIR        57
  90. #define OIF        58
  91. #define OWHILE        59
  92. #define OFOR        60
  93. #define OFORIN        61
  94. #define OVFLD        62
  95. #define OBLOCK        63
  96. #define OREGEX        64
  97. #define OLENGTH        65
  98. #define OLOG        66
  99. #define OEXP        67
  100. #define OSQRT        68
  101. #define OINT        69
  102. #define ODO        70
  103. #define OPOW        71
  104. #define OSUB        72
  105. #define OGSUB        73
  106. #define OMATCH        74
  107. #define OUSERFUN    75
  108. #define OUSERDEF    76
  109. #define OCLOSE        77
  110. #define OATAN2        78
  111. #define OSIN        79
  112. #define OCOS        80
  113. #define ORAND        81
  114. #define OSRAND        82
  115. #define ODELETE        83
  116. #define OSYSTEM        84
  117. #define OCOND        85
  118. #define ORETURN        86
  119. #define ODEFINED    87
  120. #ifndef GAWK
  121. #define OSTAR        88
  122. #else
  123. #define OTOUPPER    88
  124. #define OTOLOWER    89
  125. #define OJINDEX        90
  126. #define OJLENGTH    91
  127. #define OJSUBSTR    92
  128. #define OSYSTIME    93
  129. #define OSTAR        94
  130. #endif
  131.  
  132. #ifdef DOINIT
  133. char *opname[] = {
  134.     "0",
  135.     "PROG",
  136.     "JUNK",
  137.     "HUNKS",
  138.     "RANGE",
  139.     "PAT",
  140.     "HUNK",
  141.     "PPAREN",
  142.     "PANDAND",
  143.     "POROR",
  144.     "PNOT",
  145.     "CPAREN",
  146.     "CANDAND",
  147.     "COROR",
  148.     "CNOT",
  149.     "RELOP",
  150.     "RPAREN",
  151.     "MATCHOP",
  152.     "MPAREN",
  153.     "CONCAT",
  154.     "ASSIGN",
  155.     "ADD",
  156.     "SUBTRACT",
  157.     "MULT",
  158.     "DIV",
  159.     "MOD",
  160.     "POSTINCR",
  161.     "POSTDECR",
  162.     "PREINCR",
  163.     "PREDECR",
  164.     "UMINUS",
  165.     "UPLUS",
  166.     "PAREN",
  167.     "GETLINE",
  168.     "SPRINTF",
  169.     "SUBSTR",
  170.     "STRING",
  171.     "SPLIT",
  172.     "SNEWLINE",
  173.     "INDEX",
  174.     "NUM",
  175.     "STR",
  176.     "VAR",
  177.     "FLD",
  178.     "NEWLINE",
  179.     "COMMENT",
  180.     "COMMA",
  181.     "SEMICOLON",
  182.     "SCOMMENT",
  183.     "STATES",
  184.     "STATE",
  185.     "PRINT",
  186.     "PRINTF",
  187.     "BREAK",
  188.     "NEXT",
  189.     "EXIT",
  190.     "CONTINUE",
  191.     "REDIR",
  192.     "IF",
  193.     "WHILE",
  194.     "FOR",
  195.     "FORIN",
  196.     "VFLD",
  197.     "BLOCK",
  198.     "REGEX",
  199.     "LENGTH",
  200.     "LOG",
  201.     "EXP",
  202.     "SQRT",
  203.     "INT",
  204.     "DO",
  205.     "POW",
  206.     "SUB",
  207.     "GSUB",
  208.     "MATCH",
  209.     "USERFUN",
  210.     "USERDEF",
  211.     "CLOSE",
  212.     "ATAN2",
  213.     "SIN",
  214.     "COS",
  215.     "RAND",
  216.     "SRAND",
  217.     "DELETE",
  218.     "SYSTEM",
  219.     "COND",
  220.     "RETURN",
  221.     "DEFINED",
  222. #ifdef GAWK
  223.     "STAR",
  224.     "89"
  225. #else
  226.     "TOUPPER",
  227.     "TOLOWER",
  228.     "JINDEX",
  229.     "JLENGTH",
  230.     "JSUBSTR",
  231.     "SYSTIME",
  232.     "STAR",
  233.     "95",
  234. #endif
  235. };
  236. #else
  237. extern char *opname[];
  238. #endif
  239.  
  240. EXT int mop INIT(1);
  241.  
  242. union u_ops {
  243.     int ival;
  244.     char *cval;
  245. };
  246. #if defined(iAPX286) || defined(M_I286) || defined(I80286)     /* 80286 hack */
  247. #define OPSMAX (64000/sizeof(union u_ops))    /* approx. max segment size */
  248. #else
  249. #define OPSMAX 50000
  250. #endif                             /* 80286 hack */
  251. EXT union u_ops ops[OPSMAX];
  252.  
  253. #include <stdio.h>
  254. #include <ctype.h>
  255.  
  256. typedef struct string STR;
  257. typedef struct htbl HASH;
  258.  
  259. #include "str.h"
  260. #include "hash.h"
  261.  
  262. /* A string is TRUE if not "" or "0". */
  263. #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
  264. EXT char *Yes INIT("1");
  265. EXT char *No INIT("");
  266.  
  267. #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
  268.  
  269. #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
  270. #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  271. #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
  272. EXT STR *Str;
  273.  
  274. #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  275.  
  276. STR *str_new();
  277.  
  278. char *scanpat();
  279. char *scannum();
  280.  
  281. void str_free();
  282.  
  283. EXT int line INIT(0);
  284.  
  285. EXT FILE *rsfp;
  286. EXT char buf[2048];
  287. EXT char *bufptr INIT(buf);
  288.  
  289. EXT STR *linestr INIT(Nullstr);
  290.  
  291. EXT char tokenbuf[2048];
  292. EXT int expectterm INIT(TRUE);
  293.  
  294. #ifdef DEBUGGING
  295. EXT int debug INIT(0);
  296. EXT int dlevel INIT(0);
  297. #define YYDEBUG 1
  298. extern int yydebug;
  299. #endif
  300.  
  301. EXT STR *freestrroot INIT(Nullstr);
  302.  
  303. EXT STR str_no;
  304. EXT STR str_yes;
  305.  
  306. EXT bool do_split INIT(FALSE);
  307. EXT bool split_to_array INIT(FALSE);
  308. EXT bool set_array_base INIT(FALSE);
  309. EXT bool saw_RS INIT(FALSE);
  310. EXT bool saw_OFS INIT(FALSE);
  311. EXT bool saw_ORS INIT(FALSE);
  312. EXT bool saw_line_op INIT(FALSE);
  313. EXT bool in_begin INIT(TRUE);
  314. EXT bool do_opens INIT(FALSE);
  315. EXT bool do_fancy_opens INIT(FALSE);
  316. EXT bool lval_field INIT(FALSE);
  317. EXT bool do_chop INIT(FALSE);
  318. EXT bool need_entire INIT(FALSE);
  319. EXT bool absmaxfld INIT(FALSE);
  320. EXT bool saw_altinput INIT(FALSE);
  321.  
  322. EXT bool saw_toupper INIT(FALSE);
  323. EXT bool saw_tolower INIT(FALSE);
  324. EXT bool saw_FIELDWIDTHS INIT(FALSE);
  325. EXT bool saw_jindex INIT(FALSE);
  326. EXT bool saw_jlength INIT(FALSE);
  327. EXT bool saw_jsubstr INIT(FALSE);
  328.  
  329. EXT bool nomemok INIT(FALSE);
  330.  
  331. EXT char const_FS INIT(0);
  332. EXT char *namelist INIT(Nullch);
  333. EXT char fswitch INIT(0);
  334.  
  335. EXT int saw_FS INIT(0);
  336. EXT int maxfld INIT(0);
  337. EXT int arymax INIT(0);
  338. EXT char *nameary[100];
  339.  
  340. EXT STR *opens;
  341.  
  342. EXT HASH *symtab;
  343. EXT HASH *curarghash;
  344.  
  345. #define P_MIN        0
  346. #define P_LISTOP    5
  347. #define P_COMMA        10
  348. #define P_ASSIGN    15
  349. #define P_COND        20
  350. #define P_DOTDOT    25
  351. #define P_OROR        30
  352. #define P_ANDAND    35
  353. #define P_OR        40
  354. #define P_AND        45
  355. #define P_EQ        50
  356. #define P_REL        55
  357. #define P_UNI        60
  358. #define P_FILETEST    65
  359. #define P_SHIFT        70
  360. #define P_ADD        75
  361. #define P_MUL        80
  362. #define P_MATCH        85
  363. #define P_UNARY        90
  364. #define P_POW        95
  365. #define P_AUTO        100
  366. #define P_MAX        999
  367.