diagnostics: use gnulib's libtextstyle-optional

Bruno Haible just added a default implementation of libtextstyle's
interface when the library is not available.
https://lists.gnu.org/archive/html/bison-patches/2019-03/msg00025.html

* gnulib: Update.
* bootstrap.conf: Replace libtextstyle with libtextstyle-optional.
* src/complain.c, src/getargs.c: Remove now useless cpp guards.
This commit is contained in:
Akim Demaille
2019-03-17 19:40:08 +01:00
parent 22a413ce9f
commit 4d34b06fb3
8 changed files with 72 additions and 50 deletions

28
NEWS
View File

@@ -10,6 +10,34 @@ GNU Bison NEWS
** New features ** New features
*** Colored diagnostics
As an experimental feature, Bison now generates colored diagnostics,
controlled by the new options --color and --style.
Install the libtextstyle library before configuring Bison to use them.
It is available from
https://alpha.gnu.org/gnu/gettext/
for instance
https://alpha.gnu.org/gnu/gettext/libtextstyle-0.7.tar.gz
The option --color supports the following arguments:
- always, yes: Enable colors.
- never, no: Disable colors.
- auto, tty (default): Enable colors if the output device is a tty.
To customize the styles, create a CSS file similar to
/* black-and-white.css */
.warning { }
.error { font-weight: 800; text-decoration: underline; }
.note { }
then invoke bison with --style=black-and-white.css.
*** Disabling output *** Disabling output
When given -fsyntax-only, the diagnostics are reported, but no output is When given -fsyntax-only, the diagnostics are reported, but no output is

View File

@@ -28,7 +28,7 @@ gnulib_modules='
gpl-3.0 hash inttypes isnan javacomp-script gpl-3.0 hash inttypes isnan javacomp-script
javaexec-script javaexec-script
ldexpl ldexpl
libtextstyle libtextstyle-optional
malloc-gnu malloc-gnu
mbswidth mbswidth
non-recursive-gnulib-prefix-hack non-recursive-gnulib-prefix-hack

View File

@@ -1,3 +1,8 @@
.warning { color : purple; } /* CSS style for Bison's diagnostics.
.error { color : red; }
.note { color : cyan; } This is an experimental feature. The class names may change in the
future. */
.warning { color: purple; }
.error { color: red; }
.note { color: cyan; }

2
gnulib

Submodule gnulib updated: 9a943f6948...0d8714b7ce

2
lib/.gitignore vendored
View File

@@ -319,3 +319,5 @@
/rmdir.c /rmdir.c
/same-inode.h /same-inode.h
/assure.h /assure.h
/fsync.c
/textstyle.in.h

46
m4/.gitignore vendored
View File

@@ -5,6 +5,8 @@
/asm-underscore.m4 /asm-underscore.m4
/assert.m4 /assert.m4
/calloc.m4 /calloc.m4
/canonicalize.m4
/clock_time.m4
/close-stream.m4 /close-stream.m4
/close.m4 /close.m4
/closeout.m4 /closeout.m4
@@ -36,19 +38,26 @@
/frexpl.m4 /frexpl.m4
/fseterr.m4 /fseterr.m4
/fstat.m4 /fstat.m4
/fsync.m4
/getdtablesize.m4 /getdtablesize.m4
/gethrxtime.m4
/getopt.m4 /getopt.m4
/getprogname.m4 /getprogname.m4
/getrusage.m4
/gettext.m4 /gettext.m4
/gettime.m4
/gettimeofday.m4
/glibc2.m4 /glibc2.m4
/glibc21.m4 /glibc21.m4
/gnulib-cache.m4 /gnulib-cache.m4
/gnulib-common.m4 /gnulib-common.m4
/gnulib-comp.m4 /gnulib-comp.m4
/gnulib-tool.m4 /gnulib-tool.m4
/host-cpu-c-abi.m4
/iconv.m4 /iconv.m4
/include_next.m4 /include_next.m4
/intdiv0.m4 /intdiv0.m4
/intl-thread-locale.m4
/intl.m4 /intl.m4
/intldir.m4 /intldir.m4
/intlmacosx.m4 /intlmacosx.m4
@@ -70,12 +79,15 @@
/lib-ld.m4 /lib-ld.m4
/lib-link.m4 /lib-link.m4
/lib-prefix.m4 /lib-prefix.m4
/libtextstyle-optional.m4
/libtextstyle.m4
/libunistring-base.m4 /libunistring-base.m4
/limits-h.m4 /limits-h.m4
/localcharset.m4 /localcharset.m4
/locale-fr.m4 /locale-fr.m4
/locale-ja.m4 /locale-ja.m4
/locale-zh.m4 /locale-zh.m4
/localtime-buffer.m4
/lock.m4 /lock.m4
/longlong.m4 /longlong.m4
/lstat.m4 /lstat.m4
@@ -117,9 +129,15 @@
/quotearg.m4 /quotearg.m4
/raise.m4 /raise.m4
/rawmemchr.m4 /rawmemchr.m4
/readlink.m4
/realloc.m4 /realloc.m4
/relocatable-lib.m4
/relocatable.m4
/rename.m4
/rmdir.m4
/sched_h.m4 /sched_h.m4
/setenv.m4 /setenv.m4
/sh-filename.m4
/sig_atomic_t.m4 /sig_atomic_t.m4
/sigaction.m4 /sigaction.m4
/signal_h.m4 /signal_h.m4
@@ -132,7 +150,9 @@
/spawn_h.m4 /spawn_h.m4
/sprintf-posix.m4 /sprintf-posix.m4
/ssize_t.m4 /ssize_t.m4
/stat-time.m4
/stat.m4 /stat.m4
/std-gnu11.m4
/stdbool.m4 /stdbool.m4
/stddef_h.m4 /stddef_h.m4
/stdint.m4 /stdint.m4
@@ -148,12 +168,16 @@
/strndup.m4 /strndup.m4
/strnlen.m4 /strnlen.m4
/strverscmp.m4 /strverscmp.m4
/sys_resource_h.m4
/sys_socket_h.m4 /sys_socket_h.m4
/sys_stat_h.m4 /sys_stat_h.m4
/sys_time_h.m4
/sys_times_h.m4
/sys_types_h.m4 /sys_types_h.m4
/sys_wait_h.m4 /sys_wait_h.m4
/threadlib.m4 /threadlib.m4
/time_h.m4 /time_h.m4
/timespec.m4
/uintmax_t.m4 /uintmax_t.m4
/unistd-safer.m4 /unistd-safer.m4
/unistd_h.m4 /unistd_h.m4
@@ -177,25 +201,3 @@
/xalloc.m4 /xalloc.m4
/xsize.m4 /xsize.m4
/xstrndup.m4 /xstrndup.m4
/host-cpu-c-abi.m4
/stat-time.m4
/sys_time_h.m4
/sys_times_h.m4
/sh-filename.m4
/clock_time.m4
/gethrxtime.m4
/getrusage.m4
/gettime.m4
/gettimeofday.m4
/localtime-buffer.m4
/sys_resource_h.m4
/timespec.m4
/intl-thread-locale.m4
/canonicalize.m4
/readlink.m4
/relocatable-lib.m4
/relocatable.m4
/libtextstyle.m4
/rename.m4
/rmdir.m4
/std-gnu11.m4

