• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision2f854597399f933fbc557557c42ad9ee0e3d7046 (tree)
Time2022-01-14 21:00:07
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.4088: xxd cannot output everything in one line

Commit: https://github.com/vim/vim/commit/c0a1d370fa655cea9eaa74f5e605b95825dc9de1
Author: Erik Auerswald <auerswal@unix-ag.uni-kl.de>
Date: Fri Jan 14 11:58:48 2022 +0000

patch 8.2.4088: xxd cannot output everything in one line
Problem: Xxd cannot output everything in one line.
Solution: Make zero columns mean infinite columns. (Erik Auerswald,
closes #9524)

Change Summary

Incremental Difference

diff -r a11e7c054f98 -r 2f854597399f runtime/doc/xxd.1
--- a/runtime/doc/xxd.1 Thu Jan 13 23:15:04 2022 +0100
+++ b/runtime/doc/xxd.1 Fri Jan 14 13:00:07 2022 +0100
@@ -70,6 +70,7 @@
7070 Format
7171 .RI < cols >
7272 octets per line. Default 16 (\-i: 12, \-ps: 30, \-b: 6). Max 256.
73+No maxmimum for \-ps. With \-ps, 0 results in one long line of output.
7374 .TP
7475 .IR \-C " | " \-capitalize
7576 Capitalize variable names in C include file style, when using \-i.
diff -r a11e7c054f98 -r 2f854597399f runtime/doc/xxd.man
--- a/runtime/doc/xxd.man Thu Jan 13 23:15:04 2022 +0100
+++ b/runtime/doc/xxd.man Fri Jan 14 13:00:07 2022 +0100
@@ -42,7 +42,8 @@
4242
4343 -c cols | -cols cols
4444 Format <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b:
45- 6). Max 256.
45+ 6). Max 256. No maxmimum for -ps. With -ps, 0 results in one
46+ long line of output.
4647
4748 -C | -capitalize
4849 Capitalize variable names in C include file style, when using
diff -r a11e7c054f98 -r 2f854597399f src/testdir/test_xxd.vim
--- a/src/testdir/test_xxd.vim Thu Jan 13 23:15:04 2022 +0100
+++ b/src/testdir/test_xxd.vim Fri Jan 14 13:00:07 2022 +0100
@@ -320,10 +320,11 @@
320320 endfunc
321321
322322 " -c0 selects the format specific default column value, as if no -c was given
323+" except for -ps, where it disables extra newlines
323324 func Test_xxd_c0_is_def_cols()
324325 call writefile(["abcdefghijklmnopqrstuvwxyz0123456789"], 'Xxdin')
325326 for cols in ['-c0', '-c 0', '-cols 0']
326- for fmt in ['', '-b', '-e', '-i', '-p', ]
327+ for fmt in ['', '-b', '-e', '-i']
327328 exe 'r! ' . s:xxd_cmd . ' ' . fmt ' Xxdin > Xxdout1'
328329 exe 'r! ' . s:xxd_cmd . ' ' . cols . ' ' . fmt ' Xxdin > Xxdout2'
329330 call assert_equalfile('Xxdout1', 'Xxdout2')
@@ -334,4 +335,27 @@
334335 call delete('Xxdout2')
335336 endfunc
336337
338+" all output in a single line for -c0 -ps
339+func Test_xxd_plain_one_line()
340+ call writefile([
341+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
342+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
343+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
344+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
345+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
346+ \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"],
347+ \ 'Xxdin')
348+ for cols in ['-c0', '-c 0', '-cols 0']
349+ exe 'r! ' . s:xxd_cmd . ' -ps ' . cols ' Xxdin'
350+ " output seems to start in line 2
351+ let out = join(getline(2, '$'))
352+ bwipe!
353+ " newlines in xxd output result in spaces in the string variable out
354+ call assert_notmatch(" ", out)
355+ " xxd output must be non-empty and comprise only lower case hex digits
356+ call assert_match("^[0-9a-f][0-9a-f]*$", out)
357+ endfor
358+ call delete('Xxdin')
359+endfunc
360+
337361 " vim: shiftwidth=2 sts=2 expandtab
diff -r a11e7c054f98 -r 2f854597399f src/version.c
--- a/src/version.c Thu Jan 13 23:15:04 2022 +0100
+++ b/src/version.c Fri Jan 14 13:00:07 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4088,
755+/**/
754756 4087,
755757 /**/
756758 4086,
diff -r a11e7c054f98 -r 2f854597399f src/xxd/xxd.c
--- a/src/xxd/xxd.c Thu Jan 13 23:15:04 2022 +0100
+++ b/src/xxd/xxd.c Fri Jan 14 13:00:07 2022 +0100
@@ -54,6 +54,7 @@
5454 * 08.06.2013 Little-endian hexdump (-e) and offset (-o) by Vadim Vygonets.
5555 * 11.01.2019 Add full 64/32 bit range to -o and output by Christer Jensen.
5656 * 04.02.2020 Add -d for decimal offsets by Aapo Rantalainen
57+ * 14.01.2022 Disable extra newlines with -c0 -p by Erik Auerswald.
5758 *
5859 * (c) 1990-1998 by Juergen Weigert (jnweiger@gmail.com)
5960 *
@@ -135,7 +136,7 @@
135136 extern long int strtol();
136137 extern long int ftell();
137138
138-char version[] = "xxd 2021-10-22 by Juergen Weigert et al.";
139+char version[] = "xxd 2022-01-14 by Juergen Weigert et al.";
139140 #ifdef WIN32
140141 char osver[] = " (Win32)";
141142 #else
@@ -487,7 +488,7 @@
487488 {
488489 FILE *fp, *fpo;
489490 int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
490- int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL;
491+ int cols = 0, colsgiven = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL;
491492 int capitalize = 0, decimal_offset = 0;
492493 int ebcdic = 0;
493494 int octspergrp = -1; /* number of octets grouped in output */
@@ -540,11 +541,15 @@
540541 if (pp[2] && !STRNCMP("apitalize", pp + 2, 9))
541542 capitalize = 1;
542543 else if (pp[2] && STRNCMP("ols", pp + 2, 3))
543- cols = (int)strtol(pp + 2, NULL, 0);
544+ {
545+ colsgiven = 1;
546+ cols = (int)strtol(pp + 2, NULL, 0);
547+ }
544548 else
545549 {
546550 if (!argv[2])
547551 exit_with_usage();
552+ colsgiven = 1;
548553 cols = (int)strtol(argv[2], NULL, 0);
549554 argv++;
550555 argc--;
@@ -645,7 +650,7 @@
645650 argc--;
646651 }
647652
648- if (!cols)
653+ if (!colsgiven || (!cols && hextype != HEX_POSTSCRIPT))
649654 switch (hextype)
650655 {
651656 case HEX_POSTSCRIPT: cols = 30; break;
@@ -667,7 +672,9 @@
667672 default: octspergrp = 0; break;
668673 }
669674
670- if (cols < 1 || ((hextype == HEX_NORMAL || hextype == HEX_BITS || hextype == HEX_LITTLEENDIAN)
675+ if ((hextype == HEX_POSTSCRIPT && cols < 0) ||
676+ (hextype != HEX_POSTSCRIPT && cols < 1) ||
677+ ((hextype == HEX_NORMAL || hextype == HEX_BITS || hextype == HEX_LITTLEENDIAN)
671678 && (cols > COLS)))
672679 {
673680 fprintf(stderr, "%s: invalid number of columns (max. %d).\n", pname, COLS);
@@ -787,13 +794,13 @@
787794 putc_or_die(hexx[(e >> 4) & 0xf], fpo);
788795 putc_or_die(hexx[e & 0xf], fpo);
789796 n++;
790- if (!--p)
797+ if (cols > 0 && !--p)
791798 {
792799 putc_or_die('\n', fpo);
793800 p = cols;
794801 }
795802 }
796- if (p < cols)
803+ if (cols == 0 || p < cols)
797804 putc_or_die('\n', fpo);
798805 fclose_or_die(fp, fpo);
799806 return 0;
Show on old repository browser