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