xref: /csrg-svn/old/awk/awk.def (revision 48780)
148236Sbostic/*-
248236Sbostic * Copyright (c) 1991 The Regents of the University of California.
348236Sbostic * All rights reserved.
448236Sbostic *
548236Sbostic * %sccs.include.proprietary.c%
6*48780Sbostic *
7*48780Sbostic *	@(#)awk.def	4.6 (Berkeley) 04/27/91
848236Sbostic */
96666Smckusick
1046268Storek#include <stdlib.h>
1146268Storek
126666Smckusick#define hack	int
136666Smckusick#define	AWKFLOAT	float
146666Smckusick#define	xfree(a)	{ if(a!=NULL) { yfree(a); a=NULL;} }
1510794Ssam#define	strfree(a)	{ if(a!=NULL && a!=EMPTY) { yfree(a);} a=EMPTY; }
166666Smckusick#define yfree free
1715691Sralph#define	isnull(x)	((x) == EMPTY || (x) == NULL)
1815691Sralph
196666Smckusick#ifdef	DEBUG
206666Smckusick#	define	dprintf	if(dbg)printf
216666Smckusick#else
226666Smckusick#	define	dprintf(x1, x2, x3, x4)
236666Smckusick#endif
246666Smckusicktypedef	AWKFLOAT	awkfloat;
256666Smckusick
266666Smckusickextern char	**FS;
276666Smckusickextern char	**RS;
286666Smckusickextern char	**ORS;
296666Smckusickextern char	**OFS;
306666Smckusickextern char	**OFMT;
316666Smckusickextern awkfloat *NR;
326666Smckusickextern awkfloat *NF;
336666Smckusickextern char	**FILENAME;
346666Smckusick
356666Smckusickextern char	record[];
3610794Ssamextern char	EMPTY[];
376666Smckusickextern int	dbg;
386666Smckusickextern int	lineno;
396666Smckusickextern int	errorflag;
406666Smckusickextern int	donefld;	/* 1 if record broken into fields */
416666Smckusickextern int	donerec;	/* 1 if record is valid (no fld has changed */
426666Smckusick
436666Smckusicktypedef struct val {	/* general value during processing */
446666Smckusick	char	*nval;	/* name, for variables only */
456666Smckusick	char	*sval;	/* string value */
466666Smckusick	awkfloat	fval;	/* value as number */
476666Smckusick	unsigned	tval;	/* type info */
486666Smckusick	struct val	*nextval;	/* ptr to next if chained */
496666Smckusick} cell;
506666Smckusickextern cell *symtab[];
516666Smckusickcell	*setsymtab(), *lookup(), **makesymtab();
526666Smckusick
536666Smckusickextern cell	*recloc;	/* location of input record */
546666Smckusickextern cell	*nrloc;		/* NR */
556666Smckusickextern cell	*nfloc;		/* NF */
566666Smckusick
576666Smckusick#define	STR	01	/* string value is valid */
586666Smckusick#define	NUM	02	/* number value is valid */
596666Smckusick#define FLD	04	/* FLD means don't free string space */
606666Smckusick#define	CON	010	/* this is a constant */
616666Smckusick#define	ARR	020	/* this is an array */
626666Smckusick
636666Smckusickawkfloat setfval(), getfval();
646666Smckusickchar	*setsval(), *getsval();
6546268Storekchar	*tostring(), *tokname();
666666Smckusickdouble	log(), sqrt(), exp(), atof();
676666Smckusick
686666Smckusick/* function types */
696666Smckusick#define	FLENGTH	1
706666Smckusick#define	FSQRT	2
716666Smckusick#define	FEXP	3
726666Smckusick#define	FLOG	4
736666Smckusick#define	FINT	5
746666Smckusick
756666Smckusicktypedef struct {
766666Smckusick	char otype;
776666Smckusick	char osub;
786666Smckusick	cell *optr;
796666Smckusick} obj;
806666Smckusick
816666Smckusick#define BOTCH	1
826666Smckusickstruct nd {
836666Smckusick	char ntype;
846666Smckusick	char subtype;
856666Smckusick	struct nd *nnext;
866666Smckusick	int nobj;
876666Smckusick	struct nd *narg[BOTCH];	/* C won't take a zero length array */
886666Smckusick};
896666Smckusicktypedef struct nd node;
906666Smckusickextern node	*winner;
916666Smckusickextern node	*nullstat;
926666Smckusick
936666Smckusick/* otypes */
946666Smckusick#define OCELL	0
956666Smckusick#define OEXPR	1
966666Smckusick#define OBOOL	2
976666Smckusick#define OJUMP	3
986666Smckusick
996666Smckusick/* cell subtypes */
1006666Smckusick#define CTEMP	4
1016666Smckusick#define CNAME	3
1026666Smckusick#define CVAR	2
1036666Smckusick#define CFLD	1
1046666Smckusick#define CCON	0
1056666Smckusick
1066666Smckusick/* bool subtypes */
1076666Smckusick#define BTRUE	1
1086666Smckusick#define BFALSE	2
1096666Smckusick
1106666Smckusick/* jump subtypes */
1116666Smckusick#define JEXIT	1
1126666Smckusick#define JNEXT	2
1136666Smckusick#define	JBREAK	3
1146666Smckusick#define	JCONT	4
1156666Smckusick
1166666Smckusick/* node types */
1176666Smckusick#define NVALUE	1
1186666Smckusick#define NSTAT	2
1196666Smckusick#define NEXPR	3
1206666Smckusick#define NPA2	4
1216666Smckusick
1226666Smckusickextern obj	(*proctab[])();
1236666Smckusickextern obj	true, false;
1246666Smckusickextern int	pairstack[], paircnt;
1256666Smckusick
1266666Smckusick#define cantexec(n)	(n->ntype == NVALUE)
1276666Smckusick#define notlegal(n)	(n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN]== nullproc)
1286666Smckusick#define isexpr(n)	(n->ntype == NEXPR)
1296666Smckusick#define isjump(n)	(n.otype == OJUMP)
1306666Smckusick#define isexit(n)	(n.otype == OJUMP && n.osub == JEXIT)
1316666Smckusick#define	isbreak(n)	(n.otype == OJUMP && n.osub == JBREAK)
1326666Smckusick#define	iscont(n)	(n.otype == OJUMP && n.osub == JCONT)
1336666Smckusick#define	isnext(n)	(n.otype == OJUMP && n.osub == JNEXT)
1346666Smckusick#define isstr(n)	(n.optr->tval & STR)
1356666Smckusick#define istrue(n)	(n.otype == OBOOL && n.osub == BTRUE)
1366666Smckusick#define istemp(n)	(n.otype == OCELL && n.osub == CTEMP)
13710794Ssam#define isfld(n)	(!donefld && n.osub==CFLD && n.otype==OCELL && n.optr->nval==EMPTY)
13810794Ssam#define isrec(n)	(donefld && n.osub==CFLD && n.otype==OCELL && n.optr->nval!=EMPTY)
1396666Smckusickobj	nullproc();
1406666Smckusickobj	relop();
1416666Smckusick
1426666Smckusick#define MAXSYM	50
1436666Smckusick#define	HAT	0177	/* matches ^ in regular expr */
1446666Smckusick			/* watch out for mach dep */
145