1 # $Id: MKunctrl.awk,v 1.29 2020/02/02 23:34:34 tom Exp $
2 ##############################################################################
3 # Copyright 2020 Thomas E. Dickey #
4 # Copyright 1998-2012,2017 Free Software Foundation, Inc. #
6 # Permission is hereby granted, free of charge, to any person obtaining a #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the #
12 # following conditions: #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23 # DEALINGS IN THE SOFTWARE. #
25 # Except as contained in this notice, the name(s) of the above copyright #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written #
29 ##############################################################################
31 # Author: Thomas E. Dickey (1997-on)
35 print "/* generated by MKunctrl.awk */"
37 print "#include <curses.priv.h>"
38 print "#include <ctype.h>"
44 print "NCURSES_EXPORT(NCURSES_CONST char *) safe_unctrl(SCREEN *sp, chtype ch)"
49 printf "static const short unctrl_table[] = {"
51 printf "static const char* const unctrl_table[] = {"
53 for ( ch = 0; ch < 256; ch++ ) {
63 printf "%4d%s", offset, gap;
65 part = sprintf ("^\\%03o", ch + 64);
67 } else if (ch == 127) {
70 } else if (ch >= 128 && ch < 160) {
71 part = sprintf("~\\%03o", ch - 64);
73 } else if (ch == 255) {
76 } else if (ch >= 160) {
77 part = sprintf("M-\\%03o", ch - 128);
81 part = sprintf("\\%03o", ch);
86 else if (((ch + 1) % 8) != 0)
89 blob = blob part "\\0";
91 printf "\"%s\"%s", part, gap
98 printf "#if NCURSES_EXT_FUNCS\n";
100 blob = blob "\n/* printable values in 128-255 range */"
101 printf "static const short unctrl_c1[] = {"
103 printf "static const char* const unctrl_c1[] = {"
105 for ( ch = 128; ch < 256; ch++ ) {
114 printf "%4d%s", offset, gap;
115 part = sprintf("\\%03o\\0", ch);
118 if (((ch + 1) % 8) != 0)
122 printf "\"\\%03o\"", ch
127 else if (((ch + 1) % 8) != 0)
133 print "#endif /* NCURSES_EXT_FUNCS */"
138 print "static const char unctrl_blob[] = "blob";"
140 stringname = "unctrl_blob + unctrl"
142 stringname = "unctrl"
144 print "\tint check = (int) ChCharOf(ch);"
145 print "\tconst char *result;"
148 print "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
149 print "#if NCURSES_EXT_FUNCS"
150 print "\t\tif ((sp != 0)"
151 print "\t\t && (sp->_legacy_coding > 1)"
152 print "\t\t && (check >= 128)"
153 print "\t\t && (check < 160))"
154 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
156 print "\t\tif ((check >= 160)"
157 print "\t\t && (check < 256)"
158 print "\t\t && ((sp != 0)"
159 print "\t\t && ((sp->_legacy_coding > 0)"
160 print "\t\t || (sp->_legacy_coding == 0"
161 print "\t\t && isprint(check)))))"
162 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
164 print "#endif /* NCURSES_EXT_FUNCS */"
165 printf "\t\t\tresult = %s_table[check];\n", stringname;
167 print "\t\tresult = 0;"
169 print "\treturn (NCURSES_CONST char *)result;"
172 print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)"
174 print "\treturn safe_unctrl(CURRENT_SCREEN, ch);"