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:
@@ -954,9 +954,9 @@ struct xlock_s {
|
||||
#define NHF_BONESFILE 3
|
||||
/* modes */
|
||||
#define READING 0x0
|
||||
#define COUNTING 0x1
|
||||
#define WRITING 0x2
|
||||
#define FREEING 0x4
|
||||
#define COUNTING 0x01
|
||||
#define WRITING 0x02
|
||||
#define FREEING 0x04
|
||||
#define CONVERTING 0x08
|
||||
#define UNCONVERTING 0x10
|
||||
#if 0
|
||||
@@ -972,7 +972,7 @@ struct xlock_s {
|
||||
enum saveformats {
|
||||
invalid = 0,
|
||||
historical = 1, /* entire struct, binary, as-is */
|
||||
cnvascii = 2, /* each field, ascii text */
|
||||
exportascii = 2, /* each field written out as ascii text */
|
||||
NUM_SAVEFORMATS
|
||||
};
|
||||
|
||||
@@ -984,11 +984,11 @@ struct fieldlevel_content {
|
||||
|
||||
struct nh_file {
|
||||
int fd; /* for traditional structlevel binary writes */
|
||||
int mode; /* holds READING, WRITING, or FREEING modes */
|
||||
int mode; /* holds READING, WRITING, FREEING, CONVERTING modes */
|
||||
int ftype; /* NHF_LEVELFILE, NHF_SAVEFILE, or NHF_BONESFILE */
|
||||
int fnidx; /* index of procs for fieldlevel saves */
|
||||
long count; /* holds current line count for default style file,
|
||||
field count for binary style */
|
||||
long rcount, /* read count since opening */
|
||||
wcount; /* write count since opening */
|
||||
boolean structlevel; /* traditional structure binary saves */
|
||||
boolean fieldlevel; /* fieldlevel saves each field individually */
|
||||
boolean addinfo; /* if set, some additional context info from core */
|
||||
|
||||
Reference in New Issue
Block a user