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