home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / m4-1.1-src.lha / src / amiga / m4-1.1 / m4.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-09  |  9.1 KB  |  346 lines

  1. /* GNU m4 -- A simple macro processor
  2.    Copyright (C) 1989, 90, 91, 92, 93 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19. #ifndef __STDC__
  20. #define Args(x) ()
  21. #else
  22. #define Args(x) x
  23. #endif
  24.  
  25. #ifndef __GNUC__
  26. #define volatile
  27. #else
  28. #define volatile __volatile__
  29. #endif
  30.  
  31. #include <stdio.h>
  32. #include <ctype.h>
  33. #include <varargs.h>
  34.  
  35. #include "obstack.h"
  36.  
  37. #if defined (HAVE_STRING_H) || defined (STDC_HEADERS)
  38. #include <string.h>
  39. #ifndef index
  40. #define    index(s, c)    strchr ((s), (c))
  41. #endif
  42. #ifndef rindex
  43. #define    rindex(s, c)    strrchr ((s), (c))
  44. #endif
  45.  
  46. #ifdef NEED_MEMORY_H
  47. #include <memory.h>
  48. #endif /* NEED_MEMORY_H */
  49.  
  50. /* This is for obstack code -- should live in obstack.h.  */
  51. #ifndef bcopy
  52. #define bcopy(s,d,n)    memcpy ((d), (s), (n))
  53. #endif
  54.  
  55. #else /* not HAVE_STRING_H and not STDC_HEADERS */
  56.  
  57. #include <strings.h>
  58.  
  59. extern void bcopy ();
  60. #endif /* not HAVE_STRING_H and not STDC_HEADERS */
  61.  
  62. #ifdef STDC_HEADERS
  63. #include <stdlib.h>
  64. #else /* STDC_HEADERS */
  65. extern void *malloc ();
  66. extern void *realloc ();
  67. extern char *getenv ();
  68. #endif /* STDC_HEADERS */
  69.  
  70. extern char *mktemp ();
  71.  
  72. #define obstack_chunk_alloc    xmalloc
  73. #define obstack_chunk_free    xfree
  74.  
  75. /* If FALSE is defined, we presume TRUE is defined too.  In this case,
  76.    merely typedef boolean as being int.  Or else, define these all.  */
  77. #ifndef FALSE
  78. /* Do not use `enum boolean': this tag is used in SVR4 <sys/types.h>.  */
  79. typedef enum { FALSE = 0, TRUE = 1 } boolean;
  80. #else
  81. typedef int boolean;
  82. #endif
  83.  
  84. #include <errno.h>
  85. #ifndef errno
  86. extern int errno;
  87. #endif
  88.  
  89. extern int sys_nerr;
  90. extern char *sys_errlist[];
  91.  
  92. #define syserr() ((errno > 0 && errno < sys_nerr) ? sys_errlist[errno] : "Unknown error")
  93.  
  94. /* Miscellaneous, that must come first.  */
  95. typedef void builtin_func ();
  96. typedef struct token_data token_data;
  97.  
  98. /* File: m4.c  --- global definitions.  */
  99.  
  100. /* Option flags.  */
  101. extern int sync_output;            /* -s */
  102. extern int debug_level;            /* -d */
  103. extern int hash_table_size;        /* -H */
  104. extern int ndiversion;            /* -N */
  105. extern int no_gnu_extensions;        /* -g */
  106. extern int max_debug_argument_length;    /* -l */
  107. extern int suppress_warnings;        /* -Q */
  108.  
  109. /* Error handling.  */
  110. extern void warning ();        /* varargs */
  111. extern void m4error ();        /* varargs */
  112. extern volatile void fatal ();    /* varargs */
  113. extern volatile void internal_error ();    /* varargs */
  114.  
  115. /* Memory allocation.  */
  116. extern void *xmalloc Args ((unsigned int));
  117. extern void xfree Args ((void *));
  118. extern char *xstrdup Args ((const char *));
  119.  
  120. /* File: debug.c  --- debugging and tracing function.  */
  121.  
  122. /* debug_level is a bitmask of these.  */
  123. enum debug_info
  124. {
  125.   DEBUG_TRACE_ARGS = 0x01,    /* a: show arglist in trace output */
  126.   DEBUG_TRACE_EXPANSION = 0x02,    /* e: show expansion in trace output */
  127.   DEBUG_TRACE_QUOTE = 0x04,    /* q: quote args and expansion in trace output */
  128.   DEBUG_TRACE_ALL = 0x08,    /* t: trace all macros -- overrides trace{on,off} */
  129.   DEBUG_TRACE_LINE = 0x10,    /* l: add line numbers to trace output */
  130.   DEBUG_TRACE_FILE  = 0x20,    /* f: add file name to trace output */
  131.   DEBUG_TRACE_PATH = 0x40,    /* p: trace path search of include files */
  132.   DEBUG_TRACE_CALL = 0x80,    /* c: show macro call before args collection */
  133.   DEBUG_TRACE_INPUT = 0x100,    /* i: trace changes of input files */
  134.   DEBUG_TRACE_CALLID = 0x200,    /* x: add call id to trace output */
  135.  
  136.   DEBUG_TRACE_VERBOSE = 0x3ff,    /* V: very verbose --  print everything */
  137.   DEBUG_TRACE_DEFAULT = 0x07    /* default flags -- equiv: aeq */
  138. };
  139.  
  140. extern void debug_init Args ((void));
  141. extern int debug_decode Args ((char *));
  142. extern boolean debug_set_output Args ((char *));
  143. extern void debug_print ();    /* varargs */
  144. extern void debug_message ();    /* varargs */
  145.  
  146. extern void trace_prepre Args ((char *, int));
  147. extern void trace_pre Args ((char *, int, int, token_data **));
  148. extern void trace_post Args ((char *, int, int, token_data **, char *));
  149.  
  150. /* File: input.c  --- lexical definitions.  */
  151.  
  152. /* Various different token types.  */
  153. enum token_type
  154. {
  155.   TOKEN_EOF,            /* end of file */
  156.   TOKEN_STRING,            /* a quoted string */
  157.   TOKEN_WORD,            /* an identifier */
  158.   TOKEN_SIMPLE,            /* a single character */
  159.   TOKEN_MACDEF            /* a macros definition (see "defn") */
  160. };
  161.  
  162. /* The data for a token, a macro argument, and a macro definition.  */
  163. enum token_data_type
  164. {
  165.   TOKEN_VOID,
  166.   TOKEN_TEXT,
  167.   TOKEN_FUNC
  168. };
  169.  
  170. struct token_data
  171. {
  172.   enum token_data_type type;
  173.   union
  174.     {
  175.       struct
  176.     {
  177.       char *text;
  178.     }
  179.       u_t;
  180.       struct
  181.     {
  182.       builtin_func *func;
  183.       boolean traced;
  184.     }
  185.       u_f;
  186.     }
  187.   u;
  188. };
  189.  
  190. #define TOKEN_DATA_TYPE(td)        ((td)->type)
  191. #define TOKEN_DATA_TEXT(td)        ((td)->u.u_t.text)
  192. #define TOKEN_DATA_FUNC(td)        ((td)->u.u_f.func)
  193. #define TOKEN_DATA_FUNC_TRACED(td)     ((td)->u.u_f.traced)
  194.  
  195. typedef enum token_type token_type;
  196. typedef enum token_data_type token_data_type;
  197.  
  198. extern void input_init Args ((void));
  199. extern int peek_input Args ((void));
  200. extern token_type next_token Args ((token_data *));
  201. extern void skip_line Args ((void));
  202.  
  203. /* push back input */
  204. extern void push_file Args ((FILE *, const char *));
  205. extern void push_macro Args ((builtin_func *, boolean));
  206.  
  207. extern struct obstack *push_string_init Args ((void));
  208. extern char *push_string_finish Args ((void));
  209.  
  210. extern void push_wrapup Args ((char *));
  211. extern boolean pop_wrapup Args ((void));
  212.  
  213. /* current input file, and line */
  214. extern char *current_file;
  215. extern int current_line;
  216.  
  217. /* left and right quote, begin and end comment */
  218. extern char *bcomm, *ecomm;
  219. extern char *lquote, *rquote;
  220. /* lenght of quote strings */
  221. extern int len_lquote, len_rquote;
  222.  
  223. #define DEF_LQUOTE "`"
  224. #define DEF_RQUOTE "\'"
  225. #define DEF_BCOMM "#"
  226. #define DEF_ECOMM "\n"
  227.  
  228. extern void set_quotes Args ((char *, char *));
  229. extern void set_comment Args ((char *, char *));
  230.  
  231. /* File: output.c --- output functions.  */
  232. extern int output_current_line;
  233.  
  234. #define NDIVERSIONS    10    /* default, overridden by -Nnum */
  235.  
  236. extern void output_init Args ((void));
  237. extern void shipout_text Args ((struct obstack *, char *));
  238. extern void make_diversion Args ((int));
  239. extern void insert_diversion Args ((int));
  240. extern void insert_file Args ((FILE *));
  241.  
  242. /* File symtab.c  --- symbol table definitions.  */
  243.  
  244. /* Operation modes for lookup_symbol ().  */
  245. enum symbol_lookup
  246. {
  247.   SYMBOL_LOOKUP,
  248.   SYMBOL_INSERT,
  249.   SYMBOL_DELETE,
  250.   SYMBOL_PUSHDEF,
  251.   SYMBOL_POPDEF
  252. };
  253.  
  254. /* Symbol table entry.  */
  255. struct symbol
  256. {
  257.   struct symbol *next;
  258.   boolean traced;
  259.   boolean shadowed;
  260.   boolean macro_args;
  261.   boolean blind_no_args;
  262.  
  263.   char *name;
  264.   token_data data;
  265. };
  266.  
  267. #define SYMBOL_NEXT(s)        ((s)->next)
  268. #define SYMBOL_TRACED(s)    ((s)->traced)
  269. #define SYMBOL_SHADOWED(s)    ((s)->shadowed)
  270. #define SYMBOL_MACRO_ARGS(s)    ((s)->macro_args)
  271. #define SYMBOL_BLIND_NO_ARGS(s)    ((s)->blind_no_args)
  272. #define SYMBOL_NAME(s)        ((s)->name)
  273. #define SYMBOL_TYPE(s)        (TOKEN_DATA_TYPE (&(s)->data))
  274. #define SYMBOL_TEXT(s)        (TOKEN_DATA_TEXT (&(s)->data))
  275. #define SYMBOL_FUNC(s)        (TOKEN_DATA_FUNC (&(s)->data))
  276.  
  277. typedef enum symbol_lookup symbol_lookup;
  278. typedef struct symbol symbol;
  279. typedef void hack_symbol ();
  280.  
  281. #define HASHMAX 509        /* default, overridden by -Hsize */
  282.  
  283. extern symbol **symtab;
  284.  
  285. extern void symtab_init Args ((void));
  286. extern symbol *lookup_symbol Args ((const char *, symbol_lookup));
  287.  
  288. extern void hack_all_symbols Args ((hack_symbol *, char *));
  289.  
  290. /* File: macro.c  --- macro expansion.  */
  291.  
  292. extern void expand_input Args ((void));
  293. extern void call_macro Args ((symbol *, int, token_data **, struct obstack *));
  294.  
  295. /* File: builtin.c  --- builtins.  */
  296.  
  297. struct builtin
  298. {
  299.   char *name;
  300.   boolean gnu_extension;
  301.   boolean groks_macro_args;
  302.   boolean blind_if_no_args;
  303.   builtin_func *func;
  304. };
  305.  
  306. struct predefined
  307. {
  308.   const char *unix_name;
  309.   const char *gnu_name;
  310.   const char *func;
  311. };
  312.  
  313. typedef struct builtin builtin;
  314. typedef struct predefined predefined;
  315.  
  316. extern void builtin_init Args ((void));
  317. extern void define_user_macro Args ((const char *, const char *, symbol_lookup));
  318. extern void undivert_all Args ((void));
  319. extern void expand_user_macro Args ((struct obstack *, symbol *, int, token_data **));
  320.  
  321. extern const builtin *find_builtin_by_addr Args ((builtin_func *));
  322.  
  323. /* File: path.c  --- path search for include files.  */
  324.  
  325. extern void include_init Args ((void));
  326. extern void include_env_init Args ((void));
  327. extern void add_include_directory Args ((char *));
  328. extern FILE *path_search Args ((const char *));
  329.  
  330. /* File: eval.c  --- expression evaluation.  */
  331.  
  332. extern boolean evaluate Args ((char *, int *));
  333.  
  334. /* File: format.c  --- printf like formatting.  */
  335.  
  336. extern void format Args ((struct obstack *, int, token_data **));
  337.  
  338. /* Debug stuff.  */
  339.  
  340. #ifdef DEBUG
  341. #define DEBUG_INPUT
  342. #define DEBUG_MACRO
  343. #define DEBUG_SYM
  344. #define DEBUG_INCL
  345. #endif
  346.