xref: /titanic_50/usr/src/lib/libcurses/screen/keyname.sh (revision fca4268092e9961ebb9b5e0098dcebc545023586)
17c478bd9Sstevel@tonic-gate#
27c478bd9Sstevel@tonic-gate# CDDL HEADER START
37c478bd9Sstevel@tonic-gate#
47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate# with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23*fca42680SGary Mills# Copyright 2015 Gary Mills
247c478bd9Sstevel@tonic-gate# Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate#	Copyright (c) 1988 AT&T
307c478bd9Sstevel@tonic-gate#	  All Rights Reserved
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate#
347c478bd9Sstevel@tonic-gate# University Copyright- Copyright (c) 1982, 1986, 1988
357c478bd9Sstevel@tonic-gate# The Regents of the University of California
367c478bd9Sstevel@tonic-gate# All Rights Reserved
377c478bd9Sstevel@tonic-gate#
387c478bd9Sstevel@tonic-gate# University Acknowledgment- Portions of this document are derived from
397c478bd9Sstevel@tonic-gate# software developed by the University of California, Berkeley, and its
407c478bd9Sstevel@tonic-gate# contributors.
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gaterm -f keyname.c
44*fca42680SGary Mills/usr/bin/print "#include	\"curses_inc.h\"\n" > keyname.c
45*fca42680SGary Mills/usr/bin/print "static	char	*keystrings[] =\n\t\t{" >> keyname.c
467c478bd9Sstevel@tonic-gate{
477c478bd9Sstevel@tonic-gate    grep -v 'KEY_F(' keycaps | awk '{ print $5, $4 }' | sed -e 's/,//g' -e 's/KEY_//'
487c478bd9Sstevel@tonic-gate    # These three aren't in keycaps
497c478bd9Sstevel@tonic-gate    echo '0401 BREAK\n0530 SRESET\n0531 RESET'
507c478bd9Sstevel@tonic-gate} |  sort -n | awk '
517c478bd9Sstevel@tonic-gate    {
527c478bd9Sstevel@tonic-gate	print "\t\t    \"" $2 "\",	/* " $1 " */"
537c478bd9Sstevel@tonic-gate    }
547c478bd9Sstevel@tonic-gate' >> keyname.c
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gateLAST=`tail -1 keyname.c | awk -F'"' '{print $2}'`
577c478bd9Sstevel@tonic-gatecat << ! >> keyname.c
587c478bd9Sstevel@tonic-gate		};
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gatechar	*
617c478bd9Sstevel@tonic-gatekeyname(int key)
627c478bd9Sstevel@tonic-gate{
637c478bd9Sstevel@tonic-gate	static	char	buf[16];
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate	if (key >= 0400) {
667c478bd9Sstevel@tonic-gate		int	i;
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate		if ((key == 0400) || (key > KEY_${LAST}))
697c478bd9Sstevel@tonic-gate			return ("UNKNOWN KEY");
707c478bd9Sstevel@tonic-gate		if (key > 0507)
717c478bd9Sstevel@tonic-gate			i = key - (0401 + ((0507 - 0410) + 1));
727c478bd9Sstevel@tonic-gate		else
737c478bd9Sstevel@tonic-gate			if (key >= 0410) {
747c478bd9Sstevel@tonic-gate				(void) sprintf(buf, "KEY_F(%d)", key - 0410);
757c478bd9Sstevel@tonic-gate				goto ret_buf;
767c478bd9Sstevel@tonic-gate			} else
777c478bd9Sstevel@tonic-gate				i = key - 0401;
787c478bd9Sstevel@tonic-gate		(void) sprintf(buf, "KEY_%s", keystrings[i]);
797c478bd9Sstevel@tonic-gate		goto ret_buf;
807c478bd9Sstevel@tonic-gate	}
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate	if (key >= 0200) {
837c478bd9Sstevel@tonic-gate#ifdef SYSV
847c478bd9Sstevel@tonic-gate		if (SHELLTTYS.c_cflag & CS8)
857c478bd9Sstevel@tonic-gate#else	/* SYSV */
867c478bd9Sstevel@tonic-gate		if (SHELLTTY.c_cflag & CS8)
877c478bd9Sstevel@tonic-gate#endif	/* SYSV */
887c478bd9Sstevel@tonic-gate			(void) sprintf(buf, "%c", key);
897c478bd9Sstevel@tonic-gate		else
907c478bd9Sstevel@tonic-gate			(void) sprintf(buf, "M-%s", unctrl(key & 0177));
917c478bd9Sstevel@tonic-gate		goto ret_buf;
927c478bd9Sstevel@tonic-gate	}
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate	if (key < 0) {
957c478bd9Sstevel@tonic-gate		(void) sprintf(buf, "%d", key);
967c478bd9Sstevel@tonic-gateret_buf:
977c478bd9Sstevel@tonic-gate		return (buf);
987c478bd9Sstevel@tonic-gate	}
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate	return (unctrl(key));
1017c478bd9Sstevel@tonic-gate}
1027c478bd9Sstevel@tonic-gate!
1037c478bd9Sstevel@tonic-gateexit 0
104