make/jdk/src/classes/build/tools/spp/Spp.java
author erikj
Wed, 02 Jan 2019 12:59:26 +0100
changeset 53110 50677f43ac3d
parent 47216 71c04702a3d5
child 53648 6d37b8ec36fa
permissions -rw-r--r--
8215445: Enable building for Windows in WSL Reviewed-by: ihse Contributed-by: andrewluotechnologies@outlook.com, erik.joelsson@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
     1
/*
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
     2
 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
     4
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
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: 898
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 898
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    10
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    15
 * accompanied this code).
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    16
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 898
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 898
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 898
diff changeset
    23
 * questions.
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    24
 */
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    25
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    26
package build.tools.spp;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    27
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    28
import java.io.FileInputStream;
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    29
import java.io.FileOutputStream;
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    30
import java.util.*;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    31
import java.util.regex.*;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    32
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    33
/*
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    34
 * Spp: A simple regex-based stream preprocessor based on Mark Reinhold's
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    35
 *      sed-based spp.sh
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    36
 *
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    37
 * Usage: java build.tools.spp.Spp [-be] [-nel] [-Kkey] -Dvar=value ... <in >out
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    38
 *
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    39
 * If -nel is declared then empty lines will not be substituted for lines of
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    40
 * text in the template that do not appear in the output.
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    41
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    42
 *   Meaningful only at beginning of line, works with any number of keys:
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    43
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    44
 *    #if[key]              Includes text between #if/#end if -Kkey specified,
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    45
 *    #else[key]            otherwise changes text to blank lines; key test
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    46
 *    #end[key]             may be negated by prefixing !, e.g., #if[!key]
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    47
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    48
 *    #begin                If -be is specified then lines up to and including
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    49
 *    #end                  #begin, and from #end to EOF, are deleted
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    50
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    51
 *    #warn                 Changed into warning that file is generated
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    52
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    53
 *    // ##                 Changed into blank line
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    54
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    55
 *  Meaningful anywhere in line
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    56
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    57
 *    {#if[key]?yes}        Expands to yes if -Kkey specified
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    58
 *    {#if[key]?yes:no}     Expands to yes if -Kkey, otherwise no
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    59
 *    {#if[!key]?yes}       Expands to yes if -Kother
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    60
 *    {#if[!key]?yes:no}    Expands to yes if -Kother, otherwise no
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    61
 *    $var$                 Expands to value if -Dvar=value given
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    62
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    63
 *    yes, no must not contain whitespace
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    64
 *
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    65
 * @author Xueming Shen
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    66
 */
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    67
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    68
public class Spp {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    69
    public static void main(String args[]) throws Exception {
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    70
        Map<String, String> vars = new HashMap<>();
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    71
        Set<String> keys = new HashSet<>();
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    72
        boolean be = false;
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    73
        boolean el = true;
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    74
        String inputFile = null;
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    75
        String outputFile = null;
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    76
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    77
        for (String arg:args) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    78
            if (arg.startsWith("-D")) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    79
                int i = arg.indexOf('=');
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    80
                vars.put(arg.substring(2, i),arg.substring(i+1));
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    81
            } else if (arg.startsWith("-K")) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    82
                keys.add(arg.substring(2));
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    83
            } else if (arg.startsWith("-i")) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    84
                inputFile = arg.substring(2);
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    85
            } else if (arg.startsWith("-o")) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    86
                outputFile = arg.substring(2);
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    87
            } else if ("-be".equals(arg)) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    88
                be = true;
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    89
            } else if ("-nel".equals(arg)) {
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    90
                el = false;
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    91
            } else {
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
    92
                System.err.println("Usage: java build.tools.spp.Spp [-be] [-nel] [-Kkey] -Dvar=value ... <in >out");
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    93
                System.exit(-1);
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    94
            }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    95
        }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    96
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    97
        StringBuffer out = new StringBuffer();
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    98
        new Spp().spp(new Scanner(new FileInputStream(inputFile)),
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
    99
                      out, "",
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   100
                      keys, vars, be, el,
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   101
                      false);
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   102
        new FileOutputStream(outputFile, true).write(out.toString().getBytes());
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   103
    }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   104
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   105
    static final String LNSEP = System.getProperty("line.separator");
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   106
    static final String KEY = "([a-zA-Z0-9]+)";
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   107
    static final String VAR = "([a-zA-Z0-9_\\-]+)";
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   108
    static final String TEXT = "([a-zA-Z0-9&;,.<>/#() \\?\\[\\]\\$]+)"; // $ -- hack embedded $var$
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   109
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   110
    static final int GN_NOT = 1;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   111
    static final int GN_KEY = 2;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   112
    static final int GN_YES = 3;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   113
    static final int GN_NO  = 5;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   114
    static final int GN_VAR = 6;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   115
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   116
    final Matcher   ifkey = Pattern.compile("^#if\\[(!)?" + KEY + "\\]").matcher("");
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   117
    final Matcher elsekey = Pattern.compile("^#else\\[(!)?" + KEY + "\\]").matcher("");
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   118
    final Matcher  endkey = Pattern.compile("^#end\\[(!)?" + KEY + "\\]").matcher("");
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   119
    final Matcher  vardef = Pattern.compile("\\{#if\\[(!)?" + KEY + "\\]\\?" + TEXT + "(:"+ TEXT + ")?\\}|\\$" + VAR + "\\$").matcher("");
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   120
    final Matcher vardef2 = Pattern.compile("\\$" + VAR + "\\$").matcher("");
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   121
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   122
    void append(StringBuffer buf, String ln,
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   123
                Set<String> keys, Map<String, String> vars) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   124
        vardef.reset(ln);
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   125
        while (vardef.find()) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   126
            String repl = "";
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   127
            if (vardef.group(GN_VAR) != null)
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   128
                repl = vars.get(vardef.group(GN_VAR));
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   129
            else {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   130
                boolean test = keys.contains(vardef.group(GN_KEY));
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   131
                if (vardef.group(GN_NOT) != null)
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   132
                    test = !test;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   133
                repl = test?vardef.group(GN_YES):vardef.group(GN_NO);
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   134
                if (repl == null)
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   135
                    repl = "";
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   136
                else {  // embedded $var$
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   137
                    while (vardef2.reset(repl).find()) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   138
                        repl = vardef2.replaceFirst(vars.get(vardef2.group(1)));
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   139
                    }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   140
                }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   141
            }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   142
            vardef.appendReplacement(buf, repl);
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   143
        }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   144
        vardef.appendTail(buf);
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   145
    }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   146
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   147
    // return true if #end[key], #end or EOF reached
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   148
    boolean spp(Scanner in, StringBuffer buf, String key,
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   149
                Set<String> keys, Map<String, String> vars,
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   150
                boolean be, boolean el, boolean skip) {
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   151
        while (in.hasNextLine()) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   152
            String ln = in.nextLine();
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   153
            if (be) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   154
                if (ln.startsWith("#begin")) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   155
                    buf.setLength(0);      //clean up to this line
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   156
                    continue;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   157
                }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   158
                if (ln.equals("#end")) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   159
                    while (in.hasNextLine())
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   160
                        in.nextLine();
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   161
                    return true;           //discard the rest to EOF
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   162
                }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   163
            }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   164
            if (ifkey.reset(ln).find()) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   165
                String k = ifkey.group(GN_KEY);
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   166
                boolean test = keys.contains(k);
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   167
                if (ifkey.group(GN_NOT) != null)
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   168
                    test = !test;
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   169
                if (el) buf.append(LNSEP);
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   170
                if (!spp(in, buf, k, keys, vars, be, el, skip || !test)) {
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   171
                    spp(in, buf, k, keys, vars, be, el, skip || test);
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   172
                }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   173
                continue;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   174
            }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   175
            if (elsekey.reset(ln).find()) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   176
                if (!key.equals(elsekey.group(GN_KEY))) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   177
                    throw new Error("Mis-matched #if-else-end at line <" + ln + ">");
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   178
                }
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   179
                if (el) buf.append(LNSEP);
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   180
                return false;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   181
            }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   182
            if (endkey.reset(ln).find()) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   183
                if (!key.equals(endkey.group(GN_KEY))) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   184
                    throw new Error("Mis-matched #if-else-end at line <" + ln + ">");
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   185
                }
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   186
                if (el) buf.append(LNSEP);
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   187
                return true;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   188
            }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   189
            if (ln.startsWith("#warn")) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   190
                ln = "// -- This file was mechanically generated: Do not edit! -- //";
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   191
            } else if (ln.trim().startsWith("// ##")) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   192
                ln = "";
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   193
            }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   194
            if (!skip) {
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   195
                append(buf, ln, keys, vars);
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   196
                if (!el) buf.append(LNSEP);
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   197
            }
35253
ed92ce9fac46 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 23010
diff changeset
   198
            if (el) buf.append(LNSEP);
898
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   199
        }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   200
        return true;
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   201
    }
1c4e95595472 6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
sherman
parents:
diff changeset
   202
}