X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2FMKkeyname.awk;h=4bf83eafbcaf28a3d5a23c7e100f60bd4e5e501a;hp=aaeb4743cdfe81b86f70a8f3bfeba08819ba6343;hb=46722468f47c2b77b3987729b4bcf2321cccfd01;hpb=0eb88fc5281804773e2a0c7a488a4452463535ce diff --git a/ncurses/base/MKkeyname.awk b/ncurses/base/MKkeyname.awk index aaeb4743..4bf83eaf 100644 --- a/ncurses/base/MKkeyname.awk +++ b/ncurses/base/MKkeyname.awk @@ -1,6 +1,6 @@ -# $Id: MKkeyname.awk,v 1.17 1999/02/18 11:18:06 tom Exp $ +# $Id: MKkeyname.awk,v 1.24 2002/09/01 19:43:34 tom Exp $ ############################################################################## -# Copyright (c) 1999 Free Software Foundation, Inc. # +# Copyright (c) 1999-2001,2002 Free Software Foundation, Inc. # # # # Permission is hereby granted, free of charge, to any person obtaining a # # copy of this software and associated documentation files (the "Software"), # @@ -29,10 +29,7 @@ BEGIN { print "/* generated by MKkeyname.awk */" print "" - print "#include " - print "#include " - print "#include " - print "#include " + print "#include " print "#include " print "" print "const struct kn _nc_key_names[] = {" @@ -45,30 +42,49 @@ BEGIN { END { printf "\t{ 0, 0 }};\n" print "" - print "NCURSES_CONST char *keyname(int c)" + print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)" print "{" + print "static char **table;" print "int i;" - print "static char name[20];" + print "char name[20];" print "char *p;" print "" + print "\tif (c == -1) return \"-1\";" + print "" print "\tfor (i = 0; _nc_key_names[i].name != 0; i++)" print "\t\tif (_nc_key_names[i].code == c)" print "\t\t\treturn (NCURSES_CONST char *)_nc_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 "\tif (c < 0 || c >= 256) return 0;" + print "" + print "\tif (table == 0)" + print "\t\ttable = typeCalloc(char *, 256);" + print "\tif (table == 0)" + print "\t\treturn keyname(256);" + print "" + print "\tif (table[c] == 0) {" + print "\t\tp = name;" + print "\t\tif (c >= 128) {" + print "\t\t\tstrcpy(p, \"M-\");" + print "\t\t\tp += 2;" + print "\t\t\tc -= 128;" + print "\t\t}" + print "\t\tif (c < 32)" + print "\t\t\tsprintf(p, \"^%c\", c + '@');" + print "\t\telse if (c == 127)" + print "\t\t\tstrcpy(p, \"^?\");" + print "\t\telse" + print "\t\t\tsprintf(p, \"%c\", c);" + print "\t\ttable[c] = strdup(name);" print "\t}" - 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 (NCURSES_CONST char *)name;" + print "\treturn (NCURSES_CONST char *)table[c];" + print "}" + print "" + print "#if USE_WIDEC_SUPPORT" + print "NCURSES_EXPORT(NCURSES_CONST char *) key_name (wchar_t c)" + print "{" + print "\tNCURSES_CONST char *result = keyname((int)c);" + print "\tif (!strncmp(result, \"M-\", 2)) result = 0;" + print "\treturn result;" print "}" + print "#endif" }