jdk/make/src/classes/build/tools/charsetmapping/Main.java
author sherman
Wed, 25 Feb 2015 13:04:31 -0800
changeset 29119 f680ba340556
parent 29016 f14b019bfdfa
permissions -rw-r--r--
8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs Summary: to enable charsets build system to configure euc_tw into java.base module/sun.nio.cs Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
     1
/*
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
     4
 *
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
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
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
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.
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    10
 *
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    15
 * accompanied this code).
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    16
 *
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
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.
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    24
 */
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    25
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    26
package build.tools.charsetmapping;
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    27
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    28
import java.io.*;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    29
import java.util.ArrayList;
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    30
import java.util.Scanner;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    31
import java.util.LinkedHashMap;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    32
import java.util.Locale;
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    33
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    34
public class Main {
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    35
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    36
    public static void main(String args[]) throws Throwable {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    37
        int SRC_DIR  = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    38
        int DST_DIR  = 1;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    39
        int TYPE     = 2;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    40
        int CHARSETS = 3;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    41
        int OS       = 4;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    42
        int TEMPLATE = 5;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    43
        int EXT_SRC  = 6;
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
    44
        int COPYRIGHT_SRC  = 7;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    45
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    46
        if (args.length < 3 ) {
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    47
            System.out.println("Usage: java -jar charsetmapping.jar src dst spiType charsets os [template]");
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    48
            System.exit(1);
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    49
        }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    50
        boolean isStandard = "stdcs".equals(args[TYPE]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    51
        boolean isExtended = "extcs".equals(args[TYPE]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    52
        if (isStandard || isExtended) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    53
            LinkedHashMap<String, Charset> charsets = getCharsets(
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    54
                new File(args[SRC_DIR], args[CHARSETS]));
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    55
            String[] osStdcs = getOSStdCSList(new File(args[SRC_DIR], args[OS]));
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    56
            boolean hasBig5_HKSCS = false;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    57
            boolean hasMS950_HKSCS_XP = false;
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
    58
            boolean hasEUC_TW = false;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    59
            for (String name : osStdcs) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    60
                Charset cs = charsets.get(name);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    61
                if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    62
                    cs.pkgName = "sun.nio.cs";
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    63
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    64
                if (name.equals("Big5_HKSCS")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    65
                    hasBig5_HKSCS = true;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    66
                } else if (name.equals("MS950_HKSCS_XP")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    67
                    hasMS950_HKSCS_XP = true;
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
    68
                } else if (name.equals("EUC_TW")) {
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
    69
                    hasEUC_TW = true;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    70
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    71
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    72
            for (Charset cs : charsets.values()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    73
                if (isStandard && cs.pkgName.equals("sun.nio.cs.ext") ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    74
                    isExtended && cs.pkgName.equals("sun.nio.cs")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    75
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    76
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    77
                verbose(cs);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    78
                switch (cs.type) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    79
                case "template":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    80
                    SRC.genClass(cs, args[EXT_SRC], args[DST_DIR]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    81
                    break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    82
                case "sbcs":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    83
                    SBCS.genClass(cs, args[SRC_DIR], args[DST_DIR],
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    84
                                  "SingleByte-X.java.template");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    85
                    break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    86
                case "source":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    87
                    break;                   // source file, do nothing
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    88
                default:                     // dbcs
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    89
                    DBCS.genClass("dbcs".equals(cs.type) ?
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    90
                                      "" :  "_" + cs.type.toUpperCase(Locale.ENGLISH),
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    91
                                  cs, args[SRC_DIR], args[DST_DIR],
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    92
                                  "DoubleByte-X.java.template");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    93
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    94
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    95
            // provider StandardCharsets.java / ExtendedCharsets.java
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
    96
            SPI.genClass(args[TYPE], charsets,
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
    97
                         args[SRC_DIR], args[DST_DIR],
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
    98
                         args[TEMPLATE],
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
    99
                         args[OS].endsWith("windows") ? "windows" : "unix");
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   100
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   101
            // HKSCSMapping2008/XP.java goes together with Big5/MS950XP_HKSCS
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   102
            if (isStandard && hasBig5_HKSCS || isExtended && !hasBig5_HKSCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   103
                HKSCS.genClass2008(args[SRC_DIR], args[DST_DIR],
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   104
                                   isStandard ? "sun.nio.cs" : "sun.nio.cs.ext",
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   105
                                   new File(args[COPYRIGHT_SRC], "HKSCS.java"));
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   106
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   107
            if (isStandard && hasMS950_HKSCS_XP || isExtended && !hasMS950_HKSCS_XP) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   108
                HKSCS.genClassXP(args[SRC_DIR], args[DST_DIR],
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   109
                                 isStandard ? "sun.nio.cs" : "sun.nio.cs.ext",
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   110
                                 new File(args[COPYRIGHT_SRC], "HKSCS.java"));
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   111
            }
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   112
            if (isStandard && hasEUC_TW) {
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   113
                EUC_TW.genClass("sun.nio.cs", args);
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   114
            }
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   115
            if (!isStandard && !hasEUC_TW) {
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   116
                EUC_TW.genClass("sun.nio.cs.ext", args);
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   117
            }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   118
        } else if ("sjis0213".equals(args[TYPE])) {
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2921
diff changeset
   119
            JIS0213.genClass(args);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   120
        } else if ("hkscs".equals(args[TYPE])) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   121
            HKSCS.genClass2001(args);
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   122
        }
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   123
    }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   124
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   125
    private static LinkedHashMap<String, Charset> getCharsets(File cslist)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   126
        throws Throwable
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   127
    {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   128
        LinkedHashMap<String, Charset> charsets = new LinkedHashMap<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   129
        try (Scanner s = new Scanner(cslist)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   130
            Charset cs = null;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   131
            ArrayList<String> names = new ArrayList<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   132
            while (s.hasNextLine()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   133
                String line = s.nextLine();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   134
                if (line.startsWith("#") || line.length() == 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   135
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   136
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   137
                String[] tokens = line.split("\\s+");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   138
                if (tokens.length < 2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   139
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   140
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   141
                if ("charset".equals(tokens[0])) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   142
                    if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   143
                        cs.aliases = names.toArray(new String[names.size()]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   144
                        charsets.put(cs.clzName, cs);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   145
                        cs = null;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   146
                        names.clear();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   147
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   148
                    if (tokens.length < 3) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   149
                        throw new RuntimeException("Error: incorrect charset line [" + line + "]");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   150
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   151
                    if ((cs = charsets.get(tokens[2])) != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   152
                        throw new RuntimeException("Error: deplicate charset line [" + line + "]");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   153
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   154
                    cs = new Charset();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   155
                    cs.csName = tokens[1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   156
                    cs.clzName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   157
                } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   158
                    String key = tokens[1];           // leading empty str
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   159
                    switch (key) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   160
                    case "alias":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   161
                        if (tokens.length < 3) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   162
                            throw new RuntimeException("Error: incorrect alias line [" + line + "]");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   163
                        } else if (names != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   164
                            names.add(tokens[2]);     // ALIAS_NAME
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   165
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   166
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   167
                    case "package":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   168
                        cs.pkgName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   169
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   170
                    case "type":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   171
                        cs.type = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   172
                        break;
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   173
                    case "os":
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   174
                        cs.os = tokens[2];
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   175
                        break;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   176
                    case "hisname":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   177
                        cs.hisName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   178
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   179
                    case "ascii":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   180
                        cs.isASCII = Boolean.parseBoolean(tokens[2]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   181
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   182
                    case "minmax":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   183
                        cs.b1Min = toInteger(tokens[2]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   184
                        cs.b1Max = toInteger(tokens[3]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   185
                        cs.b2Min = toInteger(tokens[4]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   186
                        cs.b2Max = toInteger(tokens[5]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   187
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   188
                    case "internal":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   189
                        cs.isInternal = Boolean.parseBoolean(tokens[2]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   190
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   191
                    default:  // ignore
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   192
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   193
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   194
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   195
            if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   196
                cs.aliases = names.toArray(new String[names.size()]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   197
                charsets.put(cs.clzName, cs);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   198
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   199
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   200
        return charsets;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   201
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   202
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   203
    private static String[] getOSStdCSList(File stdcsos) throws Throwable
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   204
    {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   205
        ArrayList<String> names = new ArrayList<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   206
        if (stdcsos.exists()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   207
            try (Scanner s = new Scanner(stdcsos)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   208
                while (s.hasNextLine()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   209
                    String line = s.nextLine();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   210
                    int i = line.indexOf('#');
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   211
                    if (i != -1) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   212
                        line = line.substring(0, i);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   213
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   214
                    line = line.trim();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   215
                    if (line.length() != 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   216
                        names.add(line);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   217
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   218
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   219
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   220
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   221
        return names.toArray(new String[names.size()]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   222
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   223
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   224
    static void verbose(Charset cs) {
29016
f14b019bfdfa 8073328: Incremental build of gensrc broken
erikj
parents: 28969
diff changeset
   225
         System.out.printf("%s, %s, %s, %s, %s  %b%n",
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   226
                           cs.clzName, cs.csName, cs.hisName, cs.pkgName, cs.type, cs.isASCII);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   227
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   228
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   229
    static int toInteger(String s) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   230
        return (s.startsWith("0x") || s.startsWith("0X"))
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   231
               ? Integer.valueOf(s.substring(2), 16)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   232
               : Integer.valueOf(s);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   233
    }
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   234
}