Module Name: src
Committed By: rillig
Date: Mon May 16 20:57:01 UTC 2022
Modified Files:
src/games/gomoku: Makefile bdinit.c bdisp.c gomoku.h main.c makemove.c
pickmove.c
Log Message:
gomoku: prepare lint's strict bool mode
No binary change.
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/games/gomoku/Makefile
cvs rdiff -u -r1.12 -r1.13 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.23 -r1.24 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.25 -r1.26 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.32 -r1.33 src/games/gomoku/main.c
cvs rdiff -u -r1.14 -r1.15 src/games/gomoku/makemove.c
cvs rdiff -u -r1.29 -r1.30 src/games/gomoku/pickmove.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/gomoku/Makefile
diff -u src/games/gomoku/Makefile:1.6 src/games/gomoku/Makefile:1.7
--- src/games/gomoku/Makefile:1.6 Mon May 16 19:55:58 2022
+++ src/games/gomoku/Makefile Mon May 16 20:57:01 2022
@@ -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 @@ LDADD= -lcurses -lterminfo
HIDEGAME=hidegame
LINTFLAGS+= -w # treat warnings as errors
+#LINTFLAGS+= -T # strict bool mode
.include <bsd.prog.mk>
Index: src/games/gomoku/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.12 src/games/gomoku/bdinit.c:1.13
--- src/games/gomoku/bdinit.c:1.12 Mon May 16 19:55:58 2022
+++ src/games/gomoku/bdinit.c Mon May 16 20:57:01 2022
@@ -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 @@ bdinit(struct spotstr *bp)
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 @@ bdinit(struct spotstr *bp)
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 @@ bdinit(struct spotstr *bp)
* 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 @@ init_overlap(void)
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;
Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.23 src/games/gomoku/bdisp.c:1.24
--- src/games/gomoku/bdisp.c:1.23 Mon May 16 19:55:58 2022
+++ src/games/gomoku/bdisp.c Mon May 16 20:57:01 2022
@@ -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 @@ void
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 @@ bdisp_init(void)
move(20, 2 * i + 1);
addch(letters[i]);
}
- bdwho(0);
+ bdwho(false);
move(0, 47);
addstr("# black white");
lastline = 0;
@@ -170,9 +170,9 @@ bdisp(void)
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 @@ get_coord(void)
case '\f':
nx = curx;
ny = cury;
- (void)clearok(stdscr, TRUE);
+ (void)clearok(stdscr, true);
(void)refresh();
break;
#if 0 /* notyet */
Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.25 src/games/gomoku/gomoku.h:1.26
--- src/games/gomoku/gomoku.h:1.25 Sun May 15 22:56:20 2022
+++ src/games/gomoku/gomoku.h Mon May 16 20:57:01 2022
@@ -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 */
Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.32 src/games/gomoku/main.c:1.33
--- src/games/gomoku/main.c:1.32 Mon May 16 19:55:58 2022
+++ src/games/gomoku/main.c Mon May 16 20:57:01 2022
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1994\
#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 @@ __RCSID("$NetBSD: main.c,v 1.32 2022/05/
#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 @@ main(int argc, char **argv)
setgid(getgid());
tmp = getlogin();
- if (tmp) {
+ if (tmp != NULL) {
strlcpy(user, tmp, sizeof(user));
} else {
strcpy(user, "you");
@@ -108,7 +108,7 @@ main(int argc, char **argv)
color = curmove = 0;
prog = strrchr(argv[0], '/');
- if (prog)
+ if (prog != NULL)
prog++;
else
prog = argv[0];
@@ -116,7 +116,7 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
}
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 @@ again:
}
}
- 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 @@ again:
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 @@ again:
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 @@ again:
}
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 @@ again:
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 @@ debuglog(const char *fmt, ...)
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 @@ misclog(const char *fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- if (debugfp)
+ if (debugfp != NULL)
fprintf(debugfp, "%s\n", buf);
if (interactive)
dislog(buf);
Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.14 src/games/gomoku/makemove.c:1.15
--- src/games/gomoku/makemove.c:1.14 Mon May 16 19:55:58 2022
+++ src/games/gomoku/makemove.c Mon May 16 20:57:01 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: makemove.c,v 1.14 2022/05/16 19:55:58 rillig Exp $ */
+/* $NetBSD: makemove.c,v 1.15 2022/05/16 20:57:01 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)makemove.c 8.2 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: makemove.c,v 1.14 2022/05/16 19:55:58 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.15 2022/05/16 20:57:01 rillig Exp $");
#endif
#endif /* not lint */
@@ -96,12 +96,12 @@ makemove(int us, int mv)
for (f = 5; --f >= 0; fsp -= d) { /* for each frame */
if (fsp->s_occ == BORDER)
goto nextr;
- if (fsp->s_flags & bmask)
+ if ((fsp->s_flags & bmask) != 0)
continue;
/* remove this frame from the sorted list of frames */
cbp = fsp->s_frame[r];
- if (cbp->c_next) {
+ if (cbp->c_next != NULL) {
if (sortframes[BLACK] == cbp)
sortframes[BLACK] = cbp->c_next;
if (sortframes[WHITE] == cbp)
@@ -148,7 +148,7 @@ makemove(int us, int mv)
return(WIN);
/* compute new value & combo number for this frame & color */
- fsp->s_fval[!us][r].s = MAXCOMBO;
+ fsp->s_fval[us != BLACK ? BLACK : WHITE][r].s = MAXCOMBO;
cp = &fsp->s_fval[us][r];
/* both ends open? */
if (space && sp->s_occ == EMPTY) {
@@ -166,7 +166,7 @@ makemove(int us, int mv)
/* add this frame to the sorted list of frames by combo value */
cbp1 = sortframes[us];
- if (!cbp1)
+ if (cbp1 == NULL)
sortframes[us] = cbp->c_next = cbp->c_prev = cbp;
else {
cp1 = &board[cbp1->c_vertex].s_fval[us][cbp1->c_dir];
@@ -194,12 +194,12 @@ makemove(int us, int mv)
/* both ends open? */
if (fsp->s_occ == EMPTY) {
cp = &fsp->s_fval[BLACK][r];
- if (cp->c.b) {
+ if (cp->c.b != 0) {
cp->c.a += 1;
cp->c.b = 0;
}
cp = &fsp->s_fval[WHITE][r];
- if (cp->c.b) {
+ if (cp->c.b != 0) {
cp->c.a += 1;
cp->c.b = 0;
}
@@ -234,7 +234,7 @@ update_overlap(struct spotstr *osp)
for (f = 0; f < 6; f++, sp1 -= d) { /* for each frame */
if (sp1->s_occ == BORDER)
break;
- if (sp1->s_flags & bmask)
+ if ((sp1->s_flags & bmask) != 0)
continue;
/*
* Update all other frames that intersect the current one
@@ -248,7 +248,7 @@ update_overlap(struct spotstr *osp)
for (i = f + 1; i < 6; i++, sp2 -= d) {
if (sp2->s_occ == BORDER)
break;
- if (sp2->s_flags & bmask)
+ if ((sp2->s_flags & bmask) != 0)
continue;
/*
* count the number of empty spots to see if there is
@@ -295,7 +295,7 @@ update_overlap(struct spotstr *osp)
for (i = 6; --i >= 0; sp -= d1) { /* for each spot */
if (sp->s_occ == BORDER)
break;
- if (sp->s_flags & bmask1)
+ if ((sp->s_flags & bmask1) != 0)
continue;
b = (int)(sp->s_frame[r1] - frames);
str[b] = 0;
Index: src/games/gomoku/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.29 src/games/gomoku/pickmove.c:1.30
--- src/games/gomoku/pickmove.c:1.29 Mon May 16 19:55:58 2022
+++ src/games/gomoku/pickmove.c Mon May 16 20:57:01 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pickmove.c,v 1.29 2022/05/16 19:55:58 rillig Exp $ */
+/* $NetBSD: pickmove.c,v 1.30 2022/05/16 20:57:01 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: pickmove.c,v 1.29 2022/05/16 19:55:58 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.30 2022/05/16 20:57:01 rillig Exp $");
#endif
#endif /* not lint */
@@ -53,7 +53,7 @@ __RCSID("$NetBSD: pickmove.c,v 1.29 2022
#define BIT_SET(a, b) ((a)[(b)/BITS_PER_INT] |= (1 << ((b) % BITS_PER_INT)))
#define BIT_CLR(a, b) ((a)[(b)/BITS_PER_INT] &= ~(1 << ((b) % BITS_PER_INT)))
-#define BIT_TEST(a, b) ((a)[(b)/BITS_PER_INT] & (1 << ((b) % BITS_PER_INT)))
+#define BIT_TEST(a, b) (((a)[(b)/BITS_PER_INT] & (1 << ((b) % BITS_PER_INT))))
/*
* This structure is used to store overlap information between frames.
@@ -84,7 +84,7 @@ static void updatecombo(struct combostr
static void makeempty(struct combostr *);
static int checkframes(struct combostr *, struct combostr *, struct spotstr *,
int, struct overlap_info *);
-static int sortcombo(struct combostr **, struct combostr **, struct combostr *);
+static bool sortcombo(struct combostr **, struct combostr **, struct combostr *);
static void printcombo(struct combostr *, char *, size_t);
int
@@ -125,7 +125,7 @@ pickmove(int us)
sp = &board[pos];
if (sp->s_occ != EMPTY)
continue;
- if (debug && (sp->s_combo[BLACK].c.a == 1 ||
+ if (debug != 0 && (sp->s_combo[BLACK].c.a == 1 ||
sp->s_combo[WHITE].c.a == 1)) {
debuglog("- %s %x/%d %d %x/%d %d %d",
stoc((int)(sp - board)),
@@ -143,7 +143,7 @@ pickmove(int us)
sp2 = sp;
}
- if (debug) {
+ if (debug != 0) {
debuglog("B %s %x/%d %d %x/%d %d %d",
stoc((int)(sp1 - board)),
sp1->s_combo[BLACK].s, sp1->s_level[BLACK],
@@ -162,7 +162,8 @@ pickmove(int us)
*/
sp = (us == BLACK) ? sp2 : sp1;
m = (int)(sp - board);
- if (sp->s_combo[!us].c.a == 1 && !BIT_TEST(forcemap, m))
+ if (sp->s_combo[us != BLACK ? BLACK : WHITE].c.a == 1 &&
+ !BIT_TEST(forcemap, m))
debuglog("*** Can't be blocked");
}
if (us == BLACK) {
@@ -201,7 +202,7 @@ better(const struct spotstr *sp, const s
if (/* .... */ sp->s_nforce[us] != sp1->s_nforce[us])
return sp->s_nforce[us] > sp1->s_nforce[us];
- them = !us;
+ them = us != BLACK ? BLACK : WHITE;
s = (int)(sp - board);
s1 = (int)(sp1 - board);
if ((BIT_TEST(forcemap, s) != 0) != (BIT_TEST(forcemap, s1) != 0))
@@ -217,7 +218,7 @@ better(const struct spotstr *sp, const s
if (/* .... */ sp->s_wval != sp1->s_wval)
return sp->s_wval > sp1->s_wval;
- return random() & 1;
+ return (random() & 1) != 0;
}
static int curcolor; /* implicit parameter to makecombo() */
@@ -271,7 +272,7 @@ scanframes(int color)
sp = &board[cbp->c_vertex];
cp = &sp->s_fval[color][r = cbp->c_dir];
d = dd[r];
- if (cp->c.b) {
+ if (cp->c.b != 0) {
/*
* Since this is the first spot of an open ended
* frame, we treat it as a closed frame.
@@ -336,7 +337,7 @@ scanframes(int color)
d = 2;
/* LINTED 117: bitwise '>>' on signed value possibly nonportable */
while (d <= ((movenum + 1) >> 1) && combolen > n) {
- if (debug) {
+ if (debug != 0) {
debuglog("%cL%d %d %d %d", "BW"[color],
d, combolen - n, combocnt, elistcnt);
refresh();
@@ -349,7 +350,7 @@ scanframes(int color)
/* scan for combos at empty spots */
for (pos = PT(BSZ, BSZ + 1); pos-- > PT(1, 1); ) {
sp = &board[pos];
- for (ep = sp->s_empty; ep; ep = nep) {
+ for (ep = sp->s_empty; ep != NULL; ep = nep) {
cbp = ep->e_combo;
if (cbp->c_combo.s <= sp->s_combo[color].s) {
if (cbp->c_combo.s != sp->s_combo[color].s) {
@@ -363,7 +364,7 @@ scanframes(int color)
elistcnt--;
}
sp->s_empty = (struct elist *)0;
- for (ep = sp->s_nempty; ep; ep = nep) {
+ for (ep = sp->s_nempty; ep != NULL; ep = nep) {
cbp = ep->e_combo;
if (cbp->c_combo.s <= sp->s_combo[color].s) {
if (cbp->c_combo.s != sp->s_combo[color].s) {
@@ -427,7 +428,7 @@ makecombo2(struct combostr *ocbp, struct
ocb.s = s;
baseB = ocb.c.a + ocb.c.b - 1;
fcnt = ocb.c.a - 2;
- emask = fcnt ? ((ocb.c.b ? 0x1E : 0x1F) & ~(1 << off)) : 0;
+ emask = fcnt != 0 ? ((ocb.c.b != 0 ? 0x1E : 0x1F) & ~(1 << off)) : 0;
for (r = 4; --r >= 0; ) { /* for each direction */
/* don't include frames that overlap in the same direction */
if (r == ocbp->c_dir)
@@ -444,7 +445,7 @@ makecombo2(struct combostr *ocbp, struct
for (f = 0; f < 5; f++, fsp -= d) { /* for each frame */
if (fsp->s_occ == BORDER)
break;
- if (fsp->s_flags & bmask)
+ if ((fsp->s_flags & bmask) != 0)
continue;
/* don't include frames of the wrong color */
@@ -457,7 +458,7 @@ makecombo2(struct combostr *ocbp, struct
* If this is the end point of the frame,
* use the closed ended value for the frame.
*/
- if ((f == 0 && fcb.c.b) || fcb.s == 0x101) {
+ if ((f == 0 && fcb.c.b != 0) || fcb.s == 0x101) {
fcb.c.a++;
fcb.c.b = 0;
}
@@ -496,14 +497,14 @@ makecombo2(struct combostr *ocbp, struct
ncbp->c_nframes = 2;
ncbp->c_dir = 0;
ncbp->c_frameindex = 0;
- ncbp->c_flags = (ocb.c.b) ? C_OPEN_0 : 0;
- if (fcb.c.b)
+ ncbp->c_flags = ocb.c.b != 0 ? C_OPEN_0 : 0;
+ if (fcb.c.b != 0)
ncbp->c_flags |= C_OPEN_1;
ncbp->c_framecnt[0] = fcnt;
ncbp->c_emask[0] = emask;
ncbp->c_framecnt[1] = fcb.c.a - 2;
- ncbp->c_emask[1] = ncbp->c_framecnt[1] ?
- ((fcb.c.b ? 0x1E : 0x1F) & ~(1 << f)) : 0;
+ ncbp->c_emask[1] = ncbp->c_framecnt[1] != 0 ?
+ ((fcb.c.b != 0 ? 0x1E : 0x1F) & ~(1 << f)) : 0;
combocnt++;
if ((c == 1 && debug > 1) || debug > 3) {
@@ -559,7 +560,7 @@ addframes(int level)
i = curcolor;
for (pos = PT(BSZ, BSZ + 1); pos-- > PT(1, 1); ) {
sp = &board[pos];
- for (ep = sp->s_empty; ep; ep = nep) {
+ for (ep = sp->s_empty; ep != NULL; ep = nep) {
cbp = ep->e_combo;
if (cbp->c_combo.s <= sp->s_combo[i].s) {
if (cbp->c_combo.s != sp->s_combo[i].s) {
@@ -582,7 +583,7 @@ addframes(int level)
fsp = &board[cbp->c_vertex];
r = cbp->c_dir;
/* skip frames that are part of a <1,x> combo */
- if (fsp->s_flags & (FFLAG << r))
+ if ((fsp->s_flags & (FFLAG << r)) != 0)
continue;
/*
@@ -598,7 +599,7 @@ addframes(int level)
* the combo value with the end closed.
*/
if (fsp->s_occ == EMPTY) {
- if (fcb.c.b) {
+ if (fcb.c.b != 0) {
cb.c.a = fcb.c.a + 1;
cb.c.b = 0;
} else
@@ -670,8 +671,8 @@ makecombo(struct combostr *ocbp, struct
ocb.s = s;
baseB = ocb.c.a + ocb.c.b - 1;
fcnt = ocb.c.a - 2;
- emask = fcnt ? ((ocb.c.b ? 0x1E : 0x1F) & ~(1 << off)) : 0;
- for (ep = osp->s_empty; ep; ep = ep->e_next) {
+ emask = fcnt != 0 ? ((ocb.c.b != 0 ? 0x1E : 0x1F) & ~(1 << off)) : 0;
+ for (ep = osp->s_empty; ep != NULL; ep = ep->e_next) {
/* check for various kinds of overlap */
cbp = ep->e_combo;
verts = checkframes(cbp, ocbp, osp, s, vertices);
@@ -679,7 +680,7 @@ makecombo(struct combostr *ocbp, struct
continue;
/* check to see if this frame forms a valid loop */
- if (verts) {
+ if (verts > 0) {
sp = &board[vertices[0].o_intersect];
#ifdef DEBUG
if (sp->s_occ != EMPTY) {
@@ -694,7 +695,7 @@ makecombo(struct combostr *ocbp, struct
* of the completion spots of the combostr
* we are trying to attach the frame to.
*/
- for (nep = sp->s_empty; nep; nep = nep->e_next) {
+ for (nep = sp->s_empty; nep != NULL; nep = nep->e_next) {
if (nep->e_combo == cbp)
goto fnd;
if (nep->e_combo->c_nframes < cbp->c_nframes)
@@ -736,7 +737,7 @@ makecombo(struct combostr *ocbp, struct
ncbp->c_voff[1] = off;
ncbp->c_vertex = (u_short)(osp - board);
ncbp->c_nframes = cbp->c_nframes + 1;
- ncbp->c_flags = ocb.c.b ? C_OPEN_1 : 0;
+ ncbp->c_flags = ocb.c.b != 0 ? C_OPEN_1 : 0;
ncbp->c_frameindex = ep->e_frameindex;
/*
* Update the completion spot mask of the frame we
@@ -745,11 +746,11 @@ makecombo(struct combostr *ocbp, struct
*/
ncbp->c_framecnt[0] = ep->e_framecnt;
ncbp->c_emask[0] = ep->e_emask;
- if (verts) {
+ if (verts != 0) {
ncbp->c_flags |= C_LOOP;
ncbp->c_dir = vertices[0].o_frameindex;
ncbp->c_framecnt[1] = fcnt - 1;
- if (ncbp->c_framecnt[1]) {
+ if (ncbp->c_framecnt[1] != 0) {
n = (vertices[0].o_intersect - ocbp->c_vertex) /
dd[ocbp->c_dir];
ncbp->c_emask[1] = emask & ~(1 << n);
@@ -859,14 +860,14 @@ makeempty(struct combostr *ocbp)
nep->e_framecnt = cbp->c_framecnt[0];
nep->e_emask = cbp->c_emask[0];
- if (cbp->c_flags & C_LOOP) {
+ if ((cbp->c_flags & C_LOOP) != 0) {
s++;
/*
* Account for the fact that this frame connects
* to a previous one (thus forming a loop).
*/
nep = &einfo[cbp->c_dir];
- if (--nep->e_framecnt)
+ if (--nep->e_framecnt != 0)
nep->e_emask &= ~(1 << cbp->c_voff[0]);
else
nep->e_emask = 0;
@@ -877,13 +878,13 @@ makeempty(struct combostr *ocbp)
* We only need to update the emask values of "complete" loops
* to include the intersection spots.
*/
- if (s && ocbp->c_combo.c.a == 2) {
+ if (s != 0 && ocbp->c_combo.c.a == 2) {
/* process loops from the top down */
ep = &einfo[nframes];
do {
ep--;
cbp = ep->e_combo;
- if (!(cbp->c_flags & C_LOOP))
+ if ((cbp->c_flags & C_LOOP) == 0)
continue;
/*
@@ -913,7 +914,7 @@ makeempty(struct combostr *ocbp)
sp = &board[cbp->c_vertex];
d = dd[cbp->c_dir];
for (s = 0, m = 1; s < 5; s++, sp += d, m <<= 1) {
- if (sp->s_occ != EMPTY || !(emask & m))
+ if (sp->s_occ != EMPTY || (emask & m) == 0)
continue;
/* add the combo to the list of empty spots */
@@ -990,7 +991,7 @@ updatecombo(struct combostr *cbp, int co
/* update the board values for each spot in frame */
sp = &board[s = tcbp->c_vertex];
d = dd[tcbp->c_dir];
- i = (flags & C_OPEN_1) ? 6 : 5;
+ i = (flags & C_OPEN_1) != 0 ? 6 : 5;
for (; --i >= 0; sp += d, s += d) {
if (sp->s_occ != EMPTY)
continue;
@@ -1014,7 +1015,7 @@ updatecombo(struct combostr *cbp, int co
/* update the board values for each spot in frame */
sp = &board[s = cbp->c_vertex];
d = dd[cbp->c_dir];
- i = (flags & C_OPEN_0) ? 6 : 5;
+ i = (flags & C_OPEN_0) != 0 ? 6 : 5;
for (; --i >= 0; sp += d, s += d) {
if (sp->s_occ != EMPTY)
continue;
@@ -1097,7 +1098,7 @@ checkframes(struct combostr *cbp, struct
* i == which overlap bit to test based on whether 'fcbp' is
* an open or closed frame.
*/
- i = cb.c.b ? 2 : 0;
+ i = cb.c.b != 0 ? 2 : 0;
for (; (tcbp = cbp->c_link[1]) != NULL;
lcbp = cbp, cbp = cbp->c_link[0]) {
if (tcbp == fcbp)
@@ -1108,13 +1109,14 @@ checkframes(struct combostr *cbp, struct
mask = str[tcbp - frames];
flags = cbp->c_flags;
n = i + ((flags & C_OPEN_1) != 0);
- if (mask & (1 << n)) {
+ if ((mask & (1 << n)) != 0) {
/*
* The two frames are not independent if they
* both lie in the same line and intersect at
* more than one point.
*/
- if (tcbp->c_dir == fcbp->c_dir && (mask & (0x10 << n)))
+ if (tcbp->c_dir == fcbp->c_dir &&
+ (mask & (0x10 << n)) != 0)
return -1;
/*
* If this is not the spot we are attaching
@@ -1124,7 +1126,7 @@ checkframes(struct combostr *cbp, struct
n = ip[tcbp - frames];
if (osp != &board[n]) {
/* check to see if this is a valid loop */
- if (verts)
+ if (verts != 0)
return -1;
if (fcnt == 0 || cbp->c_framecnt[1] == 0)
return -1;
@@ -1133,11 +1135,11 @@ checkframes(struct combostr *cbp, struct
* one of the end points if it is an open
* ended frame.
*/
- if ((flags & C_OPEN_1) &&
+ if ((flags & C_OPEN_1) != 0 &&
(n == tcbp->c_vertex ||
n == tcbp->c_vertex + 5 * dd[tcbp->c_dir]))
return -1; /* invalid overlap */
- if (cb.c.b &&
+ if (cb.c.b != 0 &&
(n == fcbp->c_vertex ||
n == fcbp->c_vertex + 5 * dd[fcbp->c_dir]))
return -1; /* invalid overlap */
@@ -1156,13 +1158,13 @@ checkframes(struct combostr *cbp, struct
/* check for intersection of 'cbp' with 'fcbp' */
mask = str[cbp - frames];
- if (mask & (1 << n)) {
+ if ((mask & (1 << n)) != 0) {
/*
* The two frames are not independent if they
* both lie in the same line and intersect at
* more than one point.
*/
- if (cbp->c_dir == fcbp->c_dir && (mask & (0x10 << n)))
+ if (cbp->c_dir == fcbp->c_dir && (mask & (0x10 << n)) != 0)
return -1;
/*
* If this is not the spot we are attaching
@@ -1172,7 +1174,7 @@ checkframes(struct combostr *cbp, struct
n = ip[cbp - frames];
if (osp != &board[n]) {
/* check to see if this is a valid loop */
- if (verts)
+ if (verts != 0)
return -1;
if (fcnt == 0 || lcbp->c_framecnt[0] == 0)
return -1;
@@ -1181,11 +1183,11 @@ checkframes(struct combostr *cbp, struct
* one of the end points if it is an open
* ended frame.
*/
- if ((flags & C_OPEN_0) &&
+ if ((flags & C_OPEN_0) != 0 &&
(n == cbp->c_vertex ||
n == cbp->c_vertex + 5 * dd[cbp->c_dir]))
return -1; /* invalid overlap */
- if (cb.c.b &&
+ if (cb.c.b != 0 &&
(n == fcbp->c_vertex ||
n == fcbp->c_vertex + 5 * dd[fcbp->c_dir]))
return -1; /* invalid overlap */
@@ -1206,7 +1208,7 @@ checkframes(struct combostr *cbp, struct
* Return true if this list of frames is already in the hash list.
* Otherwise, add the new combo to the hash list.
*/
-static int
+static bool
sortcombo(struct combostr **scbpp, struct combostr **cbpp,
struct combostr *fcbp)
{
@@ -1259,7 +1261,7 @@ inserted:
fcbp = (void *)((char *)scbpp - sizeof(struct combostr));
hashcombos[inx] = fcbp;
fcbp->c_next = fcbp->c_prev = fcbp;
- return 0;
+ return false;
}
ecbp = cbp;
do {
@@ -1299,7 +1301,7 @@ inserted:
debuglog("%s", buf);
}
#endif /* DEBUG */
- return 1;
+ return true;
next:
;
} while ((cbp = cbp->c_next) != ecbp);
@@ -1313,7 +1315,7 @@ inserted:
fcbp->c_prev = ecbp;
cbp->c_prev = fcbp;
ecbp->c_next = fcbp;
- return 0;
+ return false;
}
/*