2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * empdump.c: Export/import Empire game state
30 * Known contributors to this file:
31 * Markus Armbruster, 2008
46 #include "prototypes.h"
50 static void dump_table(int, int);
53 main(int argc, char *argv[])
55 char *config_file = NULL;
60 int opt, i, lineno, type;
64 while ((opt = getopt(argc, argv, "e:mtxhv")) != EOF) {
70 printf("Usage: %s [OPTION]... [DUMP-FILE]\n"
71 " -e CONFIG-FILE configuration file\n"
73 " -m use machine-readable format\n"
74 " -t test import, don't update game state\n"
75 " -x export to standard output\n"
76 " -h display this help and exit\n"
77 " -v display version information and exit\n",
78 argv[0], dflt_econfig);
84 private = EFF_PRIVATE;
90 printf("%s\n\n%s", version, legal);
93 fprintf(stderr, "Try -h for help.\n");
99 import = argv[optind++];
102 impf = fopen(import, "r");
104 fprintf(stderr, "Cant open %s for reading (%s)\n",
105 import, strerror(errno));
109 private = EFF_PRIVATE;
111 /* read configuration & initialize */
113 if (emp_config(config_file) < 0)
117 if (read_builtin_tables() < 0)
119 if (read_custom_tables() < 0)
121 if (chdir(gamedir)) {
122 fprintf(stderr, "Can't chdir to %s (%s)\n",
123 gamedir, strerror(errno));
128 for (i = 0; i < EF_MAX; i++) {
129 if (!EF_IS_GAME_STATE(i))
131 if (!ef_open(i, EFF_MEM | private))
135 /* import from IMPORT */
136 memset(dirty, 0, sizeof(dirty));
139 while ((type = xundump(impf, import, &lineno, EF_BAD)) >= 0)
148 /* export to stdout */
150 for (i = 0; i < EF_MAX; i++) {
151 if (!EF_IS_GAME_STATE(i))
153 dump_table(i, human);
157 /* write out imported data */
158 for (i = 0; i < EF_MAX; i++) {
159 if (!EF_IS_GAME_STATE(i))
161 if (!private && dirty[i]) {
171 printf_wrapper(char *fmt, ...)
181 dump_table(int type, int human)
192 xdinit(&xd, 0, human, printf_wrapper);
193 xdhdr(&xd, ef_nameof(type), 0);
195 for (i = 0; (p = ef_ptr(type, i)); i++) {