coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New option for md5sum


From: djcj
Subject: New option for md5sum
Date: Sat, 19 Apr 2014 01:51:20 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

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 (_("\
       --tag            create 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 (' ');




reply via email to

[Prev in Thread] Current Thread [Next in Thread]