Module Name:    src
Committed By:   christos
Date:           Wed Nov 11 19:55:33 UTC 2020

Modified Files:
        src/games/warp: config.h config.h.SH config.sh init.c intrp.c score.c
            score.h sig.c term.c util.h warp.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/games/warp/config.h src/games/warp/sig.c \
    src/games/warp/util.h
cvs rdiff -u -r1.2 -r1.3 src/games/warp/config.h.SH
cvs rdiff -u -r1.1 -r1.2 src/games/warp/config.sh
cvs rdiff -u -r1.3 -r1.4 src/games/warp/init.c src/games/warp/score.h
cvs rdiff -u -r1.5 -r1.6 src/games/warp/intrp.c src/games/warp/score.c
cvs rdiff -u -r1.6 -r1.7 src/games/warp/term.c src/games/warp/warp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/warp/config.h
diff -u src/games/warp/config.h:1.4 src/games/warp/config.h:1.5
--- src/games/warp/config.h:1.4	Wed Nov 11 12:11:19 2020
+++ src/games/warp/config.h	Wed Nov 11 14:55:33 2020
@@ -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.
  */
Index: src/games/warp/sig.c
diff -u src/games/warp/sig.c:1.4 src/games/warp/sig.c:1.5
--- src/games/warp/sig.c:1.4	Tue Nov 10 17:42:19 2020
+++ src/games/warp/sig.c	Wed Nov 11 14:55:33 2020
@@ -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 @@ sig_init(void)
 	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 @@ sig_init(void)
     sigset(SIGTSTP, stop_catcher);
     sigset(SIGSTOP, stop_catcher);
 #endif
-#endif /* lint */
 }
 
 #ifdef SIGTSTP
Index: src/games/warp/util.h
diff -u src/games/warp/util.h:1.4 src/games/warp/util.h:1.5
--- src/games/warp/util.h:1.4	Tue Nov 10 17:42:19 2020
+++ src/games/warp/util.h	Wed Nov 11 14:55:33 2020
@@ -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)
-#define rand_mod(m) ((int)((double)myrand() / 32768.0 * ((double)(m))))
-/* pick number in 0..m-1 */
-
-#else
-
-#if RANDBITS < 31	/* 16 bits of rand()? */
-#define RANDRAND 1073741824.0 /* that's 2**30 */
-#define HALFRAND 0x8000 /* that's 2**15 */
-unsigned rand();
-#define myrand() (rand()&65535)
-#define rand_mod(m) ((int)((double)myrand() / 65536.0 * ((double)(m))))
-/* pick number in 0..m-1 */
-
-#else		/* assume 31 bits */
 #define RANDRAND 1152921504606846976.0 /* that's 2**60 */
 #define HALFRAND 0x40000000 /* that's 2**30 */
-long rand();
-#define myrand() rand()
+#define myrand() (int)random()
 #define rand_mod(m) ((myrand() / 37) % (m)) /* pick number in 0..m-1 */
 /*
  * The reason for the /37 above is that our random number generator yields
  * successive evens and odds, for some reason.  This makes strange star maps.
  */
-#endif
-#endif
-#endif
-
 
     /* we get fractions of seconds from calling ftime on timebuf */
 
-EXT struct timeb timebuf;
-#define roundsleep(x) (ftime(&timebuf),sleep(timebuf.millitm > 500?x+1:x))
+EXT struct timespec timebuf;
+#define roundsleep(x) (clock_gettime(CLOCK_REALTIME, &timebuf),sleep(timebuf.tv_nsec > 5000000000 ?x+1:x))
 
 #define waiting 0
 

Index: src/games/warp/config.h.SH
diff -u src/games/warp/config.h.SH:1.2 src/games/warp/config.h.SH:1.3
--- src/games/warp/config.h.SH:1.2	Tue Nov 10 17:42:19 2020
+++ src/games/warp/config.h.SH	Wed Nov 11 14:55:33 2020
@@ -87,16 +87,16 @@ cat <<!GROK!THIS! >config.h
  */
 #$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

Index: src/games/warp/config.sh
diff -u src/games/warp/config.sh:1.1 src/games/warp/config.sh:1.2
--- src/games/warp/config.sh:1.1	Mon Nov  9 18:37:05 2020
+++ src/games/warp/config.sh	Wed Nov 11 14:55:33 2020
@@ -60,7 +60,7 @@ d_phostname='/*undef'
 d_getpwent='/*undef'
 d_havetlib='define'
 termlib='-ltermlib'
-d_index='/*undef'
+d_strchr='/*undef'
 d_ioctl='define'
 d_normsig='define'
 jobslib=''

