diff options
-rw-r--r-- | uxd.1 | 12 | ||||
-rw-r--r-- | uxd.c | 21 | ||||
-rw-r--r-- | uxd.rst | 14 |
3 files changed, 31 insertions, 16 deletions
@@ -74,6 +74,9 @@ NOT IMPLEMENTED YET. .B \-h\fP,\fB \-\-help Print built\-in usage message and exit. .TP +.BI \-l \ length +Stop dumping after \fIlength\fP bytes (note: bytes, not characters). +.TP .B \-m Monochrome mode. Uses underline, bold, reverse video instead of color. Use this if you have trouble distinguishing the colors, or if they @@ -89,10 +92,11 @@ decimal, hex (with \fI0x\fP prefix), or octal (with \fI0\fP prefix). Highlight multi\-byte sequences in reverse video, in the hex output. Ignored if \fB\-m\fP given. .TP -.BI \-s \ position -Seek in input before starting to dump. Positive \fIposition\fP means -seek from the start of the input. Negative \fIposition\fP only works -on files (not standard input); it means seek backward from EOF. +.BI \-s \ pos +Seek in input before starting to dump. \fIpos\fP is bytes, not +characters. Positive \fIpos\fP means seek from the start of the +input. Negative \fIpos\fP only works on files (not standard input); it +means seek backward from EOF. NOT IMPLEMENTED YET. .TP .B \-u @@ -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) @@ -63,6 +63,11 @@ over the environment. -h, --help Print built-in usage message and exit. +-l length + Stop dumping after *length* bytes (not characters). If the limit is + reached in the middle of a multibyte character, the entire character + will be dumped. + -m Monochrome mode. Uses underline, bold, reverse video instead of color. Use this if you have trouble distinguishing the colors, or if they @@ -78,10 +83,11 @@ over the environment. Highlight multi-byte sequences in reverse video, in the hex output. Ignored if **-m** given. --s position - Seek in input before starting to dump. Positive *position* means - seek from the start of the input. Negative *position* only works - on files (not standard input); it means seek backward from EOF. +-s pos + Seek in input before starting to dump. *pos* is bytes, not + characters. Positive *pos* means seek from the start of the + input. Negative *pos* only works on files (not standard input); it + means seek backward from EOF. NOT IMPLEMENTED YET. -u |