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