Hi,

the attached patch allows xxd to print plain hexdump style output in a single
line. This format is accepted as input already.

I have used "{ xxd -ps | tr -d '\n'; echo; }" as a workaround in the past.

Others have asked how to omit line breaks from the output of xxd, see e.g.
https://unix.stackexchange.com/questions/218514/xxd-output-without-line-breaks

One use case is working with cryptographic material, see e.g.
https://stackoverflow.com/questions/42192490/aes-cbc-incorrect-usage

Thanks,
Erik
-- 
Always use the right tool for the job.
                        -- Rob Pike

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/xxd.1 b/runtime/doc/xxd.1
index 46bfedc..2528844 100644
--- a/runtime/doc/xxd.1
+++ b/runtime/doc/xxd.1
@@ -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.
+Specifying 0 in plain hexdump style prints everything in one line.
 .TP
 .IR \-C " | " \-capitalize
 Capitalize variable names in C include file style, when using \-i.
diff --git a/runtime/doc/xxd.man b/runtime/doc/xxd.man
index 607db8a..43b28b6 100644
--- a/runtime/doc/xxd.man
+++ b/runtime/doc/xxd.man
@@ -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.  Specifying 0 in plain hexdump style prints  every‐
+              thing in one line.
 
        -C | -capitalize
               Capitalize variable names in C include file  style,  when  using
diff --git a/src/xxd/xxd.c b/src/xxd/xxd.c
index d102db4..8478217 100644
--- a/src/xxd/xxd.c
+++ b/src/xxd/xxd.c
@@ -462,7 +462,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, capitalize = 0;
+  int cols = -1, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL, capitalize = 0;
   int ebcdic = 0;
   int octspergrp = -1;	/* number of octets grouped in output */
   int grplen;		/* total chars per octet group */
@@ -604,7 +604,7 @@ main(int argc, char *argv[])
       argc--;
     }
 
-  if (!cols)
+  if (cols < 0)
     switch (hextype)
       {
       case HEX_POSTSCRIPT:	cols = 30; break;
@@ -626,8 +626,8 @@ main(int argc, char *argv[])
       default:			octspergrp = 0; break;
       }
 
-  if (cols < 1 || ((hextype == HEX_NORMAL || hextype == HEX_BITS || hextype == HEX_LITTLEENDIAN)
-							    && (cols > COLS)))
+  if (cols < 0 || (cols == 0 && hextype != HEX_POSTSCRIPT) || (cols > COLS &&
+      (hextype == HEX_NORMAL || hextype == HEX_BITS || hextype == HEX_LITTLEENDIAN)))
     {
       fprintf(stderr, "%s: invalid number of columns (max. %d).\n", pname, COLS);
       exit(1);
@@ -779,7 +779,7 @@ main(int argc, char *argv[])
 		  || putc(hexx[e & 0xf], fpo) == EOF)
 	    die(3);
 	  n++;
-	  if (!--p)
+	  if (cols && !--p)
 	    {
 	      if (putc('\n', fpo) == EOF)
 		die(3);
@@ -788,7 +788,7 @@ main(int argc, char *argv[])
 	}
       if (e == EOF && ferror(fp))
 	die(2);
-      if (p < cols)
+      if (!cols || p < cols)
 	if (putc('\n', fpo) == EOF)
 	  die(3);
       if (fclose(fp))

Raspunde prin e-mail lui