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 | |
parent | e7d59f1e6ef99573b7432dbbeab25da6d7289c4b (diff) | |
download | uxd-734994ddaf7522f9d763cacc0f7cde63b9c7188a.tar.gz |
improve -c parsing and doc
-rw-r--r-- | usage.c | 2 | ||||
-rw-r--r-- | uxd.1 | 12 | ||||
-rw-r--r-- | uxd.c | 46 | ||||
-rw-r--r-- | uxd.rst | 12 |
4 files changed, 37 insertions, 35 deletions
@@ -2,7 +2,7 @@ char *usage_opts[] = { " --: no more options.", " -1: don't alternate colors.", " -b: bold color output.", - " -c nnnnn: colors (2 to 5 digits, 0 to 7).", + " -c nnnnn: colors (1 to 5 digits, 0 to 7).", " -d data: dump this data instead of a file.", " -h, --help: print this help message.", " -i: print number of bytes/chars/ascii/multibyte/bad sequences.", @@ -93,7 +93,7 @@ terminal and its color settings. Ignored if \fB\-m\fP given. .INDENT 0.0 .TP .BI \-c \ nnnnn -Set the colors to use. Must be 2 to 5 digits, from 0 to 7. These are +Set the colors to use. Must be 1 to 5 digits, from 0 to 7. These are standard ANSI colors: .INDENT 7.0 .TP @@ -125,15 +125,19 @@ white The first 2 digits are the alternating colors for normal characters, the 3rd and 4th (optional) are the alternating colors for non\-printable and space characters, and the 5th (optional) is for invalid UTF\-8 -sequences. Default: \fB23561\fP\&. This option also disables a prior \fB\-m\fP -option. +sequences. +.sp +Default colors are \fB23561\fP\&. If fewer than 5 colors are supplied, +the remaining colors keep their default values. .sp Note that the default color set doesn\(aqt include white or black: usually one of these is the terminal\(aqs background color. Also, it avoids blue, because blue text is hard to read on many terminals. +.sp +This option also disables a prior \fB\-m\fP option. .UNINDENT -.\" colors (2 to 5 digits, 0 to 7). +.\" colors (1 to 5 digits, 0 to 7). . .INDENT 0.0 .TP @@ -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) { @@ -76,7 +76,7 @@ as *K*, *M*, and *G* for power-of-10 based (e.g. *1K* is 1000 bytes). .. bold color output. -c nnnnn - Set the colors to use. Must be 2 to 5 digits, from 0 to 7. These are + Set the colors to use. Must be 1 to 5 digits, from 0 to 7. These are standard ANSI colors: 0 @@ -106,15 +106,19 @@ as *K*, *M*, and *G* for power-of-10 based (e.g. *1K* is 1000 bytes). The first 2 digits are the alternating colors for normal characters, the 3rd and 4th (optional) are the alternating colors for non-printable and space characters, and the 5th (optional) is for invalid UTF-8 - sequences. Default: **23561**. This option also disables a prior **-m** - option. + sequences. + + Default colors are **23561**. If fewer than 5 colors are supplied, + the remaining colors keep their default values. Note that the default color set doesn't include white or black: usually one of these is the terminal's background color. Also, it avoids blue, because blue text is hard to read on many terminals. -.. colors (2 to 5 digits, 0 to 7). + This option also disables a prior **-m** option. + +.. colors (1 to 5 digits, 0 to 7). -d data Dump this data, instead of reading from a file or stdin. If *data* |