aboutsummaryrefslogtreecommitdiff
path: root/uxd.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-18 04:29:16 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-18 04:29:16 -0500
commit88cad591cdf0668a69632650ea7ef9ca9ee530a1 (patch)
tree6f6c86b139ab427185780b75d24a60456adacbf2 /uxd.c
parentbd9833fb3a325d367c1b6c4c811fc5080fbcbbf5 (diff)
downloaduxd-88cad591cdf0668a69632650ea7ef9ca9ee530a1.tar.gz
move more magic constants to #defines
Diffstat (limited to 'uxd.c')
-rw-r--r--uxd.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/uxd.c b/uxd.c
index 21bcfba..01b4f92 100644
--- a/uxd.c
+++ b/uxd.c
@@ -63,14 +63,6 @@ extern int optind;
#define CYAN 6
#define WHITE 7 /* don't use (could be the background color) */
-/* default colors */
-int normal_colors[] = { GREEN, YELLOW };
-int bad_color = RED;
-int special_color = PURPLE;
-
-/* toggles between 0 and 1 for each normal character */
-int cur_normal_hilite = 0;
-
/* highlight types. HL_NORM_INV is only used for the hex bytes, not
the human-readable right column. */
#define HL_NORMAL 0
@@ -89,12 +81,26 @@ int cur_normal_hilite = 0;
#define PRINT_BAD "�"
#define PRINT_BOM "B"
+/* sprintf() formats for hex data */
+#define LC_BYTE_FMT "%02x"
+#define LC_ADDR_FMT "%04x: "
+#define UC_BYTE_FMT "%02X"
+#define UC_ADDR_FMT "%04X: "
+
/* 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;
+/* default colors */
+int normal_colors[] = { GREEN, YELLOW };
+int bad_color = RED;
+int special_color = PURPLE;
+
+/* toggles between 0 and 1 for each normal character */
+int cur_normal_hilite = 0;
+
/* these buffers are bigger than they need to be really. */
/* offset and hex bytes: */
char left_buf[4096];
@@ -134,8 +140,8 @@ long display_offset = 0; /* -o */
long seekpos = 0; /* -s, -S */
int seek_offset_zero = 0; /* -S */
long limit; /* -l */
-const char *hex_byte_fmt = "%02x"; /* -u */
-const char *hex_word_fmt = "%04x: "; /* " */
+const char *hex_byte_fmt = LC_BYTE_FMT; /* -u */
+const char *hex_addr_fmt = LC_ADDR_FMT; /* " */
char *dump_data_arg = NULL; /* -d */
long dump_data_idx = 0; /* -d */
@@ -291,7 +297,7 @@ void parse_args(int argc, char **argv) {
seekpos = parse_number(opt, optarg);
break;
case 'u':
- hex_byte_fmt = "%02X"; hex_word_fmt = "%04X: "; break;
+ hex_byte_fmt = UC_BYTE_FMT; hex_addr_fmt = UC_ADDR_FMT; break;
case 'h':
usage(); break;
case 'v':
@@ -481,7 +487,7 @@ void append_left(unsigned char byte, int dash, int hl_type) {
char tmpbuf[100];
if(!dump_column)
- sprintf(left_buf, hex_word_fmt, filepos + display_offset);
+ sprintf(left_buf, hex_addr_fmt, filepos + display_offset);
append_hilite(left_buf, hl_type);
sprintf(tmpbuf, hex_byte_fmt, byte);