From 9b9e0384382eef86d0a44361503cd132444fbb85 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 12 May 2015 17:18:51 -0700 Subject: [PATCH 1/6] press F3 to save game in editor. --- src/gmtool.c | 39 ++++++++++++++++++++++++++++----------- src/kernel/save.c | 2 +- src/kernel/save.h | 2 +- src/kernel/save.test.c | 2 +- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/gmtool.c b/src/gmtool.c index fc9fccdb9..5afb61a36 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -761,6 +761,29 @@ static void select_regions(state * st, int selectmode) st->wnd_map->update |= 3; } +void loaddata(state *st) { + char datafile[MAX_PATH]; + + askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); + if (strlen(datafile) > 0) { + create_backup(datafile); + readgame(datafile, false); + st->modified = 0; + } +} + +void savedata(state *st) { + char datafile[MAX_PATH]; + + askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); + if (strlen(datafile) > 0) { + create_backup(datafile); + remove_empty_units(); + writegame(datafile); + st->modified = 0; + } +} + static void handlekey(state * st, int c) { window *wnd; @@ -816,17 +839,11 @@ static void handlekey(state * st, int c) case 'S': case KEY_SAVE: case KEY_F(2): - /* if (st->modified) */ { - char datafile[MAX_PATH]; - - askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); - if (strlen(datafile) > 0) { - create_backup(datafile); - remove_empty_units(); - writegame(datafile); - st->modified = 0; - } - } + savedata(st); + break; + case KEY_F(3): + case KEY_OPEN: + loaddata(st); break; case 'B': /* diff --git a/src/kernel/save.c b/src/kernel/save.c index d9a18f2b3..ad0c51f61 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1348,7 +1348,7 @@ void writefaction(struct gamedata *data, const faction * f) write_spellbook(f->spellbook, data->store); } -int readgame(const char *filename, int backup) +int readgame(const char *filename, bool backup) { int n, p, nread; faction *f, **fp; diff --git a/src/kernel/save.h b/src/kernel/save.h index ee731fab8..11b53d620 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -44,7 +44,7 @@ extern "C" { int readorders(const char *filename); int creategame(void); - int readgame(const char *filename, int backup); + int readgame(const char *filename, bool backup); int writegame(const char *filename); /* Versionsänderungen: */ diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index cdbdbd3bf..26f48a07f 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -15,7 +15,7 @@ static void test_readwrite_data(CuTest * tc) test_cleanup(); sprintf(path, "%s/%s", datapath(), filename); CuAssertIntEquals(tc, 0, writegame(filename)); - CuAssertIntEquals(tc, 0, readgame(filename, 0)); + CuAssertIntEquals(tc, 0, readgame(filename, false)); CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version); CuAssertIntEquals(tc, 0, remove(path)); test_cleanup(); From e048b82ad2ccfa68c91385600bbe359e249b8b51 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 12 May 2015 19:25:50 -0700 Subject: [PATCH 2/6] very messy first steps towards making report_plaintext use filestream instead of FILE (lots of hacks) --- critbit | 2 +- src/report.c | 670 ++++++++++++++++++++++++++++----------------------- storage | 2 +- 3 files changed, 377 insertions(+), 297 deletions(-) diff --git a/critbit b/critbit index 61989d933..a2c6fad82 160000 --- a/critbit +++ b/critbit @@ -1 +1 @@ -Subproject commit 61989d93368022602a2a7ac4218c83f254701f0f +Subproject commit a2c6fad825e498abc2b36c8b2ed5a1ad9acf743e diff --git a/src/report.c b/src/report.c index 649eae934..6182429ca 100644 --- a/src/report.c +++ b/src/report.c @@ -81,6 +81,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include /* libc includes */ #include @@ -128,6 +129,10 @@ void rnl(FILE * F) fputc('\n', F); } +void newline(stream *out) { + sputs("", out); +} + static void centre(FILE * F, const char *s, bool breaking) { /* Bei Namen die genau 80 Zeichen lang sind, kann es hier Probleme @@ -214,6 +219,71 @@ char mark) } while (*begin); } +static void +paragraph(stream *out, const char *str, ptrdiff_t indent, int hanging_indent, +char marker) +{ + static const char *spaces = " "; + size_t length = REPORTWIDTH; + const char *end, *begin, *mark = 0; + + if (!str) return; + /* find out if there's a mark + indent already encoded in the string. */ + if (!marker) { + const char *x = str; + while (*x == ' ') + ++x; + indent += x - str; + if (x[0] && indent && x[1] == ' ') { + indent += 2; + mark = x; + str = x + 2; + hanging_indent -= 2; + } + } + else { + mark = ▮ + } + begin = end = str; + + do { + const char *last_space = begin; + + if (mark && indent >= 2) { + swrite(spaces, sizeof(char), indent - 2, out); + swrite(mark, sizeof(char), 1, out); + swrite(spaces, sizeof(char), 1, out); + mark = 0; + } + else if (begin == str) { + swrite(spaces, sizeof(char), indent, out); + } + else { + swrite(spaces, sizeof(char), indent + hanging_indent, out); + } + while (*end && end <= begin + length - indent) { + if (*end == ' ') { + last_space = end; + } + ++end; + } + if (*end == 0) + last_space = end; + if (last_space == begin) { + /* there was no space in this line. clip it */ + last_space = end; + } + swrite(begin, sizeof(char), last_space - begin, out); + begin = last_space; + while (*begin == ' ') { + ++begin; + } + if (begin > end) + begin = end; + sputs("", out); + } while (*begin); +} + static size_t write_spell_modifier(spell * sp, int flag, const char * str, bool cont, char * bufp, size_t size) { if (sp->sptyp & flag) { size_t bytes = 0; @@ -564,18 +634,53 @@ void sparagraph(strlist ** SP, const char *s, int indent, char mark) } static void -nr_curses(FILE * F, const faction * viewer, const void *obj, objtype_t typ, -int indent) +nr_curses_i(stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a) { - attrib *a = NULL; int self = 0; + + for (; a; a = a->next) { + char buf[4096]; + message *msg; + + if (fval(a->type, ATF_CURSE)) { + curse *c = (curse *)a->data.v; + + if (c->type->cansee) { + self = c->type->cansee(viewer, obj, typ, c, self); + } + msg = msg_curse(c, obj, typ, self); + + if (msg) { + newline(out); + nr_render(msg, viewer->locale, buf, sizeof(buf), viewer); + paragraph(out, buf, indent, 2, 0); + msg_release(msg); + } + } + else if (a->type == &at_effect && self) { + effect_data *data = (effect_data *)a->data.v; + if (data->value > 0) { + msg = msg_message("nr_potion_effect", "potion left", + data->type->itype->rtype, data->value); + nr_render(msg, viewer->locale, buf, sizeof(buf), viewer); + paragraph(out, buf, indent, 2, 0); + msg_release(msg); + } + } + } +} + +static void nr_curses(stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj) +{ + int self = 0; + attrib *a = NULL; region *r; /* Die Sichtbarkeit eines Zaubers und die Zaubermeldung sind bei - * Gebäuden und Schiffen je nach, ob man Besitzer ist, verschieden. - * Bei Einheiten sieht man Wirkungen auf eigene Einheiten immer. - * Spezialfälle (besonderes Talent, verursachender Magier usw. werde - * bei jedem curse gesondert behandelt. */ + * Gebäuden und Schiffen je nach, ob man Besitzer ist, verschieden. + * Bei Einheiten sieht man Wirkungen auf eigene Einheiten immer. + * Spezialfälle (besonderes Talent, verursachender Magier usw. werde + * bei jedem curse gesondert behandelt. */ if (typ == TYP_SHIP) { ship *sh = (ship *)obj; unit *owner = ship_owner(sh); @@ -629,39 +734,10 @@ int indent) a = r->attribs; } else { - /* fehler */ - } - - for (; a; a = a->next) { - char buf[4096]; - message *msg; - - if (fval(a->type, ATF_CURSE)) { - curse *c = (curse *)a->data.v; - - if (c->type->cansee) { - self = c->type->cansee(viewer, obj, typ, c, self); - } - msg = msg_curse(c, obj, typ, self); - - if (msg) { - rnl(F); - nr_render(msg, viewer->locale, buf, sizeof(buf), viewer); - rparagraph(F, buf, indent, 2, 0); - msg_release(msg); - } - } - else if (a->type == &at_effect && self) { - effect_data *data = (effect_data *)a->data.v; - if (data->value > 0) { - msg = msg_message("nr_potion_effect", "potion left", - data->type->itype->rtype, data->value); - nr_render(msg, viewer->locale, buf, sizeof(buf), viewer); - rparagraph(F, buf, indent, 2, 0); - msg_release(msg); - } - } + log_error("get_attribs: invalid object type %d", typ); + assert(!"invalid object type"); } + nr_curses_i(out, indent, viewer, typ, obj, a); } static void rps_nowrap(FILE * F, const char *s) @@ -687,7 +763,7 @@ static void rps_nowrap(FILE * F, const char *s) } static void -nr_unit(FILE * F, const faction * f, const unit * u, int indent, int mode) +nr_unit(stream *out, const faction * f, const unit * u, int indent, int mode) { attrib *a_otherfaction; char marker; @@ -698,10 +774,8 @@ nr_unit(FILE * F, const faction * f, const unit * u, int indent, int mode) if (fval(u_race(u), RCF_INVISIBLE)) return; - { - rnl(F); - dh = bufunit(f, u, indent, mode, buf, sizeof(buf)); - } + newline(out); + dh = bufunit(f, u, indent, mode, buf, sizeof(buf)); a_otherfaction = a_find(u->attribs, &at_otherfaction); @@ -723,10 +797,10 @@ nr_unit(FILE * F, const faction * f, const unit * u, int indent, int mode) marker = '-'; } } - rparagraph(F, buf, indent, 0, marker); + paragraph(out, buf, indent, 0, marker); if (!isbattle) { - nr_curses(F, f, u, TYP_UNIT, indent); + nr_curses(out, indent, f, TYP_UNIT, u); } } @@ -838,7 +912,8 @@ static void prices(FILE * F, const region * r, const faction * f) size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - } else if (n == 1) { + } + else if (n == 1) { bytes = (int)strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -849,7 +924,8 @@ static void prices(FILE * F, const region * r, const faction * f) bytes = (int)strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - } else { + } + else { bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_trade_next"), size); if (wrptr(&bufp, &size, bytes) != 0) @@ -887,7 +963,7 @@ bool see_border(const connection * b, const faction * f, const region * r) return cs; } -static void describe(FILE * F, const seen_region * sr, faction * f) +static void describe(stream *out, const seen_region * sr, faction * f) { const region *r = sr->r; int n; @@ -910,6 +986,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) char *bufp = buf; size_t size = sizeof(buf); int bytes; + FILE * F = fstream_file(out); for (d = 0; d != MAXDIRECTIONS; d++) { /* Nachbarregionen, die gesehen werden, ermitteln */ @@ -1237,10 +1314,9 @@ static void describe(FILE * F, const seen_region * sr, faction * f) } } - n = 0; - /* Wirkungen permanenter Sprüche */ - nr_curses(F, f, r, TYP_REGION, 0); + nr_curses(out, 0, f, TYP_REGION, r); + n = 0; /* Produktionsreduktion */ a = a_find(r->attribs, &at_reduceproduction); @@ -1904,7 +1980,7 @@ static void list_address(FILE * F, const faction * uf, quicklist * seenfactions) } static void -nr_ship(FILE * F, const seen_region * sr, const ship * sh, const faction * f, +nr_ship(stream *out, const seen_region * sr, const ship * sh, const faction * f, const unit * captain) { const region *r = sr->r; @@ -1912,6 +1988,7 @@ const unit * captain) size_t size = sizeof(buffer) - 1; int bytes; char ch; + FILE * F = fstream_file(out); rnl(F); @@ -1975,11 +2052,11 @@ const unit * captain) *bufp = 0; rparagraph(F, buffer, 2, 0, 0); - nr_curses(F, f, sh, TYP_SHIP, 4); + nr_curses(out, 4, f, TYP_SHIP, sh); } static void -nr_building(FILE * F, const seen_region * sr, const building * b, +nr_building(stream *out, const seen_region * sr, const building * b, const faction * f) { int i, bytes; @@ -1988,6 +2065,7 @@ const faction * f) char buffer[8192], *bufp = buffer; message *msg; size_t size = sizeof(buffer) - 1; + FILE * F = fstream_file(out); rnl(F); @@ -2052,7 +2130,8 @@ const faction * f) if (sr->mode < see_lighthouse) return; - nr_curses(F, f, b, TYP_BUILDING, 4); + i = 0; + nr_curses(out, 4, f, TYP_BUILDING, b); } static void nr_paragraph(FILE * F, message * m, faction * f) @@ -2083,9 +2162,10 @@ const char *charset) attrib *a; message *m; unsigned char op; - int bytes, ix = want(O_STATISTICS); + int maxh, bytes, ix = want(O_STATISTICS); int wants_stats = (f->options & ix); FILE *F = fopen(filename, "wt"); + stream out = { 0 }; seen_region *sr = NULL; char buf[8192]; char *bufp; @@ -2109,6 +2189,8 @@ const char *charset) perror(filename); return -1; } + fstream_init(&out, F); + if (utf8) { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; fwrite(utf8_bom, 1, 3, F); @@ -2214,266 +2296,264 @@ const char *charset) msg_release(m); centre(F, buf, true); } - { - int maxh = maxheroes(f); - if (maxh) { - message *msg = - msg_message("nr_heroes", "units maxunits", countheroes(f), maxh); - nr_render(msg, f->locale, buf, sizeof(buf), f); - msg_release(msg); - centre(F, buf, true); - } - } + maxh = maxheroes(f); + if (maxh) { + message *msg = + msg_message("nr_heroes", "units maxunits", countheroes(f), maxh); + nr_render(msg, f->locale, buf, sizeof(buf), f); + msg_release(msg); + centre(F, buf, true); + } - if (f->items != NULL) { - message *msg = msg_message("nr_claims", "items", f->items); - nr_render(msg, f->locale, buf, sizeof(buf), f); - msg_release(msg); - rnl(F); - centre(F, buf, true); - } + if (f->items != NULL) { + message *msg = msg_message("nr_claims", "items", f->items); + nr_render(msg, f->locale, buf, sizeof(buf), f); + msg_release(msg); + rnl(F); + centre(F, buf, true); + } - /* Insekten-Winter-Warnung */ - if (f->race == get_race(RC_INSECT)) { - if (thisseason == 0) { - centre(F, LOC(f->locale, "nr_insectwinter"), true); - rnl(F); - } - else { - if (nextseason == 0) { - centre(F, LOC(f->locale, "nr_insectfall"), true); - rnl(F); - } - } - } + /* Insekten-Winter-Warnung */ + if (f->race == get_race(RC_INSECT)) { + if (thisseason == 0) { + centre(F, LOC(f->locale, "nr_insectwinter"), true); + rnl(F); + } + else { + if (nextseason == 0) { + centre(F, LOC(f->locale, "nr_insectfall"), true); + rnl(F); + } + } + } - bufp = buf; - size = sizeof(buf) - 1; - bytes = _snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - for (op = 0; op != MAXOPTIONS; op++) { - if (f->options & want(op) && options[op]) { - bytes = (int)strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, LOC(f->locale, options[op]), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + bufp = buf; + size = sizeof(buf) - 1; + bytes = _snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + for (op = 0; op != MAXOPTIONS; op++) { + if (f->options & want(op) && options[op]) { + bytes = (int)strlcpy(bufp, " ", size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + bytes = (int)strlcpy(bufp, LOC(f->locale, options[op]), size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); - flag++; - } - } - if (flag > 0) { - rnl(F); - *bufp = 0; - centre(F, buf, true); - } + flag++; + } + } + if (flag > 0) { + rnl(F); + *bufp = 0; + centre(F, buf, true); + } - rp_messages(F, f->msgs, f, 0, true); - rp_battles(F, f); - a = a_find(f->attribs, &at_reportspell); - if (a) { - rnl(F); - centre(F, LOC(f->locale, "section_newspells"), true); - while (a && a->type == &at_reportspell) { - spellbook_entry *sbe = (spellbook_entry *)a->data.v; - nr_spell(F, sbe, f->locale); - a = a->next; - } - } + rp_messages(F, f->msgs, f, 0, true); + rp_battles(F, f); + a = a_find(f->attribs, &at_reportspell); + if (a) { + rnl(F); + centre(F, LOC(f->locale, "section_newspells"), true); + while (a && a->type == &at_reportspell) { + spellbook_entry *sbe = (spellbook_entry *)a->data.v; + nr_spell(F, sbe, f->locale); + a = a->next; + } + } - ch = 0; - for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; - a = a->next) { - const potion_type *ptype = - resource2potion(((const item_type *)a->data.v)->rtype); - const char *description = NULL; - if (ptype != NULL) { - const char *pname = resourcename(ptype->itype->rtype, 0); + ch = 0; + for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; + a = a->next) { + const potion_type *ptype = + resource2potion(((const item_type *)a->data.v)->rtype); + const char *description = NULL; + if (ptype != NULL) { + const char *pname = resourcename(ptype->itype->rtype, 0); - if (ch == 0) { - rnl(F); - centre(F, LOC(f->locale, "section_newpotions"), true); - ch = 1; - } + if (ch == 0) { + rnl(F); + centre(F, LOC(f->locale, "section_newpotions"), true); + ch = 1; + } - rnl(F); - centre(F, LOC(f->locale, pname), true); - _snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), - ptype->level); - centre(F, buf, true); - rnl(F); + rnl(F); + centre(F, LOC(f->locale, pname), true); + _snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), + ptype->level); + centre(F, buf, true); + rnl(F); - bufp = buf; - size = sizeof(buf) - 1; - bytes = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + bufp = buf; + size = sizeof(buf) - 1; + bytes = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); - if (ptype->itype->construction) { - requirement *m = ptype->itype->construction->materials; - while (m->number) { - bytes = - (int)strlcpy(bufp, LOC(f->locale, resourcename(m->rtype, 0)), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - ++m; - if (m->number) - bytes = (int)strlcpy(bufp, ", ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - } - } - *bufp = 0; - centre(F, buf, true); - rnl(F); - if (description == NULL) { - const char *potiontext = mkname("potion", pname); - description = LOC(f->locale, potiontext); - } - centre(F, description, true); - } - } - rnl(F); - centre(F, LOC(f->locale, "nr_alliances"), false); - rnl(F); + if (ptype->itype->construction) { + requirement *m = ptype->itype->construction->materials; + while (m->number) { + bytes = + (int)strlcpy(bufp, LOC(f->locale, resourcename(m->rtype, 0)), size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + ++m; + if (m->number) + bytes = (int)strlcpy(bufp, ", ", size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + } + } + *bufp = 0; + centre(F, buf, true); + rnl(F); + if (description == NULL) { + const char *potiontext = mkname("potion", pname); + description = LOC(f->locale, potiontext); + } + centre(F, description, true); + } + } + rnl(F); + centre(F, LOC(f->locale, "nr_alliances"), false); + rnl(F); - allies(F, f); + allies(F, f); - rpline(F); + rpline(F); - anyunits = 0; + anyunits = 0; - for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { - sr = find_seen(ctx->seen, r); - } - for (; sr != NULL; sr = sr->next) { - region *r = sr->r; - int stealthmod = stealth_modifier(sr->mode); - building *b = r->buildings; - ship *sh = r->ships; + for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { + sr = find_seen(ctx->seen, r); + } + for (; sr != NULL; sr = sr->next) { + region *r = sr->r; + int stealthmod = stealth_modifier(sr->mode); + building *b = r->buildings; + ship *sh = r->ships; - if (sr->mode < see_lighthouse) - continue; - /* Beschreibung */ + if (sr->mode < see_lighthouse) + continue; + /* Beschreibung */ - if (sr->mode == see_unit) { - anyunits = 1; - describe(F, sr, f); - if (markets_module() && r->land) { - const item_type *lux = r_luxury(r); - const item_type *herb = r->land->herbtype; - message *m = 0; - if (herb && lux) { - m = msg_message("nr_market_info_p", "p1 p2", - lux ? lux->rtype : 0, herb ? herb->rtype : 0); - } - else if (lux || herb) { - m = msg_message("nr_market_info_s", "p1", - lux ? lux->rtype : herb->rtype); - } - if (m) { - rnl(F); - nr_paragraph(F, m, f); - } - /* */ - } - else { - if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) { - rnl(F); - prices(F, r, f); - } - } - guards(F, r, f); - durchreisende(F, r, f); - } - else { - if (sr->mode == see_far) { - describe(F, sr, f); - guards(F, r, f); - durchreisende(F, r, f); - } - else if (sr->mode == see_lighthouse) { - describe(F, sr, f); - durchreisende(F, r, f); - } - else { - describe(F, sr, f); - durchreisende(F, r, f); - } - } - /* Statistik */ + if (sr->mode == see_unit) { + anyunits = 1; + describe(&out, sr, f); + if (markets_module() && r->land) { + const item_type *lux = r_luxury(r); + const item_type *herb = r->land->herbtype; + message *m = 0; + if (herb && lux) { + m = msg_message("nr_market_info_p", "p1 p2", + lux ? lux->rtype : 0, herb ? herb->rtype : 0); + } + else if (lux || herb) { + m = msg_message("nr_market_info_s", "p1", + lux ? lux->rtype : herb->rtype); + } + if (m) { + rnl(F); + nr_paragraph(F, m, f); + } + /* */ + } + else { + if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) { + rnl(F); + prices(F, r, f); + } + } + guards(F, r, f); + durchreisende(F, r, f); + } + else { + if (sr->mode == see_far) { + describe(&out, sr, f); + guards(F, r, f); + durchreisende(F, r, f); + } + else if (sr->mode == see_lighthouse) { + describe(&out, sr, f); + durchreisende(F, r, f); + } + else { + describe(&out, sr, f); + durchreisende(F, r, f); + } + } + /* Statistik */ - if (wants_stats && sr->mode == see_unit) - statistics(F, r, f); + if (wants_stats && sr->mode == see_unit) + statistics(F, r, f); - /* Nachrichten an REGION in der Region */ + /* Nachrichten an REGION in der Region */ - if (sr->mode == see_unit || sr->mode == see_travel) { - // TODO: Bug 2073 - message_list *mlist = r_getmessages(r, f); - rp_messages(F, r->msgs, f, 0, true); - if (mlist) - rp_messages(F, mlist, f, 0, true); - } + if (sr->mode == see_unit || sr->mode == see_travel) { + // TODO: Bug 2073 + message_list *mlist = r_getmessages(r, f); + rp_messages(F, r->msgs, f, 0, true); + if (mlist) + rp_messages(F, mlist, f, 0, true); + } - /* report all units. they are pre-sorted in an efficient manner */ - u = r->units; - while (b) { - while (b && (!u || u->building != b)) { - nr_building(F, sr, b, f); - b = b->next; - } - if (b) { - nr_building(F, sr, b, f); - while (u && u->building == b) { - nr_unit(F, f, u, 6, sr->mode); - u = u->next; - } - b = b->next; - } - } - while (u && !u->ship) { - if (stealthmod > INT_MIN) { - if (u->faction == f || cansee(f, r, u, stealthmod)) { - nr_unit(F, f, u, 4, sr->mode); - } - } - assert(!u->building); - u = u->next; - } - while (sh) { - while (sh && (!u || u->ship != sh)) { - nr_ship(F, sr, sh, f, NULL); - sh = sh->next; - } - if (sh) { - nr_ship(F, sr, sh, f, u); - while (u && u->ship == sh) { - nr_unit(F, f, u, 6, sr->mode); - u = u->next; - } - sh = sh->next; - } - } + /* report all units. they are pre-sorted in an efficient manner */ + u = r->units; + while (b) { + while (b && (!u || u->building != b)) { + nr_building(&out, sr, b, f); + b = b->next; + } + if (b) { + nr_building(&out, sr, b, f); + while (u && u->building == b) { + nr_unit(&out, f, u, 6, sr->mode); + u = u->next; + } + b = b->next; + } + } + while (u && !u->ship) { + if (stealthmod > INT_MIN) { + if (u->faction == f || cansee(f, r, u, stealthmod)) { + nr_unit(&out, f, u, 4, sr->mode); + } + } + assert(!u->building); + u = u->next; + } + while (sh) { + while (sh && (!u || u->ship != sh)) { + nr_ship(&out, sr, sh, f, NULL); + sh = sh->next; + } + if (sh) { + nr_ship(&out, sr, sh, f, u); + while (u && u->ship == sh) { + nr_unit(&out, f, u, 6, sr->mode); + u = u->next; + } + sh = sh->next; + } + } - assert(!u); + assert(!u); - rnl(F); - rpline(F); - } - if (!is_monsters(f)) { - if (!anyunits) { - rnl(F); - rparagraph(F, LOC(f->locale, "nr_youaredead"), 0, 2, 0); - } - else { - list_address(F, f, ctx->addresses); - } - } - fclose(F); - return 0; + rnl(F); + rpline(F); + } + if (!is_monsters(f)) { + if (!anyunits) { + rnl(F); + rparagraph(F, LOC(f->locale, "nr_youaredead"), 0, 2, 0); + } + else { + list_address(F, f, ctx->addresses); + } + } + fstream_done(&out); + return 0; } void base36conversion(void) diff --git a/storage b/storage index bcc2874cf..d2b5770a0 160000 --- a/storage +++ b/storage @@ -1 +1 @@ -Subproject commit bcc2874cf289a1d0fc9cc79ff3ed271403b2e24c +Subproject commit d2b5770a003a0b0233510e44b66defa8052fa0e6 From 53a452e4ba747bc8050160468eed961f0ebf98f9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 12 May 2015 19:57:08 -0700 Subject: [PATCH 3/6] more conversions to filestream --- src/report.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/report.c b/src/report.c index 6182429ca..80df7b13a 100644 --- a/src/report.c +++ b/src/report.c @@ -860,7 +860,7 @@ static void rp_battles(FILE * F, faction * f) } } -static void prices(FILE * F, const region * r, const faction * f) +static void prices(stream *out, const region * r, const faction * f) { const luxury_type *sale = NULL; struct demand *dmd; @@ -939,8 +939,7 @@ static void prices(FILE * F, const region * r, const faction * f) } /* Schreibe Paragraphen */ *bufp = 0; - rparagraph(F, buf, 0, 0, 0); - + paragraph(out, buf, 0, 0, 0); } bool see_border(const connection * b, const faction * f, const region * r) @@ -986,7 +985,6 @@ static void describe(stream *out, const seen_region * sr, faction * f) char *bufp = buf; size_t size = sizeof(buf); int bytes; - FILE * F = fstream_file(out); for (d = 0; d != MAXDIRECTIONS; d++) { /* Nachbarregionen, die gesehen werden, ermitteln */ @@ -1273,9 +1271,9 @@ static void describe(stream *out, const seen_region * sr, faction * f) dh = 1; } } - rnl(F); + newline(out); *bufp = 0; - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); if (sr->mode == see_unit && is_astral(r) && !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { @@ -1308,9 +1306,9 @@ static void describe(stream *out, const seen_region * sr, faction * f) WARN_STATIC_BUFFER(); free_regionlist(rl); /* Schreibe Paragraphen */ - rnl(F); + newline(out); *bufp = 0; - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); } } @@ -1322,11 +1320,11 @@ static void describe(stream *out, const seen_region * sr, faction * f) a = a_find(r->attribs, &at_reduceproduction); if (a) { const char *str = LOC(f->locale, "nr_reduced_production"); - rparagraph(F, str, 0, 0, 0); + paragraph(out, str, 0, 0, 0); } if (edges) - rnl(F); + newline(out); for (e = edges; e; e = e->next) { bool first = true; message *msg; @@ -1359,7 +1357,7 @@ static void describe(stream *out, const seen_region * sr, faction * f) WARN_STATIC_BUFFER(); *bufp = 0; - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); } if (edges) { while (edges) { @@ -1988,9 +1986,8 @@ const unit * captain) size_t size = sizeof(buffer) - 1; int bytes; char ch; - FILE * F = fstream_file(out); - rnl(F); + newline(out); if (captain && captain->faction == f) { int n = 0, p = 0; @@ -2050,7 +2047,7 @@ const unit * captain) WARN_STATIC_BUFFER(); } *bufp = 0; - rparagraph(F, buffer, 2, 0, 0); + paragraph(out, buffer, 2, 0, 0); nr_curses(out, 4, f, TYP_SHIP, sh); } @@ -2065,9 +2062,8 @@ const faction * f) char buffer[8192], *bufp = buffer; message *msg; size_t size = sizeof(buffer) - 1; - FILE * F = fstream_file(out); - rnl(F); + newline(out); if (f) lang = f->locale; @@ -2125,7 +2121,7 @@ const faction * f) WARN_STATIC_BUFFER(); } *bufp = 0; - rparagraph(F, buffer, 2, 0, 0); + paragraph(out, buffer, 2, 0, 0); if (sr->mode < see_lighthouse) return; @@ -2134,11 +2130,12 @@ const faction * f) nr_curses(out, 4, f, TYP_BUILDING, b); } -static void nr_paragraph(FILE * F, message * m, faction * f) +static void nr_paragraph(stream *out, message * m, faction * f) { int bytes; char buf[4096], *bufp = buf; size_t size = sizeof(buf) - 1; + FILE * F = fstream_file(out); bytes = (int)nr_render(m, f->locale, bufp, size, f); if (wrptr(&bufp, &size, bytes) != 0) @@ -2455,14 +2452,14 @@ const char *charset) } if (m) { rnl(F); - nr_paragraph(F, m, f); + nr_paragraph(&out, m, f); } /* */ } else { if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) { - rnl(F); - prices(F, r, f); + newline(&out); + prices(&out, r, f); } } guards(F, r, f); From 06ff88e78374924e77baf31daf2ae945edb0d7a9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 12 May 2015 20:36:00 -0700 Subject: [PATCH 4/6] use filestream for report_template, too. --- src/report.c | 437 +++++++++++++++++++++------------------------------ 1 file changed, 176 insertions(+), 261 deletions(-) diff --git a/src/report.c b/src/report.c index 80df7b13a..02549f084 100644 --- a/src/report.c +++ b/src/report.c @@ -116,24 +116,13 @@ static char *gamedate_season(const struct locale *lang) return buf; } -void rpc(FILE * F, char c, size_t num) -{ - while (num > 0) { - putc(c, F); - num--; - } -} - -void rnl(FILE * F) -{ - fputc('\n', F); -} - void newline(stream *out) { sputs("", out); } -static void centre(FILE * F, const char *s, bool breaking) +static const char *spaces = " "; + +static void centre(stream *out, const char *s, bool breaking) { /* Bei Namen die genau 80 Zeichen lang sind, kann es hier Probleme * geben. Seltsamerweise wird i dann auf MAXINT oder aehnlich @@ -145,85 +134,22 @@ static void centre(FILE * F, const char *s, bool breaking) sparagraph(&SP, s, 0, 0); T = SP; while (SP) { - centre(F, SP->s, false); + centre(out, SP->s, false); SP = SP->next; } freestrlist(T); } else { - rpc(F, ' ', (REPORTWIDTH - strlen(s) + 1) / 2); - fputs(s, F); - putc('\n', F); + swrite(spaces, sizeof(char), (REPORTWIDTH - strlen(s) + 1) / 2, out); + sputs(s, out); + newline(out); } } -static void -rparagraph(FILE * F, const char *str, ptrdiff_t indent, int hanging_indent, -char mark) -{ - static const char *spaces = " "; - size_t length = REPORTWIDTH; - const char *end, *begin; - - if (!str) return; - /* find out if there's a mark + indent already encoded in the string. */ - if (!mark) { - const char *x = str; - while (*x == ' ') - ++x; - indent += x - str; - if (x[0] && indent && x[1] == ' ') { - indent += 2; - mark = x[0]; - str = x + 2; - hanging_indent -= 2; - } - } - begin = end = str; - - do { - const char *last_space = begin; - - if (mark && indent >= 2) { - fwrite(spaces, sizeof(char), indent - 2, F); - fputc(mark, F); - fputc(' ', F); - mark = 0; - } - else if (begin == str) { - fwrite(spaces, sizeof(char), indent, F); - } - else { - fwrite(spaces, sizeof(char), indent + hanging_indent, F); - } - while (*end && end <= begin + length - indent) { - if (*end == ' ') { - last_space = end; - } - ++end; - } - if (*end == 0) - last_space = end; - if (last_space == begin) { - /* there was no space in this line. clip it */ - last_space = end; - } - fwrite(begin, sizeof(char), last_space - begin, F); - begin = last_space; - while (*begin == ' ') { - ++begin; - } - if (begin > end) - begin = end; - fputc('\n', F); - } while (*begin); -} - static void paragraph(stream *out, const char *str, ptrdiff_t indent, int hanging_indent, char marker) { - static const char *spaces = " "; size_t length = REPORTWIDTH; const char *end, *begin, *mark = 0; @@ -299,7 +225,7 @@ static size_t write_spell_modifier(spell * sp, int flag, const char * str, bool return 0; } -static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) +static void nr_spell(stream *out, spellbook_entry * sbe, const struct locale *lang) { int bytes, k, itemanz, costtyp; char buf[4096]; @@ -308,11 +234,11 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) spell * sp = sbe->sp; const char *params = sp->parameter; - rnl(F); - centre(F, spell_name(sp, lang), true); - rnl(F); - rparagraph(F, LOC(lang, "nr_spell_description"), 0, 0, 0); - rparagraph(F, spell_info(sp, lang), 2, 0, 0); + newline(out); + centre(out, spell_name(sp, lang), true); + newline(out); + paragraph(out, LOC(lang, "nr_spell_description"), 0, 0, 0); + paragraph(out, spell_info(sp, lang), 2, 0, 0); bytes = (int)strlcpy(bufp, LOC(lang, "nr_spell_type"), size); if (wrptr(&bufp, &size, bytes) != 0) @@ -337,15 +263,15 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); *bufp = 0; - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); sprintf(buf, "%s %d", LOC(lang, "nr_spell_level"), sbe->level); - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); sprintf(buf, "%s %d", LOC(lang, "nr_spell_rank"), sp->rank); - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); - rparagraph(F, LOC(lang, "nr_spell_components"), 0, 0, 0); + paragraph(out, LOC(lang, "nr_spell_components"), 0, 0, 0); for (k = 0; sp->components[k].type; ++k) { const resource_type *rtype = sp->components[k].type; itemanz = sp->components[k].amount; @@ -372,7 +298,7 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) } } *bufp = 0; - rparagraph(F, buf, 2, 2, '-'); + paragraph(out, buf, 2, 2, '-'); } } @@ -406,9 +332,8 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) } } *bufp = 0; - rparagraph(F, buf, 0, 0, 0); - - rparagraph(F, LOC(lang, "nr_spell_syntax"), 0, 0, 0); + paragraph(out, buf, 0, 0, 0); + paragraph(out, LOC(lang, "nr_spell_syntax"), 0, 0, 0); bufp = buf; size = sizeof(buf) - 1; @@ -575,8 +500,8 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) } } *bufp = 0; - rparagraph(F, buf, 2, 0, 0); - rnl(F); + paragraph(out, buf, 2, 0, 0); + newline(out); } void sparagraph(strlist ** SP, const char *s, int indent, char mark) @@ -740,12 +665,12 @@ static void nr_curses(stream *out, int indent, const faction *viewer, objtype_t nr_curses_i(out, indent, viewer, typ, obj, a); } -static void rps_nowrap(FILE * F, const char *s) +static void rps_nowrap(stream *out, const char *s) { const char *x = s; size_t indent = 0; - if (!x) return; + if (!x || !*x) return; while (*x++ == ' '); indent = x - s - 1; @@ -758,7 +683,7 @@ static void rps_nowrap(FILE * F, const char *s) if (!x) x = s + strlen(s); } - rpc(F, *s++, 1); + swrite(s++, sizeof(char), 1, out); } } @@ -805,10 +730,11 @@ nr_unit(stream *out, const faction * f, const unit * u, int indent, int mode) } static void -rp_messages(FILE * F, message_list * msgs, faction * viewer, int indent, +rp_messages(stream *out, message_list * msgs, faction * viewer, int indent, bool categorized) { nrsection *section; + if (!msgs) return; for (section = sections; section; section = section->next) { @@ -823,15 +749,15 @@ bool categorized) const char *section_title; char cat_identifier[24]; - rnl(F); + newline(out); sprintf(cat_identifier, "section_%s", section->name); section_title = LOC(viewer->locale, cat_identifier); - centre(F, section_title, true); - rnl(F); + centre(out, section_title, true); + newline(out); k = 1; } nr_render(m->msg, viewer->locale, lbuf, sizeof(lbuf), viewer); - rparagraph(F, lbuf, indent, 2, 0); + paragraph(out, lbuf, indent, 2, 0); } m = m->next; } @@ -840,21 +766,21 @@ bool categorized) } } -static void rp_battles(FILE * F, faction * f) +static void rp_battles(stream *out, faction * f) { if (f->battles != NULL) { struct bmsg *bm = f->battles; - rnl(F); - centre(F, LOC(f->locale, "section_battle"), false); - rnl(F); + newline(out); + centre(out, LOC(f->locale, "section_battle"), false); + newline(out); while (bm) { char buf[256]; RENDER(f, buf, sizeof(buf), ("battle::header", "region", bm->r)); - rnl(F); - centre(F, buf, true); - rnl(F); - rp_messages(F, bm->msgs, f, 0, false); + newline(out); + centre(out, buf, true); + newline(out); + rp_messages(out, bm->msgs, f, 0, false); bm = bm->next; } } @@ -1369,7 +1295,7 @@ static void describe(stream *out, const seen_region * sr, faction * f) } } -static void statistics(FILE * F, const region * r, const faction * f) +static void statistics(stream *out, const region * r, const faction * f) { const unit *u; int number = 0, p = rpeasants(r); @@ -1387,19 +1313,19 @@ static void statistics(FILE * F, const region * r, const faction * f) } } /* print */ - rnl(F); + newline(out); m = msg_message("nr_stat_header", "region", r); nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m); - rparagraph(F, buf, 0, 0, 0); - rnl(F); + paragraph(out, buf, 0, 0, 0); + newline(out); /* Region */ if (skill_enabled(SK_ENTERTAINMENT) && fval(r->terrain, LAND_REGION) && rmoney(r)) { m = msg_message("nr_stat_maxentertainment", "max", entertainmoney(r)); nr_render(m, f->locale, buf, sizeof(buf), f); - rparagraph(F, buf, 2, 2, 0); + paragraph(out, buf, 2, 2, 0); msg_release(m); } if (production(r) && (!fval(r->terrain, SEA_REGION) @@ -1412,14 +1338,14 @@ static void statistics(FILE * F, const region * r, const faction * f) m = msg_message("nr_stat_salary", "max", wage(r, f, f->race, turn + 1)); } nr_render(m, f->locale, buf, sizeof(buf), f); - rparagraph(F, buf, 2, 2, 0); + paragraph(out, buf, 2, 2, 0); msg_release(m); } if (p) { m = msg_message("nr_stat_recruits", "max", p / RECRUITFRACTION); nr_render(m, f->locale, buf, sizeof(buf), f); - rparagraph(F, buf, 2, 2, 0); + paragraph(out, buf, 2, 2, 0); msg_release(m); if (!markets_module()) { @@ -1430,14 +1356,14 @@ static void statistics(FILE * F, const region * r, const faction * f) m = msg_message("nr_stat_luxuries", "max", p / TRADE_FRACTION); } nr_render(m, f->locale, buf, sizeof(buf), f); - rparagraph(F, buf, 2, 2, 0); + paragraph(out, buf, 2, 2, 0); msg_release(m); } if (r->land->ownership) { m = msg_message("nr_stat_morale", "morale", r->land->morale); nr_render(m, f->locale, buf, sizeof(buf), f); - rparagraph(F, buf, 2, 2, 0); + paragraph(out, buf, 2, 2, 0); msg_release(m); } @@ -1446,19 +1372,19 @@ static void statistics(FILE * F, const region * r, const faction * f) m = msg_message("nr_stat_people", "max", number); nr_render(m, f->locale, buf, sizeof(buf), f); - rparagraph(F, buf, 2, 2, 0); + paragraph(out, buf, 2, 2, 0); msg_release(m); for (itm = items; itm; itm = itm->next) { sprintf(buf, "%s: %d", LOC(f->locale, resourcename(itm->type->rtype, GR_PLURAL)), itm->number); - rparagraph(F, buf, 2, 2, 0); + paragraph(out, buf, 2, 2, 0); } while (items) i_free(i_remove(&items, items)); } -static void durchreisende(FILE * F, const region * r, const faction * f) +static void durchreisende(stream *out, const region * r, const faction * f) { if (fval(r, RF_TRAVELUNIT)) { attrib *abegin = a_find(r->attribs, &at_travelunit), *a; @@ -1484,7 +1410,7 @@ static void durchreisende(FILE * F, const region * r, const faction * f) } /* Auflisten. */ - rnl(F); + newline(out); for (a = abegin; a && a->type == &at_travelunit; a = a->next) { unit *u = (unit *)a->data.v; @@ -1546,7 +1472,7 @@ static void durchreisende(FILE * F, const region * r, const faction * f) WARN_STATIC_BUFFER(); } *bufp = 0; - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); } } @@ -1582,6 +1508,7 @@ report_template(const char *filename, report_context * ctx, const char *charset) faction *f = ctx->f; region *r; FILE *F = fopen(filename, "wt"); + stream strm = { 0 }, *out = &strm; seen_region *sr = NULL; char buf[8192], *bufp; size_t size; @@ -1592,31 +1519,28 @@ report_template(const char *filename, report_context * ctx, const char *charset) perror(filename); return -1; } + fstream_init(&strm, F); if (utf8) { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; - fwrite(utf8_bom, 1, 3, F); + swrite(utf8_bom, 1, 3, out); } - rps_nowrap(F, ""); - rnl(F); - rps_nowrap(F, LOC(f->locale, "nr_template")); - rnl(F); - rps_nowrap(F, ""); - rnl(F); + newline(out); + rps_nowrap(out, LOC(f->locale, "nr_template")); + newline(out); + newline(out); sprintf(buf, "%s %s \"%s\"", LOC(f->locale, "ERESSEA"), factionid(f), LOC(f->locale, "enterpasswd")); - rps_nowrap(F, buf); - rnl(F); - - rps_nowrap(F, ""); - rnl(F); + rps_nowrap(out, buf); + newline(out); + newline(out); sprintf(buf, "; ECHECK -l -w4 -r%d -v%s", f->race->recruitcost, ECHECK_VERSION); /* -v3.4: ECheck Version 3.4.x */ - rps_nowrap(F, buf); - rnl(F); + rps_nowrap(out, buf); + newline(out); for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { sr = find_seen(ctx->seen, r); @@ -1639,8 +1563,7 @@ report_template(const char *filename, report_context * ctx, const char *charset) pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl, r); - rps_nowrap(F, ""); - rnl(F); + newline(out); if (pl && pl->id != 0) { sprintf(buf, "%s %d,%d,%d ; %s", LOC(f->locale, parameters[P_REGION]), nx, ny, pl->id, rname(r, f->locale)); @@ -1649,13 +1572,12 @@ report_template(const char *filename, report_context * ctx, const char *charset) sprintf(buf, "%s %d,%d ; %s", LOC(f->locale, parameters[P_REGION]), nx, ny, rname(r, f->locale)); } - rps_nowrap(F, buf); - rnl(F); + rps_nowrap(out, buf); + newline(out); sprintf(buf, "; ECheck Lohn %d", wage(r, f, f->race, turn + 1)); - rps_nowrap(F, buf); - rnl(F); - rps_nowrap(F, ""); - rnl(F); + rps_nowrap(out, buf); + newline(out); + newline(out); } dh = 1; @@ -1702,15 +1624,15 @@ report_template(const char *filename, report_context * ctx, const char *charset) WARN_STATIC_BUFFER(); *bufp = 0; - rps_nowrap(F, buf); - rnl(F); + rps_nowrap(out, buf); + newline(out); for (ord = u->old_orders; ord; ord = ord->next) { /* this new order will replace the old defaults */ strcpy(buf, " "); write_order(ord, buf + 2, sizeof(buf) - 2); - rps_nowrap(F, buf); - rnl(F); + rps_nowrap(out, buf); + newline(out); } for (ord = u->orders; ord; ord = ord->next) { if (u->old_orders && is_repeated(ord)) @@ -1718,8 +1640,8 @@ report_template(const char *filename, report_context * ctx, const char *charset) if (is_persistent(ord)) { strcpy(buf, " "); write_order(ord, buf + 2, sizeof(buf) - 2); - rps_nowrap(F, buf); - rnl(F); + rps_nowrap(out, buf); + newline(out); } } @@ -1728,12 +1650,11 @@ report_template(const char *filename, report_context * ctx, const char *charset) } } } - rps_nowrap(F, ""); - rnl(F); + newline(out); strcpy(buf, LOC(f->locale, parameters[P_NEXT])); - rps_nowrap(F, buf); - rnl(F); - fclose(F); + rps_nowrap(out, buf); + newline(out); + fstream_done(&strm); return 0; } @@ -1830,7 +1751,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size) *bufp = 0; } -static void allies(FILE * F, const faction * f) +static void allies(stream *out, const faction * f) { const group *g = f->groups; char buf[16384]; @@ -1841,8 +1762,8 @@ static void allies(FILE * F, const faction * f) bytes = _snprintf(buf, size, "%s ", LOC(f->locale, "faction_help")); size -= bytes; show_allies(f, f->allies, buf + bytes, size); - rparagraph(F, buf, 0, 0, 0); - rnl(F); + paragraph(out, buf, 0, 0, 0); + newline(out); } while (g) { @@ -1852,25 +1773,21 @@ static void allies(FILE * F, const faction * f) bytes = _snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help")); size -= bytes; show_allies(f, g->allies, buf + bytes, size); - rparagraph(F, buf, 0, 0, 0); - rnl(F); + paragraph(out, buf, 0, 0, 0); + newline(out); } g = g->next; } } -static void guards(FILE * F, const region * r, const faction * see) +static void guards(stream *out, const region * r, const faction * see) { /* die Partei see sieht dies; wegen * "unbekannte Partei", wenn man es selbst ist... */ - faction *guardians[512]; - int nextguard = 0; - unit *u; int i; - bool tarned = false; /* Bewachung */ @@ -1930,29 +1847,29 @@ static void guards(FILE * F, const region * r, const faction * see) bytes = (int)strlcpy(bufp, LOC(see->locale, "nr_guarding_postfix"), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - rnl(F); + newline(out); *bufp = 0; - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); } } -static void rpline(FILE * F) +static void rpline(stream *out) { static char line[REPORTWIDTH + 1]; if (line[0] != '-') { memset(line, '-', sizeof(line)); line[REPORTWIDTH] = '\n'; } - fwrite(line, sizeof(char), sizeof(line), F); + swrite(line, sizeof(char), sizeof(line), out); } -static void list_address(FILE * F, const faction * uf, quicklist * seenfactions) +static void list_address(stream *out, const faction * uf, quicklist * seenfactions) { int qi = 0; quicklist *flist = seenfactions; - centre(F, LOC(uf->locale, "nr_addresses"), false); - rnl(F); + centre(out, LOC(uf->locale, "nr_addresses"), false); + newline(out); while (flist != NULL) { const faction *f = (const faction *)ql_get(flist, qi); @@ -1968,13 +1885,12 @@ static void list_address(FILE * F, const faction * uf, quicklist * seenfactions) label = 'o'; else if (alliedfaction(NULL, uf, f, HELP_ALL)) label = '+'; - rparagraph(F, buf, 4, 0, label); - + paragraph(out, buf, 4, 0, label); } ql_advance(&flist, &qi, 1); } - rnl(F); - rpline(F); + newline(out); + rpline(out); } static void @@ -2135,14 +2051,13 @@ static void nr_paragraph(stream *out, message * m, faction * f) int bytes; char buf[4096], *bufp = buf; size_t size = sizeof(buf) - 1; - FILE * F = fstream_file(out); bytes = (int)nr_render(m, f->locale, bufp, size, f); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); msg_release(m); - rparagraph(F, buf, 0, 0, 0); + paragraph(out, buf, 0, 0, 0); } int @@ -2162,7 +2077,7 @@ const char *charset) int maxh, bytes, ix = want(O_STATISTICS); int wants_stats = (f->options & ix); FILE *F = fopen(filename, "wt"); - stream out = { 0 }; + stream strm = { 0 }, *out = &strm; seen_region *sr = NULL; char buf[8192]; char *bufp; @@ -2186,7 +2101,7 @@ const char *charset) perror(filename); return -1; } - fstream_init(&out, F); + fstream_init(&strm, F); if (utf8) { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; @@ -2197,16 +2112,16 @@ const char *charset) m = msg_message("nr_header_date", "game date", game_name(), pzTime); nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m); - centre(F, buf, true); + centre(out, buf, true); - centre(F, gamedate_season(f->locale), true); - rnl(F); + centre(out, gamedate_season(f->locale), true); + newline(out); sprintf(buf, "%s, %s/%s (%s)", factionname(f), LOC(f->locale, rc_name_s(f->race, NAME_PLURAL)), LOC(f->locale, mkname("school", magic_school[f->magiegebiet])), f->email); - centre(F, buf, true); + centre(out, buf, true); if (f_get_alliance(f)) { - centre(F, alliancename(f->alliance), true); + centre(out, alliancename(f->alliance), true); } if (f->age <= 2) { @@ -2215,33 +2130,33 @@ const char *charset) ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->passw)); } RENDER(f, buf, sizeof(buf), ("newbie_password", "password", f->passw)); - rnl(F); - centre(F, buf, true); + newline(out); + centre(out, buf, true); s = locale_getstring(f->locale, "newbie_info_1"); if (s) { - rnl(F); - centre(F, s, true); + newline(out); + centre(out, s, true); } s = locale_getstring(f->locale, "newbie_info_2"); if (s) { - rnl(F); - centre(F, s, true); + newline(out); + centre(out, s, true); } if ((f->options & want(O_COMPUTER)) == 0) { f->options |= want(O_COMPUTER); s = locale_getstring(f->locale, "newbie_info_3"); if (s) { - rnl(F); - centre(F, s, true); + newline(out); + centre(out, s, true); } } } - rnl(F); + newline(out); #if SCORE_MODULE if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) { RENDER(f, buf, sizeof(buf), ("nr_score", "score average", f->score, average_score_of_age(f->age, f->age / 24 + 1))); - centre(F, buf, true); + centre(out, buf, true); } #endif #ifdef COUNT_AGAIN @@ -2273,7 +2188,7 @@ const char *charset) m = msg_message("nr_population", "population units limit", no_people, no_units, rule_faction_limit()); nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m); - centre(F, buf, true); + centre(out, buf, true); if (f->race == get_race(RC_HUMAN)) { int maxmig = count_maxmigrants(f); if (maxmig > 0) { @@ -2281,7 +2196,7 @@ const char *charset) msg_message("nr_migrants", "units maxunits", count_migrants(f), maxmig); nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m); - centre(F, buf, true); + centre(out, buf, true); } } if (f_get_alliance(f)) { @@ -2291,7 +2206,7 @@ const char *charset) turn - f->alliance_joindate); nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m); - centre(F, buf, true); + centre(out, buf, true); } maxh = maxheroes(f); if (maxh) { @@ -2299,27 +2214,27 @@ const char *charset) msg_message("nr_heroes", "units maxunits", countheroes(f), maxh); nr_render(msg, f->locale, buf, sizeof(buf), f); msg_release(msg); - centre(F, buf, true); + centre(out, buf, true); } if (f->items != NULL) { message *msg = msg_message("nr_claims", "items", f->items); nr_render(msg, f->locale, buf, sizeof(buf), f); msg_release(msg); - rnl(F); - centre(F, buf, true); + newline(out); + centre(out, buf, true); } /* Insekten-Winter-Warnung */ if (f->race == get_race(RC_INSECT)) { if (thisseason == 0) { - centre(F, LOC(f->locale, "nr_insectwinter"), true); - rnl(F); + centre(out, LOC(f->locale, "nr_insectwinter"), true); + newline(out); } else { if (nextseason == 0) { - centre(F, LOC(f->locale, "nr_insectfall"), true); - rnl(F); + centre(out, LOC(f->locale, "nr_insectfall"), true); + newline(out); } } } @@ -2342,20 +2257,20 @@ const char *charset) } } if (flag > 0) { - rnl(F); + newline(out); *bufp = 0; - centre(F, buf, true); + centre(out, buf, true); } - rp_messages(F, f->msgs, f, 0, true); - rp_battles(F, f); + rp_messages(out, f->msgs, f, 0, true); + rp_battles(out, f); a = a_find(f->attribs, &at_reportspell); if (a) { - rnl(F); - centre(F, LOC(f->locale, "section_newspells"), true); + newline(out); + centre(out, LOC(f->locale, "section_newspells"), true); while (a && a->type == &at_reportspell) { spellbook_entry *sbe = (spellbook_entry *)a->data.v; - nr_spell(F, sbe, f->locale); + nr_spell(out, sbe, f->locale); a = a->next; } } @@ -2370,17 +2285,17 @@ const char *charset) const char *pname = resourcename(ptype->itype->rtype, 0); if (ch == 0) { - rnl(F); - centre(F, LOC(f->locale, "section_newpotions"), true); + newline(out); + centre(out, LOC(f->locale, "section_newpotions"), true); ch = 1; } - rnl(F); - centre(F, LOC(f->locale, pname), true); + newline(out); + centre(out, LOC(f->locale, pname), true); _snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), ptype->level); - centre(F, buf, true); - rnl(F); + centre(out, buf, true); + newline(out); bufp = buf; size = sizeof(buf) - 1; @@ -2403,22 +2318,22 @@ const char *charset) } } *bufp = 0; - centre(F, buf, true); - rnl(F); + centre(out, buf, true); + newline(out); if (description == NULL) { const char *potiontext = mkname("potion", pname); description = LOC(f->locale, potiontext); } - centre(F, description, true); + centre(out, description, true); } } - rnl(F); - centre(F, LOC(f->locale, "nr_alliances"), false); - rnl(F); + newline(out); + centre(out, LOC(f->locale, "nr_alliances"), false); + newline(out); - allies(F, f); + allies(out, f); - rpline(F); + rpline(out); anyunits = 0; @@ -2437,7 +2352,7 @@ const char *charset) if (sr->mode == see_unit) { anyunits = 1; - describe(&out, sr, f); + describe(out, sr, f); if (markets_module() && r->land) { const item_type *lux = r_luxury(r); const item_type *herb = r->land->herbtype; @@ -2451,61 +2366,61 @@ const char *charset) lux ? lux->rtype : herb->rtype); } if (m) { - rnl(F); - nr_paragraph(&out, m, f); + newline(out); + nr_paragraph(out, m, f); } /* */ } else { if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) { - newline(&out); - prices(&out, r, f); + newline(out); + prices(out, r, f); } } - guards(F, r, f); - durchreisende(F, r, f); + guards(out, r, f); + durchreisende(out, r, f); } else { if (sr->mode == see_far) { - describe(&out, sr, f); - guards(F, r, f); - durchreisende(F, r, f); + describe(out, sr, f); + guards(out, r, f); + durchreisende(out, r, f); } else if (sr->mode == see_lighthouse) { - describe(&out, sr, f); - durchreisende(F, r, f); + describe(out, sr, f); + durchreisende(out, r, f); } else { - describe(&out, sr, f); - durchreisende(F, r, f); + describe(out, sr, f); + durchreisende(out, r, f); } } /* Statistik */ if (wants_stats && sr->mode == see_unit) - statistics(F, r, f); + statistics(out, r, f); /* Nachrichten an REGION in der Region */ if (sr->mode == see_unit || sr->mode == see_travel) { // TODO: Bug 2073 message_list *mlist = r_getmessages(r, f); - rp_messages(F, r->msgs, f, 0, true); + rp_messages(out, r->msgs, f, 0, true); if (mlist) - rp_messages(F, mlist, f, 0, true); + rp_messages(out, mlist, f, 0, true); } /* report all units. they are pre-sorted in an efficient manner */ u = r->units; while (b) { while (b && (!u || u->building != b)) { - nr_building(&out, sr, b, f); + nr_building(out, sr, b, f); b = b->next; } if (b) { - nr_building(&out, sr, b, f); + nr_building(out, sr, b, f); while (u && u->building == b) { - nr_unit(&out, f, u, 6, sr->mode); + nr_unit(out, f, u, 6, sr->mode); u = u->next; } b = b->next; @@ -2514,7 +2429,7 @@ const char *charset) while (u && !u->ship) { if (stealthmod > INT_MIN) { if (u->faction == f || cansee(f, r, u, stealthmod)) { - nr_unit(&out, f, u, 4, sr->mode); + nr_unit(out, f, u, 4, sr->mode); } } assert(!u->building); @@ -2522,13 +2437,13 @@ const char *charset) } while (sh) { while (sh && (!u || u->ship != sh)) { - nr_ship(&out, sr, sh, f, NULL); + nr_ship(out, sr, sh, f, NULL); sh = sh->next; } if (sh) { - nr_ship(&out, sr, sh, f, u); + nr_ship(out, sr, sh, f, u); while (u && u->ship == sh) { - nr_unit(&out, f, u, 6, sr->mode); + nr_unit(out, f, u, 6, sr->mode); u = u->next; } sh = sh->next; @@ -2537,19 +2452,19 @@ const char *charset) assert(!u); - rnl(F); - rpline(F); + newline(out); + rpline(out); } if (!is_monsters(f)) { if (!anyunits) { - rnl(F); - rparagraph(F, LOC(f->locale, "nr_youaredead"), 0, 2, 0); + newline(out); + paragraph(out, LOC(f->locale, "nr_youaredead"), 0, 2, 0); } else { - list_address(F, f, ctx->addresses); + list_address(out, f, ctx->addresses); } } - fstream_done(&out); + fstream_done(&strm); return 0; } From 1182059b989e36da590083f4572b9a32cc97f1a5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 13 May 2015 03:35:29 -0700 Subject: [PATCH 5/6] new submodules --- critbit | 2 +- storage | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/critbit b/critbit index a2c6fad82..b38f6f8ac 160000 --- a/critbit +++ b/critbit @@ -1 +1 @@ -Subproject commit a2c6fad825e498abc2b36c8b2ed5a1ad9acf743e +Subproject commit b38f6f8acdc2ce5b0613a4bb2ff8082051a25ac3 diff --git a/storage b/storage index d2b5770a0..48768e4be 160000 --- a/storage +++ b/storage @@ -1 +1 @@ -Subproject commit d2b5770a003a0b0233510e44b66defa8052fa0e6 +Subproject commit 48768e4bef7ff28365487e047d3b910127c716d0 From 9c7fe1d7cc56f5461e2cc88b18b1cbf769a125e0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 13 May 2015 13:12:46 +0200 Subject: [PATCH 6/6] fix gcc compilation and missing argument --- src/report.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/report.c b/src/report.c index 02549f084..44f3b0b91 100644 --- a/src/report.c +++ b/src/report.c @@ -559,10 +559,8 @@ void sparagraph(strlist ** SP, const char *s, int indent, char mark) } static void -nr_curses_i(stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a) +nr_curses_i(stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a, int self) { - int self = 0; - for (; a; a = a->next) { char buf[4096]; message *msg; @@ -662,7 +660,7 @@ static void nr_curses(stream *out, int indent, const faction *viewer, objtype_t log_error("get_attribs: invalid object type %d", typ); assert(!"invalid object type"); } - nr_curses_i(out, indent, viewer, typ, obj, a); + nr_curses_i(out, indent, viewer, typ, obj, a, self); } static void rps_nowrap(stream *out, const char *s)