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