3 * Facility: m4 macro processor
8 #define unix 1 /* (kjb) */
26 #include <sys/types.h>
79 * m4 special characters
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.
98 #define DIVNAM "/tmp/m4*XXXXXX" /* unix diversion files */
99 #define UNIQUE 7 /* unique char location */
102 #define DIVNAM "sys$login:m4*XXXXXX" /* vms diversion files */
103 #define UNIQUE 12 /* unique char location */
105 #define DIVNAM "\M4*XXXXXX" /* msdos diversion files */
106 #define UNIQUE 3 /* unique char location */
111 * other important constants
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 */
129 #define cycle for(;;)
132 #define void int /* define if void is void. */
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)
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 */
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)
177 * | arg 3 ----------------------->| str |
179 * | arg 2 ---PREVEP-----+ .
182 * +-------+ | +-----+
183 * | plev | PARLEV +-------->| str |
187 * | prcf ---PREVFP--+
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 */
206 _PROTOTYPE(void eval
, (char *argv
[], int argc
, int td
));
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
));
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
));
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));
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));
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
));