forked from github/server
convert report_template to sbstring
This commit is contained in:
parent
08cf00e700
commit
fbb7a6c418
51
src/report.c
51
src/report.c
|
@ -1277,9 +1277,8 @@ report_template(const char *filename, report_context * ctx, const char *bom)
|
||||||
region *r;
|
region *r;
|
||||||
FILE *F = fopen(filename, "w");
|
FILE *F = fopen(filename, "w");
|
||||||
stream strm = { 0 }, *out = &strm;
|
stream strm = { 0 }, *out = &strm;
|
||||||
char buf[8192], *bufp;
|
char buf[4096];
|
||||||
size_t size;
|
sbstring sbs;
|
||||||
int bytes;
|
|
||||||
|
|
||||||
if (F == NULL) {
|
if (F == NULL) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
|
@ -1339,50 +1338,40 @@ report_template(const char *filename, report_context * ctx, const char *bom)
|
||||||
}
|
}
|
||||||
dh = 1;
|
dh = 1;
|
||||||
|
|
||||||
bufp = buf;
|
sbs_init(&sbs, buf, sizeof(buf));
|
||||||
size = sizeof(buf) - 1;
|
sbs_strcat(&sbs, LOC(u->faction->locale, parameters[P_UNIT]));
|
||||||
bytes = snprintf(bufp, size, "%s %s; %s [%d,%d$",
|
sbs_strcat(&sbs, " ");
|
||||||
LOC(u->faction->locale, parameters[P_UNIT]),
|
sbs_strcat(&sbs, itoa36(u->no)),
|
||||||
itoa36(u->no), unit_getname(u), u->number, get_money(u));
|
sbs_strcat(&sbs, "; ");
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
sbs_strcat(&sbs, unit_getname(u));
|
||||||
WARN_STATIC_BUFFER();
|
sbs_strcat(&sbs, " [");
|
||||||
|
sbs_strcat(&sbs, str_itoa(u->number));
|
||||||
|
sbs_strcat(&sbs, ",");
|
||||||
|
sbs_strcat(&sbs, str_itoa(get_money(u)));
|
||||||
|
sbs_strcat(&sbs, "$");
|
||||||
if (u->building && building_owner(u->building) == u) {
|
if (u->building && building_owner(u->building) == u) {
|
||||||
building *b = u->building;
|
building *b = u->building;
|
||||||
if (!curse_active(get_curse(b->attribs, &ct_nocostbuilding))) {
|
if (!curse_active(get_curse(b->attribs, &ct_nocostbuilding))) {
|
||||||
int cost = buildingmaintenance(b, rsilver);
|
int cost = buildingmaintenance(b, rsilver);
|
||||||
if (cost > 0) {
|
if (cost > 0) {
|
||||||
bytes = (int)str_strlcpy(bufp, ",U", size);
|
sbs_strcat(&sbs, ",U");
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
sbs_strcat(&sbs, str_itoa(cost));
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = (int)str_strlcpy(bufp, itoa10(cost), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (u->ship) {
|
else if (u->ship) {
|
||||||
if (ship_owner(u->ship) == u) {
|
if (ship_owner(u->ship) == u) {
|
||||||
bytes = (int)str_strlcpy(bufp, ",S", size);
|
sbs_strcat(&sbs, ",S");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bytes = (int)str_strlcpy(bufp, ",s", size);
|
sbs_strcat(&sbs, ",s");
|
||||||
}
|
}
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
sbs_strcat(&sbs,itoa36(u->ship->no));
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = (int)str_strlcpy(bufp, itoa36(u->ship->no), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
if (lifestyle(u) == 0) {
|
if (lifestyle(u) == 0) {
|
||||||
bytes = (int)str_strlcpy(bufp, ",I", size);
|
sbs_strcat(&sbs, ",I");
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
bytes = (int)str_strlcpy(bufp, "]", size);
|
sbs_strcat(&sbs, "]");
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
*bufp = 0;
|
|
||||||
rps_nowrap(out, buf);
|
rps_nowrap(out, buf);
|
||||||
newline(out);
|
newline(out);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue