aboutsummaryrefslogtreecommitdiff
path: root/uxd.c
diff options
context:
space:
mode:
Diffstat (limited to 'uxd.c')
-rw-r--r--uxd.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/uxd.c b/uxd.c
index 3fc0bbb..aebc224 100644
--- a/uxd.c
+++ b/uxd.c
@@ -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 {