2 ** termsbr.c -- termcap support
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
25 /* <sys/ioctl.h> is need anyway for ioctl()
26 #ifdef GWINSZ_IN_SYS_IOCTL
28 # include <sys/ioctl.h>
33 #ifdef WINSIZE_IN_PTEM
34 # include <sys/stream.h>
35 # include <sys/ptem.h>
41 # define TXTSIZ BUFSIZ
45 ** These variables are sometimes defined in,
46 ** and needed by the termcap library.
49 # ifdef MUST_DEFINE_OSPEED
58 static long speedcode;
60 static int initLI = 0;
61 static int initCO = 0;
63 static int HC = 0; /* are we on a hardcopy terminal? */
64 static int LI = 40; /* number of lines */
65 static int CO = 80; /* number of colums */
66 static char *CL = NULL; /* termcap string to clear screen */
67 static char *SE = NULL; /* termcap string to end standout mode */
68 static char *SO = NULL; /* termcap string to begin standout mode */
70 static char termcap[TXTSIZ];
79 #ifndef TGETENT_ACCEPTS_NULL
93 static int inited = 0;
98 if (!(term = getenv("TERM")))
102 ** If possible, we let tgetent allocate its own termcap buffer
104 #ifdef TGETENT_ACCEPTS_NULL
105 if (tgetent(NULL, term) != TGETENT_SUCCESS)
108 if (tgetent(termbuf, term) != TGETENT_SUCCESS)
112 #ifdef HAVE_TERMIOS_H
113 speedcode = cfgetospeed(&tio);
115 # ifdef HAVE_TERMIO_H
116 speedcode = ioctl(fileno(stdout), TCGETA, &tio) != NOTOK ?
117 tio.c_cflag & CBAUD : 0;
119 speedcode = ioctl(fileno(stdout), TIOCGETP, (char *) &tio) != NOTOK ?
126 if (!initCO && (CO = tgetnum("co")) <= 0)
128 if (!initLI && (LI = tgetnum("li")) <= 0)
132 CL = tgetstr("cl", &cp);
133 if ((bp = tgetstr("pc", &cp)))
135 if (tgetnum("sg") <= 0) {
136 SE = tgetstr("se", &cp);
137 SO = tgetstr("so", &cp);
149 if (ioctl(fileno(stderr), TIOCGWINSZ, &win) != NOTOK
150 && (width = win.ws_col) > 0) {
154 #endif /* TIOCGWINSZ */
167 if (ioctl(fileno(stderr), TIOCGWINSZ, &win) != NOTOK
168 && (LI = win.ws_row) > 0)
171 #endif /* TIOCGWINSZ */
184 tputs(CL, LI, putchar);
196 ** print in standout mode
199 SOprintf(char *fmt, ...)
207 tputs(SO, 1, putchar);
213 tputs(SE, 1, putchar);
219 ** Is this a hardcopy terminal?