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