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