MKkeyname.awk revision 50276
150276Speter# $Id: MKkeyname.awk,v 1.17 1999/02/18 11:18:06 tom Exp $
250276Speter##############################################################################
350276Speter# Copyright (c) 1999 Free Software Foundation, Inc.                          #
450276Speter#                                                                            #
550276Speter# Permission is hereby granted, free of charge, to any person obtaining a    #
650276Speter# copy of this software and associated documentation files (the "Software"), #
750276Speter# to deal in the Software without restriction, including without limitation  #
850276Speter# the rights to use, copy, modify, merge, publish, distribute, distribute    #
950276Speter# with modifications, sublicense, and/or sell copies of the Software, and to #
1050276Speter# permit persons to whom the Software is furnished to do so, subject to the  #
1150276Speter# following conditions:                                                      #
1250276Speter#                                                                            #
1350276Speter# The above copyright notice and this permission notice shall be included in #
1450276Speter# all copies or substantial portions of the Software.                        #
1550276Speter#                                                                            #
1650276Speter# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
1750276Speter# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
1850276Speter# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
1950276Speter# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
2050276Speter# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
2150276Speter# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
2250276Speter# DEALINGS IN THE SOFTWARE.                                                  #
2350276Speter#                                                                            #
2450276Speter# Except as contained in this notice, the name(s) of the above copyright     #
2550276Speter# holders shall not be used in advertising or otherwise to promote the sale, #
2650276Speter# use or other dealings in this Software without prior written               #
2750276Speter# authorization.                                                             #
2850276Speter##############################################################################
2950276SpeterBEGIN {
3050276Speter	print "/* generated by MKkeyname.awk */"
3150276Speter	print ""
3250276Speter	print "#include <ncurses_cfg.h>"
3350276Speter	print "#include <stdlib.h>"
3450276Speter	print "#include <string.h>"
3550276Speter	print "#include <curses.h>"
3650276Speter	print "#include <tic.h>"
3750276Speter	print ""
3850276Speter	print "const struct kn _nc_key_names[] = {"
3950276Speter}
4050276Speter
4150276Speter/^[^#]/ {
4250276Speter	printf "\t{ \"%s\", %s },\n", $1, $1;
4350276Speter	}
4450276Speter
4550276SpeterEND {
4650276Speter	printf "\t{ 0, 0 }};\n"
4750276Speter	print ""
4850276Speter	print "NCURSES_CONST char *keyname(int c)"
4950276Speter	print "{"
5050276Speter	print "int i;"
5150276Speter	print "static char name[20];"
5250276Speter	print "char *p;"
5350276Speter	print ""
5450276Speter	print "\tfor (i = 0; _nc_key_names[i].name != 0; i++)"
5550276Speter	print "\t\tif (_nc_key_names[i].code == c)"
5650276Speter	print "\t\t\treturn (NCURSES_CONST char *)_nc_key_names[i].name;"
5750276Speter	print "\tif (c >= 256) return \"UNKNOWN KEY\";"
5850276Speter	print "\tp = name;"
5950276Speter	print "\tif (c >= 128) {"
6050276Speter	print "\t\tstrcpy(p, \"M-\");"
6150276Speter	print "\t\tp += 2;"
6250276Speter	print "\t\tc -= 128;"
6350276Speter	print "\t}"
6450276Speter	print "\tif (c < 0)"
6550276Speter	print "\t\tsprintf(p, \"%d\", c);"
6650276Speter	print "\telse if (c < 32)"
6750276Speter	print "\t\tsprintf(p, \"^%c\", c + '@');"
6850276Speter	print "\telse if (c == 127)"
6950276Speter	print "\t\tstrcpy(p, \"^?\");"
7050276Speter	print "\telse"
7150276Speter	print "\t\tsprintf(p, \"%c\", c);"
7250276Speter	print "\treturn (NCURSES_CONST char *)name;"
7350276Speter	print "}"
7450276Speter}
75