1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.termcap.c - version 1.0.3 */
9 #include "config.h" /* for ROWNO and COLNO */
10 #include "def.flag.h" /* for flags.nonull */
13 static char tbuf[512];
14 static char *HO, *CL, *CE, *UP, *CM, *ND, *XD, *BC, *SO, *SE, *TI, *TE;
17 static char PC = '\0';
18 char *CD; /* tested in pri.c: docorner() */
19 int CO, LI; /* used in pri.c and whatis.c */
27 tptr = (char *) alloc(1024);
30 if(!(term = getenv("TERM")))
31 error("Can't get TERM.");
32 if(tgetent(tptr, term) < 1)
33 error("Unknown terminal type: %s.", term);
34 if(tgetflag("NP") || tgetflag("nx"))
36 if(pc = tgetstr("pc", &tbufptr))
38 if(!(BC = tgetstr("bc", &tbufptr))) {
40 error("Terminal must backspace.");
45 HO = tgetstr("ho", &tbufptr);
48 if(CO < COLNO || LI < ROWNO+2)
50 if(!(CL = tgetstr("cl", &tbufptr)))
51 error("Hack needs CL.");
52 ND = tgetstr("nd", &tbufptr);
54 error("Hack can't have OS.");
55 CE = tgetstr("ce", &tbufptr);
56 UP = tgetstr("up", &tbufptr);
57 /* It seems that xd is no longer supported, and we should use
58 a linefeed instead; unfortunately this requires resetting
59 CRMOD, and many output routines will have to be modified
60 slightly. Let's leave that till the next release. */
61 XD = tgetstr("xd", &tbufptr);
62 /* not: XD = tgetstr("do", &tbufptr); */
63 if(!(CM = tgetstr("cm", &tbufptr))) {
65 error("Hack needs CM or UP or HO.");
66 printf("Playing hack on terminals without cm is suspect...\n");
69 SO = tgetstr("so", &tbufptr);
70 SE = tgetstr("se", &tbufptr);
71 SG = tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */
72 if(!SO || !SE || (SG > 0)) SO = SE = 0;
73 CD = tgetstr("cd", &tbufptr);
74 set_whole_screen(); /* uses LI and CD */
75 if(tbufptr-tbuf > sizeof(tbuf)) error("TERMCAP entry too big...\n");
91 /* Cursor movements */
92 extern xchar curx, cury;
95 int x, y; /* not xchar: perhaps xchar is unsigned and
96 curx-x would be unsigned as well */
99 if (y == cury && x == curx)
101 if(!ND && (curx != x || x <= 3)) { /* Extremely primitive */
102 cmov(x, y); /* bunker!wtm */
105 if(abs(cury-y) <= 3 && abs(curx-x) <= 3)
107 else if((x <= 3 && abs(cury-y)<= 3) || (!CM && x<abs(curx-x))) {
108 (void) putchar('\r');
121 while (cury > y) { /* Go up. */
130 } /* else impossible("..."); */
131 } else if (cury < y) {
147 if (curx < x) { /* Go to the right. */
148 if(!ND) cmov(x, y); else /* bah */
149 /* should instead print what is there already */
154 } else if (curx > x) {
155 while (curx > x) { /* Go to the left. */
165 xputs(tgoto(CM, x-1, y-1));
171 (void) fputc(c, stdout);
181 else { /* no-CE fix - free after Harold Rynes */
182 /* this looks terrible, especially on a slow terminal
183 but is better than nothing */
184 int cx = curx, cy = cury;
186 while(curx < COLNO) {
204 xputs(tgoto(CM, 0, 0));
206 curs(1, 1); /* using UP ... */
228 (void) putchar('\007'); /* curx does not change */
229 (void) fflush(stdout);
232 static short tmspc10[] = { /* from termcap */
233 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 3, 2, 1
238 /* delay 50 ms - could also use a 'nap'-system call */
239 /* BUG: if the padding character is visible, as it is on the 5620
240 then this looks terrible. */
242 tputs("50", 1, xputc);
244 /* cbosgd!cbcephus!pds for SYS V R2 */
245 /* is this terminfo, or what? */
246 /* tputs("$<50>", 1, xputc); */
248 (void) fflush(stdout);
251 else if(ospeed > 0 || ospeed < SIZE(tmspc10)) if(CM) {
252 /* delay by sending cm(here) an appropriate number of times */
253 int cmlen = strlen(tgoto(CM, curx-1, cury-1));
254 int i = 500 + tmspc10[ospeed]/2;
258 i -= cmlen*tmspc10[ospeed];
264 cl_eos() /* free after Robert Viduya */
265 { /* must only be called with curx = 1 */
270 int cx = curx, cy = cury;
271 while(cury <= LI-2) {