13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package build.tools.charsetmapping;
27
28 import java.io.*;
29 import java.util.ArrayList;
30 import java.util.Scanner;
31 import java.util.LinkedHashMap;
32 import java.util.Locale;
33
34 public class Main {
35
36 public static void main(String args[]) throws Throwable {
37 int SRC_DIR = 0;
38 int DST_DIR = 1;
39 int TYPE = 2;
40 int CHARSETS = 3;
41 int OS = 4;
42 int TEMPLATE = 5;
43 int EXT_SRC = 6;
44 int COPYRIGHT_SRC = 7;
45
46 if (args.length < 3 ) {
47 System.out.println("Usage: java -jar charsetmapping.jar src dst spiType charsets os [template]");
48 System.exit(1);
49 }
50 boolean isStandard = "stdcs".equals(args[TYPE]);
51 boolean isExtended = "extcs".equals(args[TYPE]);
52 if (isStandard || isExtended) {
53 LinkedHashMap<String, Charset> charsets = getCharsets(
54 new File(args[SRC_DIR], args[CHARSETS]));
55 String[] osStdcs = getOSStdCSList(new File(args[SRC_DIR], args[OS]));
56 boolean hasBig5_HKSCS = false;
57 boolean hasMS950_HKSCS = false;
58 boolean hasMS950_HKSCS_XP = false;
59 boolean hasEUC_TW = false;
60 for (String name : osStdcs) {
61 Charset cs = charsets.get(name);
62 if (cs != null) {
63 cs.pkgName = "sun.nio.cs";
64 }
65 if (name.equals("Big5_HKSCS")) {
66 hasBig5_HKSCS = true;
67 } else if (name.equals("MS950_HKSCS")) {
68 hasMS950_HKSCS = true;
69 } else if (name.equals("MS950_HKSCS_XP")) {
82 case "template":
83 SRC.genClass(cs, args[EXT_SRC], args[DST_DIR]);
84 break;
85 case "sbcs":
86 SBCS.genClass(cs, args[SRC_DIR], args[DST_DIR],
87 "SingleByte-X.java.template");
88 break;
89 case "source":
90 break; // source file, do nothing
91 default: // dbcs
92 DBCS.genClass("dbcs".equals(cs.type) ?
93 "" : "_" + cs.type.toUpperCase(Locale.ENGLISH),
94 cs, args[SRC_DIR], args[DST_DIR],
95 "DoubleByte-X.java.template");
96 }
97 }
98 // provider StandardCharsets.java / ExtendedCharsets.java
99 SPI.genClass(args[TYPE], charsets,
100 args[SRC_DIR], args[DST_DIR],
101 args[TEMPLATE],
102 args[OS].endsWith("windows") ? "windows" : "unix");
103
104 // HKSCSMapping(2008).java goes std if one of Big5_HKSCS MS950_HKSCS
105 // is in std
106 if (isStandard && (hasBig5_HKSCS || hasMS950_HKSCS) ||
107 isExtended && !(hasBig5_HKSCS || hasMS950_HKSCS)) {
108 HKSCS.genClass2008(args[SRC_DIR], args[DST_DIR],
109 isStandard ? "sun.nio.cs" : "sun.nio.cs.ext",
110 new File(args[COPYRIGHT_SRC], "HKSCS.java"));
111 }
112 // HKSCS_XPMapping.java goes together with MS950XP_HKSCS
113 if (isStandard && hasMS950_HKSCS_XP || isExtended && !hasMS950_HKSCS_XP) {
114 HKSCS.genClassXP(args[SRC_DIR], args[DST_DIR],
115 isStandard ? "sun.nio.cs" : "sun.nio.cs.ext",
116 new File(args[COPYRIGHT_SRC], "HKSCS.java"));
117 }
118 if (isStandard && hasEUC_TW) {
119 EUC_TW.genClass("sun.nio.cs", args);
120 }
121 if (!isStandard && !hasEUC_TW) {
122 EUC_TW.genClass("sun.nio.cs.ext", args);
160 cs = new Charset();
161 cs.csName = tokens[1];
162 cs.clzName = tokens[2];
163 } else {
164 String key = tokens[1]; // leading empty str
165 switch (key) {
166 case "alias":
167 if (tokens.length < 3) {
168 throw new RuntimeException("Error: incorrect alias line [" + line + "]");
169 } else if (names != null) {
170 names.add(tokens[2]); // ALIAS_NAME
171 }
172 break;
173 case "package":
174 cs.pkgName = tokens[2];
175 break;
176 case "type":
177 cs.type = tokens[2];
178 break;
179 case "os":
180 cs.os = tokens[2];
181 break;
182 case "hisname":
183 cs.hisName = tokens[2];
184 break;
185 case "ascii":
186 cs.isASCII = Boolean.parseBoolean(tokens[2]);
187 break;
188 case "minmax":
189 cs.b1Min = toInteger(tokens[2]);
190 cs.b1Max = toInteger(tokens[3]);
191 cs.b2Min = toInteger(tokens[4]);
192 cs.b2Max = toInteger(tokens[5]);
193 break;
194 case "internal":
195 cs.isInternal = Boolean.parseBoolean(tokens[2]);
196 break;
197 default: // ignore
198 }
199 }
200 }
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package build.tools.charsetmapping;
27
28 import java.io.*;
29 import java.util.ArrayList;
30 import java.util.Scanner;
31 import java.util.LinkedHashMap;
32 import java.util.Locale;
33 import java.util.Arrays;
34
35 public class Main {
36
37 static String osName = null;
38
39 public static void main(String args[]) throws Throwable {
40 int SRC_DIR = 0;
41 int DST_DIR = 1;
42 int TYPE = 2;
43 int CHARSETS = 3;
44 int OS = 4;
45 int TEMPLATE = 5;
46 int EXT_SRC = 6;
47 int COPYRIGHT_SRC = 7;
48
49 if (args.length < 3 ) {
50 System.out.println("Usage: java -jar charsetmapping.jar src dst spiType charsets os [template]");
51 System.exit(1);
52 }
53 if (args.length > OS) {
54 osName = args[OS].endsWith("windows") ? "windows" : "unix";
55 if (args[OS].startsWith("stdcs-")) {
56 int pos = args[OS].indexOf("-");
57 if (pos > -1) {
58 osName = args[OS].substring(pos+1);
59 }
60 }
61 }
62 boolean isStandard = "stdcs".equals(args[TYPE]);
63 boolean isExtended = "extcs".equals(args[TYPE]);
64 if (isStandard || isExtended) {
65 LinkedHashMap<String, Charset> charsets = getCharsets(
66 new File(args[SRC_DIR], args[CHARSETS]));
67 String[] osStdcs = getOSStdCSList(new File(args[SRC_DIR], args[OS]));
68 boolean hasBig5_HKSCS = false;
69 boolean hasMS950_HKSCS = false;
70 boolean hasMS950_HKSCS_XP = false;
71 boolean hasEUC_TW = false;
72 for (String name : osStdcs) {
73 Charset cs = charsets.get(name);
74 if (cs != null) {
75 cs.pkgName = "sun.nio.cs";
76 }
77 if (name.equals("Big5_HKSCS")) {
78 hasBig5_HKSCS = true;
79 } else if (name.equals("MS950_HKSCS")) {
80 hasMS950_HKSCS = true;
81 } else if (name.equals("MS950_HKSCS_XP")) {
94 case "template":
95 SRC.genClass(cs, args[EXT_SRC], args[DST_DIR]);
96 break;
97 case "sbcs":
98 SBCS.genClass(cs, args[SRC_DIR], args[DST_DIR],
99 "SingleByte-X.java.template");
100 break;
101 case "source":
102 break; // source file, do nothing
103 default: // dbcs
104 DBCS.genClass("dbcs".equals(cs.type) ?
105 "" : "_" + cs.type.toUpperCase(Locale.ENGLISH),
106 cs, args[SRC_DIR], args[DST_DIR],
107 "DoubleByte-X.java.template");
108 }
109 }
110 // provider StandardCharsets.java / ExtendedCharsets.java
111 SPI.genClass(args[TYPE], charsets,
112 args[SRC_DIR], args[DST_DIR],
113 args[TEMPLATE],
114 osName);
115
116 // HKSCSMapping(2008).java goes std if one of Big5_HKSCS MS950_HKSCS
117 // is in std
118 if (isStandard && (hasBig5_HKSCS || hasMS950_HKSCS) ||
119 isExtended && !(hasBig5_HKSCS || hasMS950_HKSCS)) {
120 HKSCS.genClass2008(args[SRC_DIR], args[DST_DIR],
121 isStandard ? "sun.nio.cs" : "sun.nio.cs.ext",
122 new File(args[COPYRIGHT_SRC], "HKSCS.java"));
123 }
124 // HKSCS_XPMapping.java goes together with MS950XP_HKSCS
125 if (isStandard && hasMS950_HKSCS_XP || isExtended && !hasMS950_HKSCS_XP) {
126 HKSCS.genClassXP(args[SRC_DIR], args[DST_DIR],
127 isStandard ? "sun.nio.cs" : "sun.nio.cs.ext",
128 new File(args[COPYRIGHT_SRC], "HKSCS.java"));
129 }
130 if (isStandard && hasEUC_TW) {
131 EUC_TW.genClass("sun.nio.cs", args);
132 }
133 if (!isStandard && !hasEUC_TW) {
134 EUC_TW.genClass("sun.nio.cs.ext", args);
172 cs = new Charset();
173 cs.csName = tokens[1];
174 cs.clzName = tokens[2];
175 } else {
176 String key = tokens[1]; // leading empty str
177 switch (key) {
178 case "alias":
179 if (tokens.length < 3) {
180 throw new RuntimeException("Error: incorrect alias line [" + line + "]");
181 } else if (names != null) {
182 names.add(tokens[2]); // ALIAS_NAME
183 }
184 break;
185 case "package":
186 cs.pkgName = tokens[2];
187 break;
188 case "type":
189 cs.type = tokens[2];
190 break;
191 case "os":
192 boolean b = Arrays.stream(tokens[2].split(","))
193 .anyMatch(os -> os.equals(osName));
194 cs.os = b ? null : "false";
195 break;
196 case "hisname":
197 cs.hisName = tokens[2];
198 break;
199 case "ascii":
200 cs.isASCII = Boolean.parseBoolean(tokens[2]);
201 break;
202 case "minmax":
203 cs.b1Min = toInteger(tokens[2]);
204 cs.b1Max = toInteger(tokens[3]);
205 cs.b2Min = toInteger(tokens[4]);
206 cs.b2Max = toInteger(tokens[5]);
207 break;
208 case "internal":
209 cs.isInternal = Boolean.parseBoolean(tokens[2]);
210 break;
211 default: // ignore
212 }
213 }
214 }
|