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 ? tio.c_cflag & CBAUD : 0;
118 speedcode = ioctl(fileno(stdout), TIOCGETP, (char *) &tio) != NOTOK ? tio.sg_ospeed : 0;
122 HC = tgetflag ("hc");
124 if (!initCO && (CO = tgetnum ("co")) <= 0)
126 if (!initLI && (LI = tgetnum ("li")) <= 0)
130 CL = tgetstr ("cl", &cp);
131 if ((bp = tgetstr ("pc", &cp)))
133 if (tgetnum ("sg") <= 0) {
134 SE = tgetstr ("se", &cp);
135 SO = tgetstr ("so", &cp);
147 if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
148 && (width = win.ws_col) > 0) {
152 #endif /* TIOCGWINSZ */
165 if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
166 && (LI = win.ws_row) > 0)
169 #endif /* TIOCGWINSZ */
189 tputs (CL, LI, outc);
201 * print in standout mode
204 SOprintf (char *fmt, ...)
224 * Is this a hardcopy terminal?