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 initCO = 0;
62 static int CO = 80; /* number of colums */
63 static char *SE = NULL; /* termcap string to end standout mode */
64 static char *SO = NULL; /* termcap string to begin standout mode */
66 static char termcap[TXTSIZ];
75 #ifndef TGETENT_ACCEPTS_NULL
89 static int inited = 0;
94 if (!(term = getenv("TERM")))
98 ** If possible, we let tgetent allocate its own termcap buffer
100 #ifdef TGETENT_ACCEPTS_NULL
101 if (tgetent(NULL, term) != TGETENT_SUCCESS)
104 if (tgetent(termbuf, term) != TGETENT_SUCCESS)
108 #ifdef HAVE_TERMIOS_H
109 speedcode = cfgetospeed(&tio);
111 # ifdef HAVE_TERMIO_H
112 speedcode = ioctl(fileno(stdout), TCGETA, &tio) != NOTOK ?
113 tio.c_cflag & CBAUD : 0;
115 speedcode = ioctl(fileno(stdout), TIOCGETP, (char *) &tio) != NOTOK ?
120 if (!initCO && (CO = tgetnum("co")) <= 0)
124 if ((bp = tgetstr("pc", &cp)))
126 if (tgetnum("sg") <= 0) {
127 SE = tgetstr("se", &cp);
128 SO = tgetstr("so", &cp);
140 if (ioctl(fileno(stderr), TIOCGWINSZ, &win) != NOTOK
141 && (width = win.ws_col) > 0) {
145 #endif /* TIOCGWINSZ */
153 ** print in standout mode
156 SOprintf(char *fmt, ...)
164 tputs(SO, 1, putchar);
170 tputs(SE, 1, putchar);