xref: /illumos-gate/usr/src/cmd/awk_xpg4/awk.h (revision b2be350e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
579777a7dSnakanon  * Common Development and Distribution License (the "License").
679777a7dSnakanon  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2279777a7dSnakanon  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * awk -- common header file.
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * Copyright 1986, 1994 by Mortice Kern Systems Inc.  All rights reserved.
307c478bd9Sstevel@tonic-gate  *
317c478bd9Sstevel@tonic-gate  * This version uses the POSIX.2 compatible <regex.h> routines.
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * Based on MKS awk(1) ported to be /usr/xpg4/bin/awk with POSIX/XCU4 changes
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <stdio.h>
387c478bd9Sstevel@tonic-gate #include <ctype.h>
397c478bd9Sstevel@tonic-gate #include <string.h>
407c478bd9Sstevel@tonic-gate #include <math.h>
417c478bd9Sstevel@tonic-gate #include <limits.h>
427c478bd9Sstevel@tonic-gate #include <stdlib.h>
437c478bd9Sstevel@tonic-gate #include <regex.h>
447c478bd9Sstevel@tonic-gate #include <errno.h>
457c478bd9Sstevel@tonic-gate #include <sys/types.h>
467c478bd9Sstevel@tonic-gate #include <locale.h>
477c478bd9Sstevel@tonic-gate #include <wchar.h>
487c478bd9Sstevel@tonic-gate #include <widec.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	YYMAXDEPTH	300	/* Max # of productions (used by yacc) */
517c478bd9Sstevel@tonic-gate #define	YYSSIZE		300	/* Size of State/Value stacks (MKS YACC) */
527c478bd9Sstevel@tonic-gate #define	MAXDIGINT	19	/* Number of digits in an INT */
537c478bd9Sstevel@tonic-gate #define	FNULL		((FILE *)0)
547c478bd9Sstevel@tonic-gate #define	NNULL		((NODE *)0)
557c478bd9Sstevel@tonic-gate #define	SNULL		((STRING)0)
567c478bd9Sstevel@tonic-gate #define	LARGE		INT_MAX	/* Large integer */
577c478bd9Sstevel@tonic-gate #define	NPFILE		32	/* Number of -[fl] options allowed */
587c478bd9Sstevel@tonic-gate #define	NRECUR		3000	/* Maximum recursion depth */
597c478bd9Sstevel@tonic-gate 
6079777a7dSnakanon #define	M_LDATA	1
617c478bd9Sstevel@tonic-gate #ifdef M_LDATA
6279777a7dSnakanon #define	NLINE	20000	/* Longest input record */
6379777a7dSnakanon #define	NFIELD	4000	/* Number of fields allowed */
6479777a7dSnakanon #define	NBUCKET	1024	/* # of symtab buckets (power of 2) */
657c478bd9Sstevel@tonic-gate #else
6679777a7dSnakanon #define	NLINE	2048	/* Longest input record */
6779777a7dSnakanon #define	NFIELD	1024	/* Number of fields allowed */
6879777a7dSnakanon #define	NBUCKET	256	/* # of symtab buckets (power of 2) */
697c478bd9Sstevel@tonic-gate #endif
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #define	NSNODE		40	/* Number of cached nodes */
727c478bd9Sstevel@tonic-gate #define	NCONTEXT	50	/* Amount of context for error msgs */
737c478bd9Sstevel@tonic-gate #define	hashbuck(n)	((n)&(NBUCKET-1))
747c478bd9Sstevel@tonic-gate #if	BSD
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * A speedup for BSD.  Use their routines which are
777c478bd9Sstevel@tonic-gate  * already optimised.  Note that BSD bcopy does not
787c478bd9Sstevel@tonic-gate  * return a value.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate int	bcmp();
8179777a7dSnakanon #define	memcmp(b1, b2, n)	bcmp(b1, b2, n)
827c478bd9Sstevel@tonic-gate void	bcopy();
8379777a7dSnakanon #define	memcpy(b1, b2, n)	bcopy(b2, b1, (int)n)
8479777a7dSnakanon #endif	/* BSD */
857c478bd9Sstevel@tonic-gate #define	vlook(n)	vlookup(n, 0)
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * Basic AWK internal types.
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate typedef	double		REAL;
917c478bd9Sstevel@tonic-gate typedef	long long	INT;
927c478bd9Sstevel@tonic-gate typedef	wchar_t		*STRING;
9379777a7dSnakanon typedef	struct NODE	*(*FUNCTION)(struct NODE *np);
9479777a7dSnakanon typedef	void		*REGEXP;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Node in the AWK interpreter expression tree.
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate typedef	struct	NODE	{
10079777a7dSnakanon 	ushort_t	n_type;
1017c478bd9Sstevel@tonic-gate 	struct NODE	*n_next;		/* Symbol table/PARM link */
10279777a7dSnakanon 	ushort_t	n_flags;		/* Node flags, type */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	union	{
1087c478bd9Sstevel@tonic-gate 		struct	{
10979777a7dSnakanon 			ushort_t	N_hash;		/* Full hash value */
11079777a7dSnakanon 			struct NODE	*N_alink;	/* Array link */
1117c478bd9Sstevel@tonic-gate 			union	{
1127c478bd9Sstevel@tonic-gate 				struct	{
1137c478bd9Sstevel@tonic-gate 					STRING	N_string;
1147c478bd9Sstevel@tonic-gate 					size_t	N_strlen;
1157c478bd9Sstevel@tonic-gate 				}	n_str;
1167c478bd9Sstevel@tonic-gate 				INT	N_int;
1177c478bd9Sstevel@tonic-gate 				REAL	N_real;
1187c478bd9Sstevel@tonic-gate 				FUNCTION	N_function;
1197c478bd9Sstevel@tonic-gate 				struct	NODE	*N_ufunc;
1207c478bd9Sstevel@tonic-gate 			}	n_tun;
1217c478bd9Sstevel@tonic-gate 			wchar_t	N_name[1];
1227c478bd9Sstevel@tonic-gate 		}	n_term;
1237c478bd9Sstevel@tonic-gate 		struct	{
1247c478bd9Sstevel@tonic-gate 			struct	NODE	*N_left;
1257c478bd9Sstevel@tonic-gate 			struct	NODE	*N_right;
12679777a7dSnakanon 			ushort_t	N_lineno;
1277c478bd9Sstevel@tonic-gate 		}	n_op;
1287c478bd9Sstevel@tonic-gate 		struct {
1297c478bd9Sstevel@tonic-gate 			struct	NODE	*N_left;	/* Used for fliplist */
1307c478bd9Sstevel@tonic-gate 			struct	NODE	*N_right;
1317c478bd9Sstevel@tonic-gate 			REGEXP		N_regexp;	/* Regular expression */
1327c478bd9Sstevel@tonic-gate 		}	n_re;
1337c478bd9Sstevel@tonic-gate 	}	n_un;
1347c478bd9Sstevel@tonic-gate }	NODE;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Definitions to make the node access much easier.
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate #define	n_hash		n_un.n_term.N_hash	/* full hash value is sym tbl */
1407c478bd9Sstevel@tonic-gate #define	n_scope		n_un.n_term.N_hash	/* local variable scope level */
1417c478bd9Sstevel@tonic-gate #define	n_alink		n_un.n_term.N_alink	/* link to array list */
1427c478bd9Sstevel@tonic-gate #define	n_string	n_un.n_term.n_tun.n_str.N_string
1437c478bd9Sstevel@tonic-gate #define	n_strlen	n_un.n_term.n_tun.n_str.N_strlen
1447c478bd9Sstevel@tonic-gate #define	n_int		n_un.n_term.n_tun.N_int
1457c478bd9Sstevel@tonic-gate #define	n_real		n_un.n_term.n_tun.N_real
1467c478bd9Sstevel@tonic-gate #define	n_function	n_un.n_term.n_tun.N_function
1477c478bd9Sstevel@tonic-gate #define	n_ufunc		n_un.n_term.n_tun.N_ufunc
1487c478bd9Sstevel@tonic-gate #define	n_name		n_un.n_term.N_name
1497c478bd9Sstevel@tonic-gate #define	n_left		n_un.n_op.N_left
1507c478bd9Sstevel@tonic-gate #define	n_right		n_un.n_op.N_right
1517c478bd9Sstevel@tonic-gate #define	n_lineno	n_un.n_op.N_lineno
1527c478bd9Sstevel@tonic-gate #define	n_keywtype	n_un.n_op.N_lineno
1537c478bd9Sstevel@tonic-gate #define	n_regexp	n_un.n_re.N_regexp
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * Compress the types that are actually used in the final tree
1567c478bd9Sstevel@tonic-gate  * to save space in the intermediate file. Allows 1 byte to
1577c478bd9Sstevel@tonic-gate  * represent all types
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate  * n_flags bit assignments.
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate #define	FALLOC		0x01	/* Allocated node */
1707c478bd9Sstevel@tonic-gate #define	FSTATIC		0x00	/* Not allocated */
1717c478bd9Sstevel@tonic-gate #define	FMATCH		0x02	/* pattern,pattern (first part matches) */
1727c478bd9Sstevel@tonic-gate #define	FSPECIAL	0x04	/* Special pre-computed variable */
1737c478bd9Sstevel@tonic-gate #define	FINARRAY	0x08	/* NODE installed in N_alink array list */
1747c478bd9Sstevel@tonic-gate #define	FNOALLOC	0x10	/* mark node FALLOC, but don't malloc */
1757c478bd9Sstevel@tonic-gate #define	FSENSE		0x20	/* Sense if string looks like INT/REAL */
1767c478bd9Sstevel@tonic-gate #define	FSAVE		(FSPECIAL|FINARRAY)	/* assign leaves on */
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate #define	FINT		0x40	/* Node has integer type */
1797c478bd9Sstevel@tonic-gate #define	FREAL		0x80	/* Node has real type */
1807c478bd9Sstevel@tonic-gate #define	FSTRING		0x100	/* Node has string type */
1817c478bd9Sstevel@tonic-gate #define	FNONTOK		0x200	/* Node has non-token type */
1827c478bd9Sstevel@tonic-gate #define	FVINT		0x400	/* Node looks like an integer */
1837c478bd9Sstevel@tonic-gate #define	FVREAL		0x800	/* Node looks like a real number */
18479777a7dSnakanon #define	FLARRAY		0x1000	/* Local array node */
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  * n_flags macros
1887c478bd9Sstevel@tonic-gate  * These work when given an argument of np->n_flags
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate #define	isleaf(f)	(!((f)&FNONTOK))
1917c478bd9Sstevel@tonic-gate #define	isstring(f)	((f)&FSTRING)
19279777a7dSnakanon #define	isastring(f)	(((f)&(FSTRING|FALLOC)) == (FSTRING|FALLOC))
1937c478bd9Sstevel@tonic-gate #define	isnumber(f)	((f)&(FINT|FVINT|FREAL|FVREAL))
1947c478bd9Sstevel@tonic-gate #define	isreal(f)	((f)&(FREAL|FVREAL))
1957c478bd9Sstevel@tonic-gate #define	isint(f)	((f)&(FINT|FVINT))
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * Prototype file size is defined in awksize.h
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /*
2067c478bd9Sstevel@tonic-gate  * Awkrun prototype default name
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate #if defined(DOS)
20979777a7dSnakanon #if defined(__386__)
21079777a7dSnakanon #define	AWK_PROTOTYPE  M_ETCDIR(awkrunf.dos)
21179777a7dSnakanon #define	AWK_LPROTOTYPE M_ETCDIR(awkrunf.dos)
21279777a7dSnakanon #else
21379777a7dSnakanon #define	AWK_PROTOTYPE  M_ETCDIR(awkrun.dos)
21479777a7dSnakanon #define	AWK_LPROTOTYPE M_ETCDIR(awkrunl.dos)
21579777a7dSnakanon #endif
2167c478bd9Sstevel@tonic-gate #elif defined(OS2)
21779777a7dSnakanon #define	AWK_PROTOTYPE M_ETCDIR(awkrun.os2)
2187c478bd9Sstevel@tonic-gate #elif defined(NT)
21979777a7dSnakanon #define	AWK_PROTOTYPE M_ETCDIR(awkrun.nt)
2207c478bd9Sstevel@tonic-gate #else
22179777a7dSnakanon #define	AWK_PROTOTYPE M_ETCDIR(awkrun.mod)
2227c478bd9Sstevel@tonic-gate #endif
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * This is a kludge that gets around a bug in compact & large
2267c478bd9Sstevel@tonic-gate  * models under DOS.  It also makes the generated
2277c478bd9Sstevel@tonic-gate  * code faster even if there wasn't a bug.  UNIX people: try
2287c478bd9Sstevel@tonic-gate  * to ignore these noisy "near" declarations.
2297c478bd9Sstevel@tonic-gate  */
2307c478bd9Sstevel@tonic-gate #ifndef	DOS
2317c478bd9Sstevel@tonic-gate #define	near
2327c478bd9Sstevel@tonic-gate #endif
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate typedef	wchar_t	near	*LOCCHARP;	/* pointer to local strings */
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * Form of builtin symbols
2377c478bd9Sstevel@tonic-gate  * This should be a union because only one of r_ivalue
2387c478bd9Sstevel@tonic-gate  * and r_svalue is needed, but (alas) unions cannot be
2397c478bd9Sstevel@tonic-gate  * initialised.
2407c478bd9Sstevel@tonic-gate  */
2417c478bd9Sstevel@tonic-gate typedef	struct	RESERVED {
2427c478bd9Sstevel@tonic-gate 	LOCCHARP	r_name;
2437c478bd9Sstevel@tonic-gate 	int		r_type;		/* Type of node */
2447c478bd9Sstevel@tonic-gate 	INT		r_ivalue;	/* Integer value or wcslen(r_svalue) */
2457c478bd9Sstevel@tonic-gate 	STRING		r_svalue;	/* String value */
2467c478bd9Sstevel@tonic-gate }	RESERVED;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate /*
2497c478bd9Sstevel@tonic-gate  * Table of builtin functions.
2507c478bd9Sstevel@tonic-gate  */
2517c478bd9Sstevel@tonic-gate typedef	struct	RESFUNC {
2527c478bd9Sstevel@tonic-gate 	LOCCHARP	rf_name;
2537c478bd9Sstevel@tonic-gate 	int		rf_type;	/* FUNC || GETLINE */
2547c478bd9Sstevel@tonic-gate 	FUNCTION	rf_func;	/* Function pointer */
2557c478bd9Sstevel@tonic-gate }	RESFUNC;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate  * Structure holding list of open files.
2597c478bd9Sstevel@tonic-gate  */
2607c478bd9Sstevel@tonic-gate typedef	struct	OFILE	{
26179777a7dSnakanon 	ushort_t f_mode;		/* Open mode: WRITE, APPEND, PIPE */
2627c478bd9Sstevel@tonic-gate 	FILE	*f_fp;			/* File pointer if open */
2637c478bd9Sstevel@tonic-gate 	char	*f_name;		/* Remembered file name */
2647c478bd9Sstevel@tonic-gate }	OFILE;
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /* Global functions -- awk.y */
2677c478bd9Sstevel@tonic-gate int	yyparse(void);
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /* Global functions -- awk1.c */
2707c478bd9Sstevel@tonic-gate #ifdef __WATCOMC__
27179777a7dSnakanon #pragma aux yyerror aborts;
27279777a7dSnakanon #pragma aux awkerr aborts;
27379777a7dSnakanon #pragma aux awkperr aborts;
2747c478bd9Sstevel@tonic-gate #endif
2757c478bd9Sstevel@tonic-gate void	yyerror(char *msg, ...);
276*b2be350eSToomas Soome void	awkerr(char *fmt, ...) __NORETURN;
2777c478bd9Sstevel@tonic-gate void	awkperr(char *fmt, ...);
2787c478bd9Sstevel@tonic-gate void	uexit(NODE *);
2797c478bd9Sstevel@tonic-gate int	yylex(void);
2807c478bd9Sstevel@tonic-gate NODE	*renode(wchar_t *restr);
2817c478bd9Sstevel@tonic-gate wchar_t	*emalloc(unsigned);
2827c478bd9Sstevel@tonic-gate wchar_t	*erealloc(wchar_t *, unsigned);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate /* Global functions -- awk2.c */
2857c478bd9Sstevel@tonic-gate void	awk(void);
2867c478bd9Sstevel@tonic-gate void	dobegin(void);
287*b2be350eSToomas Soome void	doend(int status) __NORETURN;
2887c478bd9Sstevel@tonic-gate int	nextrecord(wchar_t *buf, FILE *fp);
2897c478bd9Sstevel@tonic-gate wchar_t	*defrecord(wchar_t *bp, int lim, FILE *fp);
2907c478bd9Sstevel@tonic-gate wchar_t	*charrecord(wchar_t *bp, int lim, FILE *fp);
2917c478bd9Sstevel@tonic-gate wchar_t	*multirecord(wchar_t *bp, int lim, FILE *fp);
2927c478bd9Sstevel@tonic-gate wchar_t	*whitefield(wchar_t **endp);
2937c478bd9Sstevel@tonic-gate wchar_t	*blackfield(wchar_t **endp);
2947c478bd9Sstevel@tonic-gate wchar_t	*refield(wchar_t **endp);
2957c478bd9Sstevel@tonic-gate void	s_print(NODE *np);
2967c478bd9Sstevel@tonic-gate void	s_prf(NODE *np);
2977c478bd9Sstevel@tonic-gate size_t	xprintf(NODE *np, FILE *fp, wchar_t **cp);
2987c478bd9Sstevel@tonic-gate void	awkclose(OFILE *op);
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate /* Global functions -- awk3.c */
3017c478bd9Sstevel@tonic-gate void	strassign(NODE *np, STRING string, int flags, size_t length);
3027c478bd9Sstevel@tonic-gate NODE	*nassign(NODE *np, NODE *value);
3037c478bd9Sstevel@tonic-gate NODE	*assign(NODE *np, NODE *value);
3047c478bd9Sstevel@tonic-gate void	delarray(NODE *np);
3057c478bd9Sstevel@tonic-gate NODE	*node(int type, NODE *left, NODE *right);
3067c478bd9Sstevel@tonic-gate NODE	*intnode(INT i);
3077c478bd9Sstevel@tonic-gate NODE	*realnode(REAL r);
3087c478bd9Sstevel@tonic-gate NODE	*stringnode(STRING str, int aflag, size_t wcslen);
3097c478bd9Sstevel@tonic-gate NODE	*vlookup(wchar_t *name, int nocreate);
3107c478bd9Sstevel@tonic-gate NODE	*emptynode(int type, size_t nlength);
3117c478bd9Sstevel@tonic-gate void	freenode(NODE *np);
3127c478bd9Sstevel@tonic-gate void	execute(NODE *np);
3137c478bd9Sstevel@tonic-gate INT	exprint(NODE *np);
3147c478bd9Sstevel@tonic-gate REAL	exprreal(NODE *np);
3157c478bd9Sstevel@tonic-gate STRING	exprstring(NODE *np);
3167c478bd9Sstevel@tonic-gate STRING	strsave(wchar_t *string);
3177c478bd9Sstevel@tonic-gate NODE	*exprreduce(NODE *np);
3187c478bd9Sstevel@tonic-gate NODE	*getlist(NODE **npp);
3197c478bd9Sstevel@tonic-gate NODE	*symwalk(int *buckp, NODE **npp);
3207c478bd9Sstevel@tonic-gate REGEXP	getregexp(NODE *np);
3217c478bd9Sstevel@tonic-gate void	addsymtab(NODE *np);
3227c478bd9Sstevel@tonic-gate void	delsymtab(NODE *np, int fflag);
3237c478bd9Sstevel@tonic-gate NODE	* finstall(LOCCHARP name, FUNCTION f, int type);
3247c478bd9Sstevel@tonic-gate void	kinstall(LOCCHARP name, int type);
3257c478bd9Sstevel@tonic-gate void	fieldsplit(void);
3267c478bd9Sstevel@tonic-gate void	promote(NODE *);
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate /* Global functions -- awk4.c */
3357c478bd9Sstevel@tonic-gate NODE	*f_exp(NODE *np);
3367c478bd9Sstevel@tonic-gate NODE	*f_int(NODE *np);
3377c478bd9Sstevel@tonic-gate NODE	*f_log(NODE *np);
3387c478bd9Sstevel@tonic-gate NODE	*f_sqrt(NODE *np);
3397c478bd9Sstevel@tonic-gate NODE	*f_getline(NODE *np);
3407c478bd9Sstevel@tonic-gate NODE	*f_index(NODE *np);
3417c478bd9Sstevel@tonic-gate NODE	*f_length(NODE *np);
3427c478bd9Sstevel@tonic-gate NODE	*f_split(NODE *np);
3437c478bd9Sstevel@tonic-gate NODE	*f_sprintf(NODE *np);
3447c478bd9Sstevel@tonic-gate NODE	*f_substr(NODE *np);
3457c478bd9Sstevel@tonic-gate NODE	*f_rand(NODE *np);
3467c478bd9Sstevel@tonic-gate NODE	*f_srand(NODE *np);
3477c478bd9Sstevel@tonic-gate NODE	*f_sin(NODE *np);
3487c478bd9Sstevel@tonic-gate NODE	*f_cos(NODE *np);
3497c478bd9Sstevel@tonic-gate NODE	*f_atan2(NODE *np);
3507c478bd9Sstevel@tonic-gate NODE	*f_sub(NODE *np);
3517c478bd9Sstevel@tonic-gate NODE	*f_gsub(NODE *np);
3527c478bd9Sstevel@tonic-gate NODE	*f_match(NODE *np);
3537c478bd9Sstevel@tonic-gate NODE	*f_system(NODE *np);
3547c478bd9Sstevel@tonic-gate NODE	*f_ord(NODE *np);
3557c478bd9Sstevel@tonic-gate NODE	*f_tolower(NODE *np);
3567c478bd9Sstevel@tonic-gate NODE	*f_toupper(NODE *np);
3577c478bd9Sstevel@tonic-gate NODE	*f_close(NODE *np);
3587c478bd9Sstevel@tonic-gate NODE	*f_asort(NODE *np);
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate /* In awk0.c */
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate extern	wchar_t	_null[];
3657c478bd9Sstevel@tonic-gate extern	char	r[];
3667c478bd9Sstevel@tonic-gate extern	char	w[];
3677c478bd9Sstevel@tonic-gate extern	wchar_t	s_OFMT[];
3687c478bd9Sstevel@tonic-gate extern	wchar_t	s_CONVFMT[];
3697c478bd9Sstevel@tonic-gate extern	wchar_t	s_NR[];
3707c478bd9Sstevel@tonic-gate extern	wchar_t	s_NF[];
3717c478bd9Sstevel@tonic-gate extern	wchar_t	s_OFS[];
3727c478bd9Sstevel@tonic-gate extern	wchar_t	s_ORS[];
3737c478bd9Sstevel@tonic-gate extern	wchar_t	s_RS[];
3747c478bd9Sstevel@tonic-gate extern	wchar_t	s_FS[];
3757c478bd9Sstevel@tonic-gate extern	wchar_t	s_FNR[];
3767c478bd9Sstevel@tonic-gate extern	wchar_t	s_SUBSEP[];
3777c478bd9Sstevel@tonic-gate extern	wchar_t	s_ARGC[], s_ARGV[], s_ENVIRON[];
3787c478bd9Sstevel@tonic-gate extern	wchar_t	s_FILENAME[], s_SYMTAB[];
3797c478bd9Sstevel@tonic-gate extern	wchar_t	s_BEGIN[], s_END[], s_next[];
3807c478bd9Sstevel@tonic-gate extern	wchar_t	_begin[], _end[];
3817c478bd9Sstevel@tonic-gate extern	wchar_t	s_exp[], s_getline[], s_index[], s_int[], s_length[], s_log[];
3827c478bd9Sstevel@tonic-gate extern	wchar_t	s_split[], s_sprintf[], s_sqrt[], s_substr[];
3837c478bd9Sstevel@tonic-gate extern	wchar_t	s_rand[], s_srand[], s_sin[], s_cos[], s_atan2[];
3847c478bd9Sstevel@tonic-gate extern	wchar_t	s_sub[], s_gsub[], s_match[], s_system[], s_ord[];
3857c478bd9Sstevel@tonic-gate extern	wchar_t	s_toupper[], s_tolower[], s_asort[];
3867c478bd9Sstevel@tonic-gate extern	wchar_t	s_close[];
3877c478bd9Sstevel@tonic-gate extern	wchar_t	redelim;
3887c478bd9Sstevel@tonic-gate extern	unsigned char	inprint;
3897c478bd9Sstevel@tonic-gate extern	unsigned char	funparm;
3907c478bd9Sstevel@tonic-gate extern	unsigned char	splitdone;
3917c478bd9Sstevel@tonic-gate extern	uint_t	npattern;
3927c478bd9Sstevel@tonic-gate extern	uint_t	nfield;
3937c478bd9Sstevel@tonic-gate extern	uint_t	fcount;
3947c478bd9Sstevel@tonic-gate extern	uint_t	phase;
3957c478bd9Sstevel@tonic-gate extern	uint_t	running;
3967c478bd9Sstevel@tonic-gate extern	uchar_t	catterm;
3977c478bd9Sstevel@tonic-gate extern	uint_t	lexlast;
3987c478bd9Sstevel@tonic-gate extern	uint_t	lineno;
3997c478bd9Sstevel@tonic-gate extern	uchar_t	needsplit, needenviron, doing_begin, begin_getline;
40079777a7dSnakanon extern	ushort_t	slevel;
40179777a7dSnakanon extern	ushort_t	loopexit;
4027c478bd9Sstevel@tonic-gate extern	wchar_t	radixpoint;
4037c478bd9Sstevel@tonic-gate extern	REGEXP	resep;
4047c478bd9Sstevel@tonic-gate extern	RESERVED	reserved[];
4057c478bd9Sstevel@tonic-gate extern	RESFUNC		resfuncs[];
4067c478bd9Sstevel@tonic-gate extern	long	NIOSTREAM;	/* Maximum open I/O streams */
4077c478bd9Sstevel@tonic-gate extern	OFILE	*ofiles;
4087c478bd9Sstevel@tonic-gate extern	wchar_t	*linebuf;
4097c478bd9Sstevel@tonic-gate extern	size_t	lbuflen;
4107c478bd9Sstevel@tonic-gate extern	char	interr[];
4117c478bd9Sstevel@tonic-gate extern	char	nomem[];
4127c478bd9Sstevel@tonic-gate extern	NODE	*symtab[NBUCKET];
4137c478bd9Sstevel@tonic-gate extern	NODE	*yytree;
4147c478bd9Sstevel@tonic-gate extern	NODE	*freelist;
4157c478bd9Sstevel@tonic-gate extern	wchar_t	*(*awkrecord)(wchar_t *, int, FILE *);
4167c478bd9Sstevel@tonic-gate extern	wchar_t	*(*awkfield)(wchar_t **);
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate extern	NODE	*constant;
4197c478bd9Sstevel@tonic-gate extern	NODE	*const0;
4207c478bd9Sstevel@tonic-gate extern	NODE	*const1;
4217c478bd9Sstevel@tonic-gate extern	NODE	*constundef;
4227c478bd9Sstevel@tonic-gate extern	NODE	*field0;
4237c478bd9Sstevel@tonic-gate extern	NODE	*incNR;
4247c478bd9Sstevel@tonic-gate extern	NODE	*incFNR;
4257c478bd9Sstevel@tonic-gate extern	NODE	*clrFNR;
4267c478bd9Sstevel@tonic-gate extern	NODE	*ARGVsubi;
4277c478bd9Sstevel@tonic-gate extern	NODE	*varNR;
4287c478bd9Sstevel@tonic-gate extern	NODE	*varFNR;
4297c478bd9Sstevel@tonic-gate extern	NODE	*varNF;
4307c478bd9Sstevel@tonic-gate extern	NODE	*varOFMT;
4317c478bd9Sstevel@tonic-gate extern	NODE	*varCONVFMT;
4327c478bd9Sstevel@tonic-gate extern	NODE	*varOFS;
4337c478bd9Sstevel@tonic-gate extern	NODE	*varORS;
4347c478bd9Sstevel@tonic-gate extern	NODE	*varFS;
4357c478bd9Sstevel@tonic-gate extern	NODE	*varRS;
4367c478bd9Sstevel@tonic-gate extern	NODE	*varARGC;
4377c478bd9Sstevel@tonic-gate extern	NODE	*varSUBSEP;
4387c478bd9Sstevel@tonic-gate extern	NODE	*varENVIRON;
4397c478bd9Sstevel@tonic-gate extern	NODE	*varSYMTAB;
4407c478bd9Sstevel@tonic-gate extern	NODE	*varFILENAME;
4417c478bd9Sstevel@tonic-gate extern	NODE	*curnode;
4427c478bd9Sstevel@tonic-gate extern	NODE    *inc_oper;
4437c478bd9Sstevel@tonic-gate extern	NODE	*asn_oper;
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate extern char *mbunconvert(wchar_t *);
4467c478bd9Sstevel@tonic-gate extern	wchar_t 	*mbstowcsdup(char *);
4477c478bd9Sstevel@tonic-gate extern	char		*wcstombsdup(wchar_t *);
4487c478bd9Sstevel@tonic-gate extern	void		awkerr(char *, ...);
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate  * The following defines the expected max length in chars of a printed number.
4517c478bd9Sstevel@tonic-gate  * This should be the longest expected size for any type of number
4527c478bd9Sstevel@tonic-gate  * ie. float, long etc. This number is used to calculate the approximate
4537c478bd9Sstevel@tonic-gate  * number of chars needed to hold the number.
4547c478bd9Sstevel@tonic-gate  */
4557c478bd9Sstevel@tonic-gate #ifdef M_NUMSIZE
45679777a7dSnakanon #define	NUMSIZE M_NUMSIZE
4577c478bd9Sstevel@tonic-gate #else
45879777a7dSnakanon #define	NUMSIZE 30
4597c478bd9Sstevel@tonic-gate #endif
4607c478bd9Sstevel@tonic-gate 
46179777a7dSnakanon #define	M_MB_L(s)	L##s
4627c478bd9Sstevel@tonic-gate #ifdef  __STDC__
46379777a7dSnakanon #define	ANSI(x) x
4647c478bd9Sstevel@tonic-gate #else
46579777a7dSnakanon #define	const
46679777a7dSnakanon #define	signed
46779777a7dSnakanon #define	volatile
46879777a7dSnakanon #define	ANSI(x) ()
4697c478bd9Sstevel@tonic-gate #endif
4707c478bd9Sstevel@tonic-gate 
47179777a7dSnakanon #define	isWblank(x) (((x) == ' ' || (x) == '\t') ? 1 : 0)
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate /*
4757c478bd9Sstevel@tonic-gate  * Wide character version of regular expression functions.
4767c478bd9Sstevel@tonic-gate  */
4777c478bd9Sstevel@tonic-gate #define	REGWMATCH_T	int_regwmatch_t
4787c478bd9Sstevel@tonic-gate #define	REGWCOMP	int_regwcomp
4797c478bd9Sstevel@tonic-gate #define	REGWEXEC	int_regwexec
48079777a7dSnakanon #define	REGWFREE	int_regwfree
48179777a7dSnakanon #define	REGWERROR	int_regwerror
4827c478bd9Sstevel@tonic-gate #define	REGWDOSUBA	int_regwdosuba
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate typedef struct {
4857c478bd9Sstevel@tonic-gate 	const wchar_t	*rm_sp, *rm_ep;
4867c478bd9Sstevel@tonic-gate 	regoff_t	rm_so, rm_eo;
4877c478bd9Sstevel@tonic-gate } int_regwmatch_t;
4887c478bd9Sstevel@tonic-gate 
48979777a7dSnakanon extern int int_regwcomp(REGEXP *, const wchar_t *);
49079777a7dSnakanon extern int int_regwexec(REGEXP, const wchar_t *, size_t,
4917c478bd9Sstevel@tonic-gate 			int_regwmatch_t *, int);
49279777a7dSnakanon extern void int_regwfree(REGEXP);
49379777a7dSnakanon extern size_t int_regwerror(int, REGEXP, char *, size_t);
49479777a7dSnakanon extern int int_regwdosuba(REGEXP, const wchar_t *,
4957c478bd9Sstevel@tonic-gate 			const wchar_t *, wchar_t **, int, int *);
496