Re: New option for md5sum

2014-04-19 Thread Bernhard Voelker
On 04/19/2014 04:48 AM, Bob Proulx wrote:
 Rather than cut and using an exact number of characters I prefer to
 use awk to cut by fields.  That way it works with all of the *sum
 programs.
 
   $ md5sum /dev/null | awk '{print$1}'

And there are many other ways:

  # using the field option of cut:
  $ md5sum /dev/null | src/cut -d ' ' -f 1
  d41d8cd98f00b204e9800998ecf8427e

  $ md5sum /dev/null | sed 's/ .*$//'
  d41d8cd98f00b204e9800998ecf8427e

etc.

Therefore 80:20 against a new option from me, too.

Have a nice day,
Berny



Re: New option for md5sum

2014-04-19 Thread Andreas Schwab
Bernhard Voelker
mail-hqe9kzqpbdrht4tgq10purvvk+yq3...@public.gmane.org writes:

 On 04/19/2014 04:48 AM, Bob Proulx wrote:
 Rather than cut and using an exact number of characters I prefer to
 use awk to cut by fields.  That way it works with all of the *sum
 programs.
 
   $ md5sum /dev/null | awk '{print$1}'

 And there are many other ways:

   # using the field option of cut:
   $ md5sum /dev/null | src/cut -d ' ' -f 1
   d41d8cd98f00b204e9800998ecf8427e

   $ md5sum /dev/null | sed 's/ .*$//'
   d41d8cd98f00b204e9800998ecf8427e

None of them handle quoted file names:

$ md5sum a\\b | awk '{print$1}'
\d41d8cd98f00b204e9800998ecf8427e

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
And now for something completely different.



Re: New option for md5sum

2014-04-19 Thread Pádraig Brady
On 04/19/2014 08:58 AM, Andreas Schwab wrote:
 Bernhard Voelker
 mail-hqe9kzqpbdrht4tgq10purvvk+yq3...@public.gmane.org writes:
 
 On 04/19/2014 04:48 AM, Bob Proulx wrote:
 Rather than cut and using an exact number of characters I prefer to
 use awk to cut by fields.  That way it works with all of the *sum
 programs.

   $ md5sum /dev/null | awk '{print$1}'

 And there are many other ways:

   # using the field option of cut:
   $ md5sum /dev/null | src/cut -d ' ' -f 1
   d41d8cd98f00b204e9800998ecf8427e

   $ md5sum /dev/null | sed 's/ .*$//'
   d41d8cd98f00b204e9800998ecf8427e
 
 None of them handle quoted file names:
 
 $ md5sum a\\b | awk '{print$1}'
 \d41d8cd98f00b204e9800998ecf8427e

The first proposed option using indirection does.
If that's awkward from a programmatic context,
then in such a context it would be trivial
(albeit not obvious) to strip.

Pádraig.



New option for md5sum

2014-04-18 Thread djcj

Can you add an option to md5sum that allows one to output only the checksum?
Here's a code example:

--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -143,6 +143,7 @@
 {
   { binary, no_argument, NULL, 'b' },
   { check, no_argument, NULL, 'c' },
+  { short, no_argument, NULL, 's' },
   { quiet, no_argument, NULL, QUIET_OPTION },
   { status, no_argument, NULL, STATUS_OPTION },
   { text, no_argument, NULL, 't' },
@@ -184,6 +185,10 @@
   fputs (_(\
   --tagcreate a BSD-style checksum\n\
 ), stdout);
+  printf (_(\
+  -s, --short  only the checksum is printed out.  Overrides the\n\
+   --tag option.\n\
+));
   if (O_BINARY)
 fputs (_(\
   -t, --text   read in text mode (default if reading tty stdin)\n\
@@ -696,6 +701,7 @@
   int opt;
   bool ok = true;
   int binary = -1;
+  bool prefix_short = false;
   bool prefix_tag = false;

   /* Setting values of global variables.  */
@@ -711,7 +717,7 @@
  so that processes running in parallel do not intersperse their 
output.  */

   setvbuf (stdout, NULL, _IOLBF, 0);

-  while ((opt = getopt_long (argc, argv, bctw, long_options, NULL)) 
!= -1)
+  while ((opt = getopt_long (argc, argv, bcstw, long_options, NULL)) 
!= -1)

 switch (opt)
   {
   case 'b':
@@ -733,6 +739,9 @@
 warn = true;
 quiet = false;
 break;
+  case 's':
+prefix_short = true;
+break;
   case QUIET_OPTION:
 status_only = false;
 warn = false;
@@ -836,7 +845,7 @@
  output in this case.  */
   bool needs_escape = strchr (file, '\\') || strchr (file, 
'\n');


-  if (prefix_tag)
+  if (prefix_tag  !prefix_short)
 {
   if (needs_escape)
 putchar ('\\');
@@ -847,17 +856,23 @@
   fputs () = , stdout);
 }

+  if (prefix_short  !prefix_tag)
+{
+  if (needs_escape)
+putchar ('\\');
+}
+
   size_t i;

   /* Output a leading backslash if the file name contains
  a newline or backslash.  */
-  if (!prefix_tag  needs_escape)
+  if (!prefix_tag  !prefix_short  needs_escape)
 putchar ('\\');

   for (i = 0; i  (digest_hex_bytes / 2); ++i)
 printf (%02x, bin_buffer[i]);

-  if (!prefix_tag)
+  if (!prefix_tag  !prefix_short)
 {
   putchar (' ');




Re: New option for md5sum

2014-04-18 Thread Pádraig Brady
On 04/19/2014 12:51 AM, djcj wrote:
 Can you add an option to md5sum that allows one to output only the checksum?
 Here's a code example:

Thanks for the patch.
However this is one of those marginal cases where it's
probably not worth the extra option to do this simple adjustment.

At the shell you can do: md5sum  the_file | cut -b1-32
Also if running from another program, one could easily
take the start of the output (accounting for leading backslashes).

So I'd be 70:30 against adding this.

thanks,
Pádraig.




Re: New option for md5sum

2014-04-18 Thread Bob Proulx
Pádraig Brady wrote:
 djcj wrote:
  Can you add an option to md5sum that allows one to output only the checksum?
  Here's a code example:
 
 Thanks for the patch.
 However this is one of those marginal cases where it's
 probably not worth the extra option to do this simple adjustment.

After all of this time I think it is one of standard is better than
better and all of the implementations are already the other way.

 At the shell you can do: md5sum  the_file | cut -b1-32

Rather than cut and using an exact number of characters I prefer to
use awk to cut by fields.  That way it works with all of the *sum
programs.

  $ md5sum /dev/null | awk '{print$1}'
  d41d8cd98f00b204e9800998ecf8427e

  $ sha1sum /dev/null | awk '{print$1}'
  da39a3ee5e6b4b0d3255bfef95601890afd80709

  $ sha512sum /dev/null | awk '{print$1}'
  
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e

 Also if running from another program, one could easily
 take the start of the output (accounting for leading backslashes).
 
 So I'd be 70:30 against adding this.

I would only add it if there were the creation of a new sum program.
Then it could be counted upon to exist in that program throughout the
lifetime of it.  But needing to add the option --short is already
almost as long as awk '{print$1}' so doesn't seem to be compelling.

Bob