jdk/make/src/classes/build/tools/charsetmapping/Main.java
author erikj
Wed, 18 Feb 2015 11:18:00 +0100
changeset 29016 f14b019bfdfa
parent 28969 f980bee32887
child 29119 f680ba340556
permissions -rw-r--r--
8073328: Incremental build of gensrc broken Reviewed-by: alanb, tbell, dfuchs, sherman
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;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    44
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    45
        if (args.length < 3 ) {
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    46
            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
    47
            System.exit(1);
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
    48
        }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    49
        boolean isStandard = "stdcs".equals(args[TYPE]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    50
        boolean isExtended = "extcs".equals(args[TYPE]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    51
        if (isStandard || isExtended) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    52
            LinkedHashMap<String, Charset> charsets = getCharsets(
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    53
                new File(args[SRC_DIR], args[CHARSETS]));
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    54
            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
    55
            boolean hasBig5_HKSCS = false;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    56
            boolean hasMS950_HKSCS_XP = false;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    57
            for (String name : osStdcs) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    58
                Charset cs = charsets.get(name);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    59
                if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    60
                    cs.pkgName = "sun.nio.cs";
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    61
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    62
                if (name.equals("Big5_HKSCS")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    63
                    hasBig5_HKSCS = true;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    64
                } else if (name.equals("MS950_HKSCS_XP")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    65
                    hasMS950_HKSCS_XP = true;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    66
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    67
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    68
            for (Charset cs : charsets.values()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    69
                if (isStandard && cs.pkgName.equals("sun.nio.cs.ext") ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    70
                    isExtended && cs.pkgName.equals("sun.nio.cs")) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    71
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    72
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    73
                verbose(cs);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    74
                switch (cs.type) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    75
                case "template":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    76
                    SRC.genClass(cs, args[EXT_SRC], args[DST_DIR]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    77
                    break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    78
                case "sbcs":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    79
                    SBCS.genClass(cs, args[SRC_DIR], args[DST_DIR],
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    80
                                  "SingleByte-X.java.template");
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 "source":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    83
                    break;                   // source file, do nothing
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    84
                default:                     // dbcs
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    85
                    DBCS.genClass("dbcs".equals(cs.type) ?
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    86
                                      "" :  "_" + cs.type.toUpperCase(Locale.ENGLISH),
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    87
                                  cs, args[SRC_DIR], args[DST_DIR],
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    88
                                  "DoubleByte-X.java.template");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    89
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    90
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    91
            // provider StandardCharsets.java / ExtendedCharsets.java
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    92
            SPI.genClass(args[TYPE], charsets, args[SRC_DIR], args[DST_DIR], args[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
            // HKSCSMapping2008/XP.java goes together with Big5/MS950XP_HKSCS
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    95
            if (isStandard && hasBig5_HKSCS || isExtended && !hasBig5_HKSCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    96
                HKSCS.genClass2008(args[SRC_DIR], args[DST_DIR],
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    97
                                   isStandard ? "sun.nio.cs" : "sun.nio.cs.ext");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    98
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
    99
            if (isStandard && hasMS950_HKSCS_XP || isExtended && !hasMS950_HKSCS_XP) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   100
                HKSCS.genClassXP(args[SRC_DIR], args[DST_DIR],
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   101
                                 isStandard ? "sun.nio.cs" : "sun.nio.cs.ext");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   102
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   103
        } else if ("euctw".equals(args[TYPE])) {
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2921
diff changeset
   104
            EUC_TW.genClass(args);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   105
        } else if ("sjis0213".equals(args[TYPE])) {
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2921
diff changeset
   106
            JIS0213.genClass(args);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   107
        } else if ("hkscs".equals(args[TYPE])) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   108
            HKSCS.genClass2001(args);
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   109
        }
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   110
    }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   111
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   112
    private static LinkedHashMap<String, Charset> getCharsets(File cslist)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   113
        throws Throwable
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   114
    {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   115
        LinkedHashMap<String, Charset> charsets = new LinkedHashMap<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   116
        try (Scanner s = new Scanner(cslist)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   117
            Charset cs = null;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   118
            ArrayList<String> names = new ArrayList<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   119
            while (s.hasNextLine()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   120
                String line = s.nextLine();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   121
                if (line.startsWith("#") || line.length() == 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   122
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   123
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   124
                String[] tokens = line.split("\\s+");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   125
                if (tokens.length < 2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   126
                    continue;
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
                if ("charset".equals(tokens[0])) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   129
                    if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   130
                        cs.aliases = names.toArray(new String[names.size()]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   131
                        charsets.put(cs.clzName, cs);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   132
                        cs = null;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   133
                        names.clear();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   134
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   135
                    if (tokens.length < 3) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   136
                        throw new RuntimeException("Error: incorrect charset line [" + line + "]");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   137
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   138
                    if ((cs = charsets.get(tokens[2])) != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   139
                        throw new RuntimeException("Error: deplicate charset line [" + line + "]");
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
                    cs = new Charset();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   142
                    cs.csName = tokens[1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   143
                    cs.clzName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   144
                } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   145
                    String key = tokens[1];           // leading empty str
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   146
                    switch (key) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   147
                    case "alias":
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 alias line [" + line + "]");
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   150
                        } else if (names != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   151
                            names.add(tokens[2]);     // ALIAS_NAME
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   152
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   153
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   154
                    case "package":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   155
                        cs.pkgName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   156
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   157
                    case "type":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   158
                        cs.type = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   159
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   160
                    case "hisname":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   161
                        cs.hisName = tokens[2];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   162
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   163
                    case "ascii":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   164
                        cs.isASCII = Boolean.parseBoolean(tokens[2]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   165
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   166
                    case "minmax":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   167
                        cs.b1Min = toInteger(tokens[2]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   168
                        cs.b1Max = toInteger(tokens[3]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   169
                        cs.b2Min = toInteger(tokens[4]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   170
                        cs.b2Max = toInteger(tokens[5]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   171
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   172
                    case "internal":
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   173
                        cs.isInternal = Boolean.parseBoolean(tokens[2]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   174
                        break;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   175
                    default:  // ignore
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   176
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   177
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   178
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   179
            if (cs != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   180
                cs.aliases = names.toArray(new String[names.size()]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   181
                charsets.put(cs.clzName, cs);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   182
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   183
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   184
        return charsets;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   185
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   186
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   187
    private static String[] getOSStdCSList(File stdcsos) throws Throwable
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   188
    {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   189
        ArrayList<String> names = new ArrayList<>();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   190
        if (stdcsos.exists()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   191
            try (Scanner s = new Scanner(stdcsos)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   192
                while (s.hasNextLine()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   193
                    String line = s.nextLine();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   194
                    int i = line.indexOf('#');
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   195
                    if (i != -1) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   196
                        line = line.substring(0, i);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   197
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   198
                    line = line.trim();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   199
                    if (line.length() != 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   200
                        names.add(line);
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
            }
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
        return names.toArray(new String[names.size()]);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   206
    }
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
    static void verbose(Charset cs) {
29016
f14b019bfdfa 8073328: Incremental build of gensrc broken
erikj
parents: 28969
diff changeset
   209
         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
   210
                           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
   211
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   212
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   213
    static int toInteger(String s) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   214
        return (s.startsWith("0x") || s.startsWith("0X"))
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   215
               ? Integer.valueOf(s.substring(2), 16)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   216
               : Integer.valueOf(s);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents: 23010
diff changeset
   217
    }
2914
1375969fd02e 6843079: Putback for the new EUC_TW is not complete
sherman
parents:
diff changeset
   218
}