xref: /titanic_54/usr/src/cmd/oawk/awk.def (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 (c) 1996, by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate#include	<locale.h>
29*7c478bd9Sstevel@tonic-gate#include	<euc.h>
30*7c478bd9Sstevel@tonic-gate#include	<widec.h>
31*7c478bd9Sstevel@tonic-gate#define	xfree(a)	{ if (a!=NULL) { yfree(a); a=NULL; } }
32*7c478bd9Sstevel@tonic-gate#define	yfree free
33*7c478bd9Sstevel@tonic-gate#ifdef	DEBUG
34*7c478bd9Sstevel@tonic-gate#define	dprintf	if (dbg) printf
35*7c478bd9Sstevel@tonic-gate#else
36*7c478bd9Sstevel@tonic-gate#	define	dprintf(x1, x2, x3, x4)
37*7c478bd9Sstevel@tonic-gate#endif
38*7c478bd9Sstevel@tonic-gate#define	WC_VERY_SMALL ((wchar_t) 0x0001)
39*7c478bd9Sstevel@tonic-gate#define	WC_VERY_LARGE ((wchar_t) ~0x0000)
40*7c478bd9Sstevel@tonic-gatetypedef double	awkfloat;
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gateextern wchar_t	**FS;
43*7c478bd9Sstevel@tonic-gateextern wchar_t	**RS;
44*7c478bd9Sstevel@tonic-gateextern wchar_t	**ORS;
45*7c478bd9Sstevel@tonic-gateextern wchar_t	**OFS;
46*7c478bd9Sstevel@tonic-gateextern wchar_t	**OFMT;
47*7c478bd9Sstevel@tonic-gateextern awkfloat *NR;
48*7c478bd9Sstevel@tonic-gateextern awkfloat *NF;
49*7c478bd9Sstevel@tonic-gateextern wchar_t	**FILENAME;
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gateextern wchar_t	record[];
52*7c478bd9Sstevel@tonic-gateextern wchar_t	L_NULL[];
53*7c478bd9Sstevel@tonic-gateextern int	dbg;
54*7c478bd9Sstevel@tonic-gateextern long long lineno;
55*7c478bd9Sstevel@tonic-gateextern int	errorflag;
56*7c478bd9Sstevel@tonic-gateextern int	donefld; /* 1 if record broken into fields */
57*7c478bd9Sstevel@tonic-gateextern int	donerec; /* 1 if record is valid (no fld has changed */
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate/* CELL:  all information about a variable or constant */
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gatetypedef struct val {
62*7c478bd9Sstevel@tonic-gate	char	ctype;		/* CELL, BOOL, JUMP, etc. */
63*7c478bd9Sstevel@tonic-gate	char	csub;		/* subtype of ctype */
64*7c478bd9Sstevel@tonic-gate	wchar_t *nval;   /* name, for variables only */
65*7c478bd9Sstevel@tonic-gate	wchar_t *sval;   /* string value */
66*7c478bd9Sstevel@tonic-gate	awkfloat fval;		/* value as number */
67*7c478bd9Sstevel@tonic-gate	unsigned tval;		/* type info */
68*7c478bd9Sstevel@tonic-gate	struct val *nextval;	/* ptr to next if chained */
69*7c478bd9Sstevel@tonic-gate} CELL;
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gateextern CELL	*symtab[];
72*7c478bd9Sstevel@tonic-gateextern CELL	*setsymtab(), *lookup(), **makesymtab();
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gateextern CELL	*recloc;	/* location of input record */
75*7c478bd9Sstevel@tonic-gateextern CELL	*nrloc;		/* NR */
76*7c478bd9Sstevel@tonic-gateextern CELL	*nfloc;		/* NF */
77*7c478bd9Sstevel@tonic-gateextern CELL	*maxmfld;	/* pointer to CELL for maximum field assigned to */
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate/* CELL.tval values: */
80*7c478bd9Sstevel@tonic-gate#define	STR	01	/* string value is valid */
81*7c478bd9Sstevel@tonic-gate#define	NUM	02	/* number value is valid */
82*7c478bd9Sstevel@tonic-gate#define	FLD	04	/* FLD means don't free string space */
83*7c478bd9Sstevel@tonic-gate#define	CON	010	/* this is a constant */
84*7c478bd9Sstevel@tonic-gate#define	ARR	020	/* this is an array */
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gateawkfloat	setfval(), getfval();
87*7c478bd9Sstevel@tonic-gatewchar_t  *setsval(), *getsval();
88*7c478bd9Sstevel@tonic-gatewchar_t  *tostring(), *tokname();
89*7c478bd9Sstevel@tonic-gatechar	*toeuccode();
90*7c478bd9Sstevel@tonic-gatedouble	log(), sqrt(), exp(), atof();
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate/* function types */
93*7c478bd9Sstevel@tonic-gate#define	FLENGTH	1
94*7c478bd9Sstevel@tonic-gate#define	FSQRT	2
95*7c478bd9Sstevel@tonic-gate#define	FEXP	3
96*7c478bd9Sstevel@tonic-gate#define	FLOG	4
97*7c478bd9Sstevel@tonic-gate#define	FINT	5
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate#define	BOTCH	1
100*7c478bd9Sstevel@tonic-gatetypedef struct nd {
101*7c478bd9Sstevel@tonic-gate	char	ntype;
102*7c478bd9Sstevel@tonic-gate	char	subtype;
103*7c478bd9Sstevel@tonic-gate	struct nd *nnext;
104*7c478bd9Sstevel@tonic-gate	int	nobj;
105*7c478bd9Sstevel@tonic-gate	struct nd *narg[BOTCH];	/* C won't take a zero length array */
106*7c478bd9Sstevel@tonic-gate} NODE;
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gateextern NODE	*winner;
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate/* ctypes */
111*7c478bd9Sstevel@tonic-gate#define	OCELL	1
112*7c478bd9Sstevel@tonic-gate#define	OBOOL	2
113*7c478bd9Sstevel@tonic-gate#define	OJUMP	3
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate/* CELL subtypes */
116*7c478bd9Sstevel@tonic-gate#define	CCON	5
117*7c478bd9Sstevel@tonic-gate#define	CTEMP	4
118*7c478bd9Sstevel@tonic-gate#define	CNAME	3
119*7c478bd9Sstevel@tonic-gate#define	CVAR	2
120*7c478bd9Sstevel@tonic-gate#define	CFLD	1
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate/* bool subtypes */
123*7c478bd9Sstevel@tonic-gate#define	BTRUE	1
124*7c478bd9Sstevel@tonic-gate#define	BFALSE	2
125*7c478bd9Sstevel@tonic-gate
126*7c478bd9Sstevel@tonic-gate/* jump subtypes */
127*7c478bd9Sstevel@tonic-gate#define	JEXIT	1
128*7c478bd9Sstevel@tonic-gate#define	JNEXT	2
129*7c478bd9Sstevel@tonic-gate#define	JBREAK	3
130*7c478bd9Sstevel@tonic-gate#define	JCONT	4
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate/* node types */
133*7c478bd9Sstevel@tonic-gate#define	NVALUE	1
134*7c478bd9Sstevel@tonic-gate#define	NSTAT	2
135*7c478bd9Sstevel@tonic-gate#define	NEXPR	3
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gateextern CELL	*(*proctab[])();
138*7c478bd9Sstevel@tonic-gateextern int	pairstack[], paircnt;
139*7c478bd9Sstevel@tonic-gate
140*7c478bd9Sstevel@tonic-gate#define	cantexec(n)	(n->ntype == NVALUE)
141*7c478bd9Sstevel@tonic-gate#define	notlegal(n)	(n <= FIRSTTOKEN || n >= LASTTOKEN || \
142*7c478bd9Sstevel@tonic-gate				proctab[n-FIRSTTOKEN]== nullproc)
143*7c478bd9Sstevel@tonic-gate#define	isexpr(n)	(n->ntype == NEXPR)
144*7c478bd9Sstevel@tonic-gate#define	isjump(n)	(n->ctype == OJUMP)
145*7c478bd9Sstevel@tonic-gate#define	isexit(n)	(n->ctype == OJUMP && n->csub == JEXIT)
146*7c478bd9Sstevel@tonic-gate#define	isbreak(n)	(n->ctype == OJUMP && n->csub == JBREAK)
147*7c478bd9Sstevel@tonic-gate#define	iscont(n)	(n->ctype == OJUMP && n->csub == JCONT)
148*7c478bd9Sstevel@tonic-gate#define	isnext(n)	(n->ctype == OJUMP && n->csub == JNEXT)
149*7c478bd9Sstevel@tonic-gate#define	isstr(n)	(n->tval & STR)
150*7c478bd9Sstevel@tonic-gate#define	isnum(n)	(n->tval & NUM)
151*7c478bd9Sstevel@tonic-gate#define	istrue(n)	(n->ctype == OBOOL && n->csub == BTRUE)
152*7c478bd9Sstevel@tonic-gate#define	istemp(n)	(n->ctype == OCELL && n->csub == CTEMP)
153*7c478bd9Sstevel@tonic-gate#define	isfld(n)	(!donefld && n->csub==CFLD && n->ctype==OCELL && \
154*7c478bd9Sstevel@tonic-gate				n->nval==0)
155*7c478bd9Sstevel@tonic-gate#define	isrec(n)	(donefld && n->csub==CFLD && n->ctype==OCELL && \
156*7c478bd9Sstevel@tonic-gate				n->nval!=0)
157*7c478bd9Sstevel@tonic-gateextern CELL	*nullproc();
158*7c478bd9Sstevel@tonic-gateextern CELL	*relop();
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate#define	MAXSYM	50
161*7c478bd9Sstevel@tonic-gate#define	HAT	0177	/* matches ^ in regular expr */
162*7c478bd9Sstevel@tonic-gate			/* watch out for mach dep */
163*7c478bd9Sstevel@tonic-gate/*
164*7c478bd9Sstevel@tonic-gate * The code set number can be knew from actual character, but "b.c"
165*7c478bd9Sstevel@tonic-gate * will use some pseudo codes.  And that psedo code will not confirm
166*7c478bd9Sstevel@tonic-gate * to rule of real code set.
167*7c478bd9Sstevel@tonic-gate */
168*7c478bd9Sstevel@tonic-gatetypedef struct  ccl_chars {
169*7c478bd9Sstevel@tonic-gate	unsigned short  cc_ns;   /* Code set Number */
170*7c478bd9Sstevel@tonic-gate	wchar_t  cc_cs;   /* Actual character */
171*7c478bd9Sstevel@tonic-gate	unsigned short  cc_ne;
172*7c478bd9Sstevel@tonic-gate	wchar_t  cc_ce;
173*7c478bd9Sstevel@tonic-gate} ccl_chars_t;
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gateccl_chars_t	*cclenter();
176