3 * termsbr.c -- termcap support
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
28 /* <sys/ioctl.h> is need anyway for ioctl()
29 #ifdef GWINSZ_IN_SYS_IOCTL
31 # include <sys/ioctl.h>
36 #ifdef WINSIZE_IN_PTEM
37 # include <sys/stream.h>
38 # include <sys/ptem.h>
44 # define TXTSIZ BUFSIZ
48 * These variables are sometimes defined in,
49 * and needed by the termcap library.
52 # ifdef MUST_DEFINE_OSPEED
61 static long speedcode;
63 static int initLI = 0;
64 static int initCO = 0;
66 static int HC = 0; /* are we on a hardcopy terminal? */
67 static int LI = 40; /* number of lines */
68 static int CO = 80; /* number of colums */
69 static char *CL = NULL; /* termcap string to clear screen */
70 static char *SE = NULL; /* termcap string to end standout mode */
71 static char *SO = NULL; /* termcap string to begin standout mode */
73 static char termcap[TXTSIZ];
82 #ifndef TGETENT_ACCEPTS_NULL
96 static int inited = 0;
101 if (!(term = getenv ("TERM")))
105 * If possible, we let tgetent allocate its own termcap buffer
107 #ifdef TGETENT_ACCEPTS_NULL
108 if (tgetent (NULL, term) != TGETENT_SUCCESS)
111 if (tgetent (termbuf, term) != TGETENT_SUCCESS)
115 #ifdef HAVE_TERMIOS_H
116 speedcode = cfgetospeed(&tio);
118 # ifdef HAVE_TERMIO_H
119 speedcode = ioctl(fileno(stdout), TCGETA, &tio) != NOTOK ? tio.c_cflag & CBAUD : 0;
121 speedcode = ioctl(fileno(stdout), TIOCGETP, (char *) &tio) != NOTOK ? tio.sg_ospeed : 0;
125 HC = tgetflag ("hc");
127 if (!initCO && (CO = tgetnum ("co")) <= 0)
129 if (!initLI && (LI = tgetnum ("li")) <= 0)
133 CL = tgetstr ("cl", &cp);
134 if ((bp = tgetstr ("pc", &cp)))
136 if (tgetnum ("sg") <= 0) {
137 SE = tgetstr ("se", &cp);
138 SO = tgetstr ("so", &cp);
150 if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
151 && (width = win.ws_col) > 0) {
155 #endif /* TIOCGWINSZ */
168 if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
169 && (LI = win.ws_row) > 0)
172 #endif /* TIOCGWINSZ */
192 tputs (CL, LI, outc);
204 * print in standout mode
207 SOprintf (char *fmt, ...)
227 * Is this a hardcopy terminal?