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