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