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.
17 /* <sys/ioctl.h> is need anyway for ioctl()
18 #ifdef GWINSZ_IN_SYS_IOCTL
20 # include <sys/ioctl.h>
25 #ifdef WINSIZE_IN_PTEM
26 # include <sys/stream.h>
27 # include <sys/ptem.h>
33 # define TXTSIZ BUFSIZ
36 static long speedcode;
38 static int initCO = 0;
40 static int CO = 80; /* number of colums */
42 static char termcap[TXTSIZ];
51 #ifndef TGETENT_ACCEPTS_NULL
56 static int inited = 0;
61 if (!(term = getenv("TERM")))
65 ** If possible, we let tgetent allocate its own termcap buffer
67 #ifdef TGETENT_ACCEPTS_NULL
68 if (tgetent(NULL, term) != TGETENT_SUCCESS)
71 if (tgetent(termbuf, term) != TGETENT_SUCCESS)
75 speedcode = cfgetospeed(&tio);
77 if (!initCO && (CO = tgetnum("co")) <= 0)
81 if ((bp = tgetstr("pc", &cp)))
93 if (ioctl(fileno(stderr), TIOCGWINSZ, &win) != NOTOK
94 && (width = win.ws_col) > 0) {
98 #endif /* TIOCGWINSZ */