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 */
64 static char termcap[TXTSIZ];
73 #ifndef TGETENT_ACCEPTS_NULL
87 static int inited = 0;
92 if (!(term = getenv("TERM")))
96 ** If possible, we let tgetent allocate its own termcap buffer
98 #ifdef TGETENT_ACCEPTS_NULL
99 if (tgetent(NULL, term) != TGETENT_SUCCESS)
102 if (tgetent(termbuf, term) != TGETENT_SUCCESS)
106 #ifdef HAVE_TERMIOS_H
107 speedcode = cfgetospeed(&tio);
109 # ifdef HAVE_TERMIO_H
110 speedcode = ioctl(fileno(stdout), TCGETA, &tio) != NOTOK ?
111 tio.c_cflag & CBAUD : 0;
113 speedcode = ioctl(fileno(stdout), TIOCGETP, (char *) &tio) != NOTOK ?
118 if (!initCO && (CO = tgetnum("co")) <= 0)
122 if ((bp = tgetstr("pc", &cp)))
134 if (ioctl(fileno(stderr), TIOCGWINSZ, &win) != NOTOK
135 && (width = win.ws_col) > 0) {
139 #endif /* TIOCGWINSZ */