Skip to content

Commit

Permalink
change how -c works (include name of the ini file)
Browse files Browse the repository at this point in the history
move rules from [lua] section to [game]

# Conflicts:
#	src/processing.c
  • Loading branch information
ennorehling committed Dec 16, 2024
1 parent d55821a commit 1f54f67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ static void parse_inifile(lua_State * L, const dictionary * d, const char *secti
lua_pushstring(L, "reportpath");
lua_pushstring(L, reportpath());
lua_rawset(L, -3);
arg = config_get("config.rules");
arg = config_get("game.rules");
if (arg) {
lua_pushstring(L, "rules");
lua_pushstring(L, arg);
Expand Down
30 changes: 18 additions & 12 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static const char * valid_keys[] = {
"game.locale",
"game.verbose",
"game.report",
"game.rules",
"game.memcheck",
"game.email",
"game.mailcmd",
Expand All @@ -89,25 +90,30 @@ static const char * valid_keys[] = {
NULL
};

static dictionary * load_config(const char *path)
{
log_debug("reading from configuration file %s\n", path);
return iniparser_load(path);
}

static dictionary *parse_config(const char *filename)
{
dictionary *d;
const char *str, *cfgpath = config_get("config.path");
char path[PATH_MAX];
dictionary *d = NULL;
const char *str;

if (cfgpath) {
char path[PATH_MAX];
path_join(cfgpath, filename, path, sizeof(path));
log_debug("reading from configuration file %s\n", path);
d = iniparser_load(path);
}
else {
log_debug("reading from configuration file %s\n", filename);
d = iniparser_load(filename);
d = load_config(filename);
if (!d) {
path_join(basepath(), filename, path, sizeof(path));
d = load_config(path);
}
if (d) {
config_set_from(d, valid_keys);
load_inifile();
}
else {
log_fatal("could not find eressea.ini");
}
str = config_get("game.locales");
make_locales(str ? str : "de,en");
return d;
Expand Down Expand Up @@ -205,7 +211,7 @@ static int parse_args(int argc, char **argv)
break;
case 'C':
i = get_arg(argc, argv, 2, i, &arg, 0);
config_set("config.path", arg);
inifile = arg;
break;
case 'r':
i = get_arg(argc, argv, 2, i, &arg, 0);
Expand Down
10 changes: 5 additions & 5 deletions tests/eressea.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[game]
rules = e2
name = Eressea
id = 2
email = [email protected]
verbose = 0
locales = de,en
verbose = 0
locales = de,en

[lua]
install = ..
maxnmrs = 20
rules = e2
install = ..
maxnmrs = 20

0 comments on commit 1f54f67

Please sign in to comment.