cppadd.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /******************************************************************************
  2. * FREXXWARE
  3. * ----------------------------------------------------------------------------
  4. *
  5. * Project: Frexx C Preprocessor
  6. * $Source: /home/user/start/cpp/RCS/cppadd.h,v $
  7. * $Revision: 1.5 $
  8. * $Date: 1994/01/24 09:38:12 $
  9. * $Author: start $
  10. * $State: Exp $
  11. * $Locker: start $
  12. *
  13. * ----------------------------------------------------------------------------
  14. * $Log: cppadd.h,v $
  15. * Revision 1.5 1994/01/24 09:38:12 start
  16. * Added the 'rightconcat' in the global structure.
  17. *
  18. * Revision 1.4 1993/12/06 13:51:20 start
  19. * A lot of new stuff (too much to mention)
  20. *
  21. * Revision 1.3 1993/11/29 14:01:13 start
  22. * New features added
  23. *
  24. * Revision 1.2 1993/11/11 07:16:39 start
  25. * New stuff
  26. *
  27. * Revision 1.1 1993/11/03 09:15:59 start
  28. * Initial revision
  29. *
  30. *
  31. *****************************************************************************/
  32. /**********************************************************************
  33. *
  34. * cppadd.h
  35. *
  36. * Prototypes and structures added by Daniel Stenberg.
  37. *
  38. *******/
  39. #include <stdarg.h>
  40. #include "memory.h"
  41. struct Global {
  42. /*
  43. * Commonly used global variables:
  44. * line is the current input line number.
  45. * wrongline is set in many places when the actual output
  46. * line is out of sync with the numbering, e.g,
  47. * when expanding a macro with an embedded newline.
  48. *
  49. * tokenbuf holds the last identifier scanned (which might
  50. * be a candidate for macro expansion).
  51. * errors is the running cpp error counter.
  52. * infile is the head of a linked list of input files (extended by
  53. * #include and macros being expanded). infile always points
  54. * to the current file/macro. infile->parent to the includer,
  55. * etc. infile->fd is NULL if this input stream is a macro.
  56. */
  57. int line; /* Current line number */
  58. int wrongline; /* Force #line to compiler */
  59. char *tokenbuf; /* Buffer for current input token */
  60. char *functionname; /* Buffer for current function */
  61. int funcline; /* Line number of current function */
  62. int tokenbsize; /* Allocated size of tokenbuf, */
  63. /* not counting zero at end. */
  64. int errors; /* cpp error counter */
  65. FILEINFO *infile; /* Current input file */
  66. #if DEBUG
  67. int debug; /* FPP_TRUE if debugging now */
  68. #endif
  69. /*
  70. * This counter is incremented when a macro expansion is initiated.
  71. * If it exceeds a built-in value, the expansion stops -- this tests
  72. * for a runaway condition:
  73. * #define X Y
  74. * #define Y X
  75. * X
  76. * This can be disabled by falsifying rec_recover. (Nothing does this
  77. * currently: it is a hook for an eventual invocation flag.)
  78. */
  79. int recursion; /* Infinite recursion counter */
  80. int rec_recover; /* Unwind recursive macros */
  81. /*
  82. * instring is set FPP_TRUE when a string is scanned. It modifies the
  83. * behavior of the "get next character" routine, causing all characters
  84. * to be passed to the caller (except <DEF_MAGIC>). Note especially that
  85. * comments and \<newline> are not removed from the source. (This
  86. * prevents cpp output lines from being arbitrarily long).
  87. *
  88. * inmacro is set by #define -- it absorbs comments and converts
  89. * form-feed and vertical-tab to space, but returns \<newline>
  90. * to the caller. Strictly speaking, this is a bug as \<newline>
  91. * shouldn't delimit tokens, but we'll worry about that some other
  92. * time -- it is more important to prevent infinitly long output lines.
  93. *
  94. * instring and inmarcor are parameters to the fpp_get() routine which
  95. * were made global for speed.
  96. */
  97. int instring; /* FPP_TRUE if scanning string */
  98. int inmacro; /* FPP_TRUE if #defining a macro */
  99. /*
  100. * work[] and workp are used to store one piece of text in a temporay
  101. * buffer. To initialize storage, set workp = work. To store one
  102. * character, call fpp_save(c); (This will fatally exit if there isn't
  103. * room.) To terminate the string, call fpp_save(EOS). Note that
  104. * the work buffer is used by several subroutines -- be sure your
  105. * data won't be overwritten. The extra byte in the allocation is
  106. * needed for string formal replacement.
  107. */
  108. char work[NWORK + 1]; /* Work buffer */
  109. char *workp; /* Work buffer pointer */
  110. /*
  111. * keepcomments is set FPP_TRUE by the -C option. If FPP_TRUE, comments
  112. * are written directly to the output stream. This is needed if
  113. * the output from cpp is to be passed to lint (which uses commands
  114. * embedded in comments). cflag contains the permanent state of the
  115. * -C flag. keepcomments is always falsified when processing #control
  116. * commands and when compilation is supressed by a false #if
  117. *
  118. * If eflag is set, CPP returns "success" even if non-fatal errors
  119. * were detected.
  120. *
  121. * If nflag is non-zero, no symbols are predefined except __LINE__.
  122. * __FILE__, and __DATE__. If nflag > 1, absolutely no symbols
  123. * are predefined.
  124. */
  125. char keepcomments; /* Write out comments flag */
  126. char cflag; /* -C option (keep comments) */
  127. char eflag; /* -E option (never fail) */
  128. char nflag; /* -N option (no predefines) */
  129. char wflag; /* -W option (write #defines) */
  130. /*
  131. * ifstack[] holds information about nested #if's. It is always
  132. * accessed via *ifptr. The information is as follows:
  133. * WAS_COMPILING state of compiling flag at outer level.
  134. * ELSE_SEEN set FPP_TRUE when #else seen to prevent 2nd #else.
  135. * FPP_TRUE_SEEN set FPP_TRUE when #if or #elif succeeds
  136. * ifstack[0] holds the compiling flag. It is FPP_TRUE if compilation
  137. * is currently enabled. Note that this must be initialized FPP_TRUE.
  138. */
  139. char ifstack[BLK_NEST]; /* #if information */
  140. char *ifptr; /* -> current ifstack[] */
  141. /*
  142. * incdir[] stores the -i directories (and the system-specific
  143. * #include <...> directories.
  144. */
  145. char *incdir[NINCLUDE]; /* -i directories */
  146. char **incend; /* -> free space in incdir[] */
  147. /*
  148. * include[] stores the -X and -x files.
  149. */
  150. char *include[NINCLUDE];
  151. char includeshow[NINCLUDE]; /* show it or not! */
  152. unsigned included;
  153. /*
  154. * This is the table used to predefine target machine and operating
  155. * system designators. It may need hacking for specific circumstances.
  156. * Note: it is not clear that this is part of the Ansi Standard.
  157. * The -B option supresses preset definitions.
  158. */
  159. char *preset[5]; /* names defined at cpp start */
  160. /*
  161. * The value of these predefined symbols must be recomputed whenever
  162. * they are evaluated. The order must not be changed.
  163. */
  164. char *magic[5]; /* Note: order is important */
  165. /*
  166. * This is the variable saying if Cpp should remove C++ style comments from
  167. * the output. Default is... FPP_TRUE, yes, pronto, do it!!!
  168. */
  169. char cplusplus;
  170. char *sharpfilename;
  171. /*
  172. * parm[], parmp, and parlist[] are used to store #define() argument
  173. * lists. nargs contains the actual number of parameters stored.
  174. */
  175. char parm[NPARMWORK + 1]; /* define param work buffer */
  176. char *parmp; /* Free space in parm */
  177. char *parlist[LASTPARM]; /* -> start of each parameter */
  178. int nargs; /* Parameters for this macro */
  179. DEFBUF *macro; /* Catches start of infinite macro */
  180. DEFBUF *symtab[SBSIZE]; /* Symbol table queue headers */
  181. int evalue; /* Current value from fpp_evallex() */
  182. void (*depends)(char *filename, void *); /* depends function */
  183. char *(*input)(char *, int, void *); /* Input function */
  184. char *first_file; /* Preprocessed file. */
  185. void *userdata; /* Data sent to input function */
  186. void (*output)(int, void *); /* output function */
  187. void (*error)(void *, char *, va_list); /* error function */
  188. char linelines;
  189. char warnillegalcpp; /* warn for illegal preprocessor instructions? */
  190. char outputLINE; /* output 'line' in #line instructions */
  191. char showversion; /* display version */
  192. char showincluded; /* display included files */
  193. char showbalance; /* display paren balance */
  194. char showspace; /* display all whitespaces as they are */
  195. char comment; /* FPP_TRUE if a comment just has been written to output */
  196. char *spacebuf; /* Buffer to store whitespaces in if -H */
  197. long chpos; /* Number of whitespaces in buffer */
  198. char nestcomments; /* Allow nested comments */
  199. char warnnestcomments; /* Warn at nested comments */
  200. char warnnoinclude; /* Warn at missing include file */
  201. char outputfile; /* output the main file */
  202. char out; /* should we output anything now? */
  203. char rightconcat; /* should the right part of a concatenation be avaluated
  204. before the concat (FPP_TRUE) or after (FPP_FALSE) */
  205. char *initialfunc; /* file to include first in all functions */
  206. char *excludedinit[20]; /* functions (names) excluded from the initfunc */
  207. int excluded;
  208. char outputfunctions; /* output all discovered functions to stderr! */
  209. char webmode; /* WWW process mode */
  210. char allowincludelocal;
  211. FILE* (*openfile)(char *,char *, void *);
  212. };
  213. typedef enum {
  214. ERROR_STRING_MUST_BE_IF,
  215. ERROR_STRING_MAY_NOT_FOLLOW_ELSE,
  216. ERROR_ERROR,
  217. ERROR_PREPROC_FAILURE,
  218. ERROR_MISSING_ARGUMENT,
  219. ERROR_INCLUDE_SYNTAX,
  220. ERROR_DEFINE_SYNTAX,
  221. ERROR_REDEFINE,
  222. ERROR_ILLEGAL_UNDEF,
  223. ERROR_RECURSIVE_MACRO,
  224. ERROR_EOF_IN_ARGUMENT,
  225. ERROR_MISPLACED_CONSTANT,
  226. ERROR_IF_OVERFLOW,
  227. ERROR_ILLEGAL_IF_LINE,
  228. ERROR_OPERATOR,
  229. ERROR_EXPR_OVERFLOW,
  230. ERROR_UNBALANCED_PARENS,
  231. ERROR_MISPLACED,
  232. ERROR_STRING_IN_IF,
  233. ERROR_DEFINED_SYNTAX,
  234. ERROR_ILLEGAL_ASSIGN,
  235. ERROR_ILLEGAL_BACKSLASH,
  236. ERROR_SIZEOF_SYNTAX,
  237. ERROR_SIZEOF_UNKNOWN,
  238. ERROR_SIZEOF_ILLEGAL_TYPE,
  239. ERROR_SIZEOF_NO_TYPE,
  240. ERROR_UNTERMINATED_STRING,
  241. ERROR_EOF_IN_COMMENT,
  242. ERROR_IFDEF_DEPTH,
  243. ERROR_ILLEGAL_CHARACTER,
  244. ERROR_ILLEGAL_CHARACTER2,
  245. ERROR_SIZEOF_BUG,
  246. ERROR_IF_OPERAND,
  247. ERROR_STRANG_CHARACTER,
  248. ERROR_STRANG_CHARACTER2,
  249. BORDER_ERROR_WARN, /* below this number: errors, above: warnings */
  250. WARN_CONTROL_LINE_IN_MACRO,
  251. WARN_ILLEGAL_COMMAND,
  252. WARN_UNEXPECTED_TEXT_IGNORED,
  253. WARN_TOO_FEW_VALUES_TO_SIZEOF,
  254. WARN_TOO_MANY_VALUES_TO_SIZEOF,
  255. WARN_NOT_DEFINED,
  256. WARN_INTERNAL_ERROR,
  257. WARN_MACRO_NEEDS_ARGUMENTS,
  258. WARN_WRONG_NUMBER_ARGUMENTS,
  259. WARN_DIVISION_BY_ZERO,
  260. WARN_ILLEGAL_OCTAL,
  261. WARN_MULTIBYTE_NOT_PORTABLE,
  262. WARN_CANNOT_OPEN_INCLUDE,
  263. WARN_BRACKET_DEPTH,
  264. WARN_PAREN_DEPTH,
  265. WARN_BRACE_DEPTH,
  266. WARN_NESTED_COMMENT,
  267. BORDER_WARN_FATAL, /* below this number: warnings, above: fatals */
  268. FATAL_TOO_MANY_NESTINGS,
  269. FATAL_FILENAME_BUFFER_OVERFLOW,
  270. FATAL_TOO_MANY_INCLUDE_DIRS,
  271. FATAL_TOO_MANY_INCLUDE_FILES,
  272. FATAL_TOO_MANY_ARGUMENTS_MACRO,
  273. FATAL_MACRO_AREA_OVERFLOW,
  274. FATAL_ILLEGAL_MACRO,
  275. FATAL_TOO_MANY_ARGUMENTS_EXPANSION,
  276. FATAL_OUT_OF_SPACE_IN_ARGUMENT,
  277. FATAL_WORK_AREA_OVERFLOW,
  278. FATAL_WORK_BUFFER_OVERFLOW,
  279. FATAL_OUT_OF_MEMORY,
  280. FATAL_TOO_MUCH_PUSHBACK
  281. } ErrorCode;
  282. /**********************************************************************
  283. * RETURN CODES:
  284. *********************************************************************/
  285. typedef enum {
  286. FPP_OK,
  287. FPP_OUT_OF_MEMORY,
  288. FPP_TOO_MANY_NESTED_STATEMENTS,
  289. FPP_FILENAME_BUFFER_OVERFLOW,
  290. FPP_NO_INCLUDE,
  291. FPP_OPEN_ERROR,
  292. FPP_TOO_MANY_ARGUMENTS,
  293. FPP_WORK_AREA_OVERFLOW,
  294. FPP_ILLEGAL_MACRO,
  295. FPP_EOF_IN_MACRO,
  296. FPP_OUT_OF_SPACE_IN_MACRO_EXPANSION,
  297. FPP_ILLEGAL_CHARACTER,
  298. FPP_CANT_USE_STRING_IN_IF,
  299. FPP_BAD_IF_DEFINED_SYNTAX,
  300. FPP_IF_ERROR,
  301. FPP_SIZEOF_ERROR,
  302. FPP_UNTERMINATED_STRING,
  303. FPP_TOO_MANY_INCLUDE_DIRS,
  304. FPP_TOO_MANY_INCLUDE_FILES,
  305. FPP_INTERNAL_ERROR,
  306. FPP_LAST_ERROR
  307. } ReturnCode;
  308. /* Nasty defines to make them appear as three different functions! */
  309. #define fpp_cwarn fpp_cerror
  310. #define fpp_cfatal fpp_cerror
  311. /**********************************************************************
  312. * PROTOTYPES:
  313. *********************************************************************/
  314. int PREFIX fppPreProcess(REG(a0) struct fppTag *);
  315. void fpp_Freemem(void *);
  316. void fpp_Error(struct Global *, char *, ...);
  317. void fpp_Putchar(struct Global *, int);
  318. void fpp_Putstring(struct Global *, char *);
  319. void fpp_Putint(struct Global *, int);
  320. char *fpp_savestring(struct Global *, char *);
  321. ReturnCode fpp_addfile(struct Global *, FILE *, char *);
  322. int fpp_catenate(struct Global *, int lhs_number, ReturnCode *);
  323. void fpp_cerror(struct Global *, ErrorCode, ...);
  324. ReturnCode fpp_control(struct Global *, int *);
  325. ReturnCode fpp_dodefine(struct Global *);
  326. int fpp_dooptions(struct Global *, struct fppTag *);
  327. void fpp_doundef(struct Global *);
  328. void fpp_dumpparm(char *);
  329. ReturnCode fpp_expand(struct Global *, DEFBUF *);
  330. int fpp_get(struct Global *);
  331. ReturnCode fpp_initdefines(struct Global *);
  332. void fpp_outdefines(struct Global *);
  333. ReturnCode fpp_save(struct Global *, int);
  334. void fpp_scanid(struct Global *, int);
  335. ReturnCode fpp_scannumber(struct Global *, int, ReturnCode(*)(struct Global *, int));
  336. ReturnCode fpp_scanstring(struct Global *, int, ReturnCode(*)(struct Global *, int));
  337. void fpp_unget(struct Global *);
  338. ReturnCode fpp_ungetstring(struct Global *, char *);
  339. ReturnCode fpp_eval(struct Global *, int *);
  340. #ifdef DEBUG_EVAL
  341. void fpp_dumpstack(OPTAB[NEXP], register OPTAB *, int [NEXP], register int *);
  342. #endif
  343. void fpp_skipnl(struct Global *);
  344. int fpp_skipws(struct Global *);
  345. ReturnCode fpp_macroid(struct Global *, int *);
  346. ReturnCode fpp_getfile(struct Global *, size_t, char *, FILEINFO **);
  347. DEFBUF *fpp_lookid(struct Global *, int );
  348. DEFBUF *fpp_defendel(struct Global *, char *, int);
  349. #if DEBUG
  350. void fpp_dumpdef(char *);
  351. void fpp_dumpadef(char *, register DEFBUF *);
  352. #endif
  353. ReturnCode fpp_openfile(struct Global *,char *);
  354. int fpp_cget(struct Global *);
  355. void fpp_delbuiltindefines(struct Global *);
  356. void fpp_delalldefines(struct Global *);
  357. char *fpp_Getmem(struct Global *, int);
  358. ReturnCode fpp_openinclude(struct Global *, char *, int);
  359. ReturnCode fpp_expstuff(struct Global *, char *, char *);