cex: don't assume the terminal supports "•"

Use of print_unicode_char suggested by Bruno Haible.
https://lists.gnu.org/r/bug-gettext/2020-06/msg00012.html

* src/gram.h (print_dot_fallback, print_dot): New.
* src/gram.c, src/derivation.c: Use it.
* tests/counterexample.at, tests/report.at: Adjust the test suite.
* .travis.yml, README-hacking.md: Adjust.
This commit is contained in:
Akim Demaille
2020-06-14 09:13:39 +02:00
parent c35e829a76
commit e077bf1ebc
15 changed files with 245 additions and 179 deletions

View File

@@ -167,7 +167,7 @@ derivation_print_impl (const derivation *deriv, FILE *f,
else if (deriv == &d_dot)
{
begin_use_class ("cex-dot", f);
fputs ("", f);
print_dot (f);
end_use_class ("cex-dot", f);
}
else // leaf.

View File

@@ -67,7 +67,8 @@ item_print (item_number *item, rule const *previous_rule, FILE *out)
for (item_number *sp = r->rhs; sp < item; sp++)
fprintf (out, " %s", symbols[*sp]->tag);
fputs (" .", out);
putc (' ', out);
print_dot (out);
if (0 <= *r->rhs)
for (item_number *sp = item; 0 <= *sp; ++sp)
fprintf (out, " %s", symbols[*sp]->tag);

View File

@@ -101,6 +101,10 @@
Associativities are recorded similarly in SYMBOLS[I]->assoc. */
# include "system.h"
# include <unicodeio.h>
# include "location.h"
# include "symtab.h"
@@ -213,6 +217,25 @@ typedef struct
extern rule *rules;
extern rule_number nrules;
/* Fallback in case we can't print "•". */
static inline long
print_dot_fallback (unsigned int code _GL_UNUSED,
const char *msg _GL_UNUSED,
void *callback_arg)
{
FILE *out = (FILE *) callback_arg;
putc ('.', out);
return -1;
}
/* Print "•", the symbol used to represent a point in an item (aka, a
pointed rule). */
static inline void
print_dot (FILE *out)
{
unicode_to_mb (0x2022, fwrite_success_callback, print_dot_fallback, out);
}
/* Get the rule associated to this item. ITEM points inside RITEM. */
rule const *item_rule (item_number const *item);

View File

@@ -133,10 +133,15 @@ src_bison_LDADD = \
$(ISNANL_LIBM) \
$(LDEXPL_LIBM) \
$(LDEXP_LIBM) \
$(LIBINTL) \
$(LIBTHREAD) \
$(LIB_CLOCK_GETTIME) \
$(LIB_GETHRXTIME) \
$(LIB_HARD_LOCALE) \
$(LIB_MBRTOWC) \
$(LIB_SETLOCALE_NULL) \
$(LIBICONV) \
$(LIBINTL) \
$(LIBREADLINE) \
$(LIBTEXTSTYLE)