forked from github/server
some factions have very long names, breaking my buffer.
use sbstring with care. fix hackish utf8 space detection.
This commit is contained in:
parent
8584b46dc0
commit
be3f63416d
2 changed files with 8 additions and 4 deletions
10
src/report.c
10
src/report.c
|
@ -1528,11 +1528,14 @@ struct show_s {
|
||||||
size_t maxlen;
|
size_t maxlen;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* TODO: does not test for non-ascii unicode spaces. */
|
||||||
|
#define IS_UTF8_SPACE(pos) (*pos > 0 && *pos <= CHAR_MAX && isspace(*pos))
|
||||||
|
|
||||||
void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal)
|
void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal)
|
||||||
{
|
{
|
||||||
while (sbs_length(sbp) > maxlen) {
|
while (sbs_length(sbp) > maxlen) {
|
||||||
char *pos, *begin = sbp->begin;
|
char *pos, *begin = sbp->begin;
|
||||||
while (*begin && isspace(*begin)) {
|
while (*begin && IS_UTF8_SPACE(begin)) {
|
||||||
/* eat whitespace */
|
/* eat whitespace */
|
||||||
++begin;
|
++begin;
|
||||||
}
|
}
|
||||||
|
@ -1551,7 +1554,7 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal)
|
||||||
swrite(begin, 1, len, out);
|
swrite(begin, 1, len, out);
|
||||||
newline(out);
|
newline(out);
|
||||||
|
|
||||||
while (*pos && isspace(*pos)) {
|
while (*pos && IS_UTF8_SPACE(pos)) {
|
||||||
++pos;
|
++pos;
|
||||||
++len;
|
++len;
|
||||||
}
|
}
|
||||||
|
@ -1564,7 +1567,7 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal)
|
||||||
}
|
}
|
||||||
if (isfinal) {
|
if (isfinal) {
|
||||||
char *pos = sbp->begin;
|
char *pos = sbp->begin;
|
||||||
while (*pos && isspace(*pos)) {
|
while (*pos && IS_UTF8_SPACE(pos)) {
|
||||||
/* eat whitespace */
|
/* eat whitespace */
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
|
@ -1590,6 +1593,7 @@ static int show_allies_cb(struct allies *all, faction *af, int status, void *uda
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sbs_strcat(sbp, factionname(af));
|
sbs_strcat(sbp, factionname(af));
|
||||||
|
pump_paragraph(sbp, show->out, show->maxlen, false);
|
||||||
sbs_strcat(sbp, " (");
|
sbs_strcat(sbp, " (");
|
||||||
if ((mode & HELP_ALL) == HELP_ALL) {
|
if ((mode & HELP_ALL) == HELP_ALL) {
|
||||||
sbs_strcat(sbp, LOC(f->locale, parameters[P_ANY]));
|
sbs_strcat(sbp, LOC(f->locale, parameters[P_ANY]));
|
||||||
|
|
|
@ -1687,7 +1687,7 @@ int reports(void)
|
||||||
faction *f;
|
faction *f;
|
||||||
FILE *mailit;
|
FILE *mailit;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
char path[4096];
|
char path[PATH_MAX];
|
||||||
const char * rpath = reportpath();
|
const char * rpath = reportpath();
|
||||||
|
|
||||||
log_info("Writing reports for turn %d:", turn);
|
log_info("Writing reports for turn %d:", turn);
|
||||||
|
|
Loading…
Reference in a new issue