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