1 | /*
|
---|
2 | * mdef.h
|
---|
3 | * Facility: m4 macro processor
|
---|
4 | * by: oz
|
---|
5 | */
|
---|
6 |
|
---|
7 |
|
---|
8 | #define unix 1 /* (kjb) */
|
---|
9 |
|
---|
10 | #ifndef unix
|
---|
11 | #define unix 0
|
---|
12 | #endif
|
---|
13 |
|
---|
14 | #ifndef vms
|
---|
15 | #define vms 0
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | #if vms
|
---|
19 |
|
---|
20 | #include stdio
|
---|
21 | #include ctype
|
---|
22 | #include signal
|
---|
23 |
|
---|
24 | #else
|
---|
25 |
|
---|
26 | #include <sys/types.h>
|
---|
27 | #include <ctype.h>
|
---|
28 | #include <signal.h>
|
---|
29 | #include <string.h>
|
---|
30 | #include <stdlib.h>
|
---|
31 | #include <unistd.h>
|
---|
32 | #include <stdio.h>
|
---|
33 |
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | /*
|
---|
37 | *
|
---|
38 | * m4 constants..
|
---|
39 | *
|
---|
40 | */
|
---|
41 |
|
---|
42 | #define MACRTYPE 1
|
---|
43 | #define DEFITYPE 2
|
---|
44 | #define EXPRTYPE 3
|
---|
45 | #define SUBSTYPE 4
|
---|
46 | #define IFELTYPE 5
|
---|
47 | #define LENGTYPE 6
|
---|
48 | #define CHNQTYPE 7
|
---|
49 | #define SYSCTYPE 8
|
---|
50 | #define UNDFTYPE 9
|
---|
51 | #define INCLTYPE 10
|
---|
52 | #define SINCTYPE 11
|
---|
53 | #define PASTTYPE 12
|
---|
54 | #define SPASTYPE 13
|
---|
55 | #define INCRTYPE 14
|
---|
56 | #define IFDFTYPE 15
|
---|
57 | #define PUSDTYPE 16
|
---|
58 | #define POPDTYPE 17
|
---|
59 | #define SHIFTYPE 18
|
---|
60 | #define DECRTYPE 19
|
---|
61 | #define DIVRTYPE 20
|
---|
62 | #define UNDVTYPE 21
|
---|
63 | #define DIVNTYPE 22
|
---|
64 | #define MKTMTYPE 23
|
---|
65 | #define ERRPTYPE 24
|
---|
66 | #define M4WRTYPE 25
|
---|
67 | #define TRNLTYPE 26
|
---|
68 | #define DNLNTYPE 27
|
---|
69 | #define DUMPTYPE 28
|
---|
70 | #define CHNCTYPE 29
|
---|
71 | #define INDXTYPE 30
|
---|
72 | #define SYSVTYPE 31
|
---|
73 | #define EXITTYPE 32
|
---|
74 | #define DEFNTYPE 33
|
---|
75 |
|
---|
76 | #define STATIC 128
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * m4 special characters
|
---|
80 | */
|
---|
81 |
|
---|
82 | #define ARGFLAG '$'
|
---|
83 | #define LPAREN '('
|
---|
84 | #define RPAREN ')'
|
---|
85 | #define LQUOTE '`'
|
---|
86 | #define RQUOTE '\''
|
---|
87 | #define COMMA ','
|
---|
88 | #define SCOMMT '#'
|
---|
89 | #define ECOMMT '\n'
|
---|
90 |
|
---|
91 | /*
|
---|
92 | * definitions of diversion files. If the name of
|
---|
93 | * the file is changed, adjust UNIQUE to point to the
|
---|
94 | * wildcard (*) character in the filename.
|
---|
95 | */
|
---|
96 |
|
---|
97 | #if unix
|
---|
98 | #define DIVNAM "/tmp/m4*XXXXXX" /* unix diversion files */
|
---|
99 | #define UNIQUE 7 /* unique char location */
|
---|
100 | #else
|
---|
101 | #if vms
|
---|
102 | #define DIVNAM "sys$login:m4*XXXXXX" /* vms diversion files */
|
---|
103 | #define UNIQUE 12 /* unique char location */
|
---|
104 | #else
|
---|
105 | #define DIVNAM "\M4*XXXXXX" /* msdos diversion files */
|
---|
106 | #define UNIQUE 3 /* unique char location */
|
---|
107 | #endif
|
---|
108 | #endif
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * other important constants
|
---|
112 | */
|
---|
113 |
|
---|
114 | #define EOS (char) 0
|
---|
115 | #define MAXINP 10 /* maximum include files */
|
---|
116 | #define MAXOUT 10 /* maximum # of diversions */
|
---|
117 | #define MAXSTR 512 /* maximum size of string */
|
---|
118 | #define BUFSIZE 4096 /* size of pushback buffer */
|
---|
119 | #define STACKMAX 1024 /* size of call stack */
|
---|
120 | #define STRSPMAX 4096 /* size of string space */
|
---|
121 | #define MAXTOK MAXSTR /* maximum chars in a tokn */
|
---|
122 | #define HASHSIZE 199 /* maximum size of hashtab */
|
---|
123 |
|
---|
124 | #define ALL 1
|
---|
125 | #define TOP 0
|
---|
126 |
|
---|
127 | #define TRUE 1
|
---|
128 | #define FALSE 0
|
---|
129 | #define cycle for(;;)
|
---|
130 |
|
---|
131 | #ifdef VOID
|
---|
132 | #define void int /* define if void is void. */
|
---|
133 | #endif
|
---|
134 |
|
---|
135 | /*
|
---|
136 | * m4 data structures
|
---|
137 | */
|
---|
138 |
|
---|
139 | typedef struct ndblock *ndptr;
|
---|
140 |
|
---|
141 | struct ndblock { /* hastable structure */
|
---|
142 | char *name; /* entry name.. */
|
---|
143 | char *defn; /* definition.. */
|
---|
144 | int type; /* type of the entry.. */
|
---|
145 | ndptr nxtptr; /* link to next entry.. */
|
---|
146 | };
|
---|
147 |
|
---|
148 | #define nil ((ndptr) 0)
|
---|
149 |
|
---|
150 | struct keyblk {
|
---|
151 | char *knam; /* keyword name */
|
---|
152 | int ktyp; /* keyword type */
|
---|
153 | };
|
---|
154 |
|
---|
155 | typedef union { /* stack structure */
|
---|
156 | int sfra; /* frame entry */
|
---|
157 | char *sstr; /* string entry */
|
---|
158 | } stae;
|
---|
159 |
|
---|
160 | /*
|
---|
161 | * macros for readibility and/or speed
|
---|
162 | *
|
---|
163 | * gpbc() - get a possibly pushed-back character
|
---|
164 | * min() - select the minimum of two elements
|
---|
165 | * pushf() - push a call frame entry onto stack
|
---|
166 | * pushs() - push a string pointer onto stack
|
---|
167 | */
|
---|
168 | #define gpbc() (bp > buf) ? *--bp : getc(infile[ilevel])
|
---|
169 | #define min(x,y) ((x > y) ? y : x)
|
---|
170 | #define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
|
---|
171 | #define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
|
---|
172 |
|
---|
173 | /*
|
---|
174 | * . .
|
---|
175 | * | . | <-- sp | . |
|
---|
176 | * +-------+ +-----+
|
---|
177 | * | arg 3 ----------------------->| str |
|
---|
178 | * +-------+ | . |
|
---|
179 | * | arg 2 ---PREVEP-----+ .
|
---|
180 | * +-------+ |
|
---|
181 | * . | | |
|
---|
182 | * +-------+ | +-----+
|
---|
183 | * | plev | PARLEV +-------->| str |
|
---|
184 | * +-------+ | . |
|
---|
185 | * | type | CALTYP .
|
---|
186 | * +-------+
|
---|
187 | * | prcf ---PREVFP--+
|
---|
188 | * +-------+ |
|
---|
189 | * | . | PREVSP |
|
---|
190 | * . |
|
---|
191 | * +-------+ |
|
---|
192 | * | <----------+
|
---|
193 | * +-------+
|
---|
194 | *
|
---|
195 | */
|
---|
196 | #define PARLEV (mstack[fp].sfra)
|
---|
197 | #define CALTYP (mstack[fp-1].sfra)
|
---|
198 | #define PREVEP (mstack[fp+3].sstr)
|
---|
199 | #define PREVSP (fp-3)
|
---|
200 | #define PREVFP (mstack[fp-2].sfra)
|
---|
201 |
|
---|
202 | /* function prototypes */
|
---|
203 |
|
---|
204 | /* eval.c */
|
---|
205 |
|
---|
206 | _PROTOTYPE(void eval, (char *argv [], int argc, int td ));
|
---|
207 |
|
---|
208 | /* expr.c */
|
---|
209 |
|
---|
210 | _PROTOTYPE(int expr, (char *expbuf ));
|
---|
211 | _PROTOTYPE(int query, (void));
|
---|
212 | _PROTOTYPE(int lor, (void));
|
---|
213 | _PROTOTYPE(int land, (void));
|
---|
214 | _PROTOTYPE(int bor, (void));
|
---|
215 | _PROTOTYPE(int bxor, (void));
|
---|
216 | _PROTOTYPE(int band, (void));
|
---|
217 | _PROTOTYPE(int eql, (void));
|
---|
218 | _PROTOTYPE(int relat, (void));
|
---|
219 | _PROTOTYPE(int shift, (void));
|
---|
220 | _PROTOTYPE(int primary, (void));
|
---|
221 | _PROTOTYPE(int term, (void));
|
---|
222 | _PROTOTYPE(int unary, (void));
|
---|
223 | _PROTOTYPE(int factor, (void));
|
---|
224 | _PROTOTYPE(int constant, (void));
|
---|
225 | _PROTOTYPE(int num, (void));
|
---|
226 | _PROTOTYPE(int geteql, (void));
|
---|
227 | _PROTOTYPE(int getrel, (void));
|
---|
228 | _PROTOTYPE(int skipws, (void));
|
---|
229 | _PROTOTYPE(int experr, (char *msg ));
|
---|
230 |
|
---|
231 | /* look.c */
|
---|
232 |
|
---|
233 | _PROTOTYPE(int hash, (char *name ));
|
---|
234 | _PROTOTYPE(ndptr lookup, (char *name ));
|
---|
235 | _PROTOTYPE(ndptr addent, (char *name ));
|
---|
236 | _PROTOTYPE(void remhash, (char *name, int all ));
|
---|
237 | _PROTOTYPE(void freent, (ndptr p ));
|
---|
238 |
|
---|
239 | /* main.c */
|
---|
240 |
|
---|
241 | _PROTOTYPE(int main, (int argc, char *argv []));
|
---|
242 | _PROTOTYPE(void macro, (void));
|
---|
243 | _PROTOTYPE(ndptr inspect, (char *tp ));
|
---|
244 | _PROTOTYPE(void initm4, (void));
|
---|
245 | _PROTOTYPE(void initkwds, (void));
|
---|
246 |
|
---|
247 | /* misc.c */
|
---|
248 |
|
---|
249 | _PROTOTYPE(int indx, (char *s1, char *s2 ));
|
---|
250 | _PROTOTYPE(void putback, (int c ));
|
---|
251 | _PROTOTYPE(void pbstr, (char *s ));
|
---|
252 | _PROTOTYPE(void pbnum, (int n ));
|
---|
253 | _PROTOTYPE(void chrsave, (int c ));
|
---|
254 | _PROTOTYPE(void getdiv, (int ind ));
|
---|
255 | _PROTOTYPE(void error, (char *s ));
|
---|
256 | _PROTOTYPE(void onintr, (int s ));
|
---|
257 | _PROTOTYPE(void killdiv, (void));
|
---|
258 | _PROTOTYPE(char *strsave, (char *s ));
|
---|
259 | _PROTOTYPE(void usage, (void));
|
---|
260 |
|
---|
261 | /* serv.c */
|
---|
262 |
|
---|
263 | _PROTOTYPE(void expand, (char *argv [], int argc ));
|
---|
264 | _PROTOTYPE(void dodefine, (char *name, char *defn ));
|
---|
265 | _PROTOTYPE(void dodefn, (char *name ));
|
---|
266 | _PROTOTYPE(void dopushdef, (char *name, char *defn ));
|
---|
267 | _PROTOTYPE(void dodump, (char *argv [], int argc ));
|
---|
268 | _PROTOTYPE(void doifelse, (char *argv [], int argc ));
|
---|
269 | _PROTOTYPE(int doincl, (char *ifile ));
|
---|
270 | _PROTOTYPE(int dopaste, (char *pfile ));
|
---|
271 | _PROTOTYPE(void dochq, (char *argv [], int argc ));
|
---|
272 | _PROTOTYPE(void dochc, (char *argv [], int argc ));
|
---|
273 | _PROTOTYPE(void dodiv, (int n ));
|
---|
274 | _PROTOTYPE(void doundiv, (char *argv [], int argc ));
|
---|
275 | _PROTOTYPE(void dosub, (char *argv [], int argc ));
|
---|
276 | _PROTOTYPE(void map, (char *dest, char *src, char *from, char *to ));
|
---|