From afd41286b514225193709a5d01f7fd61d47c6df9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 3 Aug 2014 20:37:05 +0200 Subject: [PATCH] config file reading based on game name and install location. --- conf/eressea.ini | 8 +++++--- doc/LICENSE | 15 +++++++++++++++ eressea.ini | 16 ---------------- scripts/run-turn.lua | 26 +++++++++++++++++++++----- src/bindings.c | 8 +------- src/kernel/config.c | 5 +---- src/kernel/config.h | 1 - src/laws.c | 33 +++------------------------------ src/log.pkg | 4 ++-- src/log.pkg.c | 31 +++++++++++++++++++++++++++++-- src/main.c | 9 --------- 11 files changed, 77 insertions(+), 79 deletions(-) create mode 100644 doc/LICENSE delete mode 100644 eressea.ini diff --git a/conf/eressea.ini b/conf/eressea.ini index 7ac09f4c8..6834005cc 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -6,11 +6,13 @@ lomem = 0 debug = 0 memcheck = 0 locales = de,en +;game_id = 0 -[config] -source_dir = ../git +[lua] +install = ../git +paths = ../git/lunit:../git/scripts maxnmrs = 20 -rules = eressea ; use -r to override +rules = e2 ; can use -r to override [editor] color = 1 diff --git a/doc/LICENSE b/doc/LICENSE new file mode 100644 index 000000000..00ab17b3d --- /dev/null +++ b/doc/LICENSE @@ -0,0 +1,15 @@ +Copyright (c) 1998-2010, Enno Rehling + Katja Zedel + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/eressea.ini b/eressea.ini deleted file mode 100644 index 1377293a8..000000000 --- a/eressea.ini +++ /dev/null @@ -1,16 +0,0 @@ -[eressea] -base = . -report = reports -verbose = 0 -lomem = 0 -debug = 0 -memcheck = 0 -locales = de,en - -[config] -paths = lunit -install = . -maxnmrs = 10 - -[editor] -color = 1 diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 98fafe673..efeda7ea4 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -181,13 +181,29 @@ function run_turn(rules) return result end -path = 'scripts' -if config.source_dir ~= nil then - path = config.source_dir .. '/' .. path +local confdir = 'conf/' + +if config.rules then + confdir = confdir .. config.rules .. '/' +end +if config.install then + confdir = config.install .. '/' .. confdir +end +read_xml(confdir .. 'config.xml', confdir .. 'catalog.xml') + +local path = 'scripts' +if config.install then + path = config.install .. '/' .. path end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' -rules = require('eressea.' .. config.rules) -read_xml() +require 'eressea' +local rules = {} +if config.rules then + rules = require('eressea.' .. config.rules) + eressea.log.info('loaded ' .. table.getn(rules) .. ' modules for ' .. config.rules) +else + eressea.log.warning('no rule modules loaded, specify a game in eressea.ini or with -r') +end run_turn(rules) diff --git a/src/bindings.c b/src/bindings.c index c5f927b84..71604ac8d 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1116,7 +1116,7 @@ int tolua_bindings_open(lua_State * L) tolua_module(L, TOLUA_CAST "config", 1); tolua_beginmodule(L, TOLUA_CAST "config"); { - parse_inifile(L, global.inifile, "config"); + parse_inifile(L, global.inifile, "lua"); tolua_variable(L, TOLUA_CAST "locales", &config_get_locales, 0); tolua_function(L, TOLUA_CAST "get_resource", &config_get_resource); tolua_variable(L, TOLUA_CAST "buildings", &config_get_buildings, 0); @@ -1222,12 +1222,6 @@ int eressea_run(lua_State *L, const char *luafile) global.vm_state = L; /* run the main script */ if (luafile) { - const char * install = iniparser_getstring(global.inifile, "eressea:install", 0); - char path[MAX_PATH]; - if (install) { - _snprintf(path, sizeof(path), "%s/%s", install, luafile); - luafile = path; - } log_debug("executing script %s\n", luafile); lua_getglobal(L, "debug"); diff --git a/src/kernel/config.c b/src/kernel/config.c index 5d471f72b..d45c66852 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -2922,7 +2922,7 @@ const char * game_name(void) { } int game_id(void) { - return get_param_int(global.parameters, "game.id", global.game_id); + return get_param_int(global.parameters, "game.id", 0); } void load_inifile(dictionary * d) @@ -2960,9 +2960,6 @@ void load_inifile(dictionary * d) str = iniparser_getstring(d, "eressea:locales", "de,en"); make_locales(str); - /* excerpt from [config] (the rest is used in bindings.c) */ - global.game_id = iniparser_getint(d, "config:game_id", 0); - if (global.inifile) iniparser_free(global.inifile); global.inifile = d; } diff --git a/src/kernel/config.h b/src/kernel/config.h index 958beef42..352c9dcb6 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -372,7 +372,6 @@ extern "C" { void *vm_state; float producexpchance; int cookie; - int game_id; int data_version; /* TODO: eliminate in favor of gamedata.version */ struct _dictionary_ *inifile; diff --git a/src/laws.c b/src/laws.c index 8e30c76dd..f8ad2a153 100755 --- a/src/laws.c +++ b/src/laws.c @@ -4796,41 +4796,14 @@ void update_subscriptions(void) fclose(F); } -const char *confpath = 0; - int init_data(const char *filename, const char *catalog) { - const char * install = iniparser_getstring(global.inifile, "eressea:install", 0); - char filepath[MAX_PATH], catpath[MAX_PATH]; int l; - - if (install || confpath) { - if (install && confpath) { - _snprintf(filepath, sizeof(filepath), "%s/%s/", install, confpath); - _snprintf(catpath, sizeof(catpath), "%s/%s/", install, confpath); - } - else if (confpath) { - _snprintf(filepath, sizeof(filepath), "%s/", confpath); - _snprintf(catpath, sizeof(catpath), "%s/", confpath); - } - else if (install) { - _snprintf(filepath, sizeof(filepath), "%s/", install); - _snprintf(catpath, sizeof(catpath), "%s/", install); - } - if (filename) { - strncat(filepath, filename, sizeof(filepath)); - filename = filepath; - } - if (catalog) { - strncat(catpath, catalog, sizeof(catpath)); - catalog = catpath; - } - } l = read_xml(filename, catalog); - init_locales(); - if (l) + if (l) { return l; - + } + init_locales(); if (turn < 0) { turn = first_turn; } diff --git a/src/log.pkg b/src/log.pkg index 08d004e28..c198aed03 100644 --- a/src/log.pkg +++ b/src/log.pkg @@ -2,9 +2,9 @@ $#include module eressea { module log { - void log_error @ error(const char *message); + void log_error_n @ error(const char *message); void log_debug @ debug(const char *message); void log_warning @ warning(const char *message); + void log_info @ info(const char *message); } } - diff --git a/src/log.pkg.c b/src/log.pkg.c index 8504720b3..6afada3f8 100644 --- a/src/log.pkg.c +++ b/src/log.pkg.c @@ -40,7 +40,7 @@ static int tolua_log_eressea_log_error00(lua_State* tolua_S) { const char* message = ((const char*) tolua_tostring(tolua_S,1,0)); { - log_error(message); + log_error_n(message); } } return 0; @@ -103,6 +103,32 @@ static int tolua_log_eressea_log_debug00(lua_State* tolua_S) #endif } +/* function: log_info */ +static int tolua_log_eressea_log_info00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isstring(tolua_S, 1, 0, &tolua_err) || + !tolua_isnoobj(tolua_S, 2, &tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const char* message = ((const char*)tolua_tostring(tolua_S, 1, 0)); + { + log_info(message); + } + } + return 0; +#ifndef TOLUA_RELEASE +tolua_lerror : + tolua_error(tolua_S, "#ferror in function 'info'.", &tolua_err); + return 0; +#endif +} + /* Open lib function */ LUALIB_API int luaopen_log (lua_State* tolua_S) { @@ -116,7 +142,8 @@ LUALIB_API int luaopen_log (lua_State* tolua_S) tolua_beginmodule(tolua_S,"log"); tolua_function(tolua_S,"error",tolua_log_eressea_log_error00); tolua_function(tolua_S,"warning",tolua_log_eressea_log_warning00); - tolua_function(tolua_S,"debug",tolua_log_eressea_log_debug00); + tolua_function(tolua_S, "debug",tolua_log_eressea_log_debug00); + tolua_function(tolua_S, "info",tolua_log_eressea_log_info00); tolua_endmodule(tolua_S); tolua_endmodule(tolua_S); tolua_endmodule(tolua_S); diff --git a/src/main.c b/src/main.c index 1b941b41c..a14be8040 100644 --- a/src/main.c +++ b/src/main.c @@ -41,7 +41,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -extern const char *confpath; static const char *logfile = "eressea.log"; static const char *luafile = 0; static const char *inifile = "eressea.ini"; @@ -125,9 +124,6 @@ static int parse_args(int argc, char **argv, int *exitcode) i = get_arg(argc, argv, 2, i, &arg, 0); set_param(&global.parameters, "config.rules", arg); break; - case 'c': - i = get_arg(argc, argv, 2, i, &confpath, 0); - break; case 'f': i = get_arg(argc, argv, 2, i, &luafile, 0); break; @@ -245,7 +241,6 @@ extern void bind_monsters(struct lua_State *L); int main(int argc, char **argv) { - char inipath[MAX_PATH]; int err = 0; lua_State *L; setup_signal_handler(); @@ -256,10 +251,6 @@ int main(int argc, char **argv) } /* ini file sets defaults for arguments*/ parse_config(inifile); - if (!global.inifile && confpath) { - _snprintf(inipath, sizeof(inipath), "%s/%s", confpath, inifile); - parse_config(inipath); - } if (!global.inifile) { log_error("could not open ini configuration %s\n", inifile); }