--- src/didi.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/didi.h | 1 src/wiki.c | 31 ++++++++++++++++++------------ src/wiki.h | 2 - src/wikitext.h | 6 ++--- 5 files changed, 78 insertions(+), 20 deletions(-) Index: didiwiki/src/didi.c =================================================================== --- didiwiki.orig/src/didi.c +++ didiwiki/src/didi.c @@ -1,5 +1,7 @@ #include "didi.h" +static int debug; + void usage(char *progname) { @@ -11,13 +13,61 @@ { HttpRequest *req = NULL; int port = 8000; + int c; + char *didiwiki_home = NULL; - wiki_init(); + debug = 0; - if(argc > 1 && !strcmp(argv[1],"debug")) - req = http_request_new(); /* reads request from stdin */ - else + while (1) + { + static struct option long_options[] = + { + {"debug", no_argument, 0, 'd'}, + {"port", required_argument, 0, 'p'}, + {"home", required_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + /* getopt_long stores the option index here */ + int option_index = 0; + + c = getopt_long (argc, argv, "dp:h:", long_options, &option_index); + + /* detect the end of the options */ + if (c == -1) + break; + + switch (c) + { + case 0: + break; + + case 'd': + debug = 1; + break; + + case 'p': + port = atoi(optarg); + break; + + case 'h': + didiwiki_home = optarg; + break; + + default: + abort (); + } + } + + wiki_init(didiwiki_home); + + if (debug) + { + req = http_request_new(); /* reads request from stdin */ + } + else { req = http_server(port); /* forks here */ + } wiki_handle_http_request(req); Index: didiwiki/src/didi.h =================================================================== --- didiwiki.orig/src/didi.h +++ didiwiki/src/didi.h @@ -75,6 +75,7 @@ #include #include #include +#include #endif Index: didiwiki/src/wiki.c =================================================================== --- didiwiki.orig/src/wiki.c +++ didiwiki/src/wiki.c @@ -1078,26 +1078,33 @@ } int -wiki_init(void) +wiki_init(char *didiwiki_home) { char datadir[512] = { 0 }; - struct stat st; + struct stat st; - if (getenv("DIDIWIKIHOME")) + if (didiwiki_home) { - snprintf(datadir, 512, getenv("DIDIWIKIHOME")); + snprintf(datadir, 512, "%s", didiwiki_home); } - else + else { - if (getenv("HOME") == NULL) + if (getenv("DIDIWIKIHOME")) { - fprintf(stderr, "Unable to get home directory, is HOME set?\n"); - exit(1); + snprintf(datadir, 512, "%s", getenv("DIDIWIKIHOME")); } - - snprintf(datadir, 512, "%s/.didiwiki", getenv("HOME")); - } - + else + { + if (getenv("HOME") == NULL) + { + fprintf(stderr, "Unable to get home directory, is HOME set?\n"); + exit(1); + } + + snprintf(datadir, 512, "%s/.didiwiki", getenv("HOME")); + } + } + /* Check if ~/.didiwiki exists and create if not */ if (stat(datadir, &st) != 0 ) { Index: didiwiki/src/wiki.h =================================================================== --- didiwiki.orig/src/wiki.h +++ didiwiki/src/wiki.h @@ -22,7 +22,7 @@ wiki_print_data_as_html(HttpResponse *res, char *raw_page_data); int -wiki_init(void); +wiki_init(char *didiwiki_home); #endif Index: didiwiki/src/wikitext.h =================================================================== --- didiwiki.orig/src/wikitext.h +++ didiwiki/src/wikitext.h @@ -70,13 +70,13 @@ \ "==Welcome to !DidiWiki\n" \ "/!DidiWiki / is a small and simple [http://en.wikipedia.org/wiki/Wiki WikiWikiWeb]\n" \ -"Implementaion. Its intended for personal note taking, Todo lists and any other uses you can think of.\n" \ +"implementation. It's intended for personal note-taking, \"to do\" lists, and any other uses you can think of.\n" \ "\n" \ "To learn more about what a [http://www.c2.com/cgi/wiki?WikiWikiWeb WikiWikiWeb] is, read about [http://www.c2.com/cgi/wiki?WhyWikiWorks WhyWikiWorks] and the [http://www.c2.com/cgi/wiki?WikiNature WikiNature]. Also, consult the [http://www.c2.com/cgi/wiki?WikiWikiWebFaq WikiWikiWebFaq].\n" \ "\n" \ -"For an example how a !WikiWiki entry looks in text form you can [?edit edit] this page. Also see WikiHelp for infomation on usage and formatting rules. Use The WikiSandbox to experiment.\n" \ +"For an example of how a !DidiWiki entry looks in text form you can [?edit edit] this page. Also see WikiHelp for infomation on usage and formatting rules. Use The WikiSandbox to experiment.\n" \ "\n" \ -"/!DidiWiki / is written by [mailto://mallum@o-hand.com Matthew Allum] in C and is free software, released under the [http://www.gnu.org GNU] [http://www.gnu.org/copyleft/gpl.html GPL]. It uses a formatting style similar to that of [http://www.kwiki.org kwiki] and some webserver code from [http://www.cvstrac.org cvstrac]\n" +"/!DidiWiki / is written by [mailto://mallum@o-hand.com Matthew Allum] in C and is free software, released under the [http://www.gnu.org GNU] [http://www.gnu.org/copyleft/gpl.html GPL]. It uses a formatting style similar to that of [http://www.kwiki.org kwiki] and some webserver code from [http://www.cvstrac.org cvstrac].\n" #define HELPTEXT "" \