Mercurial > vim
changeset 20601:75ef263d09d6 v8.2.0854
patch 8.2.0854: xxd cannot show offset as a decimal number
Commit: https://github.com/vim/vim/commit/363d6148dfc2cc17fb0d286c7a36c305f56f5813
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat May 30 20:50:25 2020 +0200
patch 8.2.0854: xxd cannot show offset as a decimal number
Problem: Xxd cannot show offset as a decimal number.
Solution: Add the "-d" flag. (Aapo Rantalainen, closes https://github.com/vim/vim/issues/5616
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 30 May 2020 21:00:12 +0200 |
parents | e592e571e52a |
children | 67dccb63d65c |
files | src/testdir/test_xxd.vim src/version.c src/xxd/xxd.c |
diffstat | 3 files changed, 52 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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,
--- 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)