From aa10bae90176d5025148225781d9176b6ee347d4 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 14 Dec 2024 15:43:32 -0500 Subject: add -l option, use longs for -s and -d. --- uxd.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'uxd.c') diff --git a/uxd.c b/uxd.c index 612243a..2502463 100644 --- a/uxd.c +++ b/uxd.c @@ -82,8 +82,9 @@ int filepos = 0; /* options */ int hilite_multi = 0; /* -r */ int mono = 0; /* -m */ -int display_offset = 0; /* -o */ -int seekpos = 0; /* -s */ +long display_offset = 0; /* -o */ +long seekpos = 0; /* -s */ +long limit; /* -l */ const char *hex_byte_fmt = "%02x"; /* -u */ const char *hex_word_fmt = "%04x: "; /* " */ @@ -112,6 +113,10 @@ void open_input(const char *arg) { } } +long parse_number(const char *s) { + return strtol(s, NULL, 0); /* TODO: error checking */ +} + void parse_options(int argc, char **argv) { int opt; @@ -122,18 +127,18 @@ void parse_options(int argc, char **argv) { version(); } - while((opt = getopt(argc, argv, "rmo:s:uhv")) != -1) { + while((opt = getopt(argc, argv, "l:rmo:s:uhv")) != -1) { switch(opt) { + case 'l': + limit = parse_number(optarg); break; case 'r': hilite_multi = 1; break; case 'm': mono = 1; break; case 'o': - display_offset = strtol(optarg, NULL, 0); - break; + display_offset = parse_number(optarg); break; case 's': - seekpos = strtol(optarg, NULL, 0); - break; + seekpos = parse_number(optarg); break; case 'u': hex_byte_fmt = "%02X"; hex_word_fmt = "%04X: "; break; case 'h': @@ -382,7 +387,7 @@ int dump_utf8_char(void) { void dump_file(void) { while(dump_utf8_char()) - ; + if(limit && (filepos >= limit)) break; /* handle the last line, if the file size not divisible by 16. */ if(dump_column) -- cgit v1.2.3