summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-06-13 16:03:53 +0200
committerAkim Demaille <akim.demaille@gmail.com>2020-06-13 16:58:13 +0200
commitefbcadeca72dc339802e1760db7f8336bd20f514 (patch)
treec16f87f9e45e3e324f77aca4221c94126892df95 /src
parente4d33cf57914b3718762183bcc9237fc03f3c1fe (diff)
downloadbison-efbcadeca72dc339802e1760db7f8336bd20f514.tar.gz
reports: don't escape the labels
Currently we use "quotearg" to escape the strings output in Dot. As a result, if the user's locale is C for instance, all the non-ASCII are escaped. Unfortunately graphviz does not interpret this style of escaping. For instance: 5 -> 2 [style=solid label="\"\303\221\303\271\341\271\203\303\251\342\204\235\303\264\""] was displayed as a sequence of numbers. We now output: 5 -> 2 [style=solid label="\"Ñùṃéℝô\""] independently of the user's locale. * src/system.h (obstack_backslash): New. * src/graphviz.h, src/graphviz.c (escape): Remove, use obstack_backslash instead. * src/print-graph.c: Likewise. * tests/report.at: Adjust.
Diffstat (limited to 'src')
-rw-r--r--src/graphviz.c22
-rw-r--r--src/graphviz.h6
-rw-r--r--src/print-graph.c19
-rw-r--r--src/system.h17
4 files changed, 43 insertions, 21 deletions
diff --git a/src/graphviz.c b/src/graphviz.c
index 80a2ff99..34d80b03 100644
--- a/src/graphviz.c
+++ b/src/graphviz.c
@@ -72,18 +72,20 @@ output_edge (int source, int destination, char const *label,
{
fprintf (fout, " %d -> %d [style=%s", source, destination, style);
if (label)
- fprintf (fout, " label=%s", quote (label));
+ {
+ fputs (" label=\"", fout);
+ for (const char *cp = label; *cp; ++cp)
+ switch (*cp)
+ {
+ case '"': fputs ("\\\"", fout); break;
+ case '\\': fputs ("\\\\", fout); break;
+ default: fputc (*cp, fout); break;
+ }
+ fputc ('"', fout);
+ }
fputs ("]\n", fout);
}
-char const *
-escape (char const *name)
-{
- char *q = quote (name);
- q[strlen (q) - 1] = '\0';
- return q + 1;
-}
-
static void
no_reduce_bitset_init (state const *s, bitset *no_reduce_set)
{
@@ -149,7 +151,7 @@ print_token (struct obstack *out, bool first, char const *tok)
{
if (! first)
obstack_sgrow (out, ", ");
- obstack_sgrow (out, escape (tok));
+ obstack_backslash (out, tok);
return false;
}
diff --git a/src/graphviz.h b/src/graphviz.h
index 06b42358..ead22ffd 100644
--- a/src/graphviz.h
+++ b/src/graphviz.h
@@ -63,10 +63,4 @@ void output_red (state const *s, reductions const *reds, FILE *fout);
*/
void finish_graph (FILE *fout);
-/** Escape a lookahead token.
- *
- * \param name the token.
- */
-char const *escape (char const *name);
-
#endif /* ! GRAPHVIZ_H_ */
diff --git a/src/print-graph.c b/src/print-graph.c
index 5691c6d8..adaa8bed 100644
--- a/src/print-graph.c
+++ b/src/print-graph.c
@@ -72,19 +72,28 @@ print_core (struct obstack *oout, state *s)
obstack_printf (oout, "%*s| ",
(int) strlen (previous_lhs->symbol->tag), "");
else
- obstack_printf (oout, "%s: ", escape (r->lhs->symbol->tag));
+ {
+ obstack_backslash (oout, r->lhs->symbol->tag);
+ obstack_printf (oout, ": ");
+ }
previous_lhs = r->lhs;
for (item_number const *sp = r->rhs; sp < sp1; sp++)
- obstack_printf (oout, "%s ", escape (symbols[*sp]->tag));
+ {
+ obstack_backslash (oout, symbols[*sp]->tag);
+ obstack_1grow (oout, ' ');
+ }
obstack_1grow (oout, '.');
if (0 <= *r->rhs)
for (item_number const *sp = sp1; 0 <= *sp; ++sp)
- obstack_printf (oout, " %s", escape (symbols[*sp]->tag));
+ {
+ obstack_1grow (oout, ' ');
+ obstack_backslash (oout, symbols[*sp]->tag);
+ }
else
- obstack_printf (oout, " %%empty");
+ obstack_sgrow (oout, " %empty");
/* Experimental feature: display the lookahead tokens. */
if (report_flag & report_lookahead_tokens
@@ -104,7 +113,7 @@ print_core (struct obstack *oout, state *s)
BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
{
obstack_sgrow (oout, sep);
- obstack_sgrow (oout, escape (symbols[k]->tag));
+ obstack_backslash (oout, symbols[k]->tag);
sep = ", ";
}
obstack_1grow (oout, ']');
diff --git a/src/system.h b/src/system.h
index 33986069..eac89c27 100644
--- a/src/system.h
+++ b/src/system.h
@@ -171,6 +171,23 @@ typedef size_t uintptr_t;
# define obstack_sgrow(Obs, Str) \
obstack_grow (Obs, Str, strlen (Str))
+/* Output Str escaped to be a string.
+
+ For instance "\"foo\"" -> "\\\"foo\\\"". */
+
+# define obstack_backslash(Obs, Str) \
+ do { \
+ char const *p__; \
+ for (p__ = Str; *p__; p__++) \
+ switch (*p__) \
+ { \
+ case '"': obstack_sgrow (Obs, "\\\""); break; \
+ case '\\': obstack_sgrow (Obs, "\\\\"); break; \
+ default: obstack_1grow (Obs, *p__); break; \
+ } \
+ } while (0)
+
+
/* Output Str escaped for our postprocessing (i.e., escape M4 special
characters).