]>
diplodocus.org Git - nmh/blob - uip/termsbr.c
3 * termsbr.c -- termcap support
24 #ifdef GWINSZ_IN_SYS_IOCTL
25 # include <sys/ioctl.h>
27 #ifdef WINSIZE_IN_PTEM
28 # include <sys/stream.h>
29 # include <sys/ptem.h>
35 # define TXTSIZ BUFSIZ
39 * These variables are sometimes defined in,
40 * and needed by the termcap library.
43 # ifdef MUST_DEFINE_OSPEED
52 static long speedcode
;
54 static int initLI
= 0;
55 static int initCO
= 0;
57 static int HC
= 0; /* are we on a hardcopy terminal? */
58 static int LI
= 40; /* number of lines */
59 static int CO
= 80; /* number of colums */
60 static char *CL
= NULL
; /* termcap string to clear screen */
61 static char *SE
= NULL
; /* termcap string to end standout mode */
62 static char *SO
= NULL
; /* termcap string to begin standout mode */
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
) <= 0)
102 if (tgetent (termbuf
, term
) <= 0)
106 #ifdef HAVE_TERMIOS_H
107 speedcode
= cfgetospeed(&tio
);
109 # ifdef HAVE_TERMIO_H
110 speedcode
= ioctl(fileno(stdout
), TCGETA
, &tio
) != NOTOK
? tio
.c_cflag
& CBAUD
: 0;
112 speedcode
= ioctl(fileno(stdout
), TIOCGETP
, (char *) &tio
) != NOTOK
? tio
.sg_ospeed
: 0;
116 HC
= tgetflag ("hc");
118 if (!initCO
&& (CO
= tgetnum ("co")) <= 0)
120 if (!initLI
&& (LI
= tgetnum ("li")) <= 0)
124 CL
= tgetstr ("cl", &cp
);
125 if ((bp
= tgetstr ("pc", &cp
)))
127 if (tgetnum ("sg") <= 0) {
128 SE
= tgetstr ("se", &cp
);
129 SO
= tgetstr ("so", &cp
);
141 if (ioctl (fileno (stderr
), TIOCGWINSZ
, &win
) != NOTOK
142 && (width
= win
.ws_col
) > 0) {
146 #endif /* TIOCGWINSZ */
159 if (ioctl (fileno (stderr
), TIOCGWINSZ
, &win
) != NOTOK
160 && (LI
= win
.ws_row
) > 0)
163 #endif /* TIOCGWINSZ */
183 tputs (CL
, LI
, outc
);
195 * print in standout mode
198 SOprintf (char *fmt
, ...)
218 * Is this a hardcopy terminal?