clean up md5 a little bit.

This commit is contained in:
Kelvin Sherlock 2016-07-25 20:07:25 -04:00
parent 1e412545e7
commit 22e10b6c56

42
md5.c
View File

@ -1,6 +1,8 @@
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#include <sysexits.h>
#include <tomcrypt.h> #include <tomcrypt.h>
@ -103,7 +105,7 @@ int test() {
} }
void help() { void help() {
fputs("Usage: MD5 [-x] files...\n", stdout); fputs("Usage: MD5 [-h -x] files...\n", stdout);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -111,31 +113,33 @@ int main(int argc, char **argv) {
int rv; int rv;
int i; int i;
int c;
for (i = 1; i < argc; ++i) { while ( (c = getopt(argc, argv, "hx")) != -1) {
char *cp = argv[i];
if (*cp != '-') { switch(c) {
break; case 'h':
}
if (strcmp(cp, "--")) {
++i;
break;
}
if (!strcmp(cp, "-h")) {
help(); help();
exit(0); exit(EX_OK);
} break;
if (!strcmp(cp, "-x")) { case 'x':
return test(); exit(test());
} break;
case '?':
case ':':
default:
help();
exit(EX_USAGE);
} }
argv += i; }
argc -= i;
argv += optind;
argc -= optind;
if (argc == 0) { if (argc == 0) {
help(); help();
return 1; exit(EX_USAGE);
} }
rv = 0; rv = 0;