summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1998-01-02 07:04:25 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1998-01-02 07:04:25 +0000
commit2477d2ef386737d213ec177d10749f0f6a152613 (patch)
treeb13e8f7082126e34779267544b2b8cb5568284df
parent6af80c3cd7b5a7cf502caa8e01cb7a293eb09b33 (diff)
use getopt; mph@pobox.com
-rw-r--r--bin/md5/md5.128
-rw-r--r--bin/md5/md5.c55
-rw-r--r--bin/md5/rmd160.125
-rw-r--r--bin/md5/sha1.128
4 files changed, 71 insertions, 65 deletions
diff --git a/bin/md5/md5.1 b/bin/md5/md5.1
index 5ecd0c07ced..7f21d8c8c37 100644
--- a/bin/md5/md5.1
+++ b/bin/md5/md5.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: md5.1,v 1.3 1997/11/12 14:29:47 provos Exp $
+.\" $OpenBSD: md5.1,v 1.4 1998/01/02 07:04:23 deraadt Exp $
.\"
.Dd February 14, 1994
.Dt MD5 1
@@ -8,11 +8,9 @@
.Nd "calculate a message-digest fingerprint (checksum) for a file"
.Sh SYNOPSIS
.Nm
-.Op Fl p
-.Op Fl t
-.Op Fl x
-.Op Fl s Ns Ar string
-.Op Ar filename(s)
+.Op Fl ptx
+.Op Fl s Ar string
+.Op Ar file ...
.Sh DESCRIPTION
.Nm
takes as input a message of arbitrary length and produces
@@ -28,13 +26,14 @@ encrypted with a private (secret) key under a public-key cryptosystem
such as
.Em RSA .
.Sh OPTIONS
-The following four options may be used in any combination, except
-that
-.Ar filename(s)
-must be the last objects on the command line.
-.Bl -tag -width "filename(s)"
-.It Fl s Ns Ar string
-prints a checksum of the given string.
+The following four options may be used in any combination and must
+precede any files named on the command line. The MD5
+sum of each file listed on the command line is printed after the options
+are processed.
+.Bl -tag -width Fl
+.It Fl s Ar string
+prints a checksum of the given
+.Ar string .
.It Fl p
echos stdin to stdout and appends the
.Em MD5
@@ -43,9 +42,6 @@ sum to stdout.
runs a built-in time trial.
.It Fl x
runs a built-in test script.
-.It Ar filename(s)
-prints the checksum for each file. If no files are specified,
-standard input is used.
.El
.Sh SEE ALSO
.Xr cksum 1 ,
diff --git a/bin/md5/md5.c b/bin/md5/md5.c
index bb96d726ef1..39cbf16f7bf 100644
--- a/bin/md5/md5.c
+++ b/bin/md5/md5.c
@@ -1,5 +1,5 @@
/*
- * $OpenBSD: md5.c,v 1.7 1997/08/01 10:07:11 deraadt Exp $
+ * $OpenBSD: md5.c,v 1.8 1998/01/02 07:04:23 deraadt Exp $
*
* Derived from:
* MDDRIVER.C - test driver for MD2, MD4 and MD5
@@ -40,6 +40,7 @@ static void MDString __P((char *));
static void MDTimeTrial __P((void *));
static void MDTestSuite __P((void));
static void MDFilter __P((int, void *));
+static void usage __P((char *));
int main __P((int, char *[]));
@@ -67,7 +68,7 @@ main(argc, argv)
int argc;
char *argv[];
{
- int i;
+ int ch;
char *p;
char buf[41];
void *context;
@@ -102,25 +103,35 @@ main(argc, argv)
err(1, "malloc");
}
- if (argc > 1)
- for (i = 1; i < argc; i++)
- if (argv[i][0] == '-' && argv[i][1] == 's')
- MDString(argv[i] + 2);
- else if (strcmp(argv[i], "-t") == 0)
- MDTimeTrial(context);
- else if (strcmp(argv[i], "-p") == 0)
+ if (argc > 1) {
+ while ((ch = getopt(argc, argv, "ps:tx")) != -1) {
+ switch (ch) {
+ case 'p':
MDFilter(1, context);
- else if (strcmp(argv[i], "-x") == 0)
+ break;
+ case 's':
+ MDString(optarg);
+ break;
+ case 't':
+ MDTimeTrial(context);
+ break;
+ case 'x':
MDTestSuite();
- else {
- p = MDFile(argv[i], buf);
- if (!p)
- warn(argv[i]);
- else
- (void)printf("%s (%s) = %s\n", MDType,
- argv[i], p);
+ break;
+ default:
+ usage(MDType);
}
- else
+ }
+ while (optind < argc) {
+ p = MDFile(argv[optind], buf);
+ if (!p)
+ perror(argv[optind]);
+ else
+ printf("%s (%s) = %s\n", MDType,
+ argv[optind], p);
+ optind++;
+ }
+ } else
MDFilter(0, context);
exit(0);
@@ -221,3 +232,11 @@ MDFilter(pipe, context)
}
(void)printf("%s\n", MDEnd(context,buf));
}
+
+static void
+usage(type)
+char *type;
+{
+ fprintf(stderr, "usage: %s [-ptx] [-s string] [file ...]\n", type);
+ exit(1);
+}
diff --git a/bin/md5/rmd160.1 b/bin/md5/rmd160.1
index dcc3a70f279..746a81c6b8f 100644
--- a/bin/md5/rmd160.1
+++ b/bin/md5/rmd160.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: rmd160.1,v 1.2 1997/11/12 14:29:48 provos Exp $
+.\" $OpenBSD: rmd160.1,v 1.3 1998/01/02 07:04:24 deraadt Exp $
.\"
.Dd July 16, 1997
.Dt RMD160 1
@@ -8,11 +8,9 @@
.Nd "calculate a message-digest fingerprint (checksum) for a file"
.Sh SYNOPSIS
.Nm
-.Op Fl p
-.Op Fl t
-.Op Fl x
-.Op Fl s Ns Ar string
-.Op Ar filename(s)
+.Op Fl ptx
+.Op Fl s Ar string
+.Op Ar file ...
.Sh DESCRIPTION
.Nm
takes as input a message of arbitrary length and produces
@@ -28,12 +26,12 @@ encrypted with a private (secret) key under a public-key cryptosystem
such as
.Em RSA .
.Sh OPTIONS
-The following four options may be used in any combination, except
-that
-.Ar filename(s)
-must be the last objects on the command line.
-.Bl -tag -width "filename(s)"
-.It Fl s Ns Ar string
+The following four options may be used in any combination and must
+precede any files named on the command line. The RMD-160
+sum of each file listed on the command line is printed after the options
+are processed.
+.Bl -tag -width Fl
+.It Fl s Ar string
prints a checksum of the given string.
.It Fl p
echos stdin to stdout and appends the
@@ -43,9 +41,6 @@ sum to stdout.
runs a built-in time trial.
.It Fl x
runs a built-in test script.
-.It Ar filename(s)
-prints the checksum for each file. If no files are specified,
-standard input is used.
.El
.Sh SEE ALSO
.Xr cksum 1 ,
diff --git a/bin/md5/sha1.1 b/bin/md5/sha1.1
index 8602a73267b..eb8da56fbfb 100644
--- a/bin/md5/sha1.1
+++ b/bin/md5/sha1.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sha1.1,v 1.3 1997/11/12 14:29:48 provos Exp $
+.\" $OpenBSD: sha1.1,v 1.4 1998/01/02 07:04:24 deraadt Exp $
.\"
.Dd July 12, 1997
.Dt SHA1 1
@@ -8,11 +8,9 @@
.Nd "calculate a message-digest fingerprint (checksum) for a file"
.Sh SYNOPSIS
.Nm
-.Op Fl p
-.Op Fl t
-.Op Fl x
-.Op Fl s Ns Ar string
-.Op Ar filename(s)
+.Op Fl ptx
+.Op Fl s Ar string
+.Op Ar file ...
.Sh DESCRIPTION
.Nm
takes as input a message of arbitrary length and produces
@@ -28,13 +26,14 @@ encrypted with a private (secret) key under a public-key cryptosystem
such as
.Em RSA .
.Sh OPTIONS
-The following four options may be used in any combination, except
-that
-.Ar filename(s)
-must be the last objects on the command line.
-.Bl -tag -width "filename(s)"
-.It Fl s Ns Ar string
-prints a checksum of the given string.
+The following four options may be used in any combination and must
+precede any files named on the command line. The SHA-1
+sum of each file listed on the command line is printed after the options
+are processed.
+.Bl -tag -width Fl
+.It Fl s Ar string
+prints a checksum of the given
+.Ar string .
.It Fl p
echos stdin to stdout and appends the
.Em SHA-1
@@ -43,9 +42,6 @@ sum to stdout.
runs a built-in time trial.
.It Fl x
runs a built-in test script.
-.It Ar filename(s)
-prints the checksum for each file. If no files are specified,
-standard input is used.
.El
.Sh SEE ALSO
.Xr cksum 1 ,