jdk/make/src/classes/build/tools/charsetmapping/DBCS.java
author ihse
Thu, 14 Nov 2013 11:19:32 +0100
changeset 21805 c7d7946239de
parent 19377 jdk/make/tools/src/build/tools/charsetmapping/DBCS.java@b2f2886fd1ac
child 23010 6dadb192ad81
permissions -rw-r--r--
8027566: Remove the old build system Reviewed-by: erikj, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13366
diff changeset
     2
 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     4
 *
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    10
 *
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    15
 * accompanied this code).
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    16
 *
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
    23
 * questions.
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    24
 */
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    25
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    26
package build.tools.charsetmapping;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    27
import java.io.*;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    28
import java.util.Arrays;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    29
import java.util.ArrayList;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    30
import java.util.Scanner;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    31
import java.util.Formatter;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    32
import java.util.regex.*;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    33
import java.nio.charset.*;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    34
import static build.tools.charsetmapping.Utils.*;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    35
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    36
public class DBCS {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    37
    // pattern used by this class to read in mapping table
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    38
    static Pattern mPattern = Pattern.compile("(?:0x)?(\\p{XDigit}++)\\s++(?:0x)?(\\p{XDigit}++)(?:\\s++#.*)?");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    39
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    40
    public static void genClass(String args[]) throws Exception {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    41
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    42
        Scanner s = new Scanner(new File(args[0], args[2]));
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    43
        while (s.hasNextLine()) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    44
            String line = s.nextLine();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    45
            if (line.startsWith("#") || line.length() == 0)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    46
                continue;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    47
            String[] fields = line.split("\\s+");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    48
            if (fields.length < 10) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    49
                System.err.println("Misconfiged sbcs line <" + line + ">?");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    50
                continue;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    51
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    52
            String clzName = fields[0];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    53
            String csName  = fields[1];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    54
            String hisName = ("null".equals(fields[2]))?null:fields[2];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    55
            String type = fields[3].toUpperCase();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    56
            if ("BASIC".equals(type))
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    57
                type = "";
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    58
            else
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    59
                type = "_" + type;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    60
            String pkgName  = fields[4];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    61
            boolean isASCII = Boolean.valueOf(fields[5]);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    62
            int    b1Min = toInteger(fields[6]);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    63
            int    b1Max = toInteger(fields[7]);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    64
            int    b2Min    = toInteger(fields[8]);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    65
            int    b2Max    = toInteger(fields[9]);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    66
            System.out.printf("%s,%s,%s,%b,%s%n", clzName, csName, hisName, isASCII, pkgName);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    67
            genClass0(args[0], args[1], "DoubleByte-X.java.template",
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    68
                    clzName, csName, hisName, pkgName,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    69
                    isASCII, type,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    70
                    b1Min, b1Max, b2Min, b2Max);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    71
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    72
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    73
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    74
    static int toInteger(String s) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    75
        if (s.startsWith("0x") || s.startsWith("0X"))
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    76
            return Integer.valueOf(s.substring(2), 16);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    77
        else
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    78
            return Integer.valueOf(s);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    79
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    80
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    81
    private static void genClass0(String srcDir, String dstDir, String template,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    82
                                  String clzName,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    83
                                  String csName,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    84
                                  String hisName,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    85
                                  String pkgName,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    86
                                  boolean isASCII,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    87
                                  String type,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    88
                                  int b1Min, int b1Max,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    89
                                  int b2Min, int b2Max)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    90
        throws Exception
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    91
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    92
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    93
        StringBuilder b2cSB = new StringBuilder();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    94
        StringBuilder b2cNRSB = new StringBuilder();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    95
        StringBuilder c2bNRSB = new StringBuilder();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    96
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    97
        char[] db = new char[0x10000];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    98
        char[] c2bIndex = new char[0x100];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    99
        int c2bOff = 0x100;    // first 0x100 for unmappable segs
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   100
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   101
        Arrays.fill(db, UNMAPPABLE_DECODING);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   102
        Arrays.fill(c2bIndex, UNMAPPABLE_DECODING);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   103
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   104
        char[] b2cIndex = new char[0x100];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   105
        Arrays.fill(b2cIndex, UNMAPPABLE_DECODING);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   106
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   107
        // (1)read in .map to parse all b->c entries
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   108
        FileInputStream in = new FileInputStream(new File(srcDir, clzName + ".map"));
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   109
        Parser p = new Parser(in, mPattern);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   110
        Entry  e = null;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   111
        while ((e = p.next()) != null) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   112
            db[e.bs] = (char)e.cp;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   113
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   114
            if (e.bs > 0x100 &&    // db
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   115
                b2cIndex[e.bs>>8] == UNMAPPABLE_DECODING) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   116
                b2cIndex[e.bs>>8] = 1;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   117
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   118
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   119
            if (c2bIndex[e.cp>>8] == UNMAPPABLE_DECODING) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   120
                c2bOff += 0x100;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   121
                c2bIndex[e.cp>>8] = 1;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   122
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   123
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   124
        Output out = new Output(new Formatter(b2cSB));
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   125
        out.format("%n    static final String b2cSBStr =%n");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   126
        out.format(db, 0x00, 0x100,  ";");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   127
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   128
        out.format("%n        static final String[] b2cStr = {%n");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   129
        for (int i = 0; i < 0x100; i++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   130
            if (b2cIndex[i] == UNMAPPABLE_DECODING) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   131
                out.format("            null,%n");  //unmappable segments
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   132
            } else {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   133
                out.format(db, i, b2Min, b2Max, ",");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   134
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   135
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   136
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   137
        out.format("        };%n");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   138
        out.close();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   139
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   140
        // (2)now parse the .nr file which includes "b->c" non-roundtrip entries
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   141
        File f = new File(srcDir, clzName + ".nr");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   142
        if (f.exists()) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   143
            StringBuilder sb = new StringBuilder();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   144
            in = new FileInputStream(f);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   145
            p = new Parser(in, mPattern);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   146
            e = null;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   147
            while ((e = p.next()) != null) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   148
                // A <b,c> pair
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   149
                sb.append((char)e.bs);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   150
                sb.append((char)e.cp);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   151
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   152
            char[] nr = sb.toString().toCharArray();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   153
            out = new Output(new Formatter(b2cNRSB));
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   154
            out.format("String b2cNR =%n");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   155
            out.format(nr, 0, nr.length,  ";");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   156
            out.close();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   157
        } else {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   158
            b2cNRSB.append("String b2cNR = null;");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   159
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   160
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   161
        // (3)finally the .c2b file which includes c->b non-roundtrip entries
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   162
        f = new File(srcDir, clzName + ".c2b");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   163
        if (f.exists()) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   164
            StringBuilder sb = new StringBuilder();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   165
            in = new FileInputStream(f);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   166
            p = new Parser(in, mPattern);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   167
            e = null;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   168
            while ((e = p.next()) != null) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   169
                // A <b,c> pair
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   170
                if (c2bIndex[e.cp>>8] == UNMAPPABLE_DECODING) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   171
                    c2bOff += 0x100;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   172
                    c2bIndex[e.cp>>8] = 1;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   173
                }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   174
                sb.append((char)e.bs);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   175
                sb.append((char)e.cp);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   176
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   177
            char[] nr = sb.toString().toCharArray();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   178
            out = new Output(new Formatter(c2bNRSB));
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   179
            out.format("String c2bNR =%n");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   180
            out.format(nr, 0, nr.length,  ";");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   181
            out.close();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   182
        } else {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   183
            c2bNRSB.append("String c2bNR = null;");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   184
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   185
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   186
        // (4)it's time to generate the source file
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   187
        String b2c = b2cSB.toString();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   188
        String b2cNR = b2cNRSB.toString();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   189
        String c2bNR = c2bNRSB.toString();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   190
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   191
        Scanner s = new Scanner(new File(srcDir, template));
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   192
        PrintStream ops = new PrintStream(new FileOutputStream(
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   193
                             new File(dstDir, clzName + ".java")));
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   194
        if (hisName == null)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   195
            hisName = "";
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   196
13366
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   197
        // (5) c2b replacement, only used for JIs0208/0212, which
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   198
        // are two pure db charsets so default '3f' does not work
19377
b2f2886fd1ac 6614237: missing codepage Cp290 at java runtime
sherman
parents: 14342
diff changeset
   199
        // TBD: move this into configuration file
13366
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   200
        String c2bRepl = "";
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   201
        if (clzName.startsWith("JIS_X_0208")) {
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   202
            c2bRepl = "new byte[]{ (byte)0x21, (byte)0x29 },";
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   203
        } else if (clzName.startsWith("JIS_X_0212")) {
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   204
            c2bRepl = "new byte[]{ (byte)0x22, (byte)0x44 },";
19377
b2f2886fd1ac 6614237: missing codepage Cp290 at java runtime
sherman
parents: 14342
diff changeset
   205
        } else if (clzName.startsWith("IBM300")) {
b2f2886fd1ac 6614237: missing codepage Cp290 at java runtime
sherman
parents: 14342
diff changeset
   206
            c2bRepl = "new byte[]{ (byte)0x42, (byte)0x6f },";
13366
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   207
        }
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   208
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   209
        while (s.hasNextLine()) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   210
            String line = s.nextLine();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   211
            if (line.indexOf("$") == -1) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   212
                ops.println(line);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   213
                continue;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   214
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   215
            line = line.replace("$PACKAGE$" , pkgName)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   216
                       .replace("$IMPLEMENTS$", (hisName == null)?
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   217
                                "" : "implements HistoricallyNamedCharset")
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   218
                       .replace("$NAME_CLZ$", clzName)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   219
                       .replace("$NAME_ALIASES$",
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   220
                                "sun.nio.cs".equals(pkgName) ?
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   221
                                "StandardCharsets.aliases_" + clzName :
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   222
                                "ExtendedCharsets.aliasesFor(\"" + csName + "\")")
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   223
                       .replace("$NAME_CS$" , csName)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   224
                       .replace("$CONTAINS$",
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   225
                                "MS932".equals(clzName)?
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   226
                                "return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof JIS_X_0201) || (cs instanceof " + clzName + "));":
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   227
                                (isASCII ?
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   228
                                 "return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof " + clzName + "));":
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   229
                                 "return (cs instanceof " + clzName + ");"))
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   230
                       .replace("$HISTORICALNAME$",
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   231
                                (hisName == null)? "" :
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   232
                                "    public String historicalName() { return \"" + hisName + "\"; }")
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   233
                       .replace("$DECTYPE$", type)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   234
                       .replace("$ENCTYPE$", type)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   235
                       .replace("$B1MIN$"   , "0x" + Integer.toString(b1Min, 16))
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   236
                       .replace("$B1MAX$"   , "0x" + Integer.toString(b1Max, 16))
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   237
                       .replace("$B2MIN$"   , "0x" + Integer.toString(b2Min, 16))
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   238
                       .replace("$B2MAX$"   , "0x" + Integer.toString(b2Max, 16))
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   239
                       .replace("$B2C$", b2c)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   240
                       .replace("$C2BLENGTH$", "0x" + Integer.toString(c2bOff, 16))
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   241
                       .replace("$NONROUNDTRIP_B2C$", b2cNR)
13366
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   242
                       .replace("$NONROUNDTRIP_C2B$", c2bNR)
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
   243
                       .replace("$ENC_REPLACEMENT$", c2bRepl);
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   244
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   245
            ops.println(line);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   246
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   247
        ops.close();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   248
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   249
}