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:
2
include/.gitignore
vendored
2
include/.gitignore
vendored
@@ -15,3 +15,5 @@ tile.h
|
||||
win32api.h
|
||||
# really obsolete...
|
||||
.cvsignore
|
||||
sfproto.h
|
||||
|
||||
|
||||
@@ -1068,6 +1068,10 @@ extern char **get_saved_games(void);
|
||||
extern void free_saved_games(char **);
|
||||
extern void nh_compress(const char *);
|
||||
extern void nh_uncompress(const char *);
|
||||
extern void nh_sfconvert(const char *);
|
||||
extern void nh_sfunconvert(const char *);
|
||||
extern int delete_convertedfile(const char *);
|
||||
extern void free_convert_filenames(void);
|
||||
extern boolean lock_file(const char *, int, int) NONNULLARG1;
|
||||
extern void unlock_file(const char *) NONNULLARG1;
|
||||
extern void check_recordfile(const char *);
|
||||
@@ -1093,6 +1097,7 @@ extern boolean read_tribute(const char *, const char *, int, char *, int,
|
||||
extern boolean Death_quote(char *, int) NONNULLARG1;
|
||||
extern void livelog_add(long ll_type, const char *) NONNULLARG2;
|
||||
ATTRNORETURN extern void do_deferred_showpaths(int) NORETURN;
|
||||
extern boolean contains_directory(const char *);
|
||||
|
||||
/* ### fountain.c ### */
|
||||
|
||||
@@ -1969,7 +1974,7 @@ extern int dosuspend(void);
|
||||
extern void nt_regularize(char *);
|
||||
extern int(*nt_kbhit)(void);
|
||||
extern void Delay(int);
|
||||
extern boolean contains_directory(const char *);
|
||||
boolean get_user_home_folder(char *, size_t);
|
||||
# ifdef CRASHREPORT
|
||||
struct CRctxt;
|
||||
extern struct CRctxt *ctxp;
|
||||
@@ -2678,6 +2683,12 @@ extern boolean lookup_id_mapping(unsigned, unsigned *) NONNULLARG2;
|
||||
/* extern void reset_restpref(void); */
|
||||
/* extern void set_restpref(const char *); */
|
||||
/* extern void set_savepref(const char *); */
|
||||
#ifdef SFCTOOL
|
||||
void rest_bubbles(NHFILE *);
|
||||
void restore_gamelog(NHFILE *);
|
||||
boolean restgamestate(NHFILE *);
|
||||
void restore_msghistory(NHFILE *);
|
||||
#endif
|
||||
|
||||
/* ### rip.c ### */
|
||||
|
||||
|
||||
@@ -429,6 +429,7 @@ extern struct nomakedefs_s nomakedefs;
|
||||
|
||||
/* PANICTRACE: Always defined for NH_DEVEL_STATUS != NH_STATUS_RELEASED
|
||||
but only for supported platforms. */
|
||||
#ifndef NOPANICTRACE
|
||||
#ifdef UNIX
|
||||
#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
|
||||
/* see end.c */
|
||||
@@ -439,6 +440,7 @@ extern struct nomakedefs_s nomakedefs;
|
||||
#endif /* CROSS_TO_WASM | CROSS_TO_MSDOS */
|
||||
#endif /* NH_DEVEL_STATUS != NH_STATUS_RELEASED */
|
||||
#endif /* UNIX */
|
||||
#endif /* !NOPANICTRACE */
|
||||
|
||||
/* The following are meaningless if PANICTRACE is not defined: */
|
||||
#if defined(__linux__) && defined(__GLIBC__) && (__GLIBC__ >= 2)
|
||||
@@ -569,5 +571,6 @@ typedef enum NHL_pcall_action {
|
||||
NHLpa_impossible
|
||||
} NHL_pcall_action;
|
||||
|
||||
#define SFCTOOL_BIT (1UL << 30) /* needed for upcoming savefile handling */
|
||||
#define SFCTOOL_BIT (1UL << 30)
|
||||
|
||||
#endif /* GLOBAL_H */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -23,7 +23,7 @@ extern void sfo_uint32(NHFILE *, uint32 *, const char *);
|
||||
extern void sfo_uint64(NHFILE *, uint64 *, const char *);
|
||||
extern void sfo_size_t(NHFILE *, size_t *, const char *);
|
||||
extern void sfo_time_t(NHFILE *, time_t *, const char *);
|
||||
|
||||
//extern void sfo_str(NHFILE *, char *, const char *, int);
|
||||
extern void sfo_arti_info(NHFILE *nhfp,
|
||||
struct arti_info *d_arti_info,
|
||||
const char *myname);
|
||||
@@ -199,7 +199,7 @@ extern void sfi_ulong(NHFILE *, ulong *, const char *);
|
||||
#define Sfo_uint64(a,b,c) sfo_uint64(a, b, c)
|
||||
#define Sfo_size_t(a,b,c) sfo_size_t(a, b, c)
|
||||
#define Sfo_time_t(a,b,c) sfo_time_t(a, b, c)
|
||||
|
||||
#define Sfo_str(a,b,c) sfo_str(a, b, c)
|
||||
#define Sfo_arti_info(a,b,c) sfo_arti_info(a, b, c)
|
||||
#define Sfo_dgn_topology(a,b,c) sfo_dgn_topology(a, b, c)
|
||||
#define Sfo_dungeon(a,b,c) sfo_dungeon(a, b, c)
|
||||
@@ -471,7 +471,7 @@ extern void sfi_ulong(NHFILE *, ulong *, const char *);
|
||||
#define Sfo_uint64(a,b,c) sfo(a, b, c)
|
||||
#define Sfo_size_t(a,b,c) sfo(a, b, c)
|
||||
#define Sfo_time_t(a,b,c) sfo(a, b, c)
|
||||
|
||||
#define Sfo_str(a,b,c) sfo(a, b, c)
|
||||
#define Sfo_arti_info(a,b,c) sfo(a, b, c)
|
||||
#define Sfo_dgn_topology(a,b,c) sfo(a, b, c)
|
||||
#define Sfo_dungeon(a,b,c) sfo(a, b, c)
|
||||
|
||||
@@ -97,11 +97,11 @@ SF_PROTO_X(char, char);
|
||||
#undef SF_PROTO_C
|
||||
#undef SF_PROTO_X
|
||||
|
||||
#define SF_ENTRY(dtyp) \
|
||||
#define SF_ENTRY(dtyp) \
|
||||
void (*sf_##dtyp)(NHFILE *, dtyp *, const char *)
|
||||
#define SF_ENTRY_C(keyw, dtyp) \
|
||||
#define SF_ENTRY_C(keyw, dtyp) \
|
||||
void (*sf_##dtyp)(NHFILE *, keyw dtyp *, const char *)
|
||||
#define SF_ENTRY_X(xxx, dtyp) \
|
||||
#define SF_ENTRY_X(xxx, dtyp) \
|
||||
void (*sf_##dtyp)(NHFILE *, xxx *, const char *, int bfsz)
|
||||
|
||||
struct sf_procs {
|
||||
@@ -189,11 +189,14 @@ struct sf_fieldlevel_procs {
|
||||
struct sf_procs fn_x; /* called for fieldlevel */
|
||||
};
|
||||
extern struct sf_structlevel_procs sfoprocs[NUM_SAVEFORMATS], sfiprocs[NUM_SAVEFORMATS];
|
||||
extern void sf_setprocs(int, struct sf_structlevel_procs *, struct sf_structlevel_procs *);
|
||||
extern void sf_setflprocs(int, struct sf_fieldlevel_procs *, struct sf_fieldlevel_procs *);
|
||||
extern struct sf_structlevel_procs sfoprocs[NUM_SAVEFORMATS], sfiprocs[NUM_SAVEFORMATS];
|
||||
extern struct sf_fieldlevel_procs sfoflprocs[NUM_SAVEFORMATS], sfiflprocs[NUM_SAVEFORMATS];
|
||||
extern struct sf_structlevel_procs historical_sfo_procs;
|
||||
extern struct sf_structlevel_procs historical_sfi_procs;
|
||||
extern struct sf_fieldlevel_procs cnv_sfo_procs;
|
||||
extern struct sf_fieldlevel_procs cnv_sfi_procs;
|
||||
extern struct sf_fieldlevel_procs exportascii_sfo_procs;
|
||||
extern struct sf_fieldlevel_procs exportascii_sfi_procs;
|
||||
|
||||
#endif /* SFPROCS_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user