diff options
author | Niall O'Higgins <niallo@cvs.openbsd.org> | 2005-03-27 20:35:50 +0000 |
---|---|---|
committer | Niall O'Higgins <niallo@cvs.openbsd.org> | 2005-03-27 20:35:50 +0000 |
commit | 443b3c84aa3e8893d74d84f17cc9bffcd9c52de1 (patch) | |
tree | 3121dab016069822b5a2f85b1716cab2af17c640 | |
parent | d45a6f9e5a698a987f9980221efade27f1b47dd3 (diff) |
- convert to getopt(3)
- add a usage() function that exits non-zero
ok henning@ otto@
-rw-r--r-- | usr.sbin/httpd/src/support/logresolve.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/usr.sbin/httpd/src/support/logresolve.c b/usr.sbin/httpd/src/support/logresolve.c index 21950a2024e..9223043494d 100644 --- a/usr.sbin/httpd/src/support/logresolve.c +++ b/usr.sbin/httpd/src/support/logresolve.c @@ -49,6 +49,7 @@ static void cgethost(struct in_addr ipnum, char *string, int check); static int getline(char *s, int n); static void stats(FILE *output); +static void usage(void); /* maximum line length */ @@ -253,31 +254,39 @@ static int getline (char *s, int n) return (1); } +static void usage(void) +{ + fprintf(stderr, "Usage: logresolve [-s statfile] [-c]"); + fprintf(stderr, " < input > output\n"); + exit(1); +} + int main (int argc, char *argv[]) { struct in_addr ipnum; char *bar, hoststring[MAXDNAME + 1], line[MAXLINE], *statfile; int i, check; + int ch; check = 0; statfile = NULL; - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-c") == 0) - check = 1; - else if (strcmp(argv[i], "-s") == 0) { - if (i == argc - 1) { - fprintf(stderr, "logresolve: missing filename to -s\n"); - exit(1); - } - i++; - statfile = argv[i]; - } - else { - fprintf(stderr, "Usage: logresolve [-s statfile] [-c] < input > output\n"); - exit(0); - } + while ((ch = getopt(argc, argv, "s:c")) != -1) { + switch (ch) { + case 'c': + check = 1; + break; + case 's': + statfile = optarg; + break; + default: + usage(); + } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); for (i = 0; i < BUCKETS; i++) nscache[i] = NULL; |