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