refactor, improve usage and save the argv0
This commit is contained in:
21
SICSmain.c
21
SICSmain.c
@ -28,6 +28,7 @@
|
||||
|
||||
IPair *pSICSOptions = NULL;
|
||||
pServer pServ = NULL;
|
||||
const char *argv0;
|
||||
|
||||
/* ========================= Less dreadful file statics =================== */
|
||||
|
||||
@ -36,6 +37,8 @@ pServer pServ = NULL;
|
||||
int usage(const char *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;
|
||||
}
|
||||
|
||||
@ -51,19 +54,25 @@ int main(int argc, char *argv[])
|
||||
char *file = NULL;
|
||||
int i, firstArg = 1;
|
||||
|
||||
argv0 = argv[0];
|
||||
if (argc < 2)
|
||||
return usage(argv[0]);
|
||||
|
||||
/* initialise, will die on you if problems */
|
||||
if (strcasecmp(argv[1], "-d") == 0) {
|
||||
daemonize = 1;
|
||||
firstArg = 2;
|
||||
}
|
||||
|
||||
for (i = firstArg; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-nolog") == 0) {
|
||||
SICSLogEnable(0);
|
||||
if (argv[i][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) {
|
||||
file = argv[i];
|
||||
} else {
|
||||
fprintf(stderr, "Unrecognized argument ignored: %s\n", argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user