From 591ec0349b424e94eaaaa1c9bf486f769ff34732 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Tue, 1 Nov 2011 11:23:24 +0000 Subject: [PATCH] sbtools: rework the color hack and add switch to disable color output git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30880 a1c6a512-1295-4272-9138-f99709370657 --- utils/sbtools/misc.c | 21 +++++++++++++++++++++ utils/sbtools/misc.h | 6 ++++++ utils/sbtools/sbtoelf.c | 25 +++++++------------------ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/utils/sbtools/misc.c b/utils/sbtools/misc.c index 39934951ae..4eeda4ef33 100644 --- a/utils/sbtools/misc.c +++ b/utils/sbtools/misc.c @@ -211,3 +211,24 @@ void print_key(struct crypto_key_t *key, bool newline) if(newline) printf("\n"); } + +char OFF[] = { 0x1b, 0x5b, 0x31, 0x3b, '0', '0', 0x6d, '\0' }; + +char GREY[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '0', 0x6d, '\0' }; +char RED[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '1', 0x6d, '\0' }; +char GREEN[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '2', 0x6d, '\0' }; +char YELLOW[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '3', 0x6d, '\0' }; +char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' }; + +static bool g_color_enable = true; + +void enable_color(bool enable) +{ + g_color_enable = enable; +} + +void color(color_t c) +{ + if(g_color_enable) + printf("%s", (char *)c); +} diff --git a/utils/sbtools/misc.h b/utils/sbtools/misc.h index cc0a3fb5ea..a685816047 100644 --- a/utils/sbtools/misc.h +++ b/utils/sbtools/misc.h @@ -48,4 +48,10 @@ bool parse_key(char **str, struct crypto_key_t *key); void add_keys_from_file(const char *key_file); void print_key(struct crypto_key_t *key, bool newline); +typedef char color_t[]; + +extern color_t OFF, GREY, RED, GREEN, YELLOW, BLUE; +void color(color_t c); +void enable_color(bool enable); + #endif /* __MISC_H__ */ diff --git a/utils/sbtools/sbtoelf.c b/utils/sbtools/sbtoelf.c index 47aebe7890..24417dc88e 100644 --- a/utils/sbtools/sbtoelf.c +++ b/utils/sbtools/sbtoelf.c @@ -42,22 +42,6 @@ #include "sb.h" #include "misc.h" -#if 1 /* ANSI colors */ - -# define color(a) printf("%s",a) -char OFF[] = { 0x1b, 0x5b, 0x31, 0x3b, '0', '0', 0x6d, '\0' }; - -char GREY[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '0', 0x6d, '\0' }; -char RED[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '1', 0x6d, '\0' }; -char GREEN[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '2', 0x6d, '\0' }; -char YELLOW[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '3', 0x6d, '\0' }; -char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' }; - -#else - /* disable colors */ -# define color(a) -#endif - /* all blocks are sized as a multiple of 0x1ff */ #define PAD_TO_BOUNDARY(x) (((x) + 0x1ff) & ~0x1ff) @@ -723,7 +707,8 @@ void usage(void) printf(" -k \tAdd key file\n"); printf(" -z\t\tAdd zero key\n"); printf(" -r\t\tUse raw command mode\n"); - printf(" --add-key \tAdd single key (hex or usbotp)\n"); + printf(" -a/--add-key \tAdd single key (hex or usbotp)\n"); + printf(" -n/--no-color\tDisable output colors\n"); exit(1); } @@ -742,16 +727,20 @@ int main(int argc, char **argv) {"help", no_argument, 0, '?'}, {"debug", no_argument, 0, 'd'}, {"add-key", required_argument, 0, 'a'}, + {"no-color", no_argument, 0, 'n'}, {0, 0, 0, 0} }; - int c = getopt_long(argc, argv, "?do:k:zra:", long_options, NULL); + int c = getopt_long(argc, argv, "?do:k:zra:n", long_options, NULL); if(c == -1) break; switch(c) { case -1: break; + case 'n': + enable_color(false); + break; case 'd': g_debug = true; break;