/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
* empdump.c: Export/import Empire game state
*
* Known contributors to this file:
- * Markus Armbruster, 2008-2011
+ * Markus Armbruster, 2008-2014
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include "file.h"
#include "optlist.h"
#include "nat.h"
#include "prototypes.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);
int
main(int argc, char *argv[])
{
char *config_file = NULL;
char *import = NULL;
+ int complete = 0;
int export = 0;
int private = 0;
int human = 1;
FILE *impf = NULL;
int dirty[EF_MAX];
- while ((opt = getopt(argc, argv, "e:i:mnxhv")) != EOF) {
+ while ((opt = getopt(argc, argv, "ce:i:mnxhv")) != EOF) {
switch (opt) {
+ case 'c':
+ complete = 1;
+ break;
case 'e':
config_file = optarg;
break;
break;
case 'h':
printf("Usage: %s [OPTION]...\n"
+ " -c use complete export format\n"
" -e CONFIG-FILE configuration file\n"
" (default %s)\n"
" -i DUMP-FILE import from DUMP-FILE\n"
for (i = 0; i < EF_MAX; i++) {
if (!EF_IS_GAME_STATE(i))
continue;
- dump_table(i, human);
+ dump_table(i, human, !verified, complete);
}
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, int complete)
{
struct xdstr xd;
struct castr *ca;
- int i;
+ int i, n;
void *p;
ca = ef_cadef(type);
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);
+ n = 0;
for (i = 0; (p = ef_ptr(type, i)); i++) {
+ if (!complete && xundump_redundant(type, i, p))
+ continue;
xdflds(&xd, ca, p);
+ n++;
printf("\n");
}
- xdftr(&xd, i);
+ xdftr(&xd, n);
}