home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / m4 / mdef.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-20  |  5.6 KB  |  187 lines

  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.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  *
  36.  *    @(#)mdef.h    5.6 (Berkeley) 2/26/91
  37.  */
  38.  
  39. /*
  40.  * mdef.h
  41.  * Facility: m4 macro processor
  42.  * by: oz
  43.  */
  44.  
  45. /*
  46.  *
  47.  * m4 constants..
  48.  *
  49.  */
  50.  
  51. #define MACRTYPE        1
  52. #define DEFITYPE        2
  53. #define EXPRTYPE        3
  54. #define SUBSTYPE        4
  55. #define IFELTYPE        5
  56. #define LENGTYPE        6
  57. #define CHNQTYPE        7
  58. #define SYSCTYPE        8
  59. #define UNDFTYPE        9
  60. #define INCLTYPE        10
  61. #define SINCTYPE        11
  62. #define PASTTYPE        12
  63. #define SPASTYPE        13
  64. #define INCRTYPE        14
  65. #define IFDFTYPE        15
  66. #define PUSDTYPE        16
  67. #define POPDTYPE        17
  68. #define SHIFTYPE        18
  69. #define DECRTYPE        19
  70. #define DIVRTYPE        20
  71. #define UNDVTYPE        21
  72. #define DIVNTYPE        22
  73. #define MKTMTYPE        23
  74. #define ERRPTYPE        24
  75. #define M4WRTYPE        25
  76. #define TRNLTYPE        26
  77. #define DNLNTYPE        27
  78. #define DUMPTYPE        28
  79. #define CHNCTYPE        29
  80. #define INDXTYPE        30
  81. #define SYSVTYPE        31
  82. #define EXITTYPE        32
  83. #define DEFNTYPE        33
  84.  
  85. #define STATIC          128
  86.  
  87. /*
  88.  * m4 special characters
  89.  */
  90.  
  91. #define ARGFLAG         '$'
  92. #define LPAREN          '('
  93. #define RPAREN          ')'
  94. #define LQUOTE          '`'
  95. #define RQUOTE          '\''
  96. #define COMMA           ','
  97. #define SCOMMT          '#'
  98. #define ECOMMT          '\n'
  99.  
  100. /*
  101.  * other important constants
  102.  */
  103.  
  104. #define EOS             (char) 0
  105. #define MAXINP          10              /* maximum include files   */
  106. #define MAXOUT          10              /* maximum # of diversions */
  107. #define MAXSTR          512             /* maximum size of string  */
  108. #define BUFSIZE         4096            /* size of pushback buffer */
  109. #define STACKMAX        1024            /* size of call stack      */
  110. #define STRSPMAX        4096            /* size of string space    */
  111. #define MAXTOK          MAXSTR          /* maximum chars in a tokn */
  112. #define HASHSIZE        199             /* maximum size of hashtab */
  113.  
  114. #define ALL             1
  115. #define TOP             0
  116.  
  117. #define TRUE            1
  118. #define FALSE           0
  119. #define cycle           for(;;)
  120.  
  121. /*
  122.  * m4 data structures
  123.  */
  124.  
  125. typedef struct ndblock *ndptr;
  126.  
  127. struct ndblock {                /* hastable structure         */
  128.         char    *name;          /* entry name..               */
  129.         char    *defn;          /* definition..               */
  130.         int     type;           /* type of the entry..        */
  131.         ndptr   nxtptr;         /* link to next entry..       */
  132. };
  133.  
  134. #define nil     ((ndptr) 0)
  135.  
  136. struct keyblk {
  137.         char    *knam;          /* keyword name */
  138.         int     ktyp;           /* keyword type */
  139. };
  140.  
  141. typedef union {            /* stack structure */
  142.     int    sfra;        /* frame entry  */
  143.     char     *sstr;        /* string entry */
  144. } stae;
  145.  
  146. /*
  147.  * macros for readibility and/or speed
  148.  *
  149.  *      gpbc()  - get a possibly pushed-back character
  150.  *      min()   - select the minimum of two elements
  151.  *      pushf() - push a call frame entry onto stack
  152.  *      pushs() - push a string pointer onto stack
  153.  */
  154. #define gpbc()      (bp > buf) ? *--bp : getc(infile[ilevel])
  155. #define min(x,y) ((x > y) ? y : x)
  156. #define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
  157. #define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
  158.  
  159. /*
  160.  *        .                   .
  161.  *    |   .    |  <-- sp        |  .  |
  162.  *    +-------+            +-----+
  163.  *    | arg 3 ----------------------->| str |
  164.  *    +-------+            |  .  |
  165.  *    | arg 2 ---PREVEP-----+        .
  166.  *    +-------+          |
  167.  *        .              |        |     |
  168.  *    +-------+          |     +-----+
  169.  *    | plev    |  PARLEV     +-------->| str |
  170.  *    +-------+            |  .  |
  171.  *    | type    |  CALTYP           .
  172.  *    +-------+
  173.  *    | prcf    ---PREVFP--+
  174.  *    +-------+         |
  175.  *    |   .    |  PREVSP  |
  176.  *        .              |
  177.  *    +-------+       |
  178.  *    |    <----------+
  179.  *    +-------+
  180.  *
  181.  */
  182. #define PARLEV  (mstack[fp].sfra)
  183. #define CALTYP  (mstack[fp-1].sfra)
  184. #define PREVEP    (mstack[fp+3].sstr)
  185. #define PREVSP    (fp-3)
  186. #define PREVFP    (mstack[fp-2].sfra)
  187.