]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/base/MKunctrl.awk
ncurses 5.6 - patch 20080105
[ncurses.git] / ncurses / base / MKunctrl.awk
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.                #
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 <dickey@clark.net> 1997
31 #
32
33 BEGIN   {
34                 print "/* generated by MKunctrl.awk */"
35                 print ""
36                 print "#include <curses.priv.h>"
37                 print ""
38                 print "#undef unctrl"
39                 print ""
40         }
41 END     {
42                 print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (register chtype ch)"
43                 print "{"
44
45                 blob=""
46                 offset=0
47                 if (bigstrings) {
48                         printf "static const short unctrl_table[] = {"
49                 } else {
50                         printf "static const char* const unctrl_table[] = {"
51                 }
52                 for ( ch = 0; ch < 256; ch++ ) {
53                         gap = ","
54                         part=""
55                         if ((ch % 8) == 0) {
56                                 printf "\n    "
57                                 if (ch != 0)
58                                         blob = blob "\""
59                                 blob = blob "\n    \""
60                         }
61                         if (bigstrings)
62                                 printf "%4d%s", offset, gap;
63                         if (ch < 32) {
64                                 part = sprintf ("^\\%03o", ch + 64);
65                                 offset = offset + 3;
66                         } else if (ch == 127) {
67                                 part = "^?";
68                                 offset = offset + 3;
69                         } else if (ch >= 128 && ch < 160) {
70                                 part = sprintf("~\\%03o", ch - 64);
71                                 offset = offset + 3;
72                         } else {
73                                 gap = gap " "
74                                 part = sprintf("\\%03o", ch);
75                                 offset = offset + 2;
76                         }
77                         if (ch == 255)
78                                 gap = "\n"
79                         else if (((ch + 1) % 8) != 0)
80                                 gap = gap " "
81                         if (bigstrings) {
82                                 blob = blob part "\\0";
83                         } else {
84                                 printf "\"%s\"%s", part, gap
85                         }
86                 }
87                 print "};"
88                 blob = blob "\"";
89
90                 print ""
91                 print "#if NCURSES_EXT_FUNCS"
92                 if (bigstrings) {
93                         blob = blob "\n#if NCURSES_EXT_FUNCS"
94                         printf "static const short unctrl_c1[] = {"
95                 } else {
96                         printf "static const char* const unctrl_c1[] = {"
97                 }
98                 for ( ch = 128; ch < 160; ch++ ) {
99                         gap = ","
100                         if ((ch % 8) == 0) {
101                                 if (ch != 128)
102                                         blob = blob "\""
103                                 printf "\n    "
104                                 blob = blob "\n    \""
105                         }
106                         if (bigstrings) {
107                                 printf "%4d%s", offset, gap;
108                                 part = sprintf("\\%03o\\0", ch);
109                                 blob = blob part
110                                 offset = offset + 2;
111                                 if (((ch + 1) % 8) != 0)
112                                         gap = gap " "
113                         } else {
114                                 if (ch >= 128 && ch < 160) {
115                                         printf "\"\\%03o\"", ch
116                                         gap = gap " "
117                                 }
118                                 if (ch == 255)
119                                         gap = "\n"
120                                 else if (((ch + 1) % 8) != 0)
121                                         gap = gap " "
122                                 printf "%s", gap
123                         }
124                 }
125                 print "};"
126                 print "#endif /* NCURSES_EXT_FUNCS */"
127                 blob = blob "\"\n#endif /* NCURSES_EXT_FUNCS */\n"
128
129                 print ""
130                 if (bigstrings) {
131                         print "static const char unctrl_blob[] = "blob";"
132                         print ""
133                         stringname = "unctrl_blob + unctrl"
134                 } else {
135                         stringname = "unctrl"
136                 }
137                 print "\tint check = ChCharOf(ch);"
138                 print "\tconst char *result;"
139                 print ""
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;
147                 print "\t\telse"
148                 print "#endif /* NCURSES_EXT_FUNCS */"
149                 printf "\t\t\tresult = %s_table[check];\n", stringname;
150                 print "\t} else {"
151                 print "\t\tresult = 0;"
152                 print "\t}"
153                 print "\treturn (NCURSES_CONST char *)result;"
154                 print "}"
155         }