/* #ident	"@(#)awk:awk.def	1.3" */
#ident	"$Header: /proj/irix6.5.7m/isms/eoe/cmd/pawk/RCS/awk.def,v 1.1 1997/04/28 19:40:18 pcr Exp $"
#define	xfree(a)	{ if(a!=NULL) { yfree(a); a=NULL;} }
#define yfree free
#ifdef	DEBUG
#	define	dprintf	if(dbg)printf
#else
#	define	dprintf(x1, x2, x3, x4)
#endif
typedef double	awkfloat;

extern char	**FS;
extern char	**RS;
extern char	**ORS;
extern char	**OFS;
extern char	**OFMT;
extern awkfloat *NR;
extern awkfloat *NF;
extern char	**FILENAME;

extern char	*record;
extern int	dbg;
extern int	lineno;
extern int	errorflag;
extern int	donefld;	/* 1 if record broken into fields */
extern int	donerec;	/* 1 if record is valid (no fld has changed */

/* CELL:  all information about a variable or constant */

typedef struct val {
	char	ctype;		/* CELL, BOOL, JUMP, etc. */
	char	csub;		/* subtype of ctype */
	char	*nval;		/* name, for variables only */
	char	*sval;		/* string value */
	awkfloat fval;		/* value as number */
	unsigned tval;		/* type info */
	struct val *nextval;	/* ptr to next if chained */
} CELL;

extern CELL	*symtab[];
extern CELL	*setsymtab(), *lookup(), **makesymtab();

extern CELL	*recloc;	/* location of input record */
extern CELL	*nrloc;		/* NR */
extern CELL	*nfloc;		/* NF */

/* CELL.tval values: */
#define	STR	01	/* string value is valid */
#define	NUM	02	/* number value is valid */
#define FLD	04	/* FLD means don't free string space */
#define	CON	010	/* this is a constant */
#define	ARR	020	/* this is an array */

awkfloat	setfval(), getfval();
char		*setsval(), *getsval();
char	*tostring(), *tokname(), *malloc();
double	log(), sqrt(), exp(), atof();

/* function types */
#define	FLENGTH	1
#define	FSQRT	2
#define	FEXP	3
#define	FLOG	4
#define	FINT	5

#define BOTCH	1
typedef struct nd {
	char	ntype;
	char	subtype;
	struct nd *nnext;
	int	nobj;
	struct nd *narg[BOTCH];	/* C won't take a zero length array */
} NODE;

extern NODE	*winner;
extern NODE	*nullstat;

/* ctypes */
#define OCELL	1
#define OBOOL	2
#define OJUMP	3

/* CELL subtypes */
#define CCON	5
#define CTEMP	4
#define CNAME	3 
#define CVAR	2
#define CFLD	1

/* bool subtypes */
#define BTRUE	1
#define BFALSE	2

/* jump subtypes */
#define JEXIT	1
#define JNEXT	2
#define	JBREAK	3
#define	JCONT	4

/* node types */
#define NVALUE	1
#define NSTAT	2
#define NEXPR	3

extern CELL	*(*proctab[])();
extern int	pairstack[], paircnt;

#define cantexec(n)	(n->ntype == NVALUE)
#define notlegal(n)	(n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN]== nullproc)
#define isexpr(n)	(n->ntype == NEXPR)
#define isjump(n)	(n->ctype == OJUMP)
#define isexit(n)	(n->ctype == OJUMP && n->csub == JEXIT)
#define	isbreak(n)	(n->ctype == OJUMP && n->csub == JBREAK)
#define	iscont(n)	(n->ctype == OJUMP && n->csub == JCONT)
#define	isnext(n)	(n->ctype == OJUMP && n->csub == JNEXT)
#define isstr(n)	(n->tval & STR)
#define isnum(n)	(n->tval & NUM)
#define istrue(n)	(n->ctype == OBOOL && n->csub == BTRUE)
#define istemp(n)	(n->ctype == OCELL && n->csub == CTEMP)
#define isfld(n)	(!donefld && n->csub==CFLD && n->ctype==OCELL && n->nval==0)
#define isrec(n)	(donefld && n->csub==CFLD && n->ctype==OCELL && n->nval!=0)
extern CELL	*nullproc();
extern CELL	*relop();

#define MAXSYM	50
#define	HAT	0177	/* matches ^ in regular expr */
			/* watch out for mach dep */
#define MAKE_SVAL(s)	((s) ? (s) : tostring(""))	/* Prevent NULL sval */
