Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.bin / m4 / mdef.h
1 /*      $OpenBSD: mdef.h,v 1.21 2001/09/27 11:40:33 espie Exp $ */
2 /*      $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $      */
3
4 /*
5  * Copyright (c) 1989, 1993
6  *      The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Ozan Yigit at York University.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *      @(#)mdef.h      8.1 (Berkeley) 6/6/93
40  * $FreeBSD: src/usr.bin/m4/mdef.h,v 1.3.12.2 2002/07/15 02:06:15 jmallett Exp $
41  */
42
43 #define MACRTYPE        1
44 #define DEFITYPE        2
45 #define EXPRTYPE        3
46 #define SUBSTYPE        4
47 #define IFELTYPE        5
48 #define LENGTYPE        6
49 #define CHNQTYPE        7
50 #define SYSCTYPE        8
51 #define UNDFTYPE        9
52 #define INCLTYPE        10
53 #define SINCTYPE        11
54 #define PASTTYPE        12
55 #define SPASTYPE        13
56 #define INCRTYPE        14
57 #define IFDFTYPE        15
58 #define PUSDTYPE        16
59 #define POPDTYPE        17
60 #define SHIFTYPE        18
61 #define DECRTYPE        19
62 #define DIVRTYPE        20
63 #define UNDVTYPE        21
64 #define DIVNTYPE        22
65 #define MKTMTYPE        23
66 #define ERRPTYPE        24
67 #define M4WRTYPE        25
68 #define TRNLTYPE        26
69 #define DNLNTYPE        27
70 #define DUMPTYPE        28
71 #define CHNCTYPE        29
72 #define INDXTYPE        30
73 #define SYSVTYPE        31
74 #define EXITTYPE        32
75 #define DEFNTYPE        33
76 #define SELFTYPE        34
77 #define INDIRTYPE       35
78 #define BUILTINTYPE     36
79 #define PATSTYPE        37
80 #define FILENAMETYPE    38
81 #define LINETYPE        39
82 #define REGEXPTYPE      40
83 #define ESYSCMDTYPE     41
84 #define TRACEONTYPE     42
85 #define TRACEOFFTYPE    43
86
87  
88 #define TYPEMASK        63      /* Keep bits really corresponding to a type. */
89 #define RECDEF          256     /* Pure recursive def, don't expand it */
90 #define NOARGS          512     /* builtin needs no args */
91 #define NEEDARGS        1024    /* mark builtin that need args with this */
92
93 /*
94  * m4 special characters
95  */
96  
97 #define ARGFLAG         '$'
98 #define LPAREN          '('
99 #define RPAREN          ')'
100 #define LQUOTE          '`'
101 #define RQUOTE          '\''
102 #define COMMA           ','
103 #define SCOMMT          '#'
104 #define ECOMMT          '\n'
105
106 #ifdef msdos
107 #define system(str)     (-1)
108 #endif
109
110 /*
111  * other important constants
112  */
113
114 #define EOS             '\0'
115 #define MAXINP          10              /* maximum include files            */
116 #define MAXOUT          10              /* maximum # of diversions          */
117 #define BUFSIZE         4096            /* starting size of pushback buffer */
118 #define INITSTACKMAX    4096            /* starting size of call stack      */
119 #define STRSPMAX        4096            /* starting size of string space    */
120 #define MAXTOK          512             /* maximum chars in a tokn          */
121 #define HASHSIZE        199             /* maximum size of hashtab          */
122 #define MAXCCHARS       5               /* max size of comment/quote delim  */
123  
124 #define ALL             1
125 #define TOP             0
126  
127 #define TRUE            1
128 #define FALSE           0
129 #define cycle           for(;;)
130
131 /*
132  * m4 data structures
133  */
134  
135 typedef struct ndblock *ndptr;
136  
137 struct ndblock {                /* hastable structure         */
138         char            *name;  /* entry name..               */
139         char            *defn;  /* definition..               */
140         unsigned int    type;   /* type of the entry..        */
141         unsigned int    hv;     /* hash function value..      */
142         ndptr           nxtptr; /* link to next entry..       */
143 };
144  
145 #define nil     ((ndptr) 0)
146  
147 struct keyblk {
148         const char    *knam;    /* keyword name */
149         int     ktyp;           /* keyword type */
150 };
151
152 typedef union {                 /* stack structure */
153         int     sfra;           /* frame entry  */
154         char    *sstr;          /* string entry */
155 } stae;
156
157 struct input_file {
158         FILE            *file;
159         char            *name;
160         unsigned long   lineno;
161         int             c;
162 };
163
164 #define CURRENT_NAME    (infile[ilevel].name)
165 #define CURRENT_LINE    (infile[ilevel].lineno)
166 /*
167  * macros for readibility and/or speed
168  *
169  *      pushf() - push a call frame entry onto stack
170  *      pushs() - push a string pointer onto stack
171  */
172 #define pushf(x)                                        \
173         do {                                            \
174                 if ((uintptr_t)++sp == STACKMAX)        \
175                         enlarge_stack();                \
176                 mstack[sp].sfra = (x);                  \
177                 sstack[sp] = 0;                         \
178         } while (0)
179
180 #define pushs(x)                                        \
181         do {                                            \
182                 if ((uintptr_t)++sp == STACKMAX)        \
183                         enlarge_stack();                \
184                 mstack[sp].sstr = (x);                  \
185                 sstack[sp] = 1;                         \
186         } while (0)
187
188 #define pushs1(x)                                       \
189         do {                                            \
190                 if ((uintptr_t)++sp == STACKMAX)        \
191                         enlarge_stack();                \
192                 mstack[sp].sstr = (x);                  \
193                 sstack[sp] = 0;                         \
194         } while (0)
195
196 /*
197  *          .                              .
198  *      |   .   |  <-- sp               |  .  |
199  *      +-------+                       +-----+
200  *      | arg 3 ----------------------->| str |
201  *      +-------+                       |  .  |
202  *      | arg 2 ---PREVEP-----+            .
203  *      +-------+             |
204  *          .                 |         |     |
205  *      +-------+             |         +-----+
206  *      | plev  |  PARLEV     +-------->| str |
207  *      +-------+                       |  .  |
208  *      | type  |  CALTYP                  .
209  *      +-------+
210  *      | prcf  ---PREVFP--+
211  *      +-------+          |
212  *      |   .   |  PREVSP  |
213  *          .              |
214  *      +-------+          |
215  *      |       <----------+
216  *      +-------+
217  *
218  */
219 #define PARLEV  (mstack[fp].sfra)
220 #define CALTYP  (mstack[fp-1].sfra)
221 #define PREVEP  (mstack[fp+3].sstr)
222 #define PREVSP  (fp-3)
223 #define PREVFP  (mstack[fp-2].sfra)