cpp.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /******************************************************************************
  2. * FREXXWARE
  3. * ----------------------------------------------------------------------------
  4. *
  5. * Project: Frexx C Preprocessor
  6. * $Source: /home/user/start/cpp/RCS/cpp.h,v $
  7. * $Revision: 1.3 $
  8. * $Date: 1993/12/06 13:51:20 $
  9. * $Author: start $
  10. * $State: Exp $
  11. * $Locker: start $
  12. *
  13. * ----------------------------------------------------------------------------
  14. * $Log: cpp.h,v $
  15. * Revision 1.3 1993/12/06 13:51:20 start
  16. * A lot of new stuff (too much to mention)
  17. *
  18. * Revision 1.2 1993/11/11 07:16:39 start
  19. * New stuff
  20. *
  21. * Revision 1.2 1993/11/11 07:16:39 start
  22. * New stuff
  23. *
  24. * Revision 1.1 1993/11/03 09:15:59 start
  25. * Initial revision
  26. *
  27. *
  28. *****************************************************************************/
  29. /*
  30. * I n t e r n a l D e f i n i t i o n s f o r C P P
  31. *
  32. * In general, definitions in this file should not be changed.
  33. */
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #ifndef fpp_toupper
  38. #define fpp_toupper(c) ((c) + ('A' - 'a'))
  39. #endif /* no fpp_toupper */
  40. #ifndef fpp_tolower
  41. #define fpp_tolower(c) ((c) + ('a' - 'A'))
  42. #endif /* no fpp_tolower */
  43. #ifndef FPP_TRUE
  44. #define FPP_TRUE 1
  45. #define FPP_FALSE 0
  46. #endif
  47. #ifndef EOS
  48. /*
  49. * This is predefined in Decus C
  50. */
  51. #define EOS '\0' /* End of string */
  52. #endif
  53. #define EOF_CHAR 0 /* Returned by fpp_get() on eof */
  54. #define NULLST ((char *) NULL) /* Pointer to nowhere (linted) */
  55. #define DEF_NOARGS (-1) /* #define foo vs #define foo() */
  56. /*
  57. * The following may need to change if the host system doesn't use ASCII.
  58. */
  59. #define QUOTE_PARM 0x1C /* Magic quoting operator */
  60. #define DEF_MAGIC 0x1D /* Magic for #defines */
  61. #define TOK_SEP 0x1E /* Token concatenation delim. */
  62. #define COM_SEP 0x1F /* Magic comment separator */
  63. /*
  64. * Note -- in Ascii, the following will map macro formals onto DEL + the
  65. * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
  66. * be ok as long as PAR_MAC is less than 33). Note that the last PAR_MAC
  67. * value is reserved for string substitution.
  68. */
  69. #define MAC_PARM 0x7F /* Macro formals start here */
  70. #ifndef OS9
  71. #if (PAR_MAC >= 33)
  72. #error "assertion fails -- PAR_MAC isn't less than 33"
  73. #endif
  74. #endif
  75. #define LASTPARM (PAR_MAC - 1)
  76. /*
  77. * Character type codes.
  78. */
  79. #define INV 0 /* Invalid, must be zero */
  80. #define OP_EOE INV /* End of expression */
  81. #define DIG 1 /* Digit */
  82. #define LET 2 /* Identifier start */
  83. #define FIRST_BINOP OP_ADD
  84. #define OP_ADD 3
  85. #define OP_SUB 4
  86. #define OP_MUL 5
  87. #define OP_DIV 6
  88. #define OP_MOD 7
  89. #define OP_ASL 8
  90. #define OP_ASR 9
  91. #define OP_AND 10 /* &, not && */
  92. #define OP_OR 11 /* |, not || */
  93. #define OP_XOR 12
  94. #define OP_EQ 13
  95. #define OP_NE 14
  96. #define OP_LT 15
  97. #define OP_LE 16
  98. #define OP_GE 17
  99. #define OP_GT 18
  100. #define OP_ANA 19 /* && */
  101. #define OP_ORO 20 /* || */
  102. #define OP_QUE 21 /* ? */
  103. #define OP_COL 22 /* : */
  104. #define OP_CMA 23 /* , (relevant?) */
  105. #define LAST_BINOP OP_CMA /* Last binary operand */
  106. /*
  107. * The following are unary.
  108. */
  109. #define FIRST_UNOP OP_PLU /* First Unary operand */
  110. #define OP_PLU 24 /* + (draft ANSI standard) */
  111. #define OP_NEG 25 /* - */
  112. #define OP_COM 26 /* ~ */
  113. #define OP_NOT 27 /* ! */
  114. #define LAST_UNOP OP_NOT
  115. #define OP_LPA 28 /* ( */
  116. #define OP_RPA 29 /* ) */
  117. #define OP_END 30 /* End of expression marker */
  118. #define OP_MAX (OP_END + 1) /* Number of operators */
  119. #define OP_FAIL (OP_END + 1) /* For error returns */
  120. /*
  121. * The following are for lexical scanning only.
  122. */
  123. #define QUO 65 /* Both flavors of quotation */
  124. #define DOT 66 /* . might start a number */
  125. #define SPA 67 /* Space and tab */
  126. #define BSH 68 /* Just a backslash */
  127. #define END 69 /* EOF */
  128. /*
  129. * These bits are set in ifstack[]
  130. */
  131. #define WAS_COMPILING 1 /* FPP_TRUE if compile set at entry */
  132. #define ELSE_SEEN 2 /* FPP_TRUE when #else processed */
  133. #define FPP_TRUE_SEEN 4 /* FPP_TRUE when #if FPP_TRUE processed */
  134. /*
  135. * Define bits for the basic types and their adjectives
  136. */
  137. #define T_CHAR 1
  138. #define T_INT 2
  139. #define T_FLOAT 4
  140. #define T_DOUBLE 8
  141. #define T_SHORT 16
  142. #define T_LONG 32
  143. #define T_SIGNED 64
  144. #define T_UNSIGNED 128
  145. #define T_PTR 256 /* Pointer */
  146. #define T_FPTR 512 /* Pointer to functions */
  147. /*
  148. * The DEFBUF structure stores information about #defined
  149. * macros. Note that the defbuf->repl information is always
  150. * in malloc storage.
  151. */
  152. typedef struct defbuf {
  153. struct defbuf *link; /* Next define in chain */
  154. char *repl; /* -> replacement */
  155. int hash; /* Symbol table hash */
  156. int nargs; /* For define(args) */
  157. char name[1]; /* #define name */
  158. } DEFBUF;
  159. /*
  160. * The FILEINFO structure stores information about open files
  161. * and macros being expanded.
  162. */
  163. typedef struct fileinfo {
  164. char *bptr; /* Buffer pointer */
  165. int line; /* for include or macro */
  166. FILE *fp; /* File if non-null */
  167. struct fileinfo *parent; /* Link to includer */
  168. char *filename; /* File/macro name */
  169. char *progname; /* From #line statement */
  170. unsigned int unrecur; /* For macro recursion */
  171. char buffer[1]; /* current input line */
  172. } FILEINFO;
  173. /*
  174. * The SIZES structure is used to store the values for #if sizeof
  175. */
  176. typedef struct sizes {
  177. short bits; /* If this bit is set, */
  178. short size; /* this is the datum size value */
  179. short psize; /* this is the pointer size */
  180. } SIZES;
  181. /*
  182. * nomacarg is a built-in #define on Decus C.
  183. */
  184. #ifdef nomacarg
  185. #define cput generate /* cput concatenates tokens */
  186. #else
  187. #if COMMENT_INVISIBLE
  188. #define cput(c) { if (c != TOK_SEP && c != COM_SEP) putchar(c); }
  189. #else
  190. #define cput(c) { if (c != TOK_SEP) putchar(c); }
  191. #endif
  192. #endif
  193. #ifndef nomacarg
  194. #define streq(s1, s2) (strcmp(s1, s2) == 0)
  195. #endif
  196. /*
  197. * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
  198. */
  199. #ifndef IO_NORMAL
  200. #define IO_NORMAL 0
  201. #endif
  202. #ifndef IO_ERROR
  203. #define IO_ERROR 1
  204. #endif
  205. /*
  206. * Externs
  207. */
  208. #include "fpp.h" /* structs and defines */
  209. #include "cppadd.h" /* Added prototypes for ANSI complience! */
  210. #ifdef AMIGA
  211. #include <dos.h>
  212. extern int _OSERR;
  213. #endif
  214. extern char type[]; /* Character classifier */
  215. #define compiling global->ifstack[0]
  216. #if DEBUG
  217. extern int debug; /* Debug level */
  218. #endif
  219. extern SIZES size_table[]; /* For #if sizeof sizes */
  220. #define MAX_SPACE_SIZE 512 /* maximum number of whitespaces possible
  221. to remember */