This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate mainline
[perl5.git] / x2p / a2p.h
CommitLineData
428aff04 1/* $RCSfile: a2p.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:09 $
a687059c 2 *
eb1102fc 3 * Copyright (c) 1991-2002, 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
d07c2202
GS
12
13#ifdef WIN32
14#define _INC_WIN32_PERL5 /* kludge around win32 stdio layer */
15#endif
16
774d564b
PP
17#ifdef VMS
18# include "config.h"
91c54917
NIS
19#elif defined(NETWARE)
20# include "../NetWare/config.h"
774d564b
PP
21#else
22# include "../config.h"
23#endif
be04251a 24
3730b96e
GS
25#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
26# define STANDARD_C 1
27#endif
28
d07c2202
GS
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
9c8d0b29
AD
49/* Use all the "standard" definitions? */
50#if defined(STANDARD_C) && defined(I_STDLIB)
51# include <stdlib.h>
52#endif /* STANDARD_C */
fed7345c 53
9c8d0b29
AD
54#include <stdio.h>
55
56#ifdef I_MATH
57#include <math.h>
58#endif
59
fed7345c
AD
60#ifdef I_SYS_TYPES
61# include <sys/types.h>
62#endif
63
dfe0b228
PP
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 */
9c8d0b29 69#include <appkit/NXCType.h>
dfe0b228
PP
70#endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
71
72#else /* !USE_NEXT_CTYPE */
9c8d0b29 73#include <ctype.h>
dfe0b228 74#endif /* USE_NEXT_CTYPE */
9c8d0b29
AD
75
76#define MEM_SIZE Size_t
77
c1d22f6b 78#ifndef STANDARD_C
20ce7b12
GS
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);
55497cff
PP
83#endif
84
9c8d0b29
AD
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
1aef975c
AD
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
4633a7c4
LW
116#ifdef DOSISH
117# if defined(OS2)
23da6c43 118# define PTHX_UNUSED
4633a7c4
LW
119# include "../os2ish.h"
120# else
121# include "../dosish.h"
122# endif
123#else
124# if defined(VMS)
44a8e56a 125# define NO_PERL_TYPEDEFS
774d564b 126# include "vmsish.h"
4633a7c4
LW
127# endif
128#endif
129
1aef975c
AD
130#ifndef STANDARD_C
131/* All of these are in stdlib.h or time.h for ANSI C */
132Time_t time();
133struct tm *gmtime(), *localtime();
092bebab
JH
134#if defined(OEMVS) || defined(__OPEN_VM)
135char *(strchr)(), *(strrchr)();
136char *(strcpy)(), *(strcat)();
137#else
1aef975c
AD
138char *strchr(), *strrchr();
139char *strcpy(), *strcat();
092bebab 140#endif
1aef975c
AD
141#endif /* ! STANDARD_C */
142
774d564b
PP
143#ifdef VMS
144# include "handy.h"
145#else
146# include "../handy.h"
147#endif
55497cff
PP
148
149#undef Nullfp
150#define Nullfp Null(FILE*)
151
8d063cd8
LW
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
a687059c 175#define OSUBTRACT 22
8d063cd8
LW
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
a687059c
LW
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
8d063cd8
LW
242
243#ifdef DOINIT
244char *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",
a687059c 267 "SUBTRACT",
8d063cd8
LW
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",
a687059c
LW
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"
8d063cd8
LW
335};
336#else
337extern char *opname[];
338#endif
339
a687059c
LW
340EXT int mop INIT(1);
341
d8f2e4cc 342union u_ops {
8d063cd8
LW
343 int ival;
344 char *cval;
d8f2e4cc
LW
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 */
a0d0e21e 351EXT union u_ops ops[OPSMAX];
8d063cd8 352
8d063cd8
LW
353typedef struct string STR;
354typedef struct htbl HASH;
355
356#include "str.h"
357#include "hash.h"
358
9c8d0b29 359
8d063cd8
LW
360/* A string is TRUE if not "" or "0". */
361#define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
362EXT char *Yes INIT("1");
363EXT 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
1779d84d 367#define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%"NVgf")",Str->str_nval),buf) : "" )))
8d063cd8
LW
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)))
370EXT STR *Str;
371
372#define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
373
9c8d0b29 374/* Prototypes for things in a2p.c */
20ce7b12
GS
375int aryrefarg ( int arg );
376int bl ( int arg, int maybe );
377void dump ( int branch );
378int fixfargs ( int name, int arg, int prevargs );
379int fixrargs ( char *name, int arg, int prevargs );
380void fixup ( STR *str );
381int numary ( int arg );
382int oper0 ( int type );
383int oper1 ( int type, int arg1 );
384int oper2 ( int type, int arg1, int arg2 );
385int oper3 ( int type, int arg1, int arg2, int arg3 );
386int oper4 ( int type, int arg1, int arg2, int arg3, int arg4 );
387int oper5 ( int type, int arg1, int arg2, int arg3, int arg4, int arg5 );
388void putlines ( STR *str );
389void putone ( void );
390int rememberargs ( int arg );
391char * scannum ( char *s );
392char * scanpat ( char *s );
393int string ( char *ptr, int len );
394void yyerror ( char *s );
395int yylex ( void );
8d063cd8
LW
396
397EXT int line INIT(0);
398
399EXT FILE *rsfp;
fe14fcc3 400EXT char buf[2048];
8d063cd8
LW
401EXT char *bufptr INIT(buf);
402
403EXT STR *linestr INIT(Nullstr);
404
fe14fcc3 405EXT char tokenbuf[2048];
8d063cd8
LW
406EXT int expectterm INIT(TRUE);
407
408#ifdef DEBUGGING
409EXT int debug INIT(0);
410EXT int dlevel INIT(0);
9bb9d9f7 411#define YYDEBUG 1
8d063cd8 412extern int yydebug;
9d116dd7
JH
413#else
414# ifndef YYDEBUG
415# define YYDEBUG 0
416# endif
8d063cd8
LW
417#endif
418
419EXT STR *freestrroot INIT(Nullstr);
420
421EXT STR str_no;
422EXT STR str_yes;
423
424EXT bool do_split INIT(FALSE);
425EXT bool split_to_array INIT(FALSE);
426EXT bool set_array_base INIT(FALSE);
427EXT bool saw_RS INIT(FALSE);
428EXT bool saw_OFS INIT(FALSE);
429EXT bool saw_ORS INIT(FALSE);
430EXT bool saw_line_op INIT(FALSE);
431EXT bool in_begin INIT(TRUE);
432EXT bool do_opens INIT(FALSE);
433EXT bool do_fancy_opens INIT(FALSE);
434EXT bool lval_field INIT(FALSE);
435EXT bool do_chop INIT(FALSE);
436EXT bool need_entire INIT(FALSE);
437EXT bool absmaxfld INIT(FALSE);
a687059c 438EXT bool saw_altinput INIT(FALSE);
8d063cd8 439
bf10efe7
LW
440EXT bool nomemok INIT(FALSE);
441
8d063cd8
LW
442EXT char const_FS INIT(0);
443EXT char *namelist INIT(Nullch);
444EXT char fswitch INIT(0);
a5571d59 445EXT bool old_awk INIT(0);
8d063cd8
LW
446
447EXT int saw_FS INIT(0);
448EXT int maxfld INIT(0);
449EXT int arymax INIT(0);
a0d0e21e 450EXT char *nameary[100];
8d063cd8
LW
451
452EXT STR *opens;
453
454EXT HASH *symtab;
a687059c
LW
455EXT 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
79072805
LW
479
480EXT int an;