diff options
-rw-r--r-- | uxd.1 | 1 | ||||
-rw-r--r-- | uxd.c | 46 | ||||
-rw-r--r-- | uxd.rst | 1 |
3 files changed, 40 insertions, 8 deletions
@@ -72,7 +72,6 @@ normal characters, the 3rd digit (optional) is the color for non\-printable and space characters, and the 4th (optional) is for invalid UTF\-8 sequences. Default: \fB2351\fP\&. This option also disables a prior \fB\-m\fP option. -NOT IMPLEMENTED YET. .TP .B \-h\fP,\fB \-\-help Print built\-in usage message and exit. @@ -63,11 +63,13 @@ extern int optind; #define SPECIAL PURPLE #define BAD_FG BLACK -#define BAD_BG RED +#define BAD_BG bad_color -const int normal_colors[] = { GREEN, YELLOW }; +int normal_colors[] = { GREEN, YELLOW }; int cur_normal_color = 0; int dump_color; +int bad_color = RED; +int special_color = SPECIAL; const char *self; FILE *input; @@ -128,6 +130,36 @@ void open_input(const char *arg) { } } +void color_error(void) { + fprintf(stderr, "%s: invalid -c colors (-h for help).\n", self); + exit(1); +} + +void check_color(char c) { + if(c < '0' || c > '7') color_error(); +} + +void parse_colors(char *arg) { + if(!arg[0]) return; /* should never happen anyway */ + + /* first 2 are required */ + check_color(arg[0]); + check_color(arg[1]); + + normal_colors[0] = arg[0] - '0'; + normal_colors[1] = arg[1] - '0'; + + /* optional 3rd color */ + if(!arg[2]) return; + check_color(arg[2]); + special_color = arg[2] - '0'; + + /* optional 4th color */ + if(!arg[3]) return; + check_color(arg[3]); + bad_color = arg[3] - '0'; +} + long parse_number(const char *s) { return strtol(s, NULL, 0); /* TODO: error checking */ } @@ -142,10 +174,12 @@ void parse_args(int argc, char **argv) { version(); } - while((opt = my_getopt(argc, argv, "nbl:rmo:S:s:uhv")) != -1) { + while((opt = my_getopt(argc, argv, "c:nbl:rmo:S:s:uhv")) != -1) { switch(opt) { + case 'c': + mono = 0; parse_colors(optarg); break; case 'n': - break; + break; /* already handled in parse_options() */ case 'b': bold = 1; break; case 'l': @@ -414,11 +448,11 @@ int dump_utf8_char(void) { /* replacement character � is U+FFFD */ printable = "�"; } else if(special) { - fg = SPECIAL; + fg = special_color; bg = 0; printable = get_special(bytes[0]); } else if(cont_count == 2 && is_bom(bytes)) { - fg = SPECIAL; + fg = special_color; bg = 0; printable = "B"; } else { @@ -61,7 +61,6 @@ by itself. and space characters, and the 4th (optional) is for invalid UTF-8 sequences. Default: **2351**. This option also disables a prior **-m** option. - NOT IMPLEMENTED YET. -h, --help Print built-in usage message and exit. |