]> git.saurik.com Git - bison.git/commitdiff
Also handle the output file (--verbose) with obstacks.
authorAkim Demaille <akim@epita.fr>
Wed, 20 Dec 2000 17:21:14 +0000 (17:21 +0000)
committerAkim Demaille <akim@epita.fr>
Wed, 20 Dec 2000 17:21:14 +0000 (17:21 +0000)
* files.c (foutput): Remove.
(output_obstack): New.
Adjust all dependencies.
* src/conflicts.c: Return a string.
* src/system.h (obstack_grow_string): Rename as...
(obstack_sgrow): this.  Be ready to work with non literals.
(obstack_fgrow4): New.

ChangeLog
src/conflicts.c
src/files.c
src/files.h
src/output.c
src/print.c
src/reader.c
src/reduce.c
src/system.h

index 091c26aee4aed5ec9282078e6b541d14838dbd9c..77a1e8a6f2ed3753d352ae02bbd48956ef5751e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2000-12-20  Akim Demaille  <akim@epita.fr>
+
+       Also handle the output file (--verbose) with obstacks.
+
+       * files.c (foutput): Remove.
+       (output_obstack): New.
+       Adjust all dependencies.
+       * src/conflicts.c: Return a string.
+       * src/system.h (obstack_grow_string): Rename as...
+       (obstack_sgrow): this.  Be ready to work with non literals.
+       (obstack_fgrow4): New.
+
 2000-12-20  Akim Demaille  <akim@epita.fr>
 
        * src/files.c (open_files): Fix the computation of short_base_name
index 7606ff63c5c4ade39497116e3c7462de8d3f90c9..50e82c9fed3a53338f19fae717b3ee63704ec7d7 100644 (file)
@@ -45,11 +45,10 @@ static int rrc_count;
 static inline void
 log_resolution (int state, int LAno, int token, char *resolution)
 {
-  if (verbose_flag)
-    fprintf (foutput,
-            _("\
+  obstack_fgrow4 (&output_obstack,
+                 _("\
 Conflict in state %d between rule %d and token %s resolved as %s.\n"),
-            state, LAruleno[LAno], tags[token], resolution);
+                 state, LAruleno[LAno], tags[token], resolution);
 }
 
 
@@ -407,29 +406,38 @@ count_rr_conflicts (int state)
     }
 }
 
-/*----------------------------------------------------------.
-| Output to OUT a human readable report on shift/reduce and |
-| reduce/reduce conflict numbers (SRC_NUM, RRC_NUM).        |
-`----------------------------------------------------------*/
+/*--------------------------------------------------------------.
+| Return a human readable string which reports shift/reduce and |
+| reduce/reduce conflict numbers (SRC_NUM, RRC_NUM).            |
+`--------------------------------------------------------------*/
 
-static void
-conflict_report (FILE *out, int src_num, int rrc_num)
+static const char *
+conflict_report (int src_num, int rrc_num)
 {
+  static char res[4096];
+  char *cp = res;
+
   if (src_num == 1)
-    fprintf (out, _(" 1 shift/reduce conflict"));
+    sprintf (cp, _(" 1 shift/reduce conflict"));
   else if (src_num > 1)
-    fprintf (out, _(" %d shift/reduce conflicts"), src_num);
+    sprintf (cp, _(" %d shift/reduce conflicts"), src_num);
+  cp += strlen (cp);
 
   if (src_num > 0 && rrc_num > 0)
-    fprintf (out, _(" and"));
+    sprintf (cp, _(" and"));
+  cp += strlen (cp);
 
   if (rrc_num == 1)
-    fprintf (out, _(" 1 reduce/reduce conflict"));
+    sprintf (cp, _(" 1 reduce/reduce conflict"));
   else if (rrc_num > 1)
-    fprintf (out, _(" %d reduce/reduce conflicts"), rrc_num);
+    sprintf (cp, _(" %d reduce/reduce conflicts"), rrc_num);
+  cp += strlen (cp);
+
+  *cp++ = '.';
+  *cp++ = '\n';
+  *cp++ = '\0';
 
-  putc ('.', out);
-  putc ('\n', out);
+  return res;
 }
 
 
@@ -458,8 +466,9 @@ print_conflicts (void)
 
          if (verbose_flag)
            {
-             fprintf (foutput, _("State %d contains"), i);
-             conflict_report (foutput, src_count, rrc_count);
+             obstack_fgrow1 (&output_obstack, _("State %d contains"), i);
+             obstack_sgrow (&output_obstack,
+                            conflict_report (src_count, rrc_count));
            }
        }
     }
@@ -481,7 +490,7 @@ print_conflicts (void)
   else
     {
       fprintf (stderr, _("%s contains"), infile);
-      conflict_report (stderr, src_total, rrc_total);
+      fputs (conflict_report (src_total, rrc_total), stderr);
     }
 }
 
@@ -565,8 +574,9 @@ print_reductions (int state)
       for (i = 0; i < ntokens; i++)
        {
          if (mask & *fp3)
-           fprintf (foutput, _("    %-4s\t[reduce using rule %d (%s)]\n"),
-                    tags[i], default_rule, tags[rlhs[default_rule]]);
+           obstack_fgrow3 (&output_obstack,
+                           _("    %-4s\t[reduce using rule %d (%s)]\n"),
+                           tags[i], default_rule, tags[rlhs[default_rule]]);
 
          mask <<= 1;
          if (mask == 0)
@@ -576,8 +586,9 @@ print_reductions (int state)
            }
        }
 
