updated package versions
[minix.git] / commands / m4 / mdef.h
blob1e3cd5924f25a7e2f91a1e983a9994d232e34533
1 /*
2 * mdef.h
3 * Facility: m4 macro processor
4 * by: oz
5 */
8 #define unix 1 /* (kjb) */
10 #ifndef unix
11 #define unix 0
12 #endif
14 #ifndef vms
15 #define vms 0
16 #endif
18 #if vms
20 #include stdio
21 #include ctype
22 #include signal
24 #else
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>
34 #endif
38 * m4 constants..
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
76 #define STATIC 128
79 * m4 special characters
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'
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.
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
111 * other important constants
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 */
124 #define ALL 1
125 #define TOP 0
127 #define TRUE 1
128 #define FALSE 0
129 #define cycle for(;;)
131 #ifdef VOID
132 #define void int /* define if void is void. */
133 #endif
136 * m4 data structures
139 typedef struct ndblock *ndptr;
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.. */
148 #define nil ((ndptr) 0)
150 struct keyblk {
151 char *knam; /* keyword name */
152 int ktyp; /* keyword type */
155 typedef union { /* stack structure */
156 int sfra; /* frame entry */
157 char *sstr; /* string entry */
158 } stae;
161 * macros for readibility and/or speed
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
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)
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 * +-------+
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)
202 /* function prototypes */
204 /* eval.c */
206 _PROTOTYPE(void eval, (char *argv [], int argc, int td ));
208 /* expr.c */
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 ));
231 /* look.c */
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 ));
239 /* main.c */
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));
247 /* misc.c */
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));
261 /* serv.c */
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 ));