mdef.h revision 1.4
1/*  Header : mdef.h
2    Author : Ozan Yigit
3    Updated: 4 May 1992
4*/
5#ifndef	MACRTYPE
6
7#ifndef unix
8#define unix 0
9#endif
10
11#ifndef vms
12#define vms 0
13#endif
14
15#include <stdio.h>
16#include <signal.h>
17
18#ifdef	__STDC__
19#include <string.h>
20#else
21#ifdef	VOID
22#define void	int
23#endif
24extern	int	strlen();
25extern	int	strcmp();
26extern	void	memcpy();
27#endif
28
29/*  m4 constants */
30
31#define MACRTYPE        1
32#define DEFITYPE        2
33#define EXPRTYPE        3
34#define SUBSTYPE        4
35#define IFELTYPE        5
36#define LENGTYPE        6
37#define CHNQTYPE        7
38#define SYSCTYPE        8
39#define UNDFTYPE        9
40#define INCLTYPE        10
41#define SINCTYPE        11
42#define PASTTYPE        12
43#define SPASTYPE        13
44#define INCRTYPE        14
45#define IFDFTYPE        15
46#define PUSDTYPE        16
47#define POPDTYPE        17
48#define SHIFTYPE        18
49#define DECRTYPE        19
50#define DIVRTYPE        20
51#define UNDVTYPE        21
52#define DIVNTYPE        22
53#define MKTMTYPE        23
54#define ERRPTYPE        24
55#define M4WRTYPE        25
56#define TRNLTYPE        26
57#define DNLNTYPE        27
58#define DUMPTYPE        28
59#define CHNCTYPE        29
60#define INDXTYPE        30
61#define SYSVTYPE        31
62#define EXITTYPE        32
63#define DEFNTYPE        33
64#define LINETYPE	34
65#define TRIMTYPE	35
66#define TLITTYPE	36
67#define	DEFQTYPE	37		/* defquote */
68#define QUTRTYPE	38		/* quoter thus defined */
69
70#define STATIC          128
71
72/* m4 special characters */
73
74#define ARGFLAG         '$'
75#define LPAREN          '('
76#define RPAREN          ')'
77#define LQUOTE          '`'
78#define RQUOTE          '\''
79#define	VQUOTE		('V'&(' '- 1))
80#define COMMA           ','
81#define SCOMMT          '#'
82#define ECOMMT          '\n'
83
84/*
85 * other important constants
86 */
87
88#define EOS             (char) 0
89#define MAXINP          10              /* maximum include files   */
90#define MAXOUT          10              /* maximum # of diversions */
91#ifdef	SMALL
92#define MAXSTR           512            /* maximum size of string  */
93#define BUFSIZE         4096            /* size of pushback buffer */
94#define STACKMAX        1024            /* size of call stack      */
95#define STRSPMAX        4096            /* size of string space    */
96#define HASHSIZE         199            /* maximum size of hashtab */
97#else
98#define MAXSTR          1024            /* maximum size of string  */
99#define BUFSIZE         8192            /* size of pushback buffer */
100#define STACKMAX        2048            /* size of call stack      */
101#define STRSPMAX        8192            /* size of string space    */
102#define HASHSIZE         509            /* maximum size of hashtab */
103#endif
104#define MAXTOK          MAXSTR          /* maximum chars in a tokn */
105
106#define ALL             1
107#define TOP             0
108
109#define TRUE            1
110#define FALSE           0
111
112/* m4 data structures */
113
114typedef struct ndblock *ndptr;
115
116struct ndblock                  /* hashtable structure        */
117    {
118        char    *name;          /* entry name..               */
119        char    *defn;          /* definition..               */
120        int     type;           /* type of the entry..        */
121        ndptr   nxtptr;         /* link to next entry..       */
122    };
123
124#define nil     ((ndptr) 0)
125
126typedef union			/* stack structure */
127    {	int	sfra;		/* frame entry  */
128	char 	*sstr;		/* string entry */
129    } stae;
130
131/*
132 * macros for readibility and/or speed
133 *
134 *      gpbc()  - get a possibly pushed-back character
135 *      min()   - select the minimum of two elements
136 *      pushf() - push a call frame entry onto stack
137 *      pushs() - push a string pointer onto stack
138 */
139#define gpbc() 	 bp == bb ? getc(infile[ilevel]) : *--bp
140#define min(x,y) ((x > y) ? y : x)
141#define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
142#define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
143
144/*
145 *	    .				   .
146 *	|   .	|  <-- sp		|  .  |
147 *	+-------+			+-----+
148 *	| arg 3 ----------------------->| str |
149 *	+-------+			|  .  |
150 *	| arg 2 ---PREVEP-----+ 	   .
151 *	+-------+	      |
152 *	    .		      |		|     |
153 *	+-------+	      | 	+-----+
154 *	| plev	|  PARLEV     +-------->| str |
155 *	+-------+			|  .  |
156 *	| type	|  CALTYP		   .
157 *	+-------+
158 *	| prcf	---PREVFP--+
159 *	+-------+  	   |
160 *	|   .	|  PREVSP  |
161 *	    .	   	   |
162 *	+-------+	   |
163 *	|	<----------+
164 *	+-------+
165 *
166 */
167#define PARLEV  (mstack[fp].sfra)
168#define CALTYP  (mstack[fp-1].sfra)
169#define PREVEP	(mstack[fp+3].sstr)
170#define PREVSP	(fp-3)
171#define PREVFP	(mstack[fp-2].sfra)
172
173#endif
174