X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fmain-win32.c;h=95c63b66929a92216bcdee987c33c97274b61ab2;hb=HEAD;hp=657f991330abadc7abfac4de1dd863df41c70d7a;hpb=da8cd3de6f2144016e9eeba741a138c6ac2663a7;p=srvx.git diff --git a/src/main-win32.c b/src/main-win32.c index 657f991..95c63b6 100644 --- a/src/main-win32.c +++ b/src/main-win32.c @@ -17,10 +17,91 @@ #include +static int daemon; +static int debug; + +void parse_options(LPSTR args) +{ + const char *replay_file_name; + const char *arg; + char *argv[16]; + unsigned int jj; + unsigned int check_conf; + int argc; + int ii; + + argc = split_line(args, 0, ArrayLength(argv), argv); + if (argc < 1) + return; + + replay_file_name = NULL; + check_conf = 0; + daemon = 1; + for (ii = 0; ii < argc; ++ii) { + arg = argv[ii]; + if ((arg[0] == '/') || (arg[0] == '-' && arg[1] == '-')) { + arg += 1 + (arg[0] == '-' && arg[1] == '-'); + if (!strcmp(arg, "config")) { + } else if (!strcmp(arg, "debug")) { + debug = 1; + } else if (!strcmp(arg, "foreground")) { + daemon = 0; + } else if (!strcmp(arg, "check")) { + check_conf = 1; + } else if (!strcmp(arg, "replay")) { + replay_file_name = argv[++ii]; + } else if (!strcmp(arg, "version")) { + version(); + license(); + exit(0); + } else { + usage("srvx"); + exit(0); + } + } else if (arg[0] == '-') { + for (jj = 1; arg[jj] != '\0'; ++jj) { + switch (arg[jj]) { + case 'c': services_config = argv[++ii]; break; + case 'd': debug = 1; break; + case 'f': daemon = 0; break; + case 'k': check_conf = 1; break; + case 'r': replay_file_name = argv[++ii]; break; + break; + case 'v': + version(); + license(); + exit(0); + default: + usage("srvx"); + exit(0); + } + } + } + } + + if (check_conf) { + if (conf_read(services_config)) { + printf("%s appears to be a valid configuration file.\n", services_config); + } else { + printf("%s is an invalid configuration file.\n", services_config); + } + exit(0); + } + + if (replay_file_name) { + replay_file = fopen(optarg, "r"); + if (!replay_file) { + fprintf(stderr, "Could not open %s for reading: %s (%d)\n", + optarg, strerror(errno), errno); + exit(0); + } + } +} + int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { tools_init(); - /* TODO: parse lpCmdLine */ + parse_options(lpCmdLine); log_module(MAIN_LOG, LOG_INFO, "Initializing daemon..."); if (!conf_read(services_config)) { @@ -35,6 +116,8 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int log_init(); MAIN_LOG = log_register_type("srvx", "file:main.log"); + if (debug) + log_debug(); ioset_init(); init_structs(); init_parse();