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