Merge branch 'develop' into allies

This commit is contained in:
Enno Rehling 2018-10-26 14:13:28 +02:00
commit b3361e3ccb

View file

@ -1514,18 +1514,19 @@ static void
show_allies(const faction * f, struct ally * allies, char *buf, size_t size) show_allies(const faction * f, struct ally * allies, char *buf, size_t size)
{ {
int allierte = 0; int allierte = 0;
int i = 0, h, hh = 0; int i = 0, h, hh = 0, dh = 0;
int bytes, dh = 0;
const ally *sf; const ally *sf;
char *bufp = buf; /* buf already contains data */
--size; /* leave room for a null-terminator */
for (sf = allies; sf; sf = sf->next) { for (sf = allies; sf; sf = sf->next) {
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL); int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
if (mode > 0) if (mode > 0) {
++allierte; ++allierte;
} }
}
if (allierte > 0) {
sbstring sbs;
sbs_init(&sbs, buf, size);
for (sf = allies; sf; sf = sf->next) { for (sf = allies; sf; sf = sf->next) {
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL); int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
@ -1534,26 +1535,18 @@ show_allies(const faction * f, struct ally * allies, char *buf, size_t size)
i++; i++;
if (dh) { if (dh) {
if (i == allierte) { if (i == allierte) {
bytes = (int)str_strlcpy(bufp, LOC(f->locale, "list_and"), size); sbs_strcat(&sbs, LOC(f->locale, "list_and"));
} }
else { else {
bytes = (int)str_strlcpy(bufp, ", ", size); sbs_strcat(&sbs, ", ");
} }
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
} }
dh = 1; dh = 1;
hh = 0; hh = 0;
bytes = (int)str_strlcpy(bufp, factionname(sf->faction), size); sbs_strcat(&sbs, factionname(sf->faction));
if (wrptr(&bufp, &size, bytes) != 0) sbs_strcat(&sbs, " (");
WARN_STATIC_BUFFER();
bytes = (int)str_strlcpy(bufp, " (", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if ((mode & HELP_ALL) == HELP_ALL) { if ((mode & HELP_ALL) == HELP_ALL) {
bytes = (int)str_strlcpy(bufp, LOC(f->locale, parameters[P_ANY]), size); sbs_strcat(&sbs, LOC(f->locale, parameters[P_ANY]));
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
} }
else { else {
for (h = 1; h <= HELP_TRAVEL; h *= 2) { for (h = 1; h <= HELP_TRAVEL; h *= 2) {
@ -1582,25 +1575,17 @@ show_allies(const faction * f, struct ally * allies, char *buf, size_t size)
} }
if (p != MAXPARAMS) { if (p != MAXPARAMS) {
if (hh) { if (hh) {
bytes = (int)str_strlcpy(bufp, ", ", size); sbs_strcat(&sbs, ", ");
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
} }
bytes = (int)str_strlcpy(bufp, LOC(f->locale, parameters[p]), size); sbs_strcat(&sbs, LOC(f->locale, parameters[p]));
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
hh = 1; hh = 1;
} }
} }
} }
bytes = (int)str_strlcpy(bufp, ")", size); sbs_strcat(&sbs, ")");
if (wrptr(&bufp, &size, bytes) != 0) }
WARN_STATIC_BUFFER(); sbs_strcat(&sbs, ".");
} }
bytes = (int)str_strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
*bufp = 0;
} }
static void allies(struct stream *out, const faction * f) static void allies(struct stream *out, const faction * f)