diff options
author | DungSaga <dungsaga@users.noreply.github.com> | 2021-11-22 11:57:31 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-11-22 11:57:31 +0000 |
commit | 581f41adb3ba1dc95bf4fc7c434427e1203be5e8 (patch) | |
tree | 1e35545884574d534257dee9b0afa4da0e542373 /src/xxd/xxd.c | |
parent | 88a4205f1cfbdc328e987ab00521fc8a22447fc3 (diff) | |
download | vim-git-581f41adb3ba1dc95bf4fc7c434427e1203be5e8.tar.gz |
patch 8.2.3641: xxd code has duplicate expressionsv8.2.3641
Problem: Xxd code has duplicate expressions.
Solution: Refactor to avoid duplication. (closes #9185)
Diffstat (limited to 'src/xxd/xxd.c')
-rw-r--r-- | src/xxd/xxd.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/xxd/xxd.c b/src/xxd/xxd.c index e2f893b7d..cef3c6127 100644 --- a/src/xxd/xxd.c +++ b/src/xxd/xxd.c @@ -811,24 +811,16 @@ main(int argc, char *argv[]) { if (p == 0) { - if (decimal_offset) - addrlen = sprintf(l, "%08ld:", - ((unsigned long)(n + seekoff + displayoff))); - else - addrlen = sprintf(l, "%08lx:", + addrlen = sprintf(l, decimal_offset ? "%08ld:" : "%08lx:", ((unsigned long)(n + seekoff + displayoff))); for (c = addrlen; c < LLEN; l[c++] = ' '); } - if (hextype == HEX_NORMAL) - { - l[c = (addrlen + 1 + (grplen * p) / octspergrp)] = hexx[(e >> 4) & 0xf]; - l[++c] = hexx[ e & 0xf]; - } - else if (hextype == HEX_LITTLEENDIAN) + if (hextype == HEX_NORMAL || hextype == HEX_LITTLEENDIAN) { - int x = p ^ (octspergrp-1); - l[c = (addrlen + 1 + (grplen * x) / octspergrp)] = hexx[(e >> 4) & 0xf]; - l[++c] = hexx[ e & 0xf]; + int x = hextype == HEX_NORMAL ? p : p ^ (octspergrp-1); + l[c = (addrlen + 1 + (grplen * x) / octspergrp)] + = hexx[(e >> 4) & 0xf]; + l[++c] = hexx[e & 0xf]; } else /* hextype == HEX_BITS */ { |