Source-Changes-HG archive

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

[src/trunk]: src/games/backgammon Crack down on global variables with single-...



details:   https://anonhg.NetBSD.org/src/rev/0fd75a20dd97
branches:  trunk
changeset: 782047:0fd75a20dd97
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sat Oct 13 18:44:14 2012 +0000

description:
Crack down on global variables with single-letter names.

diffstat:

 games/backgammon/backgammon/main.c     |   23 +++--
 games/backgammon/backgammon/move.c     |  123 ++++++++++++++++----------------
 games/backgammon/common_source/allow.c |   47 ++++++------
 games/backgammon/common_source/back.h  |   25 ++++--
 games/backgammon/common_source/check.c |   28 ++++---
 games/backgammon/common_source/init.c  |   14 +--
 games/backgammon/common_source/one.c   |   72 ++++++++++--------
 games/backgammon/common_source/save.c  |   10 +-
 games/backgammon/common_source/subs.c  |   25 +++--
 games/backgammon/common_source/table.c |   55 ++++++++------
 games/backgammon/teachgammon/tutor.c   |   35 ++++----
 11 files changed, 241 insertions(+), 216 deletions(-)

diffs (truncated from 1206 to 300 lines):

diff -r 4d967abf1faf -r 0fd75a20dd97 games/backgammon/backgammon/main.c
--- a/games/backgammon/backgammon/main.c        Sat Oct 13 18:26:03 2012 +0000
+++ b/games/backgammon/backgammon/main.c        Sat Oct 13 18:44:14 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.28 2010/03/22 05:10:19 mrg Exp $    */
+/*     $NetBSD: main.c,v 1.29 2012/10/13 18:44:14 dholland Exp $       */
 
 /*
  * Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: main.c,v 1.28 2010/03/22 05:10:19 mrg Exp $");
+__RCSID("$NetBSD: main.c,v 1.29 2012/10/13 18:44:14 dholland Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -94,6 +94,7 @@
        int     l;              /* non-descript index */
        char    c;              /* non-descript character storage */
        time_t  t;              /* time for random num generator */
+       struct move *mm = &gm;
 
        /* revoke setgid privileges */
        setgid(getgid());
