]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.termcap.c
1 /* $NetBSD: hack.termcap.c,v 1.11 2001/11/02 18:27:00 christos Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.termcap.c,v 1.11 2001/11/02 18:27:00 christos Exp $");
19 #include "def.flag.h" /* for flags.nonull */
21 static struct tinfo
*info
;
22 static char *HO
, *CL
, *CE
, *UP
, *CM
, *ND
, *XD
, *BC
, *SO
, *SE
, *TI
, *TE
;
25 static char PC
= '\0';
26 static char BC_char
= '\b'; /* if bc is not set use this */
27 char *CD
; /* tested in pri.c: docorner() */
28 int CO
, LI
; /* used in pri.c and whatis.c */
37 if (!(term
= getenv("TERM")))
38 error("Can't get TERM.");
39 if (!strncmp(term
, "5620", 4))
40 flags
.nonull
= 1; /* this should be a termcap flag */
41 if (t_getent(&info
, term
) < 1)
42 error("Unknown terminal type: %s.", term
);
43 if ((pc
= t_agetstr(info
, "pc")) != NULL
)
45 if (!(BC
= t_agetstr(info
, "bc"))) {
46 if (!t_getflag(info
, "bs"))
47 error("Terminal must backspace.");
50 HO
= t_agetstr(info
, "ho");
51 CO
= t_getnum(info
, "co");
52 LI
= t_getnum(info
, "li");
53 if (CO
< COLNO
|| LI
< ROWNO
+ 2)
55 if (!(CL
= t_agetstr(info
, "cl")))
56 error("Hack needs CL.");
57 ND
= t_agetstr(info
, "nd");
58 if (t_getflag(info
, "os"))
59 error("Hack can't have OS.");
60 CE
= t_agetstr(info
, "ce");
61 UP
= t_agetstr(info
, "up");
63 * It seems that xd is no longer supported, and we should use a
64 * linefeed instead; unfortunately this requires resetting CRMOD, and
65 * many output routines will have to be modified slightly. Let's
66 * leave that till the next release.
68 XD
= t_agetstr(info
, "xd");
69 /* not: XD = t_agetstr(info, "do"); */
70 if (!(CM
= t_agetstr(info
, "cm"))) {
72 error("Hack needs CM or UP or HO.");
73 printf("Playing hack on terminals without cm is suspect...\n");
76 SO
= t_agetstr(info
, "so");
77 SE
= t_agetstr(info
, "se");
78 SG
= t_getnum(info
, "sg"); /* -1: not fnd; else # of spaces left by so */
79 if (!SO
|| !SE
|| (SG
> 0))
81 CD
= t_agetstr(info
, "cd");
82 set_whole_screen(); /* uses LI and CD */
99 /* Cursor movements */
102 int x
, y
; /* not xchar: perhaps xchar is unsigned and
103 * curx-x would be unsigned as well */
106 if (y
== cury
&& x
== curx
)
108 if (!ND
&& (curx
!= x
|| x
<= 3)) { /* Extremely primitive */
109 cmov(x
, y
); /* bunker!wtm */
112 if (abs(cury
- y
) <= 3 && abs(curx
- x
) <= 3)
114 else if ((x
<= 3 && abs(cury
- y
) <= 3) || (!CM
&& x
< abs(curx
- x
))) {
115 (void) putchar('\r');
130 while (cury
> y
) { /* Go up. */
139 } /* else impossible("..."); */
140 } else if (cury
< y
) {
156 if (curx
< x
) { /* Go to the right. */
160 /* should instead print what is there already */
165 } else if (curx
> x
) {
166 while (curx
> x
) { /* Go to the left. */
179 if (t_goto(info
, CM
, x
- 1, y
- 1, buf
, 255) >= 0) {
190 return (fputc(c
, stdout
));
205 else { /* no-CE fix - free after Harold Rynes */
207 * this looks terrible, especially on a slow terminal but is
208 * better than nothing
210 int cx
= curx
, cy
= cury
;
212 while (curx
< COLNO
) {
234 else if ((CM
) && (t_goto(info
, CM
, 0, 0, buf
, 255) >= 0))
237 curs(1, 1); /* using UP ... */
265 (void) putchar('\007'); /* curx does not change */
266 (void) fflush(stdout
);
273 /* delay 50 ms - could also use a 'nap'-system call */
274 /* or the usleep call like this :-) */
280 { /* free after Robert Viduya *//* must only be
281 * called with curx = 1 */
286 int cx
= curx
, cy
= cury
;
287 while (cury
<= LI
- 2) {