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