2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)subs.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/backgammon/common_source/subs.c,v 1.12 1999/11/30 03:48:27 billf Exp $
35 * $DragonFly: src/games/backgammon/common_source/subs.c,v 1.3 2006/08/08 16:36:11 pavalos Exp $
46 static const char plred[] = "Player is red, computer is white.";
47 static const char plwhite[] = "Player is white, computer is red.";
48 static const char nocomp[] = "(No computer play.)";
50 const char *const descr[] = {
51 "Usage: backgammon [-h n r w b pr pw pb tterm sfile]\n",
52 "\t-h\tgets this list\n\t-n\tdon't ask for rules or instructions",
53 "\t-r\tplayer is red (implies -n)\n\t-w\tplayer is white (implies -n)",
54 "\t-b\ttwo players, red and white (implies -n)",
55 "\t-pr\tprint the board before red's turn",
56 "\t-pw\tprint the board before white's turn",
57 "\t-pb\tprint the board before both player's turn",
58 "\t-tterm\tterminal is a term",
59 "\t-sfile\trecover saved game from file",
64 errexit(const char *s)
75 if (buffnum == BUFSIZ) {
76 if (write(1,outbuff,BUFSIZ) != BUFSIZ)
77 errexit ("addbuf (write):");
90 if (write (1,outbuff,buffnum) != buffnum)
91 errexit ("buflush (write):");
105 if (read(0,&c,1) != 1)
107 #ifdef WHY_IS_THIS_HARDWIRED_IN_HERE
111 if (c == '\033' || c == '\015')
117 if (c >= 'a' && c <= 'z')
132 writel(const char *l)
138 trace = fopen ("bgtrace","w");
140 fprintf (trace,"writel: \"");
141 for (s = l; *s; s++) {
142 if (*s < ' ' || *s == '\177')
143 fprintf (trace,"^%c",(*s)^0100);
147 fprintf (trace,"\"\n");
161 writel ("Red's roll: ");
163 writel ("White's roll: ");
176 for (i = 4; i > 0; i--) {
178 for (j = 0; j<i; j++)
181 writec ((n/t)%10+'0');
199 writel ("Game value: ");
206 writel (" doubled last.");
209 case -1: /* player is red */
212 case 0: /* player is both colors */
215 case 1: /* player is white */
220 if (rscore || wscore) {
239 writel ("Are you sure you want to quit?");
242 writel ("Would you like to save this game?");
259 while ( (c = readc()) != 'Y' && c != 'N') {
260 if (special && c == special)
264 writel (" (Y, N, or ");
268 writel (" (Y or N)");
285 writel ("Blot hit on ");
297 c = cturn/abs(cturn);
309 getarg(int argc, char **argv)
314 /* process arguments here. dashes are ignored, nbrw are ignored
315 if the game is being recovered */
317 while ((ch = getopt (argc, argv, "nbrwp:t:s:h")) != -1) {
320 /* don't ask if rules or instructions needed */
325 args[acnt++] = strdup ("-n");
328 /* player is both red and white */
334 args[acnt++] = strdup ("-b");
343 args[acnt++] = strdup ("-r");
346 /* player is white */
352 args[acnt++] = strdup ("-w");
355 /* print board after move according to following character */
357 if (optarg[0] != 'r' && optarg[0] != 'w' && optarg[0] != 'b')
359 args[acnt] = strdup ("-p ");
360 args[acnt++][2] = optarg[0];
361 if (optarg[0] == 'r')
363 if (optarg[0] == 'w')
365 if (optarg[0] == 'b')
370 tflag = getcaps (optarg);
378 for (i = 0; descr[i] != 0; i++)
385 if ( argc && argv[0][0] != '\0' )
396 board[6] = board[13] = -5;
398 board[12] = board[19] = 5;
401 off[0] = off[1] = -15;
427 if (tcsetattr (0,TCSANOW,&tty) < 0)
434 /* go to bottom of screen */
441 /* fix terminal status */
463 while (c < '1' || c > '6')
469 while (c < '1' || c > '6')