Source-Changes-HG archive

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

[src/trunk]: src/games/gomoku gomoku: convert input source constants to an enum



details:   https://anonhg.NetBSD.org/src/rev/36507d5901ac
branches:  trunk
changeset: 366276:36507d5901ac
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat May 21 14:55:26 2022 +0000

description:
gomoku: convert input source constants to an enum

I also tried converting other macros, but s_occ would use more memory
and the return values for makemove are special values, besides the usual
coordinates in the form PT(x, y), so turning the special values into an
enum would be confusing.

No functional change.

diffstat:

 games/gomoku/Makefile |   3 ++-
 games/gomoku/gomoku.h |   5 ++---
 games/gomoku/main.c   |  15 +++++++++------
 3 files changed, 13 insertions(+), 10 deletions(-)

diffs (91 lines):

diff -r 1c18c7d7c820 -r 36507d5901ac games/gomoku/Makefile
--- a/games/gomoku/Makefile     Sat May 21 14:23:10 2022 +0000
+++ b/games/gomoku/Makefile     Sat May 21 14:55:26 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.9 2022/05/16 21:48:45 rillig Exp $
+#      $NetBSD: Makefile,v 1.10 2022/05/21 14:55:26 rillig Exp $
 #      @(#)Makefile    8.1 (Berkeley) 7/24/94
 
 PROG=  gomoku
@@ -11,5 +11,6 @@
 
 LINTFLAGS+=    -w      # treat warnings as errors
 LINTFLAGS+=    -T      # strict bool mode
+LINTFLAGS+=    -e      # strict enum checks
 
 .include <bsd.prog.mk>
diff -r 1c18c7d7c820 -r 36507d5901ac games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h     Sat May 21 14:23:10 2022 +0000
+++ b/games/gomoku/gomoku.h     Sat May 21 14:55:26 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gomoku.h,v 1.33 2022/05/21 12:29:34 rillig Exp $       */
+/*     $NetBSD: gomoku.h,v 1.34 2022/05/21 14:55:26 rillig Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -59,14 +59,13 @@
 #define EMPTY  2
 #define BORDER 3
 
-/* return values for makemove() */
+/* return values for makemove, readinput */
 #define MOVEOK 0
 #define RESIGN 1
 #define ILLEGAL        2
 #define WIN    3
 #define TIE    4
 #define SAVE   5
-
 #define PT(x, y)       ((x) + (BSZ + 1) * (y))
 
 /*
diff -r 1c18c7d7c820 -r 36507d5901ac games/gomoku/main.c
--- a/games/gomoku/main.c       Sat May 21 14:23:10 2022 +0000
+++ b/games/gomoku/main.c       Sat May 21 14:55:26 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.46 2022/05/21 14:23:10 rillig Exp $ */
+/*     $NetBSD: main.c,v 1.47 2022/05/21 14:55:26 rillig Exp $ */
 
 /*
  * Copyright (c) 1994
@@ -36,7 +36,7 @@
 __COPYRIGHT("@(#) Copyright (c) 1994\
  The Regents of the University of California.  All rights reserved.");
 /*     @(#)main.c      8.4 (Berkeley) 5/4/95   */
-__RCSID("$NetBSD: main.c,v 1.46 2022/05/21 14:23:10 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.47 2022/05/21 14:55:26 rillig Exp $");
 
 #include <sys/stat.h>
 #include <curses.h>
@@ -51,9 +51,11 @@
 
 #include "gomoku.h"
 
-#define USER   0               /* get input from standard input */
-#define PROGRAM        1               /* get input from program */
-#define INPUTF 2               /* get input from a file */
+enum input_source {
+       USER,                   /* get input from standard input */
+       PROGRAM,                /* get input from program */
+       INPUTF                  /* get input from a file */
+};
 
 bool   interactive = true;     /* true if interactive */
 int    debug;                  /* > 0 if debugging */
@@ -102,7 +104,7 @@
        char fname[PATH_MAX];
        char *user_name;
        int color, curmove, i, ch;
-       int input[2];
+       enum input_source input[2];
 
        /* Revoke setgid privileges */
        setgid(getgid());
@@ -235,6 +237,7 @@
                        curmove = readinput(inputfp);
                        if (curmove != ILLEGAL)
                                break;
+                       /* Switch to another input source. */
                        switch (test) {
                        case 0: /* user versus program */
                                input[color] = USER;



Home | Main Index | Thread Index | Old Index