aboutsummaryrefslogtreecommitdiff
path: root/uxd.c
diff options
context:
space:
mode:
Diffstat (limited to 'uxd.c')
-rw-r--r--uxd.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/uxd.c b/uxd.c
index 22a25f3..3aea465 100644
--- a/uxd.c
+++ b/uxd.c
@@ -60,30 +60,38 @@ extern int optind;
#define CYAN 6
#define WHITE 7 /* don't use (could be the background color) */
-#define SPECIAL PURPLE
+/* default colors */
+int normal_colors[] = { GREEN, YELLOW };
+int bad_color = RED;
+int special_color = PURPLE;
-#define BAD_FG BLACK
-#define BAD_BG bad_color
+/* toggles between 0 and 1 for each normal character */
+int cur_normal_hilite = 1;
+/* highlight types */
#define HL_NORMAL 0
#define HL_NORM_INV 1
#define HL_SPECIAL 2
#define HL_BAD 3
-int normal_colors[] = { GREEN, YELLOW };
-int cur_normal_hilite = 1;
-int bad_color = RED;
-int special_color = SPECIAL;
-
+/* name (read from argv[0]), for error/warning messages. */
const char *self;
+
+/* the input file, either stdin or a file we open for reading. */
FILE *input;
/* these buffers are bigger than they need to be really. */
+/* offset and hex bytes: */
char left_buf[4096];
+
+/* printable form: */
char right_buf[4096];
+/* dump_column ranges 0..(MAX_DUMP_COLS-1) */
#define MAX_DUMP_COLS 16
int dump_column = 0;
+
+/* where we're at in the input. */
int filepos = 0;
/* Unicode control character printable equivalents. For 0, use
@@ -93,20 +101,23 @@ int filepos = 0;
normal font sizes, but it's still better than using a dot for
everything like xxd does. */
char * const special_symbols[] = {
+ /* 0-0x0f: */
"∅", "␁", "␂", "␃", "␄", "␅", "␆", "␇", "␈", "⇥", "↵", "␋", "␌", "␍", "␎", "␏",
+ /* 0x10-0x1f: */
"␐", "␑", "␒", "␓", "␔", "␕", "␖", "␗", "␘", "␙", "␚", "⎋", "␜", "␝", "␞", "␟",
+ /* 0x20 (space): */
"␣",
};
/* options */
-int print_info = 0; /* -i */
-int bold = 0; /* -b */
+int print_info = 0; /* -i */
+int bold = 0; /* -b */
int hilite_multi = 0; /* -r */
-int mono = 0; /* -m */
+int mono = 0; /* -m */
long display_offset = 0; /* -o */
-long seekpos = 0; /* -s, -S */
+long seekpos = 0; /* -s, -S */
int seek_offset_zero = 0; /* -S */
-long limit; /* -l */
+long limit; /* -l */
const char *hex_byte_fmt = "%02x"; /* -u */
const char *hex_word_fmt = "%04x: "; /* " */
@@ -118,9 +129,18 @@ long bad_count = 0;
long char_count = 0;
void usage(void) {
- printf("uxd (Utf-8 heX Dump) v" VERSION " by B. Watson. WTFPL.\n");
- printf("Usage: %s [<file>]\n", self);
- printf(" With no <file>, or with -, read standard input.\n");
+ extern char *usage_opts[];
+ char **opt;
+
+ puts("uxd (Utf-8 heX Dump) v" VERSION " by B. Watson. WTFPL.");
+ printf("Usage: %s -[options] [<file>]\n", self);
+ puts(" With no <file>, or with -, read standard input.");
+ puts("Options:");
+
+ for(opt = usage_opts; *opt; opt++) {
+ puts(*opt);
+ }
+
exit(0);
}
@@ -332,7 +352,7 @@ void append_color(char *buf, int hl_type) {
break;
default:
case HL_BAD:
- fgcolor = BAD_FG;
+ fgcolor = 0;
bgcolor = bad_color;
break;
}