]> granicus.if.org Git - nethack/commitdiff
recover fix
authornhmall <nhmall@nethack.org>
Wed, 29 Jan 2020 14:15:55 +0000 (09:15 -0500)
committernhmall <nhmall@nethack.org>
Wed, 29 Jan 2020 14:15:55 +0000 (09:15 -0500)
recover had deviated somewhat from NetHack in its
file expectations:
1) A couple of 3.7 fields needed to be accommodated.
2) hard-coded file size values had deviated.

The file sizes are now in an added header file named "filesize.h",
which is included at the bottom of config.h.

There will likely be another commit to write the filename size ahead
of the file name so that the precise number of characters can be read,
but since that will break existing saves, it can go in along with another
save-breaking commit.

This commit doesn't not alter savefiles written by nethack so does not
require an editlevel bump. It does alter the read-in expectation in
recover to match the game and this get recover working again.

include/config.h
include/decl.h
include/filesize.h [new file with mode: 0644]
sys/msdos/Makefile.GCC
sys/unix/Makefile.src
sys/winnt/Makefile.gcc
sys/winnt/Makefile.msc
util/recover.c

index b606b5db1e560f268df1aad31bde01b128e170eb..53a3ebd7943d05b092faab3c3defb2d43ca58b29 100644 (file)
@@ -579,5 +579,6 @@ typedef unsigned char uchar;
 #endif
 
 #include "global.h" /* Define everything else according to choices above */
+#include "filesize.h" /* Define file sizes shared between nethack and recover */
 
 #endif /* CONFIG_H */
index 54a58aa03222ad4bae76f3bb43d567c9e520aba4..a666a5db863fd74fff309df79b1a9edcd544b661 100644 (file)
@@ -7,70 +7,6 @@
 #define DECL_H
 
 #define E extern
-#if !defined(MICRO) && !defined(VMS) && !defined(WIN32)
-#define LOCKNAMESIZE (PL_NSIZ + 14) /* long enough for uid+name+.99 */
-#define LOCKNAMEINIT "1lock"
-#define BONESINIT "bonesnn.xxx.le"
-#define BONESSIZE sizeof(BONESINIT)
-#else
-#if defined(MICRO)
-#define LOCKNAMESIZE FILENAME
-#define LOCKNAMEINIT ""
-#define BONESINIT ""
-#define BONESSIZE FILENAME
-#endif
-#if defined(VMS)
-#define LOCKNAMESIZE (PL_NSIZ + 17) /* long enough for _uid+name+.99;1 */
-#define LOCKNAMEINIT "1lock"
-#define BONESINIT "bonesnn.xxx_le;1"
-#define BONESSIZE sizeof(BONESINIT)
-#endif
-#if defined(WIN32)
-#define LOCKNAMESIZE (PL_NSIZ + 25) /* long enough for username+-+name+.99 */
-#define LOCKNAMEINIT ""
-#define BONESINIT "bonesnn.xxx.le"
-#define BONESSIZE sizeof(BONESINIT)
-#endif
-#endif
-
-#define INDEXT ".xxxxxx"           /* largest indicator suffix */
-#define INDSIZE sizeof(INDEXT)
-
-#if defined(UNIX) || defined(__BEOS__)
-#define SAVEX "save/99999.e"
-#ifndef SAVE_EXTENSION
-#define SAVE_EXTENSION ""
-#endif
-#else /* UNIX || __BEOS__ */
-#ifdef VMS
-#define SAVEX "[.save]nnnnn.e;1"
-#ifndef SAVE_EXTENSION
-#define SAVE_EXTENSION ""
-#endif
-#else /* VMS */
-#if defined(WIN32) || defined(MICRO)
-#define SAVEX ""
-#if !defined(SAVE_EXTENSION)
-#ifdef MICRO
-#define SAVE_EXTENSION ".svh"
-#endif
-#ifdef WIN32
-#define SAVE_EXTENSION ".NetHack-saved-game"
-#endif
-#endif /* !SAVE_EXTENSION */
-#endif /* WIN32 || MICRO */
-#endif /* else !VMS */
-#endif /* else !(UNIX || __BEOS__) */
-
-#ifndef SAVE_EXTENSION
-#define SAVE_EXTENSION ""
-#endif
-
-#ifndef MICRO
-#define SAVESIZE (PL_NSIZ + sizeof(SAVEX) + sizeof(SAVE_EXTENSION) + INDSIZE)
-#else
-#define SAVESIZE FILENAME
-#endif
 
 /* max size of a windowtype option */
 #define WINTYPELEN 16
