1 /* $OpenBSD: awk.h,v 1.10 2002/12/19 21:24:28 millert Exp $ */ 2 /**************************************************************** 3 Copyright (C) Lucent Technologies 1997 4 All Rights Reserved 5 6 Permission to use, copy, modify, and distribute this software and 7 its documentation for any purpose and without fee is hereby 8 granted, provided that the above copyright notice appear in all 9 copies and that both that the copyright notice and this 10 permission notice and warranty disclaimer appear in supporting 11 documentation, and that the name Lucent Technologies or any of 12 its entities not be used in advertising or publicity pertaining 13 to distribution of the software without specific, written prior 14 permission. 15 16 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 17 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 18 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 19 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 21 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 23 THIS SOFTWARE. 24 ****************************************************************/ 25 26 typedef double Awkfloat; 27 28 /* unsigned char is more trouble than it's worth */ 29 30 typedef unsigned char uschar; 31 32 #define xfree(a) { if ((a) != NULL) { free((char *) a); a = NULL; } } 33 34 #define NN(p) ((p) ? (p) : "(null)") /* guaranteed non-null for dprintf 35 */ 36 #define DEBUG 37 #ifdef DEBUG 38 /* uses have to be doubly parenthesized */ 39 # define dprintf(x) if (dbg) printf x 40 #else 41 # define dprintf(x) 42 #endif 43 44 extern int compile_time; /* 1 if compiling, 0 if running */ 45 extern int safe; /* 0 => unsafe, 1 => safe */ 46 47 #define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */ 48 extern int recsize; /* size of current record, orig RECSIZE */ 49 50 extern char **FS; 51 extern char **RS; 52 extern char **ORS; 53 extern char **OFS; 54 extern char **OFMT; 55 extern Awkfloat *NR; 56 extern Awkfloat *FNR; 57 extern Awkfloat *NF; 58 extern char **FILENAME; 59 extern char **SUBSEP; 60 extern Awkfloat *RSTART; 61 extern Awkfloat *RLENGTH; 62 63 extern char *record; /* points to $0 */ 64 extern int lineno; /* line number in awk program */ 65 extern int errorflag; /* 1 if error has occurred */ 66 extern int donefld; /* 1 if record broken into fields */ 67 extern int donerec; /* 1 if record is valid (no fld has changed */ 68 extern char inputFS[]; /* FS at time of input, for field splitting */ 69 70 extern int dbg; 71 72 extern char *patbeg; /* beginning of pattern matched */ 73 extern int patlen; /* length of pattern matched. set in b.c */ 74 75 /* Cell: all information about a variable or constant */ 76 77 typedef struct Cell { 78 uschar ctype; /* OCELL, OBOOL, OJUMP, etc. */ 79 uschar csub; /* CCON, CTEMP, CFLD, etc. */ 80 char *nval; /* name, for variables only */ 81 char *sval; /* string value */ 82 Awkfloat fval; /* value as number */ 83 int tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */ 84 struct Cell *cnext; /* ptr to next if chained */ 85 } Cell; 86 87 typedef struct Array { /* symbol table array */ 88 int nelem; /* elements in table right now */ 89 int size; /* size of tab */ 90 Cell **tab; /* hash table pointers */ 91 } Array; 92 93 #define NSYMTAB 50 /* initial size of a symbol table */ 94 extern Array *symtab; 95 96 extern Cell *nrloc; /* NR */ 97 extern Cell *fnrloc; /* FNR */ 98 extern Cell *nfloc; /* NF */ 99 extern Cell *rstartloc; /* RSTART */ 100 extern Cell *rlengthloc; /* RLENGTH */ 101 102 /* Cell.tval values: */ 103 #define NUM 01 /* number value is valid */ 104 #define STR 02 /* string value is valid */ 105 #define DONTFREE 04 /* string space is not freeable */ 106 #define CON 010 /* this is a constant */ 107 #define ARR 020 /* this is an array */ 108 #define FCN 040 /* this is a function name */ 109 #define FLD 0100 /* this is a field $1, $2, ... */ 110 #define REC 0200 /* this is $0 */ 111 112 113 /* function types */ 114 #define FLENGTH 1 115 #define FSQRT 2 116 #define FEXP 3 117 #define FLOG 4 118 #define FINT 5 119 #define FSYSTEM 6 120 #define FRAND 7 121 #define FSRAND 8 122 #define FSIN 9 123 #define FCOS 10 124 #define FATAN 11 125 #define FTOUPPER 12 126 #define FTOLOWER 13 127 #define FFLUSH 14 128 129 /* Node: parse tree is made of nodes, with Cell's at bottom */ 130 131 typedef struct Node { 132 int ntype; 133 struct Node *nnext; 134 int lineno; 135 int nobj; 136 struct Node *narg[1]; /* variable: actual size set by calling malloc */ 137 } Node; 138 139 #define NIL ((Node *) 0) 140 141 extern Node *winner; 142 extern Node *nullstat; 143 extern Node *nullnode; 144 145 /* ctypes */ 146 #define OCELL 1 147 #define OBOOL 2 148 #define OJUMP 3 149 150 /* Cell subtypes: csub */ 151 #define CFREE 7 152 #define CCOPY 6 153 #define CCON 5 154 #define CTEMP 4 155 #define CNAME 3 156 #define CVAR 2 157 #define CFLD 1 158 #define CUNK 0 159 160 /* bool subtypes */ 161 #define BTRUE 11 162 #define BFALSE 12 163 164 /* jump subtypes */ 165 #define JEXIT 21 166 #define JNEXT 22 167 #define JBREAK 23 168 #define JCONT 24 169 #define JRET 25 170 #define JNEXTFILE 26 171 172 /* node types */ 173 #define NVALUE 1 174 #define NSTAT 2 175 #define NEXPR 3 176 177 178 extern int pairstack[], paircnt; 179 180 #define notlegal(n) (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc) 181 #define isvalue(n) ((n)->ntype == NVALUE) 182 #define isexpr(n) ((n)->ntype == NEXPR) 183 #define isjump(n) ((n)->ctype == OJUMP) 184 #define isexit(n) ((n)->csub == JEXIT) 185 #define isbreak(n) ((n)->csub == JBREAK) 186 #define iscont(n) ((n)->csub == JCONT) 187 #define isnext(n) ((n)->csub == JNEXT || (n)->csub == JNEXTFILE) 188 #define isret(n) ((n)->csub == JRET) 189 #define isrec(n) ((n)->tval & REC) 190 #define isfld(n) ((n)->tval & FLD) 191 #define isstr(n) ((n)->tval & STR) 192 #define isnum(n) ((n)->tval & NUM) 193 #define isarr(n) ((n)->tval & ARR) 194 #define isfcn(n) ((n)->tval & FCN) 195 #define istrue(n) ((n)->csub == BTRUE) 196 #define istemp(n) ((n)->csub == CTEMP) 197 #define isargument(n) ((n)->nobj == ARG) 198 /* #define freeable(p) (!((p)->tval & DONTFREE)) */ 199 #define freeable(p) ( ((p)->tval & (STR|DONTFREE)) == STR ) 200 201 /* structures used by regular expression matching machinery, mostly b.c: */ 202 203 #define NCHARS (256+1) /* 256 handles 8-bit chars; 128 does 7-bit */ 204 /* watch out in match(), etc. */ 205 #define NSTATES 32 206 207 typedef struct rrow { 208 long ltype; /* long avoids pointer warnings on 64-bit */ 209 union { 210 int i; 211 Node *np; 212 uschar *up; 213 } lval; /* because Al stores a pointer in it! */ 214 int *lfollow; 215 } rrow; 216 217 typedef struct fa { 218 uschar gototab[NSTATES][NCHARS]; 219 uschar out[NSTATES]; 220 uschar *restr; 221 int *posns[NSTATES]; 222 int anchor; 223 int use; 224 int initstat; 225 int curstat; 226 int accept; 227 int reset; 228 struct rrow re[1]; /* variable: actual size set by calling malloc */ 229 } fa; 230 231 232 #include "proto.h" 233