1 | /* MakeCharTables.java - converts gnu.java.lang.CharData into
|
---|
2 | include/java-chartables.h
|
---|
3 | Copyright (C) 2002 Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | This file is part of GNU Classpath.
|
---|
6 |
|
---|
7 | GNU Classpath is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 2, or (at your option)
|
---|
10 | any later version.
|
---|
11 |
|
---|
12 | GNU Classpath is distributed in the hope that it will be useful, but
|
---|
13 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with GNU Classpath; see the file COPYING. If not, write to the
|
---|
19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
20 | 02111-1307 USA.
|
---|
21 |
|
---|
22 | Linking this library statically or dynamically with other modules is
|
---|
23 | making a combined work based on this library. Thus, the terms and
|
---|
24 | conditions of the GNU General Public License cover the whole
|
---|
25 | combination.
|
---|
26 |
|
---|
27 | As a special exception, the copyright holders of this library give you
|
---|
28 | permission to link this library with independent modules to produce an
|
---|
29 | executable, regardless of the license terms of these independent
|
---|
30 | modules, and to copy and distribute the resulting executable under
|
---|
31 | terms of your choice, provided that you also meet, for each linked
|
---|
32 | independent module, the terms and conditions of the license of that
|
---|
33 | module. An independent module is a module which is not derived from
|
---|
34 | or based on this library. If you modify this library, you may extend
|
---|
35 | this exception to your version of the library, but you are not
|
---|
36 | obligated to do so. If you do not wish to do so, delete this
|
---|
37 | exception statement from your version. */
|
---|
38 |
|
---|
39 | import gnu.java.lang.CharData;
|
---|
40 |
|
---|
41 | public class MakeCharTables implements CharData
|
---|
42 | {
|
---|
43 | public static void main(String[] args)
|
---|
44 | {
|
---|
45 | System.out.println("/* java-chartables.h -- Character tables for java.lang.Character -*- c++ -*-\n"
|
---|
46 | + " Copyright (C) 2002 Free Software Foundation, Inc.\n"
|
---|
47 | + " *** This file is generated by scripts/MakeCharTables.java ***\n"
|
---|
48 | + "\n"
|
---|
49 | + "This file is part of GNU Classpath.\n"
|
---|
50 | + "\n"
|
---|
51 | + "GNU Classpath is free software; you can redistribute it and/or modify\n"
|
---|
52 | + "it under the terms of the GNU General Public License as published by\n"
|
---|
53 | + "the Free Software Foundation; either version 2, or (at your option)\n"
|
---|
54 | + "any later version.\n"
|
---|
55 | + "\n"
|
---|
56 | + "GNU Classpath is distributed in the hope that it will be useful, but\n"
|
---|
57 | + "WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
---|
58 | + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
|
---|
59 | + "General Public License for more details.\n"
|
---|
60 | + "\n"
|
---|
61 | + "You should have received a copy of the GNU General Public License\n"
|
---|
62 | + "along with GNU Classpath; see the file COPYING. If not, write to the\n"
|
---|
63 | + "Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\n"
|
---|
64 | + "02111-1307 USA.\n"
|
---|
65 | + "\n"
|
---|
66 | + "Linking this library statically or dynamically with other modules is\n"
|
---|
67 | + "making a combined work based on this library. Thus, the terms and\n"
|
---|
68 | + "conditions of the GNU General Public License cover the whole\n"
|
---|
69 | + "combination.\n"
|
---|
70 | + "\n"
|
---|
71 | + "As a special exception, the copyright holders of this library give you\n"
|
---|
72 | + "permission to link this library with independent modules to produce an\n"
|
---|
73 | + "executable, regardless of the license terms of these independent\n"
|
---|
74 | + "modules, and to copy and distribute the resulting executable under\n"
|
---|
75 | + "terms of your choice, provided that you also meet, for each linked\n"
|
---|
76 | + "independent module, the terms and conditions of the license of that\n"
|
---|
77 | + "module. An independent module is a module which is not derived from\n"
|
---|
78 | + "or based on this library. If you modify this library, you may extend\n"
|
---|
79 | + "this exception to your version of the library, but you are not\n"
|
---|
80 | + "obligated to do so. If you do not wish to do so, delete this\n"
|
---|
81 | + "exception statement from your version. */\n"
|
---|
82 | + "\n"
|
---|
83 | + "#ifndef __JAVA_CHARTABLES_H__\n"
|
---|
84 | + "#define __JAVA_CHARTABLES_H__\n"
|
---|
85 | + "\n"
|
---|
86 | + "// These tables are automatically generated by scripts/MakeCharTables.java.\n"
|
---|
87 | + "// This is in turn parsing gnu.java.lang.CharData, which is generated by\n"
|
---|
88 | + "// scripts/unicode-muncher.pl. The Unicode data comes from\n"
|
---|
89 | + "// www.unicode.org; this header is based on\n"
|
---|
90 | + "// " + SOURCE + ". JDK 1.4 uses Unicode version 3.0.0.\n"
|
---|
91 | + "// DO NOT EDIT the tables. Instead, fix the upstream scripts and run\n"
|
---|
92 | + "// them again.\n"
|
---|
93 | + "\n"
|
---|
94 | + "// The data is stored in C style arrays of the appropriate CNI types, to\n"
|
---|
95 | + "// guarantee that the data is constant and non-relocatable. The field\n"
|
---|
96 | + "// <code>blocks</code> stores the offset of a block of 2<supSHIFT</sup>\n"
|
---|
97 | + "// characters within <code>data</code>. The data field, in turn, stores\n"
|
---|
98 | + "// information about each character in the low order bits, and an offset\n"
|
---|
99 | + "// into the attribute tables <code>upper</code>, <code>lower</code>,\n"
|
---|
100 | + "// <code>numValue</code>, and <code>direction</code>. Notice that the\n"
|
---|
101 | + "// attribute tables are much smaller than 0xffff entries; as many characters\n"
|
---|
102 | + "// in Unicode share common attributes. Finally, there is a listing for\n"
|
---|
103 | + "// <code>title</code> exceptions (most characters just have the same title\n"
|
---|
104 | + "// case as upper case).\n"
|
---|
105 | + "\n"
|
---|
106 | + "// This file should only be included by natCharacter.cc\n"
|
---|
107 | + "\n"
|
---|
108 | + "/**\n"
|
---|
109 | + " * The character shift amount to look up the block offset. In other words,\n"
|
---|
110 | + " * <code>(char) (blocks[ch >> SHIFT] + ch)</code> is the index where\n"
|
---|
111 | + " * <code>ch</code> is described in <code>data</code>.\n"
|
---|
112 | + " */\n"
|
---|
113 | + "#define SHIFT " + SHIFT);
|
---|
114 |
|
---|
115 | convertString("/**\n"
|
---|
116 | + " * The mapping of character blocks to their location in <code>data</code>.\n"
|
---|
117 | + " * Each entry has been adjusted so that a modulo 16 sum with the desired\n"
|
---|
118 | + " * character gives the actual index into <code>data</code>.\n"
|
---|
119 | + " */",
|
---|
120 | char.class, "blocks", BLOCKS);
|
---|
121 |
|
---|
122 | convertString("/**\n"
|
---|
123 | + " * Information about each character. The low order 5 bits form the\n"
|
---|
124 | + " * character type, the next bit is a flag for non-breaking spaces, and the\n"
|
---|
125 | + " * next bit is a flag for mirrored directionality. The high order 9 bits\n"
|
---|
126 | + " * form the offset into the attribute tables. Note that this limits the\n"
|
---|
127 | + " * number of unique character attributes to 512, which is not a problem\n"
|
---|
128 | + " * as of Unicode version 3.2.0, but may soon become one.\n"
|
---|
129 | + " */",
|
---|
130 | char.class, "data", DATA);
|
---|
131 |
|
---|
132 | convertString("/**\n"
|
---|
133 | + " * This is the attribute table for computing the numeric value of a\n"
|
---|
134 | + " * character. The value is -1 if Unicode does not define a value, -2\n"
|
---|
135 | + " * if the value is not a positive integer, otherwise it is the value.\n"
|
---|
136 | + " */",
|
---|
137 | short.class, "numValue", NUM_VALUE);
|
---|
138 |
|
---|
139 | convertString("/**\n"
|
---|
140 | + " * This is the attribute table for computing the uppercase representation\n"
|
---|
141 | + " * of a character. The value is the difference between the character and\n"
|
---|
142 | + " * its uppercase version.\n"
|
---|
143 | + " */",
|
---|
144 | short.class, "upper", UPPER);
|
---|
145 |
|
---|
146 | convertString("/**\n"
|
---|
147 | + " * This is the attribute table for computing the lowercase representation\n"
|
---|
148 | + " * of a character. The value is the difference between the character and\n"
|
---|
149 | + " * its lowercase version.\n"
|
---|
150 | + " */",
|
---|
151 | short.class, "lower", LOWER);
|
---|
152 |
|
---|
153 | convertString("/**\n"
|
---|
154 | + " * This is the attribute table for computing the directionality class\n"
|
---|
155 | + " * of a character. At present, the value is in the range 0 - 18 if the\n"
|
---|
156 | + " * character has a direction, otherwise it is -1.\n"
|
---|
157 | + " */",
|
---|
158 | byte.class, "direction", DIRECTION);
|
---|
159 |
|
---|
160 | convertString("/**\n"
|
---|
161 | + " * This is the listing of titlecase special cases (all other character\n"
|
---|
162 | + " * can use <code>upper</code> to determine their titlecase). The listing\n"
|
---|
163 | + " * is a sequence of character pairs; converting the first character of the\n"
|
---|
164 | + " * pair to titlecase produces the second character.\n"
|
---|
165 | + " */",
|
---|
166 | char.class, "title", TITLE);
|
---|
167 |
|
---|
168 | System.out.println();
|
---|
169 | System.out.println("#endif /* __JAVA_CHARTABLES_H__ */");
|
---|
170 | }
|
---|
171 |
|
---|
172 | private static void convertString(String header, Class type,
|
---|
173 | String name, String field)
|
---|
174 | {
|
---|
175 | System.out.println();
|
---|
176 | System.out.println(header);
|
---|
177 | System.out.println("static const j" + type.getName() + " " + name
|
---|
178 | + "[] = {");
|
---|
179 | char[] data = field.toCharArray();
|
---|
180 | int wrap;
|
---|
181 | if (type == char.class)
|
---|
182 | wrap = 10;
|
---|
183 | else if (type == byte.class)
|
---|
184 | wrap = 21;
|
---|
185 | else if (type == short.class)
|
---|
186 | wrap = 13;
|
---|
187 | else
|
---|
188 | throw new Error("Unexpeced type");
|
---|
189 | for (int i = 0; i < data.length; i += wrap)
|
---|
190 | {
|
---|
191 | System.out.print(" ");
|
---|
192 | for (int j = 0; j < wrap; j++)
|
---|
193 | {
|
---|
194 | if (i + j >= data.length)
|
---|
195 | break;
|
---|
196 | System.out.print(" ");
|
---|
197 | if (type == char.class)
|
---|
198 | System.out.print((int) data[i + j]);
|
---|
199 | else if (type == byte.class)
|
---|
200 | System.out.print((byte) data[i + j]);
|
---|
201 | else if (type == short.class)
|
---|
202 | System.out.print((short) data[i + j]);
|
---|
203 | System.out.print(",");
|
---|
204 | }
|
---|
205 | System.out.println();
|
---|
206 | }
|
---|
207 | System.out.println(" };\n"
|
---|
208 | + "/** Length of " + name + ". */\n"
|
---|
209 | + "static const int " + name + "_length = "
|
---|
210 | + data.length + ";");
|
---|
211 | }
|
---|
212 | }
|
---|