aboutsummaryrefslogtreecommitdiff
path: root/uxd.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-14 15:43:32 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-14 15:43:32 -0500
commitaa10bae90176d5025148225781d9176b6ee347d4 (patch)
treeb8f67e4568bcdd8aa9d185173df5fa95b09b4d2b /uxd.c
parent546a27e2f2b3f516886dfd6b2d6cf21b946c59ad (diff)
downloaduxd-aa10bae90176d5025148225781d9176b6ee347d4.tar.gz
add -l option, use longs for -s and -d.
Diffstat (limited to 'uxd.c')
-rw-r--r--uxd.c21
1 files changed, 13 insertions, 8 deletions
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)