X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/13b712d7d492da45303f20502adcf6a8c5a7afa2..bfdcc3a0b273c116e01d289ce52d400f22e4da14:/src/output.c diff --git a/src/output.c b/src/output.c index e157460d..3852729b 100644 --- a/src/output.c +++ b/src/output.c @@ -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 | @@ -299,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); @@ -405,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); } } @@ -615,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);