- muscle_insert ("version", VERSION);
- muscle_insert ("filename", infile);
-
- /* Types. */
- muscle_insert ("stype", "int");
- muscle_insert ("ltype", "yyltype");
-
- /* Tables. */
- muscle_insert ("rhs", NULL);
- muscle_insert ("pact", NULL);
- muscle_insert ("prhs", NULL);
- muscle_insert ("stos", NULL);
- muscle_insert ("check", NULL);
- muscle_insert ("pgoto", NULL);
- muscle_insert ("table", NULL);
- muscle_insert ("tname", NULL);
- muscle_insert ("defact", NULL);
- muscle_insert ("toknum", NULL);
- muscle_insert ("defgoto", NULL);
- muscle_insert ("translate", NULL);
-
- /* Various macros. */
- muscle_insert ("flag", NULL);
- muscle_insert ("last", NULL);
- muscle_insert ("pure", NULL);
- muscle_insert ("nsym", NULL);
- muscle_insert ("debug", NULL);
- muscle_insert ("final", NULL);
- muscle_insert ("maxtok", NULL);
- muscle_insert ("ntbase", NULL);
- muscle_insert ("error-verbose", NULL);
- muscle_insert ("prefix", NULL);
- /* Default #line formatting. */
- muscle_insert ("linef", "#line %d %s\n");
-
- /* No parser macros. */
- muscle_insert ("nnts", NULL);
- muscle_insert ("nrules", NULL);
- muscle_insert ("nstates", NULL);
- muscle_insert ("ntokens", NULL);
-
- /* Stack parameters. */
- muscle_insert ("maxdepth", "10000");
- muscle_insert ("initdepth", "200");
-
- /* C++ macros. */
- muscle_insert ("name", "Parser");
+ MUSCLE_INSERT_STRING ("version", VERSION);
+ MUSCLE_INSERT_C_STRING ("file_name", grammar_file);
+}
+
+
+/*------------------------------------------------------------.
+| Free all the memory consumed by the muscle machinery only. |
+`------------------------------------------------------------*/
+
+void
+muscle_free (void)
+{
+ hash_free (muscle_table);
+ obstack_free (&muscle_obstack, NULL);
+}
+
+
+
+/*------------------------------------------------------------.
+| Insert (KEY, VALUE). If KEY already existed, overwrite the |
+| previous value. |
+`------------------------------------------------------------*/
+
+void
+muscle_insert (const char *key, char *value)
+{
+ muscle_entry probe;
+ muscle_entry *entry;
+
+ probe.key = key;
+ entry = hash_lookup (muscle_table, &probe);
+
+ if (!entry)
+ {
+ /* First insertion in the hash. */
+ entry = xmalloc (sizeof *entry);
+ entry->key = key;
+ hash_insert (muscle_table, entry);
+ }
+ entry->value = value;
+}
+
+
+/*-------------------------------------------------------------------.
+| Insert (KEY, VALUE). If KEY already existed, overwrite the |
+| previous value. Uses MUSCLE_OBSTACK. De-allocates the previously |
+| associated value. VALUE and SEPARATOR are copied. |
+`-------------------------------------------------------------------*/
+
+void
+muscle_grow (const char *key, const char *val, const char *separator)
+{
+ muscle_entry probe;
+ muscle_entry *entry = NULL;
+
+ probe.key = key;
+ entry = hash_lookup (muscle_table, &probe);
+
+ if (!entry)
+ {
+ /* First insertion in the hash. */
+ entry = xmalloc (sizeof *entry);
+ entry->key = key;
+ hash_insert (muscle_table, entry);
+ entry->value = xstrdup (val);
+ }
+ else
+ {
+ /* Grow the current value. */
+ char *new_val;
+ obstack_sgrow (&muscle_obstack, entry->value);
+ free (entry->value);
+ obstack_sgrow (&muscle_obstack, separator);
+ obstack_sgrow (&muscle_obstack, val);
+ obstack_1grow (&muscle_obstack, 0);
+ new_val = obstack_finish (&muscle_obstack);
+ entry->value = xstrdup (new_val);
+ obstack_free (&muscle_obstack, new_val);
+ }