]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/MKkeyname.awk
ncurses 4.2
[ncurses.git] / ncurses / MKkeyname.awk
index 8518bf2335fd518ef7935fa10109c9d17174c357..98ea404fae0fb9306d7cb866b9985c4958712ed3 100644 (file)
@@ -1,10 +1,12 @@
-# $Id: MKkeyname.awk,v 1.6 1997/04/05 23:38:17 tom Exp $
+# $Id: MKkeyname.awk,v 1.12 1997/11/15 22:16:55 tom Exp $
 BEGIN {
+       print "/* generated by MKkeyname.awk */"
        print ""
        print "#include <ncurses_cfg.h>"
        print "#include <stdlib.h>"
-       print "#include <term.h>"
+       print "#include <string.h>"
        print "#include <curses.h>"
+       print "#include <term.h>"
        print ""
        print "struct kn {"
        print "\tconst char *name;"
@@ -14,7 +16,10 @@ BEGIN {
        print "const struct kn key_names[] = {"
 }
 
-{printf "\t{\"%s\", %s,},\n", $1, $2;}
+/^[^#]/ {
+#      printf "\t{ \"%s\",%*s%s },\n", $1, 16-length($1), " ", $1;
+       printf "\t{ \"%s\",%s },\n", $1, $1;
+       }
 
 END {
        print "};"
@@ -22,11 +27,28 @@ END {
        print "const char *keyname(int c)"
        print "{"
        print "int i, size = sizeof(key_names)/sizeof(struct kn);"
+       print "static char name[5];"
+       print "char *p;"
        print ""
-       print "\tfor (i = 0; i < size; i++) {"
-       print "\t\tif (key_names[i].code == c) return key_names[i].name;"
+       print "\tfor (i = 0; i < size; i++)"
+       print "\t\tif (key_names[i].code == c)"
+       print "\t\t\treturn key_names[i].name;"
+       print "\tif (c >= 256) return \"UNKNOWN KEY\";"
+       print "\tp = name;"
+       print "\tif (c >= 128) {"
+       print "\t\tstrcpy(p, \"M-\");"
+       print "\t\tp += 2;"
+       print "\t\tc -= 128;"
        print "\t}"
-       print "\treturn NULL;"
+       print "\tif (c < 0)"
+       print "\t\tsprintf(p, \"%d\", c);"
+       print "\telse if (c < 32)"
+       print "\t\tsprintf(p, \"^%c\", c + '@');"
+       print "\telse if (c == 127)"
+       print "\t\tstrcpy(p, \"^?\");"
+       print "\telse"
+       print "\t\tsprintf(p, \"%c\", c);"
+       print "\treturn name;"
        print "}"
        print "" 
 }