refactor, improve usage and save the argv0

This commit is contained in:
Douglas Clowes
2012-12-10 14:51:29 +11:00
parent d2bcea11b2
commit 9534ba4b31

View File

@ -28,6 +28,7 @@
IPair *pSICSOptions = NULL; IPair *pSICSOptions = NULL;
pServer pServ = NULL; pServer pServ = NULL;
const char *argv0;
/* ========================= Less dreadful file statics =================== */ /* ========================= Less dreadful file statics =================== */
@ -36,6 +37,8 @@ pServer pServ = NULL;
int usage(const char *name) int usage(const char *name)
{ {
fprintf(stderr, "usage: %s [-d] [-nolog] <config.tcl>\n", name); fprintf(stderr, "usage: %s [-d] [-nolog] <config.tcl>\n", name);
fprintf(stderr, " -d: daemonize the process\n");
fprintf(stderr, " -nolog: disable log file writing\n");
return 1; return 1;
} }
@ -51,19 +54,25 @@ int main(int argc, char *argv[])
char *file = NULL; char *file = NULL;
int i, firstArg = 1; int i, firstArg = 1;
argv0 = argv[0];
if (argc < 2) if (argc < 2)
return usage(argv[0]); return usage(argv[0]);
/* initialise, will die on you if problems */ /* initialise, will die on you if problems */
if (strcasecmp(argv[1], "-d") == 0) {
daemonize = 1;
firstArg = 2;
}
for (i = firstArg; i < argc; i++) { for (i = firstArg; i < argc; i++) {
if (strcmp(argv[i], "-nolog") == 0) { if (argv[i][0] == '-') {
SICSLogEnable(0); if (strcasecmp(argv[i], "-nolog") == 0) {
SICSLogEnable(0);
} else if (strcasecmp(argv[i], "-d") == 0) {
daemonize = 1;
} else {
fprintf(stderr, "Unrecognized option ignored: %s\n", argv[i]);
}
} else if (file == NULL) { } else if (file == NULL) {
file = argv[i]; file = argv[i];
} else {
fprintf(stderr, "Unrecognized argument ignored: %s\n", argv[i]);
} }
} }