@@ -245,17 +246,17 @@
                if (!rflag) {
                        if (tflag)
                                curmove(17, 0);
-                       while (D0 == D1)        /* no doubles */
+                       while (mm->D0 == mm->D1)        /* no doubles */
                                roll();
 
                        /* print rolls */
                        writel(rollr);
-                       writec(D0 + '0');
+                       writec(mm->D0 + '0');
                        writel(rollw);
-                       writec(D1 + '0');
+                       writec(mm->D1 + '0');
 
                        /* winner goes first */
-                       if (D0 > D1) {
+                       if (mm->D0 > mm->D1) {
                                writel(rstart);
                                cturn = 1;
                        } else {
@@ -292,7 +293,7 @@
                        if (cturn == pnum)      /* computer's move */
                                move(0);
                        else {  /* player's move */
-                               mvlim = movallow();
+                               mm->mvlim = movallow();
                                /* reprint roll */
                                if (tflag)
                                        curmove(cturn == -1 ? 18 : 19, 0);
@@ -380,13 +381,13 @@
                                case '\n':
                                        roll();
                                        writel(" rolls ");
-                                       writec(D0 + '0');
+                                       writec(mm->D0 + '0');
                                        writec(' ');
-                                       writec(D1 + '0');
+                                       writec(mm->D1 + '0');
                                        writel(".  ");
 
                                        /* see if he can move */
-                                       if ((mvlim = movallow()) == 0) {
+                                       if ((mm->mvlim = movallow()) == 0) {
 
                                                /* can't move */
                                                writel(toobad1);
@@ -435,7 +436,7 @@
                                proll();
 
                                /* can he move? */
-                               if ((mvlim = movallow()) == 0) {
+                               if ((mm->mvlim = movallow()) == 0) {
 
                                        /* he can't */
                                        writel(toobad2);
diff -r 4d967abf1faf -r 0fd75a20dd97 games/backgammon/backgammon/move.c
--- a/games/backgammon/backgammon/move.c        Sat Oct 13 18:26:03 2012 +0000
+++ b/games/backgammon/backgammon/move.c        Sat Oct 13 18:44:14 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: move.c,v 1.10 2009/08/12 05:17:57 dholland Exp $       */
+/*     $NetBSD: move.c,v 1.11 2012/10/13 18:44:14 dholland Exp $       */
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,10 +34,12 @@
 #if 0
 static char sccsid[] = "@(#)move.c     8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: move.c,v 1.10 2009/08/12 05:17:57 dholland Exp $");
+__RCSID("$NetBSD: move.c,v 1.11 2012/10/13 18:44:14 dholland Exp $");
 #endif
 #endif /* not lint */
 
+#include <assert.h>
+
 #include "back.h"
 #include "backlocal.h"
 
@@ -84,15 +86,15 @@
 
 
 static int bcomp(struct BOARD *, struct BOARD *);
-static struct BOARD *bsave(void);
-static void binsert(struct BOARD *);
-static void boardcopy(struct BOARD *);
+static struct BOARD *bsave(struct move *);
+static void binsert(struct move *, struct BOARD *);
+static void boardcopy(struct move *, struct BOARD *);
 static void makefree(struct BOARD *);
-static void mvcheck(struct BOARD *, struct BOARD *);
+static void mvcheck(struct move *, struct BOARD *, struct BOARD *);
 static struct BOARD *nextfree(void);
-static void trymove(int, int);
-static void pickmove(void);
-static void movcmp(void);
+static void trymove(struct move *, int, int);
+static void pickmove(struct move *);
+static void movcmp(struct move *);
 static int movegood(void);
 
 
@@ -102,6 +104,7 @@
 {
        int     i;              /* index */
        int     l;              /* last man */
+       struct move *mm = &gm;
 
        l = 0;
        if (okay) {
@@ -132,17 +135,17 @@
                curmove(cturn == -1 ? 18 : 19, 0);
        writel(*Colorptr);
        writel(" rolls ");
-       writec(D0 + '0');
+       writec(mm->D0 + '0');
        writec(' ');
-       writec(D1 + '0');
+       writec(mm->D1 + '0');
        /* make tty interruptable while thinking */
        if (tflag)
                cline();
        fixtty(&noech);
 
        /* find out how many moves */
-       mvlim = movallow();
-       if (mvlim == 0) {
+       mm->mvlim = movallow();
+       if (mm->mvlim == 0) {
                writel(" but cannot use it.\n");
                nexturn();
                fixtty(&raw);
@@ -153,17 +156,17 @@
                cp[i] = cg[i] = 0;
 
        /* strategize */
-       trymove(0, 0);
-       pickmove();
+       trymove(mm, 0, 0);
+       pickmove(mm);
 
        /* print move */
        writel(" and moves ");
-       for (i = 0; i < mvlim; i++) {
+       for (i = 0; i < mm->mvlim; i++) {
                if (i > 0)
                        writec(',');
-               wrint(p[i] = cp[i]);
+               wrint(mm->p[i] = cp[i]);
                writec('-');
-               wrint(g[i] = cg[i]);
+               wrint(mm->g[i] = cg[i]);
                makmove(i);
        }
        writec('.');
@@ -173,9 +176,9 @@
                curmove(20, 0);
        else
                writec('\n');
-       for (i = 0; i < mvlim; i++)
-               if (h[i])
-                       wrhit(g[i]);
+       for (i = 0; i < mm->mvlim; i++)
+               if (mm->h[i])
+                       wrhit(mm->g[i]);
        /* get ready for next move */
        nexturn();
        if (!okay) {
@@ -188,27 +191,27 @@
 /*     mvnum   == number of move (rel zero) */
 /*     swapped == see if swapped also tested */
 static void
-trymove(int mvnum, int swapped)
+trymove(struct move *mm, int mvnum, int swapped)
 {
        int     pos;            /* position on board */
        int     rval;           /* value of roll */
 
        /* if recursed through all dice values, compare move */
-       if (mvnum == mvlim) {
-               binsert(bsave());
+       if (mvnum == mm->mvlim) {
+               binsert(mm, bsave(mm));
                return;
        }
        /* make sure dice in always same order */
-       if (d0 == swapped)
-               swap;
+       if (mm->d0 == swapped)
+               mswap(mm);
        /* choose value for this move */
-       rval = dice[mvnum != 0];
+       rval = mm->dice[mvnum != 0];
 
        /* find all legitimate moves */
        for (pos = bar; pos != home; pos += cturn) {
                /* fix order of dice */
-               if (d0 == swapped)
-                       swap;
+               if (mm->d0 == swapped)
+                       mswap(mm);
                /* break if stuck on bar */
                if (board[bar] != 0 && pos != bar)
                        break;
@@ -216,29 +219,29 @@
                if (board[pos] * cturn <= 0)
                        continue;
                /* set up arrays for move */
-               p[mvnum] = pos;
-               g[mvnum] = pos + rval * cturn;
-               if (g[mvnum] * cturn >= home) {
+               mm->p[mvnum] = pos;
+               mm->g[mvnum] = pos + rval * cturn;
+               if (mm->g[mvnum] * cturn >= home) {
                        if (*offptr < 0)
                                break;
-                       g[mvnum] = home;
+                       mm->g[mvnum] = home;
                }
                /* try to move */
                if (makmove(mvnum))
                        continue;
                else
-                       trymove(mvnum + 1, 2);
+                       trymove(mm, mvnum + 1, 2);
                /* undo move to try another */
                backone(mvnum);
        }
 
        /* swap dice and try again */
-       if ((!swapped) && D0 != D1)
-               trymove(0, 1);
+       if ((!swapped) && mm->D0 != mm->D1)
+               trymove(mm, 0, 1);
 }
 
 static struct BOARD *
-bsave(void)
+bsave(struct move *mm)
 {
        int     i;              /* index */
        struct BOARD *now;      /* current position */
@@ -252,16 +255,16 @@
        now->b_in[1] = in[1];
        now->b_off[0] = off[0];
        now->b_off[1] = off[1];
-       for (i = 0; i < mvlim; i++) {
-               now->b_st[i] = p[i];
-               now->b_fn[i] = g[i];
+       for (i = 0; i < mm->mvlim; i++) {
+               now->b_st[i] = mm->p[i];
+               now->b_fn[i] = mm->g[i];
        }
        return (now);
 }
 
 /* new == item to insert */
 static void
-binsert(struct BOARD *new)
+binsert(struct move *mm, struct BOARD *new)
 {
        struct BOARD *qp = checkq;      /* queue pointer */
        int     result;         /* comparison result */
@@ -278,7 +281,7 @@
                return;
        }
        if (result == 0) {      /* duplicate entry */
-               mvcheck(qp, new);
+               mvcheck(mm, qp, new);
                makefree(new);
                return;
        }
@@ -290,7 +293,7 @@



Home | Main Index | Thread Index | Old Index