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