home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / cpp114.zoo / src / global.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  7.7 KB  |  269 lines

  1. /*---------------------------------------------------------------------*\
  2. |                                    |
  3. | CPP -- a stand-alone C preprocessor                    |
  4. | Copyright (c) 1993-95 Hacker Ltd.        Author: Scott Bigham    |
  5. |                                    |
  6. | Permission is granted to anyone to use this software for any purpose    |
  7. | on any computer system, and to redistribute it freely, with the    |
  8. | following restrictions:                        |
  9. | - No charge may be made other than reasonable charges for repro-    |
  10. |     duction.                                |
  11. | - Modified versions must be clearly marked as such.            |
  12. | - The author is not responsible for any harmful consequences of    |
  13. |     using this software, even if they result from defects therein.    |
  14. |                                    |
  15. | global.h -- global definitions                    |
  16. \*---------------------------------------------------------------------*/
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20.  
  21. #ifndef __MINT__
  22. # ifdef __STDC__
  23. # define __PROTO(x) x
  24. # else
  25. # define __PROTO(x) ()
  26. # endif
  27. #endif
  28.  
  29. typedef struct macro {
  30.   struct macro *next;        /* for free-list chaining */
  31.   int nargs;
  32.   unsigned int flags;
  33. #define MAGIC    0x0001        /* system special #define */
  34. #define MAGIC2    0x0002        /* as above, but not always visible */
  35. #define HASARGS    0x0004        /* check for arguments */
  36. #define MARKED    0x0008        /* used for recursive #definitions */
  37. #define UNDEF    0x0010        /* -U argument */
  38.   struct token *argnames;
  39.   struct token *m_text;
  40. } Macro;
  41.  
  42. typedef struct token {
  43.   struct token *next;
  44.   union {
  45.     char *out_of_line;
  46.     char in_line[8];
  47.   } _txt;
  48.   union {
  49.     char *out_of_line;
  50.     char in_line[4];
  51.   } _ws;
  52.   long val;
  53.   unsigned int hashval;
  54.   char type;
  55.   char subtype;
  56.   unsigned int flags;
  57. #define BLUEPAINT    0x0001    /* not available for expansion */
  58. #define UNS_VAL        0x0002    /* value is unsigned */
  59. #define STRINGIZE_ME    0x0004    /* stringized macro arg */
  60. #define CONCAT_NEXT    0x0008    /* concatenate this token with next token */
  61. #define TRAIL_SPC    0x0010    /* add spc to prevent accidental token merge */
  62. #define UNPAINT_ME    0x0020    /* see expand() and expand_tlist() */
  63. #define INLINE_TXT    0x0040    /* text of token is inline */
  64. #define INLINE_WS    0x0080    /* whitespace is inline */
  65. } Token, *TokenP;
  66.  
  67. /* accessor macros to get at the inlined strings */
  68. #define token_txt(Tp)    \
  69.     (((Tp)->flags & INLINE_TXT) ? (Tp)->_txt.in_line : (Tp)->_txt.out_of_line)
  70. #define token_ws(Tp)    \
  71.     (((Tp)->flags & INLINE_WS) ? (Tp)->_ws.in_line : (Tp)->_ws.out_of_line)
  72.  
  73. typedef struct hash {
  74.   struct hash *next;
  75.   union {
  76.     char in_line[8];
  77.     char *out_of_line;
  78.   } _id;
  79.   Macro *data;
  80.   unsigned int flags;
  81. #define INLINE_KEY    0x0001    /* text of key is inline */
  82. } Hash;
  83.  
  84. /* token types */
  85. #define UNKNOWN        1
  86. #define DONT_CARE    2
  87. #define EOL        3
  88. #define NUMBER        4
  89. #define FP_NUM        5
  90. #define ID        6
  91. #define STR_CON        7
  92. #define CHAR_CON    8
  93. #define UNARY_OP    9
  94. #define MUL_OP        10
  95. #define ADD_OP        11
  96. #define SHIFT_OP    12
  97. #define REL_OP        13
  98. #define EQ_OP        14
  99. #define B_AND_OP    15
  100. #define B_XOR_OP    16
  101. #define B_OR_OP        17
  102. #define L_AND_OP    18
  103. #define L_OR_OP        19
  104. #define LPAREN        20
  105. #define RPAREN        21
  106. #define COMMA        22
  107. #define INC_NAM        23
  108. #define POUND        24
  109. #define TOK_CAT        25
  110. #define MACRO_ARG    26
  111. #define EOF_        27
  112. #define STOP        28
  113. #define UNMARK        29
  114.  
  115. /* tokenizer modes */
  116. #define NORMAL        0    /* default behavior */
  117. #define INCLUDE_LINE    1    /* return <filename.h> as a single token */
  118. #define IF_EXPR        2    /* interpret defined(IDENTIFIER) */
  119. #define SLURP        4    /* ignore preprocessor directives */
  120.  
  121. /* types of synchronization lines */
  122. #define SL_NONE   0        /* no sync line */
  123. #define SL_NORMAL 1        /* default style:  # 15 "fred.c" */
  124. #define SL_LINE   2        /* preproc style:  #line 15 "fred.c" */
  125.  
  126. #if defined(__MINT__) || defined(UNIXHOST)
  127. #define PATH_SEP '/'
  128. #else
  129. #define PATH_SEP '\\'
  130. #endif
  131.  
  132. #define STDIN_NAME "standard input"
  133.  
  134. #define streq(s,t) (strcmp((s),(t))==0)
  135. #define nelems(arr) (sizeof(arr)/sizeof((arr)[0]))
  136.  
  137. /* Global variables and functions from each file */
  138.  
  139. /* comment.c */
  140. char *suck_ws __PROTO((char *, TokenP));
  141. void free_cmt_buf __PROTO((void));
  142.  
  143. /* define.c */
  144. void do_define __PROTO((void));
  145. void do_undefine __PROTO((void));
  146. int macro_eq __PROTO((Macro *, Macro *));
  147.  
  148. /* hash.c */
  149. Macro *lookup __PROTO((char *, unsigned int));
  150. unsigned int hash_id __PROTO((char *, char **));
  151. void hash_add __PROTO((char *, unsigned int, Macro *));
  152. void hash_clean_undef __PROTO((void));
  153. void hash_free __PROTO((void));
  154. void hash_remove __PROTO((char *, unsigned int));
  155. void hash_setup __PROTO((void));
  156.  
  157. /* if_expr.c */
  158. int if_expr __PROTO((void));
  159.  
  160. /* include.c */
  161. void do_include __PROTO((void));
  162. extern unsigned long include_level;
  163.  
  164. /* input.c */
  165. /* HSC #defines the following if and only if it is in a mode that gives
  166.    external identifiers more than 7 characters of significance.  If your
  167.    compiler can handle long identifiers, feel free to delete this
  168.    #defin'ition. */
  169. #if defined(__HSC__) && !defined(__HSC_LONGNAMES__)
  170. #define expand_rest_of_line    E_rol
  171. #endif
  172. TokenP tokenize_string __PROTO((char *));
  173. char *getline __PROTO((void));
  174. char *rest_of_line __PROTO((void));
  175. void expand_rest_of_line __PROTO((void));
  176. void flush_line __PROTO((void));
  177. extern char *cur_file;
  178. extern unsigned long last_line, this_line, next_line;
  179.  
  180. /* macro.c */
  181. Macro *mk_Macro __PROTO((void));
  182. void free_Macro __PROTO((Macro *));
  183. TokenP expand_tlist __PROTO((TokenP));
  184. void expand __PROTO((TokenP, Macro *));
  185. extern char *magic_words[];
  186. extern int N_MWORDS;
  187.  
  188. /* main.c */
  189. extern FILE *inf;
  190. extern FILE *outf;
  191. extern char *argv0;
  192. extern char **I_list;
  193. extern char date_string[], time_string[];
  194. extern int nerrs;
  195. extern int sl_style, keep_comments, do_trigraphs, ansi, w_bad_chars,
  196.        w_nest_cmts, f_cpp_cmts, w_bad_concat, w_pragma, pedantic,
  197.        gcc_strings;
  198. extern int in_config_file, Argc_end;
  199. extern int fluff_mode;
  200. void do_cmdline_arg __PROTO((char *));
  201. void do_all_cmdline_args __PROTO((void));
  202.  
  203. /* pound.c */
  204. void cond_setup __PROTO((void));
  205. void cond_shutdown __PROTO((void));
  206. void directive __PROTO((void));
  207. void endif_check __PROTO((void));
  208. extern int *if_sp;
  209. #define COND_TRUE    1
  210. #define COND_NESTED    2
  211. #define cond_true() ((if_sp[-1]&(COND_TRUE|COND_NESTED))==COND_TRUE)
  212.  
  213. /* process.c */
  214. void process_file __PROTO((char *));
  215. void sync_line __PROTO((int));
  216. void synchronize __PROTO((void));
  217.  
  218. /* token.c */
  219. TokenP mk_Token __PROTO((void));
  220. void clear_txt __PROTO((TokenP));
  221. void clear_ws __PROTO((TokenP));
  222. void set_txt __PROTO((TokenP, const char *));
  223. void set_ws __PROTO((TokenP, const char *));
  224. void set_txt_n __PROTO((TokenP, const char *, int));
  225. TokenP copy_tlist __PROTO((TokenP));
  226. TokenP copy_token __PROTO((TokenP));
  227. TokenP merge_tokens __PROTO((TokenP, TokenP));
  228. TokenP mk_eol __PROTO((void));
  229. TokenP mk_stopper __PROTO((void));
  230. TokenP mk_unmarker __PROTO((TokenP));
  231. TokenP mk_printable __PROTO((const char *));
  232. TokenP token __PROTO((void));
  233. int get_mode __PROTO((void));
  234. void change_mode __PROTO((int, int));
  235. void flush_tokenizer __PROTO((void));
  236. void free_tlist __PROTO((TokenP));
  237. void free_token __PROTO((TokenP));
  238. void print_token __PROTO((TokenP));
  239. void push_tlist __PROTO((TokenP));
  240. void set_mode __PROTO((int));
  241. void tok_shutdown __PROTO((void));
  242. TokenP exp_token __PROTO((void));
  243. TokenP _one_token __PROTO((void));
  244. void _tokenize_line __PROTO((void));
  245. #ifdef DEBUG
  246. void dump_token __PROTO((TokenP));
  247. void dump_tlist __PROTO((TokenP));
  248. void dump_pushback __PROTO((void));
  249. #endif
  250.  
  251. /* utils.c */
  252. void fatal __PROTO((const char *, ...));
  253. void bugchk __PROTO((const char *, ...));
  254. void warning __PROTO((const char *, ...));
  255. void message __PROTO((const char *, ...));
  256. void error __PROTO((const char *, ...));
  257. char *copy_filename __PROTO((char *, int));
  258. #ifndef __GNUC__
  259. char *strdup __PROTO((const char *));
  260. #endif
  261. FILE *xfopen __PROTO((const char *, const char *));
  262. #define NEWBUFSIZ ((size_t)4096)
  263. void *mallok __PROTO((size_t));
  264. void *reallok __PROTO((void *, size_t));
  265. char *grow __PROTO((char **, size_t *, char *, int));
  266.  
  267. /* ztype.c */
  268. void Z_type_init __PROTO((void));
  269.