1 /* trmsbr.c - minor termcap support (load with -ltermlib) */
10 #include <sys/ioctl.h>
24 int tgetent (), tgetnum ();
29 static int TCinited = 0;
30 static int TCavailable = 0;
31 static int initLI = 0;
33 static int initCO = 0;
35 static char *CL = NULL;
36 static char *SE = NULL;
37 static char *SO = NULL;
39 static char termcap[TXTSIZ];
40 static char area[TXTSIZ];
62 if (!isatty(fileno(stdout)))
65 if ((term = getenv ("TERM")) == NULL || tgetent (termcap, term) <= OK)
71 ospeed = ioctl(fileno (stdout), TIOCGETP, (char *) &sg) != NOTOK
74 ospeed = ioctl(fileno (stdout), TCGETA, &sg) != NOTOK
75 ? sg.c_cflag & CBAUD : 0;
78 if (!initCO && (i = tgetnum ("co")) > 0)
80 if (!initLI && (i = tgetnum ("li")) > 0)
84 CL = tgetstr ("cl", &cp);
85 if (bp = tgetstr ("pc", &cp))
87 if (tgetnum ("sg") <= 0) {
88 SE = tgetstr ("se", &cp);
89 SO = tgetstr ("so", &cp);
101 if (ioctl(fileno (stderr), TIOCGWINSZ, &win) != NOTOK && win.ws_col > 0) {
118 if (ioctl(fileno (stderr), TIOCGWINSZ, &win) != NOTOK && win.ws_row > 0) {
144 tputs (CL, LI, outc);
151 (void) fflush (stdout);
158 SOprintf(fmt, a, b, c, d, e, f)
168 if (SO == NULL || SE == NULL)
172 printf (fmt, a, b, c, d, e, f);
180 static char *TCid[MAXTCENT];
181 static char *TCent[MAXTCENT];
189 static char tcbuf[1024];
190 static char *tcptr = tcbuf;
192 for (i = 0; i < nTCent; ++i)
193 if (strcmp(TCid[i], id) == 0)
196 if (nTCent >= MAXTCENT)
199 TCid[nTCent] = getcpy(id);
207 cp = tgetstr(id, &tcptr);
209 /* check for some alternates for the entry */
210 if (strcmp(id, "mb") == 0 ||
211 strcmp(id, "md") == 0 ||
212 strcmp(id, "mh") == 0 ||
213 strcmp(id, "mr") == 0 ||
214 strcmp(id, "us") == 0)
216 else if (strcmp(id, "me") == 0 ||
217 strcmp(id, "ue") == 0)
219 cp = tgetstr(id, &tcptr);
224 /* skip leading delay spec */