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
1 changed files with 23 additions and 19 deletions

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':
} help();
if (strcmp(cp, "--")) { exit(EX_OK);
++i; break;
break; case 'x':
} exit(test());
if (!strcmp(cp, "-h")) { break;
help(); case '?':
exit(0); case ':':
} default:
if (!strcmp(cp, "-x")) { help();
return test(); exit(EX_USAGE);
} }
} }
argv += i; argv += optind;
argc -= i; argc -= optind;
if (argc == 0) { if (argc == 0) {
help(); help();
return 1; exit(EX_USAGE);
} }
rv = 0; rv = 0;