+
+/*-------------------------------------------------------------------.
+| Append VALUE to the current value of KEY. If KEY did not already |
+| exist, create it. Use MUSCLE_OBSTACK. De-allocate the previously |
+| associated value. Copy VALUE and SEPARATOR. |
+`-------------------------------------------------------------------*/
+
+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);
+ }
+}
+
+
+/*------------------------------------------------------------------.
+| Append VALUE to the current value of KEY, using muscle_grow. But |
+| in addition, issue a synchronization line for the location LOC. |
+`------------------------------------------------------------------*/
+
+void
+muscle_code_grow (const char *key, const char *val, location loc)
+{
+ char *extension = NULL;
+ obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, [[", loc.start.line);
+ MUSCLE_OBSTACK_SGROW (&muscle_obstack,
+ quotearg_style (c_quoting_style, loc.start.file));
+ obstack_sgrow (&muscle_obstack, "]])[\n");
+ obstack_sgrow (&muscle_obstack, val);
+ obstack_1grow (&muscle_obstack, 0);
+ extension = obstack_finish (&muscle_obstack);
+ muscle_grow (key, extension, "");
+}
+
+
+/*-------------------------------------------------------------------.
+| MUSCLE is an M4 list of pairs. Create or extend it with the pair |
+| (A1, A2). Note that because the muscle values are output *double* |
+| quoted, one needs to strip the first level of quotes to reach the |
+| list itself. |
+`-------------------------------------------------------------------*/
+
+void muscle_pair_list_grow (const char *muscle,
+ const char *a1, const char *a2)
+{
+ char *pair;
+ obstack_fgrow2 (&muscle_obstack, "[[[%s]], [[%s]]]", a1, a2);
+ obstack_1grow (&muscle_obstack, 0);
+ pair = obstack_finish (&muscle_obstack);
+ muscle_grow (muscle, pair, ",\n");
+ obstack_free (&muscle_obstack, pair);
+}
+
+/*-------------------------------.
+| Find the value of muscle KEY. |
+`-------------------------------*/
+
+char *