bug-textutils
[Top][All Lists]
Advanced

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

md5sum feature request


From: Ian Grant
Subject: md5sum feature request
Date: Wed, 01 Aug 2001 12:34:27 +0100

md5sum should be able to just output the checksum and nothing else. Of course 
this makes little sense when given multiple files, but for stdin or a single 
file it's useful and allows md5sum to be used in place of md5.  Here's a patch 
against textutils-2.0

diff -urN textutils-2.0/doc/textutils.texi 
textutils-2.0.md5sum.mods/doc/textutils.texi
--- textutils-2.0/doc/textutils.texi    Sat Jul 31 10:03:30 1999
+++ textutils-2.0.md5sum.mods/doc/textutils.texi        Wed Aug  1 12:27:37 2001
@@ -2029,6 +2029,14 @@
 MD5 checksums, exit successfully.  Otherwise exit with a status code
 indicating there was a failure.
 
address@hidden -s
address@hidden --sum
address@hidden outputting only the MD5 sum
+Output only the checksum, omitting the file type and name information. This
+This option is not useful when more than one filename is specified on the
+command line. The output is not suitable for use with the @samp{--check}
+option.
+
 @item -t
 @itemx --text
 @opindex -t
diff -urN textutils-2.0/man/md5sum.1 textutils-2.0.md5sum.mods/man/md5sum.1
--- textutils-2.0/man/md5sum.1  Fri Aug  6 20:24:08 1999
+++ textutils-2.0.md5sum.mods/man/md5sum.1      Wed Aug  1 12:09:56 2001
@@ -21,6 +21,9 @@
 \fB\-c\fR, \fB\-\-check\fR
 check MD5 sums against given list
 .TP
+\fB\-s\fR, \fB\-\-sum\fR
+only output the md5 sums, not the file names or types
+.TP
 \fB\-t\fR, \fB\-\-text\fR
 read files in text mode (default)
 .SS "The following two options are useful only when verifying checksums:"
diff -urN textutils-2.0/src/md5sum.c textutils-2.0.md5sum.mods/src/md5sum.c
--- textutils-2.0/src/md5sum.c  Mon May  3 18:55:37 1999
+++ textutils-2.0.md5sum.mods/src/md5sum.c      Wed Aug  1 12:19:00 2001
@@ -87,6 +87,7 @@
   { "status", no_argument, 0, 2 },
   { "string", required_argument, 0, 1 },
   { "text", no_argument, 0, 't' },
+  { "sum", no_argument, 0, 's' },
   { "warn", no_argument, 0, 'w' },
   { GETOPT_HELP_OPTION_DECL },
   { GETOPT_VERSION_OPTION_DECL },
@@ -108,6 +109,7 @@
 With no FILE, or when FILE is -, read standard input.\n\
 \n\
   -b, --binary            read files in binary mode (default on DOS/Windows)\n\
+  -s, --sum               only output the sum(s), not the file names or 
types\n\
   -c, --check             check MD5 sums against given list\n\
   -t, --text              read files in text mode (default)\n\
 \n\
@@ -456,6 +458,7 @@
   size_t n_strings = 0;
   size_t err = 0;
   int file_type_specified = 0;
+  int sum_only = 0;
 
 #if O_BINARY
   /* Binary is default on MSDOS, so the actual file contents
@@ -472,7 +475,7 @@
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
-  while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1)
+  while ((opt = getopt_long (argc, argv, "bctsw", long_options, NULL)) != -1)
     switch (opt)
       {
       case 0:                  /* long option */
@@ -502,6 +505,9 @@
        file_type_specified = 1;
        binary = 0;
        break;
+      case 's':
+       sum_only = 1;
+       break;
       case 'w':
        status_only = 0;
        warn = 1;
@@ -595,31 +601,33 @@
              for (i = 0; i < 16; ++i)
                printf ("%02x", md5buffer[i]);
 
-             putchar (' ');
-             if (binary)
-               putchar ('*');
-             else
-               putchar (' ');
-
-             /* Translate each NEWLINE byte to the string, "\\n",
-                and each backslash to "\\\\".  */
-             for (i = 0; i < strlen (file); ++i)
-               {
-                 switch (file[i])
-                   {
-                   case '\n':
-                     fputs ("\\n", stdout);
-                     break;
-
-                   case '\\':
-                     fputs ("\\\\", stdout);
-                     break;
-
-                   default:
-                     putchar (file[i]);
-                     break;
-                   }
-               }
+             if (!sum_only) {
+               putchar (' ');
+               if (binary)
+                 putchar ('*');
+               else
+                 putchar (' ');
+
+               /* Translate each NEWLINE byte to the string, "\\n",
+                  and each backslash to "\\\\".  */
+               for (i = 0; i < strlen (file); ++i)
+                 {
+                   switch (file[i])
+                     {
+                     case '\n':
+                       fputs ("\\n", stdout);
+                       break;
+
+                     case '\\':
+                       fputs ("\\\\", stdout);
+                       break;
+
+                     default:
+                       putchar (file[i]);
+                       break;
+                     }
+                 }
+             }
              putchar ('\n');
            }
        }

-- 
Ian Grant, Computer Lab., New Museums Site, Pembroke Street, Cambridge
Phone: +44 1223 334420




reply via email to

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