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