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