-      fprintf (foutput, _("    $default\treduce using rule %d (%s)\n\n"),
-              default_rule, tags[rlhs[default_rule]]);
+      obstack_fgrow2 (&output_obstack,
+                     _("    $default\treduce using rule %d (%s)\n\n"),
+                     default_rule, tags[rlhs[default_rule]]);
     }
   else if (n - m >= 1)
     {
@@ -664,7 +675,7 @@ print_reductions (int state)
                      if (j != default_LA)
                        {
                          rule = LAruleno[j];
-                         fprintf (foutput,
+                         obstack_fgrow3 (&output_obstack,
                                   _("    %-4s\treduce using rule %d (%s)\n"),
                                   tags[i], rule, tags[rlhs[rule]]);
                        }
@@ -678,13 +689,13 @@ print_reductions (int state)
                      if (defaulted)
                        {
                          rule = LAruleno[default_LA];
-                         fprintf (foutput,
+                         obstack_fgrow3 (&output_obstack,
                                   _("    %-4s\treduce using rule %d (%s)\n"),
                                   tags[i], rule, tags[rlhs[rule]]);
                          defaulted = 0;
                        }
                      rule = LAruleno[j];
-                     fprintf (foutput,
+                     obstack_fgrow3 (&output_obstack,
                               _("    %-4s\t[reduce using rule %d (%s)]\n"),
                               tags[i], rule, tags[rlhs[rule]]);
                    }
@@ -705,12 +716,11 @@ print_reductions (int state)
        }
 
       if (default_LA >= 0)
-       {
-         fprintf (foutput, _("    $default\treduce using rule %d (%s)\n"),
-                  default_rule, tags[rlhs[default_rule]]);
-       }
+       obstack_fgrow2 (&output_obstack,
+                       _("    $default\treduce using rule %d (%s)\n"),
+                       default_rule, tags[rlhs[default_rule]]);
 
-      putc ('\n', foutput);
+      obstack_1grow (&output_obstack, '\n');
     }
 }
 
index 2e65c5ae3526e832b7715736c18370a8c3108695..7433076a1f81e8afe07f30a9b73366e484791b41 100644 (file)
 #include "complain.h"
 
 FILE *finput = NULL;
-FILE *foutput = NULL;
 
 struct obstack action_obstack;
 struct obstack attrs_obstack;
 struct obstack table_obstack;
 struct obstack defines_obstack;
 struct obstack guard_obstack;
+struct obstack output_obstack;
 
 char *spec_outfile;    /* for -o. */
 char *spec_file_prefix; /* for -b. */
@@ -249,11 +249,6 @@ open_files (void)
 
   finput = xfopen (infile, "r");
 
-  if (verbose_flag)
-    /* We used to use just .out if spec_name_prefix (-p) was used, but
-       that conflicts with Posix.  */
-    foutput = xfopen (stringappend (short_base_name, EXT_OUTPUT), "w");
-
   attrsfile = stringappend (short_base_name, EXT_STYPE_H);
 
   /* Initialize the obstacks. */
@@ -262,6 +257,7 @@ open_files (void)
   obstack_init (&table_obstack);
   obstack_init (&defines_obstack);
   obstack_init (&guard_obstack);
+  obstack_init (&output_obstack);
 }
 
 
@@ -274,7 +270,6 @@ void
 output_files (void)
 {
   xfclose (finput);
-  xfclose (foutput);
 
   /* Output the main file.  */
   if (spec_outfile)
@@ -298,4 +293,9 @@ output_files (void)
       obstack_save (&guard_obstack,
                    stringappend (short_base_name, EXT_GUARD_C));
     }
+
+  if (verbose_flag)
+    /* We used to use just .out if spec_name_prefix (-p) was used, but
+       that conflicts with Posix.  */
+    obstack_save (&output_obstack, stringappend (short_base_name, EXT_OUTPUT));
 }
index 96799891563d454c5b4f39cc4ca5c8b2d450f9b1..5ac8d04a1d85eb7c6962da263fdac395cce422b5 100644 (file)
@@ -37,10 +37,6 @@ extern char *spec_file_prefix;
 /* Read grammar specifications. */
 extern FILE *finput;
 
-/* Optionally output messages describing the actions taken. */
-extern FILE *foutput;
-
-
 /* Output all the action code; precise form depends on which parser. */
 extern struct obstack action_obstack;
 
@@ -57,6 +53,9 @@ extern struct obstack attrs_obstack;
 /* ... and output yyguard, containing all the guard code. */
 extern struct obstack guard_obstack;
 
+/* The verbose output. */
+extern struct obstack output_obstack;
+
 
 extern char *infile;
 extern char *attrsfile;
index a5a0a606ec84bdc0dfa5051fd141f8a165398d7c..f4b3c3fd7f8fd8600d01c4c0f428f6f27388fe5f 100644 (file)
@@ -150,7 +150,7 @@ output_short_or_char_table (struct obstack *oout,
 
       if (j >= 10)
        {
-         obstack_grow_string (oout, "\n  ");
+         obstack_sgrow (oout, "\n  ");
          j = 1;
        }
       else
@@ -161,7 +161,7 @@ output_short_or_char_table (struct obstack *oout,
       obstack_fgrow1 (oout, "%6d", short_table[i]);
     }
 
-  obstack_grow_string (oout, "\n};\n");
+  obstack_sgrow (oout, "\n};\n");
 }
 
 
