1: /* $Header: a2p.h,v 1.0.1.2 88/02/01 17:33:40 root Exp $
2: *
3: * $Log: a2p.h,v $
4: * Revision 1.0.1.2 88/02/01 17:33:40 root
5: * patch12: forgot to fix #define YYDEBUG; bug in a2p.
6: *
7: * Revision 1.0.1.1 88/01/26 09:52:30 root
8: * patch 5: a2p didn't use config.h.
9: *
10: * Revision 1.0 87/12/18 13:06:58 root
11: * Initial revision
12: *
13: */
14:
15: #define VOIDUSED 1
16: #include "../config.h"
17:
18: #ifndef BCOPY
19: # define bcopy(s1,s2,l) memcpy(s2,s1,l);
20: # define bzero(s,l) memset(s,0,l);
21: #endif
22:
23: #include "handy.h"
24: #define Nullop 0
25:
26: #define OPROG 1
27: #define OJUNK 2
28: #define OHUNKS 3
29: #define ORANGE 4
30: #define OPAT 5
31: #define OHUNK 6
32: #define OPPAREN 7
33: #define OPANDAND 8
34: #define OPOROR 9
35: #define OPNOT 10
36: #define OCPAREN 11
37: #define OCANDAND 12
38: #define OCOROR 13
39: #define OCNOT 14
40: #define ORELOP 15
41: #define ORPAREN 16
42: #define OMATCHOP 17
43: #define OMPAREN 18
44: #define OCONCAT 19
45: #define OASSIGN 20
46: #define OADD 21
47: #define OSUB 22
48: #define OMULT 23
49: #define ODIV 24
50: #define OMOD 25
51: #define OPOSTINCR 26
52: #define OPOSTDECR 27
53: #define OPREINCR 28
54: #define OPREDECR 29
55: #define OUMINUS 30
56: #define OUPLUS 31
57: #define OPAREN 32
58: #define OGETLINE 33
59: #define OSPRINTF 34
60: #define OSUBSTR 35
61: #define OSTRING 36
62: #define OSPLIT 37
63: #define OSNEWLINE 38
64: #define OINDEX 39
65: #define ONUM 40
66: #define OSTR 41
67: #define OVAR 42
68: #define OFLD 43
69: #define ONEWLINE 44
70: #define 45
71: #define OCOMMA 46
72: #define OSEMICOLON 47
73: #define 48
74: #define OSTATES 49
75: #define OSTATE 50
76: #define OPRINT 51
77: #define OPRINTF 52
78: #define OBREAK 53
79: #define ONEXT 54
80: #define OEXIT 55
81: #define OCONTINUE 56
82: #define OREDIR 57
83: #define OIF 58
84: #define OWHILE 59
85: #define OFOR 60
86: #define OFORIN 61
87: #define OVFLD 62
88: #define OBLOCK 63
89: #define OREGEX 64
90: #define OLENGTH 65
91: #define OLOG 66
92: #define OEXP 67
93: #define OSQRT 68
94: #define OINT 69
95:
96: #ifdef DOINIT
97: char *opname[] = {
98: "0",
99: "PROG",
100: "JUNK",
101: "HUNKS",
102: "RANGE",
103: "PAT",
104: "HUNK",
105: "PPAREN",
106: "PANDAND",
107: "POROR",
108: "PNOT",
109: "CPAREN",
110: "CANDAND",
111: "COROR",
112: "CNOT",
113: "RELOP",
114: "RPAREN",
115: "MATCHOP",
116: "MPAREN",
117: "CONCAT",
118: "ASSIGN",
119: "ADD",
120: "SUB",
121: "MULT",
122: "DIV",
123: "MOD",
124: "POSTINCR",
125: "POSTDECR",
126: "PREINCR",
127: "PREDECR",
128: "UMINUS",
129: "UPLUS",
130: "PAREN",
131: "GETLINE",
132: "SPRINTF",
133: "SUBSTR",
134: "STRING",
135: "SPLIT",
136: "SNEWLINE",
137: "INDEX",
138: "NUM",
139: "STR",
140: "VAR",
141: "FLD",
142: "NEWLINE",
143: "COMMENT",
144: "COMMA",
145: "SEMICOLON",
146: "SCOMMENT",
147: "STATES",
148: "STATE",
149: "PRINT",
150: "PRINTF",
151: "BREAK",
152: "NEXT",
153: "EXIT",
154: "CONTINUE",
155: "REDIR",
156: "IF",
157: "WHILE",
158: "FOR",
159: "FORIN",
160: "VFLD",
161: "BLOCK",
162: "REGEX",
163: "LENGTH",
164: "LOG",
165: "EXP",
166: "SQRT",
167: "INT",
168: "70"
169: };
170: #else
171: extern char *opname[];
172: #endif
173:
174: union {
175: int ival;
176: char *cval;
177: } ops[50000]; /* hope they have 200k to spare */
178:
179: EXT int mop INIT(1);
180:
181: #define DEBUGGING
182:
183: #include <stdio.h>
184: #include <ctype.h>
185: #include <setjmp.h>
186: #include <sys/types.h>
187: #include <sys/stat.h>
188: #include <time.h>
189: #include <sys/times.h>
190:
191: typedef struct string STR;
192: typedef struct htbl HASH;
193:
194: #include "str.h"
195: #include "hash.h"
196:
197: /* A string is TRUE if not "" or "0". */
198: #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
199: EXT char *Yes INIT("1");
200: EXT char *No INIT("");
201:
202: #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
203:
204: #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
205: #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
206: #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
207: EXT STR *Str;
208:
209: #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
210:
211: STR *str_new();
212:
213: char *scanpat();
214: char *scannum();
215:
216: void str_free();
217:
218: EXT int line INIT(0);
219:
220: EXT FILE *rsfp;
221: EXT char buf[1024];
222: EXT char *bufptr INIT(buf);
223:
224: EXT STR *linestr INIT(Nullstr);
225:
226: EXT char tokenbuf[256];
227: EXT int expectterm INIT(TRUE);
228:
229: #ifdef DEBUGGING
230: EXT int debug INIT(0);
231: EXT int dlevel INIT(0);
232: #define YYDEBUG 1
233: extern int yydebug;
234: #endif
235:
236: EXT STR *freestrroot INIT(Nullstr);
237:
238: EXT STR str_no;
239: EXT STR str_yes;
240:
241: EXT bool do_split INIT(FALSE);
242: EXT bool split_to_array INIT(FALSE);
243: EXT bool set_array_base INIT(FALSE);
244: EXT bool saw_RS INIT(FALSE);
245: EXT bool saw_OFS INIT(FALSE);
246: EXT bool saw_ORS INIT(FALSE);
247: EXT bool saw_line_op INIT(FALSE);
248: EXT bool in_begin INIT(TRUE);
249: EXT bool do_opens INIT(FALSE);
250: EXT bool do_fancy_opens INIT(FALSE);
251: EXT bool lval_field INIT(FALSE);
252: EXT bool do_chop INIT(FALSE);
253: EXT bool need_entire INIT(FALSE);
254: EXT bool absmaxfld INIT(FALSE);
255:
256: EXT char const_FS INIT(0);
257: EXT char *namelist INIT(Nullch);
258: EXT char fswitch INIT(0);
259:
260: EXT int saw_FS INIT(0);
261: EXT int maxfld INIT(0);
262: EXT int arymax INIT(0);
263: char *nameary[100];
264:
265: EXT STR *opens;
266:
267: EXT HASH *symtab;