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