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