diff options
author | B. Watson <urchlay@slackware.uk> | 2024-12-23 14:50:24 -0500 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-12-23 14:50:24 -0500 |
commit | 734994ddaf7522f9d763cacc0f7cde63b9c7188a (patch) | |
tree | c2a8f3b5dc57d58c7a2765fdc9ac16606b6d7629 /uxd.c | |
parent | e7d59f1e6ef99573b7432dbbeab25da6d7289c4b (diff) | |
download | uxd-734994ddaf7522f9d763cacc0f7cde63b9c7188a.tar.gz |
improve -c parsing and doc
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) { |