1 /* $NetBSD: cl_bsd.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1995, 1996
4 * Keith Bostic. All rights reserved.
6 * See the LICENSE file for redistribution information.
11 #include <sys/cdefs.h>
14 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 ";
17 __RCSID("$NetBSD: cl_bsd.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 #include <sys/types.h>
21 #include <sys/queue.h>
24 #include <bitstring.h>
33 #include "../common/common.h"
37 #ifndef HAVE_CURSES_SETUPTERM
38 static char *ke
; /* Keypad on. */
39 static char *ks
; /* Keypad off. */
40 static char *vb
; /* Visible bell string. */
44 * HP's support the entire System V curses package except for the tigetstr
45 * and tigetnum functions. Ultrix supports the BSD curses package except
46 * for the idlok function. Cthulu only knows why. Break things up into a
47 * minimal set of functions.
50 #ifndef HAVE_CURSES_WADDNSTR
54 * PUBLIC: #ifndef HAVE_CURSES_WADDNSTR
55 * PUBLIC: int waddnstr __P((WINDOW*, char *, int));
66 while (n
-- && (ch
= *s
++))
72 #ifndef HAVE_CURSES_BEEP
76 * PUBLIC: #ifndef HAVE_CURSES_BEEP
77 * PUBLIC: void beep __P((void));
83 (void)write(1, "\007", 1); /* '\a' */
85 #endif /* !HAVE_CURSES_BEEP */
87 #ifndef HAVE_CURSES_FLASH
92 * PUBLIC: #ifndef HAVE_CURSES_FLASH
93 * PUBLIC: void flash __P((void));
100 (void)tputs(vb
, 1, cl_putchar
);
101 (void)fflush(stdout
);
105 #endif /* !HAVE_CURSES_FLASH */
107 #ifndef HAVE_CURSES_IDLOK
110 * Turn on/off hardware line insert/delete.
112 * PUBLIC: #ifndef HAVE_CURSES_IDLOK
113 * PUBLIC: void idlok __P((WINDOW *, int));
123 #endif /* !HAVE_CURSES_IDLOK */
125 #ifndef HAVE_CURSES_KEYPAD
128 * Put the keypad/cursor arrows into or out of application mode.
130 * PUBLIC: #ifndef HAVE_CURSES_KEYPAD
131 * PUBLIC: int keypad __P((void *, int));
141 if ((p
= tigetstr(on
? "smkx" : "rmkx")) != (char *)-1) {
142 (void)tputs(p
, 0, cl_putchar
);
143 (void)fflush(stdout
);
147 #endif /* !HAVE_CURSES_KEYPAD */
149 #ifndef HAVE_CURSES_NEWTERM
152 * Create a new curses screen.
154 * PUBLIC: #ifndef HAVE_CURSES_NEWTERM
155 * PUBLIC: void *newterm __P((const char *, FILE *, FILE *));
165 #endif /* !HAVE_CURSES_NEWTERM */
167 #ifndef HAVE_CURSES_SETUPTERM
172 * PUBLIC: #ifndef HAVE_CURSES_SETUPTERM
173 * PUBLIC: void setupterm __P((char *, int, int *));
177 setupterm(ttype
, fno
, errp
)
181 static char buf
[2048];
184 if ((*errp
= tgetent(buf
, ttype
)) > 0) {
187 ke
= ((p
= tigetstr("rmkx")) == (char *)-1) ?
191 ks
= ((p
= tigetstr("smkx")) == (char *)-1) ?
195 vb
= ((p
= tigetstr("flash")) == (char *)-1) ?
199 #endif /* !HAVE_CURSES_SETUPTERM */
201 #ifndef HAVE_CURSES_TIGETSTR
202 /* Terminfo-to-termcap translation table. */
204 const char *terminfo
; /* Terminfo name. */
205 const char *termcap
; /* Termcap name. */
207 static const TL list
[] = {
208 { "cols", "co", }, /* Terminal columns. */
209 { "cup", "cm", }, /* Cursor up. */
210 { "cuu1", "up", }, /* Cursor up. */
211 { "el", "ce", }, /* Clear to end-of-line. */
212 { "flash", "vb", }, /* Visible bell. */
213 { "kcub1", "kl", }, /* Cursor left. */
214 { "kcud1", "kd", }, /* Cursor down. */
215 { "kcuf1", "kr", }, /* Cursor right. */
216 { "kcuu1", "ku", }, /* Cursor up. */
217 { "kdch1", "kD", }, /* Delete character. */
218 { "kdl1", "kL", }, /* Delete line. */
219 { "ked", "kS", }, /* Delete to end of screen. */
220 { "kel", "kE", }, /* Delete to eol. */
221 { "kend", "@7", }, /* Go to eol. */
222 { "khome", "kh", }, /* Go to sol. */
223 { "kich1", "kI", }, /* Insert at cursor. */
224 { "kil1", "kA", }, /* Insert line. */
225 { "kind", "kF", }, /* Scroll down. */
226 { "kll", "kH", }, /* Go to eol. */
227 { "knp", "kN", }, /* Page down. */
228 { "kpp", "kP", }, /* Page up. */
229 { "kri", "kR", }, /* Scroll up. */
230 { "lines", "li", }, /* Terminal lines. */
231 { "rmcup", "te", }, /* Terminal end string. */
232 { "rmkx", "ke", }, /* Exit "keypad-transmit" mode. */
233 { "rmso", "se", }, /* Standout end. */
234 { "smcup", "ti", }, /* Terminal initialization string. */
235 { "smkx", "ks", }, /* Enter "keypad-transmit" mode. */
236 { "smso", "so", }, /* Standout begin. */
241 * AIX's implementation for function keys greater than 10 is different and
242 * only goes as far as 36.
244 static const char codes
[] = {
245 /* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
246 /* 11-20 */ '<', '>', '!', '@', '#', '$', '%', '^', '&', '*',
247 /* 21-30 */ '(', ')', '-', '_', '+', ',', ':', '?', '[', ']',
248 /* 31-36 */ '{', '}', '|', '~', '/', '='
255 * Historically, the 4BSD termcap code didn't support functions keys greater
256 * than 9. This was silently enforced -- asking for key k12 would return the
257 * value for k1. We try and get around this by using the tables specified in
258 * the terminfo(TI_ENV) man page from the 3rd Edition SVID. This assumes the
259 * implementors of any System V compatibility code or an extended termcap used
262 static const char codes
[] = {
263 /* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
264 /* 11-19 */ '1', '2', '3', '4', '5', '6', '7', '8', '9',
265 /* 20-63 */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
266 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
267 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
268 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
274 * list comparison routine for bsearch.
277 lcmp(const void *a
, const void *b
)
279 return (strcmp(a
, ((const TL
*)b
)->terminfo
));
285 * Vendors put the prototype for tigetstr into random include files, including
286 * <term.h>, which we can't include because it makes other systems unhappy.
287 * Try and work around the problem, since we only care about the return value.
289 * PUBLIC: #ifdef HAVE_CURSES_TIGETSTR
290 * PUBLIC: char *tigetstr __P((const char *));
292 * PUBLIC: char *tigetstr __P((char *));
299 static char sbuf
[256];
302 char *p
, mykeyname
[3];
304 if ((tlp
= bsearch(name
,
305 list
, sizeof(list
) / sizeof(TL
), sizeof(TL
), lcmp
)) == NULL
) {
307 if (name
[0] == 'k' &&
308 name
[1] == 'f' && (n
= atoi(name
+ 2)) <= 36) {
310 mykeyname
[1] = codes
[n
];
313 if (name
[0] == 'k' &&
314 name
[1] == 'f' && (n
= atoi(name
+ 2)) <= 63) {
315 mykeyname
[0] = n
<= 10 ? 'k' : 'F';
316 mykeyname
[1] = codes
[n
];
326 return ((p
= tgetstr(name
, &p
)) == NULL
? (char *)-1 : strcpy(sbuf
, p
));
328 return (tgetstr(name
, &p
) == NULL
? (char *)-1 : sbuf
);
335 * PUBLIC: #ifndef HAVE_CURSES_TIGETSTR
336 * PUBLIC: int tigetnum __P((char *));
346 if ((tlp
= bsearch(name
,
347 list
, sizeof(list
) / sizeof(TL
), sizeof(TL
), lcmp
)) != NULL
) {
351 return ((val
= tgetnum(name
)) == -1 ? -2 : val
);
353 #endif /* !HAVE_CURSES_TIGETSTR */