]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/base/MKunctrl.awk
ncurses 5.7 - patch 20090425
[ncurses.git] / ncurses / base / MKunctrl.awk
1 # $Id: MKunctrl.awk,v 1.25 2009/04/18 23:43:49 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.                #
4 #                                                                            #
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:                                                      #
12 #                                                                            #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software.                        #
15 #                                                                            #
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.                                                  #
23 #                                                                            #
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               #
27 # authorization.                                                             #
28 ##############################################################################
29 #
30 # Author: Thomas E. Dickey (1997-on)
31 #
32
33 BEGIN   {
34                 print "/* generated by MKunctrl.awk */"
35                 print ""
36                 print "#include <curses.priv.h>"
37                 print "#include <ctype.h>"
38                 print ""
39                 print "#if USE_WIDEC_SUPPORT"
40                 print "#if HAVE_WCTYPE_H"
41                 print "#include <wctype.h>"
42                 print "#endif"
43                 print "#endif"
44                 print ""
45                 print "#undef unctrl"
46                 print ""
47         }
48 END     {
49                 print "NCURSES_EXPORT(NCURSES_CONST char *) safe_unctrl(SCREEN *sp, chtype ch)"
50                 print "{"
51                 blob=""
52                 offset=0
53                 if (bigstrings) {
54                         printf "static const short unctrl_table[] = {"
55                 } else {
56                         printf "static const char* const unctrl_table[] = {"
57                 }
58                 for ( ch = 0; ch < 256; ch++ ) {
59                         gap = ","
60                         part=""
61                         if ((ch % 8) == 0) {
62                                 printf "\n    "
63                                 if (ch != 0)
64                                         blob = blob "\""
65                                 blob = blob "\n    \""
66                         }
67                         if (bigstrings)
68                                 printf "%4d%s", offset, gap;
69                         if (ch < 32) {
70                                 part = sprintf ("^\\%03o", ch + 64);
71                                 offset = offset + 3;
72                         } else if (ch == 127) {
73                                 part = "^?";
74                                 offset = offset + 3;
75                         } else if (ch >= 128 && ch < 160) {
76                                 part = sprintf("~\\%03o", ch - 64);
77                                 offset = offset + 3;
78                         } else if (ch == 255) {
79                                 part = "~?";
80                                 offset = offset + 3;
81                         } else if (ch >= 160) {
82                                 part = sprintf("M-\\%03o", ch - 128);
83                                 offset = offset + 4;
84                         } else {
85                                 gap = gap " "
86                                 part = sprintf("\\%03o", ch);
87                                 offset = offset + 2;
88                         }
89                         if (ch == 255)
90                                 gap = "\n"
91                         else if (((ch + 1) % 8) != 0)
92                                 gap = gap " "
93                         if (bigstrings) {
94                                 blob = blob part "\\0";
95                         } else {
96                                 printf "\"%s\"%s", part, gap
97                         }
98                 }
99                 print "};"
100                 blob = blob "\"";
101
102                 print ""
103                 printf "#if NCURSES_EXT_FUNCS\n";
104                 if (bigstrings) {
105                         blob = blob "\n/* printable values in 128-255 range */"
106                         printf "static const short unctrl_c1[] = {"
107                 } else {
108                         printf "static const char* const unctrl_c1[] = {"
109                 }
110                 for ( ch = 128; ch < 256; ch++ ) {
111                         gap = ","
112                         if ((ch % 8) == 0) {
113                                 if (ch != 128)
114                                         blob = blob "\""
115                                 printf "\n    "
116                                 blob = blob "\n    \""
117                         }
118                         if (bigstrings) {
119                                 printf "%4d%s", offset, gap;
120                                 part = sprintf("\\%03o\\0", ch);
121                                 blob = blob part
122                                 offset = offset + 2;
123                                 if (((ch + 1) % 8) != 0)
124                                         gap = gap " "
125                         } else {
126                                 if (ch >= 128) {
127                                         printf "\"\\%03o\"", ch
128                                         gap = gap " "
129                                 }
130                                 if (ch == 255)
131                                         gap = "\n"
132                                 else if (((ch + 1) % 8) != 0)
133                                         gap = gap " "
134                                 printf "%s", gap
135                         }
136                 }
137                 print "};"
138                 print "#endif /* NCURSES_EXT_FUNCS */"
139                 blob = blob "\"\n"
140
141                 print ""
142                 if (bigstrings) {
143                         print "static const char unctrl_blob[] = "blob";"
144                         print ""
145                         stringname = "unctrl_blob + unctrl"
146                 } else {
147                         stringname = "unctrl"
148                 }
149                 print  "\tint check = ChCharOf(ch);"
150                 print  "\tconst char *result;"
151                 print  ""
152                 print  "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
153                 print  "#if NCURSES_EXT_FUNCS"
154                 print  "\t\tif ((sp != 0)"
155                 print  "\t\t && (sp->_legacy_coding > 1)"
156                 print  "\t\t && (check >= 128)"
157                 print  "\t\t && (check < 160))"
158                 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
159                 print  "\t\telse"
160                 print  "#if USE_WIDEC_SUPPORT"
161                 print  "\t\tif ((check >= 160)"
162                 print  "\t\t && (check < 256)"
163                 print  "\t\t && ((sp != 0)"
164                 print  "\t\t  && ((sp->_legacy_coding > 0)"
165                 print  "\t\t   || (sp->_legacy_coding == 0"
166                 print  "\t\t       && (isprint(check) || iswprint(check))))))"
167                 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
168                 print  "\t\telse"
169                 print  "#else"
170                 print  "\t\tif ((check >= 160)"
171                 print  "\t\t && (check < 256)"
172                 print  "\t\t && ((sp != 0)"
173                 print  "\t\t  && ((sp->_legacy_coding > 0)"
174                 print  "\t\t   || (sp->_legacy_coding == 0"
175                 print  "\t\t       && isprint(check)))))"
176                 printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
177                 print  "\t\telse"
178                 print  "#endif /* USE_WIDEC_SUPPORT */"
179                 print  "#endif /* NCURSES_EXT_FUNCS */"
180                 printf "\t\t\tresult = %s_table[check];\n", stringname;
181                 print  "\t} else {"
182                 print  "\t\tresult = 0;"
183                 print  "\t}"
184                 print  "\treturn (NCURSES_CONST char *)result;"
185                 print  "}"
186                 print  ""
187                 print  "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)"
188                 print  "{"
189                 print  "\treturn safe_unctrl(CURRENT_SCREEN, ch);"
190                 print  "}"
191         }