Add keyname().

Fixes PR lib/20033.
Allow SMALL to be defined, to reduce the size of the library.
This commit is contained in:
jdc 2003-06-20 06:56:29 +00:00
parent 5879a5dcf6
commit c521d02fce
7 changed files with 580 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.45 2003/05/21 21:19:52 jdc Exp $
# $NetBSD: Makefile,v 1.46 2003/06/20 06:56:30 jdc Exp $
# @(#)Makefile 8.2 (Berkeley) 1/2/94
.include <bsd.own.mk>
@ -11,6 +11,9 @@ CFLAGS+=-g
CPPFLAGS+=-DDEBUG
.endif
.endif
.if defined(SMALL)
CPPFLAGS+=-DSMALL
.endif
LIB= curses
SRCS= acs.c addbytes.c addch.c addchnstr.c addnstr.c attributes.c \
background.c bell.c border.c box.c clear.c clearok.c clrtobot.c \
@ -18,6 +21,7 @@ SRCS= acs.c addbytes.c addch.c addchnstr.c addnstr.c attributes.c \
curses.c delch.c deleteln.c delwin.c erase.c flushok.c fullname.c \
getch.c getstr.c getyx.c id_subwins.c idlok.c idcok.c inch.c \
inchstr.c initscr.c insch.c insdelln.c insertln.c instr.c keypad.c \
keyname.c \
leaveok.c line.c longname.c meta.c move.c mvwin.c newwin.c nodelay.c \
notimeout.c overlay.c overwrite.c pause.c printw.c putchar.c \
refresh.c resize.c scanw.c screen.c scroll.c scrollok.c setterm.c \
@ -28,10 +32,11 @@ MAN= curses.3 curses_addch.3 curses_addchstr.3 curses_addstr.3 \
curses_attributes.3 curses_background.3 curses_border.3 \
curses_clear.3 curses_color.3 curses_cursor.3 curses_default_colors.3 \
curses_delch.3 curses_deleteln.3 curses_inch.3 curses_input.3 \
curses_insertch.3 curses_insertln.3 curses_insdelln.3 curses_line.3 \
curses_pad.3 curses_print.3 curses_refresh.3 curses_scanw.3 \
curses_screen.3 curses_scroll.3 curses_standout.3 curses_termcap.3 \
curses_touch.3 curses_tty.3 curses_underscore.3 curses_window.3
curses_insertch.3 curses_insertln.3 curses_insdelln.3 \
curses_keyname.3 curses_line.3 curses_pad.3 curses_print.3 \
curses_refresh.3 curses_scanw.3 curses_screen.3 curses_scroll.3 \
curses_standout.3 curses_termcap.3 curses_touch.3 curses_tty.3 \
curses_underscore.3 curses_window.3
INCS= curses.h unctrl.h
INCSDIR=/usr/include
@ -84,6 +89,7 @@ MLINKS+= curses_addch.3 addch.3 curses_addchstr.3 addchnstr.3 \
curses_insertln.3 insertln.3 curses_inch.3 instr.3 \
curses_tty.3 intrflush.3 curses_touch.3 is_linetouched.3 \
curses_touch.3 is_wintouched.3 curses_screen.3 isendwin.3 \
curses_keyname.3 keyname.3 \
curses_input.3 keypad.3 curses_tty.3 killchar.3 \
curses_refresh.3 leaveok.3 curses_termcap.3 longname.3 \
curses_tty.3 meta.3 curses_cursor.3 move.3 \

View File

@ -860,6 +860,11 @@ to FALSE the recognition of any sequence of characters
that have been associated with the key symbol will be disabled.
By default, this flag is TRUE so sequences will be recognised.
.Ds
.Fn keyname "int key"
.De
Returns a description of the key
.Vn key .
.Ds
.Fn keypad "WINDOW *win" "int boolf"
.De
Sets the boolean flag for interpretation of escape sequences. If

View File

