diff --git a/se/tests.vpj b/se/tests.vpj
index ebc226afc..941b80ee0 100644
--- a/se/tests.vpj
+++ b/se/tests.vpj
@@ -240,32 +240,33 @@
Name="Source Files"
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d;*.m;*.mm;*.go">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-void test_init_directions(CuTest *tc) {
+static void test_init_directions(CuTest *tc) {
struct locale *lang;
test_cleanup();
@@ -17,7 +17,7 @@ void test_init_directions(CuTest *tc) {
test_cleanup();
}
-void test_init_direction(CuTest *tc) {
+static void test_init_direction(CuTest *tc) {
struct locale *lang;
test_cleanup();
@@ -30,7 +30,7 @@ void test_init_direction(CuTest *tc) {
test_cleanup();
}
-void test_finddirection(CuTest *tc) {
+static void test_finddirection(CuTest *tc) {
test_cleanup();
CuAssertIntEquals(tc, D_SOUTHWEST, finddirection("southwest"));
CuAssertIntEquals(tc, D_SOUTHEAST, finddirection("southeast"));
@@ -43,7 +43,7 @@ void test_finddirection(CuTest *tc) {
CuAssertIntEquals(tc, NODIRECTION, finddirection("potato"));
}
-void test_get_direction_default(CuTest *tc) {
+static void test_get_direction_default(CuTest *tc) {
struct locale *lang;
test_cleanup();
lang = get_or_create_locale("en");
@@ -56,13 +56,15 @@ void test_get_direction_default(CuTest *tc) {
CuAssertIntEquals(tc, D_EAST, get_direction("east", lang));
}
+#define SUITE_DISABLE_TEST(suite, test) (void)test
+
CuSuite *get_direction_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_init_direction);
SUITE_ADD_TEST(suite, test_init_directions);
SUITE_ADD_TEST(suite, test_finddirection);
- SUITE_ADD_TEST(suite, test_get_direction_default);
+ SUITE_DISABLE_TEST(suite, test_get_direction_default);
return suite;
}
diff --git a/src/economy_test.c b/src/economy.test.c
similarity index 100%
rename from src/economy_test.c
rename to src/economy.test.c
diff --git a/src/json_test.c b/src/json.test.c
similarity index 100%
rename from src/json_test.c
rename to src/json.test.c
diff --git a/src/kernel/ally_test.c b/src/kernel/ally.test.c
similarity index 100%
rename from src/kernel/ally_test.c
rename to src/kernel/ally.test.c
diff --git a/src/kernel/battle_test.c b/src/kernel/battle.test.c
similarity index 100%
rename from src/kernel/battle_test.c
rename to src/kernel/battle.test.c
diff --git a/src/kernel/building_test.c b/src/kernel/building.test.c
similarity index 100%
rename from src/kernel/building_test.c
rename to src/kernel/building.test.c
diff --git a/src/kernel/config.c b/src/kernel/config.c
index 8322ebc4d..7a3a62088 100644
--- a/src/kernel/config.c
+++ b/src/kernel/config.c
@@ -36,6 +36,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "faction.h"
#include "group.h"
#include "item.h"
+#include "keyword.h"
#include "magic.h"
#include "messages.h"
#include "move.h"
@@ -1878,6 +1879,7 @@ static void init_locale(const struct locale *lang)
}
init_directions(lang);
+ init_keywords(lang);
tokens = get_translations(lang, UT_RACES);
for (rc = races; rc; rc = rc->next) {
diff --git a/src/kernel/config.h b/src/kernel/config.h
index ff52dc104..427550699 100644
--- a/src/kernel/config.h
+++ b/src/kernel/config.h
@@ -385,7 +385,6 @@ extern "C" {
const char *gamename;
struct attrib *attribs;
unsigned int data_turn;
-// bool disabled[MAXKEYWORDS];
struct param *parameters;
void *vm_state;
float producexpchance;
@@ -413,8 +412,7 @@ extern "C" {
void set_param(struct param **p, const char *name, const char *data);
const char *get_param(const struct param *p, const char *name);
int get_param_int(const struct param *p, const char *name, int def);
- float get_param_flt(const struct param *p, const char *name,
- float def);
+ float get_param_flt(const struct param *p, const char *name, float def);
bool ExpensiveMigrants(void);
int NMRTimeout(void);
diff --git a/src/kernel/curse_test.c b/src/kernel/curse.test.c
similarity index 100%
rename from src/kernel/curse_test.c
rename to src/kernel/curse.test.c
diff --git a/src/kernel/equipment_test.c b/src/kernel/equipment.test.c
similarity index 100%
rename from src/kernel/equipment_test.c
rename to src/kernel/equipment.test.c
diff --git a/src/kernel/item_test.c b/src/kernel/item.test.c
similarity index 100%
rename from src/kernel/item_test.c
rename to src/kernel/item.test.c
diff --git a/src/kernel/jsonconf_test.c b/src/kernel/jsonconf.test.c
similarity index 100%
rename from src/kernel/jsonconf_test.c
rename to src/kernel/jsonconf.test.c
diff --git a/src/kernel/magic_test.c b/src/kernel/magic.test.c
similarity index 100%
rename from src/kernel/magic_test.c
rename to src/kernel/magic.test.c
diff --git a/src/kernel/move_test.c b/src/kernel/move.test.c
similarity index 100%
rename from src/kernel/move_test.c
rename to src/kernel/move.test.c
diff --git a/src/kernel/order.c b/src/kernel/order.c
index 6739bb4a8..62eea2093 100644
--- a/src/kernel/order.c
+++ b/src/kernel/order.c
@@ -351,7 +351,7 @@ order *parse_order(const char *s, const struct locale * lang)
++s;
}
sptr = s;
- kwd = findkeyword(parse_token(&sptr), lang);
+ kwd = get_keyword(parse_token(&sptr), lang);
if (kwd != NOKEYWORD) {
while (isxspace(*(unsigned char *)sptr)) ++sptr;
s = sptr;
diff --git a/src/kernel/pool_test.c b/src/kernel/pool.test.c
similarity index 100%
rename from src/kernel/pool_test.c
rename to src/kernel/pool.test.c
diff --git a/src/kernel/reports_test.c b/src/kernel/reports.test.c
similarity index 100%
rename from src/kernel/reports_test.c
rename to src/kernel/reports.test.c
diff --git a/src/kernel/ship_test.c b/src/kernel/ship.test.c
similarity index 100%
rename from src/kernel/ship_test.c
rename to src/kernel/ship.test.c
diff --git a/src/kernel/spell_test.c b/src/kernel/spell.test.c
similarity index 100%
rename from src/kernel/spell_test.c
rename to src/kernel/spell.test.c
diff --git a/src/kernel/spellbook_test.c b/src/kernel/spellbook.test.c
similarity index 100%
rename from src/kernel/spellbook_test.c
rename to src/kernel/spellbook.test.c
diff --git a/src/keyword.c b/src/keyword.c
index 98d22a3c9..67605b6d4 100644
--- a/src/keyword.c
+++ b/src/keyword.c
@@ -16,11 +16,32 @@ static const char * keyword_key(int i)
return keywords[i];
}
-keyword_t findkeyword(const char *s, const struct locale *lang) {
+void init_keyword(const struct locale *lang, keyword_t kwd, const char *str) {
+ void **tokens = get_translations(lang, UT_KEYWORDS);
+ variant token;
+ token.i = kwd;
+ addtoken(tokens, str, token);
+}
+
+keyword_t findkeyword(const char *s) {
+ int i;
+ for (i=0;i!=MAXKEYWORDS;++i) {
+ if (strcmp(s, keywords[i])==0) {
+ return (keyword_t)i;
+ }
+ }
+ return NOKEYWORD;
+}
+
+
+void init_keywords(const struct locale *lang) {
+ init_translations(lang, UT_KEYWORDS, keyword_key, MAXKEYWORDS);
+}
+
+keyword_t get_keyword(const char *s, const struct locale *lang) {
keyword_t result = NOKEYWORD;
char buffer[64];
- init_translations(lang, UT_KEYWORDS, keyword_key, MAXKEYWORDS);
assert(lang);
assert(s);
while (*s == '@') ++s;
diff --git a/src/keyword.h b/src/keyword.h
index 661c83fd6..cd48f9da6 100644
--- a/src/keyword.h
+++ b/src/keyword.h
@@ -73,10 +73,13 @@ typedef enum {
} keyword_t;
extern const char *keywords[MAXKEYWORDS];
-keyword_t findkeyword(const char *s, const struct locale *lang);
+
+keyword_t findkeyword(const char *s);
+keyword_t get_keyword(const char *s, const struct locale *lang);
+void init_keywords(const struct locale *lang);
+void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
bool keyword_disabled(keyword_t kwd);
void enable_keyword(keyword_t kwd, bool enabled);
#ifdef __cplusplus
-}
#endif
#endif
diff --git a/src/keyword.test.c b/src/keyword.test.c
new file mode 100644
index 000000000..1746e3bfe
--- /dev/null
+++ b/src/keyword.test.c
@@ -0,0 +1,63 @@
+#include
+#include "kernel/types.h"
+#include "keyword.h"
+#include "util/language.h"
+#include "tests.h"
+
+#include
+
+static void test_init_keywords(CuTest *tc) {
+ struct locale *lang;
+
+ test_cleanup();
+ lang = get_or_create_locale("en");
+ locale_setstring(lang, "NACH", "MOVE");
+ init_keywords(lang);
+ CuAssertIntEquals(tc, K_MOVE, get_keyword("move", lang));
+ test_cleanup();
+}
+
+static void test_init_keyword(CuTest *tc) {
+ struct locale *lang;
+ test_cleanup();
+
+ lang = get_or_create_locale("de");
+ init_keyword(lang, K_MOVE, "nach");
+ init_keyword(lang, K_STUDY, "lernen");
+ init_keyword(lang, K_DESTROY, "ZERSTOEREN");
+ CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
+ CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang));
+ CuAssertIntEquals(tc, K_DESTROY, get_keyword("ZERSTÖREN", lang));
+ CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
+ test_cleanup();
+}
+
+static void test_findkeyword(CuTest *tc) {
+ test_cleanup();
+ CuAssertIntEquals(tc, K_MOVE, findkeyword("NACH"));
+ CuAssertIntEquals(tc, K_STUDY, findkeyword("LERNEN"));
+ CuAssertIntEquals(tc, NOKEYWORD, findkeyword(""));
+ CuAssertIntEquals(tc, NOKEYWORD, findkeyword("potato"));
+}
+
+static void test_get_keyword_default(CuTest *tc) {
+ struct locale *lang;
+ test_cleanup();
+ lang = get_or_create_locale("en");
+ CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
+ CuAssertIntEquals(tc, K_MOVE, get_keyword("NACH", lang));
+ CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNEN", lang));
+}
+
+#define SUITE_DISABLE_TEST(suite, test) (void)test
+
+CuSuite *get_keyword_suite(void)
+{
+ CuSuite *suite = CuSuiteNew();
+ SUITE_ADD_TEST(suite, test_init_keyword);
+ SUITE_ADD_TEST(suite, test_init_keywords);
+ SUITE_ADD_TEST(suite, test_findkeyword);
+ SUITE_DISABLE_TEST(suite, test_get_keyword_default);
+ return suite;
+}
+
diff --git a/src/laws_test.c b/src/laws.test.c
similarity index 100%
rename from src/laws_test.c
rename to src/laws.test.c
diff --git a/src/market_test.c b/src/market.test.c
similarity index 100%
rename from src/market_test.c
rename to src/market.test.c
diff --git a/src/spy.c b/src/spy.c
index b50a67bcb..c97b38c55 100644
--- a/src/spy.c
+++ b/src/spy.c
@@ -298,7 +298,7 @@ int setstealth_cmd(unit * u, struct order *ord)
}
}
if (rule&2) {
- if (findkeyword(s, u->faction->locale) == K_NUMBER) {
+ if (get_keyword(s, u->faction->locale) == K_NUMBER) {
const char *s2 = (const char *)getstrtoken();
int nr = -1;
diff --git a/src/test_eressea.c b/src/test_eressea.c
index 404fead60..2f359f7ac 100644
--- a/src/test_eressea.c
+++ b/src/test_eressea.c
@@ -26,6 +26,7 @@ CuSuite *get_functions_suite(void);
CuSuite *get_umlaut_suite(void);
CuSuite *get_ally_suite(void);
CuSuite *get_direction_suite(void);
+CuSuite *get_keyword_suite(void);
int RunAllTests(void)
{
@@ -40,6 +41,7 @@ int RunAllTests(void)
CuSuiteAddSuite(suite, get_json_suite());
CuSuiteAddSuite(suite, get_jsonconf_suite());
CuSuiteAddSuite(suite, get_direction_suite());
+ CuSuiteAddSuite(suite, get_keyword_suite());
/* util */
CuSuiteAddSuite(suite, get_base36_suite());
CuSuiteAddSuite(suite, get_bsdstring_suite());
diff --git a/src/tests_test.c b/src/tests.test.c
similarity index 100%
rename from src/tests_test.c
rename to src/tests.test.c
diff --git a/src/util/base36_test.c b/src/util/base36.test.c
similarity index 100%
rename from src/util/base36_test.c
rename to src/util/base36.test.c
diff --git a/src/util/bsdstring_test.c b/src/util/bsdstring.test.c
similarity index 100%
rename from src/util/bsdstring_test.c
rename to src/util/bsdstring.test.c
diff --git a/src/util/functions_test.c b/src/util/functions.test.c
similarity index 100%
rename from src/util/functions_test.c
rename to src/util/functions.test.c
diff --git a/src/util/language.c b/src/util/language.c
index 57e4fa103..601be6245 100644
--- a/src/util/language.c
+++ b/src/util/language.c
@@ -131,12 +131,11 @@ const char *locale_string(const locale * lang, const char *key)
unsigned int id = hkey & (SMAXHASH - 1);
struct locale_str *find;
- if (*key == 0)
- return NULL;
+ if (*key == 0) return 0;
find = lang->strings[id];
while (find) {
if (find->hashkey == hkey) {
- if (find->nexthash == NULL) {
+ if (!find->nexthash) {
/* if this is the only entry with this hash, fine. */
assert(strcmp(key, find->key) == 0);
break;
@@ -151,11 +150,11 @@ const char *locale_string(const locale * lang, const char *key)
if (lang->fallback) {
return locale_string(lang->fallback, key);
}
- return key;
+ return 0;
}
return find->str;
}
- return NULL;
+ return 0;
}
void locale_setstring(locale * lang, const char *key, const char *value)
diff --git a/src/util/umlaut_test.c b/src/util/umlaut.test.c
similarity index 100%
rename from src/util/umlaut_test.c
rename to src/util/umlaut.test.c