On 2023/05/29 08:46:02 +0300, Anton Konyahin <m...@konyahin.xyz> wrote:
> I can suggest another (much less) patch, which still allows users to
> play hack without path modification. But all this stuff with checking
> saves creating time doesn't looks actual for me, so I keep original
> patch below.

Agreed.  I prefer the second patch too, which I'm reattaching since it
was mangled (whitespaces; 'patch -l' is not enough, but 'got patch'
managed to apply it.)

Will wait a bit still in case someone disagrees, but I don't really
see the point in having hack scraping $PATH for finding itself; the
format wasn't changed since the initial import so I guess we'll be
fine :-)

diff /usr/src
commit - 79631e141468cced94e502d777a484fa0eb1f60f
path + /usr/src
blob - 4abe525065dddaabea09e3a050b3a3db78a10e39
file + games/hack/hack.bones.c
--- games/hack/hack.bones.c
+++ games/hack/hack.bones.c
@@ -139,17 +139,15 @@ getbones(void)
 int
 getbones(void)
 {
-       int fd,x,y,ok;
+       int fd,x,y;
 
        if(rn2(3)) return(0);   /* only once in three times do we find bones */
        bones[6] = '0' + dlevel/10;
        bones[7] = '0' + dlevel%10;
        if((fd = open(bones, O_RDONLY)) == -1) return(0);
-       if((ok = uptodate(fd)) != 0){
-               getlev(fd, 0, dlevel);
-               for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++)
-                       levl[x][y].seen = levl[x][y].new = 0;
-       }
+       getlev(fd, 0, dlevel);
+       for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++)
+               levl[x][y].seen = levl[x][y].new = 0;
        (void) close(fd);
 #ifdef WIZARD
        if(!wizard)     /* duvel!frans: don't remove bones while debugging */
@@ -158,5 +156,5 @@ getbones(void)
                pline("Cannot unlink %s .", bones);
                return(0);
        }
-       return(ok);
+       return(1);
 }
blob - 4fa5eafc297d74a98cd106aadcc3ab67c5783b61
file + games/hack/hack.h
--- games/hack/hack.h
+++ games/hack/hack.h
@@ -681,7 +681,6 @@ int  uptodate(int);
 int  night(void);
 int  midnight(void);
 void gethdate(char *);
-int  uptodate(int);
 void getlock(void);
 #ifdef MAIL
 void getmailstatus(void);
blob - 51a066600dbd8313b8fca95f7ef761e08c03e71d
file + games/hack/hack.main.c
--- games/hack/hack.main.c
+++ games/hack/hack.main.c
@@ -103,7 +103,6 @@ main(int argc, char **argv)
 int
 main(int argc, char **argv)
 {
-       extern char *__progname;
        int fd;
 #ifdef CHDIR
        char *dir;
@@ -183,15 +182,6 @@ main(int argc, char **argv)
        u.ux = FAR;     /* prevent nscr() */
        (void) signal(SIGHUP, hackhangup);
 
-       /*
-        * Find the creation date of this game,
-        * so as to avoid restoring outdated savefiles.
-        */
-       gethdate(__progname);
-
-       /*
-        * We cannot do chdir earlier, otherwise gethdate will fail.
-        */
 #ifdef CHDIR
        chdirx(dir,1);
 #endif
@@ -298,8 +288,7 @@ main(int argc, char **argv)
        setftty();
        (void) snprintf(SAVEF, sizeof SAVEF, "save/%u%s", getuid(), plname);
        regularize(SAVEF+5);            /* avoid . or / in name */
-       if((fd = open(SAVEF, O_RDONLY)) >= 0 &&
-          (uptodate(fd) || unlink(SAVEF) == 666)) {
+       if((fd = open(SAVEF, O_RDONLY)) >= 0) {
                (void) signal(SIGINT,done1);
                pline("Restoring old save file...");
                (void) fflush(stdout);
blob - 96a9ca84d2f783477114095339b566d36cb4d17c
file + games/hack/hack.unix.c
--- games/hack/hack.unix.c
+++ games/hack/hack.unix.c
@@ -154,53 +154,8 @@ struct stat buf, hbuf;
        return(getlt()->tm_hour == 0);
 }
 
-struct stat buf, hbuf;
+struct stat buf;
 
-void
-gethdate(char *name)
-{
-       char *p, *np, *path;
-       char filename[PATH_MAX];
-
-       if (strchr(name, '/') != NULL || (p = getenv("PATH")) == NULL)
-               p = "";
-       np = path = strdup(p);  /* Make a copy for strsep. */
-       if (path == NULL)
-               err(1, NULL);
-
-       for (;;) {
-               if ((p = strsep(&np, ":")) == NULL)
-                       break;
-               if (*p == '\0')                 /* :: */
-                       (void) strlcpy(filename, name, sizeof filename);
-               else
-                       (void) snprintf(filename, sizeof filename,
-                           "%s/%s", p, name);
-
-               if (stat(filename, &hbuf) == 0) {
-                       free(path);
-                       return;
-               }
-       }
-       error("Cannot get status of %s.",
-               (p = strrchr(name, '/')) ? p+1 : name);
-       free(path);
-}
-
-int
-uptodate(int fd)
-{
-       if(fstat(fd, &buf)) {
-               pline("Cannot get status of saved level? ");
-               return(0);
-       }
-       if(buf.st_mtime < hbuf.st_mtime) {
-               pline("Saved level is out of date. ");
-               return(0);
-       }
-       return(1);
-}
-
 /* see whether we should throw away this xlock file */
 static int
 veryold(int fd)

Reply via email to