Patch 8.2.3658

6 views
Skip to first unread message

Bram Moolenaar

unread,
Nov 24, 2021, 6:18:42 AM11/24/21
to vim...@googlegroups.com

Patch 8.2.3658
Problem: Duplicate code in xxd.
Solution: Merge duplicated code. Add more tests. (closes #9192)
Files: src/xxd/xxd.c, src/testdir/test_xxd.vim


*** ../vim-8.2.3657/src/xxd/xxd.c 2021-11-22 11:57:28.408409626 +0000
--- src/xxd/xxd.c 2021-11-24 11:15:55.577898865 +0000
***************
*** 809,841 ****
e = 0;
while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
{
if (p == 0)
{
addrlen = sprintf(l, decimal_offset ? "%08ld:" : "%08lx:",
((unsigned long)(n + seekoff + displayoff)));
for (c = addrlen; c < LLEN; l[c++] = ' ');
}
if (hextype == HEX_NORMAL || hextype == HEX_LITTLEENDIAN)
{
! 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 */
{
int i;
-
- c = (addrlen + 1 + (grplen * p) / octspergrp) - 1;
for (i = 7; i >= 0; i--)
! l[++c] = (e & (1 << i)) ? '1' : '0';
}
if (e)
nonzero++;
if (ebcdic)
e = (e < 64) ? '.' : etoa64[e-64];
/* When changing this update definition of LLEN above. */
! l[addrlen + 3 + (grplen * cols - 1)/octspergrp + p] =
#ifdef __MVS__
(e >= 64)
#else
--- 809,842 ----
e = 0;
while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
{
+ int x;
+
if (p == 0)
{
addrlen = sprintf(l, decimal_offset ? "%08ld:" : "%08lx:",
((unsigned long)(n + seekoff + displayoff)));
for (c = addrlen; c < LLEN; l[c++] = ' ');
}
+ x = hextype == HEX_LITTLEENDIAN ? p ^ (octspergrp-1) : p;
+ c = addrlen + 1 + (grplen * x) / octspergrp;
if (hextype == HEX_NORMAL || hextype == HEX_LITTLEENDIAN)
{
! l[c] = hexx[(e >> 4) & 0xf];
l[++c] = hexx[e & 0xf];
}
else /* hextype == HEX_BITS */
{
int i;
for (i = 7; i >= 0; i--)
! l[c++] = (e & (1 << i)) ? '1' : '0';
}
if (e)
nonzero++;
if (ebcdic)
e = (e < 64) ? '.' : etoa64[e-64];
/* When changing this update definition of LLEN above. */
! c = addrlen + 3 + (grplen * cols - 1)/octspergrp + p;
! l[c++] =
#ifdef __MVS__
(e >= 64)
#else
***************
*** 845,851 ****
n++;
if (++p == cols)
{
! l[c = (addrlen + 3 + (grplen * cols - 1)/octspergrp + p)] = '\n'; l[++c] = '\0';
xxdline(fpo, l, autoskip ? nonzero : 1);
nonzero = 0;
p = 0;
--- 846,853 ----
n++;
if (++p == cols)
{
! l[c] = '\n';
! l[++c] = '\0';
xxdline(fpo, l, autoskip ? nonzero : 1);
nonzero = 0;
p = 0;
***************
*** 855,861 ****
perror_exit(2);
if (p)
{
! l[c = (addrlen + 3 + (grplen * cols - 1)/octspergrp + p)] = '\n'; l[++c] = '\0';
xxdline(fpo, l, 1);
}
else if (autoskip)
--- 857,864 ----
perror_exit(2);
if (p)
{
! l[c] = '\n';
! l[++c] = '\0';
xxdline(fpo, l, 1);
}
else if (autoskip)
*** ../vim-8.2.3657/src/testdir/test_xxd.vim 2021-10-22 15:11:33.986608138 +0100
--- src/testdir/test_xxd.vim 2021-11-24 11:10:18.200502329 +0000
***************
*** 263,268 ****
--- 263,282 ----
endfor
endfunc

+ func Test_xxd_ignore_garbage()
+ new
+ exe 'r! printf "\n\r xxxx 0: 42 42" | ' . s:xxd_cmd . ' -r'
+ call assert_match('BB', join(getline(1, 3)))
+ bwipe!
+ endfunc
+
+ func Test_xxd_bit_dump()
+ new
+ exe 'r! printf "123456" | ' . s:xxd_cmd . ' -b1'
+ call assert_match('00000000: 00110001 00110010 00110011 00110100 00110101 00110110 123456', join(getline(1, 3)))
+ bwipe!
+ endfunc
+
func Test_xxd_version()
new
exe 'r! ' . s:xxd_cmd . ' -v'
*** ../vim-8.2.3657/src/version.c 2021-11-23 22:16:30.522773542 +0000
--- src/version.c 2021-11-24 11:16:25.861985230 +0000
***************
*** 759,760 ****
--- 759,762 ----
{ /* Add new patch number below this line */
+ /**/
+ 3658,
/**/

--
It is illegal to rob a bank and then shoot at the bank teller with a water
pistol.
[real standing law in Louisana, United States of America]

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages