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