1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.termcap.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.termcap.c,v 1.10 1999/11/16 10:26:38 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.termcap.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */
10 static char *HO
, *CL
, *CE
, *tcUP
, *CM
, *ND
, *XD
, *tcBC
, *SO
, *SE
, *TI
, *TE
;
13 static char tcPC
= '\0';
14 char *CD
; /* tested in pri.c: docorner() */
15 int CO
, LI
; /* used in pri.c and whatis.c */
17 static void nocmov(int, int);
18 static void cmov(int, int);
19 static int xputc(int);
20 static int xputs(char *);
29 tptr
= (char *) alloc(1024);
32 if(!(term
= getenv("TERM")))
33 error("Can't get TERM.");
34 if(tgetent(tptr
, term
) < 1)
35 error("Unknown terminal type: %s.", term
);
36 if (tgetflag(__DECONST(char *, "NP")) ||
37 tgetflag(__DECONST(char *, "nx")))
39 if((pc
= tgetstr(__DECONST(char *, "pc"), &tbufptr
)))
41 if(!(tcBC
= tgetstr(__DECONST(char *, "bc"), &tbufptr
))) {
42 if(!tgetflag(__DECONST(char *, "bs")))
43 error("Terminal must backspace.");
48 HO
= tgetstr(__DECONST(char *, "ho"), &tbufptr
);
49 CO
= tgetnum(__DECONST(char *, "co"));
50 LI
= tgetnum(__DECONST(char *, "li"));
51 if(CO
< COLNO
|| LI
< ROWNO
+2)
53 if(!(CL
= tgetstr(__DECONST(char *, "cl"), &tbufptr
)))
54 error("Hack needs CL.");
55 ND
= tgetstr(__DECONST(char *, "nd"), &tbufptr
);
56 if(tgetflag(__DECONST(char *, "os")))
57 error("Hack can't have OS.");
58 CE
= tgetstr(__DECONST(char *, "ce"), &tbufptr
);
59 tcUP
= tgetstr(__DECONST(char *, "up"), &tbufptr
);
60 /* It seems that xd is no longer supported, and we should use
61 a linefeed instead; unfortunately this requires resetting
62 CRMOD, and many output routines will have to be modified
63 slightly. Let's leave that till the next release. */
64 XD
= tgetstr(__DECONST(char *, "xd"), &tbufptr
);
65 /* not: XD = tgetstr("do", &tbufptr); */
66 if(!(CM
= tgetstr(__DECONST(char *, "cm"), &tbufptr
))) {
68 error("Hack needs CM or UP or HO.");
69 printf("Playing hack on terminals without cm is suspect...\n");
72 SO
= tgetstr(__DECONST(char *, "so"), &tbufptr
);
73 SE
= tgetstr(__DECONST(char *, "se"), &tbufptr
);
74 SG
= tgetnum(__DECONST(char *, "sg"));
75 if(!SO
|| !SE
|| (SG
> 0)) SO
= SE
= 0;
76 CD
= tgetstr(__DECONST(char *, "cd"), &tbufptr
);
77 set_whole_screen(); /* uses LI and CD */
78 if(tbufptr
-tbuf
> (int)sizeof(tbuf
)) error("TERMCAP entry too big...\n");
96 /* not xchar: perhaps xchar is unsigned and curx-x would be unsigned as well */
101 if (y
== cury
&& x
== curx
)
103 if(!ND
&& (curx
!= x
|| x
<= 3)) { /* Extremely primitive */
104 cmov(x
, y
); /* bunker!wtm */
107 if(abs(cury
-y
) <= 3 && abs(curx
-x
) <= 3)
109 else if((x
<= 3 && abs(cury
-y
)<= 3) || (!CM
&& x
<abs(curx
-x
))) {
124 while (cury
> y
) { /* Go up. */
133 } /* else impossible("..."); */
134 } else if (cury
< y
) {
150 if (curx
< x
) { /* Go to the right. */
151 if(!ND
) cmov(x
, y
); else /* bah */
152 /* should instead print what is there already */
157 } else if (curx
> x
) {
158 while (curx
> x
) { /* Go to the left. */
168 xputs(tgoto(CM
, x
-1, y
-1));
176 return(fputc(c
, stdout
));
182 return(tputs(s
, 1, xputc
));
190 else { /* no-CE fix - free after Harold Rynes */
191 /* this looks terrible, especially on a slow terminal
192 but is better than nothing */
193 int cx
= curx
, cy
= cury
;
195 while(curx
< COLNO
) {
216 xputs(tgoto(CM
, 0, 0));
218 curs(1, 1); /* using tcUP ... */
244 putchar('\007'); /* curx does not change */
249 cl_eos(void) /* free after Robert Viduya */
250 { /* must only be called with curx = 1 */
255 int cx
= curx
, cy
= cury
;
256 while(cury
<= LI
-2) {