home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / m4 / part01 / mdef.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-02-27  |  4.6 KB  |  195 lines

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