runtime/doc/xxd.1 | 12 +++++++++++- src/xxd/xxd.c | 29 ++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-)
# HG changeset patch # User Vadim Vygonets <[email protected]> # Date 1384858885 -3600 # Node ID e5b9ff009e25d661ad1f71bba70c3f7ac71d2e80 # Parent 58bcf8fa172f6bbb254a90d1b9cec91d0a040157 xxd: Add -e: little endian hexdump diff -r 58bcf8fa172f -r e5b9ff009e25 runtime/doc/xxd.1 --- a/runtime/doc/xxd.1 Sun Nov 17 20:32:54 2013 +0100 +++ b/runtime/doc/xxd.1 Tue Nov 19 12:01:25 2013 +0100 @@ -76,6 +76,16 @@ This does not change the hexadecimal representation. The option is meaningless in combinations with \-r, \-p or \-i. .TP +.IR \-e +Switch to little-endian hexdump. +This option treats byte groups as words in little-endian byte order. +The default grouping of 4 bytes may be changed using +.RI "" \-g . +This option only applies to hexdump, leaving the ASCII (or EBCDIC) +representation unchanged. +The command line switches +\-r, \-p, \-i do not work with this mode. +.TP .IR "\-g bytes " | " \-groupsize bytes" separate the output of every .RI < bytes > @@ -84,7 +94,7 @@ .I \-g 0 to suppress grouping. .RI < Bytes "> defaults to " 2 -in normal mode and \fI1\fP in bits mode. +in normal mode, \fI4\fP in little-endian mode and \fI1\fP in bits mode. Grouping does not apply to postscript or include style. .TP .IR \-h " | " \-help diff -r 58bcf8fa172f -r e5b9ff009e25 src/xxd/xxd.c --- a/src/xxd/xxd.c Sun Nov 17 20:32:54 2013 +0100 +++ b/src/xxd/xxd.c Tue Nov 19 12:01:25 2013 +0100 @@ -51,6 +51,7 @@ * 16.05.00 Improved MMS file and merge for VMS by Zoltan Arpadffy * 2011 March Better error handling by Florian Zumbiehl. * 2011 April Formatting by Bram Moolenaar + * 08.06.2013 Little-endian hexdump (-e) by Vadim Vygonets. * * (c) 1990-1998 by Juergen Weigert ([email protected]) * @@ -225,6 +226,7 @@ #define HEX_POSTSCRIPT 1 #define HEX_CINCLUDE 2 #define HEX_BITS 3 /* not hex a dump, but bits: 01111001 */ +#define HEX_LITTLEENDIAN 4 static char *pname; @@ -238,7 +240,8 @@ fprintf(stderr, " -b binary digit dump (incompatible with -ps,-i,-r). Default hex.\n"); fprintf(stderr, " -c cols format <cols> octets per line. Default 16 (-i: 12, -ps: 30).\n"); fprintf(stderr, " -E show characters in EBCDIC. Default ASCII.\n"); - fprintf(stderr, " -g number of octets per group in normal output. Default 2.\n"); + fprintf(stderr, " -e little-endian dump (incompatible with -ps,-i,-r).\n"); + fprintf(stderr, " -g number of octets per group in normal output. Default 2 (-e: 4).\n"); fprintf(stderr, " -h print this summary.\n"); fprintf(stderr, " -i output in C include file style.\n"); fprintf(stderr, " -l len stop after <len> octets.\n"); @@ -503,6 +506,7 @@ pp = argv[1] + (!STRNCMP(argv[1], "--", 2) && argv[1][2]); if (!STRNCMP(pp, "-a", 2)) autoskip = 1 - autoskip; else if (!STRNCMP(pp, "-b", 2)) hextype = HEX_BITS; + else if (!STRNCMP(pp, "-e", 2)) hextype = HEX_LITTLEENDIAN; else if (!STRNCMP(pp, "-u", 2)) hexx = hexxa + 16; else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT; else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE; @@ -603,6 +607,7 @@ case HEX_CINCLUDE: cols = 12; break; case HEX_BITS: cols = 6; break; case HEX_NORMAL: + case HEX_LITTLEENDIAN: default: cols = 16; break; } @@ -611,20 +616,28 @@ { case HEX_BITS: octspergrp = 1; break; case HEX_NORMAL: octspergrp = 2; break; + case HEX_LITTLEENDIAN: octspergrp = 4; break; case HEX_POSTSCRIPT: case HEX_CINCLUDE: default: octspergrp = 0; break; } - if (cols < 1 || ((hextype == HEX_NORMAL || hextype == HEX_BITS) + if (cols < 1 || ((hextype == HEX_NORMAL || hextype == HEX_BITS || hextype == HEX_LITTLEENDIAN) && (cols > COLS))) { fprintf(stderr, "%s: invalid number of columns (max. %d).\n", pname, COLS); exit(1); } - if (octspergrp < 1) + if (octspergrp < 1 || octspergrp > cols) octspergrp = cols; + else if (hextype == HEX_LITTLEENDIAN && (octspergrp & (octspergrp-1))) + { + fprintf(stderr, + "%s: number of octets per group must be a power of 2 with -e.\n", + pname); + exit(1); + } if (argc > 3) exit_with_usage(); @@ -781,9 +794,9 @@ return 0; } - /* hextype: HEX_NORMAL or HEX_BITS */ + /* hextype: HEX_NORMAL or HEX_BITS or HEX_LITTLEENDIAN */ - if (hextype == HEX_NORMAL) + if (hextype != HEX_BITS) grplen = octspergrp + octspergrp + 1; /* chars per octet group */ else /* hextype == HEX_BITS */ grplen = 8 * octspergrp + 1; @@ -801,6 +814,12 @@ l[c = (9 + (grplen * p) / octspergrp)] = hexx[(e >> 4) & 0xf]; l[++c] = hexx[ e & 0xf]; } + else if (hextype == HEX_LITTLEENDIAN) + { + int x = p ^ (octspergrp-1); + l[c = (9 + (grplen * x) / octspergrp)] = hexx[(e >> 4) & 0xf]; + l[++c] = hexx[ e & 0xf]; + } else /* hextype == HEX_BITS */ { int i; -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
