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