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