forked from github/server
replace bsdstring functions in cycle_route.
This commit is contained in:
parent
034872c44e
commit
6abf054b42
4 changed files with 33 additions and 29 deletions
55
src/move.c
55
src/move.c
|
@ -1047,15 +1047,17 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp)
|
||||||
order * cycle_route(order * ord, const struct locale *lang, int gereist)
|
order * cycle_route(order * ord, const struct locale *lang, int gereist)
|
||||||
{
|
{
|
||||||
int cm = 0;
|
int cm = 0;
|
||||||
char tail[1024], *bufp = tail;
|
char tail[1024];
|
||||||
char neworder[2048], *obuf = neworder;
|
char neworder[2048];
|
||||||
char token[128];
|
char token[128];
|
||||||
direction_t d = NODIRECTION;
|
direction_t d = NODIRECTION;
|
||||||
bool paused = false;
|
bool paused = false;
|
||||||
bool pause;
|
|
||||||
order *norder;
|
order *norder;
|
||||||
size_t size = sizeof(tail) - 1;
|
sbstring sbtail;
|
||||||
|
sbstring sborder;
|
||||||
|
|
||||||
|
sbs_init(&sbtail, tail, sizeof(tail));
|
||||||
|
sbs_init(&sborder, neworder, sizeof(neworder));
|
||||||
assert(getkeyword(ord) == K_ROUTE);
|
assert(getkeyword(ord) == K_ROUTE);
|
||||||
tail[0] = '\0';
|
tail[0] = '\0';
|
||||||
neworder[0] = '\0';
|
neworder[0] = '\0';
|
||||||
|
@ -1063,14 +1065,10 @@ order * cycle_route(order * ord, const struct locale *lang, int gereist)
|
||||||
|
|
||||||
for (cm = 0;; ++cm) {
|
for (cm = 0;; ++cm) {
|
||||||
const char *s;
|
const char *s;
|
||||||
pause = false;
|
|
||||||
s = gettoken(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
if (s && *s) {
|
if (s && *s) {
|
||||||
d = get_direction(s, lang);
|
d = get_direction(s, lang);
|
||||||
if (d == D_PAUSE) {
|
if (d == NODIRECTION) {
|
||||||
pause = true;
|
|
||||||
}
|
|
||||||
else if (d == NODIRECTION) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1079,38 +1077,37 @@ order * cycle_route(order * ord, const struct locale *lang, int gereist)
|
||||||
}
|
}
|
||||||
if (cm < gereist) {
|
if (cm < gereist) {
|
||||||
/* TODO: hier sollte keine PAUSE auftreten */
|
/* TODO: hier sollte keine PAUSE auftreten */
|
||||||
assert(!pause);
|
assert (d != D_PAUSE);
|
||||||
if (!pause) {
|
if (d != D_PAUSE) {
|
||||||
const char *loc = LOC(lang, shortdirections[d]);
|
const char *loc = LOC(lang, shortdirections[d]);
|
||||||
assert(loc);
|
assert(loc);
|
||||||
if (bufp != tail) {
|
if (sbs_length(&sbtail) > 0) {
|
||||||
bufp = STRLCPY_EX(bufp, " ", &size, "cycle_route");
|
sbs_strcat(&sbtail, " ");
|
||||||
}
|
}
|
||||||
bufp = STRLCPY_EX(bufp, loc, &size, "cycle_route");
|
sbs_strcat(&sbtail, loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strlen(neworder) > sizeof(neworder) / 2)
|
else if (strlen(neworder) > sizeof(neworder) / 2)
|
||||||
break;
|
break;
|
||||||
else if (cm == gereist && !paused && pause) {
|
else if (cm == gereist && !paused && (d == D_PAUSE)) {
|
||||||
const char *loc = LOC(lang, parameters[P_PAUSE]);
|
const char *loc = LOC(lang, parameters[P_PAUSE]);
|
||||||
bufp = STRLCPY_EX(bufp, " ", &size, "cycle_route");
|
sbs_strcat(&sbtail, " ");
|
||||||
bufp = STRLCPY_EX(bufp, loc, &size, "cycle_route");
|
sbs_strcat(&sbtail, loc);
|
||||||
paused = true;
|
paused = true;
|
||||||
}
|
}
|
||||||
else if (pause) {
|
|
||||||
/* da PAUSE nicht in ein shortdirections[d] umgesetzt wird (ist
|
|
||||||
* hier keine normale direction), muss jede PAUSE einzeln
|
|
||||||
* herausgefiltert und explizit gesetzt werden */
|
|
||||||
if (neworder != obuf) {
|
|
||||||
obuf += str_strlcat(obuf, " ", sizeof(neworder) - (obuf - neworder));
|
|
||||||
}
|
|
||||||
obuf += str_strlcat(obuf, LOC(lang, parameters[P_PAUSE]), sizeof(neworder) - (obuf - neworder));
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (neworder != obuf) {
|
if (sbs_length(&sbtail) > 0) {
|
||||||
obuf += str_strlcat(obuf, " ", sizeof(neworder) - (obuf - neworder));
|
sbs_strcat(&sborder, " ");
|
||||||
|
}
|
||||||
|
if (d == D_PAUSE) {
|
||||||
|
/* da PAUSE nicht in ein shortdirections[d] umgesetzt wird (ist
|
||||||
|
* hier keine normale direction), muss jede PAUSE einzeln
|
||||||
|
* herausgefiltert und explizit gesetzt werden */
|
||||||
|
sbs_strcat(&sborder, LOC(lang, parameters[P_PAUSE]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sbs_strcat(&sborder, LOC(lang, shortdirections[d]));
|
||||||
}
|
}
|
||||||
obuf += str_strlcat(obuf, LOC(lang, shortdirections[d]), sizeof(neworder) - (obuf - neworder));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -495,6 +495,7 @@ static void test_follow_ship_msg(CuTest * tc) {
|
||||||
|
|
||||||
follow_ship(u, ord);
|
follow_ship(u, ord);
|
||||||
|
|
||||||
|
CuAssertPtrEquals(tc, r, u->region);
|
||||||
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "error18"));
|
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "error18"));
|
||||||
p = msg->parameters[2].v;
|
p = msg->parameters[2].v;
|
||||||
CuAssertPtrNotNull(tc, p);
|
CuAssertPtrNotNull(tc, p);
|
||||||
|
|
|
@ -275,6 +275,11 @@ void sbs_strcpy(struct sbstring *sbs, const char *str)
|
||||||
sbs->end = sbs->begin + len;
|
sbs->end = sbs->begin + len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t sbs_length(const struct sbstring *sbs)
|
||||||
|
{
|
||||||
|
return sbs->end - sbs->begin;
|
||||||
|
}
|
||||||
|
|
||||||
char *str_unescape(char *str) {
|
char *str_unescape(char *str) {
|
||||||
char *read = str, *write = str;
|
char *read = str, *write = str;
|
||||||
while (*read) {
|
while (*read) {
|
||||||
|
|
|
@ -50,6 +50,7 @@ extern "C" {
|
||||||
void sbs_strcat(struct sbstring *sbs, const char *str);
|
void sbs_strcat(struct sbstring *sbs, const char *str);
|
||||||
void sbs_strncat(struct sbstring *sbs, const char *str, size_t size);
|
void sbs_strncat(struct sbstring *sbs, const char *str, size_t size);
|
||||||
void sbs_strcpy(struct sbstring *sbs, const char *str);
|
void sbs_strcpy(struct sbstring *sbs, const char *str);
|
||||||
|
size_t sbs_length(const struct sbstring *sbs);
|
||||||
|
|
||||||
/* benchmark for units:
|
/* benchmark for units:
|
||||||
* JENKINS_HASH: 5.25 misses/hit (with good cache behavior)
|
* JENKINS_HASH: 5.25 misses/hit (with good cache behavior)
|
||||||
|
|
Loading…
Reference in a new issue