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