+
+int check_options(int argc, char **argv)
+{
+ int ret = 0, r;
+ char *arg;
+
+ while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:", argv, argc, &arg)) != -2)
+ {
+ switch (ret)
+ {
+ case 0:
+ add_listener(arg, control_block.default_proto);
+ break;
+ case '1':
+ control_block.one_shot = 1;
+ control_block.dynamic = 0;
+ break;
+ case 'z':
+ control_block.default_proto = PROTO_Z3950;
+ break;
+ case 's':
+ control_block.default_proto = PROTO_SR;
+ break;
+ case 'S':
+ control_block.dynamic = 0;
+ break;
+ case 'T':
+#if YAZ_POSIX_THREADS
+ control_block.dynamic = 0;
+ control_block.threads = 1;
+#elif YAZ_GNU_THREADS
+ control_block.dynamic = 0;
+ control_block.threads = 1;
+#else
+ fprintf(stderr, "%s: Threaded mode not available.\n", me);
+ return 1;
+#endif
+ break;
+ case 'l':
+ strcpy(control_block.logfile, arg ? arg : "");
+ yaz_log_init(control_block.loglevel, me, control_block.logfile);
+ break;
+ case 'v':
+ control_block.loglevel = yaz_log_mask_str(arg);
+ yaz_log_init(control_block.loglevel, me, control_block.logfile);
+ break;
+ case 'a':
+ strcpy(control_block.apdufile, arg ? arg : "");
+ break;
+ case 'u':
+ strcpy(control_block.setuid, arg ? arg : "");
+ break;
+ case 'c':
+ strcpy(control_block.configname, arg ? arg : "");
+ break;
+ case 'd':
+ strcpy(control_block.daemon_name, arg ? arg : "");
+ break;
+ case 't':
+ if (!arg || !(r = atoi(arg)))
+ {
+ fprintf(stderr, "%s: Specify positive timeout for -t.\n", me);
+ return(1);
+ }
+ control_block.idle_timeout = r;
+ break;
+ case 'k':
+ if (!arg || !(r = atoi(arg)))
+ {
+ fprintf(stderr, "%s: Specify positive size for -k.\n", me);
+ return(1);
+ }
+ control_block.maxrecordsize = r * 1024;
+ break;
+ case 'i':
+ control_block.inetd = 1;
+ break;
+ case 'w':
+ if (chdir(arg))
+ {
+ perror(arg);
+ return 1;
+ }
+ break;
+ default:
+ fprintf(stderr, "Usage: %s [ -a <pdufile> -v <loglevel>"
+ " -l <logfile> -u <user> -c <config> -t <minutes>"
+ " -k <kilobytes> -d <daemon>"
+ " -zsiST -w <directory> <listender-addr>... ]\n", me);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+#ifdef WIN32
+typedef struct _Args
+{
+ char **argv;
+ int argc;
+} Args;
+
+static Args ArgDetails;
+
+/* name of the executable */
+#define SZAPPNAME "server"
+
+/* list of service dependencies - "dep1\0dep2\0\0" */
+#define SZDEPENDENCIES ""
+
+int statserv_main(int argc, char **argv,
+ bend_initresult *(*bend_init)(bend_initrequest *r),
+ void (*bend_close)(void *handle))
+{
+ statserv_options_block *cb = statserv_getcontrol();
+
+ cb->bend_init = bend_init;
+ cb->bend_close = bend_close;
+
+ statserv_setcontrol(cb);
+
+ /* Lets setup the Arg structure */
+ ArgDetails.argc = argc;
+ ArgDetails.argv = argv;
+
+ /* Now setup the service with the service controller */
+ SetupService(argc, argv, &ArgDetails, SZAPPNAME,
+ cb->service_name, /* internal service name */
+ cb->service_name, /* displayed name of the service */
+ SZDEPENDENCIES);
+ return 0;
+}
+
+int StartAppService(void *pHandle, int argc, char **argv)
+{
+ /* Initializes the App */
+ return 1;
+}
+
+void RunAppService(void *pHandle)
+{
+ Args *pArgs = (Args *)pHandle;
+
+ /* Starts the app running */
+ statserv_start(pArgs->argc, pArgs->argv);
+}
+
+void StopAppService(void *pHandle)
+{
+ /* Stops the app */
+ statserv_closedown();
+}
+#else
+int statserv_main(int argc, char **argv,
+ bend_initresult *(*bend_init)(bend_initrequest *r),
+ void (*bend_close)(void *handle))
+{
+ int ret;
+ statserv_options_block *cb = statserv_getcontrol();
+
+ cb->bend_init = bend_init;
+ cb->bend_close = bend_close;
+
+ statserv_setcontrol(cb);
+ ret = statserv_start (argc, argv);
+ statserv_closedown ();
+ return ret;
+}
+#endif