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