perl 5.0 alpha 2
[p5sagit/p5-mst-13.2.git] / x2p / a2p.h
CommitLineData
79072805 1/* $RCSfile: a2p.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:09 $
a687059c 2 *
2b317908 3 * Copyright (c) 1991, Larry Wall
a687059c 4 *
2b317908 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.
8d063cd8 7 *
8 * $Log: a2p.h,v $
79072805 9 * Revision 4.1 92/08/07 18:29:09 lwall
10 *
bf10efe7 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 *
2b317908 14 * Revision 4.0.1.1 91/06/07 12:12:27 lwall
15 * patch4: new copyright notice
16 *
fe14fcc3 17 * Revision 4.0 91/03/20 01:57:07 lwall
18 * 4.0 baseline.
8d063cd8 19 *
20 */
21
be04251a 22#define VOIDUSED 1
23#include "../config.h"
24
fe14fcc3 25#ifndef HAS_BCOPY
449aadca 26# define bcopy(s1,s2,l) memcpy(s2,s1,l)
27#endif
fe14fcc3 28#ifndef HAS_BZERO
449aadca 29# define bzero(s,l) memset(s,0,l)
be04251a 30#endif
31
8d063cd8 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
a687059c 56#define OSUBTRACT 22
8d063cd8 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
a687059c 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
8d063cd8 123
124#ifdef DOINIT
125char *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",
a687059c 148 "SUBTRACT",
8d063cd8 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",
a687059c 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"
8d063cd8 216};
217#else
218extern char *opname[];
219#endif
220
a687059c 221EXT int mop INIT(1);
222
d8f2e4cc 223union u_ops {
8d063cd8 224 int ival;
225 char *cval;
d8f2e4cc 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 */
232union u_ops ops[OPSMAX];
8d063cd8 233
8d063cd8 234#include <stdio.h>
235#include <ctype.h>
8d063cd8 236
237typedef struct string STR;
238typedef 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])))
245EXT char *Yes INIT("1");
246EXT 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)))
253EXT STR *Str;
254
255#define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
256
257STR *str_new();
258
259char *scanpat();
260char *scannum();
261
262void str_free();
263
264EXT int line INIT(0);
265
266EXT FILE *rsfp;
fe14fcc3 267EXT char buf[2048];
8d063cd8 268EXT char *bufptr INIT(buf);
269
270EXT STR *linestr INIT(Nullstr);
271
fe14fcc3 272EXT char tokenbuf[2048];
8d063cd8 273EXT int expectterm INIT(TRUE);
274
275#ifdef DEBUGGING
276EXT int debug INIT(0);
277EXT int dlevel INIT(0);
9bb9d9f7 278#define YYDEBUG 1
8d063cd8 279extern int yydebug;
280#endif
281
282EXT STR *freestrroot INIT(Nullstr);
283
284EXT STR str_no;
285EXT STR str_yes;
286
287EXT bool do_split INIT(FALSE);
288EXT bool split_to_array INIT(FALSE);
289EXT bool set_array_base INIT(FALSE);
290EXT bool saw_RS INIT(FALSE);
291EXT bool saw_OFS INIT(FALSE);
292EXT bool saw_ORS INIT(FALSE);
293EXT bool saw_line_op INIT(FALSE);
294EXT bool in_begin INIT(TRUE);
295EXT bool do_opens INIT(FALSE);
296EXT bool do_fancy_opens INIT(FALSE);
297EXT bool lval_field INIT(FALSE);
298EXT bool do_chop INIT(FALSE);
299EXT bool need_entire INIT(FALSE);
300EXT bool absmaxfld INIT(FALSE);
a687059c 301EXT bool saw_altinput INIT(FALSE);
8d063cd8 302
bf10efe7 303EXT bool nomemok INIT(FALSE);
304
8d063cd8 305EXT char const_FS INIT(0);
306EXT char *namelist INIT(Nullch);
307EXT char fswitch INIT(0);
308
309EXT int saw_FS INIT(0);
310EXT int maxfld INIT(0);
311EXT int arymax INIT(0);
312char *nameary[100];
313
314EXT STR *opens;
315
316EXT HASH *symtab;
a687059c 317EXT 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
79072805 341
342EXT int an;