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