|
| 1 | +package fortran.ofp; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.apache.commons.cli.CommandLine; |
| 9 | +import org.apache.commons.cli.DefaultParser; |
| 10 | +import org.apache.commons.cli.HelpFormatter; |
| 11 | +import org.apache.commons.cli.Option; |
| 12 | +import org.apache.commons.cli.Options; |
| 13 | +import org.apache.commons.cli.ParseException; |
| 14 | + |
| 15 | +public class Main { |
| 16 | + |
| 17 | + public static void main(String args[]) throws IOException { |
| 18 | + Options options = new Options(); |
| 19 | + options.addOption(null, "RiceCAF", false, "use Rice University's CAF extensions"); |
| 20 | + options.addOption(null, "LOPExt", false, "use OFP's LOPe research extensions"); |
| 21 | + |
| 22 | + Option input = new Option("f", "file", true, "input file path"); |
| 23 | + input.setRequired(true); |
| 24 | + options.addOption(input); |
| 25 | + |
| 26 | + Option verbose = new Option("v", false, "verbose"); |
| 27 | + options.addOption(verbose); |
| 28 | + |
| 29 | + Option output = new Option("o", "output", true, "output file"); |
| 30 | + output.setRequired(false); |
| 31 | + options.addOption(output); |
| 32 | + |
| 33 | + DefaultParser parser = new DefaultParser(); |
| 34 | + CommandLine cmd = null; |
| 35 | + try { |
| 36 | + cmd = parser.parse(options, args); |
| 37 | + } catch (ParseException e) { |
| 38 | + System.out.println(e.getMessage()); |
| 39 | + } |
| 40 | + |
| 41 | + if (cmd == null || cmd.hasOption("help")) { |
| 42 | + HelpFormatter formatter = new HelpFormatter(); |
| 43 | + formatter.printHelp("open-fortran-parser-xml [options] file", options); |
| 44 | + System.exit(1); |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + System.out.println(cmd.getArgList().toString()); |
| 49 | + System.out.println(Arrays.asList(cmd.getOptions()).toString()); |
| 50 | + |
| 51 | + String inputFilePath = cmd.getOptionValue("file"); |
| 52 | + String outputFilePath = cmd.getOptionValue("output"); |
| 53 | + |
| 54 | + System.out.println(inputFilePath); |
| 55 | + System.out.println(outputFilePath); |
| 56 | + |
| 57 | + List<String> ofpArgs = new ArrayList<String>(); |
| 58 | + if (cmd.hasOption("RiceCAF")) |
| 59 | + ofpArgs.add("--RiceCAF"); |
| 60 | + if (cmd.hasOption("LOPExt")) |
| 61 | + ofpArgs.add("--LOPExt"); |
| 62 | + String[] ofpArgsArray = ofpArgs.toArray(new String[ofpArgs.size()]); |
| 63 | + |
| 64 | + String type = "fortran.ofp.XMLPrinter"; |
| 65 | + FrontEnd ofp = new FrontEnd(ofpArgsArray, cmd.getOptionValue("file"), type); |
| 66 | + ofp.setVerbose(cmd.hasOption("verbose"), null); |
| 67 | + // TODO: incomplete implementation |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments