From a915eef8e9e5d066135bcaf61fcf436d6e3ad648 Mon Sep 17 00:00:00 2001 From: marcobaye Date: Fri, 10 Mar 2017 12:19:15 +0000 Subject: [PATCH] ACME release 0.96.2: Error output now in color using ANSI escape codes. Thanks to Clifford Carnmo for submitting this patch! git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@86 4df02467-bbd4-4a76-a152-e7ce94205b78 --- docs/Changes.txt | 8 ++++++++ src/acme.c | 4 ++++ src/global.c | 16 +++++++++++++--- src/global.h | 1 + src/version.h | 4 ++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/Changes.txt b/docs/Changes.txt index 663f06d..f53a59a 100644 --- a/docs/Changes.txt +++ b/docs/Changes.txt @@ -12,6 +12,14 @@ platform used. There should be another help file in this archive outlining the platform specific changes. +---------------------------------------------------------------------- +Section: New in release 0.96.2 +---------------------------------------------------------------------- + +Added "--color" CLI switch to enable colored error output using ANSI + escape codes. Thanks to Clifford Carnmo for submitting this patch. + + ---------------------------------------------------------------------- Section: New in release 0.96.1 ---------------------------------------------------------------------- diff --git a/src/acme.c b/src/acme.c index b2e35fe..4c4e78d 100644 --- a/src/acme.c +++ b/src/acme.c @@ -61,6 +61,7 @@ static const char arg_vicelabels[] = "VICE labels filename"; #define OPTION_USE_STDOUT "use-stdout" #define OPTION_VERSION "version" #define OPTION_MSVC "msvc" +#define OPTION_COLOR "color" // options for "-W" #define OPTIONWNO_LABEL_INDENT "no-label-indent" #define OPTIONWNO_OLD_FOR "no-old-for" @@ -138,6 +139,7 @@ static void show_help_and_exit(void) //" -W show warning level options\n" " --" OPTION_USE_STDOUT " fix for 'Relaunch64' IDE (see docs)\n" " --" OPTION_MSVC " set output error message format to that of MS Visual Studio\n" +" --" OPTION_COLOR " enable colored error output using ANSI escape codes\n" PLATFORM_OPTION_HELP " -V, --" OPTION_VERSION " show version and exit\n"); exit(EXIT_SUCCESS); @@ -464,6 +466,8 @@ static const char *long_option(const char *string) else if (strcmp(string, OPTION_MSVC) == 0) format_msvc = TRUE; PLATFORM_LONGOPTION_CODE + else if (strcmp(string, OPTION_COLOR) == 0) + format_color = TRUE; else if (strcmp(string, OPTION_VERSION) == 0) show_version(TRUE); else diff --git a/src/global.c b/src/global.c index 854d183..af79f95 100644 --- a/src/global.c +++ b/src/global.c @@ -118,6 +118,7 @@ int pass_real_errors; // Errors yet signed long max_errors = MAXERRORS; // errors before giving up FILE *msg_stream = NULL; // set to stdout by --use-stdout int format_msvc = FALSE; // actually bool, enabled by --msvc +int format_color = FALSE; // actually bool, enabled by --color struct report *report = NULL; @@ -341,7 +342,10 @@ static void throw_message(const char *message, const char *type) void Throw_warning(const char *message) { PLATFORM_WARNING(message); - throw_message(message, "Warning"); + if (format_color) + throw_message(message, "\033[33mWarning\033[0m"); + else + throw_message(message, "Warning"); } // Output a warning if in first pass. See above. void Throw_first_pass_warning(const char *message) @@ -359,7 +363,10 @@ void Throw_first_pass_warning(const char *message) void Throw_error(const char *message) { PLATFORM_ERROR(message); - throw_message(message, "Error"); + if (format_color) + throw_message(message, "\033[31mError\033[0m"); + else + throw_message(message, "Error"); ++pass_real_errors; if (pass_real_errors >= max_errors) exit(ACME_finalize(EXIT_FAILURE)); @@ -373,7 +380,10 @@ void Throw_error(const char *message) void Throw_serious_error(const char *message) { PLATFORM_SERIOUS(message); - throw_message(message, "Serious error"); + if (format_color) + throw_message(message, "\033[1m\033[31mSerious error\033[0m"); + else + throw_message(message, "Serious error"); // FIXME - exiting immediately inhibits output of macro call stack! exit(ACME_finalize(EXIT_FAILURE)); } diff --git a/src/global.h b/src/global.h index b68129e..7fba4aa 100644 --- a/src/global.h +++ b/src/global.h @@ -72,6 +72,7 @@ extern int pass_real_errors; // Errors yet extern signed long max_errors; // errors before giving up extern FILE *msg_stream; // set to stdout by --errors_to_stdout extern int format_msvc; // actually bool, enabled by --msvc +extern int format_color; // actually bool, enabled by --color // report stuff #define REPORT_ASCBUFSIZE 1024 diff --git a/src/version.h b/src/version.h index 795c2d7..a644ad4 100644 --- a/src/version.h +++ b/src/version.h @@ -7,9 +7,9 @@ #define version_H -#define RELEASE "0.96.1" // update before release (FIXME) +#define RELEASE "0.96.2" // update before release (FIXME) #define CODENAME "Fenchurch" // update before release -#define CHANGE_DATE "8 Jan" // update before release +#define CHANGE_DATE "10 Mar" // update before release #define CHANGE_YEAR "2017" // update before release //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" // FIXME #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME