This is the second of a series of changes related to save/restore.
No EDITLEVEL bump has been included, because although the code
is changed extensively by this, the content of the savefiles have
not been changed.
Push the use of the structlevel bwrite() and mread() function use
out of the core and into sfstruct.c. This is groundwork for upcoming
changes.
In the core, replace the bwrite() and mread() calls with the
use of type-specific savefile output (Sfo) and savefile
input (Sfi) macros. The macros are defined in a new header file
savefile.h, which also contains the prototypes for the sfo_* and
sfi_* functions that the macros ultimately expand to. The functions
themselves are in src/sfbase.c.
On C99, each Sfo or Sfi macro expansion refers directly to the
corresponding type-specific sfo_* or sfi_* function.
If C23 or later is is use, the majority (all but 3 types) of the
macros refer to a single _Generic output routine sfo(nhfp, dt, tag),
and a single _Generic input routine sfi(nhfp, dt, tag), which handles
the dispatch of the type-specific underlying functions. This was
somewhat experimental, but turned out to be practical because the
compiler would gripe if the type for a variable was not included in
the _Generic when passed as an argument, so it could be fixed.
This alters the savefile verication process by having a common set
return values for the related functions such as uptodate(),
check_version(), etc. The new return values return more information
about savefile incompatibilities, beyond failure/sucess. The
additional information will be useful for an upcoming addition.
The expanded return values are:
SF_UPTODATE (0) everything matched and looks good
SF_OUTDATED (1) savefile is outdated
SF_CRITICAL_BYTE_COUNT_MISMATCH (2) critical size count mismatch
SF_DM_IL32LLP64_ON_ILP32LL64 (3) Windows x64 savefile on x86
SF_DM_I32LP64_ON_ILP32LL64 (4) Unix 64 savefile on x86
SF_DM_ILP32LL64_ON_I32LP64 (5) x86 savefile on Unix 64
SF_DM_ILP32LL64_ON_IL32LLP64 (6) x86 savefile on Windows x64
SF_DM_I32LP64_ON_IL32LLP64 (7) Unix 64 savefile on Windows x64
SF_DM_IL32LLP64_ON_I32LP64 (8) Windows x64 savefile on Unix 64
SF_DM_MISMATCH (9) some other mismatch
The callers in the core have been adjusted to deal with the expanded
return values.
Other miscellaneous inclusions:
- go.oracle_loc -> svo.oracle_loc.
- add a bit (1UL << 30) to called SFCTOOL_BIT as groundwork
for changes to follow.
200 lines
5.8 KiB
C
200 lines
5.8 KiB
C
/* NetHack 3.6 sfprocs.h Tue Nov 6 19:38:48 2018 */
|
|
/* Copyright (c) NetHack Development Team 2025. */
|
|
/* NetHack may be freely redistributed. See license for details. */
|
|
|
|
#ifndef SFPROCS_H
|
|
#define SFPROCS_H
|
|
|
|
#define NHTYPE_SIMPLE 1
|
|
#define NHTYPE_COMPLEX 2
|
|
|
|
#define SF_PROTO(dtyp) \
|
|
extern void sfo_##dtyp(NHFILE *, dtyp *, const char *); \
|
|
extern void sfi_##dtyp(NHFILE *, dtyp *, const char *); \
|
|
extern void sfo_x_##dtyp(NHFILE *, dtyp *, const char *); \
|
|
extern void sfi_x_##dtyp(NHFILE *, dtyp *, const char *)
|
|
#define SF_PROTO_C(keyw, dtyp) \
|
|
extern void sfo_##dtyp(NHFILE *, keyw dtyp *, const char *); \
|
|
extern void sfi_##dtyp(NHFILE *, keyw dtyp *, const char *); \
|
|
extern void sfo_x_##dtyp(NHFILE *, keyw dtyp *, const char *); \
|
|
extern void sfi_x_##dtyp(NHFILE *, keyw dtyp *, const char *)
|
|
#define SF_PROTO_X(xxx, dtyp) \
|
|
extern void sfo_##dtyp(NHFILE *, xxx *, const char *, int bfsz); \
|
|
extern void sfi_##dtyp(NHFILE *, xxx *, const char *, int bfsz); \
|
|
extern void sfo_x_##dtyp(NHFILE *, xxx *, const char *, int bfsz); \
|
|
extern void sfi_x_##dtyp(NHFILE *, xxx *, const char *, int bfsz)
|
|
|
|
SF_PROTO_C(struct, arti_info);
|
|
SF_PROTO_C(struct, nhrect);
|
|
SF_PROTO_C(struct, branch);
|
|
SF_PROTO_C(struct, bubble);
|
|
SF_PROTO_C(struct, cemetery);
|
|
SF_PROTO_C(struct, context_info);
|
|
SF_PROTO_C(struct, nhcoord);
|
|
SF_PROTO_C(struct, damage);
|
|
SF_PROTO_C(struct, dest_area);
|
|
SF_PROTO_C(struct, dgn_topology);
|
|
SF_PROTO_C(struct, dungeon);
|
|
SF_PROTO_C(struct, d_level);
|
|
SF_PROTO_C(struct, ebones);
|
|
SF_PROTO_C(struct, edog);
|
|
SF_PROTO_C(struct, egd);
|
|
SF_PROTO_C(struct, emin);
|
|
SF_PROTO_C(struct, engr);
|
|
SF_PROTO_C(struct, epri);
|
|
SF_PROTO_C(struct, eshk);
|
|
SF_PROTO_C(struct, fe);
|
|
SF_PROTO_C(struct, flag);
|
|
SF_PROTO_C(struct, fruit);
|
|
SF_PROTO_C(struct, gamelog_line);
|
|
SF_PROTO_C(struct, kinfo);
|
|
SF_PROTO_C(struct, levelflags);
|
|
SF_PROTO_C(struct, ls_t);
|
|
SF_PROTO_C(struct, linfo);
|
|
SF_PROTO_C(struct, mapseen_feat);
|
|
SF_PROTO_C(struct, mapseen_flags);
|
|
SF_PROTO_C(struct, mapseen_rooms);
|
|
SF_PROTO_C(struct, mkroom);
|
|
SF_PROTO_C(struct, monst);
|
|
SF_PROTO_C(struct, mvitals);
|
|
SF_PROTO_C(struct, obj);
|
|
SF_PROTO_C(struct, objclass);
|
|
SF_PROTO_C(struct, q_score);
|
|
SF_PROTO_C(struct, rm);
|
|
SF_PROTO_C(struct, spell);
|
|
SF_PROTO_C(struct, stairway);
|
|
SF_PROTO_C(struct, s_level);
|
|
SF_PROTO_C(struct, trap);
|
|
SF_PROTO_C(struct, version_info);
|
|
SF_PROTO_C(struct, you);
|
|
SF_PROTO_C(union, any);
|
|
SF_PROTO(int16);
|
|
SF_PROTO(int32);
|
|
SF_PROTO(int64);
|
|
SF_PROTO(uchar);
|
|
SF_PROTO(uint16);
|
|
SF_PROTO(uint32);
|
|
SF_PROTO(uint64);
|
|
SF_PROTO(long);
|
|
SF_PROTO(ulong);
|
|
SF_PROTO(xint8);
|
|
SF_PROTO(boolean);
|
|
SF_PROTO(schar);
|
|
SF_PROTO(aligntyp);
|
|
SF_PROTO(genericptr);
|
|
SF_PROTO(size_t);
|
|
SF_PROTO(time_t);
|
|
SF_PROTO(int);
|
|
SF_PROTO(unsigned);
|
|
SF_PROTO(coordxy);
|
|
SF_PROTO(short);
|
|
SF_PROTO(xint16);
|
|
SF_PROTO(ushort);
|
|
SF_PROTO_X(uint8_t, bitfield);
|
|
SF_PROTO_X(char, char);
|
|
|
|
#undef SF_PROTO
|
|
#undef SF_PROTO_C
|
|
#undef SF_PROTO_X
|
|
|
|
#define SF_ENTRY(dtyp) \
|
|
void (*sf_##dtyp)(NHFILE *, dtyp *, const char *)
|
|
#define SF_ENTRY_C(keyw, dtyp) \
|
|
void (*sf_##dtyp)(NHFILE *, keyw dtyp *, const char *)
|
|
#define SF_ENTRY_X(xxx, dtyp) \
|
|
void (*sf_##dtyp)(NHFILE *, xxx *, const char *, int bfsz)
|
|
|
|
struct sf_procs {
|
|
SF_ENTRY_C(struct, arti_info);
|
|
SF_ENTRY_C(struct, nhrect);
|
|
SF_ENTRY_C(struct, branch);
|
|
SF_ENTRY_C(struct, bubble);
|
|
SF_ENTRY_C(struct, cemetery);
|
|
SF_ENTRY_C(struct, context_info);
|
|
SF_ENTRY_C(struct, nhcoord);
|
|
SF_ENTRY_C(struct, damage);
|
|
SF_ENTRY_C(struct, dest_area);
|
|
SF_ENTRY_C(struct, dgn_topology);
|
|
SF_ENTRY_C(struct, dungeon);
|
|
SF_ENTRY_C(struct, d_level);
|
|
SF_ENTRY_C(struct, ebones);
|
|
SF_ENTRY_C(struct, edog);
|
|
SF_ENTRY_C(struct, egd);
|
|
SF_ENTRY_C(struct, emin);
|
|
SF_ENTRY_C(struct, engr);
|
|
SF_ENTRY_C(struct, epri);
|
|
SF_ENTRY_C(struct, eshk);
|
|
SF_ENTRY_C(struct, fe);
|
|
SF_ENTRY_C(struct, flag);
|
|
SF_ENTRY_C(struct, fruit);
|
|
SF_ENTRY_C(struct, gamelog_line);
|
|
SF_ENTRY_C(struct, kinfo);
|
|
SF_ENTRY_C(struct, levelflags);
|
|
SF_ENTRY_C(struct, ls_t);
|
|
SF_ENTRY_C(struct, linfo);
|
|
SF_ENTRY_C(struct, mapseen_feat);
|
|
SF_ENTRY_C(struct, mapseen_flags);
|
|
SF_ENTRY_C(struct, mapseen_rooms);
|
|
SF_ENTRY_C(struct, mkroom);
|
|
SF_ENTRY_C(struct, monst);
|
|
SF_ENTRY_C(struct, mvitals);
|
|
SF_ENTRY_C(struct, obj);
|
|
SF_ENTRY_C(struct, objclass);
|
|
SF_ENTRY_C(struct, q_score);
|
|
SF_ENTRY_C(struct, rm);
|
|
SF_ENTRY_C(struct, spell);
|
|
SF_ENTRY_C(struct, stairway);
|
|
SF_ENTRY_C(struct, s_level);
|
|
SF_ENTRY_C(struct, trap);
|
|
SF_ENTRY_C(struct, version_info);
|
|
SF_ENTRY_C(struct, you);
|
|
SF_ENTRY_C(union, any);
|
|
|
|
SF_ENTRY(aligntyp);
|
|
SF_ENTRY(boolean);
|
|
SF_ENTRY(coordxy);
|
|
SF_ENTRY(genericptr);
|
|
SF_ENTRY(int);
|
|
SF_ENTRY(int16);
|
|
SF_ENTRY(int32);
|
|
SF_ENTRY(int64);
|
|
SF_ENTRY(long);
|
|
SF_ENTRY(schar);
|
|
SF_ENTRY(short);
|
|
SF_ENTRY(size_t);
|
|
SF_ENTRY(time_t);
|
|
SF_ENTRY(uchar);
|
|
SF_ENTRY(uint16);
|
|
SF_ENTRY(uint32);
|
|
SF_ENTRY(uint64);
|
|
SF_ENTRY(ulong);
|
|
SF_ENTRY(unsigned);
|
|
SF_ENTRY(ushort);
|
|
SF_ENTRY(xint16);
|
|
SF_ENTRY(xint8);
|
|
SF_ENTRY_X(char, char);
|
|
SF_ENTRY_X(uint8_t, bitfield);
|
|
};
|
|
|
|
#undef SF_ENTRY
|
|
#undef SF_ENTRY_C
|
|
#undef SF_ENTRY_X
|
|
|
|
struct sf_structlevel_procs {
|
|
const char *ext;
|
|
struct sf_procs fn; /* called for structlevel (historical) */
|
|
};
|
|
struct sf_fieldlevel_procs {
|
|
const char *ext;
|
|
struct sf_procs fn_x; /* called for fieldlevel */
|
|
};
|
|
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;
|
|
|
|
#endif /* SFPROCS_H */
|
|
|