View File

@@ -23,13 +23,10 @@
#include "system.h" #include "system.h"
#include <argmatch.h> #include <argmatch.h>
#include <stdarg.h>
#include <progname.h> #include <progname.h>
#include <stdarg.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <textstyle.h>
#if HAVE_LIBTEXTSTYLE
# include <textstyle.h>
#endif
#include "complain.h" #include "complain.h"
#include "files.h" #include "files.h"
@@ -68,41 +65,33 @@ static severity warnings_flag[warnings_size];
static unsigned *indent_ptr = NULL; static unsigned *indent_ptr = NULL;
#if HAVE_LIBTEXTSTYLE
styled_ostream_t errstream = NULL; styled_ostream_t errstream = NULL;
#endif
void void
begin_use_class (const char *s _GL_UNUSED, FILE *out _GL_UNUSED) begin_use_class (const char *s, FILE *out)
{ {
#if HAVE_LIBTEXTSTYLE
if (out == stderr) if (out == stderr)
{ {
styled_ostream_begin_use_class (errstream, s); styled_ostream_begin_use_class (errstream, s);
styled_ostream_flush_to_current_style (errstream); styled_ostream_flush_to_current_style (errstream);
} }
#endif
} }
void void
end_use_class (const char *s _GL_UNUSED, FILE *out _GL_UNUSED) end_use_class (const char *s, FILE *out)
{ {
#if HAVE_LIBTEXTSTYLE
if (out == stderr) if (out == stderr)
{ {
styled_ostream_end_use_class (errstream, s); styled_ostream_end_use_class (errstream, s);
styled_ostream_flush_to_current_style (errstream); styled_ostream_flush_to_current_style (errstream);
} }
#endif
} }
void void
flush (FILE *out _GL_UNUSED) flush (FILE *out)
{ {
#if HAVE_LIBTEXTSTYLE
if (out == stderr) if (out == stderr)
ostream_flush (errstream, FLUSH_THIS_STREAM); ostream_flush (errstream, FLUSH_THIS_STREAM);
#endif
fflush (out); fflush (out);
} }
@@ -267,10 +256,11 @@ complain_init_color (void)
else else
/* No styling. */ /* No styling. */
style_file_name = NULL; style_file_name = NULL;
#endif
errstream = errstream =
styled_ostream_create (STDERR_FILENO, "(stderr)", TTYCTL_AUTO, styled_ostream_create (STDERR_FILENO, "(stderr)", TTYCTL_AUTO,
style_file_name); style_file_name);
#endif
} }
void void

View File

@@ -30,10 +30,7 @@
#include <getopt.h> #include <getopt.h>
#include <progname.h> #include <progname.h>
#include <quote.h> #include <quote.h>
#include <textstyle.h>
#if HAVE_LIBTEXTSTYLE
# include <textstyle.h>
#endif
#include "complain.h" #include "complain.h"
#include "files.h" #include "files.h"
@@ -590,7 +587,6 @@ command_line_location (void)
static void static void
getargs_colors (int argc _GL_UNUSED, char *argv[] _GL_UNUSED) getargs_colors (int argc _GL_UNUSED, char *argv[] _GL_UNUSED)
{ {
#if HAVE_LIBTEXTSTYLE
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
{ {
const char *arg = argv[i]; const char *arg = argv[i];
@@ -600,7 +596,6 @@ getargs_colors (int argc _GL_UNUSED, char *argv[] _GL_UNUSED)
handle_style_option (arg + strlen ("--style=")); handle_style_option (arg + strlen ("--style="));
} }
complain_init_color (); complain_init_color ();
#endif
} }