From: Markus Armbruster Date: Sat, 1 Jun 2013 08:36:33 +0000 (+0200) Subject: empdump: Don't abort() on unresolvable symbols X-Git-Tag: v4.3.32~88 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=edfb80a1f7dcd6e3df58dc9eeb7ea4cfa947c586 empdump: Don't abort() on unresolvable symbols empdump flags them since commit 2a5d12b (v4.3.28), but still aborts. Avoid the abort. Signed-off-by: Markus Armbruster --- diff --git a/include/xdump.h b/include/xdump.h index 65c44f248..a3c8eb4b6 100644 --- a/include/xdump.h +++ b/include/xdump.h @@ -27,7 +27,7 @@ * xdump.h: Extended dumps * * Known contributors to this file: - * Markus Armbruster, 2008-2011 + * Markus Armbruster, 2008-2013 */ #ifndef XDUMP_H @@ -42,11 +42,13 @@ struct xdstr { natid cnum; /* dump for this country */ int divine; /* is this a deity dump? */ int human; /* dump human-readable format */ + int sloppy; /* try to cope with invalid data */ void (*pr)(char *fmt, ...) /* callback for printing dump */ ATTRIBUTE((format (printf, 1, 2))); }; -struct xdstr *xdinit(struct xdstr *, natid, int, void (*)(char *, ...)); +struct xdstr *xdinit(struct xdstr *, natid, int, int, + void (*)(char *, ...)); extern void xdhdr(struct xdstr *, char *, int); extern void xdcolhdr(struct xdstr *, struct castr[]); extern void xdflds(struct xdstr *, struct castr[], void *); diff --git a/src/lib/commands/xdump.c b/src/lib/commands/xdump.c index 8373d7b07..c0e02d981 100644 --- a/src/lib/commands/xdump.c +++ b/src/lib/commands/xdump.c @@ -189,7 +189,7 @@ xdump(void) if (!p || !*p) return RET_SYN; - xdinit(&xd, player->cnum, 0, pr); + xdinit(&xd, player->cnum, 0, 0, pr); natp = getnatp(player->cnum); type = isdigit(p[0]) ? atoi(p) : ef_byname(p); if (type < 0 || type >= EF_MAX) diff --git a/src/lib/common/xdump.c b/src/lib/common/xdump.c index a56f8116d..eace44cf9 100644 --- a/src/lib/common/xdump.c +++ b/src/lib/common/xdump.c @@ -27,7 +27,7 @@ * xdump.c: Extended dumps * * Known contributors to this file: - * Markus Armbruster, 2004-2010 + * Markus Armbruster, 2004-2013 */ /* @@ -84,15 +84,19 @@ * Initialize XD. * Translate dump for country CNUM, except when CNUM is NATID_BAD. * If HUMAN, dump in human-readable format. + * If SLOPPY, try to cope with invalid data (may result in invalid + * dump). * Dump is to be delivered through callback PR. * Return XD. */ struct xdstr * -xdinit(struct xdstr *xd, natid cnum, int human, void (*pr)(char *fmt, ...)) +xdinit(struct xdstr *xd, natid cnum, int human, int sloppy, + void (*pr)(char *fmt, ...)) { xd->cnum = cnum; xd->divine = cnum == NATID_BAD || getnatp(cnum)->nat_stat == STAT_GOD; xd->human = human; + xd->sloppy = sloppy; xd->pr = pr; return xd; } @@ -181,9 +185,10 @@ xdprsym(struct xdstr *xd, int key, int type, char *sep) { char *sym = symbol_by_value(key, ef_ptr(type, 0)); - if (CANT_HAPPEN(!sym)) + if (!sym) { + CANT_HAPPEN(!xd->sloppy); xd->pr("%s%d", sep, key); - else { + } else { xd->pr("%s", sep); xdpresc(xd, sym, INT_MAX); } diff --git a/src/util/empdump.c b/src/util/empdump.c index 1bf8d3e69..99eb3d281 100644 --- a/src/util/empdump.c +++ b/src/util/empdump.c @@ -27,7 +27,7 @@ * empdump.c: Export/import Empire game state * * Known contributors to this file: - * Markus Armbruster, 2008-2011 + * Markus Armbruster, 2008-2013 */ #include @@ -46,7 +46,7 @@ static void exit_bad_arg(char *, ...) ATTRIBUTE((noreturn, format (printf, 1, 2))); -static void dump_table(int, int); +static void dump_table(int, int, int); int main(int argc, char *argv[]) @@ -159,7 +159,7 @@ main(int argc, char *argv[]) for (i = 0; i < EF_MAX; i++) { if (!EF_IS_GAME_STATE(i)) continue; - dump_table(i, human); + dump_table(i, human, !verified); } if (fclose(stdout) != 0) { fprintf(stderr, "%s: error writing export (%s)\n", @@ -213,7 +213,7 @@ printf_wrapper(char *fmt, ...) } static void -dump_table(int type, int human) +dump_table(int type, int human, int sloppy) { struct xdstr xd; struct castr *ca; @@ -224,7 +224,7 @@ dump_table(int type, int human) if (!ca) return; - xdinit(&xd, NATID_BAD, human, printf_wrapper); + xdinit(&xd, NATID_BAD, human, sloppy, printf_wrapper); xdhdr(&xd, ef_nameof(type), 0); xdcolhdr(&xd, ca); for (i = 0; (p = ef_ptr(type, i)); i++) {