home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 138.lha / M4 / Sources / mdef.h < prev    next >
C/C++ Source or Header  |  1986-11-20  |  5KB  |  183 lines

  1. /*
  2.  * mdef.h
  3.  * Facility: m4 macro processor
  4.  * by: oz
  5.  */
  6. #define unix 1 /* should be here so i don't have to rewrite all the code. */
  7. #ifndef unix
  8. #define unix 0
  9. #endif 
  10. #ifndef vms
  11. #define vms 0
  12. #endif
  13. #if vms
  14. #include stdio
  15. #include ctype
  16. #include signal
  17. #else 
  18. #include <stdio.h>
  19. #include <ctype.h>
  20. #include <signal.h>
  21. #include <stdlib.h>
  22. #endif
  23. /*
  24.  *
  25.  * m4 constants..
  26.  *
  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.  * m4 special characters
  66.  */
  67.  
  68. #define ARGFLAG         '$'
  69. #define LPAREN          '('
  70. #define RPAREN          ')'
  71. #define LQUOTE          '`'
  72. #define RQUOTE          '\''
  73. #define COMMA           ','
  74. #define SCOMMT          '#'
  75. #define ECOMMT          '\n'
  76. /*
  77.  * definitions of diversion files. If the name of
  78.  * the file is changed, adjust UNIQUE to point to the
  79.  * wildcard (*) character in the filename.
  80.  */
  81. #if unix
  82. #define DIVNAM  "/tmp/m4*XXXXXX"        /* unix diversion files    */
  83. #define UNIQUE          7               /* unique char location    */
  84. #else
  85. #if vms
  86. #define DIVNAM  "sys$login:m4*XXXXXX"   /* vms diversion files     */
  87. #define UNIQUE          12              /* unique char location    */
  88. #else
  89. #if amiga
  90. #define DIVNAM  "t:M4*XXXXXX"           /* msdos diversion files   */
  91. #define UNIQUE      4                   /* unique char location    */
  92. #else
  93. #define DIVNAM  "/M4*XXXXXX"            /* msdos diversion files   */
  94. #define UNIQUE      3                   /* unique char location    */
  95. #endif
  96. #endif
  97. #endif
  98. /*
  99.  * other important constants
  100.  */
  101. #define EOS             (char) 0
  102. #define MAXINP          10              /* maximum include files   */
  103. #define MAXOUT          10              /* maximum # of diversions */
  104. #define MAXSTR          512             /* maximum size of string  */
  105. #define BUFSIZE         4096            /* size of pushback buffer */
  106. #define STACKMAX        1024            /* size of call stack      */
  107. #define STRSPMAX        4096            /* size of string space    */
  108. #define MAXTOK          MAXSTR          /* maximum chars in a tokn */
  109. #define HASHSIZE        199             /* maximum size of hashtab */
  110.  
  111. #define ALL             1
  112. #define TOP             0
  113.  
  114. #define TRUE            1
  115. #define FALSE           0
  116. #define cycle           for(;;)
  117. #ifdef VOID
  118. #define void            int             /* define if void is void. */
  119. #endif
  120. /*
  121.  * m4 data structures
  122.  */
  123.  
  124. typedef struct ndblock *ndptr;
  125.  
  126. struct ndblock {                /* hastable structure         */
  127.         char    *name;          /* entry name..               */
  128.         char    *defn;          /* definition..               */
  129.         int     type;           /* type of the entry..        */
  130.         ndptr   nxtptr;         /* link to next entry..       */
  131. };
  132.  
  133. #define nil     ((ndptr) 0)
  134.  
  135. struct keyblk {
  136.         char    *knam;          /* keyword name */
  137.         int     ktyp;           /* keyword type */
  138. };
  139. typedef union {                 /* stack structure */
  140.         int     sfra;           /* frame entry  */
  141.         char    *sstr;          /* string entry */
  142. } stae;
  143. /*
  144.  * macros for readibility and/or speed
  145.  *
  146.  *      gpbc()  - get a possibly pushed-back character
  147.  *      min()   - select the minimum of two elements
  148.  *      pushf() - push a call frame entry onto stack
  149.  *      pushs() - push a string pointer onto stack
  150.  */
  151. #define gpbc()   (bp > buf) ? *--bp : getc(infile[ilevel])
  152. /* #define min(x,y) ((x > y) ? y : x) defined in stdio.h.. */
  153. #define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
  154. #define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
  155. /*
  156.  *          .                              .
  157.  *      |   .   |  <-- sp               |  .  |
  158.  *      +-------+                       +-----+
  159.  *      | arg 3 ----------------------->| str |
  160.  *      +-------+                       |  .  |
  161.  *      | arg 2 ---PREVEP-----+            .
  162.  *      +-------+             |
  163.  *          .                 |         |     |
  164.  *      +-------+             |         +-----+
  165.  *      | plev  |  PARLEV     +-------->| str |
  166.  *      +-------+                       |  .  |
  167.  *      | type  |  CALTYP                  .
  168.  *      +-------+
  169.  *      | prcf  ---PREVFP--+
  170.  *      +-------+          |
  171.  *      |   .   |  PREVSP  |
  172.  *          .              |
  173.  *      +-------+          |
  174.  *      |       <----------+
  175.  *      +-------+
  176.  *
  177.  */
  178. #define PARLEV  (mstack[fp].sfra)
  179. #define CALTYP  (mstack[fp-1].sfra)
  180. #define PREVEP  (mstack[fp+3].sstr)
  181. #define PREVSP  (fp-3)
  182. #define PREVFP  (mstack[fp-2].sfra)
  183.