Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/warp use strchr, strrchr, random, more lint removal, s...



details:   https://anonhg.NetBSD.org/src/rev/5fe8b116f5af
branches:  trunk
changeset: 956949:5fe8b116f5af
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 11 19:55:33 2020 +0000

description:
use strchr, strrchr, random, more lint removal, savefile in /var/games/warp
not /usr/share/games/warp...

diffstat:

 games/warp/config.h    |   6 ------
 games/warp/config.h.SH |  12 ++++++------
 games/warp/config.sh   |   2 +-
 games/warp/init.c      |   6 +-----
 games/warp/intrp.c     |  18 +++++++++---------
 games/warp/score.c     |  16 +++++++++-------
 games/warp/score.h     |   2 +-
 games/warp/sig.c       |   6 ++----
 games/warp/term.c      |   4 ++--
 games/warp/util.h      |  36 +++---------------------------------
 games/warp/warp.c      |  21 ++-------------------
 11 files changed, 36 insertions(+), 93 deletions(-)

diffs (truncated from 383 to 300 lines):

diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/config.h
--- a/games/warp/config.h       Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/config.h       Wed Nov 11 19:55:33 2020 +0000
@@ -85,12 +85,6 @@
  */
 #define PREFSHELL "/bin/csh"           /**/
 
-/* RANDBITS:
- *     This symbol contains the number of bits of random number the rand()
- *     function produces.  Usual values are 15, 16, and 31.
- */
-#define RANDBITS 15            /**/
-
 /* ROOTID:
  *     This symbol contains the uid of root, normally 0.
  */
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/config.h.SH
--- a/games/warp/config.h.SH    Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/config.h.SH    Wed Nov 11 19:55:33 2020 +0000
@@ -87,16 +87,16 @@
  */
 #$d_havetlib   HAVETERMLIB     /**/
 
-/* index:
- *     This preprocessor symbol is defined, along with rindex, if the system
+/* strchr:
+ *     This preprocessor symbol is defined, along with strrchr, if the system
  *     uses the strchr and strrchr routines instead.
  */
-/* rindex:
- *     This preprocessor symbol is defined, along with index, if the system
+/* strrchr:
+ *     This preprocessor symbol is defined, along with strchr, if the system
  *     uses the strchr and strrchr routines instead.
  */
-#$d_index      index strchr    /* cultural */
-#$d_index      rindex strrchr  /*  differences? */
+#$d_strchr     strchr strchr   /* cultural */
+#$d_strchr     strrchr strrchr /*  differences? */
 
 /* IOCTL:
  *     This symbol, if defined, indicates that sys/ioctl.h exists and should
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/config.sh
--- a/games/warp/config.sh      Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/config.sh      Wed Nov 11 19:55:33 2020 +0000
@@ -60,7 +60,7 @@
 d_getpwent='/*undef'
 d_havetlib='define'
 termlib='-ltermlib'
-d_index='/*undef'
+d_strchr='/*undef'
 d_ioctl='define'
 d_normsig='define'
 jobslib=''
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/init.c
--- a/games/warp/init.c Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/init.c Wed Nov 11 19:55:33 2020 +0000
@@ -246,11 +246,9 @@
                x = rand_mod(XSIZE);    /* pick from 0..39, uniform */
                break;
            case 1: case 2: case 3:
-#ifndef lint
                x = (int)((((double)(myrand()-HALFRAND)) *
                           ((double)(myrand()-HALFRAND))/RANDRAND)
                          * 20.0) + xoff;       /* pick from -20..20, clumped */
-#endif
                break;
            case 4:
                if (fscanf(mapfp,"%d %d\n",&ypred,&xpred) == EOF)
@@ -271,11 +269,9 @@
                y = rand_mod(YSIZE);
                break;
            case 1:
-#ifndef lint
                y = (int)((((double)(myrand()-HALFRAND)) *
                           ((double)(myrand()-HALFRAND))/RANDRAND)
                          * 12.0) + yoff;       /* pick from -12..12, clumped */
-#endif
                break;
            case 2:
 #ifndef lint
@@ -492,7 +488,7 @@
 
            dist = rand_mod(20);
            ch = let[dist];
