From 04bbec2b89f820f64152f8a609c301d330b4d2c5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 4 Jan 2015 16:41:59 +0100 Subject: [PATCH 1/3] turns out that set_param with null should remove the setting. --- src/kernel/config.c | 11 +++++++++-- src/kernel/config.test.c | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 0e3d9802e..8cf3e0805 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1122,8 +1122,15 @@ void set_param(struct param **p, const char *key, const char *data) while (*p != NULL) { int cmp = strcmp((*p)->name, key); if (cmp == 0) { - free((*p)->data); - (*p)->data = _strdup(data); + par = *p; + free(par->data); + if (data) { + par->data = _strdup(data); + } + else { + *p = par->next; + free(par); + } return; } else if (cmp > 0) { diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index b5d7957be..34755c13b 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -71,6 +71,8 @@ static void test_get_set_param(CuTest * tc) set_param(&par, "bar", "foo"); CuAssertStrEquals(tc, "bar", get_param(par, "foo")); CuAssertStrEquals(tc, "foo", get_param(par, "bar")); + set_param(&par, "bar", NULL); + CuAssertPtrEquals(tc, NULL, (void *)get_param(par, "bar")); } static void test_param_int(CuTest * tc) From d3524b9eabd2106925a4b7ee2788bd3c557ce483 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 4 Jan 2015 16:43:47 +0100 Subject: [PATCH 2/3] do not write reports from tests --- scripts/tests/e3/rules.lua | 8 -------- 1 file changed, 8 deletions(-) diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 2be016a22..07fbb1a60 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -54,10 +54,6 @@ function disable_test_bug_1738_build_castle_e3() -- 33/4 makes 8 points, resulting size is 258. process_orders() - --[[ - init_reports() - write_report(f) - ]]-- -- resulting size should be 250 because unit 2 -- does not have the needed minimum skill. assert_equal(c.size, 250) @@ -302,13 +298,11 @@ function test_ship_capacity() process_orders() if r2~=u1.region then print(get_turn(), u1, u1.faction) - write_reports() end assert_equal(r2, u1.region) assert_not_equal(r2.id, u2.region.id) if r2~=u3.region then print(get_turn(), u3, u3.faction) - write_reports() end assert_equal(r2, u3.region) assert_not_equal(r2.id, u4.region.id) @@ -375,8 +369,6 @@ function test_region_owner_cannot_leave_castle() u:clear_orders() u:add_order("BETRETE BURG " .. itoa36(b2.id)) process_orders() - init_reports() - write_report(u.faction) assert_equal(b1, u.building, "region owner has left the building") -- region owners may not leave end From 23b8f2bc8a302a74006a445f3c7deaa2da706c45 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 8 Jan 2015 20:55:29 +0100 Subject: [PATCH 3/3] call init_locales after parse_json from Lua, downgrade missing string warnings during that to DEBUG (because it's quite common not to have them). also, these int to bool conversion warnings made a good point, even if I could not reproduce them. --- src/bind_config.c | 1 + src/bindings.c | 2 +- src/creport.c | 40 +++++++++++++++++--------------------- src/direction.c | 2 +- src/kernel/building.c | 2 +- src/kernel/config.c | 16 +++++++-------- src/kernel/item.c | 4 ++-- src/kernel/jsonconf.test.c | 14 ++++++------- src/kernel/order.c | 17 ++++++---------- src/kernel/save.c | 2 +- src/kernel/ship.c | 2 +- src/kernel/unit.c | 6 +++--- src/laws.c | 10 +++++----- src/lighthouse.c | 6 +++--- src/report.c | 6 +++--- src/reports.c | 16 +++++++-------- src/skill.c | 2 +- src/util/language.c | 10 ++++++---- src/util/language.h | 7 +++++-- src/vortex.c | 4 ++-- 20 files changed, 83 insertions(+), 86 deletions(-) diff --git a/src/bind_config.c b/src/bind_config.c index 35f04eaa6..e40055ee6 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -32,6 +32,7 @@ int config_parse(const char *json) if (conf) { json_config(conf); cJSON_Delete(conf); + init_locales(); return 0; } else { int line; diff --git a/src/bindings.c b/src/bindings.c index 6021339fd..58779bc0a 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -193,7 +193,7 @@ static int tolua_translate(lua_State * L) const char *lang = tolua_tostring(L, 2, 0); struct locale *loc = lang ? get_locale(lang) : default_locale; if (loc) { - str = locale_string(loc, str); + str = LOC(loc, str); tolua_pushstring(L, str); return 1; } diff --git a/src/creport.c b/src/creport.c index 0bfe10033..7d0963165 100644 --- a/src/creport.c +++ b/src/creport.c @@ -92,7 +92,7 @@ static const char *crtag(const char *key) static const struct locale *lang = NULL; if (!lang) lang = get_locale(TAG_LOCALE); - return locale_string(lang, key); + return LOC(lang, key); } #else #define crtag(x) (x) @@ -274,7 +274,7 @@ cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t ty fputs("EFFECTS\n", F); } fprintf(F, "\"%d %s\"\n", data->value, translate(key, - locale_string(default_locale, key))); + LOC(default_locale, key))); } } a = a->next; @@ -331,7 +331,7 @@ static int cr_resource(variant var, char *buffer, const void *userdata) if (r) { const char *key = resourcename(r, 0); sprintf(buffer, "\"%s\"", - translate(key, locale_string(report->locale, key))); + translate(key, LOC(report->locale, key))); return 0; } return -1; @@ -343,7 +343,7 @@ static int cr_race(variant var, char *buffer, const void *userdata) const struct race *rc = (const race *)var.v; const char *key = rc_name_s(rc, NAME_SINGULAR); sprintf(buffer, "\"%s\"", - translate(key, locale_string(report->locale, key))); + translate(key, LOC(report->locale, key))); return 0; } @@ -649,7 +649,7 @@ const faction * f, const region * r) if (sh->display && sh->display[0]) fprintf(F, "\"%s\";Beschr\n", sh->display); fprintf(F, "\"%s\";Typ\n", translate(sh->type->_name, - locale_string(f->locale, sh->type->_name))); + LOC(f->locale, sh->type->_name))); fprintf(F, "%d;Groesse\n", sh->size); if (sh->damage) { int percent = @@ -839,20 +839,20 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f, if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { const char *zRace = rc_name_s(u_race(u), NAME_PLURAL); fprintf(F, "\"%s\";wahrerTyp\n", - translate(zRace, locale_string(f->locale, zRace))); + translate(zRace, LOC(f->locale, zRace))); } } else { const race *irace = u_irace(u); const char *zRace = rc_name_s(irace, NAME_PLURAL); fprintf(F, "\"%s\";Typ\n", - translate(zRace, locale_string(f->locale, zRace))); + translate(zRace, LOC(f->locale, zRace))); if (u->faction == f && irace != u_race(u)) { assert(skill_enabled(SK_STEALTH) || !"we're resetting this on load, so.. ircase should never be used"); zRace = rc_name_s(u_race(u), NAME_PLURAL); fprintf(F, "\"%s\";wahrerTyp\n", - translate(zRace, locale_string(f->locale, zRace))); + translate(zRace, LOC(f->locale, zRace))); } } @@ -902,7 +902,7 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f, c = hp_status(u); if (c && *c && (u->faction == f || omniscient(f))) { fprintf(F, "\"%s\";hp\n", translate(c, - locale_string(u->faction->locale, c))); + LOC(u->faction->locale, c))); } if (fval(u, UFL_HERO)) { fputs("1;hero\n", F); @@ -998,8 +998,7 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f, pr = 1; fputs("GEGENSTAENDE\n", F); } - fprintf(F, "%d;%s\n", in, translate(ic, locale_string(f->locale, - ic))); + fprintf(F, "%d;%s\n", in, translate(ic, LOC(f->locale, ic))); } cr_output_curses(F, f, u, TYP_UNIT); @@ -1294,8 +1293,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr) } tname = terrain_name(r); - fprintf(F, "\"%s\";Terrain\n", translate(tname, locale_string(f->locale, - tname))); + fprintf(F, "\"%s\";Terrain\n", translate(tname, LOC(f->locale, tname))); if (sr->mode != see_unit) fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]); if (sr->mode == see_neighbour) { @@ -1359,12 +1357,12 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr) if (lux) { const char *ch = resourcename(lux->rtype, 0); fprintf(F, "%d;%s\n", 1, translate(ch, - locale_string(f->locale, ch))); + LOC(f->locale, ch))); } if (herb) { const char *ch = resourcename(herb->rtype, 0); fprintf(F, "%d;%s\n", 1, translate(ch, - locale_string(f->locale, ch))); + LOC(f->locale, ch))); } } } @@ -1376,7 +1374,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr) fprintf(F, "%d;%s\n", (dmd->value ? dmd->value * dmd->type->price : -dmd->type->price), - translate(ch, locale_string(f->locale, ch))); + translate(ch, LOC(f->locale, ch))); dmd = dmd->next; } } @@ -1491,7 +1489,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) faction *f = ctx->f; const char *prefix; region *r; - const char *mailto = locale_string(f->locale, "mailto"); + const char *mailto = LOC(f->locale, "mailto"); const attrib *a; seen_region *sr = NULL; #if SCORE_MODULE @@ -1530,7 +1528,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) fprintf(F, "%d.%d.%d;Build\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); if (mailto != NULL) { fprintf(F, "\"%s\";mailto\n", mailto); - fprintf(F, "\"%s\";mailcmd\n", locale_string(f->locale, "mailcmd")); + fprintf(F, "\"%s\";mailcmd\n", LOC(f->locale, "mailcmd")); } show_alliances_cr(F, f); @@ -1651,8 +1649,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) continue; ch = resourcename(ptype->itype->rtype, 0); fprintf(F, "TRANK %d\n", hashstring(ch)); - fprintf(F, "\"%s\";Name\n", translate(ch, locale_string(f->locale, - ch))); + fprintf(F, "\"%s\";Name\n", translate(ch, LOC(f->locale, ch))); fprintf(F, "%d;Stufe\n", ptype->level); if (description == NULL) { @@ -1669,8 +1666,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) while (m->number) { ch = resourcename(m->rtype, 0); - fprintf(F, "\"%s\"\n", translate(ch, locale_string(f->locale, - ch))); + fprintf(F, "\"%s\"\n", translate(ch, LOC(f->locale, ch))); m++; } } diff --git a/src/direction.c b/src/direction.c index c74434fb3..66603663c 100644 --- a/src/direction.c +++ b/src/direction.c @@ -43,7 +43,7 @@ void init_directions(struct locale *lang) { register_special_direction(lang, "vortex"); for (i = 0; dirs[i].direction != NODIRECTION; ++i) { - const char *str = locale_string(lang, dirs[i].name); + const char *str = locale_string(lang, dirs[i].name, false); if (str) { variant token; token.i = dirs[i].direction; diff --git a/src/kernel/building.c b/src/kernel/building.c index bd3463744..a382a63bf 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -305,7 +305,7 @@ const building_type *findbuildingtype(const char *name, for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) { building_type *btype = (building_type *)ql_get(ql, qi); - const char *n = locale_string(lang, btype->_name); + const char *n = LOC(lang, btype->_name); type.v = (void *)btype; addtoken(&bn->names, n, type); } diff --git a/src/kernel/config.c b/src/kernel/config.c index 8cf3e0805..413f4d253 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -144,7 +144,7 @@ bool ExpensiveMigrants(void) gamecookie = global.cookie; value = get_param_int(global.parameters, "study.expensivemigrants", 0); } - return value; + return value!=0; } /** Specifies automatic alliance modes. @@ -932,12 +932,12 @@ void init_terrains_translation(const struct locale *lang) { variant var; const char *name; var.v = (void *)terrain; - name = LOC(lang, terrain->_name); + name = locale_string(lang, terrain->_name, false); if (name) { addtoken(tokens, name, var); } else { - log_error("no translation for terrain %s in locale %s", terrain->_name, locale_name(lang)); + log_debug("no translation for terrain %s in locale %s", terrain->_name, locale_name(lang)); } } } @@ -951,12 +951,12 @@ void init_options_translation(const struct locale * lang) { variant var; var.i = i; if (options[i]) { - const char *name = LOC(lang, options[i]); + const char *name = locale_string(lang, options[i], false); if (name) { addtoken(tokens, name, var); } else { - log_error("no translation for OPTION %s in locale %s", options[i], locale_name(lang)); + log_debug("no translation for OPTION %s in locale %s", options[i], locale_name(lang)); } } } @@ -1006,9 +1006,9 @@ void init_locale(struct locale *lang) for (rc = races; rc; rc = rc->next) { const char *name; var.v = (void *)rc; - name = LOC(lang, rc_name_s(rc, NAME_PLURAL)); + name = locale_string(lang, rc_name_s(rc, NAME_PLURAL), false); if (name) addtoken(tokens, name, var); - name = LOC(lang, rc_name_s(rc, NAME_SINGULAR)); + name = locale_string(lang, rc_name_s(rc, NAME_SINGULAR), false); if (name) addtoken(tokens, name, var); } @@ -1693,7 +1693,7 @@ order *default_order(const struct locale *lang) assert(i < MAXLOCALES); result = defaults[i]; if (!result && usedefault) { - const char * str = locale_string(lang, "defaultorder"); + const char * str = LOC(lang, "defaultorder"); if (str) { result = defaults[i] = parse_order(str, lang); } diff --git a/src/kernel/item.c b/src/kernel/item.c index b09ea1b67..584f8b0a2 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -1045,7 +1045,7 @@ static int add_resourcename_cb(const void * match, const void * key, size_t keyl cb_get_kv(match, &rtype, sizeof(rtype)); for (i = 0; i != 2; ++i) { char buffer[128]; - const char * name = locale_string(lang, resourcename(rtype, (i==0) ? 0 : NMF_PLURAL)); + const char * name = LOC(lang, resourcename(rtype, (i == 0) ? 0 : NMF_PLURAL)); if (name && transliterate(buffer, sizeof(buffer), name)) { size_t len = strlen(buffer); @@ -1096,7 +1096,7 @@ static int add_itemname_cb(const void * match, const void * key, size_t keylen, int i; for (i = 0; i != 2; ++i) { char buffer[128]; - const char * name = locale_string(lang, resourcename(rtype, (i == 0) ? 0 : NMF_PLURAL)); + const char * name = LOC(lang, resourcename(rtype, (i == 0) ? 0 : NMF_PLURAL)); if (name && transliterate(buffer, sizeof(buffer), name)) { size_t len = strlen(buffer); diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 500c952ec..4c8c8a0fc 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -373,8 +373,8 @@ static void test_skills(CuTest * tc) CuAssertIntEquals(tc, SK_CROSSBOW, get_skill("kreuz", lang)); CuAssertIntEquals(tc, SK_ALCHEMY, get_skill("alchemie", lang)); - CuAssertStrEquals(tc, "ALCHEMIE", locale_string(lang, "skill::alchemy")); - CuAssertStrEquals(tc, "ARMBRUST", locale_string(lang, "skill::crossbow")); + CuAssertStrEquals(tc, "ALCHEMIE", LOC(lang, "skill::alchemy")); + CuAssertStrEquals(tc, "ARMBRUST", LOC(lang, "skill::crossbow")); test_cleanup(); } @@ -396,8 +396,8 @@ static void test_keywords(CuTest * tc) CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang)); CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang)); - CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "keyword::study")); - CuAssertStrEquals(tc, "NACH", locale_string(lang, "keyword::move")); + CuAssertStrEquals(tc, "LERNEN", LOC(lang, "keyword::study")); + CuAssertStrEquals(tc, "NACH", LOC(lang, "keyword::move")); test_cleanup(); } @@ -413,10 +413,10 @@ static void test_strings(CuTest * tc) test_cleanup(); lang = get_or_create_locale("de"); CuAssertPtrNotNull(tc, lang); - CuAssertPtrEquals(tc, NULL, (void *)locale_string(lang, "move")); + CuAssertPtrEquals(tc, NULL, (void *)LOC(lang, "move")); json_config(json); - CuAssertStrEquals(tc, "NACH", locale_string(lang, "move")); - CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "study")); + CuAssertStrEquals(tc, "NACH", LOC(lang, "move")); + CuAssertStrEquals(tc, "LERNEN", LOC(lang, "study")); } static void test_infinitive_from_config(CuTest *tc) { diff --git a/src/kernel/order.c b/src/kernel/order.c index 165769807..bf1001469 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -388,8 +388,6 @@ order *parse_order(const char *s, const struct locale * lang) bool is_repeated(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); - int result = 0; - switch (kwd) { case K_CAST: case K_BUY: @@ -411,13 +409,12 @@ bool is_repeated(const order * ord) case K_MAKE: case K_LOOT: case K_DESTROY: - result = 1; - break; + return true; default: - result = 0; + break; } - return result; + return false; } /** @@ -431,7 +428,6 @@ bool is_repeated(const order * ord) bool is_exclusive(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); - int result = 0; switch (kwd) { case K_MOVE: @@ -452,13 +448,12 @@ bool is_exclusive(const order * ord) case K_MAKE: case K_LOOT: case K_DESTROY: - result = 1; - break; + return true; default: - result = 0; + break; } - return result; + return false; } /** diff --git a/src/kernel/save.c b/src/kernel/save.c index 95a85cf3b..059f960ad 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1568,7 +1568,7 @@ int readgame(const char *filename, int backup) sh->type = st_find(name); if (sh->type == NULL) { /* old datafiles */ - sh->type = st_find((const char *)locale_string(default_locale, name)); + sh->type = st_find((const char *)LOC(default_locale, name)); } assert(sh->type || !"ship_type not registered!"); diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 0cf04918c..19f3fa743 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -76,7 +76,7 @@ const ship_type *findshiptype(const char *name, const struct locale *lang) for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { ship_type *stype = (ship_type *)ql_get(ql, qi); variant var2; - const char *n = locale_string(lang, stype->_name); + const char *n = LOC(lang, stype->_name); var2.v = (void *)stype; addtoken(&sn->names, n, var2); } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index e837e6b15..efd39bab9 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1883,7 +1883,7 @@ char *write_unitname(const unit * u, char *buffer, size_t size) } else { const struct locale * lang = u->faction ? u->faction->locale : default_locale; const char * name = rc_name_s(u->_race, u->number == 1 ? NAME_SINGULAR : NAME_PLURAL); - slprintf(buffer, size, "%s (%s)", locale_string(lang, name), itoa36(u->no)); + slprintf(buffer, size, "%s (%s)", LOC(lang, name), itoa36(u->no)); } buffer[size - 1] = 0; return buffer; @@ -1902,8 +1902,8 @@ bool unit_name_equals_race(const unit *u) { rc_name(u->_race, NAME_SINGULAR, sing, sizeof(sing)); rc_name(u->_race, NAME_PLURAL, plur, sizeof(plur)); if (strcmp(u->name, sing) == 0 || strcmp(u->name, plur) == 0 || - strcmp(u->name, locale_string(lang, sing)) == 0 || - strcmp(u->name, locale_string(lang, plur)) == 0) { + strcmp(u->name, LOC(lang, sing)) == 0 || + strcmp(u->name, LOC(lang, plur)) == 0) { return true; } } diff --git a/src/laws.c b/src/laws.c index 0c01f0471..1715bede1 100755 --- a/src/laws.c +++ b/src/laws.c @@ -968,7 +968,7 @@ static bool CheckOverload(void) if (value < 0) { value = get_param_int(global.parameters, "rules.check_overload", 0); } - return value; + return value!=0; } int enter_ship(unit * u, struct order *ord, int id, bool report) @@ -1411,11 +1411,11 @@ static void init_prefixnames(void) for (key = 0; race_prefixes[key]; ++key) { variant var; const char *pname = - locale_string(lang, mkname("prefix", race_prefixes[key])); + LOC(lang, mkname("prefix", race_prefixes[key])); if (findtoken(in->names, pname, &var) == E_TOK_NOMATCH || var.i != key) { var.i = key; addtoken(&in->names, pname, var); - addtoken(&in->names, locale_string(lang, mkname("prefix", + addtoken(&in->names, LOC(lang, mkname("prefix", race_prefixes[key])), var); } } @@ -2209,7 +2209,7 @@ static bool display_item(faction * f, unit * u, const item_type * itype) info = locale_getstring(f->locale, key); if (info == NULL) { - info = locale_string(f->locale, mkname("iteminfo", "no_info")); + info = LOC(f->locale, mkname("iteminfo", "no_info")); } ADDMSG(&f->msgs, msg_message("displayitem", "weight item description", itype->weight, itype->rtype, info)); @@ -2261,7 +2261,7 @@ static bool display_race(faction * f, unit * u, const race * rc) key = mkname("raceinfo", rc->_name); info = locale_getstring(f->locale, key); if (info == NULL) { - info = locale_string(f->locale, mkname("raceinfo", "no_info")); + info = LOC(f->locale, mkname("raceinfo", "no_info")); } bytes = (int)strlcpy(bufp, info, size); diff --git a/src/lighthouse.c b/src/lighthouse.c index f05687e69..da9d489dd 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -104,9 +104,9 @@ bool check_leuchtturm(region * r, faction * f) { attrib *a; - if (!fval(r->terrain, SEA_REGION)) + if (!fval(r->terrain, SEA_REGION)) { return false; - + } for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse; a = a->next) { building *b = (building *)a->data.v; @@ -141,7 +141,7 @@ bool check_leuchtturm(region * r, faction * f) } else { /* E3A rule: no perception req'd */ - return maxd; + return true; } } } diff --git a/src/report.c b/src/report.c index 3500e938f..94f384803 100644 --- a/src/report.c +++ b/src/report.c @@ -1025,7 +1025,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) if (r->land->ownership) { const char *str = - locale_string(f->locale, mkname("morale", itoa10(r->land->morale))); + LOC(f->locale, mkname("morale", itoa10(r->land->morale))); bytes = _snprintf(bufp, size, " %s", str); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1701,7 +1701,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); if ((mode & HELP_ALL) == HELP_ALL) { - bytes = (int)strlcpy(bufp, locale_string(f->locale, parameters[P_ANY]), size); + bytes = (int)strlcpy(bufp, LOC(f->locale, parameters[P_ANY]), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1736,7 +1736,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } - bytes = (int)strlcpy(bufp, locale_string(f->locale, parameters[p]), size); + bytes = (int)strlcpy(bufp, LOC(f->locale, parameters[p]), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); hh = 1; diff --git a/src/reports.c b/src/reports.c index e478a0200..f770bb655 100644 --- a/src/reports.c +++ b/src/reports.c @@ -150,7 +150,7 @@ const char **name, const char **basename, int *number, bool singular) if (owner && owner->faction == viewer) { if (name) *name = - locale_string(viewer->locale, resourcename(i->type->rtype, + LOC(viewer->locale, resourcename(i->type->rtype, ((i->number != 1 && !singular) ? GR_PLURAL : 0))); if (basename) *basename = resourcename(i->type->rtype, 0); @@ -163,19 +163,19 @@ const char **name, const char **basename, int *number, bool singular) *number = 1; if (pp > 50000 && dragonrace(u_race(owner))) { if (name) - *name = locale_string(viewer->locale, "dragonhoard"); + *name = LOC(viewer->locale, "dragonhoard"); if (basename) *basename = "dragonhoard"; } else if (pp > 5000) { if (name) - *name = locale_string(viewer->locale, "moneychest"); + *name = LOC(viewer->locale, "moneychest"); if (basename) *basename = "moneychest"; } else if (pp > 500) { if (name) - *name = locale_string(viewer->locale, "moneybag"); + *name = LOC(viewer->locale, "moneybag"); if (basename) *basename = "moneybag"; } @@ -191,7 +191,7 @@ const char **name, const char **basename, int *number, bool singular) else { if (name) *name = - locale_string(viewer->locale, resourcename(i->type->rtype, + LOC(viewer->locale, resourcename(i->type->rtype, NMF_APPEARANCE | ((i->number != 1 && !singular) ? GR_PLURAL : 0))); if (basename) *basename = resourcename(i->type->rtype, NMF_APPEARANCE); @@ -584,7 +584,7 @@ size_t size) if (u->number && (u->faction == f || telepath_see || isbattle)) { const char *c = hp_status(u); - c = c ? locale_string(f->locale, c) : 0; + c = c ? LOC(f->locale, c) : 0; bytes = (int)strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1956,7 +1956,7 @@ const char *trailinto(const region * r, const struct locale *lang) if (r) { const char *tname = terrain_name(r); strcat(strcpy(ref, tname), "_trail"); - s = locale_string(lang, ref); + s = LOC(lang, ref); if (s && *s) { if (strstr(s, "%s")) return s; @@ -2003,7 +2003,7 @@ static void eval_localize(struct opstack **stack, const void *userdata) const struct faction *f = (const struct faction *)userdata; const struct locale *lang = f ? f->locale : default_locale; const char *c = (const char *)opop_v(stack); - c = locale_string(lang, c); + c = LOC(lang, c); opush_v(stack, strcpy(balloc(strlen(c) + 1), c)); } diff --git a/src/skill.c b/src/skill.c index d7ca2fee5..0df94a85f 100644 --- a/src/skill.c +++ b/src/skill.c @@ -66,7 +66,7 @@ void init_skills(const struct locale *lang) { const char *skillname(skill_t sk, const struct locale *lang) { if (skill_disabled[sk]) return 0; - return locale_string(lang, mkname("skill", skillnames[sk])); + return LOC(lang, mkname("skill", skillnames[sk])); } diff --git a/src/util/language.c b/src/util/language.c index 564ade080..f23643b6d 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -123,7 +123,7 @@ const char *locale_getstring(const locale * lang, const char *key) return NULL; } -const char *locale_string(const locale * lang, const char *key) +const char *locale_string(const locale * lang, const char *key, bool warn) { assert(lang); assert(key); @@ -150,9 +150,11 @@ const char *locale_string(const locale * lang, const char *key) if (find) { return find->str; } - log_error("missing translation for \"%s\" in locale %s\n", key, lang->name); + if (warn) { + log_warning("missing translation for \"%s\" in locale %s\n", key, lang->name); + } if (lang->fallback) { - return locale_string(lang->fallback, key); + return locale_string(lang->fallback, key, warn); } } return 0; @@ -262,7 +264,7 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_ tokens = get_translations(lang, ut); for (i = 0; i != maxstrings; ++i) { const char * s = string_cb(i); - const char * key = s ? locale_string(lang, s) : 0; + const char * key = s ? locale_string(lang, s, false) : 0; key = key ? key : s; if (key) { struct critbit_tree ** cb = (struct critbit_tree **)tokens; diff --git a/src/util/language.h b/src/util/language.h index d02a562ea..b6e22d5e5 100644 --- a/src/util/language.h +++ b/src/util/language.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef MY_LOCALE_H #define MY_LOCALE_H + +#include + #ifdef __cplusplus extern "C" { #endif @@ -39,7 +42,7 @@ extern "C" { const char *value); extern const char *locale_getstring(const struct locale *lang, const char *key); - extern const char *locale_string(const struct locale *lang, const char *key); /* does fallback */ + extern const char *locale_string(const struct locale *lang, const char *key, bool warn); /* does fallback */ extern unsigned int locale_index(const struct locale *lang); extern const char *locale_name(const struct locale *lang); @@ -48,7 +51,7 @@ extern "C" { extern void make_locales(const char *str); -#define LOC(lang, s) (lang?locale_string(lang, s):s) +#define LOC(lang, s) (lang?locale_string(lang, s, true):s) extern struct locale *default_locale; extern struct locale *locales; diff --git a/src/vortex.c b/src/vortex.c index c9cea4649..a4aee3181 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -28,7 +28,7 @@ static dir_lookup *dir_name_lookup; void register_special_direction(struct locale *lang, const char *name) { - const char *token = LOC(lang, name); + const char *token = locale_string(lang, name, false); if (token) { void **tokens = get_translations(lang, UT_SPECDIR); @@ -47,7 +47,7 @@ void register_special_direction(struct locale *lang, const char *name) } } else { - log_error("no translation for spec_direction '%s' in locale '%s'\n", name, locale_name(lang)); + log_debug("no translation for spec_direction '%s' in locale '%s'\n", name, locale_name(lang)); } }