make/jdk/src/classes/build/tools/charsetmapping/Main.java
author pliden
Thu, 26 Sep 2019 13:56:58 +0200
changeset 58355 de246fd65587
parent 48031 d0cf025a5e79
child 57136 c9bcd764f1f4
permissions -rw-r--r--
8231294: ZGC: vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted002 fails Reviewed-by: shade, dholmes
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
/*
48031
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
     2
 * Copyright (c) 2009, 2017, 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;
48031
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
    57
            boolean hasMS950_HKSCS = false;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    58
            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
    59
            boolean hasEUC_TW = false;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    60
            for (String name : osStdcs) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    61
                Charset cs = charsets.get(name);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    62
                if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    63
                    cs.pkgName = "sun.nio.cs";
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    64
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    65
                if (name.equals("Big5_HKSCS")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    66
                    hasBig5_HKSCS = true;
48031
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
    67
                } else if (name.equals("MS950_HKSCS")) {
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
    68
                    hasMS950_HKSCS = true;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    69
                } else if (name.equals("MS950_HKSCS_XP")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    70
                    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
    71
                } 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
    72
                    hasEUC_TW = true;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    73
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    74
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    75
            for (Charset cs : charsets.values()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    76
                if (isStandard && cs.pkgName.equals("sun.nio.cs.ext") ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    77
                    isExtended && cs.pkgName.equals("sun.nio.cs")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    78
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    79
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    80
                verbose(cs);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    81
                switch (cs.type) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    82
                case "template":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    83
                    SRC.genClass(cs, args[EXT_SRC], args[DST_DIR]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    84
                    break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    85
                case "sbcs":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    86
                    SBCS.genClass(cs, args[SRC_DIR], args[DST_DIR],
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    87
                                  "SingleByte-X.java.template");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    88
                    break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    89
                case "source":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    90
                    break;                   // source file, do nothing
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    91
                default:                     // dbcs
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    92
                    DBCS.genClass("dbcs".equals(cs.type) ?
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    93
                                      "" :  "_" + cs.type.toUpperCase(Locale.ENGLISH),
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    94
                                  cs, args[SRC_DIR], args[DST_DIR],
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    95
                                  "DoubleByte-X.java.template");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    96
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    97
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    98
            // 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
    99
            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
   100
                         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
   101
                         args[TEMPLATE],
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   102
                         args[OS].endsWith("windows") ? "windows" : "unix");
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   103
48031
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
   104
            // HKSCSMapping(2008).java goes std if one of Big5_HKSCS MS950_HKSCS
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
   105
            // is in std
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
   106
            if (isStandard && (hasBig5_HKSCS || hasMS950_HKSCS) ||
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
   107
                isExtended && !(hasBig5_HKSCS  || hasMS950_HKSCS)) {
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   108
                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
   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
            }
48031
d0cf025a5e79 8187910: Charset MS950_HKSCS not supported in JDK 9
sherman
parents: 47216
diff changeset
   112
            // HKSCS_XPMapping.java goes together with MS950XP_HKSCS
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   113
            if (isStandard && hasMS950_HKSCS_XP || isExtended && !hasMS950_HKSCS_XP) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   114
                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
   115
                                 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
   116
                                 new File(args[COPYRIGHT_SRC], "HKSCS.java"));
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   117
            }
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   118
            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
   119
                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
   120
            }
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   121
            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
   122
                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
   123
            }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   124
        } else if ("sjis0213".equals(args[TYPE])) {
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2921
diff changeset
   125
            JIS0213.genClass(args);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   126
        } else if ("hkscs".equals(args[TYPE])) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   127
            HKSCS.genClass2001(args);
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   128
        }
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   129
    }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   130
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   131
    private static LinkedHashMap<String, Charset> getCharsets(File cslist)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   132
        throws Throwable
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   133
    {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   134
        LinkedHashMap<String, Charset> charsets = new LinkedHashMap<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   135
        try (Scanner s = new Scanner(cslist)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   136
            Charset cs = null;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   137
            ArrayList<String> names = new ArrayList<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   138
            while (s.hasNextLine()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   139
                String line = s.nextLine();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   140
                if (line.startsWith("#") || line.length() == 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   141
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   142
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   143
                String[] tokens = line.split("\\s+");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   144
                if (tokens.length < 2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   145
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   146
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   147
                if ("charset".equals(tokens[0])) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   148
                    if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   149
                        cs.aliases = names.toArray(new String[names.size()]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   150
                        charsets.put(cs.clzName, cs);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   151
                        cs = null;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   152
                        names.clear();
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
                    if (tokens.length < 3) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   155
                        throw new RuntimeException("Error: incorrect charset line [" + line + "]");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   156
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   157
                    if ((cs = charsets.get(tokens[2])) != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   158
                        throw new RuntimeException("Error: deplicate charset line [" + line + "]");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   159
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   160
                    cs = new Charset();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   161
                    cs.csName = tokens[1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   162
                    cs.clzName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   163
                } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   164
                    String key = tokens[1];           // leading empty str
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   165
                    switch (key) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   166
                    case "alias":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   167
                        if (tokens.length < 3) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   168
                            throw new RuntimeException("Error: incorrect alias line [" + line + "]");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   169
                        } else if (names != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   170
                            names.add(tokens[2]);     // ALIAS_NAME
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   171
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   172
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   173
                    case "package":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   174
                        cs.pkgName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   175
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   176
                    case "type":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   177
                        cs.type = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   178
                        break;
29119
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   179
                    case "os":
f680ba340556 8073893: Enable charsets build system to configure euc_tw into java.base module/sun.nio.cs
sherman
parents: 29016
diff changeset
   180
                        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
   181
                        break;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   182
                    case "hisname":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   183
                        cs.hisName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   184
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   185
                    case "ascii":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   186
                        cs.isASCII = Boolean.parseBoolean(tokens[2]);
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 "minmax":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   189
                        cs.b1Min = toInteger(tokens[2]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   190
                        cs.b1Max = toInteger(tokens[3]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   191
                        cs.b2Min = toInteger(tokens[4]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   192
                        cs.b2Max = toInteger(tokens[5]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   193
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   194
                    case "internal":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   195
                        cs.isInternal = Boolean.parseBoolean(tokens[2]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   196
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   197
                    default:  // ignore
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
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   201
            if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   202
                cs.aliases = names.toArray(new String[names.size()]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   203
                charsets.put(cs.clzName, cs);
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
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   206
        return charsets;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   207
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   208
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   209
    private static String[] getOSStdCSList(File stdcsos) throws Throwable
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   210
    {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   211
        ArrayList<String> names = new ArrayList<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   212
        if (stdcsos.exists()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   213
            try (Scanner s = new Scanner(stdcsos)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   214
                while (s.hasNextLine()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   215
                    String line = s.nextLine();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   216
                    int i = line.indexOf('#');
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   217
                    if (i != -1) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   218
                        line = line.substring(0, i);
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
                    line = line.trim();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   221
                    if (line.length() != 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   222
                        names.add(line);
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
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   225
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   226
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   227
        return names.toArray(new String[names.size()]);
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
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   230
    static void verbose(Charset cs) {
29016
f14b019bfdfa 8073328: Incremental build of gensrc broken
erikj
parents: 28969
diff changeset
   231
         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
   232
                           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
   233
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   234
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   235
    static int toInteger(String s) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   236
        return (s.startsWith("0x") || s.startsWith("0X"))
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   237
               ? Integer.valueOf(s.substring(2), 16)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   238
               : Integer.valueOf(s);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   239
    }
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   240
}