-       }               /* grr, venix doesn't like indexing into string */
+       }               /* grr, venix doesn't like strchring into string */
        obj = make_object(Enemy,ch,y,x,0,0,
            e + rand_mod(super*200+2),e/4,&root);
        if (numpirates-- > 0) {
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/intrp.c
--- a/games/warp/intrp.c        Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/intrp.c        Wed Nov 11 19:55:33 2020 +0000
@@ -67,7 +67,7 @@
 
     gethostname(buf,sizeof buf);
     hostname = savestr(buf);
-    if (index(hostname,'.'))
+    if (strchr(hostname,'.'))
        hostname = savestr(hostname);
     else {
        char hname[128];
@@ -191,7 +191,7 @@
 skipinterp(const char *pattern, const char *stoppers)
 {
 
-    while (*pattern && (!stoppers || !index(stoppers,*pattern))) {
+    while (*pattern && (!stoppers || !strchr(stoppers,*pattern))) {
 #ifdef DEBUGGING
        if (debug & 8)
            printf("skipinterp till %s at %s\r\n",stoppers?stoppers:"",pattern);
@@ -276,7 +276,7 @@
     bool lastcomp = false;
     int metabit = 0;
 
-    while (*pattern && (!stoppers || !index(stoppers,*pattern))) {
+    while (*pattern && (!stoppers || !strchr(stoppers,*pattern))) {
 #ifdef DEBUGGING
        if (debug & 8)
            printf("dointerp till %s at %s\r\n",stoppers?stoppers:"",pattern);
@@ -294,7 +294,7 @@
                    break;
                case '{':
                    pattern = cpytill(scrbuf,pattern+1,'}');
-                   if ((s = index(scrbuf,'-')) != NULL)
+                   if ((s = strchr(scrbuf,'-')) != NULL)
                        *s++ = '\0';
                    else
                        s = nullstr;
@@ -424,7 +424,7 @@
                    safecpy(scrbuf,s,(sizeof scrbuf));
                    s = scrbuf;
                }
-               if (upper || !(t=rindex(s,'/')))
+               if (upper || !(t=strrchr(s,'/')))
                    t = s;
                while (*t && !isalpha((unsigned char)*t)) {
                    t++;
@@ -531,9 +531,9 @@
 #ifdef BERKJUNK
     while (*s && !isalnum(*s) && *s != '&') s++;
 #endif
-    if ((c = index(s, ',')) != NULL)
+    if ((c = strchr(s, ',')) != NULL)
        *c = '\0';
-    if ((c = index(s, ';')) != NULL)
+    if ((c = strchr(s, ';')) != NULL)
        *c = '\0';
     s = cpytill(buf,s,'&');
     if (*s == '&') {                   /* whoever thought this one up was */
@@ -544,9 +544,9 @@
            *c = toupper((unsigned char)*c);            /* gack and double gack */
     }
 #else
-    if ((c = index(s, '(')) != NULL)
+    if ((c = strchr(s, '(')) != NULL)
        *c = '\0';
-    if ((c = index(s, '-')) != NULL)
+    if ((c = strchr(s, '-')) != NULL)
        s = c;
     strcpy(buf,tmpbuf);
 #endif
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/score.c
--- a/games/warp/score.c        Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/score.c        Wed Nov 11 19:55:33 2020 +0000
@@ -39,7 +39,7 @@
        printf("Cannot access %s\r\n",SAVEDIR);
        finalize(1);
     }
-    if (filestat.st_gid != getegid()) {
+    if (filestat.st_gid != getegid() && geteuid() != 0) {
        printf("Warp will not run right without being setgid.\r\n");
        finalize(1);
     }
@@ -63,7 +63,8 @@
     if (scorespec)
        wscore();
 
-    snprintf(savefilename, sizeof(savefilename), "save.%s", logname);
+    snprintf(savefilename, sizeof(savefilename), "%s/save.%s",
+       SAVEDIR, logname);
 
     savfil = experimenting ? NULL : fopen(savefilename,"r");
     if (savfil != NULL && fgets(spbuf,100,savfil) != NULL) {
@@ -75,7 +76,7 @@
 
            tmpbuf[strlen(tmpbuf)-1] = '\0';
            printf("You seem to have left a game %s.\r\n",tmpbuf+9);
-           s = index(tmpbuf+9, ',');
+           s = strchr(tmpbuf+9, ',');
            *s = '\0';
            processnum = atoi(s+11);
            if (kill(processnum, SIGINT)) {
@@ -615,8 +616,8 @@
     eat_typeahead();
     do {
        getcmd(&tmp);
-    } while (tmp != INTRCH && tmp != BREAKCH && !index(" rqQ",tmp));
-    if (index("qQr",tmp)) {
+    } while (tmp != INTRCH && tmp != BREAKCH && !strchr(" rqQ",tmp));
+    if (strchr("qQr",tmp)) {
        justonemoretime = (tmp == 'r');
        if (logfd != NULL)
            fclose(logfd);
@@ -646,7 +647,7 @@
        eat_typeahead();
        do {
            getcmd(&tmp);
-       } while (tmp != INTRCH && tmp != BREAKCH && !index("nNyY \n\r",tmp));
+       } while (tmp != INTRCH && tmp != BREAKCH && !strchr("nNyY \n\r",tmp));
        if (tmp == 'n' || tmp == 'N' || tmp == INTRCH || tmp == BREAKCH)
            justonemoretime = false;
     }
@@ -672,8 +673,9 @@
     if (experimenting)
        return;
     if ((savfil = fopen(savefilename,"w")) == NULL) {
+       int e = errno;
        resetty();
-       printf("Cannot save game\r\n");
+       printf("Cannot save game in %s (%s)\r\n", savefilename, strerror(e));
        finalize(1);
     }
     fprintf(savfil, "%-8s %10ld, %2d,%5d,%2d,%2d,%3d %c%c%c%c%c%c%c%c%c\n",
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/score.h
--- a/games/warp/score.h        Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/score.h        Wed Nov 11 19:55:33 2020 +0000
@@ -26,7 +26,7 @@
 EXT long oldbenergy;
 EXT long oldcurscore;
 
-EXT char savefilename[40];
+EXT char savefilename[512];
 
 #ifdef SCOREFULL
 #define COMPOFF 0
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/sig.c
--- a/games/warp/sig.c  Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/sig.c  Wed Nov 11 19:55:33 2020 +0000
@@ -25,9 +25,6 @@
 void
 sig_init(void)
 {
-#ifdef lint
-    ;
-#else
     sigignore(SIGINT);  /* for inquiry of existence via kill call */
 #ifdef SIGTTOU
     sigignore(SIGTTOU);
@@ -38,8 +35,10 @@
        sigset(SIGQUIT, sig_catcher);
        sigset(SIGILL, sig_catcher);
        sigset(SIGFPE, sig_catcher);
+#if 0
        sigset(SIGBUS, sig_catcher);
        sigset(SIGSEGV, sig_catcher);
+#endif
        sigset(SIGSYS, sig_catcher);
        sigset(SIGTERM, sig_catcher);
     }
@@ -53,7 +52,6 @@
     sigset(SIGTSTP, stop_catcher);
     sigset(SIGSTOP, stop_catcher);
 #endif
-#endif /* lint */
 }
 
 #ifdef SIGTSTP
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/term.c
--- a/games/warp/term.c Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/term.c Wed Nov 11 19:55:33 2020 +0000
@@ -286,8 +286,8 @@
        no_can_do("dumb");
     if (!scorespec && (LINES < 24 || COLS < 80))
        no_can_do("puny");
-    if (LINES > 25)
-       no_can_do("humongus");
+//    if (LINES > 25)
+//     no_can_do("humongous");
 
     crmode();
     raw();
diff -r 8351cbfa05f7 -r 5fe8b116f5af games/warp/util.h
--- a/games/warp/util.h Wed Nov 11 19:54:53 2020 +0000
+++ b/games/warp/util.h Wed Nov 11 19:55:33 2020 +0000
@@ -6,49 +6,19 @@
  * 
  */
 
-#if RANDBITS < 15 || defined(lint)
-#define rand_mod(m) getpid()
-#define RANDRAND 0.0
-#define HALFRAND 0
-#define myrand() getpid()
-#else
-#if RANDBITS == 15     /* 15 bits of rand()? */
-#define RANDRAND 268435456.0 /* that's 2**28 */
-#define HALFRAND 0x4000 /* that's 2**14 */
-int rand(void);
-#define myrand() (rand()&32767)



Home | Main Index | Thread Index | Old Index