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:
24
src/nhlua.c
24
src/nhlua.c
@@ -25,6 +25,7 @@
|
||||
|
||||
struct e;
|
||||
|
||||
#ifndef SFCTOOL
|
||||
/* lua_CFunction prototypes */
|
||||
#ifdef DUMPLOG
|
||||
staticfn int nhl_dump_fmtstr(lua_State *);
|
||||
@@ -91,7 +92,9 @@ staticfn void nhl_warn(void *, const char *, int);
|
||||
staticfn void nhl_clearfromtable(lua_State *, int, int, struct e *);
|
||||
staticfn int nhl_panic(lua_State *);
|
||||
staticfn void nhl_hookfn(lua_State *, lua_Debug *);
|
||||
#endif /* !SFCTOOL */
|
||||
|
||||
#ifndef SFCTOOL
|
||||
static const char *const nhcore_call_names[NUM_NHCORE_CALLS] = {
|
||||
"start_new_game",
|
||||
"restore_old_game",
|
||||
@@ -102,6 +105,7 @@ static const char *const nhcore_call_names[NUM_NHCORE_CALLS] = {
|
||||
"leave_tutorial",
|
||||
};
|
||||
static boolean nhcore_call_available[NUM_NHCORE_CALLS];
|
||||
#endif
|
||||
|
||||
/* internal structure that hangs off L->ud (but use lua_getallocf() )
|
||||
* Note that we use it for both memory use tracking and instruction counting.
|
||||
@@ -126,6 +130,7 @@ typedef struct nhl_user_data {
|
||||
#endif
|
||||
} nhl_user_data;
|
||||
|
||||
#ifndef SFCTOOL
|
||||
static lua_State *luapat; /* instance for file pattern matching */
|
||||
|
||||
void
|
||||
@@ -1264,20 +1269,26 @@ get_nh_lua_variables(void)
|
||||
|
||||
RESTORE_WARNING_UNREACHABLE_CODE
|
||||
|
||||
/* char *lua_data; */
|
||||
#endif /* !SFCTOOL */
|
||||
|
||||
#ifdef SFCTOOL
|
||||
char *lua_data;
|
||||
#endif
|
||||
|
||||
/* save nh_lua_variables table to file */
|
||||
void
|
||||
save_luadata(NHFILE *nhfp)
|
||||
{
|
||||
unsigned lua_data_len;
|
||||
#ifndef SFCTOOL
|
||||
char *lua_data = get_nh_lua_variables(); /* note: '\0' terminated */
|
||||
#endif
|
||||
|
||||
if (!lua_data)
|
||||
lua_data = dupstr(emptystr);
|
||||
lua_data_len = Strlen(lua_data) + 1; /* +1: include the terminator */
|
||||
Sfo_unsigned(nhfp, &lua_data_len, "luadata-lua_data_len");
|
||||
Sfo_char(nhfp, lua_data, "lua_data", lua_data_len);
|
||||
Sfo_char(nhfp, lua_data, "luadata", lua_data_len);
|
||||
free(lua_data);
|
||||
}
|
||||
|
||||
@@ -1286,18 +1297,25 @@ void
|
||||
restore_luadata(NHFILE *nhfp)
|
||||
{
|
||||
unsigned lua_data_len = 0;
|
||||
#ifndef SFCTOOL
|
||||
char *lua_data;
|
||||
#endif /* !SFCTOOL */
|
||||
|
||||
Sfi_unsigned(nhfp, &lua_data_len, "luadata-lua_data_len");
|
||||
lua_data = (char *) alloc(lua_data_len);
|
||||
Sfi_char(nhfp, lua_data, "luadata", lua_data_len);
|
||||
|
||||
#ifndef SFCTOOL
|
||||
if (!gl.luacore)
|
||||
l_nhcore_init();
|
||||
luaL_loadstring(gl.luacore, lua_data);
|
||||
free(lua_data);
|
||||
nhl_pcall_handle(gl.luacore, 0, 0, "restore_luadata", NHLpa_panic);
|
||||
#endif /* !SFCTOOL */
|
||||
}
|
||||
|
||||
#ifndef SFCTOOL
|
||||
|
||||
/* local stairs = stairways(); */
|
||||
staticfn int
|
||||
nhl_stairways(lua_State *L)
|
||||
@@ -2977,6 +2995,8 @@ nhlL_newstate(nhl_sandbox_info *sbi, const char *name)
|
||||
return L;
|
||||
}
|
||||
|
||||
#endif /* !SFCTOOL */
|
||||
|
||||
/*
|
||||
(See end of comment for conclusion.)
|
||||
to make packages safe, we need something like:
|
||||
|
||||
Reference in New Issue
Block a user