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