1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Awk -- data definitions
24 *
25 * Copyright (c) 1995 by Sun Microsystems, Inc.
26 *
27 * Copyright 1986, 1992 by Mortice Kern Systems Inc.  All rights reserved.
28 *
29 * Based on MKS awk(1) ported to be /usr/xpg4/bin/awk with POSIX/XCU4 changes
30 */
31
32#pragma ident	"%Z%%M%	%I%	%E% SMI"
33
34#include "awk.h"
35#include "y.tab.h"
36
37/*
38 * This file contains data definitions for awk.
39 */
40
41RESERVED	reserved[] = {
42	s_BEGIN, KEYWORD, BEGIN, NULL,
43	s_END, KEYWORD, END, NULL,
44	M_MB_L("break"), KEYWORD, BREAK, NULL,
45	M_MB_L("continue"), KEYWORD, CONTINUE, NULL,
46	M_MB_L("for"), KEYWORD, FOR, NULL,
47	M_MB_L("if"), KEYWORD, IF, NULL,
48	M_MB_L("else"), KEYWORD, ELSE, NULL,
49	M_MB_L("in"), KEYWORD, IN, NULL,
50	s_next, KEYWORD, NEXT, NULL,
51	M_MB_L("while"), KEYWORD, WHILE, NULL,
52	M_MB_L("do"), KEYWORD, DO, NULL,
53	M_MB_L("print"), KEYWORD, PRINT, NULL,
54	M_MB_L("printf"), KEYWORD, PRINTF, NULL,
55	M_MB_L("return"), KEYWORD, RETURN, NULL,
56	M_MB_L("func"), KEYWORD, DEFFUNC, NULL,
57	M_MB_L("function"), KEYWORD, DEFFUNC, NULL,
58	M_MB_L("delete"), KEYWORD, DELETE, NULL,
59	M_MB_L("exit"), KEYWORD, EXIT, NULL,
60	s_FILENAME, VAR, 0, _null,
61	s_NF, SVAR, 0, NULL,
62	s_NR, VAR, 0, NULL,
63	s_FS, SVAR, 1, M_MB_L(" "),
64	s_OFS, VAR, 1, M_MB_L(" "),
65	s_ORS, VAR, 1, M_MB_L("\n"),
66	s_OFMT, VAR, 4, M_MB_L("%.6g"),
67	s_CONVFMT, VAR, 4, M_MB_L("%.6g"),
68	s_RS, SVAR, 1, M_MB_L("\n"),
69	s_FNR, VAR, 0, NULL,
70	s_SUBSEP, VAR, 1,
71#ifdef	M_AWK_SUBSEP
72	M_AWK_SUBSEP,
73#else
74	M_MB_L("\34"),
75#endif
76	s_ARGC, SVAR, 0, NULL,
77	(LOCCHARP)NULL
78};
79
80RESFUNC	resfuncs[] = {
81	s_exp, FUNC, f_exp,
82	s_getline, GETLINE, f_getline,
83	s_index, FUNC, f_index,
84	s_int, FUNC, f_int,
85	s_length, FUNC, f_length,
86	s_log, FUNC, f_log,
87	s_split, FUNC, f_split,
88	s_sprintf, FUNC, f_sprintf,
89	s_sqrt, FUNC, f_sqrt,
90	s_substr, FUNC, f_substr,
91	s_rand, FUNC, f_rand,
92	s_srand, FUNC, f_srand,
93	s_sin, FUNC, f_sin,
94	s_cos, FUNC, f_cos,
95	s_atan2, FUNC, f_atan2,
96	s_sub, FUNC, f_sub,
97	s_gsub, FUNC, f_gsub,
98	s_match, FUNC, f_match,
99	s_system, FUNC, f_system,
100	s_ord, FUNC, f_ord,
101	s_toupper, FUNC, f_toupper,
102	s_tolower, FUNC, f_tolower,
103	s_asort, FUNC, f_asort,
104	s_close, FUNC, f_close,
105	(LOCCHARP)NULL
106};
107
108
109OFILE	*ofiles;			/* Remembered open files (print) */
110long	NIOSTREAM = 512;		/* max num of open file descriptors */
111
112
113
114
115wchar_t	_null[] = M_MB_L("");		/* Empty string */
116char	r[] = "r";			/* Read file mode */
117char	w[] = "w";			/* Write file mode */
118wchar_t	s_OFMT[] = M_MB_L("OFMT");	/* Name of "OFMT" variable */
119wchar_t	s_CONVFMT[] = M_MB_L("CONVFMT"); /* Name of "CONVFMT" variable */
120wchar_t	s_NR[] = M_MB_L("NR");		/* Name of "NR" variable */
121wchar_t	s_NF[] = M_MB_L("NF");		/* Name of "NF" variable */
122wchar_t	s_OFS[] = M_MB_L("OFS");	/* Name of "OFS" variable */
123wchar_t	s_ORS[] = M_MB_L("ORS");	/* Name of "ORS" variable */
124wchar_t	s_RS[] = M_MB_L("RS");		/* Name of "RS" variable */
125wchar_t	s_FS[] = M_MB_L("FS");		/* Name of "FS" variable */
126wchar_t	s_FNR[] = M_MB_L("FNR");	/* Name of "FNR" variable */
127wchar_t	s_SUBSEP[] = M_MB_L("SUBSEP");	/* Name of "SUBSEP" variable */
128wchar_t	s_ARGC[] = M_MB_L("ARGC");	/* Name of "ARGC" variable */
129wchar_t	s_ARGV[] = M_MB_L("ARGV");	/* Name of "ARGV" array variable */
130wchar_t	s_ENVIRON[] = M_MB_L("ENVIRON"); /* Name of "ENVIRON" array variable */
131wchar_t	s_FILENAME[] = M_MB_L("FILENAME"); /* Name of "FILENAME" variable */
132wchar_t	s_SYMTAB[] = M_MB_L("SYMTAB");	/* Name of "SYMTAB" variable */
133wchar_t	s_BEGIN[] = M_MB_L("BEGIN");	/* Name of "BEGIN" action */
134wchar_t	s_END[] = M_MB_L("END");	/* Name of "END" action */
135wchar_t	s_next[] = M_MB_L("next");	/* Name of "next" keyword */
136wchar_t	s_exp[] = M_MB_L("exp");	/* Name of "exp" function */
137wchar_t	s_getline[] = M_MB_L("getline"); /* Name of "getline" function */
138wchar_t	s_index[] = M_MB_L("index");	/* Name of "index" function */
139wchar_t	s_int[] = M_MB_L("int");	/* Name of "int" function */
140wchar_t	s_length[] = M_MB_L("length");	/* Name of "length" function */
141wchar_t	s_log[] = M_MB_L("log");	/* Name of "log" function */
142wchar_t	s_split[] = M_MB_L("split");	/* Name of "split" function */
143wchar_t	s_sprintf[] = M_MB_L("sprintf"); /* Name of "sprintf" function */
144wchar_t	s_sqrt[] = M_MB_L("sqrt");	/* Name of "sqrt" function */
145wchar_t	s_substr[] = M_MB_L("substr");	/* Name of "substr" function */
146wchar_t	s_rand[] = M_MB_L("rand");	/* Name of "rand" function */
147wchar_t	s_srand[] = M_MB_L("srand");	/* Name of "srand" function */
148wchar_t	s_sin[] = M_MB_L("sin");	/* Name of "sin" function */
149wchar_t	s_cos[] = M_MB_L("cos");	/* Name of "cos" function */
150wchar_t	s_atan2[] = M_MB_L("atan2");	/* Name of "atan" function */
151wchar_t	s_sub[] = M_MB_L("sub");	/* Name of "sub" function */
152wchar_t	s_gsub[] = M_MB_L("gsub");	/* Name of "gsub" function */
153wchar_t	s_match[] = M_MB_L("match");	/* Name of "match" function */
154wchar_t	s_system[] = M_MB_L("system");	/* Name of "system" function */
155wchar_t	s_ord[] = M_MB_L("ord");	/* Name of "ord" function */
156wchar_t	s_toupper[] = M_MB_L("toupper"); /* Name of "toupper" function */
157wchar_t	s_tolower[] = M_MB_L("tolower"); /* Name of "tolower" function */
158wchar_t	s_asort[] = M_MB_L("asort");	/* Name of "asort" function */
159wchar_t	s_close[] = M_MB_L("close");	/* Name of "close" function */
160
161wchar_t redelim;			/* Delimiter for regexp (yylex) */
162uchar_t	inprint;			/* Special meaning for '>' & '|' */
163uchar_t	funparm;			/* Defining function parameters */
164uchar_t	splitdone;			/* Line split into fields (fieldbuf) */
165uint	npattern;			/* Number of non-BEGIN patterns */
166uint	nfield;				/* Number of fields (if splitdone) */
167uint	fcount;				/* Field counter (used by blackfield)*/
168uint	phase;				/* BEGIN, END, or 0 */
169uint	running = 0;			/* Set if not in compile phase */
170uchar_t	catterm;			/* Can inject concat or ';' */
171uint	lexlast = '\n';			/* Last lexical token */
172uint	lineno = 0;			/* Current programme line number */
173uchar_t	doing_begin;			/* set if compiling BEGIN block */
174uchar_t	begin_getline;			/* flags a getline was done in BEGIN */
175uchar_t	needsplit;			/* Set if $0 must be split when read */
176uchar_t	needenviron;			/* Set if ENVIRON variable referenced */
177ushort	slevel;				/* Scope level (0 == root) */
178ushort	loopexit;			/* Short circuit loop with keyword */
179wchar_t	radixpoint;			/* soft radix point for I18N */
180REGEXP	resep;				/* Field separator as regexp */
181wchar_t	*linebuf = NULL;		/* $0 buffer - malloc'd in awk1.c */
182size_t	lbuflen;			/* Length of linebuf */
183
184/*
185 * XXX - Make sure to check where this error message is printed
186 */
187char	interr[] = "internal execution tree error at E string";
188char	nomem[] =  "insufficient memory for string storage";
189NODE	*symtab[NBUCKET];		/* Heads of symbol table buckets */
190NODE	*yytree;			/* Code tree */
191NODE	*freelist;			/* Free every pattern {action} line */
192wchar_t	*(*awkrecord) ANSI((wchar_t *, int, FILE*)) = defrecord;
193					/* Function to read a record */
194wchar_t	*(*awkfield) ANSI((wchar_t **)) = whitefield;
195					/* Function to extract a field */
196
197/*
198 * Nodes used to speed up the execution of the
199 * interpreter.
200 */
201NODE	*constant;			/* Node to hold a constant INT */
202NODE	*const0;			/* Constant INT 0 node */
203NODE	*const1;			/* Constant INT 1 node */
204NODE	*constundef;			/* Undefined variable */
205NODE	*field0;			/* $0 */
206NODE	*incNR;				/* Code to increment NR variable */
207NODE	*incFNR;			/* Code to increment FNR variable */
208NODE	*clrFNR;			/* Zero FNR variable (each file) */
209NODE	*ARGVsubi;			/* Compute ARGV[i] */
210NODE	*varNR;				/* Remove search for NR variable */
211NODE	*varFNR;			/* Don't search for FNR variable */
212NODE	*varNF;				/* Pointer to NF variable */
213NODE	*varOFMT;			/* For s_prf */
214NODE	*varCONVFMT;			/* For internal conv of float to str */
215NODE	*varOFS;			/* For s_print */
216NODE	*varORS;			/* For s_print */
217NODE	*varFS;				/* Field separtor */
218NODE	*varRS;				/* Record separator */
219NODE	*varARGC;			/* Quick access to ARGC */
220NODE	*varSUBSEP;			/* Quick access to SUBSEP */
221NODE	*varENVIRON;			/* Pointer to ENVIRON variable */
222NODE	*varSYMTAB;			/* Symbol table special variable */
223NODE	*varFILENAME;			/* Node for FILENAME variable */
224NODE	*curnode;			/* Pointer to current line */
225NODE	*inc_oper;			/* used by INC/DEC in awk3.c */
226NODE	*asn_oper;			/* used by AADD, etc in awk3.c */
227