Patch 8.2.4088

5 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 14, 2022, 6:59:28 AM1/14/22
to vim...@googlegroups.com

Patch 8.2.4088
Problem: Xxd cannot output everything in one line.
Solution: Make zero columns mean infinite columns. (Erik Auerswald,
closes #9524)
Files: runtime/doc/xxd.1, runtime/doc/xxd.man, src/testdir/test_xxd.vim,
src/xxd/xxd.c


*** ../vim-8.2.4087/runtime/doc/xxd.1 2018-04-03 13:20:26.000000000 +0100
--- runtime/doc/xxd.1 2022-01-14 11:54:56.436413645 +0000
***************
*** 70,75 ****
--- 70,76 ----
Format
.RI < cols >
octets per line. Default 16 (\-i: 12, \-ps: 30, \-b: 6). Max 256.
+ No maxmimum for \-ps. With \-ps, 0 results in one long line of output.
.TP
.IR \-C " | " \-capitalize
Capitalize variable names in C include file style, when using \-i.
*** ../vim-8.2.4087/runtime/doc/xxd.man 2018-04-03 13:20:27.000000000 +0100
--- runtime/doc/xxd.man 2022-01-14 11:55:16.784386307 +0000
***************
*** 42,48 ****

-c cols | -cols cols
Format <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b:
! 6). Max 256.

-C | -capitalize
Capitalize variable names in C include file style, when using
--- 42,49 ----

-c cols | -cols cols
Format <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b:
! 6). Max 256. No maxmimum for -ps. With -ps, 0 results in one
! long line of output.

-C | -capitalize
Capitalize variable names in C include file style, when using
*** ../vim-8.2.4087/src/testdir/test_xxd.vim 2022-01-13 17:42:24.171310250 +0000
--- src/testdir/test_xxd.vim 2022-01-14 11:51:21.428681791 +0000
***************
*** 320,329 ****
endfunc

" -c0 selects the format specific default column value, as if no -c was given
func Test_xxd_c0_is_def_cols()
call writefile(["abcdefghijklmnopqrstuvwxyz0123456789"], 'Xxdin')
for cols in ['-c0', '-c 0', '-cols 0']
! for fmt in ['', '-b', '-e', '-i', '-p', ]
exe 'r! ' . s:xxd_cmd . ' ' . fmt ' Xxdin > Xxdout1'
exe 'r! ' . s:xxd_cmd . ' ' . cols . ' ' . fmt ' Xxdin > Xxdout2'
call assert_equalfile('Xxdout1', 'Xxdout2')
--- 320,330 ----
endfunc

" -c0 selects the format specific default column value, as if no -c was given
+ " except for -ps, where it disables extra newlines
func Test_xxd_c0_is_def_cols()
call writefile(["abcdefghijklmnopqrstuvwxyz0123456789"], 'Xxdin')
for cols in ['-c0', '-c 0', '-cols 0']
! for fmt in ['', '-b', '-e', '-i']
exe 'r! ' . s:xxd_cmd . ' ' . fmt ' Xxdin > Xxdout1'
exe 'r! ' . s:xxd_cmd . ' ' . cols . ' ' . fmt ' Xxdin > Xxdout2'
call assert_equalfile('Xxdout1', 'Xxdout2')
***************
*** 334,337 ****
--- 335,361 ----
call delete('Xxdout2')
endfunc

