Annotation of src/usr.bin/awk/awk.h, Revision 1.9
1.9 ! millert 1: /* $OpenBSD: awk.h,v 1.8 1999/12/08 23:09:45 millert Exp $ */
1.1 tholo 2: /****************************************************************
1.5 kstailey 3: Copyright (C) Lucent Technologies 1997
1.1 tholo 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
1.5 kstailey 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.
1.1 tholo 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 */
1.5 kstailey 43: extern int safe; /* 0 => unsafe, 1 => safe */
1.1 tholo 44:
1.5 kstailey 45: #define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */
46: extern int recsize; /* size of current record, orig RECSIZE */
1.1 tholo 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 */
1.2 millert 66: extern char inputFS[]; /* FS at time of input, for field splitting */
1.1 tholo 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 */
1.6 millert 81: int tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
1.1 tholo 82: struct Cell *cnext; /* ptr to next if chained */
83: } Cell;
84:
1.5 kstailey 85: typedef struct Array { /* symbol table array */
1.1 tholo 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;
1.6 millert 134: struct Node *narg[1]; /* variable: actual size set by calling malloc */
1.1 tholo 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:
1.4 millert 176: extern int pairstack[], paircnt;
1.1 tholo 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)
1.9 ! millert 185: #define isnext(n) ((n)->csub == JNEXT || (n)->csub == JNEXTFILE)
1.1 tholo 186: #define isret(n) ((n)->csub == JRET)
1.5 kstailey 187: #define isrec(n) ((n)->tval & REC)
188: #define isfld(n) ((n)->tval & FLD)
1.1 tholo 189: #define isstr(n) ((n)->tval & STR)
190: #define isnum(n) ((n)->tval & NUM)
191: #define isarr(n) ((n)->tval & ARR)
1.5 kstailey 192: #define isfcn(n) ((n)->tval & FCN)
1.1 tholo 193: #define istrue(n) ((n)->csub == BTRUE)
194: #define istemp(n) ((n)->csub == CTEMP)
195: #define isargument(n) ((n)->nobj == ARG)
1.5 kstailey 196: /* #define freeable(p) (!((p)->tval & DONTFREE)) */
197: #define freeable(p) ( ((p)->tval & (STR|DONTFREE)) == STR )
1.1 tholo 198:
199: /* structures used by regular expression matching machinery, mostly b.c: */
200:
201: #define NCHARS (256+1) /* 256 handles 8-bit chars; 128 does 7-bit */
202: /* watch out in match(), etc. */
203: #define NSTATES 32
204:
205: typedef struct rrow {
1.6 millert 206: long ltype; /* long avoids pointer warnings on 64-bit */
1.1 tholo 207: union {
208: int i;
209: Node *np;
1.9 ! millert 210: uschar *up;
1.1 tholo 211: } lval; /* because Al stores a pointer in it! */
1.4 millert 212: int *lfollow;
1.1 tholo 213: } rrow;
214:
215: typedef struct fa {
1.6 millert 216: uschar gototab[NSTATES][NCHARS];
217: uschar out[NSTATES];
1.9 ! millert 218: uschar *restr;
1.6 millert 219: int *posns[NSTATES];
1.1 tholo 220: int anchor;
221: int use;
222: int initstat;
223: int curstat;
224: int accept;
225: int reset;
1.6 millert 226: struct rrow re[1]; /* variable: actual size set by calling malloc */
1.1 tholo 227: } fa;
228:
229:
230: #include "proto.h"