diff --git a/src/kernel/save.c b/src/kernel/save.c index e3a63156c..6338b6827 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -123,42 +123,6 @@ char *rns(FILE * f, char *c, size_t size) return c; } -struct order *read_order(const char *in, const struct locale *lang) { - assert(in); - assert(lang); - if (in[0]) { - const char *s = in; - keyword_t kwd; - char token[64]; - const char *stok; - - stok = parse_token(&s, token, sizeof(token)); - if (stok) { - param_t param = findparam(token, lang); - switch (param) { - case P_UNIT: - case P_REGION: - return NULL; - case P_FACTION: - case P_NEXT: - case P_GAMENAME: - /* these terminate the orders, so we apply extra checking */ - if (strlen(stok) >= 3) { - return NULL; - } - break; - default: - break; - } - } - /* Nun wird der Befehl erzeut und eingehängt */ - kwd = get_keyword(stok, lang); - if (kwd != NOKEYWORD) { - return parse_order(in, lang); - } - } - return NULL; -} static unit *unitorders(FILE * F, int enc, struct faction *f) { @@ -201,7 +165,6 @@ static unit *unitorders(FILE * F, int enc, struct faction *f) for (;;) { const char *s; - order * ord; /* Erst wenn wir sicher sind, dass kein Befehl * eingegeben wurde, checken wir, ob nun eine neue * Einheit oder ein neuer Spieler drankommt */ @@ -210,13 +173,49 @@ static unit *unitorders(FILE * F, int enc, struct faction *f) if (s == NULL) break; - ord = read_order(s, f->locale); - if (!ord) { - ADDMSG(&f->msgs, msg_message("parse_error", "unit command", u, s)); - break; + if (s[0]) { + if (s[0] != '@') { + char token[64]; + const char *stok = s; + stok = parse_token(&stok, token, sizeof(token)); + + if (stok) { + bool quit = false; + param_t param = findparam(stok, u->faction->locale); + switch (param) { + case P_UNIT: + case P_REGION: + quit = true; + break; + case P_FACTION: + case P_NEXT: + case P_GAMENAME: + /* these terminate the orders, so we apply extra checking */ + if (strlen(stok) >= 3) { + quit = true; + break; + } + else { + quit = false; + } + break; + default: + break; + } + if (quit) { + break; + } + } + } + /* Nun wird der Befehl erzeut und eingehängt */ + *ordp = parse_order(s, u->faction->locale); + if (*ordp) { + ordp = &(*ordp)->next; + } + else { + ADDMSG(&f->msgs, msg_message("parse_error", "unit command", u, s)); + } } - *ordp = ord; - ordp = &(*ordp)->next; } } @@ -306,7 +305,7 @@ int readorders(const char *filename) } init_tokens_str(b); s = gettoken(token, sizeof(token)); - p = (s && s[0] != '@' && s[0] != '!') ? findparam(s, lang) : NOPARAM; + p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM; } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT && p != P_GAMENAME); } diff --git a/src/kernel/save.h b/src/kernel/save.h index f706a311b..763ff66b6 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -31,8 +31,6 @@ extern "C" { struct spellbook; struct unit; struct building; - struct order; - struct locale; struct faction; struct region; struct ship; @@ -45,8 +43,6 @@ extern "C" { /* TODO: is this *really* still in use? */ extern int enc_gamedata; - struct order *read_order(const char *s, const struct locale *lang); - int readorders(const char *filename); int readgame(const char *filename); int writegame(const char *filename); diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 73fe4663b..81d5a507d 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -5,7 +5,6 @@ #include #include "save.h" -#include "order.h" #include "version.h" #include "building.h" #include "ship.h" @@ -453,45 +452,6 @@ static void test_version_no(CuTest *tc) { CuAssertIntEquals(tc, 0x10203, version_no("1.2.3-what.is.42")); } -static void test_read_order(CuTest *tc) { - char cmd[32]; - order *ord; - struct locale * lang; - - test_setup(); - lang = test_create_locale(); - - ord = read_order("MOVE NORTH", lang); - CuAssertPtrNotNull(tc, ord); - CuAssertIntEquals(tc, K_MOVE, ord->command); - CuAssertIntEquals(tc, K_MOVE, getkeyword(ord)); - CuAssertStrEquals(tc, "move NORTH", get_command(ord, cmd, sizeof(cmd))); - free_order(ord); - - ord = read_order("MAKE TEMP foo", lang); - CuAssertPtrNotNull(tc, ord); - CuAssertIntEquals(tc, K_MAKETEMP, ord->command); - CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord)); - CuAssertStrEquals(tc, "maketemp foo", get_command(ord, cmd, sizeof(cmd))); - free_order(ord); - - ord = read_order("MAKETEMP foo", lang); - CuAssertPtrNotNull(tc, ord); - CuAssertIntEquals(tc, K_MAKETEMP, ord->command); - CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord)); - CuAssertStrEquals(tc, "maketemp foo", get_command(ord, cmd, sizeof(cmd))); - free_order(ord); - - CuAssertPtrEquals(tc, NULL, read_order("HODOR HODOR HODOR", lang)); - CuAssertPtrEquals(tc, NULL, read_order("FACTION abcd", lang)); - CuAssertPtrEquals(tc, NULL, read_order("UNIT abcd", lang)); - CuAssertPtrEquals(tc, NULL, read_order("ERESSEA abcd", lang)); - CuAssertPtrEquals(tc, NULL, read_order("REGION 2,3", lang)); - CuAssertPtrEquals(tc, NULL, read_order("NEXT", lang)); - - test_cleanup(); -} - CuSuite *get_save_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -508,7 +468,6 @@ CuSuite *get_save_suite(void) SUITE_ADD_TEST(suite, test_readwrite_dead_faction_group); SUITE_ADD_TEST(suite, test_read_password); SUITE_ADD_TEST(suite, test_read_password_external); - SUITE_ADD_TEST(suite, test_read_order); SUITE_ADD_TEST(suite, test_version_no); return suite;