3 * termsbr.c -- termcap support
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
18 /* <sys/ioctl.h> is need anyway for ioctl()
19 #ifdef GWINSZ_IN_SYS_IOCTL
21 # include <sys/ioctl.h>
26 #ifdef WINSIZE_IN_PTEM
27 # include <sys/stream.h>
28 # include <sys/ptem.h>
34 # define TXTSIZ BUFSIZ
38 * These variables are sometimes defined in,
39 * and needed by the termcap library.
42 # ifdef MUST_DEFINE_OSPEED
51 static long speedcode;
53 static int initLI = 0;
54 static int initCO = 0;
56 static int HC = 0; /* are we on a hardcopy terminal? */
57 static int LI = 40; /* number of lines */
58 static int CO = 80; /* number of colums */
59 static char *CL = NULL; /* termcap string to clear screen */
60 static char *SE = NULL; /* termcap string to end standout mode */
61 static char *SO = NULL; /* termcap string to begin standout mode */
63 static char termcap[TXTSIZ];
72 #ifndef TGETENT_ACCEPTS_NULL
77 static int inited = 0;
82 if (!(term = getenv ("TERM")))
86 * If possible, we let tgetent allocate its own termcap buffer
88 #ifdef TGETENT_ACCEPTS_NULL
89 if (tgetent (NULL, term) != TGETENT_SUCCESS)
92 if (tgetent (termbuf, term) != TGETENT_SUCCESS)
96 speedcode = cfgetospeed(&tio);
100 if (!initCO && (CO = tgetnum ("co")) <= 0)
102 if (!initLI && (LI = tgetnum ("li")) <= 0)
106 CL = tgetstr ("cl", &cp);
107 if ((bp = tgetstr ("pc", &cp)))
109 if (tgetnum ("sg") <= 0) {
110 SE = tgetstr ("se", &cp);
111 SO = tgetstr ("so", &cp);
123 if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
124 && (width = win.ws_col) > 0) {
128 #endif /* TIOCGWINSZ */
141 if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
142 && (LI = win.ws_row) > 0)
145 #endif /* TIOCGWINSZ */
165 tputs (CL, LI, outc);
177 * print in standout mode
180 SOprintf (char *fmt, ...)
200 * Is this a hardcopy terminal?