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