2 |
- |
1 |
/*
|
|
|
2 |
Copyright (c) Lucent Technologies 1997
|
|
|
3 |
All Rights Reserved
|
|
|
4 |
|
|
|
5 |
*/
|
|
|
6 |
|
|
|
7 |
typedef double Awkfloat;
|
|
|
8 |
|
|
|
9 |
/* unsigned char is more trouble than it's worth */
|
|
|
10 |
|
|
|
11 |
typedef unsigned char uschar;
|
|
|
12 |
|
|
|
13 |
#define xfree(a) { if ((a) != NULL) { free((char *) a); a = NULL; } }
|
|
|
14 |
|
|
|
15 |
#define DEBUG
|
|
|
16 |
#ifdef DEBUG
|
|
|
17 |
/* uses have to be doubly parenthesized */
|
|
|
18 |
# define dprintf(x) if (dbg) printf x
|
|
|
19 |
#else
|
|
|
20 |
# define dprintf(x)
|
|
|
21 |
#endif
|
|
|
22 |
|
|
|
23 |
extern char errbuf[];
|
|
|
24 |
|
|
|
25 |
extern int compile_time; /* 1 if compiling, 0 if running */
|
|
|
26 |
extern int safe; /* 0 => unsafe, 1 => safe */
|
|
|
27 |
|
|
|
28 |
#define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */
|
|
|
29 |
extern int recsize; /* size of current record, orig RECSIZE */
|
|
|
30 |
|
|
|
31 |
extern char **FS;
|
|
|
32 |
extern char **RS;
|
|
|
33 |
extern char **ORS;
|
|
|
34 |
extern char **OFS;
|
|
|
35 |
extern char **OFMT;
|
|
|
36 |
extern Awkfloat *NR;
|
|
|
37 |
extern Awkfloat *FNR;
|
|
|
38 |
extern Awkfloat *NF;
|
|
|
39 |
extern char **FILENAME;
|
|
|
40 |
extern char **SUBSEP;
|
|
|
41 |
extern Awkfloat *RSTART;
|
|
|
42 |
extern Awkfloat *RLENGTH;
|
|
|
43 |
|
|
|
44 |
extern char *record; /* points to $0 */
|
|
|
45 |
extern int lineno; /* line number in awk program */
|
|
|
46 |
extern int errorflag; /* 1 if error has occurred */
|
|
|
47 |
extern int donefld; /* 1 if record broken into fields */
|
|
|
48 |
extern int donerec; /* 1 if record is valid (no fld has changed */
|
|
|
49 |
extern char inputFS[]; /* FS at time of input, for field splitting */
|
|
|
50 |
|
|
|
51 |
extern int dbg;
|
|
|
52 |
|
|
|
53 |
extern char *patbeg; /* beginning of pattern matched */
|
|
|
54 |
extern int patlen; /* length of pattern matched. set in b.c */
|
|
|
55 |
|
|
|
56 |
/* Cell: all information about a variable or constant */
|
|
|
57 |
|
|
|
58 |
typedef struct Cell {
|
|
|
59 |
uschar ctype; /* OCELL, OBOOL, OJUMP, etc. */
|
|
|
60 |
uschar csub; /* CCON, CTEMP, CFLD, etc. */
|
|
|
61 |
char *nval; /* name, for variables only */
|
|
|
62 |
char *sval; /* string value */
|
|
|
63 |
Awkfloat fval; /* value as number */
|
|
|
64 |
int tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
|
|
|
65 |
struct Cell *cnext; /* ptr to next if chained */
|
|
|
66 |
} Cell;
|
|
|
67 |
|
|
|
68 |
typedef struct Array { /* symbol table array */
|
|
|
69 |
int nelem; /* elements in table right now */
|
|
|
70 |
int size; /* size of tab */
|
|
|
71 |
Cell **tab; /* hash table pointers */
|
|
|
72 |
} Array;
|
|
|
73 |
|
|
|
74 |
#define NSYMTAB 50 /* initial size of a symbol table */
|
|
|
75 |
extern Array *symtab;
|
|
|
76 |
|
|
|
77 |
extern Cell *nrloc; /* NR */
|
|
|
78 |
extern Cell *fnrloc; /* FNR */
|
|
|
79 |
extern Cell *nfloc; /* NF */
|
|
|
80 |
extern Cell *rstartloc; /* RSTART */
|
|
|
81 |
extern Cell *rlengthloc; /* RLENGTH */
|
|
|
82 |
|
|
|
83 |
/* Cell.tval values: */
|
|
|
84 |
#define NUM 01 /* number value is valid */
|
|
|
85 |
#define STR 02 /* string value is valid */
|
|
|
86 |
#define DONTFREE 04 /* string space is not freeable */
|
|
|
87 |
#define CON 010 /* this is a constant */
|
|
|
88 |
#define ARR 020 /* this is an array */
|
|
|
89 |
#define FCN 040 /* this is a function name */
|
|
|
90 |
#define FLD 0100 /* this is a field $1, $2, ... */
|
|
|
91 |
#define REC 0200 /* this is $0 */
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
/* function types */
|
|
|
95 |
#define FLENGTH 1
|
|
|
96 |
#define FSQRT 2
|
|
|
97 |
#define FEXP 3
|
|
|
98 |
#define FLOG 4
|
|
|
99 |
#define FINT 5
|
|
|
100 |
#define FSYSTEM 6
|
|
|
101 |
#define FRAND 7
|
|
|
102 |
#define FSRAND 8
|
|
|
103 |
#define FSIN 9
|
|
|
104 |
#define FCOS 10
|
|
|
105 |
#define FATAN 11
|
|
|
106 |
#define FTOUPPER 12
|
|
|
107 |
#define FTOLOWER 13
|
|
|
108 |
#define FFLUSH 14
|
|
|
109 |
#define FUTF 15
|
|
|
110 |
|
|
|
111 |
/* Node: parse tree is made of nodes, with Cell's at bottom */
|
|
|
112 |
|
|
|
113 |
typedef struct Node {
|
|
|
114 |
int ntype;
|
|
|
115 |
struct Node *nnext;
|
|
|
116 |
int lineno;
|
|
|
117 |
int nobj;
|
|
|
118 |
struct Node *narg[1]; /* variable: actual size set by calling malloc */
|
|
|
119 |
} Node;
|
|
|
120 |
|
|
|
121 |
#define NIL ((Node *) 0)
|
|
|
122 |
|
|
|
123 |
extern Node *winner;
|
|
|
124 |
extern Node *nullstat;
|
|
|
125 |
extern Node *nullnode;
|
|
|
126 |
|
|
|
127 |
/* ctypes */
|
|
|
128 |
#define OCELL 1
|
|
|
129 |
#define OBOOL 2
|
|
|
130 |
#define OJUMP 3
|
|
|
131 |
|
|
|
132 |
/* Cell subtypes: csub */
|
|
|
133 |
#define CFREE 7
|
|
|
134 |
#define CCOPY 6
|
|
|
135 |
#define CCON 5
|
|
|
136 |
#define CTEMP 4
|
|
|
137 |
#define CNAME 3
|
|
|
138 |
#define CVAR 2
|
|
|
139 |
#define CFLD 1
|
|
|
140 |
#define CUNK 0
|
|
|
141 |
|
|
|
142 |
/* bool subtypes */
|
|
|
143 |
#define BTRUE 11
|
|
|
144 |
#define BFALSE 12
|
|
|
145 |
|
|
|
146 |
/* jump subtypes */
|
|
|
147 |
#define JEXIT 21
|
|
|
148 |
#define JNEXT 22
|
|
|
149 |
#define JBREAK 23
|
|
|
150 |
#define JCONT 24
|
|
|
151 |
#define JRET 25
|
|
|
152 |
#define JNEXTFILE 26
|
|
|
153 |
|
|
|
154 |
/* node types */
|
|
|
155 |
#define NVALUE 1
|
|
|
156 |
#define NSTAT 2
|
|
|
157 |
#define NEXPR 3
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
extern int pairstack[], paircnt;
|
|
|
161 |
|
|
|
162 |
#define notlegal(n) (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc)
|
|
|
163 |
#define isvalue(n) ((n)->ntype == NVALUE)
|
|
|
164 |
#define isexpr(n) ((n)->ntype == NEXPR)
|
|
|
165 |
#define isjump(n) ((n)->ctype == OJUMP)
|
|
|
166 |
#define isexit(n) ((n)->csub == JEXIT)
|
|
|
167 |
#define isbreak(n) ((n)->csub == JBREAK)
|
|
|
168 |
#define iscont(n) ((n)->csub == JCONT)
|
|
|
169 |
#define isnext(n) ((n)->csub == JNEXT)
|
|
|
170 |
#define isnextfile(n) ((n)->csub == JNEXTFILE)
|
|
|
171 |
#define isret(n) ((n)->csub == JRET)
|
|
|
172 |
#define isrec(n) ((n)->tval & REC)
|
|
|
173 |
#define isfld(n) ((n)->tval & FLD)
|
|
|
174 |
#define isstr(n) ((n)->tval & STR)
|
|
|
175 |
#define isnum(n) ((n)->tval & NUM)
|
|
|
176 |
#define isarr(n) ((n)->tval & ARR)
|
|
|
177 |
#define isfcn(n) ((n)->tval & FCN)
|
|
|
178 |
#define istrue(n) ((n)->csub == BTRUE)
|
|
|
179 |
#define istemp(n) ((n)->csub == CTEMP)
|
|
|
180 |
#define isargument(n) ((n)->nobj == ARG)
|
|
|
181 |
/* #define freeable(p) (!((p)->tval & DONTFREE)) */
|
|
|
182 |
#define freeable(p) ( ((p)->tval & (STR|DONTFREE)) == STR )
|
|
|
183 |
|
|
|
184 |
#include "proto.h"
|