mdef.h revision 1.12 1 1.12 agc /* $NetBSD: mdef.h,v 1.12 2003/08/07 11:14:33 agc 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.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.1 cgd #define MACRTYPE 1
39 1.1 cgd #define DEFITYPE 2
40 1.1 cgd #define EXPRTYPE 3
41 1.1 cgd #define SUBSTYPE 4
42 1.1 cgd #define IFELTYPE 5
43 1.1 cgd #define LENGTYPE 6
44 1.1 cgd #define CHNQTYPE 7
45 1.1 cgd #define SYSCTYPE 8
46 1.1 cgd #define UNDFTYPE 9
47 1.1 cgd #define INCLTYPE 10
48 1.1 cgd #define SINCTYPE 11
49 1.1 cgd #define PASTTYPE 12
50 1.1 cgd #define SPASTYPE 13
51 1.1 cgd #define INCRTYPE 14
52 1.1 cgd #define IFDFTYPE 15
53 1.1 cgd #define PUSDTYPE 16
54 1.1 cgd #define POPDTYPE 17
55 1.1 cgd #define SHIFTYPE 18
56 1.1 cgd #define DECRTYPE 19
57 1.1 cgd #define DIVRTYPE 20
58 1.1 cgd #define UNDVTYPE 21
59 1.1 cgd #define DIVNTYPE 22
60 1.1 cgd #define MKTMTYPE 23
61 1.1 cgd #define ERRPTYPE 24
62 1.1 cgd #define M4WRTYPE 25
63 1.1 cgd #define TRNLTYPE 26
64 1.1 cgd #define DNLNTYPE 27
65 1.1 cgd #define DUMPTYPE 28
66 1.1 cgd #define CHNCTYPE 29
67 1.1 cgd #define INDXTYPE 30
68 1.1 cgd #define SYSVTYPE 31
69 1.1 cgd #define EXITTYPE 32
70 1.1 cgd #define DEFNTYPE 33
71 1.11 tv #define SELFTYPE 34
72 1.11 tv #define INDIRTYPE 35
73 1.11 tv #define BUILTINTYPE 36
74 1.11 tv #define PATSTYPE 37
75 1.11 tv #define FILENAMETYPE 38
76 1.11 tv #define LINETYPE 39
77 1.11 tv #define REGEXPTYPE 40
78 1.11 tv #define ESYSCMDTYPE 41
79 1.11 tv #define TRACEONTYPE 42
80 1.11 tv #define TRACEOFFTYPE 43
81 1.9 jdolecek
82 1.11 tv
83 1.11 tv #define TYPEMASK 63 /* Keep bits really corresponding to a type. */
84 1.11 tv #define RECDEF 256 /* Pure recursive def, don't expand it */
85 1.11 tv #define NOARGS 512 /* builtin needs no args */
86 1.11 tv #define NEEDARGS 1024 /* mark builtin that need args with this */
87 1.1 cgd
88 1.5 glass /*
89 1.5 glass * m4 special characters
90 1.5 glass */
91 1.11 tv
92 1.1 cgd #define ARGFLAG '$'
93 1.1 cgd #define LPAREN '('
94 1.1 cgd #define RPAREN ')'
95 1.1 cgd #define LQUOTE '`'
96 1.1 cgd #define RQUOTE '\''
97 1.1 cgd #define COMMA ','
98 1.1 cgd #define SCOMMT '#'
99 1.1 cgd #define ECOMMT '\n'
100 1.1 cgd
101 1.5 glass #ifdef msdos
102 1.5 glass #define system(str) (-1)
103 1.5 glass #endif
104 1.5 glass
105 1.1 cgd /*
106 1.1 cgd * other important constants
107 1.1 cgd */
108 1.1 cgd
109 1.11 tv #define EOS '\0'
110 1.11 tv #define MAXINP 10 /* maximum include files */
111 1.11 tv #define MAXOUT 10 /* maximum # of diversions */
112 1.11 tv #define BUFSIZE 4096 /* starting size of pushback buffer */
113 1.11 tv #define INITSTACKMAX 4096 /* starting size of call stack */
114 1.11 tv #define STRSPMAX 4096 /* starting size of string space */
115 1.11 tv #define MAXTOK 512 /* maximum chars in a tokn */
116 1.11 tv #define HASHSIZE 199 /* maximum size of hashtab */
117 1.11 tv #define MAXCCHARS 5 /* max size of comment/quote delim */
118 1.1 cgd
119 1.1 cgd #define ALL 1
120 1.1 cgd #define TOP 0
121 1.11 tv
122 1.1 cgd #define TRUE 1
123 1.1 cgd #define FALSE 0
124 1.5 glass #define cycle for(;;)
125 1.1 cgd
126 1.5 glass /*
127 1.5 glass * m4 data structures
128 1.5 glass */
129 1.11 tv
130 1.1 cgd typedef struct ndblock *ndptr;
131 1.11 tv
132 1.11 tv struct ndblock { /* hastable structure */
133 1.11 tv char *name; /* entry name.. */
134 1.11 tv char *defn; /* definition.. */
135 1.11 tv unsigned int type; /* type of the entry.. */
136 1.11 tv unsigned int hv; /* hash function value.. */
137 1.11 tv ndptr nxtptr; /* link to next entry.. */
138 1.5 glass };
139 1.11 tv
140 1.1 cgd #define nil ((ndptr) 0)
141 1.11 tv
142 1.5 glass struct keyblk {
143 1.11 tv const char *knam; /* keyword name */
144 1.11 tv int ktyp; /* keyword type */
145 1.5 glass };
146 1.5 glass
147 1.5 glass typedef union { /* stack structure */
148 1.5 glass int sfra; /* frame entry */
149 1.1 cgd char *sstr; /* string entry */
150 1.5 glass } stae;
151 1.8 cgd
152 1.11 tv struct input_file {
153 1.11 tv FILE *file;
154 1.11 tv char *name;
155 1.11 tv unsigned long lineno;
156 1.11 tv int c;
157 1.11 tv };
158 1.1 cgd
159 1.11 tv #define CURRENT_NAME (infile[ilevel].name)
160 1.11 tv #define CURRENT_LINE (infile[ilevel].lineno)
161 1.1 cgd /*
162 1.1 cgd * macros for readibility and/or speed
163 1.1 cgd *
164 1.1 cgd * gpbc() - get a possibly pushed-back character
165 1.1 cgd * pushf() - push a call frame entry onto stack
166 1.1 cgd * pushs() - push a string pointer onto stack
167 1.1 cgd */
168 1.11 tv #define gpbc() (bp > bufbase) ? *--bp : obtain_char(infile+ilevel)
169 1.11 tv #define pushf(x) \
170 1.11 tv do { \
171 1.11 tv if (++sp == STACKMAX) \
172 1.11 tv enlarge_stack();\
173 1.11 tv mstack[sp].sfra = (x); \
174 1.11 tv sstack[sp] = 0; \
175 1.11 tv } while (0)
176 1.11 tv
177 1.11 tv #define pushs(x) \
178 1.11 tv do { \
179 1.11 tv if (++sp == STACKMAX) \
180 1.11 tv enlarge_stack();\
181 1.11 tv mstack[sp].sstr = (x); \
182 1.11 tv sstack[sp] = 1; \
183 1.11 tv } while (0)
184 1.11 tv
185 1.11 tv #define pushs1(x) \
186 1.11 tv do { \
187 1.11 tv if (++sp == STACKMAX) \
188 1.11 tv enlarge_stack();\
189 1.11 tv mstack[sp].sstr = (x); \
190 1.11 tv sstack[sp] = 0; \
191 1.11 tv } while (0)
192 1.1 cgd
193 1.1 cgd /*
194 1.1 cgd * . .
195 1.1 cgd * | . | <-- sp | . |
196 1.1 cgd * +-------+ +-----+
197 1.1 cgd * | arg 3 ----------------------->| str |
198 1.1 cgd * +-------+ | . |
199 1.1 cgd * | arg 2 ---PREVEP-----+ .
200 1.1 cgd * +-------+ |
201 1.1 cgd * . | | |
202 1.1 cgd * +-------+ | +-----+
203 1.1 cgd * | plev | PARLEV +-------->| str |
204 1.1 cgd * +-------+ | . |
205 1.1 cgd * | type | CALTYP .
206 1.1 cgd * +-------+
207 1.1 cgd * | prcf ---PREVFP--+
208 1.1 cgd * +-------+ |
209 1.1 cgd * | . | PREVSP |
210 1.1 cgd * . |
211 1.1 cgd * +-------+ |
212 1.1 cgd * | <----------+
213 1.1 cgd * +-------+
214 1.1 cgd *
215 1.1 cgd */
216 1.1 cgd #define PARLEV (mstack[fp].sfra)
217 1.1 cgd #define CALTYP (mstack[fp-1].sfra)
218 1.1 cgd #define PREVEP (mstack[fp+3].sstr)
219 1.1 cgd #define PREVSP (fp-3)
220 1.1 cgd #define PREVFP (mstack[fp-2].sfra)
221