diff --git a/src/kernel/config.c b/src/kernel/config.c index c2db29f22..109913560 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -213,6 +213,27 @@ param_t findparam(const char *s, const struct locale * lang) return result; } +param_t findparam_block(const char *s, const struct locale *lang, bool any_locale) +{ + param_t p; + if (!s || s[0] == '@') { + return NOPARAM; + } + p = findparam(s, lang); + if (any_locale && p==NOPARAM) { + const struct locale *loc; + for (loc=locales;loc;loc=nextlocale(loc)) { + if (loc!=lang) { + p = findparam(s, loc); + if (p==P_FACTION || p==P_GAMENAME) { + break; + } + } + } + } + return p; +} + param_t findparam_ex(const char *s, const struct locale * lang) { param_t result = findparam(s, lang); diff --git a/src/kernel/config.h b/src/kernel/config.h index 43189400c..b51ba2725 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -45,6 +45,7 @@ extern "C" { int findoption(const char *s, const struct locale *lang); param_t findparam(const char *s, const struct locale *lang); + param_t findparam_block(const char *s, const struct locale *lang, bool any_locale); param_t findparam_ex(const char *s, const struct locale * lang); bool isparam(const char *s, const struct locale * lang, param_t param); param_t getparam(const struct locale *lang); diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index ca362d6a1..72b2387ac 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -251,9 +251,33 @@ static void test_config_inifile(CuTest *tc) { test_cleanup(); } +static void test_findparam(CuTest *tc) { + struct locale *en, *de; + test_setup(); + en = get_or_create_locale("en"); + locale_setstring(en, parameters[P_FACTION], "FACTION"); + CuAssertIntEquals(tc, NOPARAM, findparam("FACTION", en)); + init_parameters(en); + CuAssertIntEquals(tc, P_FACTION, findparam("FACTION", en)); + de = get_or_create_locale("de"); + locale_setstring(de, parameters[P_FACTION], "PARTEI"); + CuAssertIntEquals(tc, NOPARAM, findparam("PARTEI", de)); + init_parameters(de); + CuAssertIntEquals(tc, P_FACTION, findparam("PARTEI", de)); + CuAssertIntEquals(tc, NOPARAM, findparam("HODOR", de)); + + CuAssertIntEquals(tc, NOPARAM, findparam("PARTEI", en)); + CuAssertIntEquals(tc, NOPARAM, findparam_block("HODOR", de, false)); + CuAssertIntEquals(tc, P_FACTION, findparam_block("PARTEI", de, true)); + CuAssertIntEquals(tc, NOPARAM, findparam_block("PARTEI", en, false)); + CuAssertIntEquals(tc, P_FACTION, findparam_block("PARTEI", en, true)); + test_cleanup(); +} + CuSuite *get_config_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_findparam); SUITE_ADD_TEST(suite, test_config_inifile); SUITE_ADD_TEST(suite, test_config_cache); SUITE_ADD_TEST(suite, test_get_set_param); diff --git a/src/kernel/save.c b/src/kernel/save.c index be461e27c..ac236d5bf 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -252,26 +252,6 @@ static faction *factionorders(void) return f; } -static param_t next_param(const char *s, const struct locale *lang) { - param_t p; - if (!s || s[0] == '@') { - return NOPARAM; - } - p = findparam(s, lang); - if (p==NOPARAM) { - const struct locale *loc; - for (loc=locales;loc;loc=nextlocale(loc)) { - if (loc!=lang) { - p = findparam(s, lang); - if (p==P_FACTION || p==P_GAMENAME) { - break; - } - } - } - } - return p; -} - int readorders(const char *filename) { FILE *F = NULL; @@ -299,7 +279,7 @@ int readorders(const char *filename) const char *s; init_tokens_str(b); s = gettoken(token, sizeof(token)); - p = next_param(s, lang); + p = findparam_block(s, lang, true); switch (p) { case P_GAMENAME: case P_FACTION: diff --git a/src/util/language.c b/src/util/language.c index efd5cd5f7..300e69103 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -295,10 +295,11 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_ // TODO: swap the name of s and key const char * s = string_cb(i); if (s) { - struct critbit_tree ** cb = (struct critbit_tree **)tokens; const char * key = locale_string(lang, s, false); - if (!key) key = s; - add_translation(cb, key, i); + if (key) { + struct critbit_tree ** cb = (struct critbit_tree **)tokens; + add_translation(cb, key, i); + } } } }