diff --git a/res/eressea/spells.xml b/res/eressea/spells.xml
index 5725b8768..a56b147ef 100644
--- a/res/eressea/spells.xml
+++ b/res/eressea/spells.xml
@@ -314,7 +314,7 @@
-
+
diff --git a/src/laws.c b/src/laws.c
index f7eba8c97..fda3f434f 100644
--- a/src/laws.c
+++ b/src/laws.c
@@ -1488,7 +1488,7 @@ int display_cmd(unit * u, struct order *ord)
{
char token[128];
char **s = NULL;
- const char *str;
+ char *str;
region *r = u->region;
init_order_depr(ord);
@@ -1525,11 +1525,19 @@ int display_cmd(unit * u, struct order *ord)
break;
case P_UNIT:
- unit_setinfo(u, getstrtoken());
+ str = getstrtoken();
+ if (str) {
+ unicode_utf8_trim(str);
+ }
+ unit_setinfo(u, str);
break;
case P_PRIVAT:
- usetprivate(u, getstrtoken());
+ str = getstrtoken();
+ if (str) {
+ unicode_utf8_trim(str);
+ }
+ usetprivate(u, str);
break;
case P_REGION:
@@ -1664,7 +1672,7 @@ int name_cmd(struct unit *u, struct order *ord)
bool foreign = false;
const char *str;
- init_order_depr(ord);
+ init_order(ord, u->faction->locale);
str = gettoken(token, sizeof(token));
p = findparam_ex(str, u->faction->locale);
diff --git a/src/laws.test.c b/src/laws.test.c
index 0896b54f3..cead8605a 100644
--- a/src/laws.test.c
+++ b/src/laws.test.c
@@ -221,6 +221,21 @@ static void test_display_cmd(CuTest *tc) {
CuAssertStrEquals(tc, "Hodor", unit_getinfo(u));
free_order(ord);
+ ord = create_order(K_DISPLAY, f->locale, "%s ' Klabautermann '", LOC(f->locale, parameters[P_UNIT]));
+ CuAssertIntEquals(tc, 0, display_cmd(u, ord));
+ CuAssertStrEquals(tc, "Klabautermann", unit_getinfo(u));
+ free_order(ord);
+
+ ord = create_order(K_DISPLAY, f->locale, "%s Hodor", LOC(f->locale, parameters[P_PRIVAT]));
+ CuAssertIntEquals(tc, 0, display_cmd(u, ord));
+ CuAssertStrEquals(tc, "Hodor", uprivate(u));
+ free_order(ord);
+
+ ord = create_order(K_DISPLAY, f->locale, "%s ' Klabautermann '", LOC(f->locale, parameters[P_PRIVAT]));
+ CuAssertIntEquals(tc, 0, display_cmd(u, ord));
+ CuAssertStrEquals(tc, "Klabautermann", uprivate(u));
+ free_order(ord);
+
ord = create_order(K_DISPLAY, f->locale, LOC(f->locale, parameters[P_UNIT]));
CuAssertIntEquals(tc, 0, display_cmd(u, ord));
CuAssertPtrEquals(tc, NULL, (void *)unit_getinfo(u));
@@ -940,6 +955,12 @@ static void test_name_unit(CuTest *tc) {
u = setup_name_cmd();
f = u->faction;
+
+ ord = create_order(K_NAME, f->locale, "%s ' Klabauterfrau '", LOC(f->locale, parameters[P_UNIT]));
+ name_cmd(u, ord);
+ CuAssertStrEquals(tc, "Klabauterfrau", u->_name);
+ free_order(ord);
+
ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_UNIT]));
name_cmd(u, ord);
CuAssertStrEquals(tc, "Hodor", u->_name);
@@ -960,10 +981,15 @@ static void test_name_region(CuTest *tc) {
order *ord;
u = setup_name_cmd();
+ u_set_building(u, test_create_building(u->region, NULL));
f = u->faction;
+ ord = create_order(K_NAME, f->locale, "%s ' Hodor Hodor '", LOC(f->locale, parameters[P_REGION]));
+ name_cmd(u, ord);
+ CuAssertStrEquals(tc, "Hodor Hodor", u->region->land->name);
+ free_order(ord);
+
ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION]));
- u_set_building(u, test_create_building(u->region, NULL));
name_cmd(u, ord);
CuAssertStrEquals(tc, "Hodor", u->region->land->name);
free_order(ord);
@@ -980,6 +1006,7 @@ static void test_name_region(CuTest *tc) {
static void test_name_building(CuTest *tc) {
unit *uo, *u, *ux;
faction *f;
+ order *ord;
u = setup_name_cmd();
u->building = test_create_building(u->region, NULL);
@@ -989,29 +1016,33 @@ static void test_name_building(CuTest *tc) {
ux = test_create_unit(f, test_create_region(0, 0, NULL));
u_set_building(ux, u->building);
- u->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_BUILDING]));
-
+ ord = create_order(K_NAME, f->locale, "%s ' Hodor Hodor '", LOC(f->locale, parameters[P_BUILDING]));
building_set_owner(uo);
- name_cmd(u, u->thisorder);
+ name_cmd(u, ord);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error148"));
test_clear_messages(f);
-
building_set_owner(u);
- name_cmd(u, u->thisorder);
+ name_cmd(u, ord);
+ CuAssertStrEquals(tc, "Hodor Hodor", u->building->name);
+ free_order(ord);
+
+ ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_BUILDING]));
+ name_cmd(u, ord);
CuAssertStrEquals(tc, "Hodor", u->building->name);
building_setname(u->building, "Home");
building_set_owner(ux);
- name_cmd(u, u->thisorder);
+ name_cmd(u, ord);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error148"));
CuAssertStrEquals(tc, "Hodor", u->building->name);
-
test_clear_messages(f);
- free_order(u->thisorder);
- u->thisorder = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_BUILDING]));
- name_cmd(u, u->thisorder);
+ free_order(ord);
+
+ ord = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_BUILDING]));
+ name_cmd(u, ord);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84"));
CuAssertStrEquals(tc, "Hodor", u->building->name);
+ free_order(ord);
/* TODO: test BTF_NAMECHANGE:
btype->flags |= BTF_NAMECHANGE;
diff --git a/src/util/parser.c b/src/util/parser.c
index 3d1ba250d..bd187b5f8 100644
--- a/src/util/parser.c
+++ b/src/util/parser.c
@@ -233,12 +233,12 @@ const char *parse_token_depr(const char **str)
return parse_token(str, pbuf, MAXTOKENSIZE);
}
-const char *getstrtoken(void)
+char *getstrtoken(void)
{
return parse_token((const char **)&states->current_token, pbuf, MAXTOKENSIZE);
}
-const char *gettoken(char *lbuf, size_t bufsize)
+char *gettoken(char *lbuf, size_t bufsize)
{
return parse_token((const char **)&states->current_token, lbuf, bufsize);
}
diff --git a/src/util/parser.h b/src/util/parser.h
index a540aa2ac..329d6f654 100644
--- a/src/util/parser.h
+++ b/src/util/parser.h
@@ -26,8 +26,8 @@ extern "C" {
void parser_pushstate(void);
void parser_popstate(void);
bool parser_end(void);
- const char *getstrtoken(void);
- const char *gettoken(char *lbuf, size_t bufsize);
+ char *getstrtoken(void);
+ char *gettoken(char *lbuf, size_t bufsize);
int getuint(void);
int getint(void);
int getid(void);
diff --git a/src/util/unicode.c b/src/util/unicode.c
index 90b63205d..b4bb803dd 100644
--- a/src/util/unicode.c
+++ b/src/util/unicode.c
@@ -11,6 +11,7 @@
#include
#include "unicode.h"
+#include
#include
#include
#include
@@ -36,6 +37,7 @@ int unicode_utf8_trim(utf8_t *buf)
{
int result = 0, ts = 0;
utf8_t *op = buf, *ip = buf, *lc = buf;
+ assert(buf);
while (*ip) {
size_t size = 1;
wint_t wc = *ip;