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