X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/83d87cc2642c6958b99e98c44891b486b944c6fe..a59b491d37669e51053c17262118e5fec67ad358:/gomoku/main.c diff --git a/gomoku/main.c b/gomoku/main.c index 32bd04d4..3d5d862b 100644 --- a/gomoku/main.c +++ b/gomoku/main.c @@ -1,5 +1,5 @@ -/* $NetBSD: main.c,v 1.2 1996/12/28 18:57:01 tls Exp $ -*/ +/* $NetBSD: main.c,v 1.10 2000/05/08 07:56:03 mycroft Exp $ */ + /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -36,26 +36,26 @@ * SUCH DAMAGE. */ +#include #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1994\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1994\n\ + The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; #else -static char rcsid[] = "$NetBSD: main.c,v 1.2 1996/12/28 18:57:01 tls Exp $"; +__RCSID("$NetBSD: main.c,v 1.10 2000/05/08 07:56:03 mycroft Exp $"); #endif #endif /* not lint */ #include #include #include -#include #include #include +#include #include #include "gomoku.h" @@ -71,7 +71,7 @@ char *prog; /* name of program */ FILE *debugfp; /* file for debug output */ FILE *inputfp; /* file for debug input */ -char pdir[4] = "-\\|/"; +const char pdir[4] = "-\\|/"; char fmtbuf[128]; struct spotstr board[BAREA]; /* info for board */ @@ -81,13 +81,11 @@ u_char overlap[FAREA * FAREA]; /* true if frame [a][b] overlap */ short intersect[FAREA * FAREA]; /* frame [a][b] intersection */ int movelog[BSZ * BSZ]; /* log of all the moves */ int movenum; /* current move number */ -char *plyr[2]; /* who's who */ +const char *plyr[2]; /* who's who */ -extern void quit(); -#ifdef DEBUG -extern void whatsup(); -#endif +int main __P((int, char *[])); +int main(argc, argv) int argc; char **argv; @@ -95,18 +93,23 @@ main(argc, argv) char buf[128]; int color, curmove, i, ch; int input[2]; - static char *fmt[2] = { + static const char *const fmt[2] = { "%3d %-6s", "%3d %-6s" }; + /* Revoke setgid privileges */ + setgid(getgid()); + + color = curmove = 0; + prog = strrchr(argv[0], '/'); if (prog) prog++; else prog = argv[0]; - while ((ch = getopt(argc, argv, "bcdD:u")) != EOF) { + while ((ch = getopt(argc, argv, "bcdD:u")) != -1) { switch (ch) { case 'b': /* background */ interactive = 0; @@ -150,7 +153,7 @@ again: #ifdef DEBUG signal(SIGINT, whatsup); #else - signal(SIGINT, quit); + signal(SIGINT, quitsig); #endif if (inputfp == NULL && test == 0) { @@ -259,7 +262,7 @@ again: ask("save file name? "); (void)getline(buf, sizeof(buf)); if ((fp = fopen(buf, "w")) == NULL) { - log("cannot create save file"); + glog("cannot create save file"); goto getinput; } for (i = 0; i < movenum - 1; i++) @@ -270,7 +273,7 @@ again: } if (curmove != RESIGN && board[curmove].s_occ != EMPTY) { - log("Illegal move"); + glog("Illegal move"); goto getinput; } } @@ -282,7 +285,7 @@ again: } if (interactive) { sprintf(fmtbuf, fmt[color], movenum, stoc(curmove)); - log(fmtbuf); + glog(fmtbuf); } if ((i = makemove(color, curmove)) != MOVEOK) break; @@ -311,7 +314,7 @@ again: replay: ask("replay? "); if (getline(buf, sizeof(buf)) && - buf[0] == 'y' || buf[0] == 'Y') + (buf[0] == 'y' || buf[0] == 'Y')) goto again; if (strcmp(buf, "save") == 0) { FILE *fp; @@ -319,7 +322,7 @@ again: ask("save file name? "); (void)getline(buf, sizeof(buf)); if ((fp = fopen(buf, "w")) == NULL) { - log("cannot create save file"); + glog("cannot create save file"); goto replay; } for (i = 0; i < movenum - 1; i++) @@ -331,8 +334,11 @@ again: } } quit(); + /* NOTREACHED */ + return(0); } +int readinput(fp) FILE *fp; { @@ -492,8 +498,9 @@ syntax: /* * Display debug info. */ +void dlog(str) - char *str; + const char *str; { if (debugfp) @@ -504,8 +511,9 @@ dlog(str) fprintf(stderr, "%s\n", str); } -log(str) - char *str; +void +glog(str) + const char *str; { if (debugfp) @@ -526,11 +534,19 @@ quit() exit(0); } +void +quitsig(dummy) + int dummy __attribute__((__unused__)); +{ + quit(); +} + /* * Die gracefully. */ +void panic(str) - char *str; + const char *str; { fprintf(stderr, "%s: %s\n", prog, str); fputs("resign\n", stdout);