aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-16 16:36:12 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-16 16:36:12 -0500
commitd0ca5c32cd0b3890725df7dd75a807217b8e1810 (patch)
tree595b7ab49ff18d4e954074ab69ce2950ef7a8d29
parentb952a8a68e0f5dc76b927d1d995cdc10fb4166a0 (diff)
downloaduxd-d0ca5c32cd0b3890725df7dd75a807217b8e1810.tar.gz
add -1 option, error checking for parse_number()
-rw-r--r--mkusage.pl2
-rw-r--r--usage.c1
-rw-r--r--uxd.17
-rw-r--r--uxd.c34
-rw-r--r--uxd.rst5
5 files changed, 39 insertions, 10 deletions
diff --git a/mkusage.pl b/mkusage.pl
index f8fe485..0506d8c 100644
--- a/mkusage.pl
+++ b/mkusage.pl
@@ -4,7 +4,7 @@ print "char *usage_opts[] = {\n";
while(<>) {
chomp;
- if(/^-[a-zA-Z]/) {
+ if(/^-[a-zA-Z\d]/) {
$opt = $_;
next;
}
diff --git a/usage.c b/usage.c
index 6664916..d3579bd 100644
--- a/usage.c
+++ b/usage.c
@@ -1,4 +1,5 @@
char *usage_opts[] = {
+ " -1: don't alternate colors for normal characters.",
" -b: bold color output.",
" -c nnnn: colors (2 to 4 digits, 0 to 7).",
" -h, --help: print this help message.",
diff --git a/uxd.1 b/uxd.1
index 7a1d583..d6868f3 100644
--- a/uxd.1
+++ b/uxd.1
@@ -63,6 +63,13 @@ by itself.
.
.INDENT 0.0
.TP
+.B \-1
+Don\(aqt alternate colors for normal characters.
+.UNINDENT
+.\" don't alternate colors for normal characters.
+.
+.INDENT 0.0
+.TP
.B \-b
Bold output. This may be more or less readable, depending on your
terminal and its color settings. Ignored if \fB\-m\fP given.
diff --git a/uxd.c b/uxd.c
index 3aea465..95a91bd 100644
--- a/uxd.c
+++ b/uxd.c
@@ -66,7 +66,7 @@ int bad_color = RED;
int special_color = PURPLE;
/* toggles between 0 and 1 for each normal character */
-int cur_normal_hilite = 1;
+int cur_normal_hilite = 0;
/* highlight types */
#define HL_NORMAL 0
@@ -110,6 +110,7 @@ char * const special_symbols[] = {
};
/* options */
+int alternate_colors = 1; /* -1 */
int print_info = 0; /* -i */
int bold = 0; /* -b */
int hilite_multi = 0; /* -r */
@@ -192,8 +193,18 @@ void parse_colors(char *arg) {
bad_color = arg[3] - '0';
}
-long parse_number(const char *s) {
- return strtol(s, NULL, 0); /* TODO: error checking */
+long parse_number(int opt, const char *s) {
+ char *e;
+ long result;
+
+ result = strtol(s, &e, 0);
+
+ if(*e) {
+ fprintf(stderr, "%s: invalid number for -%c option.\n", self, opt);
+ exit(1);
+ }
+
+ return result;
}
void parse_args(int argc, char **argv) {
@@ -206,8 +217,10 @@ void parse_args(int argc, char **argv) {
version();
}
- while((opt = my_getopt(argc, argv, "ic:nbl:rmo:S:s:uhv")) != -1) {
+ while((opt = my_getopt(argc, argv, "1ic:nbl:rmo:S:s:uhv")) != -1) {
switch(opt) {
+ case '1':
+ alternate_colors = 0; break;
case 'i':
print_info = 1; break;
case 'c':
@@ -217,18 +230,18 @@ void parse_args(int argc, char **argv) {
case 'b':
bold = 1; break;
case 'l':
- limit = parse_number(optarg); break;
+ limit = parse_number(opt, optarg); break;
case 'r':
hilite_multi = 1; break;
case 'm':
mono = 1; break;
case 'o':
- display_offset = parse_number(optarg); break;
+ display_offset = parse_number(opt, optarg); break;
case 'S':
seek_offset_zero = 1;
/* fall thru */
case 's':
- seekpos = parse_number(optarg);
+ seekpos = parse_number(opt, optarg);
break;
case 'u':
hex_byte_fmt = "%02X"; hex_word_fmt = "%04X: "; break;
@@ -330,7 +343,8 @@ void print_line(void) {
}
void next_normal_hilite() {
- cur_normal_hilite = !cur_normal_hilite;
+ if(alternate_colors)
+ cur_normal_hilite = !cur_normal_hilite;
}
void append_color(char *buf, int hl_type) {
@@ -557,7 +571,6 @@ int dump_utf8_char(void) {
} else {
hl_type = HL_NORMAL;
printable = (char *)bytes;
- next_normal_hilite();
}
/* human-readable (right) column: */
@@ -572,6 +585,9 @@ int dump_utf8_char(void) {
append_left(bytes[i], (i != cont_count), hl_type);
}
+ if(hl_type == HL_NORMAL || hl_type == HL_NORM_INV)
+ next_normal_hilite();
+
return 1;
}
diff --git a/uxd.rst b/uxd.rst
index 2f4503a..a17eb1c 100644
--- a/uxd.rst
+++ b/uxd.rst
@@ -52,6 +52,11 @@ by itself.
.. the comments are turned into the --help message by mkusage.pl.
+-1
+ Don't alternate colors for normal characters.
+
+.. don't alternate colors for normal characters.
+
-b
Bold output. This may be more or less readable, depending on your
terminal and its color settings. Ignored if **-m** given.