summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/testdir/test_xxd.vim39
-rw-r--r--src/version.c2
-rw-r--r--src/xxd/xxd.c14
3 files changed, 52 insertions, 3 deletions
diff --git a/src/testdir/test_xxd.vim b/src/testdir/test_xxd.vim
index 93cfedb47..51ee76077 100644
--- a/src/testdir/test_xxd.vim
+++ b/src/testdir/test_xxd.vim
@@ -165,6 +165,45 @@ func Test_xxd()
call delete('Xinput')
call delete('XXDfile')
+ " Test 13: simple, decimal offset
+ call PrepareBuffer(range(1,30))
+ set ff=unix
+ w! XXDfile
+ let s:test += 1
+ exe '%!' . s:xxd_cmd . ' -d %'
+ let expected = [
+ \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
+ \ '00000016: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
+ \ '00000032: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
+ \ '00000048: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
+ \ '00000064: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
+ \ '00000080: 0a .']
+ call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
+
+ " Test 14: grouping with -d
+ let s:test += 1
+ let expected = [
+ \ '00000000: 310a320a 330a340a 350a360a 370a380a 1.2.3.4.5.6.7.8.',
+ \ '00000016: 390a3130 0a31310a 31320a31 330a3134 9.10.11.12.13.14',
+ \ '00000032: 0a31350a 31360a31 370a3138 0a31390a .15.16.17.18.19.',
+ \ '00000048: 32300a32 310a3232 0a32330a 32340a32 20.21.22.23.24.2',
+ \ '00000064: 350a3236 0a32370a 32380a32 390a3330 5.26.27.28.29.30',
+ \ '00000080: 0a .']
+ for arg in ['-g 4', '-group 4', '-g4']
+ exe '%!' . s:xxd_cmd . ' ' . arg . ' -d %'
+ call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
+ endfor
+
+ " Test 15: cols with decimal offset: -c 21 -d
+ let s:test += 1
+ let expected = [
+ \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 390a 3130 0a 1.2.3.4.5.6.7.8.9.10.',
+ \ '00000021: 3131 0a31 320a 3133 0a31 340a 3135 0a31 360a 3137 0a 11.12.13.14.15.16.17.',
+ \ '00000042: 3138 0a31 390a 3230 0a32 310a 3232 0a32 330a 3234 0a 18.19.20.21.22.23.24.',
+ \ '00000063: 3235 0a32 360a 3237 0a32 380a 3239 0a33 300a 25.26.27.28.29.30.']
+ exe '%!' . s:xxd_cmd . ' -c 21 -d %'
+ call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
+
" TODO:
" -o -offset
diff --git a/src/version.c b/src/version.c
index 3bd012bcc..6fe96a374 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 854,
+/**/
853,
/**/
852,
diff --git a/src/xxd/xxd.c b/src/xxd/xxd.c
index 20a7ad748..20f06ab7c 100644
--- a/src/xxd/xxd.c
+++ b/src/xxd/xxd.c
@@ -53,6 +53,7 @@
* 2011 April Formatting by Bram Moolenaar
* 08.06.2013 Little-endian hexdump (-e) and offset (-o) by Vadim Vygonets.
* 11.01.2019 Add full 64/32 bit range to -o and output by Christer Jensen.
+ * 04.02.2020 Add -d for decimal offsets by Aapo Rantalainen
*
* (c) 1990-1998 by Juergen Weigert (jnweiger@informatik.uni-erlangen.de)
*
@@ -235,6 +236,7 @@ exit_with_usage(void)
fprintf(stderr, " -ps output in postscript plain hexdump style.\n");
fprintf(stderr, " -r reverse operation: convert (or patch) hexdump into binary.\n");
fprintf(stderr, " -r -s off revert with <off> added to file positions found in hexdump.\n");
+ fprintf(stderr, " -d show offset in decimal instead of hex.\n");
fprintf(stderr, " -s %sseek start at <seek> bytes abs. %sinfile offset.\n",
#ifdef TRY_SEEK
"[+][-]", "(or +: rel.) ");
@@ -458,7 +460,8 @@ main(int argc, char *argv[])
{
FILE *fp, *fpo;
int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
- int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL, capitalize = 0;
+ int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL;
+ int capitalize = 0, decimal_offset = 0;
int ebcdic = 0;
int octspergrp = -1; /* number of octets grouped in output */
int grplen; /* total chars per octet group */
@@ -497,6 +500,7 @@ main(int argc, char *argv[])
else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT;
else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE;
else if (!STRNCMP(pp, "-C", 2)) capitalize = 1;
+ else if (!STRNCMP(pp, "-d", 2)) decimal_offset = 1;
else if (!STRNCMP(pp, "-r", 2)) revert++;
else if (!STRNCMP(pp, "-E", 2)) ebcdic++;
else if (!STRNCMP(pp, "-v", 2))
@@ -820,8 +824,12 @@ main(int argc, char *argv[])
{
if (p == 0)
{
- addrlen = sprintf(l, "%08lx:",
- ((unsigned long)(n + seekoff + displayoff)));
+ if (decimal_offset)
+ addrlen = sprintf(l, "%08ld:",
+ ((unsigned long)(n + seekoff + displayoff)));
+ else
+ addrlen = sprintf(l, "%08lx:",
+ ((unsigned long)(n + seekoff + displayoff)));
for (c = addrlen; c < LLEN; l[c++] = ' ');
}
if (hextype == HEX_NORMAL)