]>
diplodocus.org Git - nmh/blob - uip/termsbr.c
3 * termsbr.c -- termcap support
24 /* <sys/ioctl.h> is need anyway for ioctl()
25 #ifdef GWINSZ_IN_SYS_IOCTL
27 # include <sys/ioctl.h>
32 #ifdef WINSIZE_IN_PTEM
33 # include <sys/stream.h>
34 # include <sys/ptem.h>
40 # define TXTSIZ BUFSIZ
44 * These variables are sometimes defined in,
45 * and needed by the termcap library.
48 # ifdef MUST_DEFINE_OSPEED
57 static long speedcode
;
59 static int initLI
= 0;
60 static int initCO
= 0;
62 static int HC
= 0; /* are we on a hardcopy terminal? */
63 static int LI
= 40; /* number of lines */
64 static int CO
= 80; /* number of colums */
65 static char *CL
= NULL
; /* termcap string to clear screen */
66 static char *SE
= NULL
; /* termcap string to end standout mode */
67 static char *SO
= NULL
; /* termcap string to begin standout mode */
69 static char termcap
[TXTSIZ
];
78 #ifndef TGETENT_ACCEPTS_NULL
92 static int inited
= 0;
97 if (!(term
= getenv ("TERM")))
101 * If possible, we let tgetent allocate its own termcap buffer
103 #ifdef TGETENT_ACCEPTS_NULL
104 if (tgetent (NULL
, term
) <= 0)
107 if (tgetent (termbuf
, term
) <= 0)
111 #ifdef HAVE_TERMIOS_H
112 speedcode
= cfgetospeed(&tio
);
114 # ifdef HAVE_TERMIO_H
115 speedcode
= ioctl(fileno(stdout
), TCGETA
, &tio
) != NOTOK
? tio
.c_cflag
& CBAUD
: 0;
117 speedcode
= ioctl(fileno(stdout
), TIOCGETP
, (char *) &tio
) != NOTOK
? tio
.sg_ospeed
: 0;
121 HC
= tgetflag ("hc");
123 if (!initCO
&& (CO
= tgetnum ("co")) <= 0)
125 if (!initLI
&& (LI
= tgetnum ("li")) <= 0)
129 CL
= tgetstr ("cl", &cp
);
130 if ((bp
= tgetstr ("pc", &cp
)))
132 if (tgetnum ("sg") <= 0) {
133 SE
= tgetstr ("se", &cp
);
134 SO
= tgetstr ("so", &cp
);
146 if (ioctl (fileno (stderr
), TIOCGWINSZ
, &win
) != NOTOK
147 && (width
= win
.ws_col
) > 0) {
151 #endif /* TIOCGWINSZ */
164 if (ioctl (fileno (stderr
), TIOCGWINSZ
, &win
) != NOTOK
165 && (LI
= win
.ws_row
) > 0)
168 #endif /* TIOCGWINSZ */
188 tputs (CL
, LI
, outc
);
200 * print in standout mode
203 SOprintf (char *fmt
, ...)
223 * Is this a hardcopy terminal?