mdef.h revision 1.5 1 1.5 glass /*
2 1.5 glass * Copyright (c) 1989, 1993
3 1.5 glass * The Regents of the University of California. All rights reserved.
4 1.5 glass *
5 1.5 glass * This code is derived from software contributed to Berkeley by
6 1.5 glass * Ozan Yigit at York University.
7 1.5 glass *
8 1.5 glass * Redistribution and use in source and binary forms, with or without
9 1.5 glass * modification, are permitted provided that the following conditions
10 1.5 glass * are met:
11 1.5 glass * 1. Redistributions of source code must retain the above copyright
12 1.5 glass * notice, this list of conditions and the following disclaimer.
13 1.5 glass * 2. Redistributions in binary form must reproduce the above copyright
14 1.5 glass * notice, this list of conditions and the following disclaimer in the
15 1.5 glass * documentation and/or other materials provided with the distribution.
16 1.5 glass * 3. All advertising materials mentioning features or use of this software
17 1.5 glass * must display the following acknowledgement:
18 1.5 glass * This product includes software developed by the University of
19 1.5 glass * California, Berkeley and its contributors.
20 1.5 glass * 4. Neither the name of the University nor the names of its contributors
21 1.5 glass * may be used to endorse or promote products derived from this software
22 1.5 glass * without specific prior written permission.
23 1.5 glass *
24 1.5 glass * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.5 glass * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.5 glass * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.5 glass * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.5 glass * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.5 glass * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.5 glass * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.5 glass * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.5 glass * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.5 glass * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.5 glass * SUCH DAMAGE.
35 1.5 glass *
36 1.5 glass * @(#)mdef.h 8.1 (Berkeley) 6/6/93
37 1.5 glass */
38 1.2 glass
39 1.1 cgd #define MACRTYPE 1
40 1.1 cgd #define DEFITYPE 2
41 1.1 cgd #define EXPRTYPE 3
42 1.1 cgd #define SUBSTYPE 4
43 1.1 cgd #define IFELTYPE 5
44 1.1 cgd #define LENGTYPE 6
45 1.1 cgd #define CHNQTYPE 7
46 1.1 cgd #define SYSCTYPE 8
47 1.1 cgd #define UNDFTYPE 9
48 1.1 cgd #define INCLTYPE 10
49 1.1 cgd #define SINCTYPE 11
50 1.1 cgd #define PASTTYPE 12
51 1.1 cgd #define SPASTYPE 13
52 1.1 cgd #define INCRTYPE 14
53 1.1 cgd #define IFDFTYPE 15
54 1.1 cgd #define PUSDTYPE 16
55 1.1 cgd #define POPDTYPE 17
56 1.1 cgd #define SHIFTYPE 18
57 1.1 cgd #define DECRTYPE 19
58 1.1 cgd #define DIVRTYPE 20
59 1.1 cgd #define UNDVTYPE 21
60 1.1 cgd #define DIVNTYPE 22
61 1.1 cgd #define MKTMTYPE 23
62 1.1 cgd #define ERRPTYPE 24
63 1.1 cgd #define M4WRTYPE 25
64 1.1 cgd #define TRNLTYPE 26
65 1.1 cgd #define DNLNTYPE 27
66 1.1 cgd #define DUMPTYPE 28
67 1.1 cgd #define CHNCTYPE 29
68 1.1 cgd #define INDXTYPE 30
69 1.1 cgd #define SYSVTYPE 31
70 1.1 cgd #define EXITTYPE 32
71 1.1 cgd #define DEFNTYPE 33
72 1.5 glass
73 1.1 cgd #define STATIC 128
74 1.1 cgd
75 1.5 glass /*
76 1.5 glass * m4 special characters
77 1.5 glass */
78 1.1 cgd
79 1.1 cgd #define ARGFLAG '$'
80 1.1 cgd #define LPAREN '('
81 1.1 cgd #define RPAREN ')'
82 1.1 cgd #define LQUOTE '`'
83 1.1 cgd #define RQUOTE '\''
84 1.1 cgd #define COMMA ','
85 1.1 cgd #define SCOMMT '#'
86 1.1 cgd #define ECOMMT '\n'
87 1.1 cgd
88 1.5 glass #ifdef msdos
89 1.5 glass #define system(str) (-1)
90 1.5 glass #endif
91 1.5 glass
92 1.1 cgd /*
93 1.1 cgd * other important constants
94 1.1 cgd */
95 1.1 cgd
96 1.1 cgd #define EOS (char) 0
97 1.1 cgd #define MAXINP 10 /* maximum include files */
98 1.1 cgd #define MAXOUT 10 /* maximum # of diversions */
99 1.5 glass #define MAXSTR 512 /* maximum size of string */
100 1.1 cgd #define BUFSIZE 4096 /* size of pushback buffer */
101 1.1 cgd #define STACKMAX 1024 /* size of call stack */
102 1.1 cgd #define STRSPMAX 4096 /* size of string space */
103 1.1 cgd #define MAXTOK MAXSTR /* maximum chars in a tokn */
104 1.5 glass #define HASHSIZE 199 /* maximum size of hashtab */
105 1.1 cgd
106 1.1 cgd #define ALL 1
107 1.1 cgd #define TOP 0
108 1.1 cgd
109 1.1 cgd #define TRUE 1
110 1.1 cgd #define FALSE 0
111 1.5 glass #define cycle for(;;)
112 1.1 cgd
113 1.5 glass /*
114 1.5 glass * m4 data structures
115 1.5 glass */
116 1.1 cgd
117 1.1 cgd typedef struct ndblock *ndptr;
118 1.1 cgd
119 1.5 glass struct ndblock { /* hastable structure */
120 1.1 cgd char *name; /* entry name.. */
121 1.1 cgd char *defn; /* definition.. */
122 1.1 cgd int type; /* type of the entry.. */
123 1.1 cgd ndptr nxtptr; /* link to next entry.. */
124 1.5 glass };
125 1.1 cgd
126 1.1 cgd #define nil ((ndptr) 0)
127 1.1 cgd
128 1.5 glass struct keyblk {
129 1.5 glass char *knam; /* keyword name */
130 1.5 glass int ktyp; /* keyword type */
131 1.5 glass };
132 1.5 glass
133 1.5 glass typedef union { /* stack structure */
134 1.5 glass int sfra; /* frame entry */
135 1.1 cgd char *sstr; /* string entry */
136 1.5 glass } stae;
137 1.1 cgd
138 1.1 cgd /*
139 1.1 cgd * macros for readibility and/or speed
140 1.1 cgd *
141 1.1 cgd * gpbc() - get a possibly pushed-back character
142 1.1 cgd * pushf() - push a call frame entry onto stack
143 1.1 cgd * pushs() - push a string pointer onto stack
144 1.1 cgd */
145 1.5 glass #define gpbc() (bp > bufbase) ? *--bp : getc(infile[ilevel])
146 1.1 cgd #define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
147 1.1 cgd #define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
148 1.1 cgd
149 1.1 cgd /*
150 1.1 cgd * . .
151 1.1 cgd * | . | <-- sp | . |
152 1.1 cgd * +-------+ +-----+
153 1.1 cgd * | arg 3 ----------------------->| str |
154 1.1 cgd * +-------+ | . |
155 1.1 cgd * | arg 2 ---PREVEP-----+ .
156 1.1 cgd * +-------+ |
157 1.1 cgd * . | | |
158 1.1 cgd * +-------+ | +-----+
159 1.1 cgd * | plev | PARLEV +-------->| str |
160 1.1 cgd * +-------+ | . |
161 1.1 cgd * | type | CALTYP .
162 1.1 cgd * +-------+
163 1.1 cgd * | prcf ---PREVFP--+
164 1.1 cgd * +-------+ |
165 1.1 cgd * | . | PREVSP |
166 1.1 cgd * . |
167 1.1 cgd * +-------+ |
168 1.1 cgd * | <----------+
169 1.1 cgd * +-------+
170 1.1 cgd *
171 1.1 cgd */
172 1.1 cgd #define PARLEV (mstack[fp].sfra)
173 1.1 cgd #define CALTYP (mstack[fp-1].sfra)
174 1.1 cgd #define PREVEP (mstack[fp+3].sstr)
175 1.1 cgd #define PREVSP (fp-3)
176 1.1 cgd #define PREVFP (mstack[fp-2].sfra)
177