1 /* $NetBSD: cl_bsd.c,v 1.2 2008/05/20 17:52:10 aymeric Exp $ */
4 * Copyright (c) 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 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";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
29 #include "../common/common.h"
33 static char *ke
; /* Keypad on. */
34 static char *ks
; /* Keypad off. */
35 static char *vb
; /* Visible bell string. */
38 * HP's support the entire System V curses package except for the tigetstr
39 * and tigetnum functions. Ultrix supports the BSD curses package except
40 * for the idlok function. Cthulu only knows why. Break things up into a
41 * minimal set of functions.
44 #ifndef HAVE_CURSES_WADDNSTR
48 * PUBLIC: #ifndef HAVE_CURSES_WADDNSTR
49 * PUBLIC: int waddnstr __P((WINDOW*, char *, int));
60 while (n
-- && (ch
= *s
++))
66 #ifndef HAVE_CURSES_BEEP
70 * PUBLIC: #ifndef HAVE_CURSES_BEEP
71 * PUBLIC: void beep __P((void));
77 (void)write(1, "\007", 1); /* '\a' */
79 #endif /* !HAVE_CURSES_BEEP */
81 #ifndef HAVE_CURSES_FLASH
86 * PUBLIC: #ifndef HAVE_CURSES_FLASH
87 * PUBLIC: void flash __P((void));
94 (void)tputs(vb
, 1, cl_putchar
);
99 #endif /* !HAVE_CURSES_FLASH */
101 #ifndef HAVE_CURSES_IDLOK
104 * Turn on/off hardware line insert/delete.
106 * PUBLIC: #ifndef HAVE_CURSES_IDLOK
107 * PUBLIC: void idlok __P((WINDOW *, int));
117 #endif /* !HAVE_CURSES_IDLOK */
119 #ifndef HAVE_CURSES_KEYPAD
122 * Put the keypad/cursor arrows into or out of application mode.
124 * PUBLIC: #ifndef HAVE_CURSES_KEYPAD
125 * PUBLIC: int keypad __P((void *, int));
135 if ((p
= tigetstr(on
? "smkx" : "rmkx")) != (char *)-1) {
136 (void)tputs(p
, 0, cl_putchar
);
137 (void)fflush(stdout
);
141 #endif /* !HAVE_CURSES_KEYPAD */
143 #ifndef HAVE_CURSES_NEWTERM
146 * Create a new curses screen.
148 * PUBLIC: #ifndef HAVE_CURSES_NEWTERM
149 * PUBLIC: void *newterm __P((const char *, FILE *, FILE *));
159 #endif /* !HAVE_CURSES_NEWTERM */
161 #ifndef HAVE_CURSES_SETUPTERM
166 * PUBLIC: #ifndef HAVE_CURSES_SETUPTERM
167 * PUBLIC: void setupterm __P((char *, int, int *));
171 setupterm(ttype
, fno
, errp
)
175 static char buf
[2048];
178 if ((*errp
= tgetent(buf
, ttype
)) > 0) {
181 ke
= ((p
= tigetstr("rmkx")) == (char *)-1) ?
185 ks
= ((p
= tigetstr("smkx")) == (char *)-1) ?
189 vb
= ((p
= tigetstr("flash")) == (char *)-1) ?
193 #endif /* !HAVE_CURSES_SETUPTERM */
195 #ifndef HAVE_CURSES_TIGETSTR
196 /* Terminfo-to-termcap translation table. */
198 const char *terminfo
; /* Terminfo name. */
199 const char *termcap
; /* Termcap name. */
201 static const TL list
[] = {
202 { "cols", "co", }, /* Terminal columns. */
203 { "cup", "cm", }, /* Cursor up. */
204 { "cuu1", "up", }, /* Cursor up. */
205 { "el", "ce", }, /* Clear to end-of-line. */
206 { "flash", "vb", }, /* Visible bell. */
207 { "kcub1", "kl", }, /* Cursor left. */
208 { "kcud1", "kd", }, /* Cursor down. */
209 { "kcuf1", "kr", }, /* Cursor right. */
210 { "kcuu1", "ku", }, /* Cursor up. */
211 { "kdch1", "kD", }, /* Delete character. */
212 { "kdl1", "kL", }, /* Delete line. */
213 { "ked", "kS", }, /* Delete to end of screen. */
214 { "kel", "kE", }, /* Delete to eol. */
215 { "kend", "@7", }, /* Go to eol. */
216 { "khome", "kh", }, /* Go to sol. */
217 { "kich1", "kI", }, /* Insert at cursor. */
218 { "kil1", "kA", }, /* Insert line. */
219 { "kind", "kF", }, /* Scroll down. */
220 { "kll", "kH", }, /* Go to eol. */
221 { "knp", "kN", }, /* Page down. */
222 { "kpp", "kP", }, /* Page up. */
223 { "kri", "kR", }, /* Scroll up. */
224 { "lines", "li", }, /* Terminal lines. */
225 { "rmcup", "te", }, /* Terminal end string. */
226 { "rmkx", "ke", }, /* Exit "keypad-transmit" mode. */
227 { "rmso", "se", }, /* Standout end. */
228 { "smcup", "ti", }, /* Terminal initialization string. */
229 { "smkx", "ks", }, /* Enter "keypad-transmit" mode. */
230 { "smso", "so", }, /* Standout begin. */
235 * AIX's implementation for function keys greater than 10 is different and
236 * only goes as far as 36.
238 static const char codes
[] = {
239 /* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
240 /* 11-20 */ '<', '>', '!', '@', '#', '$', '%', '^', '&', '*',
241 /* 21-30 */ '(', ')', '-', '_', '+', ',', ':', '?', '[', ']',
242 /* 31-36 */ '{', '}', '|', '~', '/', '='
249 * Historically, the 4BSD termcap code didn't support functions keys greater
250 * than 9. This was silently enforced -- asking for key k12 would return the
251 * value for k1. We try and get around this by using the tables specified in
252 * the terminfo(TI_ENV) man page from the 3rd Edition SVID. This assumes the
253 * implementors of any System V compatibility code or an extended termcap used
256 static const char codes
[] = {
257 /* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
258 /* 11-19 */ '1', '2', '3', '4', '5', '6', '7', '8', '9',
259 /* 20-63 */ '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',
261 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
262 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
268 * list comparison routine for bsearch.
271 lcmp(const void *a
, const void *b
)
273 return (strcmp(a
, ((const TL
*)b
)->terminfo
));
279 * Vendors put the prototype for tigetstr into random include files, including
280 * <term.h>, which we can't include because it makes other systems unhappy.
281 * Try and work around the problem, since we only care about the return value.
283 * PUBLIC: #ifdef HAVE_CURSES_TIGETSTR
284 * PUBLIC: char *tigetstr();
286 * PUBLIC: char *tigetstr __P((char *));
293 static char sbuf
[256];
296 char *p
, mykeyname
[3];
298 if ((tlp
= bsearch(name
,
299 list
, sizeof(list
) / sizeof(TL
), sizeof(TL
), lcmp
)) == NULL
) {
301 if (name
[0] == 'k' &&
302 name
[1] == 'f' && (n
= atoi(name
+ 2)) <= 36) {
304 mykeyname
[1] = codes
[n
];
307 if (name
[0] == 'k' &&
308 name
[1] == 'f' && (n
= atoi(name
+ 2)) <= 63) {
309 mykeyname
[0] = n
<= 10 ? 'k' : 'F';
310 mykeyname
[1] = codes
[n
];
320 return ((p
= tgetstr(name
, &p
)) == NULL
? (char *)-1 : strcpy(sbuf
, p
));
322 return (tgetstr(name
, &p
) == NULL
? (char *)-1 : sbuf
);
329 * PUBLIC: #ifndef HAVE_CURSES_TIGETSTR
330 * PUBLIC: int tigetnum __P((char *));
340 if ((tlp
= bsearch(name
,
341 list
, sizeof(list
) / sizeof(TL
), sizeof(TL
), lcmp
)) != NULL
) {
345 return ((val
= tgetnum(name
)) == -1 ? -2 : val
);
347 #endif /* !HAVE_CURSES_TIGETSTR */