Mercurial > vim
comparison src/xxd/xxd.c @ 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 | 2ef19eed524a |
children | 5690cf66ee07 |
comparison
equal
deleted
inserted
replaced
20600:e592e571e52a | 20601:75ef263d09d6 |
---|---|
51 * 16.05.00 Improved MMS file and merge for VMS by Zoltan Arpadffy | 51 * 16.05.00 Improved MMS file and merge for VMS by Zoltan Arpadffy |
52 * 2011 March Better error handling by Florian Zumbiehl. | 52 * 2011 March Better error handling by Florian Zumbiehl. |
53 * 2011 April Formatting by Bram Moolenaar | 53 * 2011 April Formatting by Bram Moolenaar |
54 * 08.06.2013 Little-endian hexdump (-e) and offset (-o) by Vadim Vygonets. | 54 * 08.06.2013 Little-endian hexdump (-e) and offset (-o) by Vadim Vygonets. |
55 * 11.01.2019 Add full 64/32 bit range to -o and output by Christer Jensen. | 55 * 11.01.2019 Add full 64/32 bit range to -o and output by Christer Jensen. |
56 * 04.02.2020 Add -d for decimal offsets by Aapo Rantalainen | |
56 * | 57 * |
57 * (c) 1990-1998 by Juergen Weigert (jnweiger@informatik.uni-erlangen.de) | 58 * (c) 1990-1998 by Juergen Weigert (jnweiger@informatik.uni-erlangen.de) |
58 * | 59 * |
59 * I hereby grant permission to distribute and use xxd | 60 * I hereby grant permission to distribute and use xxd |
60 * under X11-MIT or GPL-2.0 (at the user's choice). | 61 * under X11-MIT or GPL-2.0 (at the user's choice). |
233 fprintf(stderr, " -l len stop after <len> octets.\n"); | 234 fprintf(stderr, " -l len stop after <len> octets.\n"); |
234 fprintf(stderr, " -o off add <off> to the displayed file position.\n"); | 235 fprintf(stderr, " -o off add <off> to the displayed file position.\n"); |
235 fprintf(stderr, " -ps output in postscript plain hexdump style.\n"); | 236 fprintf(stderr, " -ps output in postscript plain hexdump style.\n"); |
236 fprintf(stderr, " -r reverse operation: convert (or patch) hexdump into binary.\n"); | 237 fprintf(stderr, " -r reverse operation: convert (or patch) hexdump into binary.\n"); |
237 fprintf(stderr, " -r -s off revert with <off> added to file positions found in hexdump.\n"); | 238 fprintf(stderr, " -r -s off revert with <off> added to file positions found in hexdump.\n"); |
239 fprintf(stderr, " -d show offset in decimal instead of hex.\n"); | |
238 fprintf(stderr, " -s %sseek start at <seek> bytes abs. %sinfile offset.\n", | 240 fprintf(stderr, " -s %sseek start at <seek> bytes abs. %sinfile offset.\n", |
239 #ifdef TRY_SEEK | 241 #ifdef TRY_SEEK |
240 "[+][-]", "(or +: rel.) "); | 242 "[+][-]", "(or +: rel.) "); |
241 #else | 243 #else |
242 "", ""); | 244 "", ""); |
456 int | 458 int |
457 main(int argc, char *argv[]) | 459 main(int argc, char *argv[]) |
458 { | 460 { |
459 FILE *fp, *fpo; | 461 FILE *fp, *fpo; |
460 int c, e, p = 0, relseek = 1, negseek = 0, revert = 0; | 462 int c, e, p = 0, relseek = 1, negseek = 0, revert = 0; |
461 int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL, capitalize = 0; | 463 int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL; |
464 int capitalize = 0, decimal_offset = 0; | |
462 int ebcdic = 0; | 465 int ebcdic = 0; |
463 int octspergrp = -1; /* number of octets grouped in output */ | 466 int octspergrp = -1; /* number of octets grouped in output */ |
464 int grplen; /* total chars per octet group */ | 467 int grplen; /* total chars per octet group */ |
465 long length = -1, n = 0, seekoff = 0; | 468 long length = -1, n = 0, seekoff = 0; |
466 unsigned long displayoff = 0; | 469 unsigned long displayoff = 0; |
495 else if (!STRNCMP(pp, "-e", 2)) hextype = HEX_LITTLEENDIAN; | 498 else if (!STRNCMP(pp, "-e", 2)) hextype = HEX_LITTLEENDIAN; |
496 else if (!STRNCMP(pp, "-u", 2)) hexx = hexxa + 16; | 499 else if (!STRNCMP(pp, "-u", 2)) hexx = hexxa + 16; |
497 else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT; | 500 else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT; |
498 else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE; | 501 else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE; |
499 else if (!STRNCMP(pp, "-C", 2)) capitalize = 1; | 502 else if (!STRNCMP(pp, "-C", 2)) capitalize = 1; |
503 else if (!STRNCMP(pp, "-d", 2)) decimal_offset = 1; | |
500 else if (!STRNCMP(pp, "-r", 2)) revert++; | 504 else if (!STRNCMP(pp, "-r", 2)) revert++; |
501 else if (!STRNCMP(pp, "-E", 2)) ebcdic++; | 505 else if (!STRNCMP(pp, "-E", 2)) ebcdic++; |
502 else if (!STRNCMP(pp, "-v", 2)) | 506 else if (!STRNCMP(pp, "-v", 2)) |
503 { | 507 { |
504 fprintf(stderr, "%s%s\n", version, osver); | 508 fprintf(stderr, "%s%s\n", version, osver); |
818 e = 0; | 822 e = 0; |
819 while ((length < 0 || n < length) && (e = getc(fp)) != EOF) | 823 while ((length < 0 || n < length) && (e = getc(fp)) != EOF) |
820 { | 824 { |
821 if (p == 0) | 825 if (p == 0) |
822 { | 826 { |
823 addrlen = sprintf(l, "%08lx:", | 827 if (decimal_offset) |
824 ((unsigned long)(n + seekoff + displayoff))); | 828 addrlen = sprintf(l, "%08ld:", |
829 ((unsigned long)(n + seekoff + displayoff))); | |
830 else | |
831 addrlen = sprintf(l, "%08lx:", | |
832 ((unsigned long)(n + seekoff + displayoff))); | |
825 for (c = addrlen; c < LLEN; l[c++] = ' '); | 833 for (c = addrlen; c < LLEN; l[c++] = ' '); |
826 } | 834 } |
827 if (hextype == HEX_NORMAL) | 835 if (hextype == HEX_NORMAL) |
828 { | 836 { |
829 l[c = (addrlen + 1 + (grplen * p) / octspergrp)] = hexx[(e >> 4) & 0xf]; | 837 l[c = (addrlen + 1 + (grplen * p) / octspergrp)] = hexx[(e >> 4) & 0xf]; |