mdef.h revision 1590
11590Srgrimes/* 21590Srgrimes * Copyright (c) 1989, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * This code is derived from software contributed to Berkeley by 61590Srgrimes * Ozan Yigit at York University. 71590Srgrimes * 81590Srgrimes * Redistribution and use in source and binary forms, with or without 91590Srgrimes * modification, are permitted provided that the following conditions 101590Srgrimes * are met: 111590Srgrimes * 1. Redistributions of source code must retain the above copyright 121590Srgrimes * notice, this list of conditions and the following disclaimer. 131590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141590Srgrimes * notice, this list of conditions and the following disclaimer in the 151590Srgrimes * documentation and/or other materials provided with the distribution. 161590Srgrimes * 3. All advertising materials mentioning features or use of this software 171590Srgrimes * must display the following acknowledgement: 181590Srgrimes * This product includes software developed by the University of 191590Srgrimes * California, Berkeley and its contributors. 201590Srgrimes * 4. Neither the name of the University nor the names of its contributors 211590Srgrimes * may be used to endorse or promote products derived from this software 221590Srgrimes * without specific prior written permission. 231590Srgrimes * 241590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341590Srgrimes * SUCH DAMAGE. 351590Srgrimes * 361590Srgrimes * @(#)mdef.h 8.1 (Berkeley) 6/6/93 371590Srgrimes */ 381590Srgrimes 391590Srgrimes#define MACRTYPE 1 401590Srgrimes#define DEFITYPE 2 411590Srgrimes#define EXPRTYPE 3 421590Srgrimes#define SUBSTYPE 4 431590Srgrimes#define IFELTYPE 5 441590Srgrimes#define LENGTYPE 6 451590Srgrimes#define CHNQTYPE 7 461590Srgrimes#define SYSCTYPE 8 471590Srgrimes#define UNDFTYPE 9 481590Srgrimes#define INCLTYPE 10 491590Srgrimes#define SINCTYPE 11 501590Srgrimes#define PASTTYPE 12 511590Srgrimes#define SPASTYPE 13 521590Srgrimes#define INCRTYPE 14 531590Srgrimes#define IFDFTYPE 15 541590Srgrimes#define PUSDTYPE 16 551590Srgrimes#define POPDTYPE 17 561590Srgrimes#define SHIFTYPE 18 571590Srgrimes#define DECRTYPE 19 581590Srgrimes#define DIVRTYPE 20 591590Srgrimes#define UNDVTYPE 21 601590Srgrimes#define DIVNTYPE 22 611590Srgrimes#define MKTMTYPE 23 621590Srgrimes#define ERRPTYPE 24 631590Srgrimes#define M4WRTYPE 25 641590Srgrimes#define TRNLTYPE 26 651590Srgrimes#define DNLNTYPE 27 661590Srgrimes#define DUMPTYPE 28 671590Srgrimes#define CHNCTYPE 29 681590Srgrimes#define INDXTYPE 30 691590Srgrimes#define SYSVTYPE 31 701590Srgrimes#define EXITTYPE 32 711590Srgrimes#define DEFNTYPE 33 721590Srgrimes 731590Srgrimes#define STATIC 128 741590Srgrimes 751590Srgrimes/* 761590Srgrimes * m4 special characters 771590Srgrimes */ 781590Srgrimes 791590Srgrimes#define ARGFLAG '$' 801590Srgrimes#define LPAREN '(' 811590Srgrimes#define RPAREN ')' 821590Srgrimes#define LQUOTE '`' 831590Srgrimes#define RQUOTE '\'' 841590Srgrimes#define COMMA ',' 851590Srgrimes#define SCOMMT '#' 861590Srgrimes#define ECOMMT '\n' 871590Srgrimes 881590Srgrimes#ifdef msdos 891590Srgrimes#define system(str) (-1) 901590Srgrimes#endif 911590Srgrimes 921590Srgrimes/* 931590Srgrimes * other important constants 941590Srgrimes */ 951590Srgrimes 961590Srgrimes#define EOS (char) 0 971590Srgrimes#define MAXINP 10 /* maximum include files */ 981590Srgrimes#define MAXOUT 10 /* maximum # of diversions */ 991590Srgrimes#define MAXSTR 512 /* maximum size of string */ 1001590Srgrimes#define BUFSIZE 4096 /* size of pushback buffer */ 1011590Srgrimes#define STACKMAX 1024 /* size of call stack */ 1021590Srgrimes#define STRSPMAX 4096 /* size of string space */ 1031590Srgrimes#define MAXTOK MAXSTR /* maximum chars in a tokn */ 1041590Srgrimes#define HASHSIZE 199 /* maximum size of hashtab */ 1051590Srgrimes 1061590Srgrimes#define ALL 1 1071590Srgrimes#define TOP 0 1081590Srgrimes 1091590Srgrimes#define TRUE 1 1101590Srgrimes#define FALSE 0 1111590Srgrimes#define cycle for(;;) 1121590Srgrimes 1131590Srgrimes/* 1141590Srgrimes * m4 data structures 1151590Srgrimes */ 1161590Srgrimes 1171590Srgrimestypedef struct ndblock *ndptr; 1181590Srgrimes 1191590Srgrimesstruct ndblock { /* hastable structure */ 1201590Srgrimes char *name; /* entry name.. */ 1211590Srgrimes char *defn; /* definition.. */ 1221590Srgrimes int type; /* type of the entry.. */ 1231590Srgrimes ndptr nxtptr; /* link to next entry.. */ 1241590Srgrimes}; 1251590Srgrimes 1261590Srgrimes#define nil ((ndptr) 0) 1271590Srgrimes 1281590Srgrimesstruct keyblk { 1291590Srgrimes char *knam; /* keyword name */ 1301590Srgrimes int ktyp; /* keyword type */ 1311590Srgrimes}; 1321590Srgrimes 1331590Srgrimestypedef union { /* stack structure */ 1341590Srgrimes int sfra; /* frame entry */ 1351590Srgrimes char *sstr; /* string entry */ 1361590Srgrimes} stae; 1371590Srgrimes 1381590Srgrimes/* 1391590Srgrimes * macros for readibility and/or speed 1401590Srgrimes * 1411590Srgrimes * gpbc() - get a possibly pushed-back character 1421590Srgrimes * pushf() - push a call frame entry onto stack 1431590Srgrimes * pushs() - push a string pointer onto stack 1441590Srgrimes */ 1451590Srgrimes#define gpbc() (bp > bufbase) ? *--bp : getc(infile[ilevel]) 1461590Srgrimes#define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x) 1471590Srgrimes#define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x) 1481590Srgrimes 1491590Srgrimes/* 1501590Srgrimes * . . 1511590Srgrimes * | . | <-- sp | . | 1521590Srgrimes * +-------+ +-----+ 1531590Srgrimes * | arg 3 ----------------------->| str | 1541590Srgrimes * +-------+ | . | 1551590Srgrimes * | arg 2 ---PREVEP-----+ . 1561590Srgrimes * +-------+ | 1571590Srgrimes * . | | | 1581590Srgrimes * +-------+ | +-----+ 1591590Srgrimes * | plev | PARLEV +-------->| str | 1601590Srgrimes * +-------+ | . | 1611590Srgrimes * | type | CALTYP . 1621590Srgrimes * +-------+ 1631590Srgrimes * | prcf ---PREVFP--+ 1641590Srgrimes * +-------+ | 1651590Srgrimes * | . | PREVSP | 1661590Srgrimes * . | 1671590Srgrimes * +-------+ | 1681590Srgrimes * | <----------+ 1691590Srgrimes * +-------+ 1701590Srgrimes * 1711590Srgrimes */ 1721590Srgrimes#define PARLEV (mstack[fp].sfra) 1731590Srgrimes#define CALTYP (mstack[fp-1].sfra) 1741590Srgrimes#define PREVEP (mstack[fp+3].sstr) 1751590Srgrimes#define PREVSP (fp-3) 1761590Srgrimes#define PREVFP (mstack[fp-2].sfra) 177