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