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 $ */
9 static char *HO, *CL, *CE, *tcUP, *CM, *ND, *XD, *tcBC, *SO, *SE, *TI, *TE;
12 static char tcPC = '\0';
13 char *CD; /* tested in pri.c: docorner() */
14 int CO, LI; /* used in pri.c and whatis.c */
16 static void nocmov(int, int);
17 static void cmov(int, int);
18 static int xputc(int);
19 static int xputs(char *);
31 if (!(term = getenv("TERM")))
32 error("Can't get TERM.");
33 if (tgetent(tptr, term) < 1)
34 error("Unknown terminal type: %s.", term);
35 if (tgetflag(__DECONST(char *, "NP")) ||
36 tgetflag(__DECONST(char *, "nx")))
38 if ((pc = tgetstr(__DECONST(char *, "pc"), &tbufptr)))
40 if (!(tcBC = tgetstr(__DECONST(char *, "bc"), &tbufptr))
41 && !(tcBC = tgetstr(__DECONST(char *, "le"), &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 = NULL;
76 CD = tgetstr(__DECONST(char *, "cd"), &tbufptr);
77 set_whole_screen(); /* uses LI and CD */
78 if (tbufptr - tbuf > (int)sizeof(tbuf)) error(
79 "TERMCAP entry too big...\n");
97 /* 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. */
154 /* should instead print what is there already */
159 } else if (curx > x) {
160 while (curx > x) { /* Go to the left. */
170 xputs(tgoto(CM, x - 1, y - 1));
178 return (fputc(c, stdout));
184 return (tputs(s, 1, xputc));
192 else { /* no-CE fix - free after Harold Rynes */
193 /* this looks terrible, especially on a slow terminal
194 * but is better than nothing */
195 int cx = curx, cy = cury;
197 while (curx < COLNO) {
218 xputs(tgoto(CM, 0, 0));
220 curs(1, 1); /* using tcUP ... */
248 putchar('\007'); /* curx does not change */
253 cl_eos(void) /* free after Robert Viduya */
254 { /* must only be called with curx = 1 */
258 int cx = curx, cy = cury;
259 while (cury <= LI - 2) {