]> git.saurik.com Git - bison.git/blobdiff - src/output.c
maint: address syntax-check errors.
[bison.git] / src / output.c
index e0d6ed3ab4316ef7eb9f8653e55afe029f2dea86..3852729bb7694436a238e282c1c33fa6c83cd4f9 100644 (file)
@@ -41,8 +41,6 @@
 #include "symtab.h"
 #include "tables.h"
 
-# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
-
 static struct obstack format_obstack;
 
 
@@ -70,7 +68,7 @@ Name (char const *name,                                                       \
   int i;                                                               \
   int j = 1;                                                           \
                                                                        \
-  obstack_fgrow1 (&format_obstack, "%6d", first);                      \
+  obstack_printf (&format_obstack, "%6d", first);                      \
   for (i = begin; i < end; ++i)                                                \
     {                                                                  \
       obstack_1grow (&format_obstack, ',');                            \
@@ -81,7 +79,7 @@ Name (char const *name,                                                       \
        }                                                               \
       else                                                             \
        ++j;                                                            \
-      obstack_fgrow1 (&format_obstack, "%6d", table_data[i]);          \
+      obstack_printf (&format_obstack, "%6d", table_data[i]);          \
       if (table_data[i] < min)                                         \
        min = table_data[i];                                            \
       if (max < table_data[i])                                         \
@@ -93,10 +91,10 @@ Name (char const *name,                                                     \
   lmin = min;                                                          \
   lmax = max;                                                          \
   /* Build `NAME_min' and `NAME_max' in the obstack. */                        \
-  obstack_fgrow1 (&format_obstack, "%s_min", name);                    \
+  obstack_printf (&format_obstack, "%s_min", name);                    \
   obstack_1grow (&format_obstack, 0);                                  \
   MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmin);     \
-  obstack_fgrow1 (&format_obstack, "%s_max", name);                    \
+  obstack_printf (&format_obstack, "%s_max", name);                    \
   obstack_1grow (&format_obstack, 0);                                  \
   MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmax);     \
 }
@@ -110,29 +108,39 @@ GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number)
 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number)
 
 
-/*--------------------------------------------------------------------.
-| Print to OUT a representation of STRING escaped both for C and M4.  |
-`--------------------------------------------------------------------*/
+/*----------------------------------------------------------------.
+| Print to OUT a representation of CP quoted and escaped for M4.  |
+`----------------------------------------------------------------*/
 
 static void
-escaped_output (FILE *out, char const *string)
+quoted_output (FILE *out, char const *cp)
 {
-  char const *p;
   fprintf (out, "[[");
 
-  for (p = quotearg_style (c_quoting_style, string); *p; p++)
-    switch (*p)
+  for (; *cp; cp++)
+    switch (*cp)
       {
       case '$': fputs ("$][", out); break;
       case '@': fputs ("@@",  out); break;
       case '[': fputs ("@{",  out); break;
       case ']': fputs ("@}",  out); break;
-      default: fputc (*p, out); break;
+      default:  fputc (*cp,   out); break;
       }
 
   fprintf (out, "]]");
 }
 
+/*----------------------------------------------------------------.
+| Print to OUT a representation of STRING quoted and escaped both |
+| for C and M4.                                                   |
+`----------------------------------------------------------------*/
+
+static void
+string_output (FILE *out, char const *string)
+{
+  quoted_output (out, quotearg_style (c_quoting_style, string));
+}
+
 
 /*------------------------------------------------------------------.
 | Prepare the muscles related to the symbols: translate, tname, and |
@@ -142,7 +150,6 @@ escaped_output (FILE *out, char const *string)
 static void
 prepare_symbols (void)
 {
-  MUSCLE_INSERT_BOOL ("token_table", token_table_flag);
   MUSCLE_INSERT_INT ("tokens_number", ntokens);
   MUSCLE_INSERT_INT ("nterms_number", nvars);
   MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
@@ -176,7 +183,7 @@ prepare_symbols (void)
 
        if (i)
          obstack_1grow (&format_obstack, ' ');
-       MUSCLE_OBSTACK_SGROW (&format_obstack, cp);
+       obstack_escape (&format_obstack, cp);
         free (cp);
        obstack_1grow (&format_obstack, ',');
        j += width;
@@ -300,7 +307,7 @@ user_actions_output (FILE *out)
       {
        fprintf (out, "b4_case(%d, [b4_syncline(%d, ", r + 1,
                 rules[r].action_location.start.line);
-       escaped_output (out, rules[r].action_location.start.file);
+       string_output (out, rules[r].action_location.start.file);
        fprintf (out, ")\n[    %s]])\n\n", rules[r].action);
       }
   fputs ("])\n\n", out);
@@ -406,12 +413,15 @@ symbol_code_props_output (FILE *out, char const *what,
              code, optional typename.  */
           fprintf (out, "%s[", sep);
           sep = ",\n";
-          escaped_output (out, loc.start.file);
+          string_output (out, loc.start.file);
           fprintf (out, ", %d, ", loc.start.line);
-          escaped_output (out, sym->tag);
+          quoted_output (out, sym->tag);
           fprintf (out, ", %d, [[%s]]", sym->number, code);
           if (sym->type_name)
-            fprintf (out, ", [[%s]]", sym->type_name);
+            {
+              fputs (", ", out);
+              quoted_output (out, sym->type_name);
+            }
           fputc (']', out);
         }
     }
@@ -616,7 +626,7 @@ prepare (void)
     use_push_for_pull_flag = true;
 
   /* Flags. */
-  MUSCLE_INSERT_BOOL ("debug_flag", debug_flag);
+  MUSCLE_INSERT_BOOL ("debug_flag", debug);
   MUSCLE_INSERT_BOOL ("defines_flag", defines_flag);
   MUSCLE_INSERT_BOOL ("error_verbose_flag", error_verbose);
   MUSCLE_INSERT_BOOL ("glr_flag", glr_parser);
@@ -624,6 +634,7 @@ prepare (void)
   MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser);
   MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);
   MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen);
+  MUSCLE_INSERT_BOOL ("token_table_flag", token_table_flag);
   MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag);
   MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag);