forked from github/server
import local changes from gelbbaer.
fix argument parsing to not crash when arguments are missing.
This commit is contained in:
parent
0317a2b61d
commit
6fe246114c
|
@ -6,7 +6,7 @@
|
||||||
url = git://github.com/eressea/crypto.git
|
url = git://github.com/eressea/crypto.git
|
||||||
[submodule "cmake"]
|
[submodule "cmake"]
|
||||||
path = cmake
|
path = cmake
|
||||||
url = git://github.com/eressea/cmake.git
|
url = git://github.com/badgerman/cmake.git
|
||||||
[submodule "quicklist"]
|
[submodule "quicklist"]
|
||||||
path = quicklist
|
path = quicklist
|
||||||
url = git://github.com/badgerman/quicklist.git
|
url = git://github.com/badgerman/quicklist.git
|
||||||
|
|
|
@ -20,10 +20,10 @@ find_package (LibXml2 REQUIRED)
|
||||||
find_package (Curses REQUIRED)
|
find_package (Curses REQUIRED)
|
||||||
find_package (SQLite3 REQUIRED)
|
find_package (SQLite3 REQUIRED)
|
||||||
|
|
||||||
|
add_subdirectory (src server)
|
||||||
add_subdirectory (crypto)
|
add_subdirectory (crypto)
|
||||||
add_subdirectory (quicklist)
|
add_subdirectory (quicklist)
|
||||||
add_subdirectory (iniparser)
|
add_subdirectory (iniparser)
|
||||||
add_subdirectory (cutest)
|
add_subdirectory (cutest)
|
||||||
add_subdirectory (critbit)
|
add_subdirectory (critbit)
|
||||||
add_subdirectory (core/src eressea)
|
add_subdirectory (core/src eressea)
|
||||||
add_subdirectory (src server)
|
|
||||||
|
|
70
src/main.c
70
src/main.c
|
@ -72,6 +72,19 @@ static int usage(const char *prog, const char *arg)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_arg(int argc, char **argv, size_t len, int index, const char **result, const char *def) {
|
||||||
|
if (argv[index][len]) {
|
||||||
|
*result = argv[index]+len;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
if (index+1 < argc) {
|
||||||
|
*result = argv[index];
|
||||||
|
return index+1;
|
||||||
|
}
|
||||||
|
*result = def;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_args(int argc, char **argv, int *exitcode)
|
static int parse_args(int argc, char **argv, int *exitcode)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -94,36 +107,39 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
||||||
return usage(argv[0], argv[i]);
|
return usage(argv[0], argv[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const char *arg;
|
||||||
switch (argv[i][1]) {
|
switch (argv[i][1]) {
|
||||||
case 'C':
|
case 'C':
|
||||||
entry_point = NULL;
|
entry_point = NULL;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
logfile = argv[i][2] ? argv[i]+2 : argv[++i];
|
i = get_arg(argc, argv, 2, i, &logfile, 0);
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
entry_point = argv[i][2] ? argv[i]+2 : argv[++i];
|
i = get_arg(argc, argv, 2, i, &entry_point, 0);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
turn = atoi(argv[i][2] ? argv[i]+2 : argv[++i]);
|
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||||
break;
|
turn = atoi(arg);
|
||||||
case 'q':
|
break;
|
||||||
verbosity = 0;
|
case 'q':
|
||||||
break;
|
verbosity = 0;
|
||||||
case 'v':
|
break;
|
||||||
verbosity = atoi(argv[i][2] ? argv[i]+2 : argv[++i]);
|
case 'v':
|
||||||
break;
|
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||||
case 'h':
|
verbosity = arg ? atoi(arg) : 0xff;
|
||||||
usage(argv[0], NULL);
|
break;
|
||||||
return 1;
|
case 'h':
|
||||||
default:
|
usage(argv[0], NULL);
|
||||||
*exitcode = -1;
|
return 1;
|
||||||
usage(argv[0], argv[i]);
|
default:
|
||||||
return 1;
|
*exitcode = -1;
|
||||||
|
usage(argv[0], argv[i]);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (verbosity) {
|
switch (verbosity) {
|
||||||
case 0:
|
case 0:
|
||||||
log_stderr = 0;
|
log_stderr = 0;
|
||||||
|
|
Loading…
Reference in New Issue