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