From 56671d969244928663cd0c99f890c668f12fc5e1 Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Sun, 2 Jan 2011 12:27:49 -0500 Subject: --help added, defaulting to CWD when wwwroot not provided --- CHANGELOG | 9 +++++++++ darkhttpd.c | 39 ++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..f5de659 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,9 @@ +# changes made since fork + +01-01-2011: fork starts officially, shttpd is the decided name for "simple http daemon" +01-02-2011: CHANGELOG: CHANGELOG created, format should be M-D-YEAR: MESSAGE +01-02-2011: --help returns usage(); +01-02-2011: when used with no arguments defaults wwwroot directory the CWD + + + diff --git a/darkhttpd.c b/darkhttpd.c index 7d4fd02..902df8c 100644 --- a/darkhttpd.c +++ b/darkhttpd.c @@ -977,7 +977,11 @@ static void usage(void) "\t--pidfile filename (default: no pidfile)\n" "\t\tWrite PID to the specified file. Note that if you are\n" "\t\tusing --chroot, then the pidfile must be relative to,\n" - "\t\tand inside the wwwroot.\n" + "\t\tand inside the wwwroot." + "\n"); + printf( + "\t--help \n" + "\t\tprints this dialogue.\n" "\n"); #ifdef __FreeBSD__ printf( @@ -1012,24 +1016,25 @@ static void parse_commandline(const int argc, char *argv[]) { int i; - if ((argc < 2) || (argc == 2 && strcmp(argv[1], "--help") == 0)) - { - usage(); /* no wwwroot given */ - exit(EXIT_FAILURE); + + if(argc == 2 && strcmp(argv[1], "--help") == 0) { + usage(); + exit(EXIT_FAILURE); } - if (strcmp(argv[1], "--version") == 0) - { - printf("%s " -#ifdef NDEBUG - "-debug" -#else - "+debug" -#endif - "\n", rcsid); - exit(EXIT_FAILURE); + if (argc == 2 && strcmp(argv[1], "--version") == 0) { + printf("%s \n", rcsid); + exit(EXIT_FAILURE); } - - wwwroot = xstrdup(argv[1]); + + if (argc < 2) { + wwwroot = getcwd(NULL, PATH_MAX); + } + else { + wwwroot = xstrdup(argv[1]); + } + + puts(wwwroot); + /* Strip ending slash. */ if (wwwroot[strlen(wwwroot)-1] == '/') wwwroot[strlen(wwwroot)-1] = '\0'; -- cgit v1.2.3