diff options
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/server.c b/server.c index c384020..0ed1c9c 100644 --- a/server.c +++ b/server.c @@ -77,25 +77,38 @@ static enum kcgi_err dispatch(struct kreq *req) { } } +#define ENV "SCOOPER_" + int main(int argc, char *argv[]) { + const char *path = NULL; bool test = false; + const char *val; + if ((val = getenv(ENV "DATABASE"))) path = val; + if ((val = getenv(ENV "GAP"))) eventsGap = strtol(val, NULL, 10); + if ((val = getenv(ENV "LIMIT"))) eventsLimit = strtol(val, NULL, 10); + if ((val = getenv(ENV "OVERLAP"))) eventsOverlap = strtol(val, NULL, 10); + if ((val = getenv(ENV "PUBLIC"))) contextsPublic = (val[0] != '0'); + if ((val = getenv(ENV "RECENT"))) contextsRecent = strtol(val, NULL, 10); + if ((val = getenv(ENV "STYLESHEET"))) htmlStylesheet = val; + for (int opt; 0 < (opt = getopt(argc, argv, "cg:l:o:pr:s:"));) { switch (opt) { - break; case 'g': eventsGap = strtol(optarg, NULL, 10); - break; case 'o': eventsOverlap = strtol(optarg, NULL, 10); break; case 'c': test = true; + break; case 'g': eventsGap = strtol(optarg, NULL, 10); break; case 'l': eventsLimit = strtol(optarg, NULL, 10); + break; case 'o': eventsOverlap = strtol(optarg, NULL, 10); break; case 'p': contextsPublic = true; break; case 'r': contextsRecent = strtol(optarg, NULL, 10); break; case 's': htmlStylesheet = optarg; break; default: return EX_USAGE; } } - if (optind == argc) errx(EX_USAGE, "database path required"); + if (optind < argc) path = argv[optind]; + if (!path) errx(EX_USAGE, "database path required"); - int error = sqlite3_open_v2(argv[optind], &db, SQLITE_OPEN_READONLY, NULL); - if (error) errx(EX_NOINPUT, "%s: %s", argv[optind], sqlite3_errmsg(db)); + int error = sqlite3_open_v2(path, &db, SQLITE_OPEN_READONLY, NULL); + if (error) errx(EX_NOINPUT, "%s: %s", path, sqlite3_errmsg(db)); atexit(finalizeAll); sqlite3_stmt *check; |