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