+ " all output in a single line for -c0 -ps
+ func Test_xxd_plain_one_line()
+ call writefile([
+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"],
+ \ 'Xxdin')
+ for cols in ['-c0', '-c 0', '-cols 0']
+ exe 'r! ' . s:xxd_cmd . ' -ps ' . cols ' Xxdin'
+ " output seems to start in line 2
+ let out = join(getline(2, '$'))
+ bwipe!
+ " newlines in xxd output result in spaces in the string variable out
+ call assert_notmatch(" ", out)
+ " xxd output must be non-empty and comprise only lower case hex digits
+ call assert_match("^[0-9a-f][0-9a-f]*$", out)
+ endfor
+ call delete('Xxdin')
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.4087/src/xxd/xxd.c 2021-12-31 17:33:43.031473720 +0000
--- src/xxd/xxd.c 2022-01-14 11:57:06.272234578 +0000
***************
*** 54,59 ****
--- 54,60 ----
* 08.06.2013 Little-endian hexdump (-e) and offset (-o) by Vadim Vygonets.
* 11.01.2019 Add full 64/32 bit range to -o and output by Christer Jensen.
* 04.02.2020 Add -d for decimal offsets by Aapo Rantalainen
+ * 14.01.2022 Disable extra newlines with -c0 -p by Erik Auerswald.
*
* (c) 1990-1998 by Juergen Weigert (jnwe...@gmail.com)
*
***************
*** 135,141 ****
extern long int strtol();
extern long int ftell();

! char version[] = "xxd 2021-10-22 by Juergen Weigert et al.";
#ifdef WIN32
char osver[] = " (Win32)";
#else
--- 136,142 ----
extern long int strtol();
extern long int ftell();

! char version[] = "xxd 2022-01-14 by Juergen Weigert et al.";
#ifdef WIN32
char osver[] = " (Win32)";
#else
***************
*** 487,493 ****
{
FILE *fp, *fpo;
int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
! int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL;
int capitalize = 0, decimal_offset = 0;
int ebcdic = 0;
int octspergrp = -1; /* number of octets grouped in output */
--- 488,494 ----
{
FILE *fp, *fpo;
int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
! int cols = 0, colsgiven = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL;
int capitalize = 0, decimal_offset = 0;
int ebcdic = 0;
int octspergrp = -1; /* number of octets grouped in output */
***************
*** 540,550 ****
if (pp[2] && !STRNCMP("apitalize", pp + 2, 9))
capitalize = 1;
else if (pp[2] && STRNCMP("ols", pp + 2, 3))
! cols = (int)strtol(pp + 2, NULL, 0);
else
{
if (!argv[2])
exit_with_usage();
cols = (int)strtol(argv[2], NULL, 0);
argv++;
argc--;
--- 541,555 ----
if (pp[2] && !STRNCMP("apitalize", pp + 2, 9))
capitalize = 1;
else if (pp[2] && STRNCMP("ols", pp + 2, 3))
! {
! colsgiven = 1;
! cols = (int)strtol(pp + 2, NULL, 0);
! }
else
{
if (!argv[2])
exit_with_usage();
+ colsgiven = 1;
cols = (int)strtol(argv[2], NULL, 0);
argv++;
argc--;
***************
*** 645,651 ****
argc--;
}

! if (!cols)
switch (hextype)
{
case HEX_POSTSCRIPT: cols = 30; break;
--- 650,656 ----
argc--;
}

! if (!colsgiven || (!cols && hextype != HEX_POSTSCRIPT))
switch (hextype)
{
case HEX_POSTSCRIPT: cols = 30; break;
***************
*** 667,673 ****
default: octspergrp = 0; break;
}

! 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);
--- 672,680 ----
default: octspergrp = 0; break;
}

! if ((hextype == HEX_POSTSCRIPT && cols < 0) ||
! (hextype != HEX_POSTSCRIPT && 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);
***************
*** 787,799 ****
putc_or_die(hexx[(e >> 4) & 0xf], fpo);
putc_or_die(hexx[e & 0xf], fpo);
n++;
! if (!--p)
{
putc_or_die('\n', fpo);
p = cols;
}
}
! if (p < cols)
putc_or_die('\n', fpo);
fclose_or_die(fp, fpo);
return 0;
--- 794,806 ----
putc_or_die(hexx[(e >> 4) & 0xf], fpo);
putc_or_die(hexx[e & 0xf], fpo);
n++;
! if (cols > 0 && !--p)
{
putc_or_die('\n', fpo);
p = cols;
}
}
! if (cols == 0 || p < cols)
putc_or_die('\n', fpo);
fclose_or_die(fp, fpo);
return 0;
*** ../vim-8.2.4087/src/version.c 2022-01-13 22:05:05.567104513 +0000
--- src/version.c 2022-01-14 11:53:21.168537450 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4088,
/**/

--
Q: Why do ducks have flat feet?
A: To stamp out forest fires.

Q: Why do elephants have flat feet?
A: To stamp out flaming ducks.

/// 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