2 * Copyright (c) 1995, 1996
3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
11 static const char sccsid
[] = "$Id: cl_bsd.c,v 8.32 2000/12/01 13:56:17 skimo Exp $ (Berkeley) $Date: 2000/12/01 13:56:17 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
18 #include <bitstring.h>
27 #include "../common/common.h"
31 static char *ke
; /* Keypad on. */
32 static char *ks
; /* Keypad off. */
33 static char *vb
; /* Visible bell string. */
36 * HP's support the entire System V curses package except for the tigetstr
37 * and tigetnum functions. Ultrix supports the BSD curses package except
38 * for the idlok function. Cthulu only knows why. Break things up into a
39 * minimal set of functions.
42 #ifndef HAVE_CURSES_WADDNSTR
46 * PUBLIC: #ifndef HAVE_CURSES_WADDNSTR
47 * PUBLIC: int waddnstr __P((WINDOW*, char *, int));
58 while (n
-- && (ch
= *s
++))
64 #ifndef HAVE_CURSES_BEEP
68 * PUBLIC: #ifndef HAVE_CURSES_BEEP
69 * PUBLIC: void beep __P((void));
75 (void)write(1, "\007", 1); /* '\a' */
77 #endif /* !HAVE_CURSES_BEEP */
79 #ifndef HAVE_CURSES_FLASH
84 * PUBLIC: #ifndef HAVE_CURSES_FLASH
85 * PUBLIC: void flash __P((void));
92 (void)tputs(vb
, 1, cl_putchar
);
97 #endif /* !HAVE_CURSES_FLASH */
99 #ifndef HAVE_CURSES_IDLOK
102 * Turn on/off hardware line insert/delete.
104 * PUBLIC: #ifndef HAVE_CURSES_IDLOK
105 * PUBLIC: void idlok __P((WINDOW *, int));
115 #endif /* !HAVE_CURSES_IDLOK */
117 #ifndef HAVE_CURSES_KEYPAD
120 * Put the keypad/cursor arrows into or out of application mode.
122 * PUBLIC: #ifndef HAVE_CURSES_KEYPAD
123 * PUBLIC: int keypad __P((void *, int));
133 if ((p
= tigetstr(on
? "smkx" : "rmkx")) != (char *)-1) {
134 (void)tputs(p
, 0, cl_putchar
);
135 (void)fflush(stdout
);
139 #endif /* !HAVE_CURSES_KEYPAD */
141 #ifndef HAVE_CURSES_NEWTERM
144 * Create a new curses screen.
146 * PUBLIC: #ifndef HAVE_CURSES_NEWTERM
147 * PUBLIC: void *newterm __P((const char *, FILE *, FILE *));
157 #endif /* !HAVE_CURSES_NEWTERM */
159 #ifndef HAVE_CURSES_SETUPTERM
164 * PUBLIC: #ifndef HAVE_CURSES_SETUPTERM
165 * PUBLIC: void setupterm __P((char *, int, int *));
169 setupterm(ttype
, fno
, errp
)
173 static char buf
[2048];
176 if ((*errp
= tgetent(buf
, ttype
)) > 0) {
179 ke
= ((p
= tigetstr("rmkx")) == (char *)-1) ?
183 ks
= ((p
= tigetstr("smkx")) == (char *)-1) ?
187 vb
= ((p
= tigetstr("flash")) == (char *)-1) ?
191 #endif /* !HAVE_CURSES_SETUPTERM */
193 #ifndef HAVE_CURSES_TIGETSTR
194 /* Terminfo-to-termcap translation table. */
196 char *terminfo
; /* Terminfo name. */
197 char *termcap
; /* Termcap name. */
199 static const TL list
[] = {
200 "cols", "co", /* Terminal columns. */
201 "cup", "cm", /* Cursor up. */
202 "cuu1", "up", /* Cursor up. */
203 "el", "ce", /* Clear to end-of-line. */
204 "flash", "vb", /* Visible bell. */
205 "kcub1", "kl", /* Cursor left. */
206 "kcud1", "kd", /* Cursor down. */
207 "kcuf1", "kr", /* Cursor right. */
208 "kcuu1", "ku", /* Cursor up. */
209 "kdch1", "kD", /* Delete character. */
210 "kdl1", "kL", /* Delete line. */
211 "ked", "kS", /* Delete to end of screen. */
212 "kel", "kE", /* Delete to eol. */
213 "kend", "@7", /* Go to eol. */
214 "khome", "kh", /* Go to sol. */
215 "kich1", "kI", /* Insert at cursor. */
216 "kil1", "kA", /* Insert line. */
217 "kind", "kF", /* Scroll down. */
218 "kll", "kH", /* Go to eol. */
219 "knp", "kN", /* Page down. */
220 "kpp", "kP", /* Page up. */
221 "kri", "kR", /* Scroll up. */
222 "lines", "li", /* Terminal lines. */
223 "rmcup", "te", /* Terminal end string. */
224 "rmkx", "ke", /* Exit "keypad-transmit" mode. */
225 "rmso", "se", /* Standout end. */
226 "smcup", "ti", /* Terminal initialization string. */
227 "smkx", "ks", /* Enter "keypad-transmit" mode. */
228 "smso", "so", /* Standout begin. */
233 * AIX's implementation for function keys greater than 10 is different and
234 * only goes as far as 36.
236 static const char codes
[] = {
237 /* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
238 /* 11-20 */ '<', '>', '!', '@', '#', '$', '%', '^', '&', '*',
239 /* 21-30 */ '(', ')', '-', '_', '+', ',', ':', '?', '[', ']',
240 /* 31-36 */ '{', '}', '|', '~', '/', '='
247 * Historically, the 4BSD termcap code didn't support functions keys greater
248 * than 9. This was silently enforced -- asking for key k12 would return the
249 * value for k1. We try and get around this by using the tables specified in
250 * the terminfo(TI_ENV) man page from the 3rd Edition SVID. This assumes the
251 * implementors of any System V compatibility code or an extended termcap used
254 static const char codes
[] = {
255 /* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
256 /* 11-19 */ '1', '2', '3', '4', '5', '6', '7', '8', '9',
257 /* 20-63 */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
258 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
259 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
260 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
266 * list comparison routine for bsearch.
272 return (strcmp(a
, ((TL
*)b
)->terminfo
));
278 * Vendors put the prototype for tigetstr into random include files, including
279 * <term.h>, which we can't include because it makes other systems unhappy.
280 * Try and work around the problem, since we only care about the return value.
282 * PUBLIC: #ifdef HAVE_CURSES_TIGETSTR
283 * PUBLIC: char *tigetstr();
285 * PUBLIC: char *tigetstr __P((char *));
292 static char sbuf
[256];
297 if ((tlp
= bsearch(name
,
298 list
, sizeof(list
) / sizeof(TL
), sizeof(TL
), lcmp
)) == NULL
) {
300 if (name
[0] == 'k' &&
301 name
[1] == 'f' && (n
= atoi(name
+ 2)) <= 36) {
303 keyname
[1] = codes
[n
];
306 if (name
[0] == 'k' &&
307 name
[1] == 'f' && (n
= atoi(name
+ 2)) <= 63) {
308 keyname
[0] = n
<= 10 ? 'k' : 'F';
309 keyname
[1] = codes
[n
];
319 return ((p
= tgetstr(name
, &p
)) == NULL
? (char *)-1 : strcpy(sbuf
, p
));
321 return (tgetstr(name
, &p
) == NULL
? (char *)-1 : sbuf
);
328 * PUBLIC: #ifndef HAVE_CURSES_TIGETSTR
329 * PUBLIC: int tigetnum __P((char *));
339 if ((tlp
= bsearch(name
,
340 list
, sizeof(list
) / sizeof(TL
), sizeof(TL
), lcmp
)) != NULL
) {
344 return ((val
= tgetnum(name
)) == -1 ? -2 : val
);
346 #endif /* !HAVE_CURSES_TIGETSTR */