@@ -234,7 +234,7 @@ output_headers (void)
   if (semantic_parser)
     obstack_fgrow1 (&action_obstack, ACTSTR, attrsfile_quoted);
   else
-    obstack_grow_string (&action_obstack, ACTSTR_SIMPLE);
+    obstack_sgrow (&action_obstack, ACTSTR_SIMPLE);
 
   /* Rename certain symbols if -p was specified.  */
   if (spec_name_prefix)
@@ -265,7 +265,7 @@ void
 output_trailers (void)
 {
   if (semantic_parser)
-    obstack_grow_string (&guard_obstack, "\n    }\n}\n");
+    obstack_sgrow (&guard_obstack, "\n    }\n}\n");
 
   obstack_1grow (&action_obstack, '\n');
 
@@ -273,9 +273,9 @@ output_trailers (void)
     return;
 
   if (semantic_parser)
-    obstack_grow_string (&action_obstack, "    }\n");
+    obstack_sgrow (&action_obstack, "    }\n");
 
-  obstack_grow_string (&action_obstack, "}\n");
+  obstack_sgrow (&action_obstack, "}\n");
 }
 
 
@@ -283,7 +283,7 @@ output_trailers (void)
 static void
 output_token_translations (void)
 {
-  obstack_grow_string (&table_obstack, "\
+  obstack_sgrow (&table_obstack, "\
 \n\
 /* YYRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n");
 
@@ -303,7 +303,7 @@ output_token_translations (void)
     }
   else
     {
-      obstack_grow_string (&table_obstack,
+      obstack_sgrow (&table_obstack,
                           "\n#define YYTRANSLATE(x) (x)\n");
     }
 }
@@ -316,7 +316,7 @@ output_gram (void)
      yyprhs and yyrhs are needed only for yydebug. */
   /* With the no_parser option, all tables are generated */
   if (!semantic_parser && !no_parser_flag)
-    obstack_grow_string (&table_obstack, "\n#if YYDEBUG != 0\n");
+    obstack_sgrow (&table_obstack, "\n#if YYDEBUG != 0\n");
 
   output_short_table (&table_obstack, NULL, "yyprhs", rrhs,
                      0, 1, nrules + 1);
@@ -339,7 +339,7 @@ output_gram (void)
   }
 
   if (!semantic_parser && !no_parser_flag)
-    obstack_grow_string (&table_obstack, "\n#endif\n");
+    obstack_sgrow (&table_obstack, "\n#endif\n");
 }
 
 
@@ -358,7 +358,7 @@ output_rule_data (void)
   int j;
   short *short_tab = NULL;
 
