main.c revision 1.20 1 1.20 dholland /* $NetBSD: main.c,v 1.20 2009/08/12 06:19:17 dholland Exp $ */
2 1.3 cgd
3 1.1 tls /*
4 1.1 tls * Copyright (c) 1994
5 1.1 tls * The Regents of the University of California. All rights reserved.
6 1.1 tls *
7 1.1 tls * This code is derived from software contributed to Berkeley by
8 1.1 tls * Ralph Campbell.
9 1.1 tls *
10 1.1 tls * Redistribution and use in source and binary forms, with or without
11 1.1 tls * modification, are permitted provided that the following conditions
12 1.1 tls * are met:
13 1.1 tls * 1. Redistributions of source code must retain the above copyright
14 1.1 tls * notice, this list of conditions and the following disclaimer.
15 1.1 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 tls * notice, this list of conditions and the following disclaimer in the
17 1.1 tls * documentation and/or other materials provided with the distribution.
18 1.11 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 tls * may be used to endorse or promote products derived from this software
20 1.1 tls * without specific prior written permission.
21 1.1 tls *
22 1.1 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 tls * SUCH DAMAGE.
33 1.1 tls */
34 1.1 tls
35 1.4 lukem #include <sys/cdefs.h>
36 1.1 tls #ifndef lint
37 1.14 lukem __COPYRIGHT("@(#) Copyright (c) 1994\
38 1.14 lukem The Regents of the University of California. All rights reserved.");
39 1.1 tls #endif /* not lint */
40 1.1 tls
41 1.1 tls #ifndef lint
42 1.2 tls #if 0
43 1.1 tls static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95";
44 1.2 tls #else
45 1.20 dholland __RCSID("$NetBSD: main.c,v 1.20 2009/08/12 06:19:17 dholland Exp $");
46 1.2 tls #endif
47 1.1 tls #endif /* not lint */
48 1.1 tls
49 1.1 tls #include <curses.h>
50 1.1 tls #include <err.h>
51 1.1 tls #include <signal.h>
52 1.16 dholland #include <stdarg.h>
53 1.1 tls #include <stdlib.h>
54 1.1 tls #include <string.h>
55 1.5 perry #include <time.h>
56 1.1 tls #include <unistd.h>
57 1.1 tls
58 1.1 tls #include "gomoku.h"
59 1.1 tls
60 1.1 tls #define USER 0 /* get input from standard input */
61 1.1 tls #define PROGRAM 1 /* get input from program */
62 1.1 tls #define INPUTF 2 /* get input from a file */
63 1.1 tls
64 1.1 tls int interactive = 1; /* true if interactive */
65 1.1 tls int debug; /* true if debugging */
66 1.20 dholland static int test; /* both moves come from 1: input, 2: computer */
67 1.20 dholland static char *prog; /* name of program */
68 1.20 dholland static FILE *debugfp; /* file for debug output */
69 1.20 dholland static FILE *inputfp; /* file for debug input */
70 1.1 tls
71 1.6 jsm const char pdir[4] = "-\\|/";
72 1.1 tls
73 1.1 tls struct spotstr board[BAREA]; /* info for board */
74 1.1 tls struct combostr frames[FAREA]; /* storage for all frames */
75 1.1 tls struct combostr *sortframes[2]; /* sorted list of non-empty frames */
76 1.1 tls u_char overlap[FAREA * FAREA]; /* true if frame [a][b] overlap */
77 1.1 tls short intersect[FAREA * FAREA]; /* frame [a][b] intersection */
78 1.1 tls int movelog[BSZ * BSZ]; /* log of all the moves */
79 1.1 tls int movenum; /* current move number */
80 1.6 jsm const char *plyr[2]; /* who's who */
81 1.1 tls
82 1.20 dholland static int readinput(FILE *);
83 1.20 dholland static void misclog(const char *, ...) __printflike(1, 2);
84 1.20 dholland static void quit(void) __dead;
85 1.20 dholland static void quitsig(int) __dead;
86 1.1 tls
87 1.4 lukem int
88 1.15 dholland main(int argc, char **argv)
89 1.1 tls {
90 1.1 tls char buf[128];
91 1.1 tls int color, curmove, i, ch;
92 1.1 tls int input[2];
93 1.6 jsm static const char *const fmt[2] = {
94 1.1 tls "%3d %-6s",
95 1.1 tls "%3d %-6s"
96 1.1 tls };
97 1.8 jsm
98 1.8 jsm /* Revoke setgid privileges */
99 1.10 mycroft setgid(getgid());
100 1.1 tls
101 1.4 lukem color = curmove = 0;
102 1.4 lukem
103 1.1 tls prog = strrchr(argv[0], '/');
104 1.1 tls if (prog)
105 1.1 tls prog++;
106 1.1 tls else
107 1.1 tls prog = argv[0];
108 1.1 tls
109 1.4 lukem while ((ch = getopt(argc, argv, "bcdD:u")) != -1) {
110 1.1 tls switch (ch) {
111 1.1 tls case 'b': /* background */
112 1.1 tls interactive = 0;
113 1.1 tls break;
114 1.1 tls case 'd': /* debugging */
115 1.1 tls debug++;
116 1.1 tls break;
117 1.1 tls case 'D': /* log debug output to file */
118 1.1 tls if ((debugfp = fopen(optarg, "w")) == NULL)
119 1.1 tls err(1, "%s", optarg);
120 1.1 tls break;
121 1.1 tls case 'u': /* testing: user verses user */
122 1.1 tls test = 1;
123 1.1 tls break;
124 1.1 tls case 'c': /* testing: computer verses computer */
125 1.1 tls test = 2;
126 1.1 tls break;
127 1.1 tls }
128 1.1 tls }
129 1.1 tls argc -= optind;
130 1.1 tls argv += optind;
131 1.1 tls if (argc) {
132 1.1 tls if ((inputfp = fopen(*argv, "r")) == NULL)
133 1.1 tls err(1, "%s", *argv);
134 1.1 tls }
135 1.1 tls
136 1.1 tls if (!debug)
137 1.1 tls #ifdef SVR4
138 1.1 tls srand(time(0));
139 1.1 tls #else
140 1.1 tls srandom(time(0));
141 1.1 tls #endif
142 1.1 tls if (interactive)
143 1.1 tls cursinit(); /* initialize curses */
144 1.1 tls again:
145 1.1 tls bdinit(board); /* initialize board contents */
146 1.1 tls
147 1.1 tls if (interactive) {
148 1.1 tls plyr[BLACK] = plyr[WHITE] = "???";
149 1.1 tls bdisp_init(); /* initialize display of board */
150 1.1 tls #ifdef DEBUG
151 1.1 tls signal(SIGINT, whatsup);
152 1.1 tls #else
153 1.4 lukem signal(SIGINT, quitsig);
154 1.1 tls #endif
155 1.1 tls
156 1.1 tls if (inputfp == NULL && test == 0) {
157 1.1 tls for (;;) {
158 1.1 tls ask("black or white? ");
159 1.19 roy get_line(buf, sizeof(buf));
160 1.1 tls if (buf[0] == 'b' || buf[0] == 'B') {
161 1.1 tls color = BLACK;
162 1.1 tls break;
163 1.1 tls }
164 1.1 tls if (buf[0] == 'w' || buf[0] == 'W') {
165 1.1 tls color = WHITE;
166 1.1 tls break;
167 1.1 tls }
168 1.1 tls move(22, 0);
169 1.1 tls printw("Black moves first. Please enter `black' or `white'\n");
170 1.1 tls }
171 1.1 tls move(22, 0);
172 1.1 tls clrtoeol();
173 1.1 tls }
174 1.1 tls } else {
175 1.1 tls setbuf(stdout, 0);
176 1.19 roy get_line(buf, sizeof(buf));
177 1.1 tls if (strcmp(buf, "black") == 0)
178 1.1 tls color = BLACK;
179 1.1 tls else if (strcmp(buf, "white") == 0)
180 1.1 tls color = WHITE;
181 1.1 tls else {
182 1.16 dholland panic("Huh? Expected `black' or `white', got `%s'\n",
183 1.1 tls buf);
184 1.1 tls }
185 1.1 tls }
186 1.1 tls
187 1.1 tls if (inputfp) {
188 1.1 tls input[BLACK] = INPUTF;
189 1.1 tls input[WHITE] = INPUTF;
190 1.1 tls } else {
191 1.1 tls switch (test) {
192 1.1 tls case 0: /* user verses program */
193 1.1 tls input[color] = USER;
194 1.1 tls input[!color] = PROGRAM;
195 1.1 tls break;
196 1.1 tls
197 1.1 tls case 1: /* user verses user */
198 1.1 tls input[BLACK] = USER;
199 1.1 tls input[WHITE] = USER;
200 1.1 tls break;
201 1.1 tls
202 1.1 tls case 2: /* program verses program */
203 1.1 tls input[BLACK] = PROGRAM;
204 1.1 tls input[WHITE] = PROGRAM;
205 1.1 tls break;
206 1.1 tls }
207 1.1 tls }
208 1.1 tls if (interactive) {
209 1.1 tls plyr[BLACK] = input[BLACK] == USER ? "you" : prog;
210 1.1 tls plyr[WHITE] = input[WHITE] == USER ? "you" : prog;
211 1.1 tls bdwho(1);
212 1.1 tls }
213 1.1 tls
214 1.1 tls for (color = BLACK; ; color = !color) {
215 1.1 tls top:
216 1.1 tls switch (input[color]) {
217 1.1 tls case INPUTF: /* input comes from a file */
218 1.1 tls curmove = readinput(inputfp);
219 1.1 tls if (curmove != ILLEGAL)
220 1.1 tls break;
221 1.1 tls switch (test) {
222 1.1 tls case 0: /* user verses program */
223 1.1 tls input[color] = USER;
224 1.1 tls input[!color] = PROGRAM;
225 1.1 tls break;
226 1.1 tls
227 1.1 tls case 1: /* user verses user */
228 1.1 tls input[BLACK] = USER;
229 1.1 tls input[WHITE] = USER;
230 1.1 tls break;
231 1.1 tls
232 1.1 tls case 2: /* program verses program */
233 1.1 tls input[BLACK] = PROGRAM;
234 1.1 tls input[WHITE] = PROGRAM;
235 1.1 tls break;
236 1.1 tls }
237 1.1 tls plyr[BLACK] = input[BLACK] == USER ? "you" : prog;
238 1.1 tls plyr[WHITE] = input[WHITE] == USER ? "you" : prog;
239 1.1 tls bdwho(1);
240 1.1 tls goto top;
241 1.1 tls
242 1.1 tls case USER: /* input comes from standard input */
243 1.1 tls getinput:
244 1.1 tls if (interactive)
245 1.1 tls ask("move? ");
246 1.19 roy if (!get_line(buf, sizeof(buf))) {
247 1.1 tls curmove = RESIGN;
248 1.1 tls break;
249 1.1 tls }
250 1.1 tls if (buf[0] == '\0')
251 1.1 tls goto getinput;
252 1.1 tls curmove = ctos(buf);
253 1.1 tls if (interactive) {
254 1.1 tls if (curmove == SAVE) {
255 1.1 tls FILE *fp;
256 1.1 tls
257 1.1 tls ask("save file name? ");
258 1.19 roy (void)get_line(buf, sizeof(buf));
259 1.1 tls if ((fp = fopen(buf, "w")) == NULL) {
260 1.16 dholland misclog("cannot create save file");
261 1.1 tls goto getinput;
262 1.1 tls }
263 1.1 tls for (i = 0; i < movenum - 1; i++)
264 1.1 tls fprintf(fp, "%s\n",
265 1.1 tls stoc(movelog[i]));
266 1.1 tls fclose(fp);
267 1.1 tls goto getinput;
268 1.1 tls }
269 1.1 tls if (curmove != RESIGN &&
270 1.1 tls board[curmove].s_occ != EMPTY) {
271 1.16 dholland misclog("Illegal move");
272 1.1 tls goto getinput;
273 1.1 tls }
274 1.1 tls }
275 1.1 tls break;
276 1.1 tls
277 1.1 tls case PROGRAM: /* input comes from the program */
278 1.1 tls curmove = pickmove(color);
279 1.1 tls break;
280 1.1 tls }
281 1.1 tls if (interactive) {
282 1.16 dholland misclog(fmt[color], movenum, stoc(curmove));
283 1.1 tls }
284 1.1 tls if ((i = makemove(color, curmove)) != MOVEOK)
285 1.1 tls break;
286 1.1 tls if (interactive)
287 1.1 tls bdisp();
288 1.1 tls }
289 1.1 tls if (interactive) {
290 1.1 tls move(22, 0);
291 1.1 tls switch (i) {
292 1.1 tls case WIN:
293 1.1 tls if (input[color] == PROGRAM)
294 1.1 tls addstr("Ha ha, I won");
295 1.1 tls else
296 1.1 tls addstr("Rats! you won");
297 1.1 tls break;
298 1.1 tls case TIE:
299 1.1 tls addstr("Wow! its a tie");
300 1.1 tls break;
301 1.1 tls case ILLEGAL:
302 1.1 tls addstr("Illegal move");
303 1.1 tls break;
304 1.1 tls }
305 1.1 tls clrtoeol();
306 1.1 tls bdisp();
307 1.1 tls if (i != RESIGN) {
308 1.1 tls replay:
309 1.1 tls ask("replay? ");
310 1.19 roy if (get_line(buf, sizeof(buf)) &&
311 1.4 lukem (buf[0] == 'y' || buf[0] == 'Y'))
312 1.1 tls goto again;
313 1.1 tls if (strcmp(buf, "save") == 0) {
314 1.1 tls FILE *fp;
315 1.1 tls
316 1.1 tls ask("save file name? ");
317 1.19 roy (void)get_line(buf, sizeof(buf));
318 1.1 tls if ((fp = fopen(buf, "w")) == NULL) {
319 1.16 dholland misclog("cannot create save file");
320 1.1 tls goto replay;
321 1.1 tls }
322 1.1 tls for (i = 0; i < movenum - 1; i++)
323 1.1 tls fprintf(fp, "%s\n",
324 1.1 tls stoc(movelog[i]));
325 1.1 tls fclose(fp);
326 1.1 tls goto replay;
327 1.1 tls }
328 1.1 tls }
329 1.1 tls }
330 1.1 tls quit();
331 1.4 lukem /* NOTREACHED */
332 1.4 lukem return(0);
333 1.1 tls }
334 1.1 tls
335 1.20 dholland static int
336 1.15 dholland readinput(FILE *fp)
337 1.1 tls {
338 1.1 tls int c;
339 1.17 dholland char buf[128];
340 1.17 dholland size_t pos;
341 1.1 tls
342 1.17 dholland pos = 0;
343 1.17 dholland while ((c = getc(fp)) != EOF && c != '\n' && pos < sizeof(buf) - 1)
344 1.17 dholland buf[pos++] = c;
345 1.17 dholland buf[pos] = '\0';
346 1.17 dholland return ctos(buf);
347 1.1 tls }
348 1.1 tls
349 1.1 tls #ifdef DEBUG
350 1.1 tls /*
351 1.1 tls * Handle strange situations.
352 1.1 tls */
353 1.1 tls void
354 1.15 dholland whatsup(int signum)
355 1.1 tls {
356 1.18 dholland int i, n, s1, s2, d1, d2;
357 1.1 tls struct spotstr *sp;
358 1.1 tls FILE *fp;
359 1.1 tls char *str;
360 1.1 tls struct elist *ep;
361 1.1 tls struct combostr *cbp;
362 1.18 dholland char input[128];
363 1.18 dholland char tmp[128];
364 1.1 tls
365 1.1 tls if (!interactive)
366 1.1 tls quit();
367 1.1 tls top:
368 1.1 tls ask("cmd? ");
369 1.19 roy if (!get_line(input, sizeof(input)))
370 1.1 tls quit();
371 1.18 dholland switch (*input) {
372 1.1 tls case '\0':
373 1.1 tls goto top;
374 1.1 tls case 'q': /* conservative quit */
375 1.1 tls quit();
376 1.1 tls case 'd': /* set debug level */
377 1.18 dholland debug = input[1] - '0';
378 1.16 dholland debuglog("Debug set to %d", debug);
379 1.1 tls sleep(1);
380 1.1 tls case 'c':
381 1.1 tls break;
382 1.1 tls case 'b': /* back up a move */
383 1.1 tls if (movenum > 1) {
384 1.1 tls movenum--;
385 1.1 tls board[movelog[movenum - 1]].s_occ = EMPTY;
386 1.1 tls bdisp();
387 1.1 tls }
388 1.1 tls goto top;
389 1.1 tls case 's': /* suggest a move */
390 1.18 dholland i = input[1] == 'b' ? BLACK : WHITE;
391 1.16 dholland debuglog("suggest %c %s", i == BLACK ? 'B' : 'W',
392 1.1 tls stoc(pickmove(i)));
393 1.1 tls goto top;
394 1.1 tls case 'f': /* go forward a move */
395 1.1 tls board[movelog[movenum - 1]].s_occ = movenum & 1 ? BLACK : WHITE;
396 1.1 tls movenum++;
397 1.1 tls bdisp();
398 1.1 tls goto top;
399 1.1 tls case 'l': /* print move history */
400 1.18 dholland if (input[1] == '\0') {
401 1.1 tls for (i = 0; i < movenum - 1; i++)
402 1.16 dholland debuglog("%s", stoc(movelog[i]));
403 1.1 tls goto top;
404 1.1 tls }
405 1.18 dholland if ((fp = fopen(input + 1, "w")) == NULL)
406 1.1 tls goto top;
407 1.1 tls for (i = 0; i < movenum - 1; i++) {
408 1.1 tls fprintf(fp, "%s", stoc(movelog[i]));
409 1.1 tls if (++i < movenum - 1)
410 1.1 tls fprintf(fp, " %s\n", stoc(movelog[i]));
411 1.1 tls else
412 1.1 tls fputc('\n', fp);
413 1.1 tls }
414 1.1 tls bdump(fp);
415 1.1 tls fclose(fp);
416 1.1 tls goto top;
417 1.1 tls case 'o':
418 1.18 dholland /* avoid use w/o initialization on invalid input */
419 1.18 dholland d1 = s1 = 0;
420 1.18 dholland
421 1.1 tls n = 0;
422 1.18 dholland for (str = input + 1; *str; str++)
423 1.1 tls if (*str == ',') {
424 1.1 tls for (d1 = 0; d1 < 4; d1++)
425 1.1 tls if (str[-1] == pdir[d1])
426 1.1 tls break;
427 1.1 tls str[-1] = '\0';
428 1.18 dholland sp = &board[s1 = ctos(input + 1)];
429 1.1 tls n = (sp->s_frame[d1] - frames) * FAREA;
430 1.1 tls *str++ = '\0';
431 1.1 tls break;
432 1.1 tls }
433 1.1 tls sp = &board[s2 = ctos(str)];
434 1.1 tls while (*str)
435 1.1 tls str++;
436 1.1 tls for (d2 = 0; d2 < 4; d2++)
437 1.1 tls if (str[-1] == pdir[d2])
438 1.1 tls break;
439 1.1 tls n += sp->s_frame[d2] - frames;
440 1.16 dholland debuglog("overlap %s%c,%s%c = %x", stoc(s1), pdir[d1],
441 1.16 dholland stoc(s2), pdir[d2], overlap[n]);
442 1.1 tls goto top;
443 1.1 tls case 'p':
444 1.18 dholland sp = &board[i = ctos(input + 1)];
445 1.16 dholland debuglog("V %s %x/%d %d %x/%d %d %d %x", stoc(i),
446 1.1 tls sp->s_combo[BLACK].s, sp->s_level[BLACK],
447 1.1 tls sp->s_nforce[BLACK],
448 1.1 tls sp->s_combo[WHITE].s, sp->s_level[WHITE],
449 1.18 dholland sp->s_nforce[WHITE], sp->s_wval, sp->s_flags);
450 1.16 dholland debuglog("FB %s %x %x %x %x", stoc(i),
451 1.1 tls sp->s_fval[BLACK][0].s, sp->s_fval[BLACK][1].s,
452 1.1 tls sp->s_fval[BLACK][2].s, sp->s_fval[BLACK][3].s);
453 1.16 dholland debuglog("FW %s %x %x %x %x", stoc(i),
454 1.1 tls sp->s_fval[WHITE][0].s, sp->s_fval[WHITE][1].s,
455 1.1 tls sp->s_fval[WHITE][2].s, sp->s_fval[WHITE][3].s);
456 1.1 tls goto top;
457 1.1 tls case 'e': /* e {b|w} [0-9] spot */
458 1.18 dholland str = input + 1;
459 1.1 tls if (*str >= '0' && *str <= '9')
460 1.1 tls n = *str++ - '0';
461 1.1 tls else
462 1.1 tls n = 0;
463 1.1 tls sp = &board[i = ctos(str)];
464 1.1 tls for (ep = sp->s_empty; ep; ep = ep->e_next) {
465 1.1 tls cbp = ep->e_combo;
466 1.1 tls if (n) {
467 1.1 tls if (cbp->c_nframes > n)
468 1.1 tls continue;
469 1.1 tls if (cbp->c_nframes != n)
470 1.1 tls break;
471 1.1 tls }
472 1.18 dholland printcombo(cbp, tmp, sizeof(tmp));
473 1.18 dholland debuglog("%s", tmp);
474 1.1 tls }
475 1.1 tls goto top;
476 1.1 tls default:
477 1.16 dholland debuglog("Options are:");
478 1.16 dholland debuglog("q - quit");
479 1.16 dholland debuglog("c - continue");
480 1.16 dholland debuglog("d# - set debug level to #");
481 1.16 dholland debuglog("p# - print values at #");
482 1.1 tls goto top;
483 1.1 tls }
484 1.1 tls }
485 1.1 tls #endif /* DEBUG */
486 1.1 tls
487 1.1 tls /*
488 1.1 tls * Display debug info.
489 1.1 tls */
490 1.4 lukem void
491 1.16 dholland debuglog(const char *fmt, ...)
492 1.1 tls {
493 1.16 dholland va_list ap;
494 1.16 dholland char buf[128];
495 1.16 dholland
496 1.16 dholland va_start(ap, fmt);
497 1.16 dholland vsnprintf(buf, sizeof(buf), fmt, ap);
498 1.16 dholland va_end(ap);
499 1.1 tls
500 1.1 tls if (debugfp)
501 1.16 dholland fprintf(debugfp, "%s\n", buf);
502 1.1 tls if (interactive)
503 1.16 dholland dislog(buf);
504 1.1 tls else
505 1.16 dholland fprintf(stderr, "%s\n", buf);
506 1.1 tls }
507 1.1 tls
508 1.20 dholland static void
509 1.16 dholland misclog(const char *fmt, ...)
510 1.1 tls {
511 1.16 dholland va_list ap;
512 1.16 dholland char buf[128];
513 1.16 dholland
514 1.16 dholland va_start(ap, fmt);
515 1.16 dholland vsnprintf(buf, sizeof(buf), fmt, ap);
516 1.16 dholland va_end(ap);
517 1.1 tls
518 1.1 tls if (debugfp)
519 1.16 dholland fprintf(debugfp, "%s\n", buf);
520 1.1 tls if (interactive)
521 1.16 dholland dislog(buf);
522 1.1 tls else
523 1.16 dholland printf("%s\n", buf);
524 1.1 tls }
525 1.1 tls
526 1.20 dholland static void
527 1.15 dholland quit(void)
528 1.1 tls {
529 1.1 tls if (interactive) {
530 1.1 tls bdisp(); /* show final board */
531 1.1 tls cursfini();
532 1.1 tls }
533 1.1 tls exit(0);
534 1.1 tls }
535 1.1 tls
536 1.20 dholland static void
537 1.15 dholland quitsig(int dummy __unused)
538 1.4 lukem {
539 1.4 lukem quit();
540 1.4 lukem }
541 1.4 lukem
542 1.1 tls /*
543 1.1 tls * Die gracefully.
544 1.1 tls */
545 1.4 lukem void
546 1.16 dholland panic(const char *fmt, ...)
547 1.1 tls {
548 1.16 dholland va_list ap;
549 1.16 dholland
550 1.16 dholland fprintf(stderr, "%s: ", prog);
551 1.16 dholland va_start(ap, fmt);
552 1.16 dholland vfprintf(stderr, fmt, ap);
553 1.16 dholland va_end(ap);
554 1.16 dholland fprintf(stderr, "\n");
555 1.16 dholland
556 1.1 tls fputs("resign\n", stdout);
557 1.1 tls quit();
558 1.1 tls }
559