diff options
Diffstat (limited to 'uxd.c')
-rw-r--r-- | uxd.c | 46 |
1 files changed, 20 insertions, 26 deletions
@@ -204,36 +204,30 @@ void color_error(void) { exit(1); } -void check_color(char c) { +int num_to_color(char c) { if(c < '0' || c > '7') color_error(); + return c - '0'; } 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_colors[0] = arg[2] - '0'; - - /* optional 4th color */ - if(!arg[3]) return; - check_color(arg[3]); - special_colors[1] = arg[3] - '0'; - - /* optional 5th color */ - if(!arg[4]) return; - check_color(arg[4]); - bad_color = arg[4] - '0'; - - if(arg[5]) color_error(); + static int *colors[] = { + &normal_colors[0], + &normal_colors[1], + &special_colors[0], + &special_colors[1], + &bad_color + }; + int i, c; + + i = strlen(arg); + if(i < 1 || i > 5) + color_error(); + + for(i = 0; i < 5; i++) { + c = arg[i]; + if(!c) break; + *colors[i] = num_to_color(c); + } } void number_err(int opt) { |