diff --git a/include/config.h b/include/config.h index b606b5db1..53a3ebd79 100644 --- a/include/config.h +++ b/include/config.h @@ -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 */ diff --git a/include/decl.h b/include/decl.h index 54a58aa03..a666a5db8 100644 --- a/include/decl.h +++ b/include/decl.h @@ -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 index 000000000..5ec05904e --- /dev/null +++ b/include/filesize.h @@ -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 */ diff --git a/sys/msdos/Makefile.GCC b/sys/msdos/Makefile.GCC index 1b0521b7c..16ecd8ec0 100644 --- a/sys/msdos/Makefile.GCC +++ b/sys/msdos/Makefile.GCC @@ -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 diff --git a/sys/unix/Makefile.src b/sys/unix/Makefile.src index 7af0bba60..06002056c 100644 --- a/sys/unix/Makefile.src +++ b/sys/unix/Makefile.src @@ -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 \ diff --git a/sys/winnt/Makefile.gcc b/sys/winnt/Makefile.gcc index 92828aea3..d835bab80 100644 --- a/sys/winnt/Makefile.gcc +++ b/sys/winnt/Makefile.gcc @@ -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 \ diff --git a/sys/winnt/Makefile.msc b/sys/winnt/Makefile.msc index 11bbbadb2..0ea5deffb 100644 --- a/sys/winnt/Makefile.msc +++ b/sys/winnt/Makefile.msc @@ -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 \ diff --git a/util/recover.c b/util/recover.c index a3ed80984..41e3a1399 100644 --- a/util/recover.c +++ b/util/recover.c @@ -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]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 '/'