From e5c95f1501a7800eed9ac1f113058715671b7221 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 7 Feb 2017 10:39:54 +0100 Subject: [PATCH 1/6] avoid division by zero when no calendar is configured --- src/kernel/xmlreader.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 6491daf20..d89259317 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -361,7 +361,6 @@ static int parse_calendar(xmlDocPtr doc) xpathCalendars = xmlXPathEvalExpression(BAD_CAST "/eressea/calendar", xpath); nsetCalendars = xpathCalendars->nodesetval; - months_per_year = 0; if (nsetCalendars != NULL && nsetCalendars->nodeNr != 0) { int c; for (c = 0; c != nsetCalendars->nodeNr; ++c) { From 17ff2ead416576937212d7ccb140a2d41e389a64 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 05:52:46 +0100 Subject: [PATCH 2/6] make_locales from config_get --- clibs | 2 +- src/kernel/xmlreader.c | 4 ---- src/main.c | 6 +++--- src/util/language.c | 6 +++--- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/clibs b/clibs index 27c8b3202..f91ef37f0 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 +Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index d89259317..5ce6800ef 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -66,10 +66,6 @@ static void xml_readtext(xmlNodePtr node, struct locale **lang, xmlChar ** text) xmlChar *propValue = xmlGetProp(node, BAD_CAST "locale"); assert(propValue != NULL); *lang = get_locale((const char *)propValue); -#ifdef MAKE_LOCALES - if (*lang == NULL) - *lang = get_or_create_locale((const char *)propValue); -#endif xmlFree(propValue); *text = xmlNodeListGetString(node->doc, node->children, 1); diff --git a/src/main.c b/src/main.c index a3bcdb866..875a33bf9 100644 --- a/src/main.c +++ b/src/main.c @@ -70,15 +70,13 @@ static void load_inifile(dictionary * d) lomem = iniparser_getint(d, "game:lomem", lomem) ? 1 : 0; verbosity = iniparser_getint(d, "game:verbose", 2); - str = iniparser_getstring(d, "game:locales", "de,en"); - make_locales(str); } static dictionary *parse_config(const char *filename) { char path[MAX_PATH]; dictionary *d; - const char *cfgpath = config_get("config.path"); + const char *str, *cfgpath = config_get("config.path"); if (cfgpath) { join_path(cfgpath, filename, path, sizeof(path)); @@ -99,6 +97,8 @@ static dictionary *parse_config(const char *filename) gm_codepage = iniparser_getint(d, "editor:codepage", gm_codepage); #endif } + str = config_get("game.locales"); + make_locales(str ? str : "de,en"); return d; } diff --git a/src/util/language.c b/src/util/language.c index 86a6895be..3f628036d 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -327,10 +327,10 @@ static int locale_init = 0; void init_locales(void) { - int l; + locale * lang; if (locale_init) return; - for (l = 0; localenames[l]; ++l) { - struct locale *lang = get_or_create_locale(localenames[l]); + assert(locales); + for (lang = locales; lang; lang = lang->next) { init_locale(lang); } locale_init = 1; From 6893248473d740557197b2f4d5405c5197f84c6f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 06:06:33 +0100 Subject: [PATCH 3/6] jsonconf should not need to create locales --- src/kernel/jsonconf.c | 8 ++++---- src/kernel/jsonconf.test.c | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 7a074a410..89219665e 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -654,7 +654,7 @@ static void json_strings(cJSON *json) { } for (child = json->child; child; child = child->next) { if (child->type == cJSON_Object) { - struct locale *lang = get_or_create_locale(child->string); + struct locale *lang = get_locale(child->string); json_locale(child, lang); } else { @@ -695,7 +695,7 @@ static void json_directions(cJSON *json) { return; } for (child = json->child; child; child = child->next) { - struct locale * lang = get_or_create_locale(child->string); + struct locale * lang = get_locale(child->string); json_direction(child, lang); } } @@ -771,7 +771,7 @@ static void json_skills(cJSON *json) { return; } for (child = json->child; child; child = child->next) { - struct locale * lang = get_or_create_locale(child->string); + struct locale * lang = get_locale(child->string); json_skill(child, lang); } } @@ -783,7 +783,7 @@ static void json_keywords(cJSON *json) { return; } for (child = json->child; child; child = child->next) { - struct locale * lang = get_or_create_locale(child->string); + struct locale * lang = get_locale(child->string); json_keyword(child, lang); } } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 7c591f075..abf64e7d5 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -600,9 +600,10 @@ static void test_infinitive_from_config(CuTest *tc) { cJSON *json = cJSON_Parse(data); CuAssertPtrNotNull(tc, json); + test_setup(); + lang = get_or_create_locale("de"); json_config(json); - lang = get_or_create_locale("de"); CuAssertIntEquals(tc, K_STUDY, get_keyword("LERN", lang)); CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNE", lang)); CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNEN", lang)); From ac8250ecd85b1cb31c2164b236abf867a542975e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 06:14:29 +0100 Subject: [PATCH 4/6] remove global read_orders binding --- src/bindings.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index 2e4ed3dc6..21f2aad58 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -223,14 +223,6 @@ static int tolua_rng_int(lua_State * L) return 1; } -static int tolua_read_orders(lua_State * L) -{ - const char *filename = tolua_tostring(L, 1, 0); - int result = readorders(filename); - lua_pushinteger(L, result); - return 1; -} - static int tolua_message_unit(lua_State * L) { unit *sender = (unit *)tolua_tousertype(L, 1, 0); @@ -1072,8 +1064,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "factions", tolua_get_factions); tolua_function(L, TOLUA_CAST "regions", tolua_get_regions); tolua_function(L, TOLUA_CAST "read_turn", tolua_read_turn); -// tolua_function(L, TOLUA_CAST "write_map", &tolua_write_map); - tolua_function(L, TOLUA_CAST "read_orders", tolua_read_orders); tolua_function(L, TOLUA_CAST "process_orders", tolua_process_orders); tolua_function(L, TOLUA_CAST "init_reports", tolua_init_reports); tolua_function(L, TOLUA_CAST "write_reports", tolua_write_reports); From 75514014bc7769963d82cb7e8368118b6cbcf654 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 06:20:37 +0100 Subject: [PATCH 5/6] no need to create locale here --- src/reports.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reports.c b/src/reports.c index 318660024..f904f5799 100644 --- a/src/reports.c +++ b/src/reports.c @@ -157,7 +157,7 @@ size_t report_status(const unit * u, const struct locale *lang, char *fsbuf, siz if (!status) { const char *lname = locale_name(lang); - struct locale *wloc = get_or_create_locale(lname); + struct locale *wloc = get_locale(lname); log_warning("no translation for combat status %s in %s", combatstatus[u->status], lname); locale_setstring(wloc, combatstatus[u->status], combatstatus[u->status]+7); len = strlcpy(fsbuf, combatstatus[u->status]+7, buflen); From a4bd4320e538db848d2e523ebc110e0ad84fc007 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 06:24:25 +0100 Subject: [PATCH 6/6] fix bad read_orders call --- scripts/run-turn.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 92efa8a14..9118ed8ee 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -146,7 +146,7 @@ function process(rules, orders) init_summary() -- run the turn: - if read_orders(orders) ~= 0 then + if eressea.read_orders(orders) ~= 0 then print("could not read " .. orders) return -1 end