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