mirror of
https://github.com/vim/vim.git
synced 2025-07-25 10:54:51 -04:00
patch 8.2.3658: duplicate code in xxd
Problem: Duplicate code in xxd. Solution: Merge duplicated code. Add more tests. (closes #9192)
This commit is contained in:
parent
112bed0cbe
commit
48608b4a4b
@ -263,6 +263,20 @@ func Test_xxd_usage()
|
|||||||
endfor
|
endfor
|
||||||
endfunc
|
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()
|
func Test_xxd_version()
|
||||||
new
|
new
|
||||||
exe 'r! ' . s:xxd_cmd . ' -v'
|
exe 'r! ' . s:xxd_cmd . ' -v'
|
||||||
|
@ -757,6 +757,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3658,
|
||||||
/**/
|
/**/
|
||||||
3657,
|
3657,
|
||||||
/**/
|
/**/
|
||||||
|
@ -809,33 +809,34 @@ main(int argc, char *argv[])
|
|||||||
e = 0;
|
e = 0;
|
||||||
while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
|
while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
|
||||||
{
|
{
|
||||||
|
int x;
|
||||||
|
|
||||||
if (p == 0)
|
if (p == 0)
|
||||||
{
|
{
|
||||||
addrlen = sprintf(l, decimal_offset ? "%08ld:" : "%08lx:",
|
addrlen = sprintf(l, decimal_offset ? "%08ld:" : "%08lx:",
|
||||||
((unsigned long)(n + seekoff + displayoff)));
|
((unsigned long)(n + seekoff + displayoff)));
|
||||||
for (c = addrlen; c < LLEN; l[c++] = ' ');
|
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)
|
if (hextype == HEX_NORMAL || hextype == HEX_LITTLEENDIAN)
|
||||||
{
|
{
|
||||||
int x = hextype == HEX_NORMAL ? p : p ^ (octspergrp-1);
|
l[c] = hexx[(e >> 4) & 0xf];
|
||||||
l[c = (addrlen + 1 + (grplen * x) / octspergrp)]
|
|
||||||
= hexx[(e >> 4) & 0xf];
|
|
||||||
l[++c] = hexx[e & 0xf];
|
l[++c] = hexx[e & 0xf];
|
||||||
}
|
}
|
||||||
else /* hextype == HEX_BITS */
|
else /* hextype == HEX_BITS */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
c = (addrlen + 1 + (grplen * p) / octspergrp) - 1;
|
|
||||||
for (i = 7; i >= 0; i--)
|
for (i = 7; i >= 0; i--)
|
||||||
l[++c] = (e & (1 << i)) ? '1' : '0';
|
l[c++] = (e & (1 << i)) ? '1' : '0';
|
||||||
}
|
}
|
||||||
if (e)
|
if (e)
|
||||||
nonzero++;
|
nonzero++;
|
||||||
if (ebcdic)
|
if (ebcdic)
|
||||||
e = (e < 64) ? '.' : etoa64[e-64];
|
e = (e < 64) ? '.' : etoa64[e-64];
|
||||||
/* When changing this update definition of LLEN above. */
|
/* When changing this update definition of LLEN above. */
|
||||||
l[addrlen + 3 + (grplen * cols - 1)/octspergrp + p] =
|
c = addrlen + 3 + (grplen * cols - 1)/octspergrp + p;
|
||||||
|
l[c++] =
|
||||||
#ifdef __MVS__
|
#ifdef __MVS__
|
||||||
(e >= 64)
|
(e >= 64)
|
||||||
#else
|
#else
|
||||||
@ -845,7 +846,8 @@ main(int argc, char *argv[])
|
|||||||
n++;
|
n++;
|
||||||
if (++p == cols)
|
if (++p == cols)
|
||||||
{
|
{
|
||||||
l[c = (addrlen + 3 + (grplen * cols - 1)/octspergrp + p)] = '\n'; l[++c] = '\0';
|
l[c] = '\n';
|
||||||
|
l[++c] = '\0';
|
||||||
xxdline(fpo, l, autoskip ? nonzero : 1);
|
xxdline(fpo, l, autoskip ? nonzero : 1);
|
||||||
nonzero = 0;
|
nonzero = 0;
|
||||||
p = 0;
|
p = 0;
|
||||||
@ -855,7 +857,8 @@ main(int argc, char *argv[])
|
|||||||
perror_exit(2);
|
perror_exit(2);
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
l[c = (addrlen + 3 + (grplen * cols - 1)/octspergrp + p)] = '\n'; l[++c] = '\0';
|
l[c] = '\n';
|
||||||
|
l[++c] = '\0';
|
||||||
xxdline(fpo, l, 1);
|
xxdline(fpo, l, 1);
|
||||||
}
|
}
|
||||||
else if (autoskip)
|
else if (autoskip)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user