Attached is a minor patch to allow the suppression of filenames in the
output.
I am aware it's doable with a:
md5sum diffs | cut -c-32
but I find having it integrated would be more beneficial. Indentation of
the code within the if() was not done in order to make the diffs more
legible.
If approved, I can easily produce some diffs for sha1sum as well.
cheers,
--
Iain.
diff -durp textutils-2.1/doc/coreutils.texi textutils-2.1-custom/doc/coreutils.texi
--- textutils-2.1/doc/coreutils.texi Sun Jul 28 16:40:29 2002
+++ textutils-2.1-custom/doc/coreutils.texi Fri Nov 8 15:06:06 2002
@@ -2714,6 +2714,16 @@ If all listed files are readable and are
MD5 checksums, exit successfully. Otherwise exit with a status code
indicating there was a failure.
+@item -s
+@itemx --suppress
+@opindex -s
+@opindex --suppress
+@cindex suppressing filenames
+Sometimes all you want is the checksum, without any indication of
+the file from which it was derived. This option will suppress the
+printing of the input file (or @samp{-} in the case of standard
+input) and display only the checksum.
+
@item -t
@itemx --text
@opindex -t
diff -durp textutils-2.1/src/md5sum.c textutils-2.1-custom/src/md5sum.c
--- textutils-2.1/src/md5sum.c Tue Jul 2 15:15:06 2002
+++ textutils-2.1-custom/src/md5sum.c Fri Nov 8 13:42:44 2002
@@ -109,6 +109,7 @@ static const struct option long_options[
{ "string", required_argument, 0, 1 },
{ "text", no_argument, 0, 't' },
{ "warn", no_argument, 0, 'w' },
+ { "suppress", no_argument, 0, 's' },
{ GETOPT_HELP_OPTION_DECL },
{ GETOPT_VERSION_OPTION_DECL },
{ NULL, 0, NULL, 0 }
@@ -136,6 +137,7 @@ With no FILE, or when FILE is -, read st
-b, --binary read files in binary mode (default on DOS/Windows)\n\
-c, --check check %s sums against given list\n\
-t, --text read files in text mode (default)\n\
+ -s, --suppress only display sum, not the filename\n\
\n\
"),
DIGEST_TYPE_STRING (algorithm));
@@ -491,6 +493,7 @@ main (int argc, char **argv)
char **string = NULL;
size_t n_strings = 0;
size_t err = 0;
+ int suppress_filename = 0;
int file_type_specified = 0;
#if O_BINARY
@@ -540,6 +543,9 @@ main (int argc, char **argv)
file_type_specified = 1;
binary = 0;
break;
+ case 's':
+ suppress_filename = 1;
+ break;
case 'w':
status_only = 0;
warn = 1;
@@ -641,6 +647,8 @@ verifying checksums"));
for (i = 0; i < (digest_hex_bytes / 2); ++i)
printf ("%02x", bin_buffer[i]);
+ if (!suppress_filename)
+ {
putchar (' ');
if (binary)
putchar ('*');
@@ -666,6 +674,7 @@ verifying checksums"));
break;
}
}
+ }
putchar ('\n');
}
}
diff -durp textutils-2.1/tests/md5sum/basic-1 textutils-2.1-custom/tests/md5sum/basic-1
--- textutils-2.1/tests/md5sum/basic-1 Fri Jul 16 02:13:47 1999
+++ textutils-2.1-custom/tests/md5sum/basic-1 Fri Nov 8 13:46:24 2002
@@ -34,6 +34,8 @@ my @Tests =
{OUT=>"d174ab98d277d9f5a5611c2c9f419d9f f\n"}],
['7', {IN=> {f=> '1234567890' x 8}},
{OUT=>"57edf4a22be3c955ac49da2e2107b67a f\n"}],
+ ['8', '--suppress', {IN=> {f=> '1234567890' x 8}},
+ {OUT=>"57edf4a22be3c955ac49da2e2107b67a\n"}],
['backslash', {IN=> {".\\foo"=> ''}},
{OUT=>"\\$degenerate .\\\\foo\n"}],
);
diff -durp textutils-2.1/tests/md5sum/newline-1
textutils-2.1-custom/tests/md5sum/newline-1
--- textutils-2.1/tests/md5sum/newline-1 Sun Jul 2 02:45:31 2000
+++ textutils-2.1-custom/tests/md5sum/newline-1 Fri Nov 8 13:47:46 2002
@@ -42,6 +42,8 @@ my $t = '--text';
my @Tests =
(
['newline', $t, {IN=> {"a\nb"=> ''}}, {OUT=>"\\$degenerate a\\nb\n"}],
+ ['suppress', "--suppress $t",
+ {IN=> {"a\nb"=> ''}}, {OUT=>"\\$degenerate\n"}],
);
my $save_temps = $ENV{DEBUG};