Fix command line argument processing (issue #516)

This commit is contained in:
o9000 2015-08-03 18:34:12 +02:00 committed by Ovidiu Mara
parent 8eca71ac95
commit ed24d0bd4c

View file

@ -123,23 +123,35 @@ void init (int argc, char *argv[])
// read options // read options
for (i = 1; i < argc; ++i) { for (i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { int error = 0;
printf("Usage: tint2 [-c] <config_file>\n"); if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
printf("Usage: tint2 [[-c] <config_file>]\n");
exit(0); exit(0);
} } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
printf("tint2 version %s\n", VERSION_STRING); printf("tint2 version %s\n", VERSION_STRING);
exit(0); exit(0);
} } else if (strcmp(argv[i], "-c") == 0) {
if (!strcmp(argv[i], "-c")) { if (i+1 < argc) {
i++; i++;
if (i < argc)
config_path = strdup(argv[i]); config_path = strdup(argv[i]);
} } else {
if (!strcmp(argv[i], "-s")) { error = 1;
i++; }
if (i < argc) } else if (strcmp(argv[i], "-s") == 0) {
if (i+1 < argc) {
i++;
snapshot_path = strdup(argv[i]); snapshot_path = strdup(argv[i]);
} else {
error = 1;
}
} else if (i+1 == argc) {
config_path = strdup(argv[i]);
} else {
error = 1;
}
if (error) {
printf("Usage: tint2 [[-c] <config_file>]\n");
exit(1);
} }
} }
// Set signal handler // Set signal handler