summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2011-11-01 11:23:24 +0000
committerAmaury Pouly <pamaury@rockbox.org>2011-11-01 11:23:24 +0000
commit591ec0349b424e94eaaaa1c9bf486f769ff34732 (patch)
treef08595af7af1d51a456bcaaf516b7a30cda12c57
parent9e0ab22262ffd29b5273bb23162a15bf0a8c391f (diff)
downloadrockbox-591ec0349b424e94eaaaa1c9bf486f769ff34732.tar.gz
rockbox-591ec0349b424e94eaaaa1c9bf486f769ff34732.zip
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
-rw-r--r--utils/sbtools/misc.c21
-rw-r--r--utils/sbtools/misc.h6
-rw-r--r--utils/sbtools/sbtoelf.c25
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)
211 if(newline) 211 if(newline)
212 printf("\n"); 212 printf("\n");
213} 213}
214
215char OFF[] = { 0x1b, 0x5b, 0x31, 0x3b, '0', '0', 0x6d, '\0' };
216
217char GREY[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '0', 0x6d, '\0' };
218char RED[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '1', 0x6d, '\0' };
219char GREEN[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '2', 0x6d, '\0' };
220char YELLOW[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '3', 0x6d, '\0' };
221char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' };
222
223static bool g_color_enable = true;
224
225void enable_color(bool enable)
226{
227 g_color_enable = enable;
228}
229
230void color(color_t c)
231{
232 if(g_color_enable)
233 printf("%s", (char *)c);
234}
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);
48void add_keys_from_file(const char *key_file); 48void add_keys_from_file(const char *key_file);
49void print_key(struct crypto_key_t *key, bool newline); 49void print_key(struct crypto_key_t *key, bool newline);
50 50
51typedef char color_t[];
52
53extern color_t OFF, GREY, RED, GREEN, YELLOW, BLUE;
54void color(color_t c);
55void enable_color(bool enable);
56
51#endif /* __MISC_H__ */ 57#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 @@
42#include "sb.h" 42#include "sb.h"
43#include "misc.h" 43#include "misc.h"
44 44
45#if 1 /* ANSI colors */
46
47# define color(a) printf("%s",a)
48char OFF[] = { 0x1b, 0x5b, 0x31, 0x3b, '0', '0', 0x6d, '\0' };
49
50char GREY[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '0', 0x6d, '\0' };
51char RED[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '1', 0x6d, '\0' };
52char GREEN[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '2', 0x6d, '\0' };
53char YELLOW[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '3', 0x6d, '\0' };
54char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' };
55
56#else
57 /* disable colors */
58# define color(a)
59#endif
60
61/* all blocks are sized as a multiple of 0x1ff */ 45/* all blocks are sized as a multiple of 0x1ff */
62#define PAD_TO_BOUNDARY(x) (((x) + 0x1ff) & ~0x1ff) 46#define PAD_TO_BOUNDARY(x) (((x) + 0x1ff) & ~0x1ff)
63 47
@@ -723,7 +707,8 @@ void usage(void)
723 printf(" -k <file>\tAdd key file\n"); 707 printf(" -k <file>\tAdd key file\n");
724 printf(" -z\t\tAdd zero key\n"); 708 printf(" -z\t\tAdd zero key\n");
725 printf(" -r\t\tUse raw command mode\n"); 709 printf(" -r\t\tUse raw command mode\n");
726 printf(" --add-key <key>\tAdd single key (hex or usbotp)\n"); 710 printf(" -a/--add-key <key>\tAdd single key (hex or usbotp)\n");
711 printf(" -n/--no-color\tDisable output colors\n");
727 exit(1); 712 exit(1);
728} 713}
729 714
@@ -742,16 +727,20 @@ int main(int argc, char **argv)
742 {"help", no_argument, 0, '?'}, 727 {"help", no_argument, 0, '?'},
743 {"debug", no_argument, 0, 'd'}, 728 {"debug", no_argument, 0, 'd'},
744 {"add-key", required_argument, 0, 'a'}, 729 {"add-key", required_argument, 0, 'a'},
730 {"no-color", no_argument, 0, 'n'},
745 {0, 0, 0, 0} 731 {0, 0, 0, 0}
746 }; 732 };
747 733
748 int c = getopt_long(argc, argv, "?do:k:zra:", long_options, NULL); 734 int c = getopt_long(argc, argv, "?do:k:zra:n", long_options, NULL);
749 if(c == -1) 735 if(c == -1)
750 break; 736 break;
751 switch(c) 737 switch(c)
752 { 738 {
753 case -1: 739 case -1:
754 break; 740 break;
741 case 'n':
742 enable_color(false);
743 break;
755 case 'd': 744 case 'd':
756 g_debug = true; 745 g_debug = true;
757 break; 746 break;