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