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