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