1 /* $NetBSD: cl_bsd.c,v 1.2 2013/11/22 15:52:05 christos Exp $ */
3 * Copyright (c) 1995, 1996
4 * Keith Bostic. All rights reserved.
6 * See the LICENSE file for redistribution information.
12 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 ";
15 #include <sys/types.h>
16 #include <sys/queue.h>
19 #include <bitstring.h>
28 #include "../common/common.h"
32 #ifndef HAVE_CURSES_SETUPTERM
33 static char *ke
; /* Keypad on. */
34 static char *ks
; /* Keypad off. */
35 static char *vb
; /* Visible bell string. */
39 * HP's support the entire System V curses package except for the tigetstr
40 * and tigetnum functions. Ultrix supports the BSD curses package except
41 * for the idlok function. Cthulu only knows why. Break things up into a
42 * minimal set of functions.
45 #ifndef HAVE_CURSES_WADDNSTR
49 * PUBLIC: #ifndef HAVE_CURSES_WADDNSTR
50 * PUBLIC: int waddnstr __P((WINDOW*, char *, int));
61 while (n
-- && (ch
= *s
++))
67 #ifndef HAVE_CURSES_BEEP
71 * PUBLIC: #ifndef HAVE_CURSES_BEEP
72 * PUBLIC: void beep __P((void));
78 (void)write(1, "\007", 1); /* '\a' */
80 #endif /* !HAVE_CURSES_BEEP */
82 #ifndef HAVE_CURSES_FLASH
87 * PUBLIC: #ifndef HAVE_CURSES_FLASH
88 * PUBLIC: void flash __P((void));
95 (void)tputs(vb
, 1, cl_putchar
);
100 #endif /* !HAVE_CURSES_FLASH */
102 #ifndef HAVE_CURSES_IDLOK
105 * Turn on/off hardware line insert/delete.
107 * PUBLIC: #ifndef HAVE_CURSES_IDLOK
108 * PUBLIC: void idlok __P((WINDOW *, int));
118 #endif /* !HAVE_CURSES_IDLOK */
120 #ifndef HAVE_CURSES_KEYPAD
123 * Put the keypad/cursor arrows into or out of application mode.
125 * PUBLIC: #ifndef HAVE_CURSES_KEYPAD
126 * PUBLIC: int keypad __P((void *, int));
136 if ((p
= tigetstr(on
? "smkx" : "rmkx")) != (char *)-1) {
137 (void)tputs(p
, 0, cl_putchar
);
138 (void)fflush(stdout
);
142 #endif /* !HAVE_CURSES_KEYPAD */
144 #ifndef HAVE_CURSES_NEWTERM
147 * Create a new curses screen.
149 * PUBLIC: #ifndef HAVE_CURSES_NEWTERM
150 * PUBLIC: void *newterm __P((const char *, FILE *, FILE *));
160 #endif /* !HAVE_CURSES_NEWTERM */
162 #ifndef HAVE_CURSES_SETUPTERM
167 * PUBLIC: #ifndef HAVE_CURSES_SETUPTERM
168 * PUBLIC: void setupterm __P((char *, int, int *));
172 setupterm(ttype
, fno
, errp
)
176 static char buf
[2048];
179 if ((*errp
= tgetent(buf
, ttype
)) > 0) {
182 ke
= ((p
= tigetstr("rmkx")) == (char *)-1) ?
186 ks
= ((p
= tigetstr("smkx")) == (char *)-1) ?
190 vb
= ((p
= tigetstr("flash")) == (char *)-1) ?
194 #endif /* !HAVE_CURSES_SETUPTERM */
196 #ifndef HAVE_CURSES_TIGETSTR
197 /* Terminfo-to-termcap translation table. */
199 const char *terminfo
; /* Terminfo name. */
200 const char *termcap
; /* Termcap name. */
202 static const TL list
[] = {
203 { "cols", "co", }, /* Terminal columns. */
204 { "cup", "cm", }, /* Cursor up. */
205 { "cuu1", "up", }, /* Cursor up. */
206 { "el", "ce", }, /* Clear to end-of-line. */
207 { "flash", "vb", }, /* Visible bell. */
208 { "kcub1", "kl", }, /* Cursor left. */
209 { "kcud1", "kd", }, /* Cursor down. */
210 { "kcuf1", "kr", }, /* Cursor right. */
211 { "kcuu1", "ku", }, /* Cursor up. */
212 { "kdch1", "kD", }, /* Delete character. */
213 { "kdl1", "kL", }, /* Delete line. */
214 { "ked", "kS", }, /* Delete to end of screen. */
215 { "kel", "kE", }, /* Delete to eol. */
216 { "kend", "@7", }, /* Go to eol. */
217 { "khome", "kh", }, /* Go to sol. */
218 { "kich1", "kI", }, /* Insert at cursor. */
219 { "kil1", "kA", }, /* Insert line. */
220 { "kind", "kF", }, /* Scroll down. */
221 { "kll", "kH", }, /* Go to eol. */
222 { "knp", "kN", }, /* Page down. */
223 { "kpp", "kP", }, /* Page up. */
224 { "kri", "kR", }, /* Scroll up. */
225 { "lines", "li", }, /* Terminal lines. */
226 { "rmcup", "te", }, /* Terminal end string. */
227 { "rmkx", "ke", }, /* Exit "keypad-transmit" mode. */
228 { "rmso", "se", }, /* Standout end. */
229 { "smcup", "ti", }, /* Terminal initialization string. */
230 { "smkx", "ks", }, /* Enter "keypad-transmit" mode. */
231 { "smso", "so", }, /* Standout begin. */
236 * AIX's implementation for function keys greater than 10 is different and
237 * only goes as far as 36.
239 static const char codes
[] = {
240 /* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
241 /* 11-20 */ '<', '>', '!', '@', '#', '$', '%', '^', '&', '*',
242 /* 21-30 */ '(', ')', '-', '_', '+', ',', ':', '?', '[', ']',
243 /* 31-36 */ '{', '}', '|', '~', '/', '='
250 * Historically, the 4BSD termcap code didn't support functions keys greater
251 * than 9. This was silently enforced -- asking for key k12 would return the
252 * value for k1. We try and get around this by using the tables specified in
253 * the terminfo(TI_ENV) man page from the 3rd Edition SVID. This assumes the
254 * implementors of any System V compatibility code or an extended termcap used
257 static const char codes
[] = {
258 /* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
259 /* 11-19 */ '1', '2', '3', '4', '5', '6', '7', '8', '9',
260 /* 20-63 */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
261 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
262 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
263 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
269 * list comparison routine for bsearch.
272 lcmp(const void *a
, const void *b
)
274 return (strcmp(a
, ((const TL
*)b
)->terminfo
));
280 * Vendors put the prototype for tigetstr into random include files, including
281 * <term.h>, which we can't include because it makes other systems unhappy.
282 * Try and work around the problem, since we only care about the return value.
284 * PUBLIC: #ifdef HAVE_CURSES_TIGETSTR
285 * PUBLIC: char *tigetstr __P((const char *));
287 * PUBLIC: char *tigetstr __P((char *));
294 static char sbuf
[256];
297 char *p
, mykeyname
[3];
299 if ((tlp
= bsearch(name
,
300 list
, sizeof(list
) / sizeof(TL
), sizeof(TL
), lcmp
)) == NULL
) {
302 if (name
[0] == 'k' &&
303 name
[1] == 'f' && (n
= atoi(name
+ 2)) <= 36) {
305 mykeyname
[1] = codes
[n
];
308 if (name
[0] == 'k' &&
309 name
[1] == 'f' && (n
= atoi(name
+ 2)) <= 63) {
310 mykeyname
[0] = n
<= 10 ? 'k' : 'F';
311 mykeyname
[1] = codes
[n
];
321 return ((p
= tgetstr(name
, &p
)) == NULL
? (char *)-1 : strcpy(sbuf
, p
));
323 return (tgetstr(name
, &p
) == NULL
? (char *)-1 : sbuf
);
330 * PUBLIC: #ifndef HAVE_CURSES_TIGETSTR
331 * PUBLIC: int tigetnum __P((char *));
341 if ((tlp
= bsearch(name
,
342 list
, sizeof(list
) / sizeof(TL
), sizeof(TL
), lcmp
)) != NULL
) {
346 return ((val
= tgetnum(name
)) == -1 ? -2 : val
);
348 #endif /* !HAVE_CURSES_TIGETSTR */