xref: /titanic_53/usr/src/cmd/awk_xpg4/awk.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * awk -- common header file.
29*7c478bd9Sstevel@tonic-gate  *
30*7c478bd9Sstevel@tonic-gate  * Copyright 1986, 1994 by Mortice Kern Systems Inc.  All rights reserved.
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  * This version uses the POSIX.2 compatible <regex.h> routines.
33*7c478bd9Sstevel@tonic-gate  *
34*7c478bd9Sstevel@tonic-gate  * Based on MKS awk(1) ported to be /usr/xpg4/bin/awk with POSIX/XCU4 changes
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  */
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #include <stdio.h>
41*7c478bd9Sstevel@tonic-gate #include <ctype.h>
42*7c478bd9Sstevel@tonic-gate #include <string.h>
43*7c478bd9Sstevel@tonic-gate #include <math.h>
44*7c478bd9Sstevel@tonic-gate #include <limits.h>
45*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
46*7c478bd9Sstevel@tonic-gate #include <regex.h>
47*7c478bd9Sstevel@tonic-gate #include <errno.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
49*7c478bd9Sstevel@tonic-gate #include <locale.h>
50*7c478bd9Sstevel@tonic-gate #include <wchar.h>
51*7c478bd9Sstevel@tonic-gate #include <widec.h>
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate #define	YYMAXDEPTH	300	/* Max # of productions (used by yacc) */
54*7c478bd9Sstevel@tonic-gate #define	YYSSIZE		300	/* Size of State/Value stacks (MKS YACC) */
55*7c478bd9Sstevel@tonic-gate #define	MAXDIGINT	19	/* Number of digits in an INT */
56*7c478bd9Sstevel@tonic-gate #define	FNULL		((FILE *)0)
57*7c478bd9Sstevel@tonic-gate #define	NNULL		((NODE *)0)
58*7c478bd9Sstevel@tonic-gate #define	SNULL		((STRING)0)
59*7c478bd9Sstevel@tonic-gate #define	LARGE		INT_MAX	/* Large integer */
60*7c478bd9Sstevel@tonic-gate #define	NPFILE		32	/* Number of -[fl] options allowed */
61*7c478bd9Sstevel@tonic-gate #define	NRECUR		3000	/* Maximum recursion depth */
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #define M_LDATA	1
64*7c478bd9Sstevel@tonic-gate #ifdef M_LDATA
65*7c478bd9Sstevel@tonic-gate # define	NLINE	20000	/* Longest input record */
66*7c478bd9Sstevel@tonic-gate # define	NFIELD	4000	/* Number of fields allowed */
67*7c478bd9Sstevel@tonic-gate # define	NBUCKET	1024	/* # of symtab buckets (power of 2) */
68*7c478bd9Sstevel@tonic-gate #else
69*7c478bd9Sstevel@tonic-gate # define	NLINE	2048	/* Longest input record */
70*7c478bd9Sstevel@tonic-gate # define	NFIELD	1024	/* Number of fields allowed */
71*7c478bd9Sstevel@tonic-gate # define	NBUCKET	256	/* # of symtab buckets (power of 2) */
72*7c478bd9Sstevel@tonic-gate #endif
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate #define	NSNODE		40	/* Number of cached nodes */
75*7c478bd9Sstevel@tonic-gate #define	NCONTEXT	50	/* Amount of context for error msgs */
76*7c478bd9Sstevel@tonic-gate #define	hashbuck(n)	((n)&(NBUCKET-1))
77*7c478bd9Sstevel@tonic-gate #if	BSD
78*7c478bd9Sstevel@tonic-gate /*
79*7c478bd9Sstevel@tonic-gate  * A speedup for BSD.  Use their routines which are
80*7c478bd9Sstevel@tonic-gate  * already optimised.  Note that BSD bcopy does not
81*7c478bd9Sstevel@tonic-gate  * return a value.
82*7c478bd9Sstevel@tonic-gate  */
83*7c478bd9Sstevel@tonic-gate int	bcmp();
84*7c478bd9Sstevel@tonic-gate #define	memcmp(b1,b2,n)	bcmp(b1,b2,n)
85*7c478bd9Sstevel@tonic-gate void	bcopy();
86*7c478bd9Sstevel@tonic-gate #define	memcpy(b1,b2,n)	bcopy(b2,b1,(int)n)
87*7c478bd9Sstevel@tonic-gate #endif	/*BSD*/
88*7c478bd9Sstevel@tonic-gate #define	vlook(n)	vlookup(n, 0)
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate /*
91*7c478bd9Sstevel@tonic-gate  * Basic AWK internal types.
92*7c478bd9Sstevel@tonic-gate  */
93*7c478bd9Sstevel@tonic-gate typedef	double		REAL;
94*7c478bd9Sstevel@tonic-gate typedef	long long	INT;
95*7c478bd9Sstevel@tonic-gate typedef	wchar_t		*STRING;
96*7c478bd9Sstevel@tonic-gate typedef	struct NODE	*(*FUNCTION)(struct NODE * np);
97*7c478bd9Sstevel@tonic-gate typedef	regex_t		*REGEXP;
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /*
100*7c478bd9Sstevel@tonic-gate  * Node in the AWK interpreter expression tree.
101*7c478bd9Sstevel@tonic-gate  */
102*7c478bd9Sstevel@tonic-gate typedef	struct	NODE	{
103*7c478bd9Sstevel@tonic-gate 	ushort	n_type;
104*7c478bd9Sstevel@tonic-gate 	struct NODE	*n_next;		/* Symbol table/PARM link */
105*7c478bd9Sstevel@tonic-gate 	ushort	n_flags;			/* Node flags, type */
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	union	{
111*7c478bd9Sstevel@tonic-gate 		struct	{
112*7c478bd9Sstevel@tonic-gate 			ushort	N_hash;			/* Full hash value */
113*7c478bd9Sstevel@tonic-gate 			struct NODE *N_alink;		/* Array link */
114*7c478bd9Sstevel@tonic-gate 			union	{
115*7c478bd9Sstevel@tonic-gate 				struct	{
116*7c478bd9Sstevel@tonic-gate 					STRING	N_string;
117*7c478bd9Sstevel@tonic-gate 					size_t	N_strlen;
118*7c478bd9Sstevel@tonic-gate 				}	n_str;
119*7c478bd9Sstevel@tonic-gate 				INT	N_int;
120*7c478bd9Sstevel@tonic-gate 				REAL	N_real;
121*7c478bd9Sstevel@tonic-gate 				FUNCTION	N_function;
122*7c478bd9Sstevel@tonic-gate 				struct	NODE	*N_ufunc;
123*7c478bd9Sstevel@tonic-gate 			}	n_tun;
124*7c478bd9Sstevel@tonic-gate 			wchar_t	N_name[1];
125*7c478bd9Sstevel@tonic-gate 		}	n_term;
126*7c478bd9Sstevel@tonic-gate 		struct	{
127*7c478bd9Sstevel@tonic-gate 			struct	NODE	*N_left;
128*7c478bd9Sstevel@tonic-gate 			struct	NODE	*N_right;
129*7c478bd9Sstevel@tonic-gate 			ushort	N_lineno;
130*7c478bd9Sstevel@tonic-gate 		}	n_op;
131*7c478bd9Sstevel@tonic-gate 		struct {
132*7c478bd9Sstevel@tonic-gate 			struct	NODE	*N_left;	/* Used for fliplist */
133*7c478bd9Sstevel@tonic-gate 			struct	NODE	*N_right;
134*7c478bd9Sstevel@tonic-gate 			REGEXP		N_regexp;	/* Regular expression */
135*7c478bd9Sstevel@tonic-gate 		}	n_re;
136*7c478bd9Sstevel@tonic-gate 	}	n_un;
137*7c478bd9Sstevel@tonic-gate }	NODE;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate /*
140*7c478bd9Sstevel@tonic-gate  * Definitions to make the node access much easier.
141*7c478bd9Sstevel@tonic-gate  */
142*7c478bd9Sstevel@tonic-gate #define	n_hash		n_un.n_term.N_hash	/* full hash value is sym tbl */
143*7c478bd9Sstevel@tonic-gate #define	n_scope		n_un.n_term.N_hash	/* local variable scope level */
144*7c478bd9Sstevel@tonic-gate #define	n_alink		n_un.n_term.N_alink	/* link to array list */
145*7c478bd9Sstevel@tonic-gate #define	n_string	n_un.n_term.n_tun.n_str.N_string
146*7c478bd9Sstevel@tonic-gate #define	n_strlen	n_un.n_term.n_tun.n_str.N_strlen
147*7c478bd9Sstevel@tonic-gate #define	n_int		n_un.n_term.n_tun.N_int
148*7c478bd9Sstevel@tonic-gate #define	n_real		n_un.n_term.n_tun.N_real
149*7c478bd9Sstevel@tonic-gate #define	n_function	n_un.n_term.n_tun.N_function
150*7c478bd9Sstevel@tonic-gate #define	n_ufunc		n_un.n_term.n_tun.N_ufunc
151*7c478bd9Sstevel@tonic-gate #define	n_name		n_un.n_term.N_name
152*7c478bd9Sstevel@tonic-gate #define	n_left		n_un.n_op.N_left
153*7c478bd9Sstevel@tonic-gate #define	n_right		n_un.n_op.N_right
154*7c478bd9Sstevel@tonic-gate #define	n_lineno	n_un.n_op.N_lineno
155*7c478bd9Sstevel@tonic-gate #define	n_keywtype	n_un.n_op.N_lineno
156*7c478bd9Sstevel@tonic-gate #define	n_regexp	n_un.n_re.N_regexp
157*7c478bd9Sstevel@tonic-gate /*
158*7c478bd9Sstevel@tonic-gate  * Compress the types that are actually used in the final tree
159*7c478bd9Sstevel@tonic-gate  * to save space in the intermediate file. Allows 1 byte to
160*7c478bd9Sstevel@tonic-gate  * represent all types
161*7c478bd9Sstevel@tonic-gate  */
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate /*
170*7c478bd9Sstevel@tonic-gate  * n_flags bit assignments.
171*7c478bd9Sstevel@tonic-gate  */
172*7c478bd9Sstevel@tonic-gate #define	FALLOC		0x01	/* Allocated node */
173*7c478bd9Sstevel@tonic-gate #define	FSTATIC		0x00	/* Not allocated */
174*7c478bd9Sstevel@tonic-gate #define	FMATCH		0x02	/* pattern,pattern (first part matches) */
175*7c478bd9Sstevel@tonic-gate #define	FSPECIAL	0x04	/* Special pre-computed variable */
176*7c478bd9Sstevel@tonic-gate #define	FINARRAY	0x08	/* NODE installed in N_alink array list */
177*7c478bd9Sstevel@tonic-gate #define	FNOALLOC	0x10	/* mark node FALLOC, but don't malloc */
178*7c478bd9Sstevel@tonic-gate #define	FSENSE		0x20	/* Sense if string looks like INT/REAL */
179*7c478bd9Sstevel@tonic-gate #define	FSAVE		(FSPECIAL|FINARRAY)	/* assign leaves on */
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate #define	FINT		0x40	/* Node has integer type */
182*7c478bd9Sstevel@tonic-gate #define	FREAL		0x80	/* Node has real type */
183*7c478bd9Sstevel@tonic-gate #define	FSTRING		0x100	/* Node has string type */
184*7c478bd9Sstevel@tonic-gate #define	FNONTOK		0x200	/* Node has non-token type */
185*7c478bd9Sstevel@tonic-gate #define	FVINT		0x400	/* Node looks like an integer */
186*7c478bd9Sstevel@tonic-gate #define	FVREAL		0x800	/* Node looks like a real number */
187*7c478bd9Sstevel@tonic-gate #define FLARRAY		0x1000	/* Local array node */
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate /*
190*7c478bd9Sstevel@tonic-gate  * n_flags macros
191*7c478bd9Sstevel@tonic-gate  * These work when given an argument of np->n_flags
192*7c478bd9Sstevel@tonic-gate  */
193*7c478bd9Sstevel@tonic-gate #define	isleaf(f)	(!((f)&FNONTOK))
194*7c478bd9Sstevel@tonic-gate #define	isstring(f)	((f)&FSTRING)
195*7c478bd9Sstevel@tonic-gate #define	isastring(f)	(((f)&(FSTRING|FALLOC))==(FSTRING|FALLOC))
196*7c478bd9Sstevel@tonic-gate #define	isnumber(f)	((f)&(FINT|FVINT|FREAL|FVREAL))
197*7c478bd9Sstevel@tonic-gate #define	isreal(f)	((f)&(FREAL|FVREAL))
198*7c478bd9Sstevel@tonic-gate #define	isint(f)	((f)&(FINT|FVINT))
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate /*
201*7c478bd9Sstevel@tonic-gate  * Prototype file size is defined in awksize.h
202*7c478bd9Sstevel@tonic-gate  */
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate /*
209*7c478bd9Sstevel@tonic-gate  * Awkrun prototype default name
210*7c478bd9Sstevel@tonic-gate  */
211*7c478bd9Sstevel@tonic-gate #if defined(DOS)
212*7c478bd9Sstevel@tonic-gate # if defined(__386__)
213*7c478bd9Sstevel@tonic-gate #  define AWK_PROTOTYPE  M_ETCDIR(awkrunf.dos)
214*7c478bd9Sstevel@tonic-gate #  define AWK_LPROTOTYPE M_ETCDIR(awkrunf.dos)
215*7c478bd9Sstevel@tonic-gate # else
216*7c478bd9Sstevel@tonic-gate #  define AWK_PROTOTYPE  M_ETCDIR(awkrun.dos)
217*7c478bd9Sstevel@tonic-gate #  define AWK_LPROTOTYPE M_ETCDIR(awkrunl.dos)
218*7c478bd9Sstevel@tonic-gate # endif
219*7c478bd9Sstevel@tonic-gate #elif defined(OS2)
220*7c478bd9Sstevel@tonic-gate # define AWK_PROTOTYPE M_ETCDIR(awkrun.os2)
221*7c478bd9Sstevel@tonic-gate #elif defined(NT)
222*7c478bd9Sstevel@tonic-gate # define AWK_PROTOTYPE M_ETCDIR(awkrun.nt)
223*7c478bd9Sstevel@tonic-gate #else
224*7c478bd9Sstevel@tonic-gate # define AWK_PROTOTYPE M_ETCDIR(awkrun.mod)
225*7c478bd9Sstevel@tonic-gate #endif
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate /*
228*7c478bd9Sstevel@tonic-gate  * This is a kludge that gets around a bug in compact & large
229*7c478bd9Sstevel@tonic-gate  * models under DOS.  It also makes the generated
230*7c478bd9Sstevel@tonic-gate  * code faster even if there wasn't a bug.  UNIX people: try
231*7c478bd9Sstevel@tonic-gate  * to ignore these noisy "near" declarations.
232*7c478bd9Sstevel@tonic-gate  */
233*7c478bd9Sstevel@tonic-gate #ifndef	DOS
234*7c478bd9Sstevel@tonic-gate #define	near
235*7c478bd9Sstevel@tonic-gate #endif
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate typedef	wchar_t	near	*LOCCHARP;	/* pointer to local strings */
238*7c478bd9Sstevel@tonic-gate /*
239*7c478bd9Sstevel@tonic-gate  * Form of builtin symbols
240*7c478bd9Sstevel@tonic-gate  * This should be a union because only one of r_ivalue
241*7c478bd9Sstevel@tonic-gate  * and r_svalue is needed, but (alas) unions cannot be
242*7c478bd9Sstevel@tonic-gate  * initialised.
243*7c478bd9Sstevel@tonic-gate  */
244*7c478bd9Sstevel@tonic-gate typedef	struct	RESERVED {
245*7c478bd9Sstevel@tonic-gate 	LOCCHARP	r_name;
246*7c478bd9Sstevel@tonic-gate 	int		r_type;		/* Type of node */
247*7c478bd9Sstevel@tonic-gate 	INT		r_ivalue;	/* Integer value or wcslen(r_svalue) */
248*7c478bd9Sstevel@tonic-gate 	STRING		r_svalue;	/* String value */
249*7c478bd9Sstevel@tonic-gate }	RESERVED;
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate /*
252*7c478bd9Sstevel@tonic-gate  * Table of builtin functions.
253*7c478bd9Sstevel@tonic-gate  */
254*7c478bd9Sstevel@tonic-gate typedef	struct	RESFUNC {
255*7c478bd9Sstevel@tonic-gate 	LOCCHARP	rf_name;
256*7c478bd9Sstevel@tonic-gate 	int		rf_type;	/* FUNC || GETLINE */
257*7c478bd9Sstevel@tonic-gate 	FUNCTION	rf_func;	/* Function pointer */
258*7c478bd9Sstevel@tonic-gate }	RESFUNC;
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate /*
261*7c478bd9Sstevel@tonic-gate  * Structure holding list of open files.
262*7c478bd9Sstevel@tonic-gate  */
263*7c478bd9Sstevel@tonic-gate typedef	struct	OFILE	{
264*7c478bd9Sstevel@tonic-gate 	ushort	f_mode;			/* Open mode: WRITE, APPEND, PIPE */
265*7c478bd9Sstevel@tonic-gate 	FILE	*f_fp;			/* File pointer if open */
266*7c478bd9Sstevel@tonic-gate 	char	*f_name;		/* Remembered file name */
267*7c478bd9Sstevel@tonic-gate }	OFILE;
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate /* Global functions -- awk.y */
270*7c478bd9Sstevel@tonic-gate int	yyparse(void);
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate /* Global functions -- awk1.c */
273*7c478bd9Sstevel@tonic-gate #ifdef __WATCOMC__
274*7c478bd9Sstevel@tonic-gate # pragma aux yyerror aborts;
275*7c478bd9Sstevel@tonic-gate # pragma aux awkerr aborts;
276*7c478bd9Sstevel@tonic-gate # pragma aux awkperr aborts;
277*7c478bd9Sstevel@tonic-gate #endif
278*7c478bd9Sstevel@tonic-gate void	yyerror(char *msg, ...);
279*7c478bd9Sstevel@tonic-gate void	awkerr(char *fmt, ...);
280*7c478bd9Sstevel@tonic-gate void	awkperr(char *fmt, ...);
281*7c478bd9Sstevel@tonic-gate void	uexit(NODE *);
282*7c478bd9Sstevel@tonic-gate int	yylex(void);
283*7c478bd9Sstevel@tonic-gate NODE	*renode(wchar_t *restr);
284*7c478bd9Sstevel@tonic-gate wchar_t	*emalloc(unsigned);
285*7c478bd9Sstevel@tonic-gate wchar_t	*erealloc(wchar_t *, unsigned);
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate /* Global functions -- awk2.c */
288*7c478bd9Sstevel@tonic-gate void	awk(void);
289*7c478bd9Sstevel@tonic-gate void	dobegin(void);
290*7c478bd9Sstevel@tonic-gate void	doend(int status);
291*7c478bd9Sstevel@tonic-gate int	nextrecord(wchar_t *buf, FILE *fp);
292*7c478bd9Sstevel@tonic-gate wchar_t	*defrecord(wchar_t *bp, int lim, FILE *fp);
293*7c478bd9Sstevel@tonic-gate wchar_t	*charrecord(wchar_t *bp, int lim, FILE *fp);
294*7c478bd9Sstevel@tonic-gate wchar_t	*multirecord(wchar_t *bp, int lim, FILE *fp);
295*7c478bd9Sstevel@tonic-gate wchar_t	*whitefield(wchar_t **endp);
296*7c478bd9Sstevel@tonic-gate wchar_t	*blackfield(wchar_t **endp);
297*7c478bd9Sstevel@tonic-gate wchar_t	*refield(wchar_t **endp);
298*7c478bd9Sstevel@tonic-gate void	s_print(NODE *np);
299*7c478bd9Sstevel@tonic-gate void	s_prf(NODE *np);
300*7c478bd9Sstevel@tonic-gate size_t	xprintf(NODE *np, FILE *fp, wchar_t **cp);
301*7c478bd9Sstevel@tonic-gate void	awkclose(OFILE *op);
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate /* Global functions -- awk3.c */
304*7c478bd9Sstevel@tonic-gate void	strassign(NODE *np, STRING string, int flags, size_t length);
305*7c478bd9Sstevel@tonic-gate NODE	*nassign(NODE *np, NODE *value);
306*7c478bd9Sstevel@tonic-gate NODE	*assign(NODE *np, NODE *value);
307*7c478bd9Sstevel@tonic-gate void	delarray(NODE *np);
308*7c478bd9Sstevel@tonic-gate NODE	*node(int type, NODE *left, NODE *right);
309*7c478bd9Sstevel@tonic-gate NODE	*intnode(INT i);
310*7c478bd9Sstevel@tonic-gate NODE	*realnode(REAL r);
311*7c478bd9Sstevel@tonic-gate NODE	*stringnode(STRING str, int aflag, size_t wcslen);
312*7c478bd9Sstevel@tonic-gate NODE	*vlookup(wchar_t *name, int nocreate);
313*7c478bd9Sstevel@tonic-gate NODE	*emptynode(int type, size_t nlength);
314*7c478bd9Sstevel@tonic-gate void	freenode(NODE *np);
315*7c478bd9Sstevel@tonic-gate void	execute(NODE *np);
316*7c478bd9Sstevel@tonic-gate INT	exprint(NODE *np);
317*7c478bd9Sstevel@tonic-gate REAL	exprreal(NODE *np);
318*7c478bd9Sstevel@tonic-gate STRING	exprstring(NODE *np);
319*7c478bd9Sstevel@tonic-gate STRING	strsave(wchar_t *string);
320*7c478bd9Sstevel@tonic-gate NODE	*exprreduce(NODE *np);
321*7c478bd9Sstevel@tonic-gate NODE	*getlist(NODE **npp);
322*7c478bd9Sstevel@tonic-gate NODE	*symwalk(int *buckp, NODE **npp);
323*7c478bd9Sstevel@tonic-gate REGEXP	getregexp(NODE *np);
324*7c478bd9Sstevel@tonic-gate void	addsymtab(NODE *np);
325*7c478bd9Sstevel@tonic-gate void	delsymtab(NODE *np, int fflag);
326*7c478bd9Sstevel@tonic-gate NODE	* finstall(LOCCHARP name, FUNCTION f, int type);
327*7c478bd9Sstevel@tonic-gate void	kinstall(LOCCHARP name, int type);
328*7c478bd9Sstevel@tonic-gate void	fieldsplit(void);
329*7c478bd9Sstevel@tonic-gate void	promote(NODE *);
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate /* Global functions -- awk4.c */
338*7c478bd9Sstevel@tonic-gate NODE	*f_exp(NODE *np);
339*7c478bd9Sstevel@tonic-gate NODE	*f_int(NODE *np);
340*7c478bd9Sstevel@tonic-gate NODE	*f_log(NODE *np);
341*7c478bd9Sstevel@tonic-gate NODE	*f_sqrt(NODE *np);
342*7c478bd9Sstevel@tonic-gate NODE	*f_getline(NODE *np);
343*7c478bd9Sstevel@tonic-gate NODE	*f_index(NODE *np);
344*7c478bd9Sstevel@tonic-gate NODE	*f_length(NODE *np);
345*7c478bd9Sstevel@tonic-gate NODE	*f_split(NODE *np);
346*7c478bd9Sstevel@tonic-gate NODE	*f_sprintf(NODE *np);
347*7c478bd9Sstevel@tonic-gate NODE	*f_substr(NODE *np);
348*7c478bd9Sstevel@tonic-gate NODE	*f_rand(NODE *np);
349*7c478bd9Sstevel@tonic-gate NODE	*f_srand(NODE *np);
350*7c478bd9Sstevel@tonic-gate NODE	*f_sin(NODE *np);
351*7c478bd9Sstevel@tonic-gate NODE	*f_cos(NODE *np);
352*7c478bd9Sstevel@tonic-gate NODE	*f_atan2(NODE *np);
353*7c478bd9Sstevel@tonic-gate NODE	*f_sub(NODE *np);
354*7c478bd9Sstevel@tonic-gate NODE	*f_gsub(NODE *np);
355*7c478bd9Sstevel@tonic-gate NODE	*f_match(NODE *np);
356*7c478bd9Sstevel@tonic-gate NODE	*f_system(NODE *np);
357*7c478bd9Sstevel@tonic-gate NODE	*f_ord(NODE *np);
358*7c478bd9Sstevel@tonic-gate NODE	*f_tolower(NODE *np);
359*7c478bd9Sstevel@tonic-gate NODE	*f_toupper(NODE *np);
360*7c478bd9Sstevel@tonic-gate NODE	*f_close(NODE *np);
361*7c478bd9Sstevel@tonic-gate NODE	*f_asort(NODE *np);
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate /* In awk0.c */
364*7c478bd9Sstevel@tonic-gate 
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate extern	wchar_t	_null[];
368*7c478bd9Sstevel@tonic-gate extern	char	r[];
369*7c478bd9Sstevel@tonic-gate extern	char	w[];
370*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_OFMT[];
371*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_CONVFMT[];
372*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_NR[];
373*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_NF[];
374*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_OFS[];
375*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_ORS[];
376*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_RS[];
377*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_FS[];
378*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_FNR[];
379*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_SUBSEP[];
380*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_ARGC[], s_ARGV[], s_ENVIRON[];
381*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_FILENAME[], s_SYMTAB[];
382*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_BEGIN[], s_END[], s_next[];
383*7c478bd9Sstevel@tonic-gate extern	wchar_t	_begin[], _end[];
384*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_exp[], s_getline[], s_index[], s_int[], s_length[], s_log[];
385*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_split[], s_sprintf[], s_sqrt[], s_substr[];
386*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_rand[], s_srand[], s_sin[], s_cos[], s_atan2[];
387*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_sub[], s_gsub[], s_match[], s_system[], s_ord[];
388*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_toupper[], s_tolower[], s_asort[];
389*7c478bd9Sstevel@tonic-gate extern	wchar_t	s_close[];
390*7c478bd9Sstevel@tonic-gate extern	wchar_t	redelim;
391*7c478bd9Sstevel@tonic-gate extern	unsigned char	inprint;
392*7c478bd9Sstevel@tonic-gate extern	unsigned char	funparm;
393*7c478bd9Sstevel@tonic-gate extern	unsigned char	splitdone;
394*7c478bd9Sstevel@tonic-gate extern	uint_t	npattern;
395*7c478bd9Sstevel@tonic-gate extern	uint_t	nfield;
396*7c478bd9Sstevel@tonic-gate extern	uint_t	fcount;
397*7c478bd9Sstevel@tonic-gate extern	uint_t	phase;
398*7c478bd9Sstevel@tonic-gate extern	uint_t	running;
399*7c478bd9Sstevel@tonic-gate extern	uchar_t	catterm;
400*7c478bd9Sstevel@tonic-gate extern	uint_t	lexlast;
401*7c478bd9Sstevel@tonic-gate extern	uint_t	lineno;
402*7c478bd9Sstevel@tonic-gate extern	uchar_t	needsplit, needenviron, doing_begin, begin_getline;
403*7c478bd9Sstevel@tonic-gate extern	ushort	slevel;
404*7c478bd9Sstevel@tonic-gate extern	ushort	loopexit;
405*7c478bd9Sstevel@tonic-gate extern	wchar_t	radixpoint;
406*7c478bd9Sstevel@tonic-gate extern	REGEXP	resep;
407*7c478bd9Sstevel@tonic-gate extern	RESERVED	reserved[];
408*7c478bd9Sstevel@tonic-gate extern	RESFUNC		resfuncs[];
409*7c478bd9Sstevel@tonic-gate extern	long	NIOSTREAM;	/* Maximum open I/O streams */
410*7c478bd9Sstevel@tonic-gate extern	OFILE	*ofiles;
411*7c478bd9Sstevel@tonic-gate extern	wchar_t	*linebuf;
412*7c478bd9Sstevel@tonic-gate extern	size_t	lbuflen;
413*7c478bd9Sstevel@tonic-gate extern	char	interr[];
414*7c478bd9Sstevel@tonic-gate extern	char	nomem[];
415*7c478bd9Sstevel@tonic-gate extern	NODE	*symtab[NBUCKET];
416*7c478bd9Sstevel@tonic-gate extern	NODE	*yytree;
417*7c478bd9Sstevel@tonic-gate extern	NODE	*freelist;
418*7c478bd9Sstevel@tonic-gate extern	wchar_t	*(*awkrecord)(wchar_t *, int, FILE *);
419*7c478bd9Sstevel@tonic-gate extern	wchar_t	*(*awkfield)(wchar_t **);
420*7c478bd9Sstevel@tonic-gate 
421*7c478bd9Sstevel@tonic-gate extern	NODE	*constant;
422*7c478bd9Sstevel@tonic-gate extern	NODE	*const0;
423*7c478bd9Sstevel@tonic-gate extern	NODE	*const1;
424*7c478bd9Sstevel@tonic-gate extern	NODE	*constundef;
425*7c478bd9Sstevel@tonic-gate extern	NODE	*field0;
426*7c478bd9Sstevel@tonic-gate extern	NODE	*incNR;
427*7c478bd9Sstevel@tonic-gate extern	NODE	*incFNR;
428*7c478bd9Sstevel@tonic-gate extern	NODE	*clrFNR;
429*7c478bd9Sstevel@tonic-gate extern	NODE	*ARGVsubi;
430*7c478bd9Sstevel@tonic-gate extern	NODE	*varNR;
431*7c478bd9Sstevel@tonic-gate extern	NODE	*varFNR;
432*7c478bd9Sstevel@tonic-gate extern	NODE	*varNF;
433*7c478bd9Sstevel@tonic-gate extern	NODE	*varOFMT;
434*7c478bd9Sstevel@tonic-gate extern	NODE	*varCONVFMT;
435*7c478bd9Sstevel@tonic-gate extern	NODE	*varOFS;
436*7c478bd9Sstevel@tonic-gate extern	NODE	*varORS;
437*7c478bd9Sstevel@tonic-gate extern	NODE	*varFS;
438*7c478bd9Sstevel@tonic-gate extern	NODE	*varRS;
439*7c478bd9Sstevel@tonic-gate extern	NODE	*varARGC;
440*7c478bd9Sstevel@tonic-gate extern	NODE	*varSUBSEP;
441*7c478bd9Sstevel@tonic-gate extern	NODE	*varENVIRON;
442*7c478bd9Sstevel@tonic-gate extern	NODE	*varSYMTAB;
443*7c478bd9Sstevel@tonic-gate extern	NODE	*varFILENAME;
444*7c478bd9Sstevel@tonic-gate extern	NODE	*curnode;
445*7c478bd9Sstevel@tonic-gate extern	NODE    *inc_oper;
446*7c478bd9Sstevel@tonic-gate extern	NODE	*asn_oper;
447*7c478bd9Sstevel@tonic-gate 
448*7c478bd9Sstevel@tonic-gate extern char *mbunconvert(wchar_t *);
449*7c478bd9Sstevel@tonic-gate extern	wchar_t 	*mbstowcsdup(char *);
450*7c478bd9Sstevel@tonic-gate extern	char		*wcstombsdup(wchar_t *);
451*7c478bd9Sstevel@tonic-gate extern	void		awkerr(char *, ...);
452*7c478bd9Sstevel@tonic-gate /*
453*7c478bd9Sstevel@tonic-gate  * The following defines the expected max length in chars of a printed number.
454*7c478bd9Sstevel@tonic-gate  * This should be the longest expected size for any type of number
455*7c478bd9Sstevel@tonic-gate  * ie. float, long etc. This number is used to calculate the approximate
456*7c478bd9Sstevel@tonic-gate  * number of chars needed to hold the number.
457*7c478bd9Sstevel@tonic-gate  */
458*7c478bd9Sstevel@tonic-gate #ifdef M_NUMSIZE
459*7c478bd9Sstevel@tonic-gate #define NUMSIZE M_NUMSIZE
460*7c478bd9Sstevel@tonic-gate #else
461*7c478bd9Sstevel@tonic-gate #define NUMSIZE 30
462*7c478bd9Sstevel@tonic-gate #endif
463*7c478bd9Sstevel@tonic-gate 
464*7c478bd9Sstevel@tonic-gate #define M_MB_L(s)       L##s
465*7c478bd9Sstevel@tonic-gate #ifdef  __STDC__
466*7c478bd9Sstevel@tonic-gate #define ANSI(x) x
467*7c478bd9Sstevel@tonic-gate #define _VOID   void            /* Used in VOID *malloc() */
468*7c478bd9Sstevel@tonic-gate #else
469*7c478bd9Sstevel@tonic-gate #define const
470*7c478bd9Sstevel@tonic-gate #define signed
471*7c478bd9Sstevel@tonic-gate #define volatile
472*7c478bd9Sstevel@tonic-gate #define ANSI(x) ()
473*7c478bd9Sstevel@tonic-gate #define _VOID   char            /* Used in _VOID *malloc() */
474*7c478bd9Sstevel@tonic-gate #endif
475*7c478bd9Sstevel@tonic-gate 
476*7c478bd9Sstevel@tonic-gate #define isWblank(x) (((x) == ' ' || (x) == '\t') ? 1 : 0 )
477*7c478bd9Sstevel@tonic-gate 
478*7c478bd9Sstevel@tonic-gate 
479*7c478bd9Sstevel@tonic-gate /*
480*7c478bd9Sstevel@tonic-gate  * Wide character version of regular expression functions.
481*7c478bd9Sstevel@tonic-gate  */
482*7c478bd9Sstevel@tonic-gate #define	REGWMATCH_T	int_regwmatch_t
483*7c478bd9Sstevel@tonic-gate #define	REGWCOMP	int_regwcomp
484*7c478bd9Sstevel@tonic-gate #define	REGWEXEC	int_regwexec
485*7c478bd9Sstevel@tonic-gate #define	REGWDOSUBA	int_regwdosuba
486*7c478bd9Sstevel@tonic-gate 
487*7c478bd9Sstevel@tonic-gate typedef struct {
488*7c478bd9Sstevel@tonic-gate 	const wchar_t	*rm_sp, *rm_ep;
489*7c478bd9Sstevel@tonic-gate 	regoff_t	rm_so, rm_eo;
490*7c478bd9Sstevel@tonic-gate } int_regwmatch_t;
491*7c478bd9Sstevel@tonic-gate 
492*7c478bd9Sstevel@tonic-gate extern int int_regwcomp(regex_t *, const wchar_t *, int);
493*7c478bd9Sstevel@tonic-gate extern int int_regwexec(const regex_t *, const wchar_t *, size_t,
494*7c478bd9Sstevel@tonic-gate 			int_regwmatch_t *, int);
495*7c478bd9Sstevel@tonic-gate extern int int_regwdosuba(regex_t *, const wchar_t *,
496*7c478bd9Sstevel@tonic-gate 			const wchar_t *, wchar_t **, int, int *);
497