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