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
This commit is contained in:
Amaury Pouly 2011-11-01 11:23:24 +00:00
parent 9e0ab22262
commit 591ec0349b
3 changed files with 34 additions and 18 deletions

View file

@ -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);
}

View file

@ -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__ */

View file

@ -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 <file>\tAdd key file\n");
printf(" -z\t\tAdd zero key\n");
printf(" -r\t\tUse raw command mode\n");
printf(" --add-key <key>\tAdd single key (hex or usbotp)\n");
printf(" -a/--add-key <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;