summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>2001-06-23 23:50:07 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>2001-06-23 23:50:07 +0000
commit4b888f757520208f6eb16c642891507450aea872 (patch)
tree88ad863f2489148ec58400d846f1b340b0fc7de3
parent0ffd7e0316588c2558ff550c5d0e25f5a8b2ea65 (diff)
termios -> curses
-rw-r--r--games/backgammon/backgammon/backgammon.631
-rw-r--r--games/backgammon/backgammon/backlocal.h4
-rw-r--r--games/backgammon/backgammon/extra.c26
-rw-r--r--games/backgammon/backgammon/main.c176
-rw-r--r--games/backgammon/backgammon/move.c45
-rw-r--r--games/backgammon/backgammon/text.c19
-rw-r--r--games/backgammon/common_source/back.h25
-rw-r--r--games/backgammon/common_source/board.c35
-rw-r--r--games/backgammon/common_source/check.c58
-rw-r--r--games/backgammon/common_source/fancy.c511
-rw-r--r--games/backgammon/common_source/init.c11
-rw-r--r--games/backgammon/common_source/one.c18
-rw-r--r--games/backgammon/common_source/save.c73
-rw-r--r--games/backgammon/common_source/subs.c262
-rw-r--r--games/backgammon/common_source/table.c122
-rw-r--r--games/backgammon/teachgammon/teach.c30
-rw-r--r--games/backgammon/teachgammon/ttext1.c6
-rw-r--r--games/backgammon/teachgammon/ttext2.c36
-rw-r--r--games/backgammon/teachgammon/tutor.c58
19 files changed, 369 insertions, 1177 deletions
diff --git a/games/backgammon/backgammon/backgammon.6 b/games/backgammon/backgammon/backgammon.6
index ba6313ef845..91daf7983f4 100644
--- a/games/backgammon/backgammon/backgammon.6
+++ b/games/backgammon/backgammon/backgammon.6
@@ -1,4 +1,4 @@
-.\" $OpenBSD: backgammon.6,v 1.6 2000/04/21 03:10:24 pjanzen Exp $
+.\" $OpenBSD: backgammon.6,v 1.7 2001/06/23 23:49:53 pjanzen Exp $
.\"
.\" Copyright (c) 1980, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -43,8 +43,6 @@
.Nm backgammon
.Op Fl
.Op Fl nrwb
-.Op Fl p Ar [r | w | b]
-.Op Fl t Ar term
.Op Fl s Ar file
.Sh DESCRIPTION
This program lets you play backgammon against the computer
@@ -79,15 +77,6 @@ player is red (implies n)
player is white (implies n)
.It Fl b
two players, red and white (implies n)
-.It Fl p Ar r
-print the board before red's turn
-.It Fl p Ar w
-print the board before white's turn
-.It Fl p Ar b
-print the board before any turn
-.It Fl t Ar term
-terminal is type
-.Ar term
.It Fl s Ar file
recover previously saved game from
.Ar file .
@@ -98,24 +87,6 @@ An argument of
.Fl h
gets a description of possible arguments.
.Pp
-If
-.Ar term
-has capabilities for direct cursor movement (see
-.Xr terminfo 5 )
-.Nm
-.Dq fixes
-the board after each move,
-so the board does not need to be reprinted
-unless the screen suffers some horrendous malady.
-Also, any
-.Fl p
-option will be ignored.
-(The
-.Fl t
-option is not necessary unless the terminal type does not match
-the entry in the
-.Xr terminfo 5
-data base.)
.Sh QUICK REFERENCE
When the program prompts by typing only your color,
type a space or carriage return to roll, or
diff --git a/games/backgammon/backgammon/backlocal.h b/games/backgammon/backgammon/backlocal.h
index f69fc47b156..4d800a01337 100644
--- a/games/backgammon/backgammon/backlocal.h
+++ b/games/backgammon/backgammon/backlocal.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: backlocal.h,v 1.1 1998/03/19 11:13:05 pjanzen Exp $ */
+/* $OpenBSD: backlocal.h,v 1.2 2001/06/23 23:49:53 pjanzen Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@ int dblgood __P((void));
int eval __P((void));
int freemen __P((int));
void movcmp __P((void));
-void move __P((int));
+void domove __P((int));
int movegood __P((void));
void pickmove __P((void));
int trapped __P((int, int));
diff --git a/games/backgammon/backgammon/extra.c b/games/backgammon/backgammon/extra.c
index 97314f88a21..53388d8e854 100644
--- a/games/backgammon/backgammon/extra.c
+++ b/games/backgammon/backgammon/extra.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: extra.c,v 1.2 1998/03/19 11:13:06 pjanzen Exp $ */
+/* $OpenBSD: extra.c,v 1.3 2001/06/23 23:49:53 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)extra.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: extra.c,v 1.2 1998/03/19 11:13:06 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: extra.c,v 1.3 2001/06/23 23:49:53 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -55,34 +55,31 @@ dble()
int resp; /* response to y/n */
for (;;) {
- writel(" doubles."); /* indicate double */
+ addstr(" doubles."); /* indicate double */
if (cturn == -pnum) { /* see if computer accepts */
if (dblgood()) { /* guess not */
- writel(" Declined.\n");
+ addstr(" Declined.\n");
nexturn();
cturn *= -2; /* indicate loss */
return;
} else {/* computer accepts */
- writel(" Accepted.\n");
+ addstr(" Accepted.\n");
gvalue *= 2; /* double game value */
dlast = cturn;
- if (tflag)
- gwrite();
+ gwrite();
return;
}
}
/* ask if player accepts */
- writel(" Does ");
- writel(cturn == 1 ? color[2] : color[3]);
- writel(" accept?");
+ printw(" Does %s accept?", cturn == 1 ? color[2] : color[3]);
/* get response from yorn; a "2" means he said "p" to print board. */
if ((resp = yorn ('r')) == 2) {
- writel(" Reprint.\n");
- buflush();
+ addstr(" Reprint.\n");
+ moveplayers();
wrboard();
- writel(*Colorptr);
+ addstr(*Colorptr);
continue;
}
/* check response */
@@ -90,8 +87,7 @@ dble()
/* accepted */
gvalue *= 2;
dlast = cturn;
- if (tflag)
- gwrite();
+ gwrite();
return;
}
nexturn(); /* declined */
diff --git a/games/backgammon/backgammon/main.c b/games/backgammon/backgammon/main.c
index 8b9826dc1ba..a0ecfd86e9c 100644
--- a/games/backgammon/backgammon/main.c
+++ b/games/backgammon/backgammon/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.8 2001/02/18 03:32:49 pjanzen Exp $ */
+/* $OpenBSD: main.c,v 1.9 2001/06/23 23:49:54 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -43,10 +43,11 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.8 2001/02/18 03:32:49 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.9 2001/06/23 23:49:54 pjanzen Exp $";
#endif
#endif /* not lint */
+#include <err.h>
#include <time.h>
#include "back.h"
#include "backlocal.h"
@@ -54,7 +55,7 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.8 2001/02/18 03:32:49 pjanzen Exp $"
#define MVPAUSE 5 /* time to sleep when stuck */
/* #define MAXUSERS 35 */ /* maximum number of users */
-extern const char *const instr[]; /* text of instructions */
+extern const char *const instruct[]; /* text of instructions */
const char *const helpm[] = { /* help message */
"Enter a space or newline to roll, or",
@@ -110,42 +111,24 @@ main (argc,argv)
setegid(getgid());
setgid(getgid());
- /* initialization */
- bflag = 2; /* default no board */
signal(SIGINT, getout); /* trap interrupts */
- if (tcgetattr(0, &old) == -1) /* get old tty mode */
- errexit("backgammon(gtty)");
- noech = old;
- noech.c_lflag &= ~ECHO;
- traw = noech;
- traw.c_lflag &= ~ICANON; /* set up modes */
+ initcurses();
/* check user count */
#if 0
if (ucount() > MAXUSERS) {
- writel(user1a);
- wrint(MAXUSERS);
- writel(user1b);
+ printw("%s%d%s", user1a, MAXUSERS, user1b);
getout(0);
}
#endif
- /* get terminal capabilities, and decide if it can cursor address */
- tflag = getcaps(getenv("TERM"));
/* use whole screen for text */
- if (tflag)
- begscr = 0;
- t = time(0);
+ begscr = 0;
+ t = time(NULL);
srandom(t); /* 'random' seed */
getarg(argc, argv);
args[acnt] = '\0';
- if (tflag) { /* clear screen */
- noech.c_oflag &= ~(ONLCR | OXTABS);
- traw.c_oflag &= ~(ONLCR | OXTABS);
- clear();
- }
- fixtty(&traw); /* go into raw mode */
/* check if restored game and save flag for later */
if ((rfl = rflag)) {
@@ -157,27 +140,24 @@ main (argc,argv)
rscore = wscore = 0; /* zero score */
if (aflag) { /* print rules */
- writel(rules);
+ addstr(rules);
if (yorn(0)) {
- fixtty(&old); /* restore tty */
+ endwin();
execl(TEACH, "teachgammon", args, 0);
- tflag = 0; /* error! */
- writel(noteach);
- exit(1);
+ err(1, "%s", noteach);
} else {/* if not rules, then instructions */
- writel(need);
+ addstr(need);
if (yorn(0)) { /* print instructions */
clear();
- text(instr);
+ text(instruct);
}
}
}
init(); /* initialize board */
if (pnum == 2) {/* ask for color(s) */
- writec('\n');
- writel(askcol);
+ printw("\n%s", askcol);
while (pnum == 2) {
c = readc();
switch (c) {
@@ -196,28 +176,22 @@ main (argc,argv)
case 'P': /* Control the dice */
iroll = 1;
- writec('\n');
- writel("Dice controlled!");
- writec('\n');
- writel(askcol);
+ addstr("\nDice controlled!\n");
+ addstr(askcol);
break;
default: /* error */
- writec('\007');
+ beep();
}
}
}
wrboard(); /* print board */
- if (tflag)
- curmove(18, 0);
- else
- writec('\n');
+ move(18, 0);
}
/* limit text to bottom of screen */
- if (tflag)
- begscr = 17;
+ begscr = 17;
for (;;) { /* begin game! */
/* initial roll if needed */
@@ -226,23 +200,19 @@ main (argc,argv)
/* perform ritual of first roll */
if (!rflag) {
- if (tflag)
- curmove(17, 0);
+ move(17, 0);
while (D0 == D1) /* no doubles */
roll();
/* print rolls */
- writel(rollr);
- writec(D0 + '0');
- writel(rollw);
- writec(D1 + '0');
+ printw("%s%d%s%d", rollr, D0, rollw, D1);
/* winner goes first */
if (D0 > D1) {
- writel(rstart);
+ addstr(rstart);
cturn = 1;
} else {
- writel(wstart);
+ addstr(wstart);
cturn = -1;
}
}
@@ -273,21 +243,18 @@ main (argc,argv)
/* do first move (special case) */
if (!(rflag && raflag)) {
if (cturn == pnum) /* computer's move */
- move(0);
+ domove(0);
else { /* player's move */
mvlim = movallow();
/* reprint roll */
- if (tflag)
- curmove(cturn == -1 ? 18 : 19, 0);
+ move(cturn == -1 ? 18 : 19, 0);
proll();
getmove(); /* get player's move */
}
}
- if (tflag) {
- curmove(17, 0);
- cline();
- begscr = 18;
- }
+ move(17, 0);
+ clrtoeol();
+ begscr = 18;
/* no longer any difference between normal and recovered game. */
rflag = 0;
@@ -295,16 +262,11 @@ main (argc,argv)
while (cturn == 1 || cturn == -1) {
/* board maintainence */
- if (tflag)
- refresh(); /* fix board */
- else
- /* redo board if -p */
- if (cturn == bflag || bflag == 0)
- wrboard();
+ moveplayers(); /* fix board */
/* do computer's move */
if (cturn == pnum) {
- move(1);
+ domove(1);
/* see if double refused */
if (cturn == -2 || cturn == 2)
@@ -321,16 +283,15 @@ main (argc,argv)
/* (player's move) */
/* clean screen if safe */
- if (tflag && hflag) {
- curmove(20, 0);
- clend();
+ if (hflag) {
+ move(20, 0);
+ clrtobot();
hflag = 1;
}
/* if allowed, give him a chance to double */
if (dlast != cturn && gvalue < 64) {
- if (tflag)
- curmove(cturn == -1 ? 18: 19, 0);
- writel(*Colorptr);
+ move(cturn == -1 ? 18: 19, 0);
+ addstr(*Colorptr);
c = readc();
/* character cases */
@@ -356,24 +317,16 @@ main (argc,argv)
case ' ': /* roll */
case '\n':
roll();
- writel(" rolls ");
- writec(D0 + '0');
- writec(' ');
- writec(D1 + '0');
- writel(". ");
+ printw(" rolls %d %d. ", D0, D1);
/* see if he can move */
if ((mvlim = movallow()) == 0) {
/* can't move */
- writel(toobad1);
- writel(*colorptr);
- writel(unable);
- if (tflag) {
- if (pnum) {
- buflush();
- sleep(MVPAUSE);
- }
+ printw("%s%s%s", toobad1, *colorptr, unable);
+ if (pnum) {
+ moveplayers();
+ sleep(MVPAUSE);
}
nexturn();
break;
@@ -388,15 +341,9 @@ main (argc,argv)
default: /* invalid character */
/* print help message */
- if (tflag)
- curmove(20, 0);
- else
- writec('\n');
+ move(20, 0);
text(helpm);
- if (tflag)
- curmove(cturn == -1 ? 18 : 19, 0);
- else
- writec('\n');
+ move(cturn == -1 ? 18 : 19, 0);
/* don't erase */
hflag = 0;
@@ -405,18 +352,15 @@ main (argc,argv)
/* print roll */
roll();
- if (tflag)
- curmove(cturn == -1 ? 18: 19, 0);
+ move(cturn == -1 ? 18: 19, 0);
proll();
/* can he move? */
if ((mvlim = movallow()) == 0) {
/* he can't */
- writel(toobad2);
- writel(*colorptr);
- writel(cantmv);
- buflush();
+ printw("%s%s%s", toobad2, *colorptr, cantmv);
+ moveplayers();
sleep(MVPAUSE);
nexturn();
continue;
@@ -434,8 +378,7 @@ main (argc,argv)
cturn /= -2;
/* final board pos. */
- if (tflag)
- refresh();
+ moveplayers();
/* backgammon? */
mflag = 0;
@@ -445,31 +388,26 @@ main (argc,argv)
mflag++;
/* compute game value */
- if (tflag)
- curmove(20, 0);
+ move(20, 0);
if (*offopp == 15) {
if (mflag) {
- writel(bgammon);
+ addstr(bgammon);
gvalue *= 3;
}
else if (*offptr <= 0) {
- writel(gammon);
+ addstr(gammon);
gvalue *= 2;
}
}
/* report situation */
if (cturn == -1) {
- writel("Red wins ");
+ addstr("Red wins ");
rscore += gvalue;
} else {
- writel("White wins ");
+ addstr("White wins ");
wscore += gvalue;
}
- wrint(gvalue);
- writel(" point");
- if (gvalue > 1)
- writec('s');
- writel(".\n");
+ printw("%d point%s.\n", gvalue, (gvalue > 1) ? "s":"");
/* write score */
wrscore();
@@ -477,22 +415,20 @@ main (argc,argv)
/* check user count */
#if 0
if (ucount() > MAXUSERS) {
- writel (user2a);
- wrint (MAXUSERS);
- writel (user2b);
+ printw("%s%d%s", user2a, MAXUSERS, user2b);
rfl = 1;
break;
}
#endif
/* see if he wants another game */
- writel(again);
+ addstr(again);
if ((i = yorn('S')) == 0)
break;
init();
if (i == 2) {
- writel(" Save.\n");
+ addstr(" Save.\n");
cturn = 0;
save(0);
}
@@ -502,7 +438,7 @@ main (argc,argv)
/* give him a chance to save if game was recovered */
if (rfl && cturn) {
- writel(svpromt);
+ addstr(svpromt);
if (yorn(0)) {
/* re-initialize for recovery */
init();
diff --git a/games/backgammon/backgammon/move.c b/games/backgammon/backgammon/move.c
index 4d8d4a28c47..3f458a4cfa7 100644
--- a/games/backgammon/backgammon/move.c
+++ b/games/backgammon/backgammon/move.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: move.c,v 1.3 2001/02/18 04:16:36 ericj Exp $ */
+/* $OpenBSD: move.c,v 1.4 2001/06/23 23:49:54 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: move.c,v 1.3 2001/02/18 04:16:36 ericj Exp $";
+static char rcsid[] = "$OpenBSD: move.c,v 1.4 2001/06/23 23:49:54 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -95,7 +95,7 @@ static struct BOARD *nextfree __P((void));
void
-move(okay)
+domove(okay)
int okay; /* zero if first move */
{
int i; /* index */
@@ -103,7 +103,7 @@ move(okay)
if (okay) { /* see if comp should double */
if (gvalue < 64 && dlast != cturn && dblgood()) {
- writel(*Colorptr);
+ addstr(*Colorptr);
dble(); /* double */
/* return if declined */
if (cturn != 1 && cturn != -1)
@@ -124,24 +124,15 @@ move(okay)
race = 1;
/* print roll */
- if (tflag)
- curmove(cturn == -1 ? 18 : 19, 0);
- writel(*Colorptr);
- writel(" rolls ");
- writec(D0 + '0');
- writec(' ');
- writec(D1 + '0');
- /* make tty interruptable while thinking */
- if (tflag)
- cline();
- fixtty(&noech);
+ move(cturn == -1 ? 18 : 19, 0);
+ printw("%s rolls %d %d", *Colorptr, D0, D1);
+ clrtoeol();
/* find out how many moves */
mvlim = movallow();
if (mvlim == 0) {
- writel(" but cannot use it.\n");
+ addstr(" but cannot use it.\n");
nexturn();
- fixtty(&traw);
return;
}
/* initialize */
@@ -153,32 +144,26 @@ move(okay)
pickmove();
/* print move */
- writel(" and moves ");
+ addstr(" and moves ");
for (i = 0; i < mvlim; i++) {
if (i > 0)
- writec(',');
- wrint(p[i] = cp[i]);
- writec('-');
- wrint(g[i] = cg[i]);
+ addch(',');
+ printw("%d-%d", p[i] = cp[i], g[i] = cg[i]);
makmove(i);
}
- writec('.');
+ addch('.');
/* print blots hit */
- if (tflag)
- curmove(20, 0);
- else
- writec('\n');
+ move(20, 0);
for (i = 0; i < mvlim; i++)
if (h[i])
wrhit(g[i]);
/* get ready for next move */
nexturn();
if (!okay) {
- buflush();
+ refresh();
sleep(3);
}
- fixtty(&traw); /* no more tty interrupt */
}
void
@@ -353,7 +338,7 @@ nextfree()
if (freeq == 0) {
new = (struct BOARD *)calloc (1, sizeof(struct BOARD));
if (new == 0) {
- writel("\nOut of memory\n");
+ addstr("\nOut of memory\n");
getout(0);
}
} else {
diff --git a/games/backgammon/backgammon/text.c b/games/backgammon/backgammon/text.c
index aff710442f7..49f35823980 100644
--- a/games/backgammon/backgammon/text.c
+++ b/games/backgammon/backgammon/text.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: text.c,v 1.4 2001/02/18 04:16:36 ericj Exp $ */
+/* $OpenBSD: text.c,v 1.5 2001/06/23 23:49:54 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,13 +37,13 @@
#if 0
static char sccsid[] = "@(#)text.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: text.c,v 1.4 2001/02/18 04:16:36 ericj Exp $";
+static char rcsid[] = "$OpenBSD: text.c,v 1.5 2001/06/23 23:49:54 pjanzen Exp $";
#endif
#endif /* not lint */
#include "back.h"
-const char *const instr[] = {
+const char *const instruct[] = {
" This program reacts to keystrokes immediately, without waiting",
"for a newline. Consequently, special characters such as RUBOUT",
"and ESC will not perform their special functions during most of",
@@ -111,23 +111,18 @@ text(t)
int i;
const char *s, *a;
- fixtty(&noech);
while (*t != 0) {
s = a = *t;
for (i = 0; *a != '\0'; i--)
a++;
- if (i) {
- writel(s);
- writec('\n');
- } else {
- writel("-->");
- fixtty(&traw);
+ if (i)
+ printw("%s\n", s);
+ else {
+ addstr("-->");
while ((i = readc()) != ' ' && i != '\n');
- fixtty(&noech);
clear();
}
t++;
}
- fixtty(&traw);
return(0);
}
diff --git a/games/backgammon/common_source/back.h b/games/backgammon/common_source/back.h
index 2c78d5b7fe9..ce2151b17c6 100644
--- a/games/backgammon/common_source/back.h
+++ b/games/backgammon/common_source/back.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: back.h,v 1.5 2001/02/18 03:32:52 pjanzen Exp $ */
+/* $OpenBSD: back.h,v 1.6 2001/06/23 23:50:02 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,12 +38,12 @@
#include <sys/types.h>
#include <sys/uio.h>
+#include <curses.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <termios.h>
#include <term.h>
#include <unistd.h>
@@ -80,13 +80,11 @@ extern int pnum; /* color of player:
extern char args[100]; /* args passed to teachgammon and back */
extern int acnt; /* length of args */
extern int aflag; /* flag to ask for rules or instructions */
-extern int bflag; /* flag for automatic board printing */
extern int cflag; /* case conversion flag */
extern int hflag; /* flag for cleaning screen */
extern int mflag; /* backgammon flag */
extern int raflag; /* 'roll again' flag for recovered game */
extern int rflag; /* recovered game flag */
-extern int tflag; /* cursor addressing flag */
extern int rfl; /* saved value of rflag */
extern int iroll; /* special flag for inputting rolls */
extern int board[26]; /* board: negative values are white,
@@ -130,45 +128,34 @@ extern const char *const *Colorptr; /* color of current player,
* capitalized */
extern int colen; /* length of color of current player */
-extern struct termios old, noech, traw;/* original tty status */
-
-extern int curr; /* row position of cursor */
-extern int curc; /* column position of cursor */
extern int begscr; /* 'beginning' of screen
(not including board) */
int addbuf __P((int));
void backone __P((int));
void bsect __P((int, int, int, int));
-void buflush __P((void));
int canhit __P((int, int));
int checkd __P((int));
int checkmove __P((int));
-void clear __P((void));
-void clend __P((void));
-void cline __P((void));
int count __P((void));
-void curmove __P((int, int));
int dotable __P((char, int));
void errexit __P((const char *));
-void fancyc __P((int));
void fboard __P((void));
void fixcol __P((int, int, int, int, int));
void fixpos __P((int, int, int, int, int));
-void fixtty __P((struct termios *));
void getarg __P((int, char **));
-int getcaps __P((const char *));
void getmove __P((void));
void getout __P((int)); /* function to exit backgammon cleanly */
void gwrite __P((void));
void init __P((void));
+void initcurses __P((void));
int last __P((void));
int makmove __P((int));
int movallow __P((void));
void movback __P((int));
+void moveplayers __P((void));
void moverr __P((int));
int movokay __P((int));
-void newpos __P((void));
void nexturn __P((void));
void norec __P((const char *));
void odds __P((int, int, int));
@@ -176,7 +163,6 @@ void proll __P((void));
int quit __P((void));
int readc __P((void));
void recover __P((const char *));
-void refresh __P((void));
void roll __P((void));
int rsetbrd __P((void));
void save __P((int));
@@ -184,8 +170,5 @@ int text __P((const char *const *));
void wrboard __P((void));
void wrbsub __P((void));
void wrhit __P((int));
-void wrint __P((int));
-void writec __P((char));
-void writel __P((const char *));
void wrscore __P((void));
int yorn __P((char));
diff --git a/games/backgammon/common_source/board.c b/games/backgammon/common_source/board.c
index 1c6dff60eec..fa5dfe7c3ca 100644
--- a/games/backgammon/common_source/board.c
+++ b/games/backgammon/common_source/board.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: board.c,v 1.4 2001/02/18 03:32:52 pjanzen Exp $ */
+/* $OpenBSD: board.c,v 1.5 2001/06/23 23:50:03 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)board.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: board.c,v 1.4 2001/02/18 03:32:52 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: board.c,v 1.5 2001/06/23 23:50:03 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -55,15 +55,12 @@ wrboard()
static const char sv[] =
"| | | | \n";
- fixtty(&noech);
clear();
- if (tflag) {
- fboard();
- goto lastline;
- }
- writel("_____________________________________________________\n");
- writel(bl);
+ fboard();
+ goto lastline;
+ addstr("_____________________________________________________\n");
+ addstr(bl);
strcpy(ln, bl);
for (j = 1; j < 50; j += 4) {
k = j / 4 + (j > 24 ? 12 : 13);
@@ -72,7 +69,7 @@ wrboard()
if (j == 21)
j += 4;
}
- writel(ln);
+ addstr(ln);
for (i = 0; i < 5; i++) {
strcpy(ln, sv);
for (j = 1; j < 50; j += 4) {
@@ -102,13 +99,13 @@ wrboard()
}
ln[l++] = '\n';
ln[l] = '\0';
- writel(ln);
+ addstr(ln);
}
strcpy(ln, bl);
ln[25] = 'B';
ln[26] = 'A';
ln[27] = 'R';
- writel(ln);
+ addstr(ln);
strcpy(ln, sv);
for (i = 4; i > -1; i--) {
for (j = 1; j < 50; j += 4) {
@@ -138,7 +135,7 @@ wrboard()
}
ln[l++] = '\n';
ln[l] = '\0';
- writel(ln);
+ addstr(ln);
}
strcpy(ln, bl);
for (j = 1; j < 50; j += 4) {
@@ -149,18 +146,12 @@ wrboard()
if (j == 21)
j += 4;
}
- writel(ln);
- writel("|_______________________|___|_______________________|\n");
+ addstr(ln);
+ addstr("|_______________________|___|_______________________|\n");
lastline:
gwrite();
- if (tflag)
- curmove(18, 0);
- else {
- writec('\n');
- writec('\n');
- }
- fixtty(&traw);
+ move(18, 0);
}
void
diff --git a/games/backgammon/common_source/check.c b/games/backgammon/common_source/check.c
index a5bec6c6396..164c348d7c0 100644
--- a/games/backgammon/common_source/check.c
+++ b/games/backgammon/common_source/check.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check.c,v 1.3 1999/07/31 21:57:40 pjanzen Exp $ */
+/* $OpenBSD: check.c,v 1.4 2001/06/23 23:50:03 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)check.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: check.c,v 1.3 1999/07/31 21:57:40 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: check.c,v 1.4 2001/06/23 23:50:03 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -55,41 +55,26 @@ getmove()
switch (i) {
case -1:
if (movokay(mvlim)) {
- if (tflag)
- curmove(20, 0);
- else
- writec('\n');
+ move(20, 0);
for (i = 0; i < mvlim; i++)
if (h[i])
wrhit(g[i]);
nexturn();
if (*offopp == 15)
cturn *= -2;
- if (tflag && pnum)
- bflag = pnum;
return;
}
case -4:
case 0:
- if (tflag)
- refresh();
+ refresh();
if (i != 0 && i != -4)
break;
- if (tflag)
- curmove(20, 0);
- else
- writec('\n');
- writel(*Colorptr);
+ mvaddstr(20, 0, *Colorptr);
if (i == -4)
- writel(" must make ");
+ addstr(" must make ");
else
- writel(" can only make ");
- writec(mvlim + '0');
- writel(" move");
- if (mvlim > 1)
- writec('s');
- writec('.');
- writec('\n');
+ addstr(" can only make ");
+ printw("%d move%s.\n", mvlim, mvlim > 1 ? "s":"");
break;
case -3:
@@ -97,13 +82,9 @@ getmove()
return;
}
- if (!tflag)
- proll();
- else {
- curmove(cturn == -1 ? 18 : 19, 39);
- cline();
- c = -1;
- }
+ move(cturn == -1 ? 18 : 19, 39);
+ clrtoeol();
+ c = -1;
}
}
@@ -119,39 +100,36 @@ movokay(mv)
for (i = 0; i < mv; i++) {
if (p[i] == g[i]) {
moverr(i);
- curmove(20, 0);
- writel("Attempt to move to same location.\n");
+ mvaddstr(20, 0, "Attempt to move to same location.\n");
return(0);
}
if (cturn * (g[i] - p[i]) < 0) {
moverr(i);
- curmove(20, 0);
- writel("Backwards move.\n");
+ mvaddstr(20, 0, "Backwards move.\n");
return(0);
}
if (abs(board[bar]) && p[i] != bar) {
moverr(i);
- curmove(20, 0);
- writel("Men still on bar.\n");
+ mvaddstr(20, 0, "Men still on bar.\n");
return(0);
}
if ((m = makmove(i))) {
moverr(i);
switch (m) {
case 1:
- writel("Move not rolled.\n");
+ addstr("Move not rolled.\n");
break;
case 2:
- writel("Bad starting position.\n");
+ addstr("Bad starting position.\n");
break;
case 3:
- writel("Destination occupied.\n");
+ addstr("Destination occupied.\n");
break;
case 4:
- writel("Can't remove men yet.\n");
+ addstr("Can't remove men yet.\n");
}
return(0);
}
diff --git a/games/backgammon/common_source/fancy.c b/games/backgammon/common_source/fancy.c
index 315d39dd643..f4a391e35da 100644
--- a/games/backgammon/common_source/fancy.c
+++ b/games/backgammon/common_source/fancy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fancy.c,v 1.9 2000/07/23 21:35:00 pjanzen Exp $ */
+/* $OpenBSD: fancy.c,v 1.10 2001/06/23 23:50:03 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,141 +37,81 @@
#if 0
static char sccsid[] = "@(#)fancy.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: fancy.c,v 1.9 2000/07/23 21:35:00 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: fancy.c,v 1.10 2001/06/23 23:50:03 pjanzen Exp $";
#endif
#endif /* not lint */
+#include <err.h>
#include "back.h"
-char PC; /* padding character */
-char *BC; /* backspace sequence */
-char *CD; /* clear to end of screen sequence */
-char *CE; /* clear to end of line sequence */
-char *CL; /* clear screen sequence */
-char *CM; /* cursor movement instructions */
-char *HO; /* home cursor sequence */
-char *ND; /* forward cursor sequence */
-char *UP; /* up cursor sequence */
-
-int lHO; /* length of HO */
-int lBC; /* length of BC */
-int lND; /* length of ND */
-int lUP; /* length of UP */
-int CO; /* number of columns */
-int LI; /* number of lines */
-int *linect; /* array of lengths of lines on screen
- (the actual screen is not stored) */
-
-/* two letter codes */
-char *tcap[] = {"le", "cd", "ce", "cl", "cm", "ho", "nd", "up", NULL};
-/* corresponding strings */
-char **tstr[] = {&BC, &CD, &CE, &CL, &CM, &HO, &ND, &UP};
-
-int buffnum; /* pointer to output buffer */
-
-char tbuf[1024]; /* buffer for decoded terminfo entries */
-
int oldb[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-
-int oldr;
-int oldw;
-
-/* "real" cursor positions, so it knows when to reposition.
- * These are -1 if curr and curc are accurate */
-int realr;
-int realc;
+int oldr, oldw;
void
fboard()
{
- int i, j, l;
+ int i, j, k, l;
- curmove(0, 0); /* do top line */
+ /* could use box() or wborder() instead of the following */
+ move(0, 0); /* do top line */
for (i = 0; i < 53; i++)
- fancyc('_');
+ addch('_');
- curmove(15, 0); /* do botttom line */
+ move(15, 0); /* do bottom line */
for (i = 0; i < 53; i++)
- fancyc('_');
+ addch('_');
l = 1; /* do vertical lines */
for (i = 52; i > -1; i -= 28) {
- curmove((l == 1 ? 1 : 15), i);
- fancyc('|');
- for (j = 0; j < 14; j++) {
- curmove(curr + l, curc - 1);
- fancyc('|');
- }
+ k = (l == 1 ? 1 : 15);
+ mvaddch(k, i, '|');
+ for (j = 0; j < 14; j++)
+ mvaddch(k += l, i, '|');
if (i == 24)
i += 32;
l = -l; /* alternate directions */
}
- curmove(2, 1); /* label positions 13-18 */
- for (i = 13; i < 18; i++) {
- fancyc('1');
- fancyc((i % 10) + '0');
- curmove(curr, curc + 2);
- }
- fancyc('1');
- fancyc('8');
-
- curmove(2, 29); /* label positions 19-24 */
- fancyc('1');
- fancyc('9');
- for (i = 20; i < 25; i++) {
- curmove(curr, curc + 2);
- fancyc('2');
- fancyc((i % 10) + '0');
- }
-
- curmove(14, 1); /* label positions 12-7 */
- fancyc('1');
- fancyc('2');
- for (i = 11; i > 6; i--) {
- curmove(curr, curc + 2);
- fancyc(i > 9 ? '1' : ' ');
- fancyc((i % 10) + '0');
- }
-
- curmove(14, 30); /* label positions 6-1 */
- fancyc('6');
- for (i = 5; i > 0; i--) {
- curmove(curr, curc + 3);
- fancyc(i + '0');
- }
-
- for (i = 12; i > 6; i--)/* print positions 12-7 */
+ /* label positions */
+ for (i = 13; i < 19; i++)
+ mvprintw(2, 1 + (i - 13) * 4, "%d", i);
+ for (i = 19; i < 25; i++)
+ mvprintw(2, 29 + (i - 19) * 4, "%d", i);
+ for (i = 12; i > 6; i--)
+ mvprintw(14, 1 + (12 - i) * 4, "%2d", i);
+ for (i = 6; i > 0; i--)
+ mvprintw(14, 30 + (6 - i) * 4, "%d", i);
+
+ /* print positions 12-7 */
+ for (i = 12; i > 6; i--)
if (board[i])
bsect(board[i], 13, 1 + 4 * (12 - i), -1);
-
- if (board[0]) /* print red men on bar */
+ /* print red men on bar */
+ if (board[0])
bsect(board[0], 13, 25, -1);
-
- for (i = 6; i > 0; i--) /* print positions 6-1 */
+ /* print positions 6-1 */
+ for (i = 6; i > 0; i--)
if (board[i])
bsect(board[i], 13, 29 + 4 * (6 - i), -1);
-
- l = (off[1] < 0 ? off[1] + 15 : off[1]); /* print white's home */
+ /* print white's home */
+ l = (off[1] < 0 ? off[1] + 15 : off[1]);
bsect(l, 3, 54, 1);
- curmove(8, 25); /* print the word BAR */
- fancyc('B');
- fancyc('A');
- fancyc('R');
+ mvaddstr(8, 25, "BAR");
- for (i = 13; i < 19; i++) /* print positions 13-18 */
+ /* print positions 13-18 */
+ for (i = 13; i < 19; i++)
if (board[i])
bsect(board[i], 3, 1 + 4 * (i - 13), 1);
-
- if (board[25]) /* print white's men on bar */
+ /* print white's men on bar */
+ if (board[25])
bsect(board[25], 3, 25, 1);
-
- for (i = 19; i < 25; i++) /* print positions 19-24 */
+ /* print positions 19-24 */
+ for (i = 19; i < 25; i++)
if (board[i])
bsect(board[i], 3, 29 + 4 * (i - 19), 1);
-
- l = (off[0] < 0 ? off[0] + 15 : off[0]); /* print red's home */
+ /* print red's home */
+ l = (off[0] < 0 ? off[0] + 15 : off[0]);
bsect(-l, 13, 54, -1);
for (i = 0; i < 26; i++)/* save board position for refresh later */
@@ -206,15 +146,15 @@ bsect(b, rpos, cpos, cnext)
pc = (b > 0 ? 'r' : 'w');
if (n < 6 && cpos < 54) /* position cursor at start */
- curmove(rpos, cpos + 1);
+ move(rpos, cpos + 1);
else
- curmove(rpos, cpos);
+ move(rpos, cpos);
for (j = 0; j < 5; j++) { /* print position row by row */
for (k = 0; k < 15; k += 5) /* print men */
if (n > j + k)
- fancyc(pc);
+ addch(pc);
if (j < 4) { /* figure how far to back up for next row */
if (n < 6) { /* stop if none left */
@@ -223,13 +163,12 @@ bsect(b, rpos, cpos, cnext)
bct = 1; /* single column */
} else {
if (n < 11) { /* two columns */
- if (cpos == 54) { /* home pos */
+ if (cpos >= 54) { /* home pos */
if (j + 5 >= n)
bct = 1;
else
bct = 2;
- }
- if (cpos < 54) { /* not home */
+ } else { /* not home */
if (j + 6 >= n)
bct = 1;
else
@@ -242,19 +181,18 @@ bsect(b, rpos, cpos, cnext)
bct = 3;
}
}
- curmove(curr + cnext, curc - bct); /* reposition cursor */
+ getyx(stdscr, rpos, cpos);
+ move(rpos + cnext, cpos - bct);
}
}
}
void
-refresh()
+moveplayers()
{
- int i, r, c;
-
- r = curr; /* save current position */
- c = curc;
+ int i, r, c;
+ getyx(stdscr, r, c);
for (i = 12; i > 6; i--)/* fix positions 12-7 */
if (board[i] != oldb[i]) {
fixpos(oldb[i], board[i], 13, 1 + (12 - i) * 4, -1);
@@ -293,10 +231,10 @@ refresh()
fixpos(oldr, i, 3, 54, 1);
oldr = i;
}
- curmove(r, c); /* return to saved position */
- newpos();
- buflush();
+ move(r, c); /* return to saved position */
+ refresh();
}
+
void
fixpos(old, new, r, c, inc)
@@ -375,339 +313,26 @@ fixcol(r, c, l, ch, inc)
{
int i;
- curmove(r, c);
- fancyc(ch);
+ mvaddch(r, c, ch);
for (i = 1; i < l; i++) {
- curmove(curr + inc, curc - 1);
- fancyc(ch);
+ r += inc;
+ mvaddch(r, c, ch);
}
}
-void
-curmove(r, c)
- int r, c;
-{
- if (curr == r && curc == c)
- return;
- if (realr == -1) {
- realr = curr;
- realc = curc;
- }
- curr = r;
- curc = c;
-}
void
-newpos()
+initcurses()
{
- int r; /* destination row */
- int c; /* destination column */
- int mode = -1; /* mode of movement */
-
- int count = 1000; /* character count */
- int i; /* index */
- int n; /* temporary variable */
- char *m; /* string containing CM movement */
-
- if (realr == -1) /* see if already there */
- return;
-
- r = curr; /* set current and dest. positions */
- c = curc;
- curr = realr;
- curc = realc;
-
- /* double check position */
- if (curr == r && curc == c) {
- realr = realc = -1;
- return;
- }
- if (CM) { /* try CM to get there */
- mode = 0;
- m = (char *)tgoto(CM, c, r);
- count = strlen(m);
- }
- /* try HO and local movement */
- if (HO && (n = r + c * lND + lHO) < count) {
- mode = 1;
- count = n;
- }
- /* try various LF combinations */
- if (r >= curr) {
- /* CR, LF, and ND */
- if ((n = (r - curr) + c * lND + 1) < count) {
- mode = 2;
- count = n;
- }
- /* LF, ND */
- if (c >= curc && (n = (r - curr) + (c - curc) * lND) < count) {
- mode = 3;
- count = n;
- }
- /* LF, BS */
- if (c < curc && (n = (r - curr) + (curc - c) * lBC) < count) {
- mode = 4;
- count = n;
- }
+ initscr();
+ cbreak();
+ noecho();
+ keypad(stdscr, TRUE);
+ nl();
+ clear();
+
+ if ((LINES < 24) || (COLS < 80)) {
+ endwin();
+ errx(1, "screen must be at least 24x80.");
}
- /* try corresponding UP combinations */
- if (r < curr) {
- /* CR, UP, and ND */
- if ((n = (curr - r) * lUP + c * lND + 1) < count) {
- mode = 5;
- count = n;
- }
- /* UP and ND */
- if (c >= curc && (n = (curr - r) * lUP + (c - curc) * lND) < count) {
- mode = 6;
- count = n;
- }
- /* UP and BS */
- if (c < curc && (n = (curr - r) * lUP + (curc - c) * lBC) < count) {
- mode = 7;
- count = n;
- }
- }
- /* space over */
- if (curr == r && c > curc && linect[r] < curc && c - curc < count)
- mode = 8;
-
- switch (mode) {
- case -1: /* error! */
- write(STDERR_FILENO, "\r\nInternal cursor error.\r\n", 26);
- tflag = 0; /* So we don't loop */
- getout(0);
-
- case 0: /* direct cursor motion */
- tputs(m, abs(curr - r), addbuf);
- break;
-
- case 1: /* relative to "home" */
- tputs(HO, r, addbuf);
- for (i = 0; i < r; i++)
- addbuf('\012');
- for (i = 0; i < c; i++)
- tputs(ND, 1, addbuf);
- break;
-
- case 2: /* CR and down and over */
- addbuf('\015');
- for (i = 0; i < r - curr; i++)
- addbuf('\012');
- for (i = 0; i < c; i++)
- tputs(ND, 1, addbuf);
- break;
-
- case 3: /* down and over */
- for (i = 0; i < r - curr; i++)
- addbuf('\012');
- for (i = 0; i < c - curc; i++)
- tputs(ND, 1, addbuf);
- break;
-
- case 4: /* down and back */
- for (i = 0; i < r - curr; i++)
- addbuf('\012');
- for (i = 0; i < curc - c; i++)
- addbuf('\010');
- break;
-
- case 5: /* CR and up and over */
- addbuf('\015');
- for (i = 0; i < curr - r; i++)
- tputs(UP, 1, addbuf);
- for (i = 0; i < c; i++)
- tputs(ND, 1, addbuf);
- break;
-
- case 6: /* up and over */
- for (i = 0; i < curr - r; i++)
- tputs(UP, 1, addbuf);
- for (i = 0; i < c - curc; i++)
- tputs(ND, 1, addbuf);
- break;
-
- case 7: /* up and back */
- for (i = 0; i < curr - r; i++)
- tputs(UP, 1, addbuf);
- for (i = 0; i < curc - c; i++) {
- if (BC)
- tputs(BC, 1, addbuf);
- else
- addbuf('\010');
- }
- break;
-
- case 8: /* safe space */
- for (i = 0; i < c - curc; i++)
- addbuf(' ');
- }
- /* fix positions */
- curr = r;
- curc = c;
- realr = -1;
- realc = -1;
-}
-
-void
-clear()
-{
- int i;
-
- /* double space if can't clear */
- if (CL == 0) {
- writel("\n\n");
- return;
- }
- curr = curc = 0; /* fix position markers */
- realr = realc = -1;
- for (i = 0; i < 24; i++)/* clear line counts */
- linect[i] = -1;
- buffnum = -1; /* ignore leftover buffer contents */
- tputs(CL, LI, addbuf); /* put CL in buffer */
-}
-
-void
-fancyc(c)
- int c; /* character to output */
-{
- int sp; /* counts spaces in a tab */
-
- if (c == '\007') { /* bells go in blindly */
- addbuf(c);
- return;
- }
- /* process tabs, use spaces if the the tab should be erasing things,
- * otherwise use cursor movement routines. Note this does not use
- * hardware tabs at all. */
- if (c == '\t') {
- sp = (curc + 8) & (~7); /* compute spaces */
- /* check line length */
- if (linect[curr] >= curc || sp < 4) {
- for (; sp > curc; sp--)
- addbuf(' ');
- curc = sp; /* fix curc */
- } else
- curmove(curr, sp);
- return;
- }
- if (c == '\n') {
- cline();
- if (curr == LI - 1)
- curmove(begscr, 0);
- else
- curmove(curr + 1, 0);
- return;
- }
- /* ignore any other control chars */
- if (c < ' ')
- return;
-
- /* if an erasing space or non-space, just add it to buffer. Otherwise
- * use cursor movement routine, so that multiple spaces will be grouped
- * together */
- if (c > ' ' || linect[curr] >= curc) {
- newpos(); /* make sure position correct */
- addbuf(c); /* add character to buffer */
- /* fix line length */
- if (c == ' ' && linect[curr] == curc)
- linect[curr]--;
- else if (linect[curr] < curc)
- linect[curr] = curc;
- curc++; /* fix curc */
- } else
- /* use cursor movement routine */
- curmove(curr, curc + 1);
-}
-
-void
-clend()
-{
- int i;
-
-/* *** Why does this code fail? ***
- * if (CD) {
- * tputs(CD, (LI - curr), addbuf);
- * for (i = curr; i < LI; i++)
- * linect[i] = -1;
- * return;
- * }
- */
- curmove(i = curr, 0);
- cline();
- while (curr < LI - 1) {
- curmove(curr + 1, 0);
- if (linect[curr] > -1)
- cline();
- }
- curmove(i, 0);
-}
-
-void
-cline()
-{
- int c;
-
- if (curc > linect[curr])
- return;
- newpos();
- if (CE) {
- tputs(CE, 1, addbuf);
- linect[curr] = curc - 1;
- } else {
- c = curc - 1;
- while (linect[curr] > c) {
- addbuf(' ');
- curc++;
- linect[curr]--;
- }
- curmove(curr, c + 1);
- }
-}
-
-int
-getcaps(s)
- const char *s;
-{
- char **code; /* two letter code */
- char ***cap; /* pointer to cap string */
- char *bufp; /* pointer to cap buffer */
- char tentry[1024]; /* temporary uncoded caps buffer */
-
- tgetent(tentry, s); /* get uncoded terminfo entry */
-
- LI = tgetnum("li"); /* get number of lines */
- if (LI == -1)
- LI = 12;
- CO = tgetnum("co"); /* get number of columns */
- if (CO == -1)
- CO = 65;
-
- bufp = tbuf; /* get padding character */
- tgetstr("pc", &bufp);
- if (bufp != tbuf)
- PC = *tbuf;
- else
- PC = 0;
-
- bufp = tbuf; /* get string entries */
- cap = tstr;
- for (code = tcap; *code; code++)
- **cap++ = (char *)tgetstr(*code, &bufp);
-
- /* get pertinent lengths */
- if (HO)
- lHO = strlen(HO);
- if (BC)
- lBC = strlen(BC);
- else
- lBC = 1;
- if (UP)
- lUP = strlen(UP);
- if (ND)
- lND = strlen(ND);
- linect = (int *)calloc(LI + 1, sizeof(int));
- if (LI < 24 || CO < 72 || !(CL && UP && ND))
- return(0);
- return(1);
}
diff --git a/games/backgammon/common_source/init.c b/games/backgammon/common_source/init.c
index 7de84135f24..88f2dea2fd5 100644
--- a/games/backgammon/common_source/init.c
+++ b/games/backgammon/common_source/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.4 2001/02/18 03:32:52 pjanzen Exp $ */
+/* $OpenBSD: init.c,v 1.5 2001/06/23 23:50:03 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,12 +37,10 @@
#if 0
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: init.c,v 1.4 2001/02/18 03:32:52 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: init.c,v 1.5 2001/06/23 23:50:03 pjanzen Exp $";
#endif
#endif /* not lint */
-#include <termios.h>
-
/*
* variable initialization.
*/
@@ -63,13 +61,11 @@ int pnum = 2; /* color of player:
2 = not yet init'ed */
int acnt = 0; /* length of args */
int aflag = 1; /* flag to ask for rules or instructions */
-int bflag = 0; /* flag for automatic board printing */
int cflag = 0; /* case conversion flag */
int hflag = 1; /* flag for cleaning screen */
int mflag = 0; /* backgammon flag */
int raflag = 0; /* 'roll again' flag for recovered game */
int rflag = 0; /* recovered game flag */
-int tflag = 0; /* cursor addressing flag */
int iroll = 0; /* special flag for inputting rolls */
int rfl = 0;
@@ -89,8 +85,6 @@ int board[26];
char cin[100];
int colen;
int cturn;
-int curc;
-int curr;
int d0;
int dice[2];
int dlast;
@@ -107,4 +101,3 @@ int p[5];
int rscore;
int table[6][6];
int wscore;
-struct termios old, noech, traw;
diff --git a/games/backgammon/common_source/one.c b/games/backgammon/common_source/one.c
index a30b3e0f29d..a61ff36e7b7 100644
--- a/games/backgammon/common_source/one.c
+++ b/games/backgammon/common_source/one.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: one.c,v 1.2 1998/03/19 11:13:23 pjanzen Exp $ */
+/* $OpenBSD: one.c,v 1.3 2001/06/23 23:50:03 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)one.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: one.c,v 1.2 1998/03/19 11:13:23 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: one.c,v 1.3 2001/06/23 23:50:03 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -103,19 +103,13 @@ moverr(i)
{
int j;
- if (tflag)
- curmove(20, 0);
- else
- writec('\n');
- writel("Error: ");
+ mvprintw(20, 0, "Error: ");
for (j = 0; j <= i; j++) {
- wrint(p[j]);
- writec('-');
- wrint(g[j]);
+ printw("%d-%d", p[j], g[j]);
if (j < i)
- writec(',');
+ addch(',');
}
- writel("... ");
+ addstr("... ");
movback(i);
}
diff --git a/games/backgammon/common_source/save.c b/games/backgammon/common_source/save.c
index 7cf1dbdbe03..e1ddcf1c06b 100644
--- a/games/backgammon/common_source/save.c
+++ b/games/backgammon/common_source/save.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: save.c,v 1.6 2001/03/30 04:41:34 pjanzen Exp $ */
+/* $OpenBSD: save.c,v 1.7 2001/06/23 23:50:04 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,11 +37,12 @@
#if 0
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: save.c,v 1.6 2001/03/30 04:41:34 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: save.c,v 1.7 2001/06/23 23:50:04 pjanzen Exp $";
#endif
#endif /* not lint */
#include <sys/param.h>
+#include <ctype.h>
#include <errno.h>
#include "back.h"
@@ -63,37 +64,37 @@ save(n)
int fdesc;
char *fs;
char fname[MAXPATHLEN];
+ int r, c, i;
if (n) {
- if (tflag) {
- curmove(20, 0);
- clend();
- } else
- writec('\n');
- writel(confirm);
+ move(20, 0);
+ clrtobot();
+ addstr(confirm);
if (!yorn(0))
return;
}
cflag = 1;
for (;;) {
- writel(prompt);
+ addstr(prompt);
fs = fname;
- while ((*fs = readc()) != '\n') {
- if (*fs == old.c_cc[VERASE]) {
+ while ((i = readc()) != '\n') {
+ if (i == KEY_BACKSPACE || i == 0177) {
if (fs > fname) {
fs--;
- if (tflag)
- curmove(curr, curc - 1);
- else
- writec(*fs);
+ getyx(stdscr, r, c);
+ move(r, c - 1);
} else
- writec('\007');
+ beep();
continue;
}
- if (fs - fname < MAXPATHLEN - 1)
- writec(*fs++);
- else
- writec('\007');
+ if (fs - fname < MAXPATHLEN - 1) {
+ if (isascii(i)) {
+ *fs = i;
+ addch(*fs++);
+ } else
+ beep();
+ } else
+ beep();
}
*fs = '\0';
if ((fdesc = open(fname, O_RDWR)) == -1 && errno == ENOENT) {
@@ -101,14 +102,9 @@ save(n)
break;
}
if (fdesc != -1) {
- if (tflag) {
- curmove(18, 0);
- clend();
- } else
- writec('\n');
- writel(exist1);
- writel(fname);
- writel(exist2);
+ move(18, 0);
+ clrtobot();
+ printw("%s%s%s", exist1, fname, exist2);
cflag = 0;
close(fdesc);
if (yorn(0)) {
@@ -120,9 +116,7 @@ save(n)
continue;
}
}
- writel(cantuse);
- writel(fname);
- writel(".\n");
+ printw("%s%s.\n", cantuse, fname);
close(fdesc);
cflag = 1;
}
@@ -138,15 +132,9 @@ save(n)
write(fdesc, &gvalue, sizeof(gvalue));
write(fdesc, &raflag, sizeof(raflag));
close(fdesc);
- if (tflag)
- curmove(18, 0);
- writel(saved);
- writel(fname);
- writel(type);
- writel(fname);
- writel(rec);
- if (tflag)
- clend();
+ move(18, 0);
+ printw("%s%s%s%s%s", saved, fname, type, fname, rec);
+ clrtobot();
getout(0);
}
@@ -179,10 +167,9 @@ norec(s)
{
const char *c;
- tflag = 0;
- writel(cantrec);
+ addstr(cantrec);
c = s;
while (*c != '\0')
- writec(*c++);
+ addch(*c++);
getout(0);
}
diff --git a/games/backgammon/common_source/subs.c b/games/backgammon/common_source/subs.c
index c891a58c3e2..c6557e00662 100644
--- a/games/backgammon/common_source/subs.c
+++ b/games/backgammon/common_source/subs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subs.c,v 1.10 2000/07/23 21:35:00 pjanzen Exp $ */
+/* $OpenBSD: subs.c,v 1.11 2001/06/23 23:50:04 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)subs.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: subs.c,v 1.10 2000/07/23 21:35:00 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: subs.c,v 1.11 2001/06/23 23:50:04 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -51,14 +51,10 @@ static const char plwhite[] = "Player is white, computer is red.";
static const char nocomp[] = "(No computer play.)";
const char *const descr[] = {
- "Usage: backgammon [-] [-nrwb] [-p [r|w|b]] [-t <term>] [-s <file>]\n",
+ "Usage: backgammon [-] [-nrwb] [-s <file>]\n",
"\t-h\tget this list\n\t-n\tdon't ask for rules or instructions",
"\t-r\tplayer is red (implies n)\n\t-w\tplayer is white (implies n)",
"\t-b\ttwo players, red and white (implies n)",
- "\t-p r\tprint the board before red's turn",
- "\t-p w\tprint the board before white's turn",
- "\t-p b\tprint the board before all turns",
- "\t-t term\tterminal is type term",
"\t-s file\trecover previously saved game from file",
0
};
@@ -73,43 +69,14 @@ errexit(s)
}
int
-addbuf(c)
- int c;
-{
- buffnum++;
- if (buffnum == BUFSIZ) {
- if (write(STDOUT_FILENO, outbuff, BUFSIZ) != BUFSIZ)
- errexit("addbuf (write):");
- buffnum = 0;
- }
- outbuff[buffnum] = c;
- return(0);
-}
-
-void
-buflush()
-{
- if (buffnum < 0)
- return;
- buffnum++;
- if (write(STDOUT_FILENO, outbuff, buffnum) != buffnum)
- errexit("buflush (write):");
- buffnum = -1;
-}
-
-int
readc()
{
- char c;
+ int c;
- if (tflag) {
- cline();
- newpos();
- }
- buflush();
- if (read(0, &c, 1) != 1)
- errexit("readc");
- if (c == '\004') /* ^D */
+ clrtoeol();
+ refresh();
+ c = getch();
+ if (c == '\004' || c == ERR) /* ^D or failure */
getout(0);
if (c == '\033' || c == '\015')
return('\n');
@@ -118,75 +85,21 @@ readc()
if (c == '\014')
return('R');
if (c >= 'a' && c <= 'z')
- return(c & 0137);
+ return(c & 0137); /* upper case */
return(c);
}
void
-writec(c)
- char c;
-{
- if (tflag)
- fancyc(c);
- else
- addbuf(c);
-}
-
-void
-writel(l)
- const char *l;
-{
-#ifdef DEBUG
- const char *s;
-
- if (trace == NULL)
- trace = fopen("bgtrace", "w");
-
- fprintf(trace, "writel: \"");
- for (s = l; *s; s++) {
- if (*s < ' ' || *s == '\177')
- fprintf(trace, "^%c", (*s)^0100);
- else
- putc(*s, trace);
- }
- fprintf(trace, "\"\n");
- fflush(trace);
-#endif
-
- while (*l)
- writec(*l++);
-}
-
-void
proll()
{
if (d0)
swap;
if (cturn == 1)
- writel("Red's roll: ");
+ printw("Red's roll: ");
else
- writel("White's roll: ");
- writec(D0 + '0');
- writec('\040');
- writec(D1 + '0');
- if (tflag)
- cline();
-}
-
-void
-wrint(n)
- int n;
-{
- int i, j, t;
-
- for (i = 4; i > 0; i--) {
- t = 1;
- for (j = 0; j < i; j++)
- t *= 10;
- if (n > t - 1)
- writec((n / t) % 10 + '0');
- }
- writec(n % 10 + '0');
+ printw("White's roll: ");
+ printw("%d,%d", D0, D1);
+ clrtoeol();
}
void
@@ -194,54 +107,44 @@ gwrite()
{
int r, c;
- if (tflag) {
- r = curr;
- c = curc;
- curmove(16, 0);
- }
+ getyx(stdscr, r, c);
+ move(16, 0);
if (gvalue > 1) {
- writel("Game value: ");
- wrint(gvalue);
- writel(". ");
+ printw("Game value: %d. ", gvalue);
if (dlast == -1)
- writel(color[0]);
+ addstr(color[0]);
else
- writel(color[1]);
- writel(" doubled last.");
+ addstr(color[1]);
+ addstr(" doubled last.");
} else {
switch (pnum) {
case -1: /* player is red */
- writel(plred);
+ addstr(plred);
break;
case 0: /* player is both colors */
- writel(nocomp);
+ addstr(nocomp);
break;
case 1: /* player is white */
- writel(plwhite);
+ addstr(plwhite);
}
}
if (rscore || wscore) {
- writel(" ");
+ addstr(" ");
wrscore();
}
- if (tflag) {
- cline();
- curmove(r, c);
- }
+ clrtoeol();
+ move(r, c);
}
int
quit()
{
- if (tflag) {
- curmove(20, 0);
- clend();
- } else
- writec('\n');
- writel("Are you sure you want to quit?");
+ move(20, 0);
+ clrtobot();
+ addstr("Are you sure you want to quit?");
if (yorn(0)) {
if (rfl) {
- writel("Would you like to save this game?");
+ addstr("Would you like to save this game?");
if (yorn(0))
save(0);
}
@@ -263,22 +166,19 @@ yorn(special)
if (special && c == special)
return(2);
if (i) {
- if (special) {
- writel(" (Y, N, or ");
- writec(special);
- writec(')');
- } else
- writel(" (Y or N)");
+ if (special)
+ printw(" (Y, N, or %c)", special);
+ else
+ printw(" (Y or N)");
i = 0;
} else
- writec('\007');
+ beep();
}
if (c == 'Y')
- writel(" Yes.\n");
+ addstr(" Yes.\n");
else
- writel(" No.\n");
- if (tflag)
- buflush();
+ addstr(" No.\n");
+ refresh();
return(c == 'Y');
}
@@ -286,10 +186,7 @@ void
wrhit(i)
int i;
{
- writel("Blot hit on ");
- wrint(i);
- writec('.');
- writec('\n');
+ printw("Blot hit on %d.\n", i);
}
void
@@ -350,26 +247,10 @@ getarg(argc,argv)
args[acnt++] = 'w';
break;
- case 't': /* use spec'd term from terminfo database */
- tflag = getcaps(optarg);
- break;
-
case 's': /* restore saved game */
recover(optarg);
break;
- case 'p': /* print board after move */
- switch(optarg[0]) {
- case 'r': bflag = 1;
- break;
- case 'w': bflag = -1;
- break;
- case 'b':
- default: bflag = 0;
- break;
- }
- break;
-
default: /* print cmdline options */
case 'h':
for (j = 0; descr[j] != NULL; j++)
@@ -401,43 +282,19 @@ init()
void
wrscore()
{
- writel("Score: ");
- writel(color[1]);
- writec(' ');
- wrint(rscore);
- writel(", ");
- writel(color[0]);
- writec(' ');
- wrint(wscore);
+ printw("Score: %s %d, %s %d", color[1], rscore, color[0], wscore);
}
-void
-fixtty(t)
- struct termios *t;
-{
- if (tflag)
- newpos();
- buflush();
- if (tcsetattr(STDIN_FILENO, TCSADRAIN, t) < 0)
- errexit("fixtty");
-}
void
getout(dummy)
int dummy;
{
/* go to bottom of screen */
- if (tflag) {
- curmove(23, 0);
- cline();
- newpos();
- } else
- writec('\n');
-
- /* fix terminal status; avoid calling fixtty() to avoid loop */
- if (buffnum >= 0)
- write(STDOUT_FILENO, outbuff, buffnum + 1);
- tcsetattr(STDIN_FILENO, TCSADRAIN, &old);
+ move(23, 0);
+ clrtoeol();
+
+ endwin();
exit(0);
}
@@ -449,40 +306,27 @@ roll()
int col;
if (iroll) {
- if (tflag) {
- row = curr;
- col = curc;
- curmove(17, 0);
- } else
- writec('\n');
- writel("ROLL: ");
+ getyx(stdscr, row, col);
+ mvprintw(17, 0, "ROLL: ");
c = readc();
if (c != '\n') {
while (c < '1' || c > '6')
c = readc();
D0 = c - '0';
- writec(' ');
- writec(c);
+ printw(" %c", c);
c = readc();
while (c < '1' || c > '6')
c = readc();
D1 = c - '0';
- writec(' ');
- writec(c);
- if (tflag) {
- curmove(17, 0);
- cline();
- curmove(row, col);
- } else
- writec('\n');
+ printw(" %c", c);
+ move(17, 0);
+ clrtoeol();
+ move(row, col);
return;
}
- if (tflag) {
- curmove(17, 0);
- cline();
- curmove(row, col);
- } else
- writec('\n');
+ move(17, 0);
+ clrtoeol();
+ move(row, col);
}
D0 = rnum(6) + 1;
D1 = rnum(6) + 1;
diff --git a/games/backgammon/common_source/table.c b/games/backgammon/common_source/table.c
index 98601bd3231..3d9addc8d31 100644
--- a/games/backgammon/common_source/table.c
+++ b/games/backgammon/common_source/table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.c,v 1.3 1999/07/31 21:57:41 pjanzen Exp $ */
+/* $OpenBSD: table.c,v 1.4 2001/06/23 23:50:04 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,10 +37,11 @@
#if 0
static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: table.c,v 1.3 1999/07/31 21:57:41 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: table.c,v 1.4 2001/06/23 23:50:04 pjanzen Exp $";
#endif
#endif /* not lint */
+#include <ctype.h>
#include "back.h"
const char *const help2[] = {
@@ -84,17 +85,14 @@ int
checkmove(ist)
int ist;
{
+ int curr, curc;
int j, n;
- char c;
+ int c;
domove:
- if (ist == 0) {
- if (tflag)
- curmove(curr, 32);
- else
- writel("\t\t");
- writel("Move: ");
- }
+ getyx(stdscr, curr, curc);
+ if (ist == 0)
+ mvprintw(curr, 32, "Move: ");
ist = mvl = ncin = 0;
for (j = 0; j < 5; j++)
p[j] = g[j] = -1;
@@ -105,61 +103,40 @@ dochar:
if (c == 'S') {
raflag = 0;
save(1);
- if (tflag) {
- curmove(cturn == -1 ? 18 : 19, 39);
- ist = -1;
- goto domove;
- } else {
- proll();
- ist = 0;
- goto domove;
- }
+ move(cturn == -1 ? 18 : 19, 39);
+ ist = -1;
+ goto domove;
}
- if (c == old.c_cc[VERASE] && ncin > 0) {
- if (tflag)
- curmove(curr, curc - 1);
- else {
- if (old.c_cc[VERASE] == '\010')
- writel("\010 \010");
- else
- writec(cin[ncin - 1]);
- }
+ if ((c == KEY_BACKSPACE || c == 0177) && ncin > 0) {
+ getyx(stdscr, curr, curc);
+ move(curr, curc - 1);
ncin--;
n = rsetbrd();
if (n == 0) {
n = -1;
- if (tflag)
- refresh();
+ refresh();
}
if ((ist = n) > 0)
goto dochar;
goto domove;
}
- if (c == old.c_cc[VKILL] && ncin > 0) {
- if (tflag) {
- refresh();
- curmove(curr, 39);
- ist = -1;
- goto domove;
- } else if (old.c_cc[VERASE] == '\010') {
- for (j = 0; j < ncin; j++)
- writel("\010 \010");
- ist = -1;
- goto domove;
- } else {
- writec('\\');
- writec('\n');
- proll();
- ist = 0;
- goto domove;
- }
+ if (c == KEY_DL && ncin > 0) {
+ refresh();
+ getyx(stdscr, curr, curc);
+ move(curr, 39);
+ ist = -1;
+ goto domove;
+ }
+ if (!isascii(c)) {
+ beep();
+ goto domove;
}
n = dotable(c, ist);
if (n >= 0) {
cin[ncin++] = c;
if (n > 2)
- if ((!tflag) || c != '\n')
- writec(c);
+ if (c != '\n')
+ addch(c);
ist = n;
if (n)
goto dochar;
@@ -171,28 +148,17 @@ dochar:
if (n == -1 && mvl < mvlim-1)
return(-4);
if (n == -6) {
- if (!tflag) {
- if (movokay(mvl + 1)) {
- wrboard();
- movback(mvl + 1);
- }
- proll();
- writel("\t\tMove: ");
- for (j = 0; j < ncin;)
- writec(cin[j++]);
- } else {
- if (movokay(mvl + 1)) {
- refresh();
- movback(mvl + 1);
- } else
- curmove(cturn == -1 ? 18 : 19, ncin + 39);
- }
+ if (movokay(mvl + 1)) {
+ moveplayers();
+ movback(mvl + 1);
+ } else
+ move(cturn == -1 ? 18 : 19, ncin + 39);
ist = n = rsetbrd();
goto dochar;
}
if (n != -5)
return(n);
- writec('\007');
+ beep();
goto dochar;
}
@@ -211,12 +177,9 @@ dotable(c, i)
switch (atmata[i].fcode) {
case 1:
wrboard();
- if (tflag) {
- curmove(cturn == -1 ? 18 : 19, 0);
- proll();
- writel("\t\t");
- } else
- proll();
+ move(cturn == -1 ? 18 : 19, 0);
+ proll();
+ addstr("\t\t");
break;
case 2:
@@ -258,18 +221,9 @@ dotable(c, i)
break;
case 7:
- if (tflag)
- curmove(20, 0);
- else
- writec('\n');
+ move(20, 0);
text(help2);
- if (tflag) {
- curmove(cturn == -1 ? 18 : 19, 39);
- } else {
- writec('\n');
- proll();
- writel("\t\tMove: ");
- }
+ move(cturn == -1 ? 18 : 19, 39);
break;
case 8:
diff --git a/games/backgammon/teachgammon/teach.c b/games/backgammon/teachgammon/teach.c
index be026a0a1ed..c0158d4c3ed 100644
--- a/games/backgammon/teachgammon/teach.c
+++ b/games/backgammon/teachgammon/teach.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: teach.c,v 1.8 2001/03/08 21:18:32 deraadt Exp $ */
+/* $OpenBSD: teach.c,v 1.9 2001/06/23 23:50:05 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -43,10 +43,11 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)teach.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: teach.c,v 1.8 2001/03/08 21:18:32 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: teach.c,v 1.9 2001/06/23 23:50:05 pjanzen Exp $";
#endif
#endif /* not lint */
+#include <err.h>
#include "back.h"
#include "tutor.h"
@@ -77,20 +78,7 @@ main(argc, argv)
setgid(getgid());
signal(SIGINT, getout);
- if (tcgetattr(0, &old) == -1) /* get old tty mode */
- errexit("teachgammon(gtty)");
- noech = old;
- noech.c_lflag &= ~ECHO;
- traw = noech;
- traw.c_lflag &= ~ICANON; /* set up modes */
- ospeed = cfgetospeed(&old); /* for termlib */
- tflag = getcaps(getenv("TERM"));
- getarg(argc, argv);
- if (tflag) {
- noech.c_oflag &= ~(ONLCR | OXTABS);
- traw.c_oflag &= ~(ONLCR | OXTABS);
- clear();
- }
+ initcurses();
text(hello);
text(list);
i = text(contin);
@@ -149,12 +137,8 @@ main(argc, argv)
void
leave()
{
- if (tflag)
- clear();
- else
- writec('\n');
- fixtty(&old);
+ clear();
+ endwin();
execl(EXEC, "backgammon", "-n", args, 0);
- writel("Help! Backgammon program is missing\007!!\n");
- exit(1);
+ errx(1, "help! Backgammon program is missing!!");
}
diff --git a/games/backgammon/teachgammon/ttext1.c b/games/backgammon/teachgammon/ttext1.c
index 4df56854144..d84af8c19ef 100644
--- a/games/backgammon/teachgammon/ttext1.c
+++ b/games/backgammon/teachgammon/ttext1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttext1.c,v 1.3 1999/07/31 21:57:41 pjanzen Exp $ */
+/* $OpenBSD: ttext1.c,v 1.4 2001/06/23 23:50:05 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)ttext1.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: ttext1.c,v 1.3 1999/07/31 21:57:41 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: ttext1.c,v 1.4 2001/06/23 23:50:05 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -95,7 +95,7 @@ const char *const intro2[] = {
"\n Although they are not shown on the board, the players' homes are",
"located just to the right of the board. A player's men are placed",
"there when they are removed from the board. The board you just",
- "saw was in it's initial position: all games start with the board",
+ "saw was in its initial position: all games start with the board",
"looking like this. Notice that red's pieces are represented by",
"the letter `r' and white's pieces are represented by the letter",
"`w'. A position may have zero or more pieces on it: for example,",
diff --git a/games/backgammon/teachgammon/ttext2.c b/games/backgammon/teachgammon/ttext2.c
index 40769d0fc30..db1c29897fa 100644
--- a/games/backgammon/teachgammon/ttext2.c
+++ b/games/backgammon/teachgammon/ttext2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttext2.c,v 1.4 2001/02/18 03:32:52 pjanzen Exp $ */
+/* $OpenBSD: ttext2.c,v 1.5 2001/06/23 23:50:05 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)ttext2.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: ttext2.c,v 1.4 2001/02/18 03:32:52 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: ttext2.c,v 1.5 2001/06/23 23:50:05 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -135,28 +135,22 @@ text(txt)
const char *c;
int i;
- fixtty(&noech);
begin = txt;
while (*txt) {
a = *(txt++);
if (*a != '\0') {
c = a;
for (i = 0; *(c++) != '\0'; i--);
- writel(a);
- writec('\n');
+ printw("%s\n", a);
} else {
- fixtty(&traw);
- writel(prompt);
+ addstr(prompt);
/* if begscr is set we're past the rules screens */
if (!begscr) {
for (;;) {
if ((b = readc()) == '?') {
- if (tflag)
- clear();
- else
- writec('\n');
+ clear();
text(list);
- writel(prompt);
+ addstr(prompt);
continue;
}
i = 0;
@@ -168,7 +162,7 @@ text(txt)
i++;
}
if (i == 11)
- writec('\007');
+ beep();
else
break;
}
@@ -176,22 +170,16 @@ text(txt)
b = readc();
i = 0;
}
- if (tflag) {
- if (begscr) {
- curmove(18, 0);
- clend();
- } else
- clear();
+ if (begscr) {
+ move(18, 0);
+ clrtobot();
} else
- writec('\n');
+ clear();
if (i)
return(i);
- fixtty(&noech);
- if (tflag)
- curmove(curr, 0);
+ /* move to start of current line? */
begin = txt;
}
}
- fixtty(&traw);
return(0);
}
diff --git a/games/backgammon/teachgammon/tutor.c b/games/backgammon/teachgammon/tutor.c
index 885f7e6402b..0808ef006e5 100644
--- a/games/backgammon/teachgammon/tutor.c
+++ b/games/backgammon/teachgammon/tutor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tutor.c,v 1.3 1999/07/31 21:57:41 pjanzen Exp $ */
+/* $OpenBSD: tutor.c,v 1.4 2001/06/23 23:50:06 pjanzen Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)tutor.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: tutor.c,v 1.3 1999/07/31 21:57:41 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: tutor.c,v 1.4 2001/06/23 23:50:06 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -70,8 +70,7 @@ tutor()
while (1) {
if (!brdeq(test[i].brd, board)) {
wrongans++;
- if (tflag && curr == 23)
- curmove(18, 0);
+ move(18, 0);
if (wrongans >= 3) {
wrongans = 0;
text(*test[i].ans);
@@ -84,23 +83,20 @@ tutor()
for (j = 0; j < 19; j++)
k += (board[j] > 0 ? board[j] : 0);
*offopp = k - 30; /* -15 at start */
- if (tflag) {
- refresh();
- clrest();
- }
+ moveplayers();
+ clrest();
} else {
- writel(better);
+ addstr(better);
nexturn();
movback(mvlim);
- if (tflag) {
- refresh();
- clrest();
- }
- if ((!tflag) || curr == 19) {
+ moveplayers();
+ clrest();
+ getyx(stdscr, j, k);
+ if (j == 19) {
proll();
- writec('\t');
+ addch('\t');
} else
- curmove(curr > 19 ? curr - 2 : curr + 4, 25);
+ move(j > 19 ? j - 2 : j + 4, 25);
getmove();
if (cturn == 0)
leave();
@@ -108,13 +104,9 @@ tutor()
}
} else
wrongans = 0;
- if (tflag)
- curmove(18, 0);
+ move(18, 0);
text(*test[i].com);
- if (!tflag)
- writec('\n');
- else
- curmove(19, 0);
+ move(19, 0);
if (i == maxmoves)
break;
D0 = test[i].roll1;
@@ -131,9 +123,8 @@ tutor()
if (mvlim)
for (j = 0; j < mvlim; j++)
if (makmove(j))
- writel("AARGH!!!\n");
- if (tflag)
- refresh();
+ addstr("AARGH!!!\n");
+ moveplayers();
nexturn();
D0 = test[i].new1;
D1 = test[i].new2;
@@ -141,13 +132,11 @@ tutor()
i++;
mvlim = movallow();
if (mvlim) {
- if (tflag)
- clrest();
+ clrest();
proll();
- writec('\t');
+ addch('\t');
getmove();
- if (tflag)
- refresh();
+ moveplayers();
if (cturn == 0)
leave();
}
@@ -160,13 +149,12 @@ clrest()
{
int r, c, j;
- r = curr;
- c = curc;
+ getyx(stdscr, r, c);
for (j = r + 1; j < 24; j++) {
- curmove(j, 0);
- cline();
+ move(j, 0);
+ clrtoeol();
}
- curmove(r, c);
+ move(r, c);
}
int