+/*--------------------------------------------------------------.
+| Return a human readable string which reports shift/reduce and |
+| reduce/reduce conflict numbers (SRC_NUM, RRC_NUM). |
+`--------------------------------------------------------------*/
+
+static const char *
+conflict_report (int src_num, int rrc_num)
+{
+ static char res[4096];
+ char *cp = res;
+
+ if (src_num == 1)
+ {
+ sprintf (cp, _(" 1 shift/reduce conflict"));
+ cp += strlen (cp);
+ }
+ else if (src_num > 1)
+ {
+ sprintf (cp, _(" %d shift/reduce conflicts"), src_num);
+ cp += strlen (cp);
+ }
+
+ if (src_num > 0 && rrc_num > 0)
+ {
+ sprintf (cp, _(" and"));
+ cp += strlen (cp);
+ }
+
+ if (rrc_num == 1)
+ {
+ sprintf (cp, _(" 1 reduce/reduce conflict"));
+ cp += strlen (cp);
+ }
+ else if (rrc_num > 1)
+ {
+ sprintf (cp, _(" %d reduce/reduce conflicts"), rrc_num);
+ cp += strlen (cp);
+ }
+
+ *cp++ = '.';
+ *cp++ = '\n';
+ *cp++ = '\0';
+
+ return res;
+}
+
+
+/*---------------------------------------------.
+| Compute and give a report on the conflicts. |
+`---------------------------------------------*/
+
+void
+print_conflicts (void)
+{
+ int i;
+
+ src_total = 0;
+ rrc_total = 0;
+
+ /* Count the total number of conflicts, and if wanted, give a
+ detailed report in FOUTPUT. */
+ for (i = 0; i < nstates; i++)
+ {
+ if (conflicts[i])
+ {
+ count_sr_conflicts (i);
+ count_rr_conflicts (i);
+ src_total += src_count;
+ rrc_total += rrc_count;
+
+ if (verbose_flag)
+ {
+ obstack_fgrow1 (&output_obstack, _("State %d contains"), i);
+ obstack_sgrow (&output_obstack,
+ conflict_report (src_count, rrc_count));
+ }
+ }
+ }
+
+ /* Report the total number of conflicts on STDERR. */
+ if (yacc_flag)
+ {
+ /* If invoked with `--yacc', use the output format specified by
+ POSIX. */
+ fprintf (stderr, _("conflicts: "));
+ if (src_total > 0)
+ fprintf (stderr, _(" %d shift/reduce"), src_total);
+ if (src_total > 0 && rrc_total > 0)
+ fprintf (stderr, ",");
+ if (rrc_total > 0)
+ fprintf (stderr, _(" %d reduce/reduce"), rrc_total);
+ putc ('\n', stderr);
+ }
+ else
+ {
+ fprintf (stderr, _("%s contains"), infile);
+ fputs (conflict_report (src_total, rrc_total), stderr);
+ }
+}
+