#include <string.h>
+#include "xalloc.h"
#include "system.h"
#include "hash.h"
#include "files.h"
struct hash_table macro_table;
static unsigned long
-mhash1 (const void* item)
+mhash1 (const void *item)
{
- return_STRING_HASH_1 (((macro_entry_t*) item)->key);
+ return_STRING_HASH_1 (((macro_entry_t *) item)->key);
}
static unsigned long
-mhash2 (const void* item)
+mhash2 (const void *item)
{
- return_STRING_HASH_2 (((macro_entry_t*) item)->key);
+ return_STRING_HASH_2 (((macro_entry_t *) item)->key);
}
static int
-mcmp (const void* x, const void* y)
+mcmp (const void *x, const void *y)
{
- return strcmp (((macro_entry_t*) x)->key, ((macro_entry_t*) y)->key);
+ return strcmp (((macro_entry_t*) x)->key, ((macro_entry_t *) y)->key);
}
void
{
hash_init (¯o_table, MTABSIZE, &mhash1, &mhash2, &mcmp);
- /* Version and input file. */
+ /* Version and input file. */
macro_insert ("version", VERSION);
- macro_insert ("filename", "a.y");
+ macro_insert ("filename", infile);
- /* Types. */
+ /* Types. */
macro_insert ("stype", "int");
macro_insert ("ltype", "yyltype");
- /* Tokens. */
+ /* Tokens. */
macro_insert ("tokendef", "");
- /* Tables. */
+ /* Tables. */
macro_insert ("rhs", "0");
macro_insert ("pact", "0");
macro_insert ("prhs", "0");
macro_insert ("defgoto", "0");
macro_insert ("translate", "0");
- /* Various macros. */
+ /* Various macros. */
macro_insert ("flag", "0");
macro_insert ("last", "0");
macro_insert ("pure", "0");
macro_insert ("maxtok", "0");
macro_insert ("ntbase", "0");
macro_insert ("verbose", "0");
+ macro_insert ("prefix", "yy");
- /* Variable prefix names. */
- macro_insert ("yyparse", "yyparse");
- macro_insert ("yylex", "yylex");
- macro_insert ("yyerror", "yyerror");
- macro_insert ("yylval", "yylval");
- macro_insert ("yychar", "yychar");
- macro_insert ("yydebug", "yydebug");
- macro_insert ("yynerrs", "yynerrs");
-
- /* No parser macros. */
+ /* No parser macros. */
macro_insert ("nnts", "0");
macro_insert ("nrules", "0");
macro_insert ("nstates", "0");
macro_insert ("ntokens", "0");
- /* Stack parameters. */
+ /* Stack parameters. */
macro_insert ("maxdepth", "10000");
macro_insert ("initdepth", "200");
- /* C++ macros. */
+ /* C++ macros. */
macro_insert ("name", "Parser");
}
void
-macro_insert (char* key, char* value)
+macro_insert (const char *key, const char *value)
{
- macro_entry_t* pair = (macro_entry_t*) xmalloc (sizeof (macro_entry_t));
+ macro_entry_t *pair = XMALLOC (macro_entry_t, 1);
pair->key = key;
pair->value = value;
hash_insert (¯o_table, pair);
}
-char*
-macro_find (char* key)
+const char*
+macro_find (const char *key)
{
macro_entry_t pair = { key, 0 };
- macro_entry_t* result = hash_find_item (¯o_table, &pair);
+ macro_entry_t *result = hash_find_item (¯o_table, &pair);
return result ? result->value : 0;
}