1 # $Id: MKunctrl.awk,v 1.27 2012/06/09 20:29:33 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2009,2012 Free Software Foundation, Inc. #
5 # Permission is hereby granted, free of charge, to any person obtaining a #
6 # copy of this software and associated documentation files (the "Software"), #
7 # to deal in the Software without restriction, including without limitation #
8 # the rights to use, copy, modify, merge, publish, distribute, distribute #
9 # with modifications, sublicense, and/or sell copies of the Software, and to #
10 # permit persons to whom the Software is furnished to do so, subject to the #
11 # following conditions: #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software. #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
19 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
22 # DEALINGS IN THE SOFTWARE. #
24 # Except as contained in this notice, the name(s) of the above copyright #
25 # holders shall not be used in advertising or otherwise to promote the sale, #
26 # use or other dealings in this Software without prior written #
28 ##############################################################################
30 # Author: Thomas E. Dickey (1997-on)
34 print "/* generated by MKunctrl.awk */"
36 print "#include <curses.priv.h>"
37 print "#include <ctype.h>"
43 print "NCURSES_EXPORT(NCURSES_CONST char *) safe_unctrl(SCREEN *sp, chtype ch)"
48 printf "static const short unctrl_table[] = {"
50 printf "static const char* const unctrl_table[] = {"
52 for ( ch = 0; ch < 256; ch++ ) {
62 printf "%4d%s", offset, gap;
64 part = sprintf ("^\\%03o", ch + 64);
66 } else if (ch == 127) {
69 } else if (ch >= 128 && ch < 160) {
70 part = sprintf("~\\%03o", ch - 64);
72 } else if (ch == 255) {
75 } else if (ch >= 160) {
76 part = sprintf("M-\\%03o", ch - 128);
80 part = sprintf("\\%03o", ch);
85 else if (((ch + 1) % 8) != 0)
88 blob = blob part "\\0";
90 printf "\"%s\"%s", part, gap
97 printf "#if NCURSES_EXT_FUNCS\n";
99 blob = blob "\n/* printable values in 128-255 range */"
100 printf "static const short unctrl_c1[] = {"
102 printf "static const char* const unctrl_c1[] = {"
104 for ( ch = 128; ch < 256; ch++ ) {
113 printf "%4d%s", offset, gap;
114 part = sprintf("\\%03o\\0", ch);
117 if (((ch + 1) % 8) != 0)
121 printf "\"\\%03o\"", ch
126 else if (((ch + 1) % 8) != 0)
132 print "#endif /* NCURSES_EXT_FUNCS */"
137 print "static const char unctrl_blob[] = "blob";"
139 stringname = "unctrl_blob + unctrl"
141 stringname = "unctrl"
143 print "\tint check = (int) ChCharOf(ch);"
144 print "\tconst char *result;"
146 print "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
147 print "#if NCURSES_EXT_FUNCS"
148 print "\t\tif ((sp != 0)"
149 print "\t\t && (sp->_legacy_coding > 1)"
150 print "\t\t && (check >= 128)"
151 print "\t\t && (check < 160))"
152 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
154 print "\t\tif ((check >= 160)"
155 print "\t\t && (check < 256)"
156 print "\t\t && ((sp != 0)"
157 print "\t\t && ((sp->_legacy_coding > 0)"
158 print "\t\t || (sp->_legacy_coding == 0"
159 print "\t\t && isprint(check)))))"
160 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
162 print "#endif /* NCURSES_EXT_FUNCS */"
163 printf "\t\t\tresult = %s_table[check];\n", stringname;
165 print "\t\tresult = 0;"
167 print "\treturn (NCURSES_CONST char *)result;"
170 print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)"
172 print "\treturn safe_unctrl(CURRENT_SCREEN, ch);"