2 Copyright (c) Lucent Technologies 1997
7 typedef double Awkfloat;
9 #define xfree(a) { if ((a) != nil) { free((a)); (a) = nil; } }
13 /* uses have to be doubly parenthesized */
14 # define dprint(x) if (dbg) print x
19 #define FOPEN_MAX 40 /* max number of open files */
23 extern int compile_time; /* 1 if compiling, 0 if running */
24 extern int safe; /* 0 => unsafe, 1 => safe */
26 #define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */
27 extern int recsize; /* size of current record, orig RECSIZE */
41 extern char **FILENAME;
43 extern Awkfloat *RSTART;
44 extern Awkfloat *RLENGTH;
46 extern char *record; /* points to $0 */
47 extern int lineno; /* line number in awk program */
48 extern char *exitstatus; /* exit status string */
49 extern int donefld; /* 1 if record broken into fields */
50 extern int donerec; /* 1 if record is valid (no fld has changed */
51 extern char inputFS[]; /* FS at time of input, for field splitting */
55 extern char *patbeg; /* beginning of pattern matched */
56 extern int patlen; /* length of pattern matched. set in b.c */
58 /* Cell: all information about a variable or constant */
61 uchar ctype; /* OCELL, OBOOL, OJUMP, etc. */
62 uchar csub; /* CCON, CTEMP, CFLD, etc. */
63 char *nval; /* name, for variables only */
64 char *sval; /* string value */
65 Awkfloat fval; /* value as number */
66 int tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
67 struct Cell *cnext; /* ptr to next if chained */
70 typedef struct Array { /* symbol table array */
71 int nelemt; /* elements in table right now */
72 int size; /* size of tab */
73 Cell **tab; /* hash table pointers */
76 #define NSYMTAB 50 /* initial size of a symbol table */
79 extern Cell *nrloc; /* NR */
80 extern Cell *fnrloc; /* FNR */
81 extern Cell *nfloc; /* NF */
82 extern Cell *rstartloc; /* RSTART */
83 extern Cell *rlengthloc; /* RLENGTH */
85 /* Cell.tval values: */
86 #define NUM 01 /* number value is valid */
87 #define STR 02 /* string value is valid */
88 #define DONTFREE 04 /* string space is not freeable */
89 #define CON 010 /* this is a constant */
90 #define ARR 020 /* this is an array */
91 #define FCN 040 /* this is a function name */
92 #define FLD 0100 /* this is a field $1, $2, ... */
93 #define REC 0200 /* this is $0 */
113 /* Node: parse tree is made of nodes, with Cell's at bottom */
115 typedef struct Node {
120 struct Node *narg[1]; /* variable: actual size set by calling malloc */
123 #define NIL ((Node *) 0)
126 extern Node *nullstat;
127 extern Node *nullnode;
134 /* Cell subtypes: csub */
162 extern int pairstack[], paircnt;
164 #define notlegal(n) (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc)
165 #define isvalue(n) ((n)->ntype == NVALUE)
166 #define isexpr(n) ((n)->ntype == NEXPR)
167 #define isjump(n) ((n)->ctype == OJUMP)
168 #define isexit(n) ((n)->csub == JEXIT)
169 #define isbreak(n) ((n)->csub == JBREAK)
170 #define iscont(n) ((n)->csub == JCONT)
171 #define isnext(n) ((n)->csub == JNEXT)
172 #define isnextfile(n) ((n)->csub == JNEXTFILE)
173 #define isret(n) ((n)->csub == JRET)
174 #define isrec(n) ((n)->tval & REC)
175 #define isfld(n) ((n)->tval & FLD)
176 #define isstr(n) ((n)->tval & STR)
177 #define isnum(n) ((n)->tval & NUM)
178 #define isarr(n) ((n)->tval & ARR)
179 #define isfcn(n) ((n)->tval & FCN)
180 #define istrue(n) ((n)->csub == BTRUE)
181 #define istemp(n) ((n)->csub == CTEMP)
182 #define isargument(n) ((n)->nobj == ARG)
183 /* #define freeable(p) (!((p)->tval & DONTFREE)) */
184 #define freeable(p) ( ((p)->tval & (STR|DONTFREE)) == STR )