-  obstack_grow_string (&table_obstack, "\n\
+  obstack_sgrow (&table_obstack, "\n\
 #if YYDEBUG != 0\n");
 
   output_short_table (&table_obstack,
@@ -366,7 +366,7 @@ output_rule_data (void)
                      "yyrline", rline,
                      0, 1, nrules + 1);
 
-  obstack_grow_string (&table_obstack, "#endif\n\n");
+  obstack_sgrow (&table_obstack, "#endif\n\n");
 
   if (token_table_flag || no_parser_flag)
     {
@@ -380,11 +380,11 @@ output_rule_data (void)
 
   /* Output the table of symbol names.  */
   if (!token_table_flag && !no_parser_flag)
-    obstack_grow_string (&table_obstack,
+    obstack_sgrow (&table_obstack,
                         "\n#if YYDEBUG != 0 || defined YYERROR_VERBOSE\n\n");
-  obstack_grow_string (&table_obstack, "\
+  obstack_sgrow (&table_obstack, "\
 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */\n");
-  obstack_grow_string (&table_obstack,
+  obstack_sgrow (&table_obstack,
           "static const char *const yytname[] =\n{\n  ");
 
   j = 0;
@@ -408,7 +408,7 @@ output_rule_data (void)
 
       if (j + strsize > 75)
        {
-         obstack_grow_string (&table_obstack, "\n  ");
+         obstack_sgrow (&table_obstack, "\n  ");
          j = 2;
        }
 
@@ -418,25 +418,25 @@ output_rule_data (void)
          if (*p == '"' || *p == '\\')
            obstack_fgrow1 (&table_obstack, "\\%c", *p);
          else if (*p == '\n')
-           obstack_grow_string (&table_obstack, "\\n");
+           obstack_sgrow (&table_obstack, "\\n");
          else if (*p == '\t')
-           obstack_grow_string (&table_obstack, "\\t");
+           obstack_sgrow (&table_obstack, "\\t");
          else if (*p == '\b')
-           obstack_grow_string (&table_obstack, "\\b");
+           obstack_sgrow (&table_obstack, "\\b");
          else if (*p < 040 || *p >= 0177)
            obstack_fgrow1 (&table_obstack, "\\%03o", *p);
          else
            obstack_1grow (&table_obstack, *p);
        }
 
-      obstack_grow_string (&table_obstack, "\", ");
+      obstack_sgrow (&table_obstack, "\", ");
       j += strsize;
     }
   /* add a NULL entry to list of tokens */
-  obstack_grow_string (&table_obstack, "NULL\n};\n");
+  obstack_sgrow (&table_obstack, "NULL\n};\n");
 
   if (!token_table_flag && !no_parser_flag)
-    obstack_grow_string (&table_obstack, "#endif\n\n");
+    obstack_sgrow (&table_obstack, "#endif\n\n");
 
   /* Output YYTOKNUM. */
   if (token_table_flag)
@@ -1150,7 +1150,7 @@ output_parser (void)
   int actions_dumped = 0;
 
   if (pure_parser)
-    obstack_grow_string (&table_obstack, "#define YYPURE 1\n\n");
+    obstack_sgrow (&table_obstack, "#define YYPURE 1\n\n");
 
   /* Loop over lines in the standard parser file.  */
   if (semantic_parser)
@@ -1187,13 +1187,13 @@ output_parser (void)
                if ((c = getc (fskel)) == 'e')
                  line_type = sync_line;
                else
-                 obstack_grow_string (&table_obstack, "#lin");
+                 obstack_sgrow (&table_obstack, "#lin");
              else
-               obstack_grow_string (&table_obstack, "#li");
+               obstack_sgrow (&table_obstack, "#li");
            else
-             obstack_grow_string (&table_obstack, "#l");
+             obstack_sgrow (&table_obstack, "#l");
          else
-           obstack_grow_string (&table_obstack, "#");
+           obstack_sgrow (&table_obstack, "#");
        }
       else if (c == '%')
        {
@@ -1209,23 +1209,23 @@ output_parser (void)
                          if ((c = getc (fskel)) == 's')
                            line_type = actions_line;
                          else
-                           obstack_grow_string (&table_obstack, "%% action");
+                           obstack_sgrow (&table_obstack, "%% action");
                        else
-                         obstack_grow_string (&table_obstack, "%% actio");
+                         obstack_sgrow (&table_obstack, "%% actio");
                      else
-                       obstack_grow_string (&table_obstack, "%% acti");
+                       obstack_sgrow (&table_obstack, "%% acti");
                    else
-                     obstack_grow_string (&table_obstack, "%% act");
+                     obstack_sgrow (&table_obstack, "%% act");
                  else
-                   obstack_grow_string (&table_obstack, "%% ac");
+                   obstack_sgrow (&table_obstack, "%% ac");
                else
-                 obstack_grow_string (&table_obstack, "%% a");
+                 obstack_sgrow (&table_obstack, "%% a");
              else
-               obstack_grow_string (&table_obstack, "%% ");
+               obstack_sgrow (&table_obstack, "%% ");
            else
-             obstack_grow_string (&table_obstack, "%%");
+             obstack_sgrow (&table_obstack, "%%");
          else
-           obstack_grow_string (&table_obstack, "%");
+           obstack_sgrow (&table_obstack, "%");
        }
 
       switch (line_type)
@@ -1317,7 +1317,7 @@ output (void)
     }
   reader_output_yylsp (&table_obstack);
   if (debug_flag)
-    obstack_grow_string (&table_obstack, "\
+    obstack_sgrow (&table_obstack, "\
 #ifndef YYDEBUG\n\
 # define YYDEBUG 1\n\
 #endif\n\
@@ -1328,10 +1328,10 @@ output (void)
                    quotearg_style (c_quoting_style, attrsfile));
 
   if (!no_parser_flag)
-    obstack_grow_string (&table_obstack, "#include <stdio.h>\n\n");
+    obstack_sgrow (&table_obstack, "#include <stdio.h>\n\n");
 
   /* Make "const" do nothing if not in ANSI C.  */
-  obstack_grow_string (&table_obstack, "\
+  obstack_sgrow (&table_obstack, "\
 #ifndef __cplusplus\n\
 # ifndef __STDC__\n\
 #  define const\n\
index 390770ca1cf9281fa1533ea44c01da7d8d5dea22..a5be5737bb349e7bd3dfa31bb3cd4e025fdac77b 100644 (file)
@@ -35,7 +35,7 @@
 static void
 print_token (int extnum, int token)
 {
-  fprintf (foutput, _(" type %d is %s\n"), extnum, tags[token]);
+  obstack_fgrow2 (&output_obstack, _(" type %d is %s\n"), extnum, tags[token]);
 }
 #endif
 
@@ -68,26 +68,26 @@ print_core (int state)
        sp++;
 
       rule = -(*sp);
-      fprintf (foutput, "    %s  ->  ", tags[rlhs[rule]]);
+      obstack_fgrow1 (&output_obstack, "    %s  ->  ", tags[rlhs[rule]]);
 
       for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
        {
-         fprintf (foutput, "%s ", tags[*sp]);
+         obstack_fgrow1 (&output_obstack, "%s ", tags[*sp]);
        }
 
-      putc ('.', foutput);
+      obstack_1grow (&output_obstack, '.');
 
       while (*sp > 0)
        {
-         fprintf (foutput, " %s", tags[*sp]);
+         obstack_fgrow1 (&output_obstack, " %s", tags[*sp]);
          sp++;
        }
 
-      fprintf (foutput, _("   (rule %d)"), rule);
-      putc ('\n', foutput);
+      obstack_fgrow1 (&output_obstack, _("   (rule %d)"), rule);
+      obstack_1grow (&output_obstack, '\n');
     }
 
-  putc ('\n', foutput);
+  obstack_1grow (&output_obstack, '\n');
 }
 
 static void
