make this work with dm(8) -- fix is ugly, but the code is worse
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 6 Mar 1989 12:20:59 +0000 (04:20 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 6 Mar 1989 12:20:59 +0000 (04:20 -0800)
SCCS-vsn: games/adventure/main.c 4.2
SCCS-vsn: games/adventure/init.c 4.2
SCCS-vsn: games/adventure/save.c 4.3

usr/src/games/adventure/init.c
usr/src/games/adventure/main.c
usr/src/games/adventure/save.c

index 44773a8..2fd2194 100644 (file)
@@ -1,9 +1,12 @@
 #
 /*      Re-coding of advent in C: data initialization                   */
 
 #
 /*      Re-coding of advent in C: data initialization                   */
 
-static char sccsid[] = "       init.c  4.1     82/05/11        ";
+static char sccsid[] = "       init.c  4.2     89/03/05        ";
 
 
-# include "hdr.h"
+#include <sys/types.h>
+#include <stdio.h>
+#include "hdr.h"
+#include "pathnames.h"
 
 int blklin = TRUE;
 int setup  = 0;
 
 int blklin = TRUE;
 int setup  = 0;
@@ -19,27 +22,22 @@ char *command;                          /* command we were called with  */
        linkdata();
        poof();
        setup=1;                        /* indicate that data is in     */
        linkdata();
        poof();
        setup=1;                        /* indicate that data is in     */
-       if (confirm("got the data.  save as \"advent\"? "))
-       {       if (save(command,"advent")<0)   /* save core image      */
-               {       printf("Save failed\n");
-                       exit(0);
-               }
+       if (save(command, "adventure") < 0) {
+               fprintf(stderr, "adventure: save failed\n");
+               exit(1);
        }
        }
-       else exit(0);
-       printf("Save succeeded.  Adding messages.\n");
-       adfd=open("advent",1);
+       adfd=open("adventure",1);
        lseek(adfd,0L,2);
        close(datfd);
        lseek(adfd,0L,2);
        close(datfd);
-       if (fork()==0)                  /* child process                */
-       {       close(1);
-               dup(adfd);              /* output goes to advent file   */
-               execl("/bin/cat","cat",TMPFILE,0);
-               printf("unable to find /bin/cat\n");
+       if (vfork() == 0) {
+               dup2(adfd, 1);
+               execl(_PATH_CAT, "cat", TMPFILE, 0);
+               fprintf(stderr, "adventure: unable to find %s\n", _PATH_CAT);
+               exit(1);
        }
        wait(&stat);
        unlink(TMPFILE);
        }
        wait(&stat);
        unlink(TMPFILE);
-       printf("Advent is ready.\n");
-       exit(0);
+       exit(stat);
 }
 
 
 }
 
 
@@ -167,11 +165,12 @@ trapdel()                               /* come here if he hits a del   */
 
 
 startup()
 
 
 startup()
