diff options
-rw-r--r-- | tests/xxd.test | 3 | ||||
-rw-r--r-- | toys/other/xxd.c | 8 |
2 files changed, 7 insertions, 4 deletions
diff --git a/tests/xxd.test b/tests/xxd.test index 97634e86..48ed319d 100644 --- a/tests/xxd.test +++ b/tests/xxd.test @@ -15,7 +15,6 @@ testing "file1" "xxd file1" \ testing "file1 -l" "xxd -l 2 file1" \ "00000000: 7468 th\n" \ "" "" -testing "file2" "xxd file2" "" "" "" testing "-" "xxd -" \ "00000000: 6865 6c6c 6f hello\n" "" "hello" testing "xxd" "xxd" \ @@ -27,6 +26,8 @@ testing "-c 8 -g 3 file1" "xxd -c 8 -g 3 file1" \ testing "-i" "cat file1 | xxd -i -" " 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x6d, 0x65,\n 0x20, 0x74, 0x65, 0x78, 0x74, 0x0a\n" "" "" +testing "-o 0x8000" "xxd -o 0x8000 file1" "00008000: 7468 6973 2069 7320 736f 6d65 2074 6578 this is some tex\n00008010: 740a t.\n" "" "" + testing "-p" "xxd -p file1" "7468697320697320736f6d6520746578740a\n" "" "" testing "-s" "xxd -s 13 file1" "0000000d: 7465 7874 0a text.\n" "" "" diff --git a/toys/other/xxd.c b/toys/other/xxd.c index edc5772c..6203d7aa 100644 --- a/toys/other/xxd.c +++ b/toys/other/xxd.c @@ -10,13 +10,13 @@ * xxd -p "plain" output: * "4c696e75782076657273696f6e20342e392e302d342d616d643634202864" -USE_XXD(NEWTOY(xxd, ">1c#l#g#<1=2iprs#[!rs]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_XXD(NEWTOY(xxd, ">1c#l#o#g#<1=2iprs#[!rs]", TOYFLAG_USR|TOYFLAG_BIN)) config XXD bool "xxd" default y help - usage: xxd [-c n] [-g n] [-i] [-l n] [-p] [-r] [-s n] [file] + usage: xxd [-c n] [-g n] [-i] [-l n] [-o n] [-p] [-r] [-s n] [file] Hexdump a file to stdout. If no file is listed, copy from stdin. Filename "-" is a synonym for stdin. @@ -25,6 +25,7 @@ config XXD -g n Group bytes by adding a ' ' every n bytes (default 2) -i Include file output format (comma-separated hex byte literals) -l n Limit of n bytes before stopping (default is no limit) + -o n Add n to display offset -p Plain hexdump (30 bytes/line, no grouping) -r Reverse operation: turn a hexdump into a binary file -s n Skip to offset n @@ -36,6 +37,7 @@ config XXD GLOBALS( long s; long g; + long o; long l; long c; ) @@ -54,7 +56,7 @@ static void do_xxd(int fd, char *name) while (0<(len = readall(fd, toybuf, (limit && limit-pos<TT.c)?limit-pos:TT.c))) { - if (!(toys.optflags&FLAG_p)) printf("%08llx: ", pos); + if (!(toys.optflags&FLAG_p)) printf("%08llx: ", TT.o + pos); pos += len; space = 2*TT.c+TT.c/TT.g+1; |