]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.termcap.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$Id: hack.termcap.c,v 1.2 1993/08/02 17:19:27 mycroft Exp $";
10 #include "config.h" /* for ROWNO and COLNO */
11 #include "def.flag.h" /* for flags.nonull */
12 extern char *tgetstr(), *tgoto(), *getenv();
16 extern /* it is defined in libtermlib (libtermcap) */
18 short ospeed
; /* terminal baudrate; used by tputs */
19 static char tbuf
[512];
20 static char *HO
, *CL
, *CE
, *UP
, *CM
, *ND
, *XD
, *BC
, *SO
, *SE
, *TI
, *TE
;
23 static char PC
= '\0';
24 char *CD
; /* tested in pri.c: docorner() */
25 int CO
, LI
; /* used in pri.c and whatis.c */
33 tptr
= (char *) alloc(1024);
36 if(!(term
= getenv("TERM")))
37 error("Can't get TERM.");
38 if(!strncmp(term
, "5620", 4))
39 flags
.nonull
= 1; /* this should be a termcap flag */
40 if(tgetent(tptr
, term
) < 1)
41 error("Unknown terminal type: %s.", term
);
42 if(pc
= tgetstr("pc", &tbufptr
))
44 if(!(BC
= tgetstr("bc", &tbufptr
))) {
46 error("Terminal must backspace.");
51 HO
= tgetstr("ho", &tbufptr
);
54 if(CO
< COLNO
|| LI
< ROWNO
+2)
56 if(!(CL
= tgetstr("cl", &tbufptr
)))
57 error("Hack needs CL.");
58 ND
= tgetstr("nd", &tbufptr
);
60 error("Hack can't have OS.");
61 CE
= tgetstr("ce", &tbufptr
);
62 UP
= tgetstr("up", &tbufptr
);
63 /* It seems that xd is no longer supported, and we should use
64 a linefeed instead; unfortunately this requires resetting
65 CRMOD, and many output routines will have to be modified
66 slightly. Let's leave that till the next release. */
67 XD
= tgetstr("xd", &tbufptr
);
68 /* not: XD = tgetstr("do", &tbufptr); */
69 if(!(CM
= tgetstr("cm", &tbufptr
))) {
71 error("Hack needs CM or UP or HO.");
72 printf("Playing hack on terminals without cm is suspect...\n");
75 SO
= tgetstr("so", &tbufptr
);
76 SE
= tgetstr("se", &tbufptr
);
77 SG
= tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */
78 if(!SO
|| !SE
|| (SG
> 0)) SO
= SE
= 0;
79 CD
= tgetstr("cd", &tbufptr
);
80 set_whole_screen(); /* uses LI and CD */
81 if(tbufptr
-tbuf
> sizeof(tbuf
)) error("TERMCAP entry too big...\n");
97 /* Cursor movements */
98 extern xchar curx
, cury
;
101 register int x
, y
; /* not xchar: perhaps xchar is unsigned and
102 curx-x would be unsigned as well */
105 if (y
== cury
&& x
== curx
)
107 if(!ND
&& (curx
!= x
|| x
<= 3)) { /* Extremely primitive */
108 cmov(x
, y
); /* bunker!wtm */
111 if(abs(cury
-y
) <= 3 && abs(curx
-x
) <= 3)
113 else if((x
<= 3 && abs(cury
-y
)<= 3) || (!CM
&& x
<abs(curx
-x
))) {
114 (void) putchar('\r');
127 while (cury
> y
) { /* Go up. */
136 } /* else impossible("..."); */
137 } else if (cury
< y
) {
153 if (curx
< x
) { /* Go to the right. */
154 if(!ND
) cmov(x
, y
); else /* bah */
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));
177 (void) fputc(c
, stdout
);
187 else { /* no-CE fix - free after Harold Rynes */
188 /* this looks terrible, especially on a slow terminal
189 but is better than nothing */
190 register cx
= curx
, cy
= cury
;
192 while(curx
< COLNO
) {
210 xputs(tgoto(CM
, 0, 0));
212 curs(1, 1); /* using UP ... */
234 (void) putchar('\007'); /* curx does not change */
235 (void) fflush(stdout
);
238 static short tmspc10
[] = { /* from termcap */
239 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
243 /* delay 50 ms - could also use a 'nap'-system call */
244 /* BUG: if the padding character is visible, as it is on the 5620
245 then this looks terrible. */
247 tputs("50", 1, xputc
);
249 /* cbosgd!cbcephus!pds for SYS V R2 */
250 /* is this terminfo, or what? */
251 /* tputs("$<50>", 1, xputc); */
253 else if(ospeed
> 0 || ospeed
< SIZE(tmspc10
)) if(CM
) {
254 /* delay by sending cm(here) an appropriate number of times */
255 register int cmlen
= strlen(tgoto(CM
, curx
-1, cury
-1));
256 register int i
= 500 + tmspc10
[ospeed
]/2;
260 i
-= cmlen
*tmspc10
[ospeed
];
265 cl_eos() /* free after Robert Viduya */
266 { /* must only be called with curx = 1 */
271 register int cx
= curx
, cy
= cury
;
272 while(cury
<= LI
-2) {