@@ -945,6 +881,7 @@ struct instance_globals {
     boolean chosen_symset_start;
     boolean chosen_symset_end;
     int symset_which_set;
+    /* SAVESIZE, BONESSIZE, LOCKNAMESIZE are defined in "filesize.h" */
     char SAVEF[SAVESIZE]; /* holds relative path of save file from playground */
 #ifdef MICRO
     char SAVEP[SAVESIZE]; /* holds path of directory for save file */
diff --git a/include/filesize.h b/include/filesize.h
new file mode 100644 (file)
index 0000000..5ec0590
--- /dev/null
@@ -0,0 +1,79 @@
+/* NetHack 3.7 filesize.h      $NHDT-Date: 1575245033 2019/12/02 00:03:53 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.126 $ */
+/*-Copyright (c) Michael Allison, 2020. */
+/* NetHack may be freely redistributed.  See license for details. */
+
+#ifndef FILESIZE_H 
+#define FILESIZE_H
+
+/*
+ *  Declarations for some file sizes, some of which need to be shared
+ *  between NetHack and recover. By placing them in here, there is less
+ *  chance of deviation between the two.
+ */
+
+#if !defined(MICRO) && !defined(VMS) && !defined(WIN32)
+#define LOCKNAMESIZE (PL_NSIZ + 14) /* long enough for uid+name+.99 */
+#define LOCKNAMEINIT "1lock"
+#define BONESINIT "bonesnn.xxx.le"
+#define BONESSIZE sizeof(BONESINIT)
+#else
+#if defined(MICRO)
+#define LOCKNAMESIZE FILENAME
+#define LOCKNAMEINIT ""
+#define BONESINIT ""
+#define BONESSIZE FILENAME
+#endif
+#if defined(VMS)
+#define LOCKNAMESIZE (PL_NSIZ + 17) /* long enough for _uid+name+.99;1 */
+#define LOCKNAMEINIT "1lock"
+#define BONESINIT "bonesnn.xxx_le;1"
+#define BONESSIZE sizeof(BONESINIT)
+#endif
+#if defined(WIN32)
+#define LOCKNAMESIZE (PL_NSIZ + 25) /* long enough for username+-+name+.99 */
+#define LOCKNAMEINIT ""
+#define BONESINIT "bonesnn.xxx.le"
+#define BONESSIZE sizeof(BONESINIT)
+#endif
+#endif
+
+#define INDEXT ".xxxxxx"           /* largest indicator suffix */
+#define INDSIZE sizeof(INDEXT)
+
+#if defined(UNIX) || defined(__BEOS__)
+#define SAVEX "save/99999.e"
+#ifndef SAVE_EXTENSION
+#define SAVE_EXTENSION ""
+#endif
+#else /* UNIX || __BEOS__ */
+#ifdef VMS
+#define SAVEX "[.save]nnnnn.e;1"
+#ifndef SAVE_EXTENSION
+#define SAVE_EXTENSION ""
+#endif
+#else /* VMS */
+#if defined(WIN32) || defined(MICRO)
+#define SAVEX ""
+#if !defined(SAVE_EXTENSION)
+#ifdef MICRO
+#define SAVE_EXTENSION ".svh"
+#endif
+#ifdef WIN32
+#define SAVE_EXTENSION ".NetHack-saved-game"
+#endif
+#endif /* !SAVE_EXTENSION */
+#endif /* WIN32 || MICRO */
+#endif /* else !VMS */
+#endif /* else !(UNIX || __BEOS__) */
+
+#ifndef SAVE_EXTENSION
+#define SAVE_EXTENSION ""
+#endif
+
+#ifndef MICRO
+#define SAVESIZE (PL_NSIZ + sizeof(SAVEX) + sizeof(SAVE_EXTENSION) + INDSIZE)
+#else
+#define SAVESIZE FILENAME
+#endif
+
+#endif /* FILESIZE_H */
index 1b0521b7c3beaaf59bb9ec6a6f5e36432d3dceab..16ecd8ec02016372aed6f492e9077a06b101d7da 100644 (file)
@@ -424,8 +424,8 @@ YOU_H          = $(MONST_H)         $(YOUPROP_H)        $(INCL)/align.h   \
 DISPLAY_H  = $(MONDATA_H)      $(INCL)/vision.h    $(INCL)/display.h
 PCCONF_H   = $(INCL)/micro.h   $(INCL)/system.h    $(INCL)/pcconf.h \
            $(MSYS)/pcvideo.h
-CONFIG_H   = $(GLOBAL_H)       $(INCL)/tradstdc.h  $(INCL)/config1.h \
-           $(INCL)/config.h
+CONFIG_H   = $(GLOBAL_H)       $(INCL)/filesize.h  $(INCL)/tradstdc.h \
+            $(INCL)/config1.h $(INCL)/config.h
 DECL_H    = $(YOU_H)           $(INCL)/spell.h     $(INCL)/color.h   \
             $(INCL)/obj.h      $(INCL)/onames.h    $(INCL)/pm.h      \
              $(INCL)/decl.h
index 7af0bba60b73f874180de6580a5984de084b1f52..06002056c86c67e23ecc14a1613ad8843508cb79 100644 (file)
@@ -729,11 +729,12 @@ depend: ../sys/unix/depend.awk \
 
 # config.h timestamp
 $(CONFIG_H): ../include/config.h ../include/config1.h ../include/tradstdc.h \
-               ../include/global.h ../include/coord.h ../include/vmsconf.h \
-               ../include/system.h ../include/nhlua.h ../include/unixconf.h \
-               ../include/os2conf.h ../include/micro.h ../include/pcconf.h \
-               ../include/tosconf.h ../include/amiconf.h ../include/macconf.h \
-               ../include/beconf.h ../include/wceconf.h ../include/ntconf.h
+               ../include/global.h ../include/filesize.h ../include/coord.h \
+               ../include/vmsconf.h ../include/system.h ../include/nhlua.h \
+               ../include/unixconf.h ../include/os2conf.h ../include/micro.h \
+               ../include/pcconf.h ../include/tosconf.h ../include/amiconf.h \
+               ../include/macconf.h ../include/beconf.h ../include/wceconf.h \
+               ../include/ntconf.h
        touch $(CONFIG_H)
 # hack.h timestamp
 $(HACK_H): ../include/hack.h $(CONFIG_H) ../include/lint.h ../include/align.h \
index 92828aea3ec65c7b85d5f9067da3eb00d0b6f29b..d835bab809ba43e272daf7d87ef42d6c325d74f0 100644 (file)
@@ -469,11 +469,11 @@ endif
 #==========================================
 
 CONFIG_H = $(INCL)/config.h $(INCL)/config1.h $(INCL)/tradstdc.h \
-              $(INCL)/global.h $(INCL)/coord.h $(INCL)/vmsconf.h \
-              $(INCL)/system.h $(INCL)/unixconf.h $(INCL)/os2conf.h \
-              $(INCL)/micro.h $(INCL)/pcconf.h $(INCL)/tosconf.h \
-              $(INCL)/amiconf.h $(INCL)/macconf.h $(INCL)/beconf.h \
-              $(INCL)/ntconf.h
+               $(INCL)/global.h $(INCL)/filesize.h $(INCL)/coord.h \
+               $(INCL)/vmsconf.h $(INCL)/system.h $(INCL)/unixconf.h \
+               $(INCL)/os2conf.h $(INCL)/micro.h $(INCL)/pcconf.h \
+               $(INCL)/tosconf.h $(INCL)/amiconf.h $(INCL)/macconf.h \
+               $(INCL)/beconf.h $(INCL)/ntconf.h
 
 HACK_H = $(INCL)/hack.h $(CONFIG_H) $(INCL)/align.h $(INCL)/context.h \
               $(INCL)/dungeon.h $(INCL)/monsym.h $(INCL)/mkroom.h \
index 11bbbadb23f5c46256b02bc2bc1d0c19c88a115b..0ea5deffb909e85b7b5ea9ea0d0d15a600de3509 100644 (file)
@@ -485,11 +485,12 @@ PDCLIB =
 #==========================================
 
 CONFIG_H = $(INCL)\config.h $(INCL)\config1.h $(INCL)\tradstdc.h \
-               $(INCL)\global.h $(INCL)\coord.h $(INCL)\vmsconf.h \
-               $(INCL)\system.h $(INCL)\nhlua.h $(INCL)\unixconf.h \
-               $(INCL)\os2conf.h $(INCL)\micro.h $(INCL)\pcconf.h \
-               $(INCL)\tosconf.h $(INCL)\amiconf.h $(INCL)\macconf.h \
-               $(INCL)\beconf.h $(INCL)\wceconf.h $(INCL)\ntconf.h
+               $(INCL)\global.h $(INCL)\filesize.h $(INCL)\coord.h \
+               $(INCL)\vmsconf.h $(INCL)\system.h $(INCL)\nhlua.h \
+               $(INCL)\unixconf.h $(INCL)\os2conf.h $(INCL)\micro.h \
+               $(INCL)\pcconf.h $(INCL)\tosconf.h $(INCL)\amiconf.h \
+               $(INCL)\macconf.h $(INCL)\beconf.h $(INCL)\wceconf.h \
+               $(INCL)\ntconf.h
 
 HACK_H = $(INCL)\hack.h $(CONFIG_H) $(INCL)\lint.h $(INCL)\align.h \
                $(INCL)\dungeon.h $(INCL)\monsym.h $(INCL)\mkroom.h \
index a3ed80984429eba4ac9ce75f4b46b2c5a187bac7..41e3a1399a9e83306027a488a3ee097bbb2c1e60 100644 (file)
@@ -27,6 +27,7 @@ void FDECL(set_levelfile_name, (int));
 int FDECL(open_levelfile, (int));
 int NDECL(create_savefile);
 void FDECL(copy_bytes, (int, int));
+static void FDECL(store_formatindicator, (int));
 
 #ifndef WIN_CE
 #define Fprintf (void) fprintf
@@ -37,20 +38,6 @@ static void nhce_message(FILE *, const char *, ...);
 
 #define Close (void) close
 
-#ifdef UNIX
-#define SAVESIZE (PL_NSIZ + 13) /* save/99999player.e */
-#else
-#ifdef VMS
-#define SAVESIZE (PL_NSIZ + 22) /* [.save]<uid>player.e;1 */
-#else
-#ifdef WIN32
-#define SAVESIZE (PL_NSIZ + 40) /* username-player.NetHack-saved-game */
-#else
-#define SAVESIZE FILENAME /* from macconf.h or pcconf.h */
-#endif
-#endif
-#endif
-
 #if defined(EXEPATH)
 char *FDECL(exepath, (char *));
 #endif
@@ -58,6 +45,8 @@ char *FDECL(exepath, (char *));
 #if defined(__BORLANDC__) && !defined(_WIN32)
 extern unsigned _stklen = STKSIZ;
 #endif
+
+/* SAVESIZE is defined in "filesize.h" */
 char savename[SAVESIZE]; /* holds relative path of save file from playground */
 
 int
@@ -216,11 +205,11 @@ restore_savefile(basename)
 char *basename;
 {
     int gfd, lfd, sfd;
-    int res = 0, lev, savelev, hpid, pltmpsiz;
+    int res = 0, lev, savelev, hpid, pltmpsiz, filecmc;
     xchar levc;
     struct version_info version_data;
     struct savefile_info sfi;
-    char plbuf[PL_NSIZ];
+    char plbuf[PL_NSIZ], indicator;
 
     /* level 0 file contains:
      *  pid of creating process (ignored here)
@@ -265,6 +254,10 @@ char *basename;
     }
     if ((read(gfd, (genericptr_t) savename, sizeof savename)
          != sizeof savename)
+        || (read(gfd, (genericptr_t) &indicator, sizeof indicator)
+            != sizeof indicator)
+        || (read(gfd, (genericptr_t) &filecmc, sizeof filecmc)
+            != sizeof filecmc)
         || (read(gfd, (genericptr_t) &version_data, sizeof version_data)
             != sizeof version_data)
         || (read(gfd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi)
@@ -277,6 +270,7 @@ char *basename;
     }
 
     /* save file should contain:
+     *  format indicator and cmc
      *  version info
      *  savefile info
      *  player name
@@ -299,6 +293,7 @@ char *basename;
         return -1;
     }
 
+    store_formatindicator(sfd);
     if (write(sfd, (genericptr_t) &version_data, sizeof version_data)
         != sizeof version_data) {
         Fprintf(stderr, "Error writing %s; recovery failed.\n", savename);
@@ -394,6 +389,19 @@ char *basename;
     return res;
 }
 
+static void
+store_formatindicator(fd)
+int fd;
+{
+    char indicate = 'h';      /* historical */
+    int cmc = 0;
+
+    write(fd, (genericptr_t) &indicate, sizeof indicate);
+    write(fd, (genericptr_t) &cmc, sizeof cmc);
+}
+
+
+
 #ifdef EXEPATH
 #ifdef __DJGPP__
 #define PATH_SEPARATOR '/'