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