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