@ -1,4 +1,4 @@
.\" $NetBSD: curses.3,v 1.47 2003/05/21 21:19:52 jdc Exp $
.\" $NetBSD: curses.3,v 1.48 2003/06/20 06:56:30 jdc Exp $
.\"
.\" Copyright (c) 1985, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -166,6 +166,7 @@ must be called before any of the other routines that deal with color are used.
.It is_linetouched Ta Xr curses_touch 3
.It is_wintouched Ta Xr curses_touch 3
.It isendwin Ta Xr curses_screen 3
.It keyname Ta Xr curses_keyname 3
.It keypad Ta Xr curses_input 3
.It keyok Ta Xr curses_input 3
.It killchar Ta Xr curses_tty 3

View File

@ -1,4 +1,4 @@
/* $NetBSD: curses.h,v 1.75 2003/05/21 21:19:52 jdc Exp $ */
/* $NetBSD: curses.h,v 1.76 2003/06/20 06:56:29 jdc Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -565,6 +565,7 @@ bool is_linetouched(WINDOW *, int);
bool is_wintouched(WINDOW *);
int keyok(int, bool);
void keypad(WINDOW *, bool);
char *keyname(int);
char killchar(void);
int leaveok(WINDOW *, bool);
char *longname(void);

View File

@ -1,4 +1,4 @@
.\" $NetBSD: curses_input.3,v 1.11 2003/04/16 13:35:01 wiz Exp $
.\" $NetBSD: curses_input.3,v 1.12 2003/06/20 06:56:30 jdc Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\"
.Dd April 8, 2003
.Dd June 13, 2003
.Dt CURSES_INPUT 3
.Os
.Sh NAME
@ -539,6 +539,7 @@ An error occurred in the function.
.El
.Sh SEE ALSO
.Xr curses_cursor 3 ,
.Xr curses_keyname 3 ,
.Xr curses_refresh 3 ,
.Xr curses_tty 3 ,
.Xr termcap 5

View File

@ -0,0 +1,70 @@
.\" $NetBSD: curses_keyname.3,v 1.1 2003/06/20 06:56:30 jdc Exp $
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Julian Coleman.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd Jun 13, 2003
.Dt CURSES_KEYNAME 3
.Os
.Sh NAME
.Nm curses_keyname ,
.Nm keyname
.Nd curses report key name routine
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft "char *"
.Fn keyname "int key"
.Sh DESCRIPTION
The function
.Fn keyname
generates a character string containing a description of the key specified in
.Fa key .
.Pp
The string is formatted according to the following table:
.Bl -column "Meta + control character" "KEY_MIN - KEY_MAX" "String format"
.It "Description" Ta "Key range" Ta "String format"
.It Li "Control character" Ta "0 - 31" Ta "^X"
.It Li "Visible character" Ta "32 - 126" Ta "X"
.It Li "Delete charaacter" Ta "127" Ta "^?"
.It Li "Meta + control character" Ta "128 - 158" Ta "M-^X"
.It Li "Meta + visible character" Ta "159 - 254" Ta "M-X"
.It Li "Meta + delete charaacter" Ta "255" Ta "M-^?"
.It Li "Named key" Ta "KEY_MIN - KEY_MAX" Ta "KEY_EXIT"
.El
.Sh SEE ALSO
.Xr curses_input 3
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
These functions first appeared in
.Nx 2.0 .

487
lib/libcurses/keyname.c Normal file
View File

@ -0,0 +1,487 @@
/* $NetBSD: keyname.c,v 1.1 2003/06/20 06:56:29 jdc Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Julian Coleman.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: keyname.c,v 1.1 2003/06/20 06:56:29 jdc Exp $");
#endif /* not lint */
#include <stdlib.h>
#include <string.h>
#include "curses.h"
#include "curses_private.h"
#define KEYNAMEMAX (size_t) 14 /* "KEY_BACKSPACE\0" */
/*
* keyname --
* Return name of key or NULL;
*/
char *
keyname(int key)
{
/* We don't bother with the large keyname table if SMALL is defined. */
#ifdef SMALL
return NULL;
#else
char *name;
if ((name = malloc(KEYNAMEMAX + 1)) == NULL)
return NULL;
if (key < 0)
return NULL;
/* Control codes */
if (key < 0x20) {
name[0] = '^';
name[1] = (char) (key + 64); /* Offset of '@' */
name[2] = '\0';
return name;
}
/* "Normal" keys */
if (key < 0x7F) {
name[0] = (char) key;
name[1] = '\0';
return name;
}
/* Delete key */
if (key == 0x7F) {
strcpy(name, "^?\0");
return name;
}
/* Meta + control codes */
if (key < 0x9F) {
strcpy(name, "M-^");
name[3] = (char) (key - 64); /* Offset of '@' */
name[4] = '\0';
return name;
}
/* Meta + "normal" keys */
if (key < 0xFF) {
strcpy (name, "M-");
name[2] = (char) (key - 128);
name[3] = '\0';
return name;
}
/* Meta + delete key */
if (key == 0xFF) {
strcpy(name, "M-^?\0");
return name;
}
/* No name. */
if (key == 0x100)
return NULL;
/* Key names. Synchronise this with curses.h. */
if (key == 0x101) {
strncpy(name, "KEY_BREAK\0", KEYNAMEMAX);
return name;
}
if (key == 0x102) {
strncpy(name, "KEY_DOWN\0", KEYNAMEMAX);
return name;
}
if (key == 0x103) {
strncpy(name, "KEY_UP\0", KEYNAMEMAX);
return name;
}
if (key == 0x104) {
strncpy(name, "KEY_LEFT\0", KEYNAMEMAX);
return name;
}
if (key == 0x105) {
strncpy(name, "KEY_RIGHT\0", KEYNAMEMAX);
return name;
}
if (key == 0x106) {
strncpy(name, "KEY_HOME\0", KEYNAMEMAX);
return name;
}
if (key == 0x107) {
strncpy(name, "KEY_BACKSPACE\0", KEYNAMEMAX);
return name;
}
/* Function key block (64 keys). */
if (key < 0x148) {
int i;
strcpy(name, "KEY_F(");
i = snprintf(&name[6], (size_t) 3, "%d", key - 0x108);
name[6 + i] = ')';
name[7 + i] = '\0';
return name;
}
if (key == 0x148) {
strncpy(name, "KEY_DL\0", KEYNAMEMAX);
return name;
}
if (key == 0x149) {
strncpy(name, "KEY_IL\0", KEYNAMEMAX);
return name;
}
if (key == 0x14A) {
strncpy(name, "KEY_DC\0", KEYNAMEMAX);
return name;
}
if (key == 0x14B) {
strncpy(name, "KEY_IC\0", KEYNAMEMAX);
return name;
}
if (key == 0x14C) {
strncpy(name, "KEY_EIC\0", KEYNAMEMAX);
return name;
}
if (key == 0x14D) {
strncpy(name, "KEY_CLEAR\0", KEYNAMEMAX);
return name;
}
if (key == 0x14E) {
strncpy(name, "KEY_EOS\0", KEYNAMEMAX);
return name;
}
if (key == 0x14F) {
strncpy(name, "KEY_EOL\0", KEYNAMEMAX);
return name;
}
if (key == 0x150) {
strncpy(name, "KEY_SF\0", KEYNAMEMAX);
return name;
}
if (key == 0x151) {
strncpy(name, "KEY_SR\0", KEYNAMEMAX);
return name;
}
if (key == 0x152) {
strncpy(name, "KEY_NPAGE\0", KEYNAMEMAX);
return name;
}
if (key == 0x153) {
strncpy(name, "KEY_PPAGE\0", KEYNAMEMAX);
return name;
}
if (key == 0x154) {
strncpy(name, "KEY_STAB\0", KEYNAMEMAX);
return name;
}
if (key == 0x155) {
strncpy(name, "KEY_CTAB\0", KEYNAMEMAX);
return name;
}
if (key == 0x156) {
strncpy(name, "KEY_CATAB\0", KEYNAMEMAX);
return name;
}
if (key == 0x157) {
strncpy(name, "KEY_ENTER\0", KEYNAMEMAX);
return name;
}
if (key == 0x158) {
strncpy(name, "KEY_SRESET\0", KEYNAMEMAX);
return name;
}
if (key == 0x159) {
strncpy(name, "KEY_RESET\0", KEYNAMEMAX);
return name;
}
if (key == 0x15A) {
strncpy(name, "KEY_PRINT\0", KEYNAMEMAX);
return name;
}
if (key == 0x15B) {
strncpy(name, "KEY_LL\0", KEYNAMEMAX);
return name;
}
if (key == 0x15C) {
strncpy(name, "KEY_A1\0", KEYNAMEMAX);
return name;
}
if (key == 0x15D) {
strncpy(name, "KEY_A3\0", KEYNAMEMAX);
return name;
}
if (key == 0x15E) {
strncpy(name, "KEY_B2\0", KEYNAMEMAX);
return name;
}
if (key == 0x15F) {
strncpy(name, "KEY_C1\0", KEYNAMEMAX);
return name;
}
if (key == 0x160) {
strncpy(name, "KEY_C3\0", KEYNAMEMAX);
return name;
}
if (key == 0x161) {
strncpy(name, "KEY_BTAB\0", KEYNAMEMAX);
return name;
}
if (key == 0x162) {
strncpy(name, "KEY_BEG\0", KEYNAMEMAX);
return name;
}
if (key == 0x163) {
strncpy(name, "KEY_CANCEL\0", KEYNAMEMAX);
return name;
}
if (key == 0x164) {
strncpy(name, "KEY_CLOSE\0", KEYNAMEMAX);
return name;
}
if (key == 0x165) {
strncpy(name, "KEY_COMMAND\0", KEYNAMEMAX);
return name;
}
if (key == 0x166) {
strncpy(name, "KEY_COPY\0", KEYNAMEMAX);
return name;
}
if (key == 0x167) {
strncpy(name, "KEY_CREATE\0", KEYNAMEMAX);
return name;
}
if (key == 0x168) {
strncpy(name, "KEY_END\0", KEYNAMEMAX);
return name;
}
if (key == 0x169) {
strncpy(name, "KEY_EXIT\0", KEYNAMEMAX);
return name;
}
if (key == 0x16A) {
strncpy(name, "KEY_FIND\0", KEYNAMEMAX);
return name;
}
if (key == 0x16B) {
strncpy(name, "KEY_HELP\0", KEYNAMEMAX);
return name;
}
if (key == 0x16C) {
strncpy(name, "KEY_MARK\0", KEYNAMEMAX);
return name;
}
if (key == 0x16D) {
strncpy(name, "KEY_MESSAGE\0", KEYNAMEMAX);
return name;
}
if (key == 0x16E) {
strncpy(name, "KEY_MOVE\0", KEYNAMEMAX);
return name;
}
if (key == 0x16F) {
strncpy(name, "KEY_NEXT\0", KEYNAMEMAX);
return name;
}
if (key == 0x170) {
strncpy(name, "KEY_OPEN\0", KEYNAMEMAX);
return name;
}
if (key == 0x171) {
strncpy(name, "KEY_OPTIONS\0", KEYNAMEMAX);
return name;
}
if (key == 0x172) {
strncpy(name, "KEY_PREVIOUS\0", KEYNAMEMAX);
return name;
}
if (key == 0x173) {
strncpy(name, "KEY_REDO\0", KEYNAMEMAX);
return name;
}
if (key == 0x174) {
strncpy(name, "KEY_REFERENCE\0", KEYNAMEMAX);
return name;
}
if (key == 0x175) {
strncpy(name, "KEY_REFRESH\0", KEYNAMEMAX);
return name;
}
if (key == 0x176) {
strncpy(name, "KEY_REPLACE\0", KEYNAMEMAX);
return name;
}
if (key == 0x177) {
strncpy(name, "KEY_RESTART\0", KEYNAMEMAX);
return name;
}
if (key == 0x178) {
strncpy(name, "KEY_RESUME\0", KEYNAMEMAX);
return name;
}
if (key == 0x179) {
strncpy(name, "KEY_SAVE\0", KEYNAMEMAX);
return name;
}
if (key == 0x17A) {
strncpy(name, "KEY_SBEG\0", KEYNAMEMAX);
return name;
}
if (key == 0x17B) {
strncpy(name, "KEY_SCANCEL\0", KEYNAMEMAX);
return name;
}
if (key == 0x17C) {
strncpy(name, "KEY_SCOMMAND\0", KEYNAMEMAX);
return name;
}
if (key == 0x17D) {
strncpy(name, "KEY_SCOPY\0", KEYNAMEMAX);
return name;
}
if (key == 0x17E) {
strncpy(name, "KEY_SCREATE\0", KEYNAMEMAX);
return name;
}
if (key == 0x17F) {
strncpy(name, "KEY_SDC\0", KEYNAMEMAX);
return name;
}
if (key == 0x180) {
strncpy(name, "KEY_SDL\0", KEYNAMEMAX);
return name;
}
if (key == 0x181) {
strncpy(name, "KEY_SELECT\0", KEYNAMEMAX);
return name;
}
if (key == 0x182) {
strncpy(name, "KEY_SEND\0", KEYNAMEMAX);
return name;
}
if (key == 0x183) {
strncpy(name, "KEY_SEOL\0", KEYNAMEMAX);
return name;
}
if (key == 0x184) {
strncpy(name, "KEY_SEXIT\0", KEYNAMEMAX);
return name;
}
if (key == 0x185) {
strncpy(name, "KEY_SFIND\0", KEYNAMEMAX);
return name;
}
if (key == 0x186) {
strncpy(name, "KEY_SHELP\0", KEYNAMEMAX);
return name;
}
if (key == 0x187) {
strncpy(name, "KEY_SHOME\0", KEYNAMEMAX);
return name;
}
if (key == 0x188) {
strncpy(name, "KEY_SIC\0", KEYNAMEMAX);
return name;
}
if (key == 0x189) {
strncpy(name, "KEY_SLEFT\0", KEYNAMEMAX);
return name;
}
if (key == 0x18A) {
strncpy(name, "KEY_SMESSAGE\0", KEYNAMEMAX);
return name;
}
if (key == 0x18B) {
strncpy(name, "KEY_SMOVE\0", KEYNAMEMAX);
return name;
}
if (key == 0x18C) {
strncpy(name, "KEY_SNEXT\0", KEYNAMEMAX);
return name;
}
if (key == 0x18D) {
strncpy(name, "KEY_SOPTIONS\0", KEYNAMEMAX);
return name;
}
if (key == 0x18E) {
strncpy(name, "KEY_SPREVIOUS\0", KEYNAMEMAX);
return name;
}
if (key == 0x18F) {
strncpy(name, "KEY_SPRINT\0", KEYNAMEMAX);
return name;
}
if (key == 0x190) {
strncpy(name, "KEY_SREDO\0", KEYNAMEMAX);
return name;
}
if (key == 0x191) {
strncpy(name, "KEY_SREPLACE\0", KEYNAMEMAX);
return name;
}
if (key == 0x192) {
strncpy(name, "KEY_SRIGHT\0", KEYNAMEMAX);
return name;
}
if (key == 0x193) {
strncpy(name, "KEY_SRSUME\0", KEYNAMEMAX);
return name;
}
if (key == 0x194) {
strncpy(name, "KEY_SSAVE\0", KEYNAMEMAX);
return name;
}
if (key == 0x195) {
strncpy(name, "KEY_SSUSPEND\0", KEYNAMEMAX);
return name;
}
if (key == 0x196) {
strncpy(name, "KEY_SUNDO\0", KEYNAMEMAX);
return name;
}
if (key == 0x197) {
strncpy(name, "KEY_SUSPEND\0", KEYNAMEMAX);
return name;
}
if (key == 0x198) {
strncpy(name, "KEY_UNDO\0", KEYNAMEMAX);
return name;
}
if (key == 0x199) {
strncpy(name, "KEY_MOUSE\0", KEYNAMEMAX);
return name;
}
/* No more names. */
return NULL;
#endif
}