1 /* $NetBSD: keyname.c,v 1.6 2008/04/28 20:23:01 martin Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: keyname.c,v 1.6 2008/04/28 20:23:01 martin Exp $");
41 #include "curses_private.h"
43 #define KEYNAMEMAX (size_t) 14 /* "KEY_BACKSPACE\0" */
44 static char name
[KEYNAMEMAX
+ 1];
48 * Return name of key or NULL;
53 /* We don't bother with the large keyname table if SMALL is defined. */
72 name
[1] = (char) (key
+ 64); /* Offset of '@' */
90 /* Meta + control codes */
93 name
[3] = (char) (key
- 64); /* Offset of '@' */
98 /* Meta + "normal" keys */
101 name
[2] = (char) (key
- 128);
106 /* Meta + delete key */
108 strcpy(name
, "M-^?\0");
112 /* Key names. Synchronise this with curses.h. */
114 strncpy(name
, "KEY_BREAK\0", KEYNAMEMAX
);
118 strncpy(name
, "KEY_DOWN\0", KEYNAMEMAX
);
122 strncpy(name
, "KEY_UP\0", KEYNAMEMAX
);
126 strncpy(name
, "KEY_LEFT\0", KEYNAMEMAX
);
130 strncpy(name
, "KEY_RIGHT\0", KEYNAMEMAX
);
134 strncpy(name
, "KEY_HOME\0", KEYNAMEMAX
);
138 strncpy(name
, "KEY_BACKSPACE\0", KEYNAMEMAX
);
141 /* Function key block (64 keys). */
145 strcpy(name
, "KEY_F(");
146 i
= snprintf(&name
[6], (size_t) 3, "%d", key
- 0x108);
152 strncpy(name
, "KEY_DL\0", KEYNAMEMAX
);
156 strncpy(name
, "KEY_IL\0", KEYNAMEMAX
);
160 strncpy(name
, "KEY_DC\0", KEYNAMEMAX
);
164 strncpy(name
, "KEY_IC\0", KEYNAMEMAX
);
168 strncpy(name
, "KEY_EIC\0", KEYNAMEMAX
);
172 strncpy(name
, "KEY_CLEAR\0", KEYNAMEMAX
);
176 strncpy(name
, "KEY_EOS\0", KEYNAMEMAX
);
180 strncpy(name
, "KEY_EOL\0", KEYNAMEMAX
);
184 strncpy(name
, "KEY_SF\0", KEYNAMEMAX
);
188 strncpy(name
, "KEY_SR\0", KEYNAMEMAX
);
192 strncpy(name
, "KEY_NPAGE\0", KEYNAMEMAX
);
196 strncpy(name
, "KEY_PPAGE\0", KEYNAMEMAX
);
200 strncpy(name
, "KEY_STAB\0", KEYNAMEMAX
);
204 strncpy(name
, "KEY_CTAB\0", KEYNAMEMAX
);
208 strncpy(name
, "KEY_CATAB\0", KEYNAMEMAX
);
212 strncpy(name
, "KEY_ENTER\0", KEYNAMEMAX
);
216 strncpy(name
, "KEY_SRESET\0", KEYNAMEMAX
);
220 strncpy(name
, "KEY_RESET\0", KEYNAMEMAX
);
224 strncpy(name
, "KEY_PRINT\0", KEYNAMEMAX
);
228 strncpy(name
, "KEY_LL\0", KEYNAMEMAX
);
232 strncpy(name
, "KEY_A1\0", KEYNAMEMAX
);
236 strncpy(name
, "KEY_A3\0", KEYNAMEMAX
);
240 strncpy(name
, "KEY_B2\0", KEYNAMEMAX
);
244 strncpy(name
, "KEY_C1\0", KEYNAMEMAX
);
248 strncpy(name
, "KEY_C3\0", KEYNAMEMAX
);
252 strncpy(name
, "KEY_BTAB\0", KEYNAMEMAX
);
256 strncpy(name
, "KEY_BEG\0", KEYNAMEMAX
);
260 strncpy(name
, "KEY_CANCEL\0", KEYNAMEMAX
);
264 strncpy(name
, "KEY_CLOSE\0", KEYNAMEMAX
);
268 strncpy(name
, "KEY_COMMAND\0", KEYNAMEMAX
);
272 strncpy(name
, "KEY_COPY\0", KEYNAMEMAX
);
276 strncpy(name
, "KEY_CREATE\0", KEYNAMEMAX
);
280 strncpy(name
, "KEY_END\0", KEYNAMEMAX
);
284 strncpy(name
, "KEY_EXIT\0", KEYNAMEMAX
);
288 strncpy(name
, "KEY_FIND\0", KEYNAMEMAX
);
292 strncpy(name
, "KEY_HELP\0", KEYNAMEMAX
);
296 strncpy(name
, "KEY_MARK\0", KEYNAMEMAX
);
300 strncpy(name
, "KEY_MESSAGE\0", KEYNAMEMAX
);
304 strncpy(name
, "KEY_MOVE\0", KEYNAMEMAX
);
308 strncpy(name
, "KEY_NEXT\0", KEYNAMEMAX
);
312 strncpy(name
, "KEY_OPEN\0", KEYNAMEMAX
);
316 strncpy(name
, "KEY_OPTIONS\0", KEYNAMEMAX
);
320 strncpy(name
, "KEY_PREVIOUS\0", KEYNAMEMAX
);
324 strncpy(name
, "KEY_REDO\0", KEYNAMEMAX
);
328 strncpy(name
, "KEY_REFERENCE\0", KEYNAMEMAX
);
332 strncpy(name
, "KEY_REFRESH\0", KEYNAMEMAX
);
336 strncpy(name
, "KEY_REPLACE\0", KEYNAMEMAX
);
340 strncpy(name
, "KEY_RESTART\0", KEYNAMEMAX
);
344 strncpy(name
, "KEY_RESUME\0", KEYNAMEMAX
);
348 strncpy(name
, "KEY_SAVE\0", KEYNAMEMAX
);
352 strncpy(name
, "KEY_SBEG\0", KEYNAMEMAX
);
356 strncpy(name
, "KEY_SCANCEL\0", KEYNAMEMAX
);
360 strncpy(name
, "KEY_SCOMMAND\0", KEYNAMEMAX
);
364 strncpy(name
, "KEY_SCOPY\0", KEYNAMEMAX
);
368 strncpy(name
, "KEY_SCREATE\0", KEYNAMEMAX
);
372 strncpy(name
, "KEY_SDC\0", KEYNAMEMAX
);
376 strncpy(name
, "KEY_SDL\0", KEYNAMEMAX
);
380 strncpy(name
, "KEY_SELECT\0", KEYNAMEMAX
);
384 strncpy(name
, "KEY_SEND\0", KEYNAMEMAX
);
388 strncpy(name
, "KEY_SEOL\0", KEYNAMEMAX
);
392 strncpy(name
, "KEY_SEXIT\0", KEYNAMEMAX
);
396 strncpy(name
, "KEY_SFIND\0", KEYNAMEMAX
);
400 strncpy(name
, "KEY_SHELP\0", KEYNAMEMAX
);
404 strncpy(name
, "KEY_SHOME\0", KEYNAMEMAX
);
408 strncpy(name
, "KEY_SIC\0", KEYNAMEMAX
);
412 strncpy(name
, "KEY_SLEFT\0", KEYNAMEMAX
);
416 strncpy(name
, "KEY_SMESSAGE\0", KEYNAMEMAX
);
420 strncpy(name
, "KEY_SMOVE\0", KEYNAMEMAX
);
424 strncpy(name
, "KEY_SNEXT\0", KEYNAMEMAX
);
428 strncpy(name
, "KEY_SOPTIONS\0", KEYNAMEMAX
);
432 strncpy(name
, "KEY_SPREVIOUS\0", KEYNAMEMAX
);
436 strncpy(name
, "KEY_SPRINT\0", KEYNAMEMAX
);
440 strncpy(name
, "KEY_SREDO\0", KEYNAMEMAX
);
444 strncpy(name
, "KEY_SREPLACE\0", KEYNAMEMAX
);
448 strncpy(name
, "KEY_SRIGHT\0", KEYNAMEMAX
);
452 strncpy(name
, "KEY_SRSUME\0", KEYNAMEMAX
);
456 strncpy(name
, "KEY_SSAVE\0", KEYNAMEMAX
);
460 strncpy(name
, "KEY_SSUSPEND\0", KEYNAMEMAX
);
464 strncpy(name
, "KEY_SUNDO\0", KEYNAMEMAX
);
468 strncpy(name
, "KEY_SUSPEND\0", KEYNAMEMAX
);
472 strncpy(name
, "KEY_UNDO\0", KEYNAMEMAX
);
476 strncpy(name
, "KEY_MOUSE\0", KEYNAMEMAX
);
480 strncpy(name
, "KEY_RESIZE\0", KEYNAMEMAX
);
484 strncpy(name
, "UNKOWN KEY\0", KEYNAMEMAX
);
490 * Return name of key or NULL;
493 key_name(wchar_t key
)
498 (void) keyname((int) key
);
500 if (!strncmp(name
, "M-", 2)) {
501 /* Remove the "M-" */
506 #endif /* HAVE_WCHAR */