]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4088: xxd cannot output everything in one line v8.2.4088
authorErik Auerswald <auerswal@unix-ag.uni-kl.de>
Fri, 14 Jan 2022 11:58:48 +0000 (11:58 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 14 Jan 2022 11:58:48 +0000 (11:58 +0000)
Problem:    Xxd cannot output everything in one line.
Solution:   Make zero columns mean infinite columns. (Erik Auerswald,
            closes #9524)

runtime/doc/xxd.1
runtime/doc/xxd.man
src/testdir/test_xxd.vim
src/version.c
src/xxd/xxd.c

index 46bfedc1e89162b8543fd4dcc4acf7fe4cd907b0..fb0ac44b10ad348908f1bd37e7d34a0e8c7343d6 100644 (file)
@@ -70,6 +70,7 @@ followed by an ascii (or ebcdic) representation. The command line switches
 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.
index 607db8aa99d87d73f60b36fbcb8da5a9945d1011..26d89e5659e72d522e1a730d85da00edad723e21 100644 (file)
@@ -42,7 +42,8 @@ OPTIONS
 
        -c cols | -cols cols
               Format  <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b:
-              6). Max 256.
+              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
index 7d0cbabefafdeb40657723ffa1ad48b6734b88d2..bdcbd082ce95f4c3180060864b5ab6f4826cfe73 100644 (file)
@@ -320,10 +320,11 @@ func Test_xxd_max_cols()
 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', '-p', ]
+    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,4 +335,27 @@ func Test_xxd_c0_is_def_cols()
   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
index 782a64a1154cc4c3d03b23a18e5f97eae234ebd8..b55bddaf69df954e3ef6ca7b6efed1555c7d21b7 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4088,
 /**/
     4087,
 /**/
index c32b9b8fbe2c2101b543acc6ce44f13503d2f678..0e056c93d7e2629ff286536aa107f3df8d6214ff 100644 (file)
@@ -54,6 +54,7 @@
  * 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 (jnweiger@gmail.com)
  *
@@ -135,7 +136,7 @@ extern void perror __P((char *));
 extern long int strtol();
 extern long int ftell();
 
-char version[] = "xxd 2021-10-22 by Juergen Weigert et al.";
+char version[] = "xxd 2022-01-14 by Juergen Weigert et al.";
 #ifdef WIN32
 char osver[] = " (Win32)";
 #else
@@ -487,7 +488,7 @@ main(int argc, char *argv[])
 {
   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 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,11 +541,15 @@ main(int argc, char *argv[])
          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);
+           {
+             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,7 +650,7 @@ main(int argc, char *argv[])
       argc--;
     }
 
-  if (!cols)
+  if (!colsgiven || (!cols && hextype != HEX_POSTSCRIPT))
     switch (hextype)
       {
       case HEX_POSTSCRIPT:     cols = 30; break;
@@ -667,7 +672,9 @@ main(int argc, char *argv[])
       default:                 octspergrp = 0; break;
       }
 
-  if (cols < 1 || ((hextype == HEX_NORMAL || hextype == HEX_BITS || hextype == HEX_LITTLEENDIAN)
+  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,13 +794,13 @@ main(int argc, char *argv[])
          putc_or_die(hexx[(e >> 4) & 0xf], fpo);
          putc_or_die(hexx[e & 0xf], fpo);
          n++;
-         if (!--p)
+         if (cols > 0 && !--p)
            {
              putc_or_die('\n', fpo);
              p = cols;
            }
        }
-      if (p < cols)
+      if (cols == 0 || p < cols)
        putc_or_die('\n', fpo);
       fclose_or_die(fp, fpo);
       return 0;