1 /* 2 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Sun designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Sun in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 * CA 95054 USA or visit www.sun.com if you need additional information or 23 * have any questions. 24 */ 25 26 package build.tools.charsetmapping; 27 28 import java.io.*; 29 import java.util.regex.*; 30 import build.tools.charsetmapping.GenerateSBCS; 31 import static build.tools.charsetmapping.CharsetMapping.*; 32 33 public class GenerateMapping { 34 public static void main(String argv[]) throws IOException { 35 if (argv.length < 2) { 36 System.out.println("Usage: java GenerateMapping fMap fDat"); 37 System.exit(1); 38 } 39 genDataJIS0213(new FileInputStream(argv[0]), 40 new FileOutputStream(argv[1])); 41 } 42 43 // regex pattern to parse the "jis0213.map" file 44 static Pattern sjis0213 = Pattern.compile("0x(\\p{XDigit}++)\\s++U\\+(\\p{XDigit}++)(?:\\+(\\p{XDigit}++))?\\s++#.*"); 45 private static void genDataJIS0213(InputStream in, OutputStream out) 46 { 47 int[] sb = new int[0x100]; // singlebyte 48 int[] db = new int[0x10000]; // doublebyte 49 int[] indexC2B = new int[256]; 50 Entry[] supp = new Entry[0x10000]; 51 Entry[] comp = new Entry[0x100]; 52 int suppTotal = 0; 53 int compTotal = 0; 54 55 int b1Min1 = 0x81; 56 int b1Max1 = 0x9f; 57 int b1Min2 = 0xe0; 58 int b1Max2 = 0xfc; 59 int b2Min = 0x40; 60 int b2Max = 0xfe; 61 62 //init 63 for (int i = 0; i < 0x80; i++) sb[i] = i; 64 for (int i = 0x80; i < 0x100; i++) sb[i] = UNMAPPABLE_DECODING; 65 for (int i = 0; i < 0x10000; i++) db[i] = UNMAPPABLE_DECODING; 66 try { 67 Parser p = new Parser(in, sjis0213); 68 Entry e = null; 69 while ((e = p.next()) != null) { 70 if (e.cp2 != 0) { 71 comp[compTotal++] = e; 72 } else { 73 if (e.cp <= 0xffff) { 74 if (e.bs <= 0xff) 75 sb[e.bs] = e.cp; 76 else 77 db[e.bs] = e.cp; 78 indexC2B[e.cp>>8] = 1; 79 } else { 80 supp[suppTotal++] = e; 81 } 82 } 83 } 84 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 85 // c2b Index Table, always the first one 86 writeINDEXC2B(baos, indexC2B); 87 writeSINGLEBYTE(baos, sb); 88 writeDOUBLEBYTE1(baos, db, b1Min1, b1Max1, b2Min, b2Max); 89 writeDOUBLEBYTE2(baos, db, b1Min2, b1Max2, b2Min, b2Max); 90 writeSUPPLEMENT(baos, supp, suppTotal); 91 writeCOMPOSITE(baos, comp, compTotal); 92 writeSIZE(out, baos.size()); 93 baos.writeTo(out); 94 out.close(); 95 } catch (Exception x) { 96 x.printStackTrace(); 97 } 98 } 99 }