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