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