Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/gomoku gomoku: prepare lint's strict bool mode
details: https://anonhg.NetBSD.org/src/rev/be3eb412c94d
branches: trunk
changeset: 366162:be3eb412c94d
user: rillig <rillig%NetBSD.org@localhost>
date: Mon May 16 20:57:01 2022 +0000
description:
gomoku: prepare lint's strict bool mode
No binary change.
diffstat:
games/gomoku/Makefile | 3 +-
games/gomoku/bdinit.c | 12 ++--
games/gomoku/bdisp.c | 16 +++---
games/gomoku/gomoku.h | 3 +-
games/gomoku/main.c | 38 +++++++++--------
games/gomoku/makemove.c | 22 ++++----
games/gomoku/pickmove.c | 106 ++++++++++++++++++++++++-----------------------
7 files changed, 103 insertions(+), 97 deletions(-)
diffs (truncated from 820 to 300 lines):
diff -r 2b3ccd2fb7a7 -r be3eb412c94d games/gomoku/Makefile
--- a/games/gomoku/Makefile Mon May 16 20:09:13 2022 +0000
+++ b/games/gomoku/Makefile Mon May 16 20:57:01 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.6 2022/05/16 19:55:58 rillig Exp $
+# $NetBSD: Makefile,v 1.7 2022/05/16 20:57:01 rillig Exp $
# @(#)Makefile 8.1 (Berkeley) 7/24/94
PROG= gomoku
@@ -9,5 +9,6 @@
HIDEGAME=hidegame
LINTFLAGS+= -w # treat warnings as errors
+#LINTFLAGS+= -T # strict bool mode
.include <bsd.prog.mk>
diff -r 2b3ccd2fb7a7 -r be3eb412c94d games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c Mon May 16 20:09:13 2022 +0000
+++ b/games/gomoku/bdinit.c Mon May 16 20:57:01 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bdinit.c,v 1.12 2022/05/16 19:55:58 rillig Exp $ */
+/* $NetBSD: bdinit.c,v 1.13 2022/05/16 20:57:01 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "from: @(#)bdinit.c 8.2 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: bdinit.c,v 1.12 2022/05/16 19:55:58 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.13 2022/05/16 20:57:01 rillig Exp $");
#endif
#endif /* not lint */
@@ -108,7 +108,7 @@
sp->s_fval[BLACK][0].s = 0x500;
sp->s_fval[WHITE][0].s = 0x500;
/* if direction 1 is not blocked */
- if (!(sp->s_flags & (BFLAG << 1))) {
+ if ((sp->s_flags & (BFLAG << 1)) == 0) {
sp->s_fval[BLACK][1].s = 0x500;
sp->s_fval[WHITE][1].s = 0x500;
}
@@ -121,7 +121,7 @@
sp->s_fval[BLACK][3].s = MAXCOMBO;
sp->s_fval[WHITE][3].s = MAXCOMBO;
} else if (i == 5 &&
- !(sp->s_flags & (BFLAG << 3))) {
+ (sp->s_flags & (BFLAG << 3)) == 0) {
sp->s_fval[BLACK][3].s = 0x500;
sp->s_fval[WHITE][3].s = 0x500;
}
@@ -130,7 +130,7 @@
* Allocate a frame structure for non blocked frames.
*/
for (r = 4; --r >= 0; ) {
- if (sp->s_flags & (BFLAG << r))
+ if ((sp->s_flags & (BFLAG << r)) != 0)
continue;
cbp->c_combo.s = sp->s_fval[BLACK][r].s;
cbp->c_vertex = (u_short)(sp - board);
@@ -211,7 +211,7 @@
for (f = 0; f < 6; f++, sp2 -= d2) {
if (sp2->s_occ == BORDER)
break;
- if (sp2->s_flags & bmask)
+ if ((sp2->s_flags & bmask) != 0)
continue;
n = (int)(sp2->s_frame[r] - frames);
ip[n] = vertex;
diff -r 2b3ccd2fb7a7 -r be3eb412c94d games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c Mon May 16 20:09:13 2022 +0000
+++ b/games/gomoku/bdisp.c Mon May 16 20:57:01 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bdisp.c,v 1.23 2022/05/16 19:55:58 rillig Exp $ */
+/* $NetBSD: bdisp.c,v 1.24 2022/05/16 20:57:01 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)bdisp.c 8.2 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: bdisp.c,v 1.23 2022/05/16 19:55:58 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.24 2022/05/16 20:57:01 rillig Exp $");
#endif
#endif /* not lint */
@@ -60,14 +60,14 @@
cursinit(void)
{
- if (!initscr()) {
+ if (initscr() == NULL) {
errx(EXIT_FAILURE, "Couldn't initialize screen");
}
if ((LINES < SCRNH) || (COLS < SCRNW)) {
errx(EXIT_FAILURE, "Screen too small (need %d%xd)",
SCRNW, SCRNH);
}
- keypad(stdscr, TRUE);
+ keypad(stdscr, true);
nonl();
noecho();
cbreak();
@@ -117,7 +117,7 @@
move(20, 2 * i + 1);
addch(letters[i]);
}
- bdwho(0);
+ bdwho(false);
move(0, 47);
addstr("# black white");
lastline = 0;
@@ -170,9 +170,9 @@
move(BSZ + 1 - j, 2 * i + 1);
sp = &board[i + j * (BSZ + 1)];
if (debug > 1 && sp->s_occ == EMPTY) {
- if (sp->s_flags & IFLAGALL)
+ if ((sp->s_flags & IFLAGALL) != 0)
c = '+';
- else if (sp->s_flags & CFLAGALL)
+ else if ((sp->s_flags & CFLAGALL) != 0)
c = '-';
else
c = '.';
@@ -425,7 +425,7 @@
case '\f':
nx = curx;
ny = cury;
- (void)clearok(stdscr, TRUE);
+ (void)clearok(stdscr, true);
(void)refresh();
break;
#if 0 /* notyet */
diff -r 2b3ccd2fb7a7 -r be3eb412c94d games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h Mon May 16 20:09:13 2022 +0000
+++ b/games/gomoku/gomoku.h Mon May 16 20:57:01 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gomoku.h,v 1.25 2022/05/15 22:56:20 rillig Exp $ */
+/* $NetBSD: gomoku.h,v 1.26 2022/05/16 20:57:01 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -36,6 +36,7 @@
#include <sys/types.h>
#include <sys/endian.h>
+#include <stdbool.h>
#include <stdio.h>
/* board dimensions */
diff -r 2b3ccd2fb7a7 -r be3eb412c94d games/gomoku/main.c
--- a/games/gomoku/main.c Mon May 16 20:09:13 2022 +0000
+++ b/games/gomoku/main.c Mon May 16 20:57:01 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.32 2022/05/16 19:55:58 rillig Exp $ */
+/* $NetBSD: main.c,v 1.33 2022/05/16 20:57:01 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: main.c,v 1.32 2022/05/16 19:55:58 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.33 2022/05/16 20:57:01 rillig Exp $");
#endif
#endif /* not lint */
@@ -62,8 +62,8 @@
#define PROGRAM 1 /* get input from program */
#define INPUTF 2 /* get input from a file */
-int interactive = 1; /* true if interactive */
-int debug; /* true if debugging */
+int interactive = true; /* true if interactive */
+int debug; /* > 0 if debugging */
static int test; /* both moves come from 1: input, 2: computer */
static char *prog; /* name of program */
static char user[LOGIN_NAME_MAX]; /* name of player */
@@ -99,7 +99,7 @@
setgid(getgid());
tmp = getlogin();
- if (tmp) {
+ if (tmp != NULL) {
strlcpy(user, tmp, sizeof(user));
} else {
strcpy(user, "you");
@@ -108,7 +108,7 @@
color = curmove = 0;
prog = strrchr(argv[0], '/');
- if (prog)
+ if (prog != NULL)
prog++;
else
prog = argv[0];
@@ -116,7 +116,7 @@
while ((ch = getopt(argc, argv, "bcdD:u")) != -1) {
switch (ch) {
case 'b': /* background */
- interactive = 0;
+ interactive = false;
break;
case 'd': /* debugging */
debug++;
@@ -135,12 +135,12 @@
}
argc -= optind;
argv += optind;
- if (argc) {
+ if (argc != 0) {
if ((inputfp = fopen(*argv, "r")) == NULL)
err(1, "%s", *argv);
}
- if (!debug)
+ if (debug == 0)
srandom((unsigned int)time(0));
if (interactive)
cursinit(); /* initialize curses */
@@ -192,14 +192,14 @@
}
}
- if (inputfp) {
+ if (inputfp != NULL) {
input[BLACK] = INPUTF;
input[WHITE] = INPUTF;
} else {
switch (test) {
case 0: /* user versus program */
input[color] = USER;
- input[!color] = PROGRAM;
+ input[color != BLACK ? BLACK : WHITE] = PROGRAM;
break;
case 1: /* user versus user */
@@ -216,10 +216,10 @@
if (interactive) {
plyr[BLACK] = input[BLACK] == USER ? user : prog;
plyr[WHITE] = input[WHITE] == USER ? user : prog;
- bdwho(1);
+ bdwho(true);
}
- for (color = BLACK; ; color = !color) {
+ for (color = BLACK; ; color = color != BLACK ? BLACK : WHITE) {
top:
switch (input[color]) {
case INPUTF: /* input comes from a file */
@@ -229,7 +229,8 @@
switch (test) {
case 0: /* user versus program */
input[color] = USER;
- input[!color] = PROGRAM;
+ input[color != BLACK ? BLACK : WHITE] =
+ PROGRAM;
break;
case 1: /* user versus user */
@@ -244,7 +245,7 @@
}
plyr[BLACK] = input[BLACK] == USER ? user : prog;
plyr[WHITE] = input[WHITE] == USER ? user : prog;
- bdwho(1);
+ bdwho(true);
goto top;
case USER: /* input comes from standard input */
@@ -291,7 +292,8 @@
break;
}
if (interactive) {
- misclog("%3d%s%-6s", movenum, color ? " " : " ",
+ misclog("%3d%s%-6s", movenum,
+ color != BLACK ? " " : " ",
stoc(curmove));
}
if ((i = makemove(color, curmove)) != MOVEOK)
@@ -512,7 +514,7 @@
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- if (debugfp)
+ if (debugfp != NULL)
fprintf(debugfp, "%s\n", buf);
if (interactive)
dislog(buf);
@@ -530,7 +532,7 @@
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- if (debugfp)
+ if (debugfp != NULL)
fprintf(debugfp, "%s\n", buf);
if (interactive)
dislog(buf);
Home |
Main Index |
Thread Index |
Old Index