save/restore changes - part 2

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.
This commit is contained in:
nhmall
2025-05-25 15:03:13 -04:00
parent 15ced6f1ff
commit f4a6da2e52
50 changed files with 2551 additions and 1287 deletions

View File

@@ -1969,6 +1969,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 *);
# ifdef CRASHREPORT
struct CRctxt;
extern struct CRctxt *ctxp;
@@ -1976,7 +1977,6 @@ extern int win32_cr_helper(char, struct CRctxt *, void *, int);
extern int win32_cr_gettrace(int, char *, int);
extern int *win32_cr_shellexecute(const char *);
# endif
extern boolean contains_directory(const char *);
#endif /* WIN32 */
#endif /* MICRO || WIN32 */
@@ -2675,7 +2675,6 @@ extern void get_plname_from_file(NHFILE *, char *, boolean) NONNULLARG12;
extern int restore_menu(winid);
#endif
extern boolean lookup_id_mapping(unsigned, unsigned *) NONNULLARG2;
extern int validate(NHFILE *, const char *, boolean) NONNULLARG1;
/* extern void reset_restpref(void); */
/* extern void set_restpref(const char *); */
/* extern void set_savepref(const char *); */
@@ -3496,8 +3495,7 @@ extern boolean comp_times(long);
#endif
extern boolean check_version(struct version_info *, const char *, boolean,
unsigned long) NONNULLARG1;
extern boolean uptodate(NHFILE *, const char *, unsigned long) NONNULLARG1;
extern void store_formatindicator(NHFILE *) NONNULLARG1;
extern int uptodate(NHFILE *, const char *, unsigned long) NONNULLARG1;
extern void store_version(NHFILE *) NONNULLARG1;
extern unsigned long get_feature_notice_ver(char *) NO_NNARGS;
extern unsigned long get_current_feature_ver(void);
@@ -3505,8 +3503,9 @@ extern const char *copyright_banner_line(int) NONNULL;
extern void early_version_info(boolean);
extern void dump_version_info(void);
extern void store_critical_bytes(NHFILE *) NONNULLARG1;
extern int compare_critical_bytes(NHFILE *);
extern int compare_critical_bytes(NHFILE *, int *, unsigned long) NONNULLARG1;
extern int get_critical_size_count(void);
extern int validate(NHFILE *, const char *, boolean) NONNULLARG1;
/* ### video.c ### */