xref: /illumos-gate/usr/src/cmd/oawk/awk.def (revision e00bdde3c6d406f40f53f3025defadc22f7ec31a)
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
98typedef struct nd {
99	char	ntype;
100	char	subtype;
101	struct nd *nnext;
102	int	nobj;
103	struct nd *narg[];
104} NODE;
105
106extern NODE	*winner;
107
108/* ctypes */
109#define	OCELL	1
110#define	OBOOL	2
111#define	OJUMP	3
112
113/* CELL subtypes */
114#define	CCON	5
115#define	CTEMP	4
116#define	CNAME	3
117#define	CVAR	2
118#define	CFLD	1
119
120/* bool subtypes */
121#define	BTRUE	1
122#define	BFALSE	2
123
124/* jump subtypes */
125#define	JEXIT	1
126#define	JNEXT	2
127#define	JBREAK	3
128#define	JCONT	4
129
130/* node types */
131#define	NVALUE	1
132#define	NSTAT	2
133#define	NEXPR	3
134
135extern CELL	*(*proctab[])();
136extern int	pairstack[], paircnt;
137
138#define	cantexec(n)	(n->ntype == NVALUE)
139#define	notlegal(n)	(n <= FIRSTTOKEN || n >= LASTTOKEN || \
140				proctab[n-FIRSTTOKEN]== nullproc)
141#define	isexpr(n)	(n->ntype == NEXPR)
142#define	isjump(n)	(n->ctype == OJUMP)
143#define	isexit(n)	(n->ctype == OJUMP && n->csub == JEXIT)
144#define	isbreak(n)	(n->ctype == OJUMP && n->csub == JBREAK)
145#define	iscont(n)	(n->ctype == OJUMP && n->csub == JCONT)
146#define	isnext(n)	(n->ctype == OJUMP && n->csub == JNEXT)
147#define	isstr(n)	(n->tval & STR)
148#define	isnum(n)	(n->tval & NUM)
149#define	istrue(n)	(n->ctype == OBOOL && n->csub == BTRUE)
150#define	istemp(n)	(n->ctype == OCELL && n->csub == CTEMP)
151#define	isfld(n)	(!donefld && n->csub==CFLD && n->ctype==OCELL && \
152				n->nval==0)
153#define	isrec(n)	(donefld && n->csub==CFLD && n->ctype==OCELL && \
154				n->nval!=0)
155extern CELL	*nullproc();
156extern CELL	*relop();
157
158#define	MAXSYM	50
159#define	HAT	0177	/* matches ^ in regular expr */
160			/* watch out for mach dep */
161/*
162 * The code set number can be knew from actual character, but "b.c"
163 * will use some pseudo codes.  And that psedo code will not confirm
164 * to rule of real code set.
165 */
166typedef struct  ccl_chars {
167	unsigned short  cc_ns;   /* Code set Number */
168	wchar_t  cc_cs;   /* Actual character */
169	unsigned short  cc_ne;
170	wchar_t  cc_ce;
171} ccl_chars_t;
172
173ccl_chars_t	*cclenter();
174
175extern void error(int, char *, ...);
176