From 23e536af498ac6ecb42cb00a0bd09bf34835126f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 7 May 2019 08:41:29 +0200 Subject: [PATCH] diagnostics: support --color=html Based on a message from Bruno Haible. https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=fe18e92743b7226791a5f28d7c786941a1bf8cc9 This does not generate proper HTML: special characters are not escaped for instance. This is a hidden feature meant for Bison developers, not end users. * src/complain.c (complain_init_color): Support --color=html. --- src/complain.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/complain.c b/src/complain.c index 8a6d8c57..b6412441 100644 --- a/src/complain.c +++ b/src/complain.c @@ -252,6 +252,7 @@ complain_init_color (void) { #if HAVE_LIBTEXTSTYLE if (color_mode == color_yes + || color_mode == color_html || (color_mode == color_tty && isatty (STDERR_FILENO))) { style_file_prepare ("BISON_DIAGNOSTICS_STYLE", NULL, @@ -268,9 +269,25 @@ complain_init_color (void) style_file_name = NULL; #endif + /* Workaround clang's warning (starting at Clang 3.5) about the stub + code of html_styled_ostream_create: + + | src/complain.c:274:7: error: code will never be executed [-Werror,-Wunreachable-code] + | ? html_styled_ostream_create (file_ostream_create (stderr), + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#if defined __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunreachable-code" +#endif errstream = - styled_ostream_create (STDERR_FILENO, "(stderr)", TTYCTL_AUTO, - style_file_name); + color_mode == color_html + ? html_styled_ostream_create (file_ostream_create (stderr), + style_file_name) + : styled_ostream_create (STDERR_FILENO, "(stderr)", TTYCTL_AUTO, + style_file_name); +#if defined __clang__ +# pragma clang diagnostic pop +#endif } void