forked from github/server
allow reading the configuration from a different directory (-c dir).
This commit is contained in:
parent
af73c6dcdf
commit
51207167c8
3 changed files with 3869 additions and 3741 deletions
384
src/laws.c
384
src/laws.c
File diff suppressed because it is too large
Load diff
66
src/main.c
66
src/main.c
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -41,7 +41,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <wctype.h>
|
||||
#include <iniparser.h>
|
||||
|
||||
static const char *logfile= "eressea.log";
|
||||
extern const char *confpath;
|
||||
static const char *logfile = "eressea.log";
|
||||
static const char *luafile = 0;
|
||||
static const char *inifile = "eressea.ini";
|
||||
static int memdebug = 0;
|
||||
|
@ -60,8 +61,9 @@ static void parse_config(const char *filename)
|
|||
#endif
|
||||
/* excerpt from [config] (the rest is used in bindings.c) */
|
||||
game_name = iniparser_getstring(d, "config:game", game_name);
|
||||
} else {
|
||||
log_warning("could not open configuration file %s\n", filename);
|
||||
}
|
||||
else {
|
||||
log_error("could not open configuration file %s\n", filename);
|
||||
}
|
||||
global.inifile = d;
|
||||
}
|
||||
|
@ -83,12 +85,12 @@ static int usage(const char *prog, const char *arg)
|
|||
|
||||
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;
|
||||
*result = argv[index] + len;
|
||||
return index;
|
||||
}
|
||||
if (index+1 < argc) {
|
||||
*result = argv[index+1];
|
||||
return index+1;
|
||||
if (index + 1 < argc) {
|
||||
*result = argv[index + 1];
|
||||
return index + 1;
|
||||
}
|
||||
*result = def;
|
||||
return index;
|
||||
|
@ -101,25 +103,33 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
|||
for (i = 1; i != argc; ++i) {
|
||||
if (argv[i][0] != '-') {
|
||||
luafile = argv[i];
|
||||
} else if (argv[i][1] == '-') { /* long format */
|
||||
}
|
||||
else if (argv[i][1] == '-') { /* long format */
|
||||
if (strcmp(argv[i] + 2, "version") == 0) {
|
||||
printf("\n%s PBEM host\n"
|
||||
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
|
||||
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %d.%d.%d\n\n",
|
||||
global.gamename, VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
|
||||
#ifdef USE_CURSES
|
||||
} else if (strcmp(argv[i] + 2, "color") == 0) {
|
||||
}
|
||||
else if (strcmp(argv[i] + 2, "color") == 0) {
|
||||
/* force the editor to have colors */
|
||||
force_color = 1;
|
||||
#endif
|
||||
} else if (strcmp(argv[i] + 2, "help") == 0) {
|
||||
}
|
||||
else if (strcmp(argv[i] + 2, "help") == 0) {
|
||||
return usage(argv[0], NULL);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return usage(argv[0], argv[i]);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
const char *arg;
|
||||
switch (argv[i][1]) {
|
||||
case 'c':
|
||||
i = get_arg(argc, argv, 2, i, &confpath, 0);
|
||||
break;
|
||||
case 'f':
|
||||
i = get_arg(argc, argv, 2, i, &luafile, 0);
|
||||
break;
|
||||
|
@ -160,13 +170,13 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
|||
log_stderr = LOG_CPERROR;
|
||||
break;
|
||||
case 2:
|
||||
log_stderr = LOG_CPERROR|LOG_CPWARNING;
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING;
|
||||
break;
|
||||
case 3:
|
||||
log_stderr = LOG_CPERROR|LOG_CPWARNING|LOG_CPDEBUG;
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG;
|
||||
break;
|
||||
default:
|
||||
log_stderr = LOG_CPERROR|LOG_CPWARNING|LOG_CPDEBUG|LOG_CPINFO;
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG | LOG_CPINFO;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -241,17 +251,27 @@ extern void bind_monsters(struct lua_State *L);
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int err, result = 0;
|
||||
char inipath[MAX_PATH];
|
||||
int err = 0;
|
||||
lua_State *L;
|
||||
setup_signal_handler();
|
||||
parse_config(inifile);
|
||||
log_open(logfile);
|
||||
|
||||
err = parse_args(argc, argv, &result);
|
||||
if (err) {
|
||||
return result;
|
||||
/* parse args once to read config file location */
|
||||
if (parse_args(argc, argv, &err) != 0) {
|
||||
return err;
|
||||
}
|
||||
/* ini file sets defaults for arguments*/
|
||||
if (confpath) {
|
||||
_snprintf(inipath, sizeof(inipath), "%s/%s", confpath, inifile);
|
||||
parse_config(inipath);
|
||||
}
|
||||
else {
|
||||
parse_config(inifile);
|
||||
}
|
||||
/* parse arguments again, to override ini file */
|
||||
parse_args(argc, argv, &err);
|
||||
|
||||
log_open(logfile);
|
||||
locale_init();
|
||||
|
||||
#ifdef CRTDBG
|
||||
|
|
Loading…
Add table
Reference in a new issue