1 # $Id: MKunctrl.awk,v 1.23 2008/10/04 21:40:24 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2007,2008 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>"
39 print "#if USE_WIDEC_SUPPORT"
40 print "#if HAVE_WCTYPE_H"
41 print "#include <wctype.h>"
49 print "NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *sp, chtype ch)"
55 printf "static const short unctrl_table[] = {"
57 printf "static const char* const unctrl_table[] = {"
59 for ( ch = 0; ch < 256; ch++ ) {
69 printf "%4d%s", offset, gap;
71 part = sprintf ("^\\%03o", ch + 64);
73 } else if (ch == 127) {
76 } else if (ch >= 128 && ch < 160) {
77 part = sprintf("~\\%03o", ch - 64);
79 } else if (ch == 255) {
82 } else if (ch >= 160) {
83 part = sprintf("M-\\%03o", ch - 128);
87 part = sprintf("\\%03o", ch);
92 else if (((ch + 1) % 8) != 0)
95 blob = blob part "\\0";
97 printf "\"%s\"%s", part, gap
104 printf "#if NCURSES_EXT_FUNCS\n";
106 blob = blob "\n/* printable values in 128-255 range */"
107 printf "static const short unctrl_c1[] = {"
109 printf "static const char* const unctrl_c1[] = {"
111 for ( ch = 128; ch < 256; ch++ ) {
120 printf "%4d%s", offset, gap;
121 part = sprintf("\\%03o\\0", ch);
124 if (((ch + 1) % 8) != 0)
128 printf "\"\\%03o\"", ch
133 else if (((ch + 1) % 8) != 0)
139 print "#endif /* NCURSES_EXT_FUNCS */"
144 print "static const char unctrl_blob[] = "blob";"
146 stringname = "unctrl_blob + unctrl"
148 stringname = "unctrl"
150 print "\tint check = ChCharOf(ch);"
151 print "\tconst char *result;"
153 print "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
154 print "#if NCURSES_EXT_FUNCS"
155 print "\t\tif ((sp != 0)"
156 print "\t\t && (sp->_legacy_coding > 1)"
157 print "\t\t && (check >= 128)"
158 print "\t\t && (check < 160))"
159 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
161 print "#if USE_WIDEC_SUPPORT"
162 print "\t\tif ((check >= 160)"
163 print "\t\t && (check < 256)"
164 print "\t\t && ((sp != 0)"
165 print "\t\t && ((sp->_legacy_coding > 0)"
166 print "\t\t || (sp->_legacy_coding == 0"
167 print "\t\t && (isprint(check) || iswprint(check))))))"
168 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
171 print "\t\tif ((check >= 160)"
172 print "\t\t && (check < 256)"
173 print "\t\t && ((sp != 0)"
174 print "\t\t && ((sp->_legacy_coding > 0)"
175 print "\t\t || (sp->_legacy_coding == 0"
176 print "\t\t && isprint(check)))))"
177 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
179 print "#endif /* USE_WIDEC_SUPPORT */"
180 print "#endif /* NCURSES_EXT_FUNCS */"
181 printf "\t\t\tresult = %s_table[check];\n", stringname;
183 print "\t\tresult = 0;"
185 print "\treturn (NCURSES_CONST char *)result;"
188 print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)"
190 print "\treturn _nc_unctrl(SP, ch);"