make/jdk/src/classes/build/tools/spp/Spp.java
changeset 53110 50677f43ac3d
parent 47216 71c04702a3d5
child 53648 6d37b8ec36fa
equal deleted inserted replaced
53109:b99b41325d89 53110:50677f43ac3d
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package build.tools.spp;
    26 package build.tools.spp;
    27 
    27 
       
    28 import java.io.FileInputStream;
       
    29 import java.io.FileOutputStream;
    28 import java.util.*;
    30 import java.util.*;
    29 import java.util.regex.*;
    31 import java.util.regex.*;
    30 
    32 
    31 /*
    33 /*
    32  * Spp: A simple regex-based stream preprocessor based on Mark Reinhold's
    34  * Spp: A simple regex-based stream preprocessor based on Mark Reinhold's
    67     public static void main(String args[]) throws Exception {
    69     public static void main(String args[]) throws Exception {
    68         Map<String, String> vars = new HashMap<>();
    70         Map<String, String> vars = new HashMap<>();
    69         Set<String> keys = new HashSet<>();
    71         Set<String> keys = new HashSet<>();
    70         boolean be = false;
    72         boolean be = false;
    71         boolean el = true;
    73         boolean el = true;
       
    74         String inputFile = null;
       
    75         String outputFile = null;
    72 
    76 
    73         for (String arg:args) {
    77         for (String arg:args) {
    74             if (arg.startsWith("-D")) {
    78             if (arg.startsWith("-D")) {
    75                 int i = arg.indexOf('=');
    79                 int i = arg.indexOf('=');
    76                 vars.put(arg.substring(2, i),arg.substring(i+1));
    80                 vars.put(arg.substring(2, i),arg.substring(i+1));
    77             } else if (arg.startsWith("-K")) {
    81             } else if (arg.startsWith("-K")) {
    78                 keys.add(arg.substring(2));
    82                 keys.add(arg.substring(2));
       
    83             } else if (arg.startsWith("-i")) {
       
    84                 inputFile = arg.substring(2);
       
    85             } else if (arg.startsWith("-o")) {
       
    86                 outputFile = arg.substring(2);
    79             } else if ("-be".equals(arg)) {
    87             } else if ("-be".equals(arg)) {
    80                 be = true;
    88                 be = true;
    81             } else if ("-nel".equals(arg)) {
    89             } else if ("-nel".equals(arg)) {
    82                 el = false;
    90                 el = false;
    83             } else {
    91             } else {
    85                 System.exit(-1);
    93                 System.exit(-1);
    86             }
    94             }
    87         }
    95         }
    88 
    96 
    89         StringBuffer out = new StringBuffer();
    97         StringBuffer out = new StringBuffer();
    90         new Spp().spp(new Scanner(System.in),
    98         new Spp().spp(new Scanner(new FileInputStream(inputFile)),
    91                       out, "",
    99                       out, "",
    92                       keys, vars, be, el,
   100                       keys, vars, be, el,
    93                       false);
   101                       false);
    94         System.out.print(out.toString());
   102         new FileOutputStream(outputFile, true).write(out.toString().getBytes());
    95     }
   103     }
    96 
   104 
    97     static final String LNSEP = System.getProperty("line.separator");
   105     static final String LNSEP = System.getProperty("line.separator");
    98     static final String KEY = "([a-zA-Z0-9]+)";
   106     static final String KEY = "([a-zA-Z0-9]+)";
    99     static final String VAR = "([a-zA-Z0-9_\\-]+)";
   107     static final String VAR = "([a-zA-Z0-9_\\-]+)";