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