]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.termcap.c
1 /* $NetBSD: hack.termcap.c,v 1.8 1999/08/14 16:36:42 tron Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.termcap.c,v 1.8 1999/08/14 16:36:42 tron Exp $");
18 #include "def.flag.h" /* for flags.nonull */
20 static char tbuf
[512];
21 static char *HO
, *CL
, *CE
, *UP
, *CM
, *ND
, *XD
, *BC
, *SO
, *SE
, *TI
, *TE
;
24 static char PC
= '\0';
25 char *CD
; /* tested in pri.c: docorner() */
26 int CO
, LI
; /* used in pri.c and whatis.c */
35 tptr
= (char *) alloc(1024);
38 if (!(term
= getenv("TERM")))
39 error("Can't get TERM.");
40 if (!strncmp(term
, "5620", 4))
41 flags
.nonull
= 1; /* this should be a termcap flag */
42 if (tgetent(tptr
, term
) < 1)
43 error("Unknown terminal type: %s.", term
);
44 if ((pc
= tgetstr("pc", &tbufptr
)) != NULL
)
46 if (!(BC
= tgetstr("bc", &tbufptr
))) {
48 error("Terminal must backspace.");
53 HO
= tgetstr("ho", &tbufptr
);
56 if (CO
< COLNO
|| LI
< ROWNO
+ 2)
58 if (!(CL
= tgetstr("cl", &tbufptr
)))
59 error("Hack needs CL.");
60 ND
= tgetstr("nd", &tbufptr
);
62 error("Hack can't have OS.");
63 CE
= tgetstr("ce", &tbufptr
);
64 UP
= tgetstr("up", &tbufptr
);
66 * It seems that xd is no longer supported, and we should use a
67 * linefeed instead; unfortunately this requires resetting CRMOD, and
68 * many output routines will have to be modified slightly. Let's
69 * leave that till the next release.
71 XD
= tgetstr("xd", &tbufptr
);
72 /* not: XD = tgetstr("do", &tbufptr); */
73 if (!(CM
= tgetstr("cm", &tbufptr
))) {
75 error("Hack needs CM or UP or HO.");
76 printf("Playing hack on terminals without cm is suspect...\n");
79 SO
= tgetstr("so", &tbufptr
);
80 SE
= tgetstr("se", &tbufptr
);
81 SG
= tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */
82 if (!SO
|| !SE
|| (SG
> 0))
84 CD
= tgetstr("cd", &tbufptr
);
85 set_whole_screen(); /* uses LI and CD */
86 if (tbufptr
- tbuf
> sizeof(tbuf
))
87 error("TERMCAP entry too big...\n");
105 /* Cursor movements */
108 int x
, y
; /* not xchar: perhaps xchar is unsigned and
109 * curx-x would be unsigned as well */
112 if (y
== cury
&& x
== curx
)
114 if (!ND
&& (curx
!= x
|| x
<= 3)) { /* Extremely primitive */
115 cmov(x
, y
); /* bunker!wtm */
118 if (abs(cury
- y
) <= 3 && abs(curx
- x
) <= 3)
120 else if ((x
<= 3 && abs(cury
- y
) <= 3) || (!CM
&& x
< abs(curx
- x
))) {
121 (void) putchar('\r');
136 while (cury
> y
) { /* Go up. */
145 } /* else impossible("..."); */
146 } else if (cury
< y
) {
162 if (curx
< x
) { /* Go to the right. */
166 /* should instead print what is there already */
171 } else if (curx
> x
) {
172 while (curx
> x
) { /* Go to the left. */
183 xputs(tgoto(CM
, x
- 1, y
- 1));
192 (void) fputc(c
, stdout
);
207 else { /* no-CE fix - free after Harold Rynes */
209 * this looks terrible, especially on a slow terminal but is
210 * better than nothing
212 int cx
= curx
, cy
= cury
;
214 while (curx
< COLNO
) {
235 xputs(tgoto(CM
, 0, 0));
237 curs(1, 1); /* using UP ... */
265 (void) putchar('\007'); /* curx does not change */
266 (void) fflush(stdout
);
272 /* delay 50 ms - could also use a 'nap'-system call */
274 * BUG: if the padding character is visible, as it is on the 5620
275 * then this looks terrible.
278 tputs("50", 1, xputc
);
280 /* cbosgd!cbcephus!pds for SYS V R2 */
281 /* is this terminfo, or what? */
282 /* tputs("$<50>", 1, xputc); */
287 * delay by sending cm(here) an appropriate number of
290 int cmlen
= strlen(tgoto(CM
, curx
- 1, cury
- 1));
291 int i
= (ospeed
+ (100 * cmlen
)) / (200 * cmlen
);
301 { /* free after Robert Viduya *//* must only be
302 * called with curx = 1 */
307 int cx
= curx
, cy
= cury
;
308 while (cury
<= LI
- 2) {