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 *);
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 && !(tcBC = tgetstr(__DECONST(char *, "le"), &tbufptr))) {
43 if (!tgetflag(__DECONST(char *, "bs")))
44 error("Terminal must backspace.");
49 HO = tgetstr(__DECONST(char *, "ho"), &tbufptr);
50 CO = tgetnum(__DECONST(char *, "co"));
51 LI = tgetnum(__DECONST(char *, "li"));
52 if (CO < COLNO || LI < ROWNO + 2)
54 if (!(CL = tgetstr(__DECONST(char *, "cl"), &tbufptr)))
55 error("Hack needs CL.");
56 ND = tgetstr(__DECONST(char *, "nd"), &tbufptr);
57 if (tgetflag(__DECONST(char *, "os")))
58 error("Hack can't have OS.");
59 CE = tgetstr(__DECONST(char *, "ce"), &tbufptr);
60 tcUP = tgetstr(__DECONST(char *, "up"), &tbufptr);
61 /* It seems that xd is no longer supported, and we should use
62 * a linefeed instead; unfortunately this requires resetting
63 * CRMOD, and many output routines will have to be modified
64 * slightly. Let's leave that till the next release. */
65 XD = tgetstr(__DECONST(char *, "xd"), &tbufptr);
66 /* not: XD = tgetstr("do", &tbufptr); */
67 if (!(CM = tgetstr(__DECONST(char *, "cm"), &tbufptr))) {
69 error("Hack needs CM or UP or HO.");
70 printf("Playing hack on terminals without cm is suspect...\n");
73 SO = tgetstr(__DECONST(char *, "so"), &tbufptr);
74 SE = tgetstr(__DECONST(char *, "se"), &tbufptr);
75 SG = tgetnum(__DECONST(char *, "sg"));
76 if (!SO || !SE || (SG > 0)) SO = SE = 0;
77 CD = tgetstr(__DECONST(char *, "cd"), &tbufptr);
78 set_whole_screen(); /* uses LI and CD */
79 if (tbufptr - tbuf > (int)sizeof(tbuf)) error(
80 "TERMCAP entry too big...\n");
98 /* not xchar: perhaps xchar is unsigned and curx-x would be unsigned as well */
102 if (y == cury && x == curx)
104 if (!ND && (curx != x || x <= 3)) { /* Extremely primitive */
105 cmov(x, y); /* bunker!wtm */
108 if (abs(cury - y) <= 3 && abs(curx - x) <= 3)
110 else if ((x <= 3 && abs(cury - y) <= 3) || (!CM && x < abs(curx - x))) {
125 while (cury > y) { /* Go up. */
134 } /* else impossible("..."); */
135 } else if (cury < y) {
151 if (curx < x) { /* Go to the right. */
155 /* should instead print what is there already */
160 } else if (curx > x) {
161 while (curx > x) { /* Go to the left. */
171 xputs(tgoto(CM, x - 1, y - 1));
179 return (fputc(c, stdout));
185 return (tputs(s, 1, xputc));
193 else { /* no-CE fix - free after Harold Rynes */
194 /* this looks terrible, especially on a slow terminal
195 * but is better than nothing */
196 int cx = curx, cy = cury;
198 while (curx < COLNO) {
219 xputs(tgoto(CM, 0, 0));
221 curs(1, 1); /* using tcUP ... */
249 putchar('\007'); /* curx does not change */
254 cl_eos(void) /* free after Robert Viduya */
255 { /* must only be called with curx = 1 */
259 int cx = curx, cy = cury;
260 while (cury <= LI - 2) {