Fix markup. Fix backslashes to surive roff.
[netbsd-mini2440.git] / dist / nawk / awk.h
blob25297fbc7c4810df176cbf8505cde0941502528b
1 /****************************************************************
2 Copyright (C) Lucent Technologies 1997
3 All Rights Reserved
5 Permission to use, copy, modify, and distribute this software and
6 its documentation for any purpose and without fee is hereby
7 granted, provided that the above copyright notice appear in all
8 copies and that both that the copyright notice and this
9 permission notice and warranty disclaimer appear in supporting
10 documentation, and that the name Lucent Technologies or any of
11 its entities not be used in advertising or publicity pertaining
12 to distribution of the software without specific, written prior
13 permission.
15 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
17 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
18 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
22 THIS SOFTWARE.
23 ****************************************************************/
25 #include <assert.h>
27 typedef double Awkfloat;
29 /* unsigned char is more trouble than it's worth */
31 typedef unsigned char uschar;
33 #define xfree(a) { if ((a) != NULL) { free((void *) (a)); (a) = NULL; } }
35 #define NN(p) ((p) ? (p) : "(null)") /* guaranteed non-null for dprintf
37 #define DEBUG
38 #ifdef DEBUG
39 /* uses have to be doubly parenthesized */
40 # define dprintf(x) if (dbg) printf x
41 #else
42 # define dprintf(x)
43 #endif
45 extern int compile_time; /* 1 if compiling, 0 if running */
46 extern int safe; /* 0 => unsafe, 1 => safe */
48 #define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */
49 extern int recsize; /* size of current record, orig RECSIZE */
51 extern char **FS;
52 extern char **RS;
53 extern char **ORS;
54 extern char **OFS;
55 extern char **OFMT;
56 extern Awkfloat *NR;
57 extern Awkfloat *FNR;
58 extern Awkfloat *NF;
59 extern char **FILENAME;
60 extern char **SUBSEP;
61 extern Awkfloat *RSTART;
62 extern Awkfloat *RLENGTH;
64 extern uschar *record; /* points to $0 */
65 extern int lineno; /* line number in awk program */
66 extern int errorflag; /* 1 if error has occurred */
67 extern int donefld; /* 1 if record broken into fields */
68 extern int donerec; /* 1 if record is valid (no fld has changed */
70 extern int dbg;
72 extern uschar *patbeg; /* beginning of pattern matched */
73 extern int patlen; /* length of pattern matched. set in b.c */
75 /* Cell: all information about a variable or constant */
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;
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;
93 #define NSYMTAB 50 /* initial size of a symbol table */
94 extern Array *symtab;
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 */
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 */
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 #define FSYSTIME 15
129 #define FSTRFTIME 16
131 /* Node: parse tree is made of nodes, with Cell's at bottom */
133 typedef struct Node {
134 int ntype;
135 struct Node *nnext;
136 int lineno;
137 int nobj;
138 struct Node *narg[1]; /* variable: actual size set by calling malloc */
139 } Node;
141 #define NIL ((Node *) 0)
143 extern Node *winner;
144 extern Node *nullstat;
145 extern Node *nullnode;
147 /* ctypes */
148 #define OCELL 1
149 #define OBOOL 2
150 #define OJUMP 3
152 /* Cell subtypes: csub */
153 #define CFREE 7
154 #define CCOPY 6
155 #define CCON 5
156 #define CTEMP 4
157 #define CNAME 3
158 #define CVAR 2
159 #define CFLD 1
160 #define CUNK 0
162 /* bool subtypes */
163 #define BTRUE 11
164 #define BFALSE 12
166 /* jump subtypes */
167 #define JEXIT 21
168 #define JNEXT 22
169 #define JBREAK 23
170 #define JCONT 24
171 #define JRET 25
172 #define JNEXTFILE 26
174 /* node types */
175 #define NVALUE 1
176 #define NSTAT 2
177 #define NEXPR 3
180 extern int pairstack[], paircnt;
182 #define notlegal(n) (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc)
183 #define isvalue(n) ((n)->ntype == NVALUE)
184 #define isexpr(n) ((n)->ntype == NEXPR)
185 #define isjump(n) ((n)->ctype == OJUMP)
186 #define isexit(n) ((n)->csub == JEXIT)
187 #define isbreak(n) ((n)->csub == JBREAK)
188 #define iscont(n) ((n)->csub == JCONT)
189 #define isnext(n) ((n)->csub == JNEXT || (n)->csub == JNEXTFILE)
190 #define isret(n) ((n)->csub == JRET)
191 #define isrec(n) ((n)->tval & REC)
192 #define isfld(n) ((n)->tval & FLD)
193 #define isstr(n) ((n)->tval & STR)
194 #define isnum(n) ((n)->tval & NUM)
195 #define isarr(n) ((n)->tval & ARR)
196 #define isfcn(n) ((n)->tval & FCN)
197 #define istrue(n) ((n)->csub == BTRUE)
198 #define istemp(n) ((n)->csub == CTEMP)
199 #define isargument(n) ((n)->nobj == ARG)
200 /* #define freeable(p) (!((p)->tval & DONTFREE)) */
201 #define freeable(p) ( ((p)->tval & (STR|DONTFREE)) == STR )
203 /* structures used by regular expression matching machinery, mostly b.c: */
205 #define NCHARS (256+3) /* 256 handles 8-bit chars; 128 does 7-bit */
206 /* watch out in match(), etc. */
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;
217 typedef struct fa {
218 unsigned int **gototab;
219 uschar *out;
220 uschar *restr;
221 int **posns;
222 int state_count;
223 int anchor;
224 int use;
225 int initstat;
226 int curstat;
227 int accept;
228 struct rrow re[1]; /* variable: actual size set by calling malloc */
229 } fa;
232 #include "proto.h"