import local changes from gelbbaer.

fix argument parsing to not crash when arguments are missing.
This commit is contained in:
Enno Rehling 2013-12-26 22:56:59 +01:00
parent 0317a2b61d
commit 6fe246114c
3 changed files with 45 additions and 29 deletions

2
.gitmodules vendored
View File

@ -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

View File

@ -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)

View File

@ -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,24 +107,27 @@ 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);
turn = atoi(arg);
break; break;
case 'q': case 'q':
verbosity = 0; verbosity = 0;
break; break;
case 'v': case 'v':
verbosity = atoi(argv[i][2] ? argv[i]+2 : argv[++i]); i = get_arg(argc, argv, 2, i, &arg, 0);
verbosity = arg ? atoi(arg) : 0xff;
break; break;
case 'h': case 'h':
usage(argv[0], NULL); usage(argv[0], NULL);