xref: /titanic_51/usr/src/lib/libcurses/screen/keyname.sh (revision c10c16dec587a0662068f6e2991c29ed3a9db943)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License, Version 1.0 only
6# (the "License").  You may not use this file except in compliance
7# with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26
27#
28#	Copyright (c) 1988 AT&T
29#	  All Rights Reserved
30#
31
32#
33# University Copyright- Copyright (c) 1982, 1986, 1988
34# The Regents of the University of California
35# All Rights Reserved
36#
37# University Acknowledgment- Portions of this document are derived from
38# software developed by the University of California, Berkeley, and its
39# contributors.
40#
41
42#ident	"%Z%%M%	%I%	%E% SMI"
43
44rm -f keyname.c
45/usr/bin/echo "#include	\"curses_inc.h\"\n" > keyname.c
46/usr/bin/echo "static	char	*keystrings[] =\n\t\t{" >> keyname.c
47{
48    grep -v 'KEY_F(' keycaps | awk '{ print $5, $4 }' | sed -e 's/,//g' -e 's/KEY_//'
49    # These three aren't in keycaps
50    echo '0401 BREAK\n0530 SRESET\n0531 RESET'
51} |  sort -n | awk '
52    {
53	print "\t\t    \"" $2 "\",	/* " $1 " */"
54    }
55' >> keyname.c
56
57LAST=`tail -1 keyname.c | awk -F'"' '{print $2}'`
58cat << ! >> keyname.c
59		};
60
61char	*
62keyname(int key)
63{
64	static	char	buf[16];
65
66	if (key >= 0400) {
67		int	i;
68
69		if ((key == 0400) || (key > KEY_${LAST}))
70			return ("UNKNOWN KEY");
71		if (key > 0507)
72			i = key - (0401 + ((0507 - 0410) + 1));
73		else
74			if (key >= 0410) {
75				(void) sprintf(buf, "KEY_F(%d)", key - 0410);
76				goto ret_buf;
77			} else
78				i = key - 0401;
79		(void) sprintf(buf, "KEY_%s", keystrings[i]);
80		goto ret_buf;
81	}
82
83	if (key >= 0200) {
84#ifdef SYSV
85		if (SHELLTTYS.c_cflag & CS8)
86#else	/* SYSV */
87		if (SHELLTTY.c_cflag & CS8)
88#endif	/* SYSV */
89			(void) sprintf(buf, "%c", key);
90		else
91			(void) sprintf(buf, "M-%s", unctrl(key & 0177));
92		goto ret_buf;
93	}
94
95	if (key < 0) {
96		(void) sprintf(buf, "%d", key);
97ret_buf:
98		return (buf);
99	}
100
101	return (unctrl(key));
102}
103!
104exit 0
105