empdump: Omit redundant data from export, new -c includes it
Cuts size of export files in test suite by a factor of four. Not a big deal for disk usage, as export files compress very well, and disk space is cheap anyway. Export files are simply easier to work with when they aren't full of redundant crap. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
7d3a3df283
commit
f4f048234c
12 changed files with 43 additions and 42173 deletions
|
@ -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-2013
|
* Markus Armbruster, 2008-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef XDUMP_H
|
#ifndef XDUMP_H
|
||||||
|
@ -54,5 +54,6 @@ extern void xdcolhdr(struct xdstr *, struct castr[]);
|
||||||
extern void xdflds(struct xdstr *, struct castr[], void *);
|
extern void xdflds(struct xdstr *, struct castr[], void *);
|
||||||
extern void xdftr(struct xdstr *, int);
|
extern void xdftr(struct xdstr *, int);
|
||||||
extern int xundump(FILE *, char *, int *, int);
|
extern int xundump(FILE *, char *, int *, int);
|
||||||
|
extern int xundump_redundant(int, int, void *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,7 +4,7 @@ empdump \- Export/import Empire game state
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B empdump
|
.B empdump
|
||||||
[
|
[
|
||||||
.B \-hmnvx
|
.B \-chmnvx
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
.BI \-e " configfile"
|
.BI \-e " configfile"
|
||||||
|
@ -18,6 +18,9 @@ empdump \- Export/import Empire game state
|
||||||
exports and imports game state as plain text.
|
exports and imports game state as plain text.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
|
.B \-c
|
||||||
|
Use complete export format: don't omit data import doesn't need.
|
||||||
|
.TP
|
||||||
.BI \-e " configfile"
|
.BI \-e " configfile"
|
||||||
Use game configuration in \fIconfigfile\fR.
|
Use game configuration in \fIconfigfile\fR.
|
||||||
.TP
|
.TP
|
||||||
|
|
|
@ -135,6 +135,27 @@ can_fill_gaps(int type)
|
||||||
&& !have_hardcoded_indexes(type);
|
&& !have_hardcoded_indexes(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Is table TYPE's ID-th record OBJ redundant for xundump()
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
xundump_redundant(int type, int id, void *obj)
|
||||||
|
{
|
||||||
|
char buf[EF_WITH_CADEF_MAX_ENTRY_SIZE];
|
||||||
|
|
||||||
|
if (!can_fill_gaps(type))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (may_truncate(type) && id == ef_nelem(type) - 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ef_blank(type, id, buf);
|
||||||
|
if (ef_flags(type) & EFF_TYPED)
|
||||||
|
return ef_typedstr_eq((struct ef_typedstr *)buf,
|
||||||
|
(struct ef_typedstr *)obj);
|
||||||
|
return !memcmp(obj, buf, empfile[type].size);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gripe about the current line to stderr, return -1.
|
* Gripe about the current line to stderr, return -1.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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-2013
|
* Markus Armbruster, 2008-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -46,13 +46,14 @@
|
||||||
|
|
||||||
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, int);
|
static void dump_table(int, int, int, int);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *config_file = NULL;
|
char *config_file = NULL;
|
||||||
char *import = NULL;
|
char *import = NULL;
|
||||||
|
int complete = 0;
|
||||||
int export = 0;
|
int export = 0;
|
||||||
int private = 0;
|
int private = 0;
|
||||||
int human = 1;
|
int human = 1;
|
||||||
|
@ -60,8 +61,11 @@ main(int argc, char *argv[])
|
||||||
FILE *impf = NULL;
|
FILE *impf = NULL;
|
||||||
int dirty[EF_MAX];
|
int dirty[EF_MAX];
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "e:i:mnxhv")) != EOF) {
|
while ((opt = getopt(argc, argv, "ce:i:mnxhv")) != EOF) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'c':
|
||||||
|
complete = 1;
|
||||||
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
config_file = optarg;
|
config_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -79,6 +83,7 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
printf("Usage: %s [OPTION]...\n"
|
printf("Usage: %s [OPTION]...\n"
|
||||||
|
" -c use complete export format\n"
|
||||||
" -e CONFIG-FILE configuration file\n"
|
" -e CONFIG-FILE configuration file\n"
|
||||||
" (default %s)\n"
|
" (default %s)\n"
|
||||||
" -i DUMP-FILE import from DUMP-FILE\n"
|
" -i DUMP-FILE import from DUMP-FILE\n"
|
||||||
|
@ -159,7 +164,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, !verified);
|
dump_table(i, human, !verified, complete);
|
||||||
}
|
}
|
||||||
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,11 +218,11 @@ printf_wrapper(char *fmt, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_table(int type, int human, int sloppy)
|
dump_table(int type, int human, int sloppy, int complete)
|
||||||
{
|
{
|
||||||
struct xdstr xd;
|
struct xdstr xd;
|
||||||
struct castr *ca;
|
struct castr *ca;
|
||||||
int i;
|
int i, n;
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
ca = ef_cadef(type);
|
ca = ef_cadef(type);
|
||||||
|
@ -227,9 +232,13 @@ dump_table(int type, int human, int sloppy)
|
||||||
xdinit(&xd, NATID_BAD, human, sloppy, 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);
|
||||||
|
n = 0;
|
||||||
for (i = 0; (p = ef_ptr(type, i)); i++) {
|
for (i = 0; (p = ef_ptr(type, i)); i++) {
|
||||||
|
if (!complete && xundump_redundant(type, i, p))
|
||||||
|
continue;
|
||||||
xdflds(&xd, ca, p);
|
xdflds(&xd, ca, p);
|
||||||
|
n++;
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
xdftr(&xd, i);
|
xdftr(&xd, n);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue