xref: /original-bsd/usr.bin/m4/mdef.h (revision 6884d44a)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Ozan Yigit.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)mdef.h	5.6 (Berkeley) 02/26/91
11  */
12 
13 /*
14  * mdef.h
15  * Facility: m4 macro processor
16  * by: oz
17  */
18 
19 /*
20  *
21  * m4 constants..
22  *
23  */
24 
25 #define MACRTYPE        1
26 #define DEFITYPE        2
27 #define EXPRTYPE        3
28 #define SUBSTYPE        4
29 #define IFELTYPE        5
30 #define LENGTYPE        6
31 #define CHNQTYPE        7
32 #define SYSCTYPE        8
33 #define UNDFTYPE        9
34 #define INCLTYPE        10
35 #define SINCTYPE        11
36 #define PASTTYPE        12
37 #define SPASTYPE        13
38 #define INCRTYPE        14
39 #define IFDFTYPE        15
40 #define PUSDTYPE        16
41 #define POPDTYPE        17
42 #define SHIFTYPE        18
43 #define DECRTYPE        19
44 #define DIVRTYPE        20
45 #define UNDVTYPE        21
46 #define DIVNTYPE        22
47 #define MKTMTYPE        23
48 #define ERRPTYPE        24
49 #define M4WRTYPE        25
50 #define TRNLTYPE        26
51 #define DNLNTYPE        27
52 #define DUMPTYPE        28
53 #define CHNCTYPE        29
54 #define INDXTYPE        30
55 #define SYSVTYPE        31
56 #define EXITTYPE        32
57 #define DEFNTYPE        33
58 
59 #define STATIC          128
60 
61 /*
62  * m4 special characters
63  */
64 
65 #define ARGFLAG         '$'
66 #define LPAREN          '('
67 #define RPAREN          ')'
68 #define LQUOTE          '`'
69 #define RQUOTE          '\''
70 #define COMMA           ','
71 #define SCOMMT          '#'
72 #define ECOMMT          '\n'
73 
74 /*
75  * other important constants
76  */
77 
78 #define EOS             (char) 0
79 #define MAXINP          10              /* maximum include files   */
80 #define MAXOUT          10              /* maximum # of diversions */
81 #define MAXSTR          512             /* maximum size of string  */
82 #define BUFSIZE         4096            /* size of pushback buffer */
83 #define STACKMAX        1024            /* size of call stack      */
84 #define STRSPMAX        4096            /* size of string space    */
85 #define MAXTOK          MAXSTR          /* maximum chars in a tokn */
86 #define HASHSIZE        199             /* maximum size of hashtab */
87 
88 #define ALL             1
89 #define TOP             0
90 
91 #define TRUE            1
92 #define FALSE           0
93 #define cycle           for(;;)
94 
95 /*
96  * m4 data structures
97  */
98 
99 typedef struct ndblock *ndptr;
100 
101 struct ndblock {                /* hastable structure         */
102         char    *name;          /* entry name..               */
103         char    *defn;          /* definition..               */
104         int     type;           /* type of the entry..        */
105         ndptr   nxtptr;         /* link to next entry..       */
106 };
107 
108 #define nil     ((ndptr) 0)
109 
110 struct keyblk {
111         char    *knam;          /* keyword name */
112         int     ktyp;           /* keyword type */
113 };
114 
115 typedef union {			/* stack structure */
116 	int	sfra;		/* frame entry  */
117 	char 	*sstr;		/* string entry */
118 } stae;
119 
120 /*
121  * macros for readibility and/or speed
122  *
123  *      gpbc()  - get a possibly pushed-back character
124  *      min()   - select the minimum of two elements
125  *      pushf() - push a call frame entry onto stack
126  *      pushs() - push a string pointer onto stack
127  */
128 #define gpbc() 	 (bp > buf) ? *--bp : getc(infile[ilevel])
129 #define min(x,y) ((x > y) ? y : x)
130 #define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
131 #define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
132 
133 /*
134  *	    .				   .
135  *	|   .	|  <-- sp		|  .  |
136  *	+-------+			+-----+
137  *	| arg 3 ----------------------->| str |
138  *	+-------+			|  .  |
139  *	| arg 2 ---PREVEP-----+ 	   .
140  *	+-------+	      |
141  *	    .		      |		|     |
142  *	+-------+	      | 	+-----+
143  *	| plev	|  PARLEV     +-------->| str |
144  *	+-------+			|  .  |
145  *	| type	|  CALTYP		   .
146  *	+-------+
147  *	| prcf	---PREVFP--+
148  *	+-------+  	   |
149  *	|   .	|  PREVSP  |
150  *	    .	   	   |
151  *	+-------+	   |
152  *	|	<----------+
153  *	+-------+
154  *
155  */
156 #define PARLEV  (mstack[fp].sfra)
157 #define CALTYP  (mstack[fp-1].sfra)
158 #define PREVEP	(mstack[fp+3].sstr)
159 #define PREVSP	(fp-3)
160 #define PREVFP	(mstack[fp-2].sfra)
161