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