X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2FMKkeyname.awk;fp=ncurses%2Fbase%2FMKkeyname.awk;h=11dcfe5c23755b2080e2e670d86913269b1f1418;hp=9ac65837a519d7f4b248591344135fdfedd90cf6;hb=027ae42953e3186daed8f3882da73de48291b606;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8 diff --git a/ncurses/base/MKkeyname.awk b/ncurses/base/MKkeyname.awk index 9ac65837..11dcfe5c 100644 --- a/ncurses/base/MKkeyname.awk +++ b/ncurses/base/MKkeyname.awk @@ -1,6 +1,6 @@ -# $Id: MKkeyname.awk,v 1.28 2005/04/30 19:26:25 tom Exp $ +# $Id: MKkeyname.awk,v 1.30 2006/05/20 17:35:30 tom Exp $ ############################################################################## -# Copyright (c) 1999-2002,2005 Free Software Foundation, Inc. # +# Copyright (c) 1999-2005,2006 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"), # @@ -43,9 +43,11 @@ BEGIN { END { printf "\t{ 0, 0 }};\n" print "" + print "#define SIZEOF_TABLE 256" + print "static char **keyname_table;" + print "" print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)" print "{" - print " static char **table;" print " int i;" print " char name[20];" print " char *p;" @@ -61,26 +63,27 @@ END { print " }" print " }" print "" - print " if (result == 0 && (c >= 0 && c < 256)) {" - print " if (table == 0)" - print " table = typeCalloc(char *, 256);" - print " if (table != 0) {" - print " if (table[c] == 0) {" + print " if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {" + print " if (keyname_table == 0)" + print " keyname_table = typeCalloc(char *, SIZEOF_TABLE);" + print " if (keyname_table != 0) {" + print " if (keyname_table[c] == 0) {" + print " int cc = c;" print " p = name;" - print " if (c >= 128) {" + print " if (cc >= 128) {" print " strcpy(p, \"M-\");" print " p += 2;" - print " c -= 128;" + print " cc -= 128;" print " }" - print " if (c < 32)" - print " sprintf(p, \"^%c\", c + '@');" - print " else if (c == 127)" + print " if (cc < 32)" + print " sprintf(p, \"^%c\", cc + '@');" + print " else if (cc == 127)" print " strcpy(p, \"^?\");" print " else" - print " sprintf(p, \"%c\", c);" - print " table[c] = strdup(name);" + print " sprintf(p, \"%c\", cc);" + print " keyname_table[c] = strdup(name);" print " }" - print " result = table[c];" + print " result = keyname_table[c];" print " }" print "#if NCURSES_EXT_FUNCS && NCURSES_XNAMES" print " } else if (result == 0 && cur_term != 0) {" @@ -97,6 +100,7 @@ END { print " break;" print " }" print " }" + print " free(bound);" print " if (result != 0)" print " break;" print " }" @@ -115,4 +119,17 @@ END { print " return result;" print "}" print "#endif" + print "" + print "#if NO_LEAKS" + print "void _nc_keyname_leaks(void)" + print "{" + print " int j;" + print " if (keyname_table != 0) {" + print " for (j = 0; j < SIZEOF_TABLE; ++j) {" + print " FreeIfNeeded(keyname_table[j]);" + print " }" + print " FreeAndNull(keyname_table);" + print " }" + print "}" + print "#endif /* NO_LEAKS */" }