This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
silence a compiler warning
[perl5.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 #undef Nullfp
161 #define Nullfp Null(FILE*)
162
163 #define Nullop 0
164
165 #define OPROG           1
166 #define OJUNK           2
167 #define OHUNKS          3
168 #define ORANGE          4
169 #define OPAT            5
170 #define OHUNK           6
171 #define OPPAREN         7
172 #define OPANDAND        8
173 #define OPOROR          9
174 #define OPNOT           10
175 #define OCPAREN         11
176 #define OCANDAND        12
177 #define OCOROR          13
178 #define OCNOT           14
179 #define ORELOP          15
180 #define ORPAREN         16
181 #define OMATCHOP        17
182 #define OMPAREN         18
183 #define OCONCAT         19
184 #define OASSIGN         20
185 #define OADD            21
186 #define OSUBTRACT       22
187 #define OMULT           23
188 #define ODIV            24
189 #define OMOD            25
190 #define OPOSTINCR       26
191 #define OPOSTDECR       27
192 #define OPREINCR        28
193 #define OPREDECR        29
194 #define OUMINUS         30
195 #define OUPLUS          31
196 #define OPAREN          32
197 #define OGETLINE        33
198 #define OSPRINTF        34
199 #define OSUBSTR         35
200 #define OSTRING         36
201 #define OSPLIT          37
202 #define OSNEWLINE       38
203 #define OINDEX          39
204 #define ONUM            40
205 #define OSTR            41
206 #define OVAR            42
207 #define OFLD            43
208 #define ONEWLINE        44
209 #define OCOMMENT        45
210 #define OCOMMA          46
211 #define OSEMICOLON      47
212 #define OSCOMMENT       48
213 #define OSTATES         49
214 #define OSTATE          50
215 #define OPRINT          51
216 #define OPRINTF         52
217 #define OBREAK          53
218 #define ONEXT           54
219 #define OEXIT           55
220 #define OCONTINUE       56
221 #define OREDIR          57
222 #define OIF             58
223 #define OWHILE          59
224 #define OFOR            60
225 #define OFORIN          61
226 #define OVFLD           62
227 #define OBLOCK          63
228 #define OREGEX          64
229 #define OLENGTH         65
230 #define OLOG            66
231 #define OEXP            67
232 #define OSQRT           68
233 #define OINT            69
234 #define ODO             70
235 #define OPOW            71
236 #define OSUB            72
237 #define OGSUB           73
238 #define OMATCH          74
239 #define OUSERFUN        75
240 #define OUSERDEF        76
241 #define OCLOSE          77
242 #define OATAN2          78
243 #define OSIN            79
244 #define OCOS            80
245 #define ORAND           81
246 #define OSRAND          82
247 #define ODELETE         83
248 #define OSYSTEM         84
249 #define OCOND           85
250 #define ORETURN         86
251 #define ODEFINED        87
252 #define OSTAR           88
253
254 #ifdef DOINIT
255 char *opname[] = {
256     "0",
257     "PROG",
258     "JUNK",
259     "HUNKS",
260     "RANGE",
261     "PAT",
262     "HUNK",
263     "PPAREN",
264     "PANDAND",
265     "POROR",
266     "PNOT",
267     "CPAREN",
268     "CANDAND",
269     "COROR",
270     "CNOT",
271     "RELOP",
272     "RPAREN",
273     "MATCHOP",
274     "MPAREN",
275     "CONCAT",
276     "ASSIGN",
277     "ADD",
278     "SUBTRACT",
279     "MULT",
280     "DIV",
281     "MOD",
282     "POSTINCR",
283     "POSTDECR",
284     "PREINCR",
285     "PREDECR",
286     "UMINUS",
287     "UPLUS",
288     "PAREN",
289     "GETLINE",
290     "SPRINTF",
291     "SUBSTR",
292     "STRING",
293     "SPLIT",
294     "SNEWLINE",
295     "INDEX",
296     "NUM",
297     "STR",
298     "VAR",
299     "FLD",
300     "NEWLINE",
301     "COMMENT",
302     "COMMA",
303     "SEMICOLON",
304     "SCOMMENT",
305     "STATES",
306     "STATE",
307     "PRINT",
308     "PRINTF",
309     "BREAK",
310     "NEXT",
311     "EXIT",
312     "CONTINUE",
313     "REDIR",
314     "IF",
315     "WHILE",
316     "FOR",
317     "FORIN",
318     "VFLD",
319     "BLOCK",
320     "REGEX",
321     "LENGTH",
322     "LOG",
323     "EXP",
324     "SQRT",
325     "INT",
326     "DO",
327     "POW",
328     "SUB",
329     "GSUB",
330     "MATCH",
331     "USERFUN",
332     "USERDEF",
333     "CLOSE",
334     "ATAN2",
335     "SIN",
336     "COS",
337     "RAND",
338     "SRAND",
339     "DELETE",
340     "SYSTEM",
341     "COND",
342     "RETURN",
343     "DEFINED",
344     "STAR",
345     "89"
346 };
347 #else
348 extern char *opname[];
349 #endif
350
351 EXT int mop INIT(1);
352
353 union u_ops {
354     int ival;
355     char *cval;
356 };
357 #if defined(iAPX286) || defined(M_I286) || defined(I80286)      /* 80286 hack */
358 #define OPSMAX (64000/sizeof(union u_ops))      /* approx. max segment size */
359 #else
360 #define OPSMAX 50000
361 #endif                                                  /* 80286 hack */
362 EXT union u_ops ops[OPSMAX];
363
364 typedef struct string STR;
365 typedef struct htbl HASH;
366
367 #include "str.h"
368 #include "hash.h"
369
370
371 /* A string is TRUE if not "" or "0". */
372 #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
373 EXT char *Yes INIT("1");
374 EXT char *No INIT("");
375
376 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
377 EXT STR *Str;
378
379 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
380
381 /* Prototypes for things in a2p.c */
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 );
403
404 EXT int line INIT(0);
405
406 EXT FILE *rsfp;
407 EXT char buf[2048];
408 EXT char *bufptr INIT(buf);
409
410 EXT STR *linestr INIT(Nullstr);
411
412 EXT char tokenbuf[2048];
413 EXT int expectterm INIT(TRUE);
414
415 #ifdef DEBUGGING
416 EXT int debug INIT(0);
417 EXT int dlevel INIT(0);
418 #define YYDEBUG 1
419 extern int yydebug;
420 #else
421 # ifndef YYDEBUG
422 #  define YYDEBUG 0
423 # endif
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);
445 EXT bool saw_altinput INIT(FALSE);
446
447 EXT bool nomemok INIT(FALSE);
448
449 EXT char const_FS INIT(0);
450 EXT char *namelist INIT(Nullch);
451 EXT char fswitch INIT(0);
452 EXT bool old_awk INIT(0);
453
454 EXT int saw_FS INIT(0);
455 EXT int maxfld INIT(0);
456 EXT int arymax INIT(0);
457 EXT char *nameary[100];
458
459 EXT STR *opens;
460
461 EXT HASH *symtab;
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
486
487 EXT int an;