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