-/* $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.
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#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 <curses.h>
#include <err.h>
#include <signal.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include "gomoku.h"
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 */
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;
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;
#ifdef DEBUG
signal(SIGINT, whatsup);
#else
- signal(SIGINT, quit);
+ signal(SIGINT, quitsig);
#endif
if (inputfp == NULL && test == 0) {
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++)
}
if (curmove != RESIGN &&
board[curmove].s_occ != EMPTY) {
- log("Illegal move");
+ glog("Illegal move");
goto getinput;
}
}
}
if (interactive) {
sprintf(fmtbuf, fmt[color], movenum, stoc(curmove));
- log(fmtbuf);
+ glog(fmtbuf);
}
if ((i = makemove(color, curmove)) != MOVEOK)
break;
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;
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++)
}
}
quit();
+ /* NOTREACHED */
+ return(0);
}
+int
readinput(fp)
FILE *fp;
{
/*
* Display debug info.
*/
+void
dlog(str)
- char *str;
+ const char *str;
{
if (debugfp)
fprintf(stderr, "%s\n", str);
}
-log(str)
- char *str;
+void
+glog(str)
+ const char *str;
{
if (debugfp)
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);