* xdump.h: Extended dumps
*
* Known contributors to this file:
- * Markus Armbruster, 2008-2011
+ * Markus Armbruster, 2008-2013
*/
#ifndef XDUMP_H
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 *);
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)
* xdump.c: Extended dumps
*
* Known contributors to this file:
- * Markus Armbruster, 2004-2010
+ * Markus Armbruster, 2004-2013
*/
/*
* 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;
}
{
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);
}
* empdump.c: Export/import Empire game state
*
* Known contributors to this file:
- * Markus Armbruster, 2008-2011
+ * Markus Armbruster, 2008-2013
*/
#include <config.h>
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[])
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",
}
static void
-dump_table(int type, int human)
+dump_table(int type, int human, int sloppy)
{
struct xdstr xd;
struct castr *ca;
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++) {