]>
diplodocus.org Git - nmh/blob - uip/termsbr.c
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.
26 /* <sys/ioctl.h> is need anyway for ioctl()
27 #ifdef GWINSZ_IN_SYS_IOCTL
29 # include <sys/ioctl.h>
34 #ifdef WINSIZE_IN_PTEM
35 # include <sys/stream.h>
36 # include <sys/ptem.h>
42 # define TXTSIZ BUFSIZ
46 * These variables are sometimes defined in,
47 * and needed by the termcap library.
50 # ifdef MUST_DEFINE_OSPEED
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
94 static int inited
= 0;
99 if (!(term
= getenv ("TERM")))
103 * If possible, we let tgetent allocate its own termcap buffer
105 #ifdef TGETENT_ACCEPTS_NULL
106 if (tgetent (NULL
, term
) != TGETENT_SUCCESS
)
109 if (tgetent (termbuf
, term
) != TGETENT_SUCCESS
)
113 #ifdef HAVE_TERMIOS_H
114 speedcode
= cfgetospeed(&tio
);
116 # ifdef HAVE_TERMIO_H
117 speedcode
= ioctl(fileno(stdout
), TCGETA
, &tio
) != NOTOK
? tio
.c_cflag
& CBAUD
: 0;
119 speedcode
= ioctl(fileno(stdout
), TIOCGETP
, (char *) &tio
) != NOTOK
? tio
.sg_ospeed
: 0;
123 HC
= tgetflag ("hc");
125 if (!initCO
&& (CO
= tgetnum ("co")) <= 0)
127 if (!initLI
&& (LI
= tgetnum ("li")) <= 0)
131 CL
= tgetstr ("cl", &cp
);
132 if ((bp
= tgetstr ("pc", &cp
)))
134 if (tgetnum ("sg") <= 0) {
135 SE
= tgetstr ("se", &cp
);
136 SO
= tgetstr ("so", &cp
);
148 if (ioctl (fileno (stderr
), TIOCGWINSZ
, &win
) != NOTOK
149 && (width
= win
.ws_col
) > 0) {
153 #endif /* TIOCGWINSZ */
166 if (ioctl (fileno (stderr
), TIOCGWINSZ
, &win
) != NOTOK
167 && (LI
= win
.ws_row
) > 0)
170 #endif /* TIOCGWINSZ */
190 tputs (CL
, LI
, outc
);
202 * print in standout mode
205 SOprintf (char *fmt
, ...)
225 * Is this a hardcopy terminal?