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