save/restore changes - part 3
This is the third of a series of savefile-related changes.
This adds early-days experimental support for a completely optional
'sfctool' utility (savefile conversion tool), to be able to export
a savefile's contents into a more portable format. There are likely
to be bugs at this stage. In this initial first-attempt, the export
format is a very simple ascii output.
NetHack can be built entirely, without also building this tool.
NetHack has no dependencies on the tool.
Attempts were made to minimize duplication of existing NetHack code.
To achieve that, unfortunately, #ifdef SFCTOOL and #ifndef SFCTOOL
had to be sprinkled around through some of the existing NetHack
source code, so that it could be re-used for building the utility.
The process for building the sfctool typically recompiles the source
files with #define SFCTOOL and a distinct object file with SF- is
produced.
sfctool notes:
Universal ctags is used and required to produce the sfctool utility.
Some targets were added to the Unix and Windows Makefiles to
facilitate the build process.
make sfctool
That should build a copy in util.
Note: At present, the Unix Makefiles do not copy sfctool over to the
NetHack playground during 'make install' or 'make update'.
Until that gets resolved by someone, The tool will
have to be manually copied there by the builder/admin if
desired.
cp util/sfctool ~/nh/install/games/lib/nethackdir/sfctool
Also, a separate Visual Studio sfctool.sln solution was written and
placed in sys/windows/vs. That has has only very limited testing.
Usage:
i) To convert an existing savefile to an exportascii format
that co-resides with the savefile:
sfctool -c savefile
That *must* be executed on the same platform / architecture /
data model that produced the save file in the first place.
ii) To unconvert an existing exportascii format export file to a
historical format savefile that can then be used by NetHack:
sfctool -u savefile
That must be executed on the same target platform / architecture /
data model that was used to build the NetHack that will
utilize the save file that results.
A Windows example:
sfctool -c Fred.NetHack-saved-game
That should result in creation of Fred.NetHack-saved-game.exportascii
from existing savefile:
%USERPROFILE%\AppData\Local\NetHack\3.7\Fred.NetHack-saved-game
A Unix example:
sfctool -c 1000wizard
That should result in creation of 1000wizard.exportascii.gz
from existing savefile in the playground save directory:
1000wizard.gz
Current Mechanics:
1. Makefile recipe, or script uses universal ctags to produce
util/sf.tags.
2. util/sftags is built and executed to read util/sf.tags and
generate: include/sfproto.h and src/sfdata.c.
3. util/sfctool is built from the following:
generated file compiled with -DSFCTOOL:
src/sfdata.c -> sfdata.o
existing files compiled with -DSFCTOOL:
util/sfctool.c -> sfctool.o
util/sfexpasc.c -> sfexpasc.o
src/alloc.c -> sf-alloc.o
src/monst.c -> sf-monst.o
src/objects.c -> sf-objects.o
src/sfbase.c -> sfbase.o
src/sfstruct.c -> sfstruct.o
src/nhlua.c -> sf-nhlua.o
util/panic.c -> panic.o
src/date.c -> sf-date.o
src/decl.c -> sf-decl.o
src/artifact.c -> sf-artifact.o
src/dungeon.c -> sf-dungeon.o
src/end.c -> sf-end.o
src/engrave.c -> sf-engrave.o
src/cfgfiles.c -> sf-cfgfiles.o
src/files.c -> sf-files.o
src/light.c -> sf-light.o
src/mdlib.c -> sf-mdlib.o
src/mkmaze.c -> sf-mkmaze.o
src/mkroom.c -> sf-mkroom.o
src/o_init.c -> sf-o_init.o
src/region.c -> sf-region.o
src/restore.c -> sf-restore.o
src/rumors.c -> sf-rumors.o
src/sys.c -> sf-sys.o
src/timeout.c -> sf-timeout.o
src/track.c -> sf-track.o
src/version.c -> sf-version.o
src/worm.c -> sf-worm.o
src/strutil.c -> strutil.o
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "dlb.h"
|
||||
|
||||
#ifndef MINIMAL_FOR_RECOVER
|
||||
#ifndef SFCTOOL
|
||||
|
||||
#ifndef OPTIONS_AT_RUNTIME
|
||||
#define OPTIONS_AT_RUNTIME
|
||||
@@ -357,6 +358,14 @@ comp_times(long filetime)
|
||||
return ((unsigned long) filetime < (unsigned long) nomakedefs.build_time);
|
||||
}
|
||||
#endif
|
||||
#endif /* !SFCTOOL */
|
||||
|
||||
#ifdef SFCTOOL
|
||||
#ifdef wait_synch
|
||||
#undef wait_synch
|
||||
#endif
|
||||
#define wait_synch()
|
||||
#endif /* SFCTOOL */
|
||||
|
||||
boolean
|
||||
check_version(
|
||||
@@ -385,11 +394,13 @@ check_version(
|
||||
version_data->incarnation != nomakedefs.version_number
|
||||
#endif
|
||||
) {
|
||||
#ifndef SFCTOOL
|
||||
if (complain) {
|
||||
pline("Version mismatch for file \"%s\".", filename);
|
||||
if (WIN_MESSAGE != WIN_ERR)
|
||||
display_nhwindow(WIN_MESSAGE, TRUE);
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
} else if (
|
||||
(version_data->feature_set & ~nomakedefs.ignored_features)
|
||||
@@ -397,42 +408,18 @@ check_version(
|
||||
|| ((utdflags & UTD_SKIP_SANITY1) == 0
|
||||
&& version_data->entity_count != nomakedefs.version_sanity1)
|
||||
) {
|
||||
#ifndef SFCTOOL
|
||||
if (complain) {
|
||||
pline("Configuration incompatibility for file \"%s\".", filename);
|
||||
display_nhwindow(WIN_MESSAGE, TRUE);
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
store_version(NHFILE *nhfp)
|
||||
{
|
||||
struct version_info version_data = {
|
||||
0UL, 0UL, 0UL,
|
||||
};
|
||||
|
||||
/* actual version number */
|
||||
version_data.incarnation = nomakedefs.version_number;
|
||||
/* bitmask of config settings */
|
||||
version_data.feature_set = nomakedefs.version_features;
|
||||
/* # of monsters and objects */
|
||||
version_data.entity_count = nomakedefs.version_sanity1;
|
||||
|
||||
/* bwrite() before bufon() uses plain write() */
|
||||
if (nhfp->structlevel)
|
||||
bufoff(nhfp->fd);
|
||||
|
||||
store_critical_bytes(nhfp);
|
||||
Sfo_version_info(nhfp, (struct version_info *) &version_data,
|
||||
"version_info");
|
||||
|
||||
if (nhfp->structlevel)
|
||||
bufon(nhfp->fd);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef SFCTOOL
|
||||
#ifdef AMIGA
|
||||
const char amiga_version_string[] = AMIGA_VERSION_STRING;
|
||||
#endif
|
||||
@@ -518,6 +505,34 @@ dump_version_info(void)
|
||||
release_runtime_info();
|
||||
return;
|
||||
}
|
||||
void
|
||||
store_version(NHFILE *nhfp)
|
||||
{
|
||||
struct version_info version_data = {
|
||||
0UL,
|
||||
0UL,
|
||||
0UL,
|
||||
};
|
||||
/* actual version number */
|
||||
version_data.incarnation = nomakedefs.version_number;
|
||||
/* bitmask of config settings */
|
||||
version_data.feature_set = nomakedefs.version_features;
|
||||
/* # of monsters and objects */
|
||||
version_data.entity_count = nomakedefs.version_sanity1;
|
||||
|
||||
/* bwrite() before bufon() uses plain write() */
|
||||
if (nhfp->structlevel)
|
||||
bufoff(nhfp->fd);
|
||||
|
||||
store_critical_bytes(nhfp);
|
||||
Sfo_version_info(nhfp, (struct version_info *) &version_data,
|
||||
"version_info");
|
||||
|
||||
if (nhfp->structlevel)
|
||||
bufon(nhfp->fd);
|
||||
return;
|
||||
}
|
||||
#endif /* !SFCTOOL */
|
||||
#endif /* MINIMAL_FOR_RECOVER */
|
||||
|
||||
struct critical_sizes_with_names {
|
||||
@@ -662,9 +677,10 @@ store_critical_bytes(NHFILE *nhfp)
|
||||
/* int cmc = 0; */
|
||||
|
||||
if (nhfp->mode & WRITING) {
|
||||
indicate = (nhfp->structlevel) ? 'h'
|
||||
: (nhfp->fnidx == cnvascii) ? 'a'
|
||||
: '?';
|
||||
indicate = (nhfp->structlevel) ? 'h'
|
||||
: (nhfp->fnidx == exportascii)
|
||||
? 'a'
|
||||
: '?';
|
||||
Sfo_char(nhfp, &indicate, "indicate-format", 1);
|
||||
Sfo_char(nhfp, &csc_count, "count-critical_sizes", 1);
|
||||
cnt = (int) csc_count;
|
||||
@@ -693,7 +709,11 @@ store_critical_bytes(NHFILE *nhfp)
|
||||
int
|
||||
uptodate(NHFILE *nhfp, const char *name, unsigned long utdflags)
|
||||
{
|
||||
#ifdef SFCTOOL
|
||||
extern struct version_info vers_info;
|
||||
#else
|
||||
struct version_info vers_info;
|
||||
#endif
|
||||
char indicator;
|
||||
int sfstatus = 0, idx_1st_mismatch = 0;
|
||||
boolean quietly = (utdflags & UTD_QUIETLY) != 0;
|
||||
@@ -708,19 +728,18 @@ uptodate(NHFILE *nhfp, const char *name, unsigned long utdflags)
|
||||
critical_sizes[idx_1st_mismatch].ucsize,
|
||||
critical_sizes[idx_1st_mismatch].nm);
|
||||
}
|
||||
return sfstatus;
|
||||
}
|
||||
|
||||
Sfi_version_info(nhfp, &vers_info, "version_info");
|
||||
if (!check_version(&vers_info, name, verbose, utdflags)) {
|
||||
if (verbose) {
|
||||
if ((utdflags & UTD_WITHOUT_WAITSYNCH_PERFILE) == 0)
|
||||
if ((utdflags & UTD_WITHOUT_WAITSYNCH_PERFILE) == 0) {
|
||||
wait_synch();
|
||||
}
|
||||
}
|
||||
return SF_OUTDATED;
|
||||
}
|
||||
|
||||
return SF_UPTODATE;
|
||||
return sfstatus;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -819,12 +838,15 @@ validate(NHFILE *nhfp, const char *name, boolean without_waitsynch_perfile)
|
||||
unsigned long utdflags = 0L;
|
||||
int validsf = 0;
|
||||
|
||||
#ifdef SFCTOOL
|
||||
utdflags |= UTD_QUIETLY;
|
||||
#endif
|
||||
if (nhfp->structlevel)
|
||||
utdflags |= UTD_CHECKSIZES;
|
||||
if (without_waitsynch_perfile)
|
||||
utdflags |= UTD_WITHOUT_WAITSYNCH_PERFILE;
|
||||
if (nhfp->fieldlevel)
|
||||
utdflags |= UTD_CHECKFIELDCOUNTS | UTD_SKIP_SANITY1 | UTD_QUIETLY;
|
||||
utdflags |= UTD_CHECKFIELDCOUNTS | UTD_SKIP_SANITY1;
|
||||
validsf = uptodate(nhfp, name, utdflags);
|
||||
return validsf;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user