@@ -109,9 +109,9 @@ print_actions (int state)
   if (!shiftp && !redp)
     {
       if (final_state == state)
-       fprintf (foutput, _("    $default\taccept\n"));
+       obstack_sgrow (&output_obstack, _("    $default\taccept\n"));
       else
-       fprintf (foutput, _("    NO ACTIONS\n"));
+       obstack_sgrow (&output_obstack, _("    NO ACTIONS\n"));
       return;
     }
 
@@ -129,14 +129,16 @@ print_actions (int state)
          if (ISVAR (symbol))
            break;
          if (symbol == 0)      /* I.e. strcmp(tags[symbol],"$")==0 */
-           fprintf (foutput, _("    $   \tgo to state %d\n"), state1);
+           obstack_fgrow1 (&output_obstack,
+                           _("    $   \tgo to state %d\n"), state1);
          else
-           fprintf (foutput, _("    %-4s\tshift, and go to state %d\n"),
-                    tags[symbol], state1);
+           obstack_fgrow2 (&output_obstack,
+                           _("    %-4s\tshift, and go to state %d\n"),
+                           tags[symbol], state1);
        }
 
       if (i > 0)
-       putc ('\n', foutput);
+       obstack_1grow (&output_obstack, '\n');
     }
   else
     {
@@ -155,20 +157,21 @@ print_actions (int state)
          if (!errp->errs[j])
            continue;
          symbol = errp->errs[j];
-         fprintf (foutput, _("    %-4s\terror (nonassociative)\n"),
+         obstack_fgrow1 (&output_obstack, _("    %-4s\terror (nonassociative)\n"),
                   tags[symbol]);
        }
 
       if (j > 0)
-       putc ('\n', foutput);
+       obstack_1grow (&output_obstack, '\n');
     }
 
   if (consistent[state] && redp)
     {
       rule = redp->rules[0];
       symbol = rlhs[rule];
-      fprintf (foutput, _("    $default\treduce using rule %d (%s)\n\n"),
-              rule, tags[symbol]);
+      obstack_fgrow2 (&output_obstack,
+                     _("    $default\treduce using rule %d (%s)\n\n"),
+                     rule, tags[symbol]);
     }
   else if (redp)
     {
@@ -183,20 +186,21 @@ print_actions (int state)
            continue;
          state1 = shiftp->shifts[i];
          symbol = accessing_symbol[state1];
-         fprintf (foutput, _("    %-4s\tgo to state %d\n"), tags[symbol],
-                  state1);
+         obstack_fgrow2 (&output_obstack,
+                         _("    %-4s\tgo to state %d\n"),
+                         tags[symbol], state1);
        }
 
-      putc ('\n', foutput);
+      obstack_1grow (&output_obstack, '\n');
     }
 }
 
 static void
 print_state (int state)
 {
-  fputs ("\n\n", foutput);
-  fprintf (foutput, _("state %d"), state);
-  fputs ("\n\n", foutput);
+  obstack_sgrow (&output_obstack, "\n\n");
+  obstack_fgrow1 (&output_obstack, _("state %d"), state);
+  obstack_sgrow (&output_obstack, "\n\n");
   print_core (state);
   print_actions (state);
 }
@@ -205,14 +209,15 @@ print_state (int state)
 | Print information on the whole grammar.  |
 `-----------------------------------------*/
 
-#define END_TEST(end)                          \
-  do {                                         \
-    if (column + strlen(buffer) > (end)) {     \
-      fprintf (foutput, "%s\n   ", buffer);    \
-      column = 3;                              \
-      buffer[0] = 0;                           \
-    }                                          \
-  } while (0)
+#define END_TEST(End)                                          \
+do {                                                           \
+  if (column + strlen(buffer) > (End))                         \
+    {                                                          \
+      obstack_fgrow1 (&output_obstack, "%s\n   ", buffer);     \
+      column = 3;                                              \
+      buffer[0] = 0;                                           \
+    }                                                          \
+} while (0)
 
 
 static void
@@ -224,28 +229,30 @@ print_grammar (void)
   int column = 0;
 
   /* rule # : LHS -> RHS */
-  putc ('\n', foutput);
-  fputs (_("Grammar"), foutput);
-  putc ('\n', foutput);
+  obstack_1grow (&output_obstack, '\n');
+  obstack_sgrow (&output_obstack, _("Grammar"));
+  obstack_1grow (&output_obstack, '\n');
   for (i = 1; i <= nrules; i++)
     /* Don't print rules disabled in reduce_grammar_tables.  */
     if (rlhs[i] >= 0)
       {
-       fprintf (foutput, _("rule %-4d %s ->"), i, tags[rlhs[i]]);
+       obstack_fgrow2 (&output_obstack,
+                       _("rule %-4d %s ->"), i, tags[rlhs[i]]);
        rule = &ritem[rrhs[i]];
        if (*rule > 0)
          while (*rule > 0)
-           fprintf (foutput, " %s", tags[*rule++]);
+           obstack_fgrow1 (&output_obstack, " %s", tags[*rule++]);
        else
-         fputs (_("            /* empty */"), foutput);
-       putc ('\n', foutput);
+         obstack_sgrow (&output_obstack, _("           /* empty */"));
+       obstack_1grow (&output_obstack, '\n');
       }
 
   /* TERMINAL (type #) : rule #s terminal is on RHS */
-  fputs ("\n", foutput);
-  fputs (_("Terminals, with rules where they appear"), foutput);
-  fputs ("\n\n", foutput);
-  fprintf (foutput, "%s (-1)\n", tags[0]);
+  obstack_sgrow (&output_obstack, "\n");
+  obstack_sgrow (&output_obstack,
+                _("Terminals, with rules where they appear"));
+  obstack_sgrow (&output_obstack, "\n\n");
+  obstack_fgrow1 (&output_obstack, "%s (-1)\n", tags[0]);
   if (translations)
     {
       for (i = 0; i <= max_user_token_number; i++)
@@ -253,34 +260,32 @@ print_grammar (void)
          {
            buffer[0] = 0;
            column = strlen (tags[token_translations[i]]);
-           fprintf (foutput, "%s", tags[token_translations[i]]);
+           obstack_sgrow (&output_obstack, tags[token_translations[i]]);
            END_TEST (50);
            sprintf (buffer, " (%d)", i);
 
            for (j = 1; j <= nrules; j++)
-             {
-               for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
-                 if (*rule == token_translations[i])
-                   {
-                     END_TEST (65);
-                     sprintf (buffer + strlen (buffer), " %d", j);
-                     break;
-                   }
-             }
-           fprintf (foutput, "%s\n", buffer);
+             for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
+               if (*rule == token_translations[i])
+                 {
+                   END_TEST (65);
+                   sprintf (buffer + strlen (buffer), " %d", j);
+                   break;
+                 }
+           obstack_fgrow1 (&output_obstack, "%s\n", buffer);
          }
     }
   else
-    for (i = 1; i < ntokens; i++)
-      {
-       buffer[0] = 0;
-       column = strlen (tags[i]);
-       fprintf (foutput, "%s", tags[i]);
-       END_TEST (50);
-       sprintf (buffer, " (%d)", i);
+    {
+      for (i = 1; i < ntokens; i++)
+       {
+         buffer[0] = 0;
+         column = strlen (tags[i]);
+         obstack_sgrow (&output_obstack, tags[i]);
+         END_TEST (50);
+         sprintf (buffer, " (%d)", i);
 
-       for (j = 1; j <= nrules; j++)
-         {
+         for (j = 1; j <= nrules; j++)
            for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
              if (*rule == i)
                {
@@ -288,13 +293,14 @@ print_grammar (void)
                  sprintf (buffer + strlen (buffer), " %d", j);
                  break;
                }
-         }
-       fprintf (foutput, "%s\n", buffer);
-      }
+         obstack_fgrow1 (&output_obstack, "%s\n", buffer);
+       }
+    }
 
-  fputs ("\n", foutput);
-  fputs (_("Nonterminals, with rules where they appear"), foutput);
-  fputs ("\n\n", foutput);
+  obstack_sgrow (&output_obstack, "\n");
+  obstack_sgrow (&output_obstack,
+                _("Nonterminals, with rules where they appear"));
+  obstack_sgrow (&output_obstack, "\n\n");
   for (i = ntokens; i <= nsyms - 1; i++)
     {
       int left_count = 0, right_count = 0;
@@ -312,7 +318,7 @@ print_grammar (void)
        }
 
       buffer[0] = 0;
-      fprintf (foutput, "%s", tags[i]);
+      obstack_sgrow (&output_obstack, tags[i]);
       column = strlen (tags[i]);
       sprintf (buffer, " (%d)", i);
       END_TEST (0);
@@ -347,7 +353,7 @@ print_grammar (void)
                  }
            }
        }
-      fprintf (foutput, "%s\n", buffer);
+      obstack_fgrow1 (&output_obstack, "%s\n", buffer);
     }
 }
 \f
index dc49be3e91c6e11a4650cd14d3ad9057d7d57a49..4f62e759a8e731c6af7f26311881c3c6988e6d58 100644 (file)
@@ -309,7 +309,7 @@ copy_at (FILE *fin, struct obstack *oout, int stack_offset)
   c = getc (fin);
   if (c == '$')
     {
-      obstack_grow_string (oout, "yyloc");
+      obstack_sgrow (oout, "yyloc");
       locations_flag = 1;
     }
   else if (isdigit (c) || c == '-')
@@ -360,7 +360,7 @@ copy_dollar (FILE *fin, struct obstack *oout,
 
   if (c == '$')
     {
-      obstack_grow_string (oout, "yyval");
+      obstack_sgrow (oout, "yyval");
 
       if (!type_name)
        type_name = get_type_name (0, rule);
@@ -732,9 +732,9 @@ parse_union_decl (void)
   else
     obstack_1grow (&attrs_obstack, '\n');
 
-  obstack_grow_string (&attrs_obstack, "typedef union");
+  obstack_sgrow (&attrs_obstack, "typedef union");
   if (defines_flag)
-    obstack_grow_string (&defines_obstack, "typedef union");
+    obstack_sgrow (&defines_obstack, "typedef union");
 
   c = getc (finput);
 
@@ -764,9 +764,9 @@ parse_union_decl (void)
          count--;
          if (count <= 0)
            {
-             obstack_grow_string (&attrs_obstack, " YYSTYPE;\n");
+             obstack_sgrow (&attrs_obstack, " YYSTYPE;\n");
              if (defines_flag)
-               obstack_grow_string (&defines_obstack, " YYSTYPE;\n");
+               obstack_sgrow (&defines_obstack, " YYSTYPE;\n");
              /* JF don't choke on trailing semi */
              c = skip_white_space ();
              if (c != ';')
@@ -1061,7 +1061,7 @@ copy_action (symbol_list *rule, int stack_offset)
        }
     }
 
-  obstack_grow_string (&action_obstack, ";\n    break;}");
+  obstack_sgrow (&action_obstack, ";\n    break;}");
 }
 \f
 /*-------------------------------------------------------------------.
@@ -1149,7 +1149,7 @@ copy_guard (symbol_list *rule, int stack_offset)
 
   c = skip_white_space ();
 
-  obstack_grow_string (&guard_obstack, ";\n    break;}");
+  obstack_sgrow (&guard_obstack, ";\n    break;}");
   if (c == '{')
     copy_action (rule, stack_offset);
   else if (c == '=')
@@ -1540,10 +1540,10 @@ readgram (void)
       /* We used to use `unsigned long' as YYSTYPE on MSDOS,
          but it seems better to be consistent.
          Most programs should declare their own type anyway.  */
