1 # $Id: MKunctrl.awk,v 1.14 2007/07/28 21:13:21 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2006,2007 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 <dickey@clark.net> 1997
34 print "/* generated by MKunctrl.awk */"
36 print "#include <curses.priv.h>"
42 print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (register 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);
74 part = sprintf("\\%03o", ch);
79 else if (((ch + 1) % 8) != 0)
82 blob = blob part "\\0";
84 printf "\"%s\"%s", part, gap
91 print "#if NCURSES_EXT_FUNCS"
93 blob = blob "\n#if NCURSES_EXT_FUNCS"
94 printf "static const short unctrl_c1[] = {"
96 printf "static const char* const unctrl_c1[] = {"
98 for ( ch = 128; ch < 160; ch++ ) {
107 printf "%4d%s", offset, gap;
108 part = sprintf("\\%03o\\0", ch);
111 if (((ch + 1) % 8) != 0)
114 if (ch >= 128 && ch < 160) {
115 printf "\"\\%03o\"", ch
120 else if (((ch + 1) % 8) != 0)
126 print "#endif /* NCURSES_EXT_FUNCS */"
127 blob = blob "\"\n#endif /* NCURSES_EXT_FUNCS */\n"
131 print "static const char unctrl_blob[] = "blob";"
133 stringname = "unctrl_blob + unctrl"
135 stringname = "unctrl"
137 print "\tint check = ChCharOf(ch);"
138 print "\tconst char *result;"
140 print "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
141 print "#if NCURSES_EXT_FUNCS"
142 print "\t\tif ((SP != 0)"
143 print "\t\t && (SP->_legacy_coding > 1)"
144 print "\t\t && (check >= 128)"
145 print "\t\t && (check < 160))"
146 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
148 print "#endif /* NCURSES_EXT_FUNCS */"
149 printf "\t\t\tresult = %s_table[check];\n", stringname;
151 print "\t\tresult = 0;"
153 print "\treturn (NCURSES_CONST char *)result;"