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
37 #ifdef notdef_lyndon_posix
40 XXX No current termcap should need this. If your compile barfs,
41 email details to lyndon@orthanc.ca. This code will vanish soon ...
44 * These variables are sometimes defined in,
45 * and needed by the termcap library.
48 # ifdef MUST_DEFINE_OSPEED
57 #endif /* notdef_lyndon_posix */
59 static long speedcode;
61 static int initLI = 0;
62 static int initCO = 0;
64 static int HC = 0; /* are we on a hardcopy terminal? */
65 static int LI = 40; /* number of lines */
66 static int CO = 80; /* number of colums */
67 static char *CL = NULL; /* termcap string to clear screen */
68 static char *SE = NULL; /* termcap string to end standout mode */
69 static char *SO = NULL; /* termcap string to begin standout mode */
71 static char termcap[TXTSIZ];
80 #ifndef TGETENT_ACCEPTS_NULL
85 static int inited = 0;
90 if (!(term = getenv ("TERM")))
94 * If possible, we let tgetent allocate its own termcap buffer
96 #ifdef TGETENT_ACCEPTS_NULL
97 if (tgetent (NULL, term) != TGETENT_SUCCESS)
100 if (tgetent (termbuf, term) != TGETENT_SUCCESS)
104 speedcode = cfgetospeed(&tio);
106 HC = tgetflag ("hc");
108 if (!initCO && (CO = tgetnum ("co")) <= 0)
110 if (!initLI && (LI = tgetnum ("li")) <= 0)
114 CL = tgetstr ("cl", &cp);
115 if ((bp = tgetstr ("pc", &cp)))
117 if (tgetnum ("sg") <= 0) {
118 SE = tgetstr ("se", &cp);
119 SO = tgetstr ("so", &cp);
131 if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
132 && (width = win.ws_col) > 0) {
136 #endif /* TIOCGWINSZ */
149 if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
150 && (LI = win.ws_row) > 0)
153 #endif /* TIOCGWINSZ */
173 tputs (CL, LI, outc);
185 * print in standout mode
188 SOprintf (char *fmt, ...)
208 * Is this a hardcopy terminal?