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 <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2013-06-01 10:36:33 +02:00
parent 9ca3fa95b8
commit edfb80a1f7
4 changed files with 19 additions and 12 deletions

View file

@ -27,7 +27,7 @@
* xdump.h: Extended dumps * xdump.h: Extended dumps
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2008-2011 * Markus Armbruster, 2008-2013
*/ */
#ifndef XDUMP_H #ifndef XDUMP_H
@ -42,11 +42,13 @@ struct xdstr {
natid cnum; /* dump for this country */ natid cnum; /* dump for this country */
int divine; /* is this a deity dump? */ int divine; /* is this a deity dump? */
int human; /* dump human-readable format */ int human; /* dump human-readable format */
int sloppy; /* try to cope with invalid data */
void (*pr)(char *fmt, ...) /* callback for printing dump */ void (*pr)(char *fmt, ...) /* callback for printing dump */
ATTRIBUTE((format (printf, 1, 2))); 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 xdhdr(struct xdstr *, char *, int);
extern void xdcolhdr(struct xdstr *, struct castr[]); extern void xdcolhdr(struct xdstr *, struct castr[]);
extern void xdflds(struct xdstr *, struct castr[], void *); extern void xdflds(struct xdstr *, struct castr[], void *);

View file

@ -189,7 +189,7 @@ xdump(void)
if (!p || !*p) if (!p || !*p)
return RET_SYN; return RET_SYN;
xdinit(&xd, player->cnum, 0, pr); xdinit(&xd, player->cnum, 0, 0, pr);
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
type = isdigit(p[0]) ? atoi(p) : ef_byname(p); type = isdigit(p[0]) ? atoi(p) : ef_byname(p);
if (type < 0 || type >= EF_MAX) if (type < 0 || type >= EF_MAX)

View file

@ -27,7 +27,7 @@
* xdump.c: Extended dumps * xdump.c: Extended dumps
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2004-2010 * Markus Armbruster, 2004-2013
*/ */
/* /*
@ -84,15 +84,19 @@
* Initialize XD. * Initialize XD.
* Translate dump for country CNUM, except when CNUM is NATID_BAD. * Translate dump for country CNUM, except when CNUM is NATID_BAD.
* If HUMAN, dump in human-readable format. * 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. * Dump is to be delivered through callback PR.
* Return XD. * Return XD.
*/ */
struct xdstr * 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->cnum = cnum;
xd->divine = cnum == NATID_BAD || getnatp(cnum)->nat_stat == STAT_GOD; xd->divine = cnum == NATID_BAD || getnatp(cnum)->nat_stat == STAT_GOD;
xd->human = human; xd->human = human;
xd->sloppy = sloppy;
xd->pr = pr; xd->pr = pr;
return xd; 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)); 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); xd->pr("%s%d", sep, key);
else { } else {
xd->pr("%s", sep); xd->pr("%s", sep);
xdpresc(xd, sym, INT_MAX); xdpresc(xd, sym, INT_MAX);
} }

View file

@ -27,7 +27,7 @@
* empdump.c: Export/import Empire game state * empdump.c: Export/import Empire game state
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2008-2011 * Markus Armbruster, 2008-2013
*/ */
#include <config.h> #include <config.h>
@ -46,7 +46,7 @@
static void exit_bad_arg(char *, ...) static void exit_bad_arg(char *, ...)
ATTRIBUTE((noreturn, format (printf, 1, 2))); ATTRIBUTE((noreturn, format (printf, 1, 2)));
static void dump_table(int, int); static void dump_table(int, int, int);
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@ -159,7 +159,7 @@ main(int argc, char *argv[])
for (i = 0; i < EF_MAX; i++) { for (i = 0; i < EF_MAX; i++) {
if (!EF_IS_GAME_STATE(i)) if (!EF_IS_GAME_STATE(i))
continue; continue;
dump_table(i, human); dump_table(i, human, !verified);
} }
if (fclose(stdout) != 0) { if (fclose(stdout) != 0) {
fprintf(stderr, "%s: error writing export (%s)\n", fprintf(stderr, "%s: error writing export (%s)\n",
@ -213,7 +213,7 @@ printf_wrapper(char *fmt, ...)
} }
static void static void
dump_table(int type, int human) dump_table(int type, int human, int sloppy)
{ {
struct xdstr xd; struct xdstr xd;
struct castr *ca; struct castr *ca;
@ -224,7 +224,7 @@ dump_table(int type, int human)
if (!ca) if (!ca)
return; return;
xdinit(&xd, NATID_BAD, human, printf_wrapper); xdinit(&xd, NATID_BAD, human, sloppy, printf_wrapper);
xdhdr(&xd, ef_nameof(type), 0); xdhdr(&xd, ef_nameof(type), 0);
xdcolhdr(&xd, ca); xdcolhdr(&xd, ca);
for (i = 0; (p = ef_ptr(type, i)); i++) { for (i = 0; (p = ef_ptr(type, i)); i++) {