-      obstack_grow_string (&attrs_obstack,
+      obstack_sgrow (&attrs_obstack,
                           "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
       if (defines_flag)
-       obstack_grow_string (&defines_obstack, "\
+       obstack_sgrow (&defines_obstack, "\
 #ifndef YYSTYPE\n\
 # define YYSTYPE int\n\
 #endif\n");
@@ -1753,7 +1753,7 @@ packsymbols (void)
            obstack_fgrow1 (&defines_obstack, "\nextern YYSTYPE %slval;\n",
                            spec_name_prefix);
          else
-           obstack_grow_string (&defines_obstack,
+           obstack_sgrow (&defines_obstack,
                                 "\nextern YYSTYPE yylval;\n");
        }
 
@@ -1906,7 +1906,7 @@ reader (void)
                  no_parser_flag ? "Bison-generated parse tables" : "A Bison parser",
                  infile, VERSION);
 
-  obstack_grow_string (&table_obstack,
+  obstack_sgrow (&table_obstack,
                       "#define YYBISON 1  /* Identify Bison output.  */\n\n");
   read_declarations ();
   /* Start writing the guard and action files, if they are needed.  */
@@ -1921,7 +1921,7 @@ reader (void)
   /* Write closing delimiters for actions and guards.  */
   output_trailers ();
   if (locations_flag)
-    obstack_grow_string (&table_obstack, "#define YYLSP_NEEDED 1\n\n");
+    obstack_sgrow (&table_obstack, "#define YYLSP_NEEDED 1\n\n");
   /* Assign the symbols their symbol numbers.  Write #defines for the
      token symbols into FDEFINES if requested.  */
   packsymbols ();
@@ -1942,7 +1942,7 @@ void
 reader_output_yylsp (struct obstack *oout)
 {
   if (locations_flag)
-    obstack_grow_string (oout, "\
+    obstack_sgrow (oout, "\
 \n\
 #ifndef YYLTYPE\n\
 typedef struct yyltype\n\
index c2efee931de0a10133cb8025a52a93170939cc32..c5be01feab1f43c23c3dfdbade3fff8decb8cf6c 100644 (file)
@@ -401,11 +401,11 @@ print_results (void)
 
   if (nuseless_nonterminals > 0)
     {
-      fputs (_("Useless nonterminals:"), foutput);
-      fputs ("\n\n", foutput);
+      obstack_sgrow (&output_obstack, _("Useless nonterminals:"));
+      obstack_sgrow (&output_obstack, "\n\n");
       for (i = ntokens; i < nsyms; i++)
        if (!BITISSET (V, i))
-         fprintf (foutput, "   %s\n", tags[i]);
+         obstack_fgrow1 (&output_obstack, "   %s\n", tags[i]);
     }
   b = FALSE;
   for (i = 0; i < ntokens; i++)
@@ -414,36 +414,35 @@ print_results (void)
        {
          if (!b)
            {
-             fputs ("\n\n", foutput);
-             fprintf (foutput, _("Terminals which are not used:"));
-             fputs ("\n\n", foutput);
+             obstack_sgrow (&output_obstack, "\n\n");
+             obstack_sgrow (&output_obstack,
+                                  _("Terminals which are not used:"));
+             obstack_sgrow (&output_obstack, "\n\n");
              b = TRUE;
            }
-         fprintf (foutput, "   %s\n", tags[i]);
+         obstack_fgrow1 (&output_obstack, "   %s\n", tags[i]);
        }
     }
 
   if (nuseless_productions > 0)
     {
-      fputs ("\n\n", foutput);
-      fprintf (foutput, _("Useless rules:"));
-      fputs ("\n\n", foutput);
+      obstack_sgrow (&output_obstack, "\n\n");
+      obstack_sgrow (&output_obstack, _("Useless rules:"));
+      obstack_sgrow (&output_obstack, "\n\n");
       for (i = 1; i <= nrules; i++)
        {
          if (!BITISSET (P, i))
            {
-             fprintf (foutput, "#%-4d  ", i);
-             fprintf (foutput, "%s :\t", tags[rlhs[i]]);
+             obstack_fgrow1 (&output_obstack, "#%-4d  ", i);
+             obstack_fgrow1 (&output_obstack, "%s :\t", tags[rlhs[i]]);
              for (r = &ritem[rrhs[i]]; *r >= 0; r++)
-               {
-                 fprintf (foutput, " %s", tags[*r]);
-               }
-             fprintf (foutput, ";\n");
+               obstack_fgrow1 (&output_obstack, " %s", tags[*r]);
+             obstack_sgrow (&output_obstack, ";\n");
            }
        }
     }
   if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b)
-    fputs ("\n\n", foutput);
+    obstack_sgrow (&output_obstack, "\n\n");
 }
 \f
 #if 0                          /* XXX currently unused.  */
@@ -453,35 +452,38 @@ dump_grammar (void)
   int i;
   rule r;
 
-  fprintf (foutput,
-          "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n",
-          ntokens, nvars, nsyms, nrules, nitems);
-  fprintf (foutput, _("Variables\n---------\n\n"));
-  fprintf (foutput, _("Value  Sprec    Sassoc    Tag\n"));
+  obstack_fgrow5 (&output_obstack,
+        "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n",
+        ntokens, nvars, nsyms, nrules, nitems);
+  obstack_sgrow (&output_obstack,
+                      _("Variables\n---------\n\n"));
+  obstack_sgrow (&output_obstack,
+                      _("Value  Sprec    Sassoc    Tag\n"));
   for (i = ntokens; i < nsyms; i++)
-    fprintf (foutput, "%5d  %5d  %5d  %s\n", i, sprec[i], sassoc[i], tags[i]);
-  fprintf (foutput, "\n\n");
-  fprintf (foutput, _("Rules\n-----\n\n"));
+    obstack_fgrow4 (&output_obstack,
+                   "%5d  %5d  %5d  %s\n", i, sprec[i], sassoc[i], tags[i]);
+  obstack_sgrow (&output_obstack, "\n\n");
+  obstack_sgrow (&output_obstack, _("Rules\n-----\n\n"));
   for (i = 1; i <= nrules; i++)
     {
-      fprintf (foutput, "%-5d(%5d%5d)%5d : (@%-5d)",
-              i, rprec[i], rassoc[i], rlhs[i], rrhs[i]);
+      obstack_fgrow5 (&output_obstack, "%-5d(%5d%5d)%5d : (@%-5d)",
+                     i, rprec[i], rassoc[i], rlhs[i], rrhs[i]);
       for (r = &ritem[rrhs[i]]; *r > 0; r++)
-       fprintf (foutput, "%5d", *r);
-      fprintf (foutput, " [%d]\n", -(*r));
+       obstack_fgrow1 (&output_obstack, "%5d", *r);
+      obstack_fgrow1 (&output_obstack, " [%d]\n", -(*r));
     }
-  fprintf (foutput, "\n\n");
-  fprintf (foutput, _("Rules interpreted\n-----------------\n\n"));
+  obstack_sgrow (&output_obstack, "\n\n");
+  obstack_sgrow (&output_obstack,
+                      _("Rules interpreted\n-----------------\n\n"));
   for (i = 1; i <= nrules; i++)
     {
-      fprintf (foutput, "%-5d  %s :", i, tags[rlhs[i]]);
+      obstack_fgrow2 (&output_obstack, "%-5d  %s :", i, tags[rlhs[i]]);
       for (r = &ritem[rrhs[i]]; *r > 0; r++)
-       fprintf (foutput, " %s", tags[*r]);
-      fprintf (foutput, "\n");
+       obstack_fgrow1 (&output_obstack, " %s", tags[*r]);
+      obstack_grow1 (&output_obstack, '\n');
     }
-  fprintf (foutput, "\n\n");
+  obstack_sgrow (&output_obstack, "\n\n");
 }
-
 #endif
 
 
@@ -544,7 +546,7 @@ reduce_grammar (void)
 #if 0
   if (verbose_flag)
     {
-      fprintf (foutput, "REDUCED GRAMMAR\n\n");
+      obstack_fgrow1 (&output_obstack, "REDUCED GRAMMAR\n\n");
       dump_grammar ();
     }
 #endif
index 8229d484ee5681128d778988565ee77c0cd0561b..c6f77daeba453b7d76cf94c1dfdce4683b836f63 100644 (file)
@@ -145,8 +145,8 @@ typedef int bool;
 #define obstack_chunk_free  free
 #include "obstack.h"
 
-#define obstack_grow_string(Obs, Str) \
-  obstack_grow (Obs, Str, sizeof (Str) - 1)
+#define obstack_sgrow(Obs, Str) \
+  obstack_grow (Obs, Str, strlen (Str))
 
 #define obstack_fgrow1(Obs, Format, Arg1)      \
 do {                                           \
@@ -169,6 +169,13 @@ do {                                                       \
   obstack_grow (Obs, buf, strlen (buf));               \
 } while (0)
 
+#define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4)    \
+do {                                                           \
+  char buf[4096];                                              \
+  sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4);               \
+  obstack_grow (Obs, buf, strlen (buf));                       \
+} while (0)
+
 
 /*---------------------------------.
 | Machine-dependencies for Bison.  |