home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / perl / os2perl / a2p.h < prev    next >
C/C++ Source or Header  |  1991-06-11  |  7KB  |  334 lines

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