source: trunk/minix/commands/m4/mdef.h@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 7.0 KB
Line 
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
139typedef struct ndblock *ndptr;
140
141struct 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
150struct keyblk {
151 char *knam; /* keyword name */
152 int ktyp; /* keyword type */
153};
154
155typedef 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 ));
Note: See TracBrowser for help on using the repository browser.