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