diff options
author | Robert Nagy <robert@cvs.openbsd.org> | 2005-03-25 14:01:38 +0000 |
---|---|---|
committer | Robert Nagy <robert@cvs.openbsd.org> | 2005-03-25 14:01:38 +0000 |
commit | 407174ae4ad4305a4fee8e4876d5232c2f15db8c (patch) | |
tree | 8b7726943e65edeff83611ccd8bbf293147c0af2 /usr.sbin | |
parent | 73e896e10fae69399b445ad27d4907e2642f05b3 (diff) |
use getopt() for argument list parsing
ok otto@ henning@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/httpd/src/support/htpasswd.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/usr.sbin/httpd/src/support/htpasswd.c b/usr.sbin/httpd/src/support/htpasswd.c index f4b6a0d6fb9..23e035532b2 100644 --- a/usr.sbin/httpd/src/support/htpasswd.c +++ b/usr.sbin/httpd/src/support/htpasswd.c @@ -337,7 +337,8 @@ int main(int argc, char *argv[]) int i; int args_left = 2; int tfd; - + int ch; + signal(SIGINT, (void (*)(int)) interrupted); /* @@ -353,50 +354,49 @@ int main(int argc, char *argv[]) * Go through the argument list and pick out any options. They * have to precede any other arguments. */ - for (i = 1; i < argc; i++) { - arg = argv[i]; - if (*arg != '-') { - break; - } - while (*++arg != '\0') { - if (*arg == 'c') { - newfile++; - } - else if (*arg == 'n') { - nofile++; - args_left--; - } - else if (*arg == 'm') { - alg = ALG_APMD5; - } - else if (*arg == 's') { - alg = ALG_APSHA; + while ((ch = getopt(argc, argv, "bcdlnmsp")) != -1) { + switch (ch) { + case 'b': + noninteractive++; + args_left++; + break; + case 'c': + newfile++; + break; + case 'd': + alg = ALG_CRYPT; + break; + case 'l': + alg = ALG_APBLF; + break; + case 'n': + nofile++; + args_left--; + break; + case 'm': + alg = ALG_APMD5; + break; + case 's': + alg = ALG_APSHA; + break; + case 'p': + alg = ALG_PLAIN; + break; + default: + usage(); } - else if (*arg == 'p') { - alg = ALG_PLAIN; - } - else if (*arg == 'd') { - alg = ALG_CRYPT; - } - else if (*arg == 'l') { - alg = ALG_APBLF; - } - else if (*arg == 'b') { - noninteractive++; - args_left++; - } - else { - return usage(); - } - } } + argc -= optind; + argv += optind; + i = argc - args_left; + /* * Make sure we still have exactly the right number of arguments left * (the filename, the username, and possibly the password if -b was * specified). */ - if ((argc - i) != args_left) { + if (argc != args_left) { return usage(); } if (newfile && nofile) { |