forked from github/server
more sbstring upgrades
This commit is contained in:
parent
4b5bd11f29
commit
5b0f3f9ea7
1 changed files with 28 additions and 42 deletions
70
src/report.c
70
src/report.c
|
@ -79,6 +79,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
|
#include "util/bsdstring.h"
|
||||||
#include <util/goodies.h>
|
#include <util/goodies.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/lists.h>
|
#include <util/lists.h>
|
||||||
|
@ -426,8 +427,6 @@ void nr_spell_syntax(char *buf, size_t size, spellbook_entry * sbe, const struct
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "util/bsdstring.h"
|
|
||||||
|
|
||||||
void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *lang)
|
void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *lang)
|
||||||
{
|
{
|
||||||
int bytes, k, itemanz, costtyp;
|
int bytes, k, itemanz, costtyp;
|
||||||
|
@ -1841,72 +1840,61 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f,
|
||||||
static void
|
static void
|
||||||
nr_building(struct stream *out, const region *r, const building *b, const faction *f)
|
nr_building(struct stream *out, const region *r, const building *b, const faction *f)
|
||||||
{
|
{
|
||||||
int i, bytes;
|
int i;
|
||||||
const char *name, *bname, *billusion = NULL;
|
const char *name, *bname, *billusion = NULL;
|
||||||
const struct locale *lang;
|
const struct locale *lang;
|
||||||
char buffer[8192], *bufp = buffer;
|
char buffer[8192];
|
||||||
message *msg;
|
message *msg;
|
||||||
size_t size = sizeof(buffer) - 1;
|
size_t size;
|
||||||
|
sbstring sbs;
|
||||||
|
|
||||||
assert(f);
|
assert(f);
|
||||||
lang = f->locale;
|
lang = f->locale;
|
||||||
newline(out);
|
newline(out);
|
||||||
bytes =
|
sbs_init(&sbs, buffer, sizeof(buffer));
|
||||||
snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(lang,
|
|
||||||
"nr_size"), b->size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
report_building(b, &bname, &billusion);
|
report_building(b, &bname, &billusion);
|
||||||
|
|
||||||
|
size = str_slprintf(buffer, sizeof(buffer), "%s, %s %d, ", buildingname(b),
|
||||||
|
LOC(lang, "nr_size"), b->size);
|
||||||
|
sbs.end += size;
|
||||||
name = LOC(lang, billusion ? billusion : bname);
|
name = LOC(lang, billusion ? billusion : bname);
|
||||||
bytes = (int)str_strlcpy(bufp, name, size);
|
sbs_strcat(&sbs, name);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (billusion) {
|
if (billusion) {
|
||||||
unit *owner = building_owner(b);
|
unit *owner = building_owner(b);
|
||||||
if (owner && owner->faction == f) {
|
if (owner && owner->faction == f) {
|
||||||
/* illusion. report real type */
|
/* illusion. report real type */
|
||||||
name = LOC(lang, bname);
|
sbs_strcat(&sbs, " (");
|
||||||
bytes = snprintf(bufp, size, " (%s)", name);
|
sbs_strcat(&sbs, LOC(lang, bname));
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
sbs_strcat(&sbs, ")");
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!building_finished(b)) {
|
if (!building_finished(b)) {
|
||||||
bytes = (int)str_strlcpy(bufp, " ", size);
|
sbs_strcat(&sbs, " ");
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
sbs_strcat(&sbs, LOC(lang, "nr_building_inprogress"));
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = (int)str_strlcpy(bufp, LOC(lang, "nr_building_inprogress"), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->besieged > 0 && r->seen.mode >= seen_lighthouse) {
|
if (b->besieged > 0 && r->seen.mode >= seen_lighthouse) {
|
||||||
msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged,
|
msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged,
|
||||||
b->besieged - b->size * SIEGEFACTOR);
|
b->besieged - b->size * SIEGEFACTOR);
|
||||||
bytes = (int)nr_render(msg, lang, bufp, size, f);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
size = nr_render(msg, lang, sbs.end, sbs.size - (sbs.end - sbs.begin), f);
|
||||||
WARN_STATIC_BUFFER();
|
sbs.end += size;
|
||||||
|
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
if (b->display && b->display[0]) {
|
if (b->display && b->display[0]) {
|
||||||
bytes = (int)str_strlcpy(bufp, "; ", size);
|
sbs_strcat(&sbs, "; ");
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
sbs_strcat(&sbs, b->display);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = (int)str_strlcpy(bufp, b->display, size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
i = b->display[strlen(b->display) - 1];
|
i = b->display[strlen(b->display) - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i != '!' && i != '?' && i != '.') {
|
if (i != '!' && i != '?' && i != '.') {
|
||||||
bytes = (int)str_strlcpy(bufp, ".", size);
|
sbs_strcat(&sbs, ".");
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
*bufp = 0;
|
|
||||||
paragraph(out, buffer, 2, 0, 0);
|
paragraph(out, buffer, 2, 0, 0);
|
||||||
|
|
||||||
if (r->seen.mode >= seen_lighthouse) {
|
if (r->seen.mode >= seen_lighthouse) {
|
||||||
|
@ -1916,14 +1904,10 @@ nr_building(struct stream *out, const region *r, const building *b, const factio
|
||||||
|
|
||||||
static void nr_paragraph(struct stream *out, message * m, faction * f)
|
static void nr_paragraph(struct stream *out, message * m, faction * f)
|
||||||
{
|
{
|
||||||
int bytes;
|
char buf[4096];
|
||||||
char buf[4096], *bufp = buf;
|
|
||||||
size_t size = sizeof(buf) - 1;
|
|
||||||
|
|
||||||
assert(f);
|
assert(f);
|
||||||
bytes = (int)nr_render(m, f->locale, bufp, size, f);
|
nr_render(m, f->locale, buf, sizeof(buf), f);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
|
|
||||||
paragraph(out, buf, 0, 0, 0);
|
paragraph(out, buf, 0, 0, 0);
|
||||||
|
@ -2027,6 +2011,8 @@ void report_travelthru(struct stream *out, region *r, const faction *f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "util/bsdstring.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
report_plaintext(const char *filename, report_context * ctx,
|
report_plaintext(const char *filename, report_context * ctx,
|
||||||
const char *bom)
|
const char *bom)
|
||||||
|
|
Loading…
Reference in a new issue