perl 5.0 alpha 6
[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  * Revision 4.1  92/08/07  18:29:09  lwall
10  * 
11  * Revision 4.0.1.2  92/06/08  16:12:23  lwall
12  * patch20: hash tables now split only if the memory is available to do so
13  * 
14  * Revision 4.0.1.1  91/06/07  12:12:27  lwall
15  * patch4: new copyright notice
16  * 
17  * Revision 4.0  91/03/20  01:57:07  lwall
18  * 4.0 baseline.
19  * 
20  */
21
22 #define VOIDUSED 1
23 #include "../config.h"
24
25 #ifndef HAS_BCOPY
26 #   define bcopy(s1,s2,l) memcpy(s2,s1,l)
27 #endif
28 #ifndef HAS_BZERO
29 #   define bzero(s,l) memset(s,0,l)
30 #endif
31
32 #include "handy.h"
33 #define Nullop 0
34
35 #define OPROG           1
36 #define OJUNK           2
37 #define OHUNKS          3
38 #define ORANGE          4
39 #define OPAT            5
40 #define OHUNK           6
41 #define OPPAREN         7
42 #define OPANDAND        8
43 #define OPOROR          9
44 #define OPNOT           10
45 #define OCPAREN         11
46 #define OCANDAND        12
47 #define OCOROR          13
48 #define OCNOT           14
49 #define ORELOP          15
50 #define ORPAREN         16
51 #define OMATCHOP        17
52 #define OMPAREN         18
53 #define OCONCAT         19
54 #define OASSIGN         20
55 #define OADD            21
56 #define OSUBTRACT       22
57 #define OMULT           23
58 #define ODIV            24
59 #define OMOD            25
60 #define OPOSTINCR       26
61 #define OPOSTDECR       27
62 #define OPREINCR        28
63 #define OPREDECR        29
64 #define OUMINUS         30
65 #define OUPLUS          31
66 #define OPAREN          32
67 #define OGETLINE        33
68 #define OSPRINTF        34
69 #define OSUBSTR         35
70 #define OSTRING         36
71 #define OSPLIT          37
72 #define OSNEWLINE       38
73 #define OINDEX          39
74 #define ONUM            40
75 #define OSTR            41
76 #define OVAR            42
77 #define OFLD            43
78 #define ONEWLINE        44
79 #define OCOMMENT        45
80 #define OCOMMA          46
81 #define OSEMICOLON      47
82 #define OSCOMMENT       48
83 #define OSTATES         49
84 #define OSTATE          50
85 #define OPRINT          51
86 #define OPRINTF         52
87 #define OBREAK          53
88 #define ONEXT           54
89 #define OEXIT           55
90 #define OCONTINUE       56
91 #define OREDIR          57
92 #define OIF             58
93 #define OWHILE          59
94 #define OFOR            60
95 #define OFORIN          61
96 #define OVFLD           62
97 #define OBLOCK          63
98 #define OREGEX          64
99 #define OLENGTH         65
100 #define OLOG            66
101 #define OEXP            67
102 #define OSQRT           68
103 #define OINT            69
104 #define ODO             70
105 #define OPOW            71
106 #define OSUB            72
107 #define OGSUB           73
108 #define OMATCH          74
109 #define OUSERFUN        75
110 #define OUSERDEF        76
111 #define OCLOSE          77
112 #define OATAN2          78
113 #define OSIN            79
114 #define OCOS            80
115 #define ORAND           81
116 #define OSRAND          82
117 #define ODELETE         83
118 #define OSYSTEM         84
119 #define OCOND           85
120 #define ORETURN         86
121 #define ODEFINED        87
122 #define OSTAR           88
123
124 #ifdef DOINIT
125 char *opname[] = {
126     "0",
127     "PROG",
128     "JUNK",
129     "HUNKS",
130     "RANGE",
131     "PAT",
132     "HUNK",
133     "PPAREN",
134     "PANDAND",
135     "POROR",
136     "PNOT",
137     "CPAREN",
138     "CANDAND",
139     "COROR",
140     "CNOT",
141     "RELOP",
142     "RPAREN",
143     "MATCHOP",
144     "MPAREN",
145     "CONCAT",
146     "ASSIGN",
147     "ADD",
148     "SUBTRACT",
149     "MULT",
150     "DIV",
151     "MOD",
152     "POSTINCR",
153     "POSTDECR",
154     "PREINCR",
155     "PREDECR",
156     "UMINUS",
157     "UPLUS",
158     "PAREN",
159     "GETLINE",
160     "SPRINTF",
161     "SUBSTR",
162     "STRING",
163     "SPLIT",
164     "SNEWLINE",
165     "INDEX",
166     "NUM",
167     "STR",
168     "VAR",
169     "FLD",
170     "NEWLINE",
171     "COMMENT",
172     "COMMA",
173     "SEMICOLON",
174     "SCOMMENT",
175     "STATES",
176     "STATE",
177     "PRINT",
178     "PRINTF",
179     "BREAK",
180     "NEXT",
181     "EXIT",
182     "CONTINUE",
183     "REDIR",
184     "IF",
185     "WHILE",
186     "FOR",
187     "FORIN",
188     "VFLD",
189     "BLOCK",
190     "REGEX",
191     "LENGTH",
192     "LOG",
193     "EXP",
194     "SQRT",
195     "INT",
196     "DO",
197     "POW",
198     "SUB",
199     "GSUB",
200     "MATCH",
201     "USERFUN",
202     "USERDEF",
203     "CLOSE",
204     "ATAN2",
205     "SIN",
206     "COS",
207     "RAND",
208     "SRAND",
209     "DELETE",
210     "SYSTEM",
211     "COND",
212     "RETURN",
213     "DEFINED",
214     "STAR",
215     "89"
216 };
217 #else
218 extern char *opname[];
219 #endif
220
221 EXT int mop INIT(1);
222
223 union u_ops {
224     int ival;
225     char *cval;
226 };
227 #if defined(iAPX286) || defined(M_I286) || defined(I80286)      /* 80286 hack */
228 #define OPSMAX (64000/sizeof(union u_ops))      /* approx. max segment size */
229 #else
230 #define OPSMAX 50000
231 #endif                                                  /* 80286 hack */
232 union u_ops ops[OPSMAX];
233
234 #include <stdio.h>
235 #include <ctype.h>
236
237 typedef struct string STR;
238 typedef struct htbl HASH;
239
240 #include "str.h"
241 #include "hash.h"
242
243 /* A string is TRUE if not "" or "0". */
244 #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
245 EXT char *Yes INIT("1");
246 EXT char *No INIT("");
247
248 #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
249
250 #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
251 #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
252 #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
253 EXT STR *Str;
254
255 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
256
257 STR *str_new();
258
259 char *scanpat();
260 char *scannum();
261
262 void str_free();
263
264 EXT int line INIT(0);
265
266 EXT FILE *rsfp;
267 EXT char buf[2048];
268 EXT char *bufptr INIT(buf);
269
270 EXT STR *linestr INIT(Nullstr);
271
272 EXT char tokenbuf[2048];
273 EXT int expectterm INIT(TRUE);
274
275 #ifdef DEBUGGING
276 EXT int debug INIT(0);
277 EXT int dlevel INIT(0);
278 #define YYDEBUG 1
279 extern int yydebug;
280 #endif
281
282 EXT STR *freestrroot INIT(Nullstr);
283
284 EXT STR str_no;
285 EXT STR str_yes;
286
287 EXT bool do_split INIT(FALSE);
288 EXT bool split_to_array INIT(FALSE);
289 EXT bool set_array_base INIT(FALSE);
290 EXT bool saw_RS INIT(FALSE);
291 EXT bool saw_OFS INIT(FALSE);
292 EXT bool saw_ORS INIT(FALSE);
293 EXT bool saw_line_op INIT(FALSE);
294 EXT bool in_begin INIT(TRUE);
295 EXT bool do_opens INIT(FALSE);
296 EXT bool do_fancy_opens INIT(FALSE);
297 EXT bool lval_field INIT(FALSE);
298 EXT bool do_chop INIT(FALSE);
299 EXT bool need_entire INIT(FALSE);
300 EXT bool absmaxfld INIT(FALSE);
301 EXT bool saw_altinput INIT(FALSE);
302
303 EXT bool nomemok INIT(FALSE);
304
305 EXT char const_FS INIT(0);
306 EXT char *namelist INIT(Nullch);
307 EXT char fswitch INIT(0);
308
309 EXT int saw_FS INIT(0);
310 EXT int maxfld INIT(0);
311 EXT int arymax INIT(0);
312 char *nameary[100];
313
314 EXT STR *opens;
315
316 EXT HASH *symtab;
317 EXT HASH *curarghash;
318
319 #define P_MIN           0
320 #define P_LISTOP        5
321 #define P_COMMA         10
322 #define P_ASSIGN        15
323 #define P_COND          20
324 #define P_DOTDOT        25
325 #define P_OROR          30
326 #define P_ANDAND        35
327 #define P_OR            40
328 #define P_AND           45
329 #define P_EQ            50
330 #define P_REL           55
331 #define P_UNI           60
332 #define P_FILETEST      65
333 #define P_SHIFT         70
334 #define P_ADD           75
335 #define P_MUL           80
336 #define P_MATCH         85
337 #define P_UNARY         90
338 #define P_POW           95
339 #define P_AUTO          100
340 #define P_MAX           999
341
342 EXT int an;