summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-12-23 23:57:56 +0000
committerJim Meyering <jim@meyering.net>1996-12-23 23:57:56 +0000
commit3bcffe04d7161a42fe4fb99a3113b169a6e5c738 (patch)
tree4e8317189b496ecb045a1d69443285baee5c6dd6
parent79523152dd6d8d995241646b56a8e8a15f6c519f (diff)
downloadcoreutils-3bcffe04d7161a42fe4fb99a3113b169a6e5c738.tar.xz
revert last change
-rw-r--r--src/md5sum.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/md5sum.c b/src/md5sum.c
index da863a964..16f35476e 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -85,11 +85,14 @@ static const struct option long_options[] =
{ "binary", no_argument, 0, 'b' },
{ "check", no_argument, 0, 'c' },
{ "status", no_argument, 0, 2 },
+ { "string", required_argument, 0, 1 },
{ "text", no_argument, 0, 't' },
{ "warn", no_argument, 0, 'w' },
{ NULL, 0, NULL, 0 }
};
+char *xmalloc ();
+
static void
usage (int status)
{
@@ -443,6 +446,8 @@ main (int argc, char **argv)
unsigned char md5buffer[16];
int do_check = 0;
int opt;
+ char **string = NULL;
+ size_t n_strings = 0;
size_t i;
size_t err = 0;
int file_type_specified = 0;
@@ -464,6 +469,16 @@ main (int argc, char **argv)
{
case 0: /* long option */
break;
+ case 1: /* --string */
+ {
+ if (string == NULL)
+ string = (char **) xmalloc ((argc - 1) * sizeof (char *));
+
+ if (optarg == NULL)
+ optarg = "";
+ string[n_strings++] = optarg;
+ }
+ break;
case 'b':
file_type_specified = 1;
binary = 1;
@@ -494,6 +509,13 @@ verifying checksums"));
usage (EXIT_FAILURE);
}
+ if (n_strings > 0 && do_check)
+ {
+ error (0, 0,
+ _("the --string and --check options are mutually exclusive"));
+ usage (EXIT_FAILURE);
+ }
+
if (status_only && !do_check)
{
error (0, 0,
@@ -508,7 +530,25 @@ verifying checksums"));
usage (EXIT_FAILURE);
}
- if (do_check)
+ if (n_strings > 0)
+ {
+ if (optind < argc)
+ {
+ error (0, 0, _("no files may be specified when using --string"));
+ usage (EXIT_FAILURE);
+ }
+ for (i = 0; i < n_strings; ++i)
+ {
+ size_t cnt;
+ md5_buffer (string[i], strlen (string[i]), md5buffer);
+
+ for (cnt = 0; cnt < 16; ++cnt)
+ printf ("%02x", md5buffer[cnt]);
+
+ printf (" \"%s\"\n", string[i]);
+ }
+ }
+ else if (do_check)
{
if (optind + 1 < argc)
{