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