summaryrefslogtreecommitdiff
path: root/util-linux/hexdump_xxd.c
diff options
context:
space:
mode:
authorDenys Vlasenko2021-06-17 23:53:30 +0200
committerDenys Vlasenko2021-06-17 23:53:30 +0200
commit4d1616179745ee3883a726aaf13468e9c44dff9e (patch)
treebed5bc2f6afc768df587db7058b968f6e920b897 /util-linux/hexdump_xxd.c
parenta0f8076d19d721996b95b64eba95adae011215af (diff)
downloadbusybox-4d1616179745ee3883a726aaf13468e9c44dff9e.zip
busybox-4d1616179745ee3883a726aaf13468e9c44dff9e.tar.gz
xxd: implement -o DISPLAYOFFSET
function old new delta xxd_main 680 710 +30 xstrtoll - 30 +30 bb_dump_dump 1511 1531 +20 rewrite 941 951 +10 packed_usage 33629 33639 +10 .rodata 103250 103252 +2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 5/0 up/down: 102/0) Total: 102 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/hexdump_xxd.c')
-rw-r--r--util-linux/hexdump_xxd.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/util-linux/hexdump_xxd.c b/util-linux/hexdump_xxd.c
index 29bbc66..817250c 100644
--- a/util-linux/hexdump_xxd.c
+++ b/util-linux/hexdump_xxd.c
@@ -41,7 +41,7 @@
// -u use upper case hex letters.
//usage:#define xxd_trivial_usage
-//usage: "[-pr] [-g N] [-c N] [-n LEN] [-s OFS] [FILE]"
+//usage: "[-pr] [-g N] [-c N] [-n LEN] [-s OFS] [-o OFS] [FILE]"
//usage:#define xxd_full_usage "\n\n"
//usage: "Hex dump FILE (or stdin)\n"
//usage: "\n -g N Bytes per group"
@@ -50,6 +50,7 @@
// exactly the same help text lines in hexdump and xxd:
//usage: "\n -l LENGTH Show only first LENGTH bytes"
//usage: "\n -s OFFSET Skip OFFSET bytes"
+//usage: "\n -o OFFSET Add OFFSET to displayed offset"
//usage: "\n -r Reverse (with -p, assumes no offsets in input)"
#include "libbb.h"
@@ -62,6 +63,9 @@
#define OPT_a (1 << 2)
#define OPT_p (1 << 3)
#define OPT_r (1 << 4)
+#define OPT_g (1 << 5)
+#define OPT_c (1 << 6)
+#define OPT_o (1 << 7)
static void reverse(unsigned opt, unsigned cols, const char *filename)
{
@@ -127,15 +131,15 @@ int xxd_main(int argc UNUSED_PARAM, char **argv)
{
char buf[80];
dumper_t *dumper;
- char *opt_l, *opt_s;
+ char *opt_l, *opt_s, *opt_o;
unsigned bytes = 2;
unsigned cols = 0;
unsigned opt;
dumper = alloc_dumper();
- opt = getopt32(argv, "^" "l:s:aprg:+c:+" "\0" "?1" /* 1 argument max */,
- &opt_l, &opt_s, &bytes, &cols
+ opt = getopt32(argv, "^" "l:s:aprg:+c:+o:" "\0" "?1" /* 1 argument max */,
+ &opt_l, &opt_s, &bytes, &cols, &opt_o
);
argv += optind;
@@ -158,6 +162,11 @@ int xxd_main(int argc UNUSED_PARAM, char **argv)
//BUGGY for /proc/version (unseekable?)
}
+ if (opt & OPT_o) {
+ /* -o accepts negative numbers too */
+ dumper->xxd_displayoff = xstrtoll(opt_o, /*base:*/ 0);
+ }
+
if (opt & OPT_p) {
if (cols == 0)
cols = 30;
@@ -206,7 +215,7 @@ int xxd_main(int argc UNUSED_PARAM, char **argv)
bb_dump_add(dumper, buf);
} else {
bb_dump_add(dumper, "\"\n\"");
- dumper->eofstring = "\n";
+ dumper->xxd_eofstring = "\n";
}
return bb_dump_dump(dumper, argv);