1 /* 2 Copyright (c) 1989 AT&T 3 All Rights Reserved 4 5 THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T. 6 7 The copyright notice above does not evidence any 8 actual or intended publication of such source code. 9 */ 10 11 typedef double Awkfloat; 12 typedef /*unsigned*/ char uchar; 13 14 #define xfree(a) { if ((a) != NULL) { free((char *) a); a = NULL; } } 15 16 #define DEBUG 17 #ifdef DEBUG 18 /* uses have to be doubly parenthesized */ 19 # define dprintf(x) if (dbg) printf x 20 #else 21 # define dprintf(x) 22 #endif 23 24 extern char errbuf[200]; 25 #define ERROR sprintf(errbuf, 26 #define FATAL ), error(1, errbuf) 27 #define WARNING ), error(0, errbuf) 28 #define SYNTAX ), yyerror(errbuf) 29 30 extern int compile_time; /* 1 if compiling, 0 if running */ 31 32 #define RECSIZE (3 * 1024) /* sets limit on records, fields, etc., etc. */ 33 extern int recsize; /* variable version */ 34 35 extern uchar **FS; 36 extern uchar **RS; 37 extern uchar **ORS; 38 extern uchar **OFS; 39 extern uchar **OFMT; 40 extern Awkfloat *NR; 41 extern Awkfloat *FNR; 42 extern Awkfloat *NF; 43 extern uchar **FILENAME; 44 extern uchar **SUBSEP; 45 extern Awkfloat *RSTART; 46 extern Awkfloat *RLENGTH; 47 48 extern uchar *record; /* points to $0 */ 49 extern int lineno; /* line number in awk program */ 50 extern int errorflag; /* 1 if error has occurred */ 51 extern int donefld; /* 1 if record broken into fields */ 52 extern int donerec; /* 1 if record is valid (no fld has changed */ 53 54 extern int dbg; 55 56 #define CBUFLEN 400 57 extern uchar cbuf[CBUFLEN]; /* miscellaneous character collection */ 58 59 extern uchar *patbeg; /* beginning of pattern matched */ 60 extern int patlen; /* length of pattern matched. set in b.c */ 61 62 /* Cell: all information about a variable or constant */ 63 64 typedef struct Cell { 65 uchar ctype; /* OCELL, OBOOL, OJUMP, etc. */ 66 uchar csub; /* CCON, CTEMP, CFLD, etc. */ 67 uchar *nval; /* name, for variables only */ 68 uchar *sval; /* string value */ 69 Awkfloat fval; /* value as number */ 70 unsigned tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */ 71 struct Cell *cnext; /* ptr to next if chained */ 72 } Cell; 73 74 typedef struct { /* symbol table array */ 75 int nelem; /* elements in table right now */ 76 int size; /* size of tab */ 77 Cell **tab; /* hash table pointers */ 78 } Array; 79 80 #define NSYMTAB 50 /* initial size of a symbol table */ 81 extern Array *symtab; 82 83 extern Cell *recloc; /* location of input record */ 84 extern Cell *nrloc; /* NR */ 85 extern Cell *fnrloc; /* FNR */ 86 extern Cell *nfloc; /* NF */ 87 extern Cell *rstartloc; /* RSTART */ 88 extern Cell *rlengthloc; /* RLENGTH */ 89 90 /* Cell.tval values: */ 91 #define NUM 01 /* number value is valid */ 92 #define STR 02 /* string value is valid */ 93 #define DONTFREE 04 /* string space is not freeable */ 94 #define CON 010 /* this is a constant */ 95 #define ARR 020 /* this is an array */ 96 #define FCN 040 /* this is a function name */ 97 #define FLD 0100 /* this is a field $1, $2, ... */ 98 #define REC 0200 /* this is $0 */ 99 100 101 /* function types */ 102 #define FLENGTH 1 103 #define FSQRT 2 104 #define FEXP 3 105 #define FLOG 4 106 #define FINT 5 107 #define FSYSTEM 6 108 #define FRAND 7 109 #define FSRAND 8 110 #define FSIN 9 111 #define FCOS 10 112 #define FATAN 11 113 #define FTOUPPER 12 114 #define FTOLOWER 13 115 #define FFLUSH 14 116 #define FUTF 15 117 118 /* Node: parse tree is made of nodes, with Cell's at bottom */ 119 120 typedef struct Node { 121 int ntype; 122 struct Node *nnext; 123 int lineno; 124 int nobj; 125 struct Node *narg[1]; /* variable: actual size set by calling malloc */ 126 } Node; 127 128 #define NIL ((Node *) 0) 129 130 extern Node *winner; 131 extern Node *nullstat; 132 extern Node *nullnode; 133 134 /* ctypes */ 135 #define OCELL 1 136 #define OBOOL 2 137 #define OJUMP 3 138 139 /* Cell subtypes: csub */ 140 #define CFREE 7 141 #define CCOPY 6 142 #define CCON 5 143 #define CTEMP 4 144 #define CNAME 3 145 #define CVAR 2 146 #define CFLD 1 147 148 /* bool subtypes */ 149 #define BTRUE 11 150 #define BFALSE 12 151 152 /* jump subtypes */ 153 #define JEXIT 21 154 #define JNEXT 22 155 #define JBREAK 23 156 #define JCONT 24 157 #define JRET 25 158 159 /* node types */ 160 #define NVALUE 1 161 #define NSTAT 2 162 #define NEXPR 3 163 #define NFIELD 4 164 165 166 extern int pairstack[], paircnt; 167 168 #define notlegal(n) (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc) 169 #define isvalue(n) ((n)->ntype == NVALUE) 170 #define isexpr(n) ((n)->ntype == NEXPR) 171 #define isjump(n) ((n)->ctype == OJUMP) 172 #define isexit(n) ((n)->csub == JEXIT) 173 #define isbreak(n) ((n)->csub == JBREAK) 174 #define iscont(n) ((n)->csub == JCONT) 175 #define isnext(n) ((n)->csub == JNEXT) 176 #define isret(n) ((n)->csub == JRET) 177 #define isstr(n) ((n)->tval & STR) 178 #define isnum(n) ((n)->tval & NUM) 179 #define isarr(n) ((n)->tval & ARR) 180 #define isfunc(n) ((n)->tval & FCN) 181 #define istrue(n) ((n)->csub == BTRUE) 182 #define istemp(n) ((n)->csub == CTEMP) 183 #define isargument(n) ((n)->nobj == ARG) 184 #define freeable(p) (!((p)->tval & DONTFREE)) 185 186 #include "proto.h" 187