Module Name: src Committed By: rillig Date: Sun May 15 22:00:12 UTC 2022
Modified Files: src/games/gomoku: bdinit.c bdisp.c gomoku.h main.c makemove.c pickmove.c stoc.c Log Message: gomoku: apply some style fixes towards KNF There are still parts of the code that use an indentation level of 4 instead of the usual 8. Fixing that right now would introduce more unnatural line breaks, so defer that until later. No binary change. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/games/gomoku/bdinit.c cvs rdiff -u -r1.19 -r1.20 src/games/gomoku/bdisp.c cvs rdiff -u -r1.21 -r1.22 src/games/gomoku/gomoku.h cvs rdiff -u -r1.28 -r1.29 src/games/gomoku/main.c cvs rdiff -u -r1.11 -r1.12 src/games/gomoku/makemove.c cvs rdiff -u -r1.23 -r1.24 src/games/gomoku/pickmove.c cvs rdiff -u -r1.13 -r1.14 src/games/gomoku/stoc.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/bdinit.c diff -u src/games/gomoku/bdinit.c:1.9 src/games/gomoku/bdinit.c:1.10 --- src/games/gomoku/bdinit.c:1.9 Sat Oct 13 20:57:35 2012 +++ src/games/gomoku/bdinit.c Sun May 15 22:00:11 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bdinit.c,v 1.9 2012/10/13 20:57:35 dholland Exp $ */ +/* $NetBSD: bdinit.c,v 1.10 2022/05/15 22:00:11 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.9 2012/10/13 20:57:35 dholland Exp $"); +__RCSID("$NetBSD: bdinit.c,v 1.10 2022/05/15 22:00:11 rillig Exp $"); #endif #endif /* not lint */ @@ -58,7 +58,7 @@ bdinit(struct spotstr *bp) /* mark the borders as such */ sp = bp; for (i = BSZ2; --i >= 0; sp++) { - sp->s_occ = BORDER; /* top border */ + sp->s_occ = BORDER; /* top border */ sp->s_flags = BFLAGALL; } @@ -73,7 +73,7 @@ bdinit(struct spotstr *bp) if (j < 5) { /* directions 1, 2, 3 are blocked */ sp->s_flags |= (BFLAG << 1) | (BFLAG << 2) | - (BFLAG << 3); + (BFLAG << 3); sp->s_fval[BLACK][1].s = MAXCOMBO; sp->s_fval[BLACK][2].s = MAXCOMBO; sp->s_fval[BLACK][3].s = MAXCOMBO; Index: src/games/gomoku/bdisp.c diff -u src/games/gomoku/bdisp.c:1.19 src/games/gomoku/bdisp.c:1.20 --- src/games/gomoku/bdisp.c:1.19 Sat May 14 16:21:04 2022 +++ src/games/gomoku/bdisp.c Sun May 15 22:00:11 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bdisp.c,v 1.19 2022/05/14 16:21:04 rillig Exp $ */ +/* $NetBSD: bdisp.c,v 1.20 2022/05/15 22:00:11 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.19 2022/05/14 16:21:04 rillig Exp $"); +__RCSID("$NetBSD: bdisp.c,v 1.20 2022/05/15 22:00:11 rillig Exp $"); #endif #endif /* not lint */ @@ -133,11 +133,11 @@ bdwho(int update) int i, j; move(21, 0); - printw(" "); + printw(" "); i = strlen(plyr[BLACK]); j = strlen(plyr[WHITE]); if (i + j <= 20) { - move(21, 10 - (i+j)/2); + move(21, 10 - (i + j) / 2); printw("BLACK/%s (*) vs. WHITE/%s (O)", plyr[BLACK], plyr[WHITE]); } else { @@ -317,7 +317,7 @@ get_line(char *buf, int size) } } *cp = '\0'; - return(c != EOF); + return (c != EOF); } /* @@ -336,8 +336,8 @@ get_coord(void) nx = curx; ny = cury; for (;;) { - mvprintw(BSZ3, (BSZ -6)/2, "(%c %d) ", - 'A'+ ((curx > 7) ? (curx+1) : curx), cury + 1); + mvprintw(BSZ3, (BSZ - 6) / 2, "(%c %d) ", + 'A' + ((curx > 7) ? (curx + 1) : curx), cury + 1); BGOTO(cury, curx); ch = getch(); @@ -407,7 +407,7 @@ get_coord(void) ny = cury; break; case 'Y': - nx = BSZ + curx - 5; + nx = BSZ + curx - 5; ny = cury + 5; break; case 'B': @@ -453,11 +453,11 @@ get_coord(void) return SAVE; case ' ': case '\r': - (void) mvaddstr(BSZ3, (BSZ -6)/2, " "); - return PT(curx+1,cury+1); - } + (void)mvaddstr(BSZ3, (BSZ - 6) / 2, " "); + return PT(curx + 1, cury + 1); + } - curx = nx % BSZ; - cury = ny % BSZ; - } + curx = nx % BSZ; + cury = ny % BSZ; + } } Index: src/games/gomoku/gomoku.h diff -u src/games/gomoku/gomoku.h:1.21 src/games/gomoku/gomoku.h:1.22 --- src/games/gomoku/gomoku.h:1.21 Sat May 14 16:21:04 2022 +++ src/games/gomoku/gomoku.h Sun May 15 22:00:11 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: gomoku.h,v 1.21 2022/05/14 16:21:04 rillig Exp $ */ +/* $NetBSD: gomoku.h,v 1.22 2022/05/15 22:00:11 rillig Exp $ */ /* * Copyright (c) 1994 @@ -40,16 +40,16 @@ /* board dimensions */ #define BSZ 19 -#define BSZ1 (BSZ+1) -#define BSZ2 (BSZ+2) -#define BSZ3 (BSZ+3) -#define BSZ4 (BSZ+4) -#define BAREA (BSZ2*BSZ1+1) +#define BSZ1 (BSZ + 1) +#define BSZ2 (BSZ + 2) +#define BSZ3 (BSZ + 3) +#define BSZ4 (BSZ + 4) +#define BAREA (BSZ2 * BSZ1 + 1) -#define TRANSCRIPT_COL 46 /* necessarily == 2*BSZ4 */ +#define TRANSCRIPT_COL (2 * BSZ4) /* interactive curses stuff */ -#define BGOTO(y,x) move(BSZ - (y), 2 * (x) + 3) +#define BGOTO(y, x) move(BSZ - (y), 2 * (x) + 3) /* frame dimensions (based on 5 in a row) */ #define FSZ1 BSZ @@ -95,7 +95,7 @@ #define S 18 #define T 19 -#define PT(x,y) ((x) + BSZ1 * (y)) +#define PT(x, y) ((x) + BSZ1 * (y)) /* * A 'frame' is a group of five or six contiguous board locations. @@ -147,7 +147,7 @@ #define MAXB 2 #define MAXCOMBO 0x600 -union comboval { +union comboval { struct { #if BYTE_ORDER == BIG_ENDIAN u_char a; /* # moves to complete force */ Index: src/games/gomoku/main.c diff -u src/games/gomoku/main.c:1.28 src/games/gomoku/main.c:1.29 --- src/games/gomoku/main.c:1.28 Sun May 2 12:50:44 2021 +++ src/games/gomoku/main.c Sun May 15 22:00:11 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.28 2021/05/02 12:50:44 rillig Exp $ */ +/* $NetBSD: main.c,v 1.29 2022/05/15 22:00:11 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.28 2021/05/02 12:50:44 rillig Exp $"); +__RCSID("$NetBSD: main.c,v 1.29 2022/05/15 22:00:11 rillig Exp $"); #endif #endif /* not lint */ @@ -79,7 +79,7 @@ u_char overlap[FAREA * FAREA]; /* true short intersect[FAREA * FAREA]; /* frame [a][b] intersection */ int movelog[BSZ * BSZ]; /* log of all the moves */ int movenum; /* current move number */ -const char *plyr[2]; /* who's who */ +const char *plyr[2]; /* who's who */ static int readinput(FILE *); static void misclog(const char *, ...) __printflike(1, 2); @@ -263,7 +263,7 @@ again: } for (i = 0; i < movenum - 1; i++) fprintf(fp, "%s\n", - stoc(movelog[i])); + stoc(movelog[i])); fclose(fp); goto getinput; } @@ -336,7 +336,7 @@ again: } for (i = 0; i < movenum - 1; i++) fprintf(fp, "%s\n", - stoc(movelog[i])); + stoc(movelog[i])); fclose(fp); goto replay; } @@ -344,7 +344,7 @@ again: } quit(); /* NOTREACHED */ - return(0); + return (0); } static int Index: src/games/gomoku/makemove.c diff -u src/games/gomoku/makemove.c:1.11 src/games/gomoku/makemove.c:1.12 --- src/games/gomoku/makemove.c:1.11 Wed Aug 12 06:19:17 2009 +++ src/games/gomoku/makemove.c Sun May 15 22:00:11 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: makemove.c,v 1.11 2009/08/12 06:19:17 dholland Exp $ */ +/* $NetBSD: makemove.c,v 1.12 2022/05/15 22:00:11 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.11 2009/08/12 06:19:17 dholland Exp $"); +__RCSID("$NetBSD: makemove.c,v 1.12 2022/05/15 22:00:11 rillig Exp $"); #endif #endif /* not lint */ @@ -73,18 +73,18 @@ makemove(int us, int mv) /* check for end of game */ if (mv == RESIGN) - return(RESIGN); + return (RESIGN); /* check for illegal move */ sp = &board[mv]; if (sp->s_occ != EMPTY) - return(ILLEGAL); + return (ILLEGAL); /* make move */ sp->s_occ = us; movelog[movenum - 1] = mv; if (++movenum == BSZ * BSZ) - return(TIE); + return (TIE); /* compute new frame values */ sp->s_wval = 0; @@ -211,7 +211,7 @@ makemove(int us, int mv) update_overlap(osp); - return(MOVEOK); + return (MOVEOK); } /* Index: src/games/gomoku/pickmove.c diff -u src/games/gomoku/pickmove.c:1.23 src/games/gomoku/pickmove.c:1.24 --- src/games/gomoku/pickmove.c:1.23 Sat May 14 16:21:04 2022 +++ src/games/gomoku/pickmove.c Sun May 15 22:00:11 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: pickmove.c,v 1.23 2022/05/14 16:21:04 rillig Exp $ */ +/* $NetBSD: pickmove.c,v 1.24 2022/05/15 22:00:11 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.23 2022/05/14 16:21:04 rillig Exp $"); +__RCSID("$NetBSD: pickmove.c,v 1.24 2022/05/15 22:00:11 rillig Exp $"); #endif #endif /* not lint */ @@ -88,10 +88,10 @@ pickmove(int us) /* first move is easy */ if (movenum == 1) - return (PT(K,10)); + return (PT(K, 10)); /* initialize all the board values */ - for (pos = PT(T,20); pos-- > PT(A,1); ) { + for (pos = PT(T, 20); pos-- > PT(A, 1); ) { sp = &board[pos]; sp->s_combo[BLACK].s = MAXCOMBO + 1; sp->s_combo[WHITE].s = MAXCOMBO + 1; @@ -110,20 +110,21 @@ pickmove(int us) scanframes(WHITE); /* find the spot with the highest value */ - pos = PT(T,19); + pos = PT(T, 19); sp1 = sp2 = &board[pos]; - for ( ; pos-- > PT(A,1); ) { + for ( ; pos-- > PT(A, 1); ) { sp = &board[pos]; if (sp->s_occ != EMPTY) continue; if (debug && (sp->s_combo[BLACK].c.a == 1 || sp->s_combo[WHITE].c.a == 1)) { - debuglog("- %s %x/%d %d %x/%d %d %d", stoc(sp - board), - sp->s_combo[BLACK].s, sp->s_level[BLACK], - sp->s_nforce[BLACK], - sp->s_combo[WHITE].s, sp->s_level[WHITE], - sp->s_nforce[WHITE], - sp->s_wval); + debuglog("- %s %x/%d %d %x/%d %d %d", + stoc(sp - board), + sp->s_combo[BLACK].s, sp->s_level[BLACK], + sp->s_nforce[BLACK], + sp->s_combo[WHITE].s, sp->s_level[WHITE], + sp->s_nforce[WHITE], + sp->s_wval); } /* pick the best black move */ if (better(sp, sp1, BLACK)) @@ -135,17 +136,17 @@ pickmove(int us) if (debug) { debuglog("B %s %x/%d %d %x/%d %d %d", - stoc(sp1 - board), - sp1->s_combo[BLACK].s, sp1->s_level[BLACK], - sp1->s_nforce[BLACK], - sp1->s_combo[WHITE].s, sp1->s_level[WHITE], - sp1->s_nforce[WHITE], sp1->s_wval); + stoc(sp1 - board), + sp1->s_combo[BLACK].s, sp1->s_level[BLACK], + sp1->s_nforce[BLACK], + sp1->s_combo[WHITE].s, sp1->s_level[WHITE], + sp1->s_nforce[WHITE], sp1->s_wval); debuglog("W %s %x/%d %d %x/%d %d %d", - stoc(sp2 - board), - sp2->s_combo[WHITE].s, sp2->s_level[WHITE], - sp2->s_nforce[WHITE], - sp2->s_combo[BLACK].s, sp2->s_level[BLACK], - sp2->s_nforce[BLACK], sp2->s_wval); + stoc(sp2 - board), + sp2->s_combo[WHITE].s, sp2->s_level[WHITE], + sp2->s_nforce[WHITE], + sp2->s_combo[BLACK].s, sp2->s_level[BLACK], + sp2->s_nforce[BLACK], sp2->s_wval); /* * Check for more than one force that can't * all be blocked with one move. @@ -342,7 +343,7 @@ scanframes(int color) while (d <= ((movenum + 1) >> 1) && combolen > n) { if (debug) { debuglog("%cL%d %d %d %d", "BW"[color], - d, combolen - n, combocnt, elistcnt); + d, combolen - n, combocnt, elistcnt); refresh(); } n = combolen; @@ -351,7 +352,7 @@ scanframes(int color) } /* scan for combos at empty spots */ - for (pos = PT(T,20); pos-- > PT(A,1); ) { + for (pos = PT(T, 20); pos-- > PT(A, 1); ) { sp = &board[pos]; for (ep = sp->s_empty; ep; ep = nep) { cbp = ep->e_combo; @@ -561,7 +562,7 @@ addframes(int level) /* scan for combos at empty spots */ i = curcolor; - for (pos = PT(T,20); pos-- > PT(A,1); ) { + for (pos = PT(T, 20); pos-- > PT(A, 1); ) { sp = &board[pos]; for (ep = sp->s_empty; ep; ep = nep) { cbp = ep->e_combo; @@ -923,7 +924,7 @@ makeempty(struct combostr *ocbp) /* add the combo to the list of empty spots */ nep = (struct elist *)malloc(sizeof(struct elist)); if (nep == NULL) - panic("Out of memory!"); + panic("Out of memory!"); nep->e_combo = ocbp; nep->e_off = s; nep->e_frameindex = i; @@ -937,12 +938,12 @@ makeempty(struct combostr *ocbp) nep->e_fval.s = ep->e_fval.s; if (debug > 2) { debuglog("e %s o%d i%d c%d m%x %x", - stoc(sp - board), - nep->e_off, - nep->e_frameindex, - nep->e_framecnt, - nep->e_emask, - nep->e_fval.s); + stoc(sp - board), + nep->e_off, + nep->e_frameindex, + nep->e_framecnt, + nep->e_emask, + nep->e_fval.s); } /* sort by the number of frames in the combo */ @@ -1247,9 +1248,9 @@ sortcombo(struct combostr **scbpp, struc cpp--; if (fcbp > *cpp) { *--spp = fcbp; - do + do { *--spp = *cpp; - while (cpp-- != cbpp); + } while (cpp-- != cbpp); goto inserted; } *--spp = *cpp; @@ -1265,7 +1266,7 @@ inserted: * Add it to the hash list. */ fcbp = (struct combostr *) - ((char *)scbpp - sizeof(struct combostr)); + ((char *)scbpp - sizeof(struct combostr)); hashcombos[inx] = fcbp; fcbp->c_next = fcbp->c_prev = fcbp; return (0); @@ -1335,16 +1336,16 @@ printcombo(struct combostr *cbp, char *b size_t pos = 0; snprintf(buf + pos, max - pos, "%x/%d", - cbp->c_combo.s, cbp->c_nframes); + cbp->c_combo.s, cbp->c_nframes); pos += strlen(buf + pos); for (; (tcbp = cbp->c_link[1]) != NULL; cbp = cbp->c_link[0]) { snprintf(buf + pos, max - pos, " %s%c%x", - stoc(tcbp->c_vertex), pdir[tcbp->c_dir], cbp->c_flags); + stoc(tcbp->c_vertex), pdir[tcbp->c_dir], cbp->c_flags); pos += strlen(buf + pos); } snprintf(buf + pos, max - pos, " %s%c", - stoc(cbp->c_vertex), pdir[cbp->c_dir]); + stoc(cbp->c_vertex), pdir[cbp->c_dir]); } #ifdef DEBUG Index: src/games/gomoku/stoc.c diff -u src/games/gomoku/stoc.c:1.13 src/games/gomoku/stoc.c:1.14 --- src/games/gomoku/stoc.c:1.13 Sun May 2 12:50:44 2021 +++ src/games/gomoku/stoc.c Sun May 15 22:00:11 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: stoc.c,v 1.13 2021/05/02 12:50:44 rillig Exp $ */ +/* $NetBSD: stoc.c,v 1.14 2022/05/15 22:00:11 rillig Exp $ */ /* * Copyright (c) 1994 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)stoc.c 8.1 (Berkeley) 7/24/94"; #else -__RCSID("$NetBSD: stoc.c,v 1.13 2021/05/02 12:50:44 rillig Exp $"); +__RCSID("$NetBSD: stoc.c,v 1.14 2022/05/15 22:00:11 rillig Exp $"); #endif #endif /* not lint */ @@ -73,9 +73,9 @@ stoc(int s) for (i = 0; mv[i].m_code >= 0; i++) if (s == mv[i].m_code) - return(mv[i].m_text); + return (mv[i].m_text); snprintf(buf, sizeof(buf), "%c%d", letters[s % BSZ1], s / BSZ1); - return(buf); + return (buf); } /* @@ -88,13 +88,13 @@ ctos(const char *mp) for (i = 0; mv[i].m_code >= 0; i++) if (strcmp(mp, mv[i].m_text) == 0) - return(mv[i].m_code); + return (mv[i].m_code); if (!isalpha((unsigned char)mp[0])) - return(ILLEGAL); + return (ILLEGAL); i = atoi(&mp[1]); if (i < 1 || i > 19) - return(ILLEGAL); - return(PT(lton((unsigned char)mp[0]), i)); + return (ILLEGAL); + return (PT(lton((unsigned char)mp[0]), i)); } /* @@ -109,5 +109,5 @@ lton(int c) c = toupper(c); for (i = 1; i <= BSZ && letters[i] != c; i++) ; - return(i); + return (i); }