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