Source-Changes-HG archive

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

[src/trunk]: src/games/boggle/boggle Factor out some common code; pass -Wstri...



details:   https://anonhg.NetBSD.org/src/rev/b1551f965a3a
branches:  trunk
changeset: 782055:b1551f965a3a
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sat Oct 13 20:12:18 2012 +0000

description:
Factor out some common code; pass -Wstrict-overflow.

diffstat:

 games/boggle/boggle/bog.c |  47 ++++++++++++++++++++++++-----------------------
 1 files changed, 24 insertions(+), 23 deletions(-)

diffs (127 lines):

diff -r b79dc71073c6 -r b1551f965a3a games/boggle/boggle/bog.c
--- a/games/boggle/boggle/bog.c Sat Oct 13 19:58:53 2012 +0000
+++ b/games/boggle/boggle/bog.c Sat Oct 13 20:12:18 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bog.c,v 1.27 2011/08/26 06:18:17 dholland Exp $        */
+/*     $NetBSD: bog.c,v 1.28 2012/10/13 20:12:18 dholland Exp $        */
 
 /*-
  * Copyright (c) 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)bog.c      8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: bog.c,v 1.27 2011/08/26 06:18:17 dholland Exp $");
+__RCSID("$NetBSD: bog.c,v 1.28 2012/10/13 20:12:18 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -64,6 +64,7 @@
 static void checkdict(void);
 static void newgame(const char *);
 static int compar(const void *, const void *);
+static void clearwordpath(int full);
 static void usage(void) __dead;
 
 struct dictindex dictindex[26];
@@ -286,19 +287,13 @@
 static char *
 batchword(FILE *fp)
 {
-       int *p, *q;
        char *w;
 
-       q = &wordpath[MAXWORDLEN + 1];
-       p = wordpath;
-       while (p < q)
-               *p++ = -1;
+       clearwordpath(1);
        while ((w = nextword(fp)) != NULL) {
                if (wordlen < minlength)
                        continue;
-               p = wordpath;
-               while (p < q && *p != -1)
-                       *p++ = -1;
+               clearwordpath(0);
                usedbits = 0;
                if (checkword(w, -1, wordpath) != -1)
                        return (w);
@@ -314,7 +309,7 @@
 static void
 playgame(void)
 {
-       int i, *p, *q;
+       int i;
        time_t t;
        char buf[MAXWORDLEN + 1];
 
@@ -326,10 +321,7 @@
 
        time(&start_t);
 
-       q = &wordpath[MAXWORDLEN + 1];
-       p = wordpath;
-       while (p < q)
-               *p++ = -1;
+       clearwordpath(1);
        showboard(board);
        startwords();
        if (setjmp(env)) {
@@ -362,9 +354,7 @@
                        continue;
                }
 
-               p = wordpath;
-               while (p < q && *p != -1)
-                       *p++ = -1;
+               clearwordpath(0);
                usedbits = 0;
 
                if (checkword(buf, -1, wordpath) < 0)
@@ -554,13 +544,12 @@
        char *p, *w;
        const char **pw;
        int i;
-       int prevch, previndex, *pi, *qi, st;
+       int prevch, previndex, st;
 
        mwordsp = mwords;
        nmwords = 0;
        pw = pword;
        prevch ='a';
-       qi = &wordpath[MAXWORDLEN + 1];
 
        (void) dictseek(dictfp, 0L, SEEK_SET);
        while ((w = nextword(dictfp)) != NULL) {
@@ -598,9 +587,7 @@
                        }
                }
 
-               pi = wordpath;
-               while (pi < qi && *pi != -1)
-                       *pi++ = -1;
+               clearwordpath(0);
                usedbits = 0;
                if (checkword(w, -1, wordpath) == -1)
                        continue;
@@ -697,6 +684,20 @@
 
 }
 
+/*
+ * Clear wordpath[].
+ */
+static void
+clearwordpath(int full)
+{
+       size_t pos;
+       const size_t max = MAXWORDLEN + 1;
+
+       for (pos = 0; pos < max && (full || wordpath[pos] != -1); pos++) {
+               wordpath[pos] = -1;
+       }
+}
+
 static int
 compar(const void *p, const void *q)
 {



Home | Main Index | Thread Index | Old Index