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