This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Mark grok_bslash functions as intfce changeable
[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 __cplusplus
155 #  define PERL_EXPORT_C extern "C"
156 #else
157 #  define PERL_EXPORT_C extern
158 #endif
159
160 #ifdef VMS
161 #  include "handy.h"
162 #else 
163 #  include "../handy.h"
164 #endif
165
166 #define Nullop 0
167
168 #define OPROG           1
169 #define OJUNK           2
170 #define OHUNKS          3
171 #define ORANGE          4
172 #define OPAT            5
173 #define OHUNK           6
174 #define OPPAREN         7
175 #define OPANDAND        8
176 #define OPOROR          9
177 #define OPNOT           10
178 #define OCPAREN         11
179 #define OCANDAND        12
180 #define OCOROR          13
181 #define OCNOT           14
182 #define ORELOP          15
183 #define ORPAREN         16
184 #define OMATCHOP        17
185 #define OMPAREN         18
186 #define OCONCAT         19
187 #define OASSIGN         20
188 #define OADD            21
189 #define OSUBTRACT       22
190 #define OMULT           23
191 #define ODIV            24
192 #define OMOD            25
193 #define OPOSTINCR       26
194 #define OPOSTDECR       27
195 #define OPREINCR        28
196 #define OPREDECR        29
197 #define OUMINUS         30
198 #define OUPLUS          31
199 #define OPAREN          32
200 #define OGETLINE        33
201 #define OSPRINTF        34
202 #define OSUBSTR         35
203 #define OSTRING         36
204 #define OSPLIT          37
205 #define OSNEWLINE       38
206 #define OINDEX          39
207 #define ONUM            40
208 #define OSTR            41
209 #define OVAR            42
210 #define OFLD            43
211 #define ONEWLINE        44
212 #define OCOMMENT        45
213 #define OCOMMA          46
214 #define OSEMICOLON      47
215 #define OSCOMMENT       48
216 #define OSTATES         49
217 #define OSTATE          50
218 #define OPRINT          51
219 #define OPRINTF         52
220 #define OBREAK          53
221 #define ONEXT           54
222 #define OEXIT           55
223 #define OCONTINUE       56
224 #define OREDIR          57
225 #define OIF             58
226 #define OWHILE          59
227 #define OFOR            60
228 #define OFORIN          61
229 #define OVFLD           62
230 #define OBLOCK          63
231 #define OREGEX          64
232 #define OLENGTH         65
233 #define OLOG            66
234 #define OEXP            67
235 #define OSQRT           68
236 #define OINT            69
237 #define ODO             70
238 #define OPOW            71
239 #define OSUB            72
240 #define OGSUB           73
241 #define OMATCH          74
242 #define OUSERFUN        75
243 #define OUSERDEF        76
244 #define OCLOSE          77
245 #define OATAN2          78
246 #define OSIN            79
247 #define OCOS            80
248 #define ORAND           81
249 #define OSRAND          82
250 #define ODELETE         83
251 #define OSYSTEM         84
252 #define OCOND           85
253 #define ORETURN         86
254 #define ODEFINED        87
255 #define OSTAR           88
256
257 #ifdef DOINIT
258 const char *opname[] = {
259     "0",
260     "PROG",
261     "JUNK",
262     "HUNKS",
263     "RANGE",
264     "PAT",
265     "HUNK",
266     "PPAREN",
267     "PANDAND",
268     "POROR",
269     "PNOT",
270     "CPAREN",
271     "CANDAND",
272     "COROR",
273     "CNOT",
274     "RELOP",
275     "RPAREN",
276     "MATCHOP",
277     "MPAREN",
278     "CONCAT",
279     "ASSIGN",
280     "ADD",
281     "SUBTRACT",
282     "MULT",
283     "DIV",
284     "MOD",
285     "POSTINCR",
286     "POSTDECR",
287     "PREINCR",
288     "PREDECR",
289     "UMINUS",
290     "UPLUS",
291     "PAREN",
292     "GETLINE",
293     "SPRINTF",
294     "SUBSTR",
295     "STRING",
296     "SPLIT",
297     "SNEWLINE",
298     "INDEX",
299     "NUM",
300     "STR",
301     "VAR",
302     "FLD",
303     "NEWLINE",
304     "COMMENT",
305     "COMMA",
306     "SEMICOLON",
307     "SCOMMENT",
308     "STATES",
309     "STATE",
310     "PRINT",
311     "PRINTF",
312     "BREAK",
313     "NEXT",
314     "EXIT",
315     "CONTINUE",
316     "REDIR",
317     "IF",
318     "WHILE",
319     "FOR",
320     "FORIN",
321     "VFLD",
322     "BLOCK",
323     "REGEX",
324     "LENGTH",
325     "LOG",
326     "EXP",
327     "SQRT",
328     "INT",
329     "DO",
330     "POW",
331     "SUB",
332     "GSUB",
333     "MATCH",
334     "USERFUN",
335     "USERDEF",
336     "CLOSE",
337     "ATAN2",
338     "SIN",
339     "COS",
340     "RAND",
341     "SRAND",
342     "DELETE",
343     "SYSTEM",
344     "COND",
345     "RETURN",
346     "DEFINED",
347     "STAR",
348     "89"
349 };
350 #else
351 extern const char *opname[];
352 #endif
353
354 EXT int mop INIT(1);
355
356 union u_ops {
357     int ival;
358     char *cval;
359 };
360 #if defined(iAPX286) || defined(M_I286) || defined(I80286)      /* 80286 hack */
361 #define OPSMAX (64000/sizeof(union u_ops))      /* approx. max segment size */
362 #else
363 #define OPSMAX 50000
364 #endif                                                  /* 80286 hack */
365 EXT union u_ops ops[OPSMAX];
366
367 typedef struct string STR;
368 typedef struct htbl HASH;
369
370 #include "str.h"
371 #include "hash.h"
372
373
374 /* A string is TRUE if not "" or "0". */
375 #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
376 EXT const char *Yes INIT("1");
377 EXT const char *No INIT("");
378
379 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
380 EXT STR *Str;
381
382 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
383
384 /* Prototypes for things in a2p.c */
385 int aryrefarg ( int arg );
386 int bl ( int arg, int maybe );
387 void dump ( int branch );
388 int fixfargs ( int name, int arg, int prevargs );
389 int fixrargs ( char *name, int arg, int prevargs );
390 void fixup ( STR *str );
391 int numary ( int arg );
392 int oper0 ( int type );
393 int oper1 ( int type, int arg1 );
394 int oper2 ( int type, int arg1, int arg2 );
395 int oper3 ( int type, int arg1, int arg2, int arg3 );
396 int oper4 ( int type, int arg1, int arg2, int arg3, int arg4 );
397 int oper5 ( int type, int arg1, int arg2, int arg3, int arg4, int arg5 );
398 void putlines ( STR *str );
399 void putone ( void );
400 int rememberargs ( int arg );
401 char * scannum ( char *s );
402 char * scanpat ( char *s );
403 int string ( const char *ptr, int len );
404 void yyerror ( const char *s );
405 int yylex ( void );
406
407 EXT int line INIT(0);
408
409 EXT FILE *rsfp;
410 EXT char buf[2048];
411 EXT char *bufptr INIT(buf);
412
413 EXT STR *linestr INIT(NULL);
414
415 EXT char tokenbuf[2048];
416 EXT int expectterm INIT(TRUE);
417
418 #ifdef DEBUGGING
419 EXT int debug INIT(0);
420 EXT int dlevel INIT(0);
421 #define YYDEBUG 1
422 extern int yydebug;
423 #else
424 # ifndef YYDEBUG
425 #  define YYDEBUG 0
426 # endif
427 #endif
428
429 EXT STR *freestrroot INIT(NULL);
430
431 EXT STR str_no;
432 EXT STR str_yes;
433
434 EXT bool do_split INIT(FALSE);
435 EXT bool split_to_array INIT(FALSE);
436 EXT bool saw_RS INIT(FALSE);
437 EXT bool saw_OFS INIT(FALSE);
438 EXT bool saw_ORS INIT(FALSE);
439 EXT bool saw_line_op INIT(FALSE);
440 EXT bool in_begin INIT(TRUE);
441 EXT bool do_opens INIT(FALSE);
442 EXT bool do_fancy_opens INIT(FALSE);
443 EXT bool lval_field INIT(FALSE);
444 EXT bool do_chop INIT(FALSE);
445 EXT bool need_entire INIT(FALSE);
446 EXT bool absmaxfld INIT(FALSE);
447 EXT bool saw_altinput INIT(FALSE);
448
449 EXT bool nomemok INIT(FALSE);
450
451 EXT char const_FS INIT(0);
452 EXT char *namelist INIT(NULL);
453 EXT char fswitch INIT(0);
454 EXT bool old_awk INIT(0);
455
456 EXT int saw_FS INIT(0);
457 EXT int maxfld INIT(0);
458 EXT int arymax INIT(0);
459 EXT char *nameary[100];
460
461 EXT STR *opens;
462
463 EXT HASH *symtab;
464 EXT HASH *curarghash;
465
466 #define P_MIN           0
467 #define P_LISTOP        5
468 #define P_COMMA         10
469 #define P_ASSIGN        15
470 #define P_COND          20
471 #define P_DOTDOT        25
472 #define P_OROR          30
473 #define P_ANDAND        35
474 #define P_OR            40
475 #define P_AND           45
476 #define P_EQ            50
477 #define P_REL           55
478 #define P_UNI           60
479 #define P_FILETEST      65
480 #define P_SHIFT         70
481 #define P_ADD           75
482 #define P_MUL           80
483 #define P_MATCH         85
484 #define P_UNARY         90
485 #define P_POW           95
486 #define P_AUTO          100
487 #define P_MAX           999
488
489 EXT int an;