Index: src/games/warp/init.c
diff -u src/games/warp/init.c:1.3 src/games/warp/init.c:1.4
--- src/games/warp/init.c:1.3	Tue Nov 10 17:42:19 2020
+++ src/games/warp/init.c	Wed Nov 11 14:55:33 2020
@@ -246,11 +246,9 @@ stars_again:
 		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 @@ stars_again:
 		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 @@ stars_again:
 
 	    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) {
Index: src/games/warp/score.h
diff -u src/games/warp/score.h:1.3 src/games/warp/score.h:1.4
--- src/games/warp/score.h:1.3	Tue Nov 10 17:42:19 2020
+++ src/games/warp/score.h	Wed Nov 11 14:55:33 2020
@@ -26,7 +26,7 @@ EXT long oldeenergy;
 EXT long oldbenergy;
 EXT long oldcurscore;
 
-EXT char savefilename[40];
+EXT char savefilename[512];
 
 #ifdef SCOREFULL
 #define COMPOFF 0

Index: src/games/warp/intrp.c
diff -u src/games/warp/intrp.c:1.5 src/games/warp/intrp.c:1.6
--- src/games/warp/intrp.c:1.5	Wed Nov 11 12:11:19 2020
+++ src/games/warp/intrp.c	Wed Nov 11 14:55:33 2020
@@ -67,7 +67,7 @@ intrp_init(char *tcbuf)
 
     gethostname(buf,sizeof buf);
     hostname = savestr(buf);
-    if (index(hostname,'.'))
+    if (strchr(hostname,'.'))
 	hostname = savestr(hostname);
     else {
 	char hname[128];
@@ -191,7 +191,7 @@ static char *
 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 @@ dointerp(char *dest, size_t destsize, co
     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 @@ dointerp(char *dest, size_t destsize, co
 		    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 @@ dointerp(char *dest, size_t destsize, co
 		    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 @@ getrealname(uid_t uid)
 #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 @@ getrealname(uid_t uid)
 	    *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
Index: src/games/warp/score.c
diff -u src/games/warp/score.c:1.5 src/games/warp/score.c:1.6
--- src/games/warp/score.c:1.5	Wed Nov 11 12:11:19 2020
+++ src/games/warp/score.c	Wed Nov 11 14:55:33 2020
@@ -39,7 +39,7 @@ score_init(void)
 	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 @@ score_init(void)
     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 @@ score_init(void)
 
 	    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 @@ score(void)
     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 @@ score(void)
 	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 @@ save_game(void)
     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",

Index: src/games/warp/term.c
diff -u src/games/warp/term.c:1.6 src/games/warp/term.c:1.7
--- src/games/warp/term.c:1.6	Wed Nov 11 12:11:19 2020
+++ src/games/warp/term.c	Wed Nov 11 14:55:33 2020
@@ -286,8 +286,8 @@ term_set(char *tcbuf) /* temp area for "
 	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();
Index: src/games/warp/warp.c
diff -u src/games/warp/warp.c:1.6 src/games/warp/warp.c:1.7
--- src/games/warp/warp.c:1.6	Wed Nov 11 06:54:42 2020
+++ src/games/warp/warp.c	Wed Nov 11 14:55:33 2020
@@ -155,23 +155,6 @@ main(int argc, char *argv[])
 
     FILE *savfil;
 
-#if RANDBITS > 16
-    for (i=100; i; i--)
-	if (rand() >= 65536)
-	    goto rand_ok;
-    printf("Recompile with RANDBITS = 15 or 16.\n");
-    exit(1);
-#else
-#if RANDBITS > 15
-    for (i=100; i; i--) {
-	if (rand() >= 32768)
-	    goto rand_ok;
-    }
-    printf("Recompile with RANDBITS = 15.\n");
-    exit(1);
-#endif
-#endif
-
 #ifdef lint  /* to suppress "defined but never used" */
 # ifdef SIGTSTP
     (void)stop_catcher();
@@ -334,7 +317,7 @@ main(int argc, char *argv[])
 	roundsleep(1);
     }
 
-    srand(getpid());
+    srandom(getpid());
 
     do {
 	for (keepgoing = true;;) {
@@ -395,7 +378,7 @@ main(int argc, char *argv[])
 		    else
 			tmp = 1;
 		}
-	    } while (tmp != INTRCH && tmp != BREAKCH && !index(" qQs",tmp));
+	    } while (tmp != INTRCH && tmp != BREAKCH && !strchr(" qQs",tmp));
 	  if (tmp != ' ' && tmp != 's') break;
 	    if (!beginner && smarts < 20)
 		smarts += 4;

Reply via email to