]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.termcap.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.termcap.c,v 1.4 1995/04/24 12:23:34 cgd Exp $";
11 #include "config.h" /* for ROWNO and COLNO */
12 #include "def.flag.h" /* for flags.nonull */
13 extern char *tgetstr(), *tgoto(), *getenv();
17 extern /* it is defined in libtermlib (libtermcap) */
19 short ospeed
; /* terminal baudrate; used by tputs */
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 */
34 tptr
= (char *) alloc(1024);
37 if(!(term
= getenv("TERM")))
38 error("Can't get TERM.");
39 if(!strncmp(term
, "5620", 4))
40 flags
.nonull
= 1; /* this should be a termcap flag */
41 if(tgetent(tptr
, term
) < 1)
42 error("Unknown terminal type: %s.", term
);
43 if(pc
= tgetstr("pc", &tbufptr
))
45 if(!(BC
= tgetstr("bc", &tbufptr
))) {
47 error("Terminal must backspace.");
52 HO
= tgetstr("ho", &tbufptr
);
55 if(CO
< COLNO
|| LI
< ROWNO
+2)
57 if(!(CL
= tgetstr("cl", &tbufptr
)))
58 error("Hack needs CL.");
59 ND
= tgetstr("nd", &tbufptr
);
61 error("Hack can't have OS.");
62 CE
= tgetstr("ce", &tbufptr
);
63 UP
= tgetstr("up", &tbufptr
);
64 /* It seems that xd is no longer supported, and we should use
65 a linefeed instead; unfortunately this requires resetting
66 CRMOD, and many output routines will have to be modified
67 slightly. Let's leave that till the next release. */
68 XD
= tgetstr("xd", &tbufptr
);
69 /* not: XD = tgetstr("do", &tbufptr); */
70 if(!(CM
= tgetstr("cm", &tbufptr
))) {
72 error("Hack needs CM or UP or HO.");
73 printf("Playing hack on terminals without cm is suspect...\n");
76 SO
= tgetstr("so", &tbufptr
);
77 SE
= tgetstr("se", &tbufptr
);
78 SG
= tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */
79 if(!SO
|| !SE
|| (SG
> 0)) SO
= SE
= 0;
80 CD
= tgetstr("cd", &tbufptr
);
81 set_whole_screen(); /* uses LI and CD */
82 if(tbufptr
-tbuf
> sizeof(tbuf
)) error("TERMCAP entry too big...\n");
98 /* Cursor movements */
99 extern xchar curx
, cury
;
102 register int x
, y
; /* not xchar: perhaps xchar is unsigned and
103 curx-x would be unsigned as well */
106 if (y
== cury
&& x
== curx
)
108 if(!ND
&& (curx
!= x
|| x
<= 3)) { /* Extremely primitive */
109 cmov(x
, y
); /* bunker!wtm */
112 if(abs(cury
-y
) <= 3 && abs(curx
-x
) <= 3)
114 else if((x
<= 3 && abs(cury
-y
)<= 3) || (!CM
&& x
<abs(curx
-x
))) {
115 (void) putchar('\r');
128 while (cury
> y
) { /* Go up. */
137 } /* else impossible("..."); */
138 } else if (cury
< y
) {
154 if (curx
< x
) { /* Go to the right. */
155 if(!ND
) cmov(x
, y
); else /* bah */
156 /* should instead print what is there already */
161 } else if (curx
> x
) {
162 while (curx
> x
) { /* Go to the left. */
172 xputs(tgoto(CM
, x
-1, y
-1));
178 (void) fputc(c
, stdout
);
188 else { /* no-CE fix - free after Harold Rynes */
189 /* this looks terrible, especially on a slow terminal
190 but is better than nothing */
191 register cx
= curx
, cy
= cury
;
193 while(curx
< COLNO
) {
211 xputs(tgoto(CM
, 0, 0));
213 curs(1, 1); /* using UP ... */
235 (void) putchar('\007'); /* curx does not change */
236 (void) fflush(stdout
);
239 static short tmspc10
[] = { /* from termcap */
240 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
244 /* delay 50 ms - could also use a 'nap'-system call */
245 /* BUG: if the padding character is visible, as it is on the 5620
246 then this looks terrible. */
248 tputs("50", 1, xputc
);
250 /* cbosgd!cbcephus!pds for SYS V R2 */
251 /* is this terminfo, or what? */
252 /* tputs("$<50>", 1, xputc); */
254 else if(ospeed
> 0 || ospeed
< SIZE(tmspc10
)) if(CM
) {
255 /* delay by sending cm(here) an appropriate number of times */
256 register int cmlen
= strlen(tgoto(CM
, curx
-1, cury
-1));
257 register int i
= 500 + tmspc10
[ospeed
]/2;
261 i
-= cmlen
*tmspc10
[ospeed
];
266 cl_eos() /* free after Robert Viduya */
267 { /* must only be called with curx = 1 */
272 register int cx
= curx
, cy
= cury
;
273 while(cury
<= LI
-2) {