xref: /original-bsd/old/awk/awk.def (revision e59fb703)
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 *
7 *	@(#)awk.def	4.6 (Berkeley) 04/27/91
8 */
9
10#include <stdlib.h>
11
12#define hack	int
13#define	AWKFLOAT	float
14#define	xfree(a)	{ if(a!=NULL) { yfree(a); a=NULL;} }
15#define	strfree(a)	{ if(a!=NULL && a!=EMPTY) { yfree(a);} a=EMPTY; }
16#define yfree free
17#define	isnull(x)	((x) == EMPTY || (x) == NULL)
18
19#ifdef	DEBUG
20#	define	dprintf	if(dbg)printf
21#else
22#	define	dprintf(x1, x2, x3, x4)
23#endif
24typedef	AWKFLOAT	awkfloat;
25
26extern char	**FS;
27extern char	**RS;
28extern char	**ORS;
29extern char	**OFS;
30extern char	**OFMT;
31extern awkfloat *NR;
32extern awkfloat *NF;
33extern char	**FILENAME;
34
35extern char	record[];
36extern char	EMPTY[];
37extern int	dbg;
38extern int	lineno;
39extern int	errorflag;
40extern int	donefld;	/* 1 if record broken into fields */
41extern int	donerec;	/* 1 if record is valid (no fld has changed */
42
43typedef struct val {	/* general value during processing */
44	char	*nval;	/* name, for variables only */
45	char	*sval;	/* string value */
46	awkfloat	fval;	/* value as number */
47	unsigned	tval;	/* type info */
48	struct val	*nextval;	/* ptr to next if chained */
49} cell;
50extern cell *symtab[];
51cell	*setsymtab(), *lookup(), **makesymtab();
52
53extern cell	*recloc;	/* location of input record */
54extern cell	*nrloc;		/* NR */
55extern cell	*nfloc;		/* NF */
56
57#define	STR	01	/* string value is valid */
58#define	NUM	02	/* number value is valid */
59#define FLD	04	/* FLD means don't free string space */
60#define	CON	010	/* this is a constant */
61#define	ARR	020	/* this is an array */
62
63awkfloat setfval(), getfval();
64char	*setsval(), *getsval();
65char	*tostring(), *tokname();
66double	log(), sqrt(), exp(), atof();
67
68/* function types */
69#define	FLENGTH	1
70#define	FSQRT	2
71#define	FEXP	3
72#define	FLOG	4
73#define	FINT	5
74
75typedef struct {
76	char otype;
77	char osub;
78	cell *optr;
79} obj;
80
81#define BOTCH	1
82struct nd {
83	char ntype;
84	char subtype;
85	struct nd *nnext;
86	int nobj;
87	struct nd *narg[BOTCH];	/* C won't take a zero length array */
88};
89typedef struct nd node;
90extern node	*winner;
91extern node	*nullstat;
92
93/* otypes */
94#define OCELL	0
95#define OEXPR	1
96#define OBOOL	2
97#define OJUMP	3
98
99/* cell subtypes */
100#define CTEMP	4
101#define CNAME	3
102#define CVAR	2
103#define CFLD	1
104#define CCON	0
105
106/* bool subtypes */
107#define BTRUE	1
108#define BFALSE	2
109
110/* jump subtypes */
111#define JEXIT	1
112#define JNEXT	2
113#define	JBREAK	3
114#define	JCONT	4
115
116/* node types */
117#define NVALUE	1
118#define NSTAT	2
119#define NEXPR	3
120#define NPA2	4
121
122extern obj	(*proctab[])();
123extern obj	true, false;
124extern int	pairstack[], paircnt;
125
126#define cantexec(n)	(n->ntype == NVALUE)
127#define notlegal(n)	(n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN]== nullproc)
128#define isexpr(n)	(n->ntype == NEXPR)
129#define isjump(n)	(n.otype == OJUMP)
130#define isexit(n)	(n.otype == OJUMP && n.osub == JEXIT)
131#define	isbreak(n)	(n.otype == OJUMP && n.osub == JBREAK)
132#define	iscont(n)	(n.otype == OJUMP && n.osub == JCONT)
133#define	isnext(n)	(n.otype == OJUMP && n.osub == JNEXT)
134#define isstr(n)	(n.optr->tval & STR)
135#define istrue(n)	(n.otype == OBOOL && n.osub == BTRUE)
136#define istemp(n)	(n.otype == OCELL && n.osub == CTEMP)
137#define isfld(n)	(!donefld && n.osub==CFLD && n.otype==OCELL && n.optr->nval==EMPTY)
138#define isrec(n)	(donefld && n.osub==CFLD && n.otype==OCELL && n.optr->nval!=EMPTY)
139obj	nullproc();
140obj	relop();
141
142#define MAXSYM	50
143#define	HAT	0177	/* matches ^ in regular expr */
144			/* watch out for mach dep */
145