diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-11-08 12:24:23 -0500 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-11-08 12:24:23 -0500 |
commit | 91ac4dd03f4130e5e416d495d53237b74a37efc1 (patch) | |
tree | 7ad67c3dbee7735f8542303de5582adb2f7607b6 /src/c | |
parent | 7d6eed032a2b129056ff264a91076cec68035a34 (diff) |
Add help text for generated web servers
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/driver.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/c/driver.c b/src/c/driver.c index 3c750d67..49537614 100644 --- a/src/c/driver.c +++ b/src/c/driver.c @@ -292,6 +292,10 @@ static void *worker(void *data) { } } +static void help(char *cmd) { + printf("Usage: %s [-p <port>] [-t <thread-count>]\n", cmd); +} + int main(int argc, char *argv[]) { // The skeleton for this function comes from Beej's sockets tutorial. int sockfd; // listen on sock_fd @@ -300,16 +304,22 @@ int main(int argc, char *argv[]) { int sin_size, yes = 1; int uw_port = 8080, nthreads = 1, i, *names, opt; - while ((opt = getopt(argc, argv, "p:t:")) != -1) { + while ((opt = getopt(argc, argv, "hp:t:")) != -1) { switch (opt) { case '?': fprintf(stderr, "Unknown command-line option"); + help(argv[0]); return 1; + case 'h': + help(argv[0]); + return 0; + case 'p': uw_port = atoi(optarg); if (uw_port <= 0) { fprintf(stderr, "Invalid port number\n"); + help(argv[0]); return 1; } break; @@ -318,6 +328,7 @@ int main(int argc, char *argv[]) { nthreads = atoi(optarg); if (nthreads <= 0) { fprintf(stderr, "Invalid thread count\n"); + help(argv[0]); return 1; } break; |