-{       int tvec[2];
+{
+       time_t time();
+
        demo=start(0);
        demo=start(0);
-       time(tvec);
-       srand(tvec[1]|1);               /* random odd seed              */
-/*      srand(371);             */      /* non-random seed                      */
+       srand((int)(time((time_t *)NULL)));     /* random seed */
+       /* srand(371);                          /* non-random seed */
        hinted[3]=yes(65,1,0);
        newloc=1;
        setup=3;
        hinted[3]=yes(65,1,0);
        newloc=1;
        setup=3;
index c6c8c8b..ffe729c 100644 (file)
@@ -1,29 +1,40 @@
 /*      Re-coding of advent in C: main program                          */
 
 /*      Re-coding of advent in C: main program                          */
 
+#include <sys/file.h>
+#include <stdio.h>
 #include "hdr.h"
 #include "hdr.h"
+#include "pathnames.h"
 
 
-static char sccsid[] = "       main.c  4.1     82/05/11        ";
+static char sccsid[] = "       main.c  4.2     89/03/05        ";
 
 int    datfd = -1;
 main(argc,argv)
 int argc;
 char **argv;
 
 int    datfd = -1;
 main(argc,argv)
 int argc;
 char **argv;
-{       register int i;
+{
+       extern int errno;
+       register int i;
        int rval,ll;
        struct text *kk;
        extern trapdel();
        int rval,ll;
        struct text *kk;
        extern trapdel();
+       char *strerror();
        static reenter;
        static reenter;
-       if ((datfd = getcmd(argv[0])) < 0) {
-               write(2, "No adventure just now\n", 22);
-               exit(1);
-       }
+
        reenter++;
        reenter++;
-       setuid(getuid());
        switch (setup) {
        case 0:
        switch (setup) {
        case 0:
-               init(argv[0]);          /* set up initial variables     */
+               if ((datfd = open(*argv, O_RDONLY, 0)) < 0) {
+                       fprintf(stderr, "adventure: can't init\n");
+                       exit(1);
+               }
+               init(*argv);
                /* NOTREACHED */
        case 1:
                /* NOTREACHED */
        case 1:
+               if ((datfd = open(_PATH_ADVENTURE, O_RDONLY, 0)) < 0) {
+                       fprintf(stderr, "adventure: %s: %s\n", _PATH_ADVENTURE,
+                           strerror(errno));
+                       exit(1);
+               }
                startup();              /* prepare for a user           */
                signal(2,trapdel);
                break;
                startup();              /* prepare for a user           */
                signal(2,trapdel);
                break;
index 004883c..977d32f 100644 (file)
@@ -6,8 +6,9 @@
  *      (but people that do that get what they deserve)
  */
 
  *      (but people that do that get what they deserve)
  */
 
-static char sccsid[] = "       save.c  4.2     86/11/17        ";
+static char sccsid[] = "       save.c  4.3     89/03/05        ";
 
 
+#include <sys/file.h>
 #include <a.out.h>
 int filesize;                    /* accessible to caller         */
 
 #include <a.out.h>
 int filesize;                    /* accessible to caller         */
 
@@ -21,13 +22,8 @@ char *cmdfile,*outfile;
        struct exec header;
        int counter;
        char buff[512],pwbuf[120];
        struct exec header;
        int counter;
        char buff[512],pwbuf[120];
-       fdaout=getcmd(cmdfile);         /* open command wherever it is  */
+       fdaout = open(cmdfile, O_RDONLY, 0);    /* open command */
        if (fdaout<0) return(-1);       /* can do nothing without text  */
        if (fdaout<0) return(-1);       /* can do nothing without text  */
-       if ((fd=open(outfile,0))>0)     /* this restriction is so that  */
-       {       printf("Can't use an existing file\n"); /* we don't try */
-               close(fd);              /* to write over the commnd file*/
-               return(-1);
-       }
        if ((fd=creat(outfile,0755))== -1)
        {       printf("Cannot create %s\n",outfile);
                return(-1);
        if ((fd=creat(outfile,0755))== -1)
        {       printf("Cannot create %s\n",outfile);
                return(-1);
@@ -96,47 +92,3 @@ char *cmdfile,*outfile;
        write(fd,c,header.a_data);         /* write all data in 1 glob     */
        close(fd);
 }
        write(fd,c,header.a_data);         /* write all data in 1 glob     */
        close(fd);
 }
-
-#define        NULL    0
-
-char   *execat(), *getenv();
-
-getcmd(command)         /* get command name (wherever it is) like shell */
-char *command;
-{
-       char *pathstr;
-       register char *cp;
-       char fname[128];
-       int fd;
-
-       if ((pathstr = getenv("PATH")) == NULL)
-               pathstr = ":/bin:/usr/bin";
-       cp = index(command, '/')? "": pathstr;
-
-       do {
-               cp = execat(cp, command, fname);
-               if ((fd=open(fname,0))>0)
-                       return(fd);
-       } while (cp);
-
-       printf("Couldn't open %s\n",command);
-       return(-1);
-}
-
-static char *
-execat(s1, s2, si)
-register char *s1, *s2;
-char *si;
-{
-       register char *s;
-
-       s = si;
-       while (*s1 && *s1 != ':' && *s1 != '-')
-               *s++ = *s1++;
-       if (si != s)
-               *s++ = '/';
-       while (*s2)
-               *s++ = *s2++;
-       *s = '\0';
-       return(*s1? ++s1: 0);
-}