diff --git a/src/kernel/config.c b/src/kernel/config.c index 65623235c..3f511ffd9 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -587,19 +587,6 @@ int change_hitpoints(unit * u, int value) return hp; } -unsigned int atoip(const char *s) -{ - int n; - - assert(s); - n = atoi(s); - - if (n < 0) - n = 0; - - return n; -} - bool unit_has_cursed_item(const unit * u) { item *itm = u->items; diff --git a/src/kernel/config.h b/src/kernel/config.h index 67355aae7..ea521d5c8 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -108,8 +108,6 @@ extern "C" { /* special units */ void make_undead_unit(struct unit *); - unsigned int atoip(const char *s); - param_t findparam(const char *s, const struct locale *lang); param_t findparam_ex(const char *s, const struct locale * lang); bool isparam(const char *s, const struct locale * lang, param_t param); diff --git a/src/laws.c b/src/laws.c index a7fd9a3f4..b8ea9fa2e 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2017,19 +2017,15 @@ int mail_cmd(unit * u, struct order *ord) } case P_FACTION: - { - bool see = false; - n = getfactionid(); for (u2 = r->units; u2; u2 = u2->next) { if (u2->faction->no == n && seefaction(u->faction, r, u2, 0)) { - see = true; break; } } - if (!see) { + if (!u2) { cmistake(u, ord, 66, MSG_MESSAGE); break; } @@ -2041,21 +2037,17 @@ int mail_cmd(unit * u, struct order *ord) } mailfaction(u, n, ord, s); return 0; - } case P_UNIT: - { - bool see = false; n = getid(); for (u2 = r->units; u2; u2 = u2->next) { if (u2->no == n && cansee(u->faction, r, u2, 0)) { - see = true; break; } } - if (!see) { + if (!u2) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", "")); return 0; @@ -2081,7 +2073,6 @@ int mail_cmd(unit * u, struct order *ord) mailunit(r, u, n, ord, s); } return 0; - } case P_BUILDING: case P_GEBAEUDE: diff --git a/src/util/parser.c b/src/util/parser.c index 3e3dbb374..51e99a9b6 100644 --- a/src/util/parser.c +++ b/src/util/parser.c @@ -240,3 +240,16 @@ int getid(void) } return i; } + +unsigned int atoip(const char *s) +{ + int n; + + assert(s); + n = atoi(s); + + if (n < 0) + n = 0; + + return n; +} diff --git a/src/util/parser.h b/src/util/parser.h index f1e01393c..01804ab01 100644 --- a/src/util/parser.h +++ b/src/util/parser.h @@ -26,6 +26,8 @@ extern "C" { unsigned int getuint(void); int getint(void); int getid(void); + unsigned int atoip(const char *s); + #define getshipid() getid() #define getfactionid() getid() diff --git a/src/util/parser.test.c b/src/util/parser.test.c index 961761188..0c6e0059c 100644 --- a/src/util/parser.test.c +++ b/src/util/parser.test.c @@ -41,9 +41,16 @@ static void test_getstrtoken(CuTest *tc) { CuAssertPtrEquals(tc, NULL, (void *)getstrtoken()); } +static void test_atoip(CuTest *tc) { + CuAssertIntEquals(tc, 42, atoip("42")); + CuAssertIntEquals(tc, 0, atoip("-42")); + CuAssertIntEquals(tc, 0, atoip("NOPE")); +} + CuSuite *get_parser_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_atoip); SUITE_ADD_TEST(suite, test_skip_token); SUITE_ADD_TEST(suite, test_gettoken); SUITE_ADD_TEST(suite, test_getintegers);