From: Peter S. <sch...@us...> - 2008-07-07 16:19:36
|
Update of /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18388/Plb/src/java/net/sf/plb4jedit/plb Modified Files: PLBCompiler.java Log Message: options to compile with listing file and debug infos Index: PLBCompiler.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/PLBCompiler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- PLBCompiler.java 8 Jan 2007 11:19:40 -0000 1.3 +++ PLBCompiler.java 7 Jul 2008 16:19:38 -0000 1.4 @@ -28,116 +28,144 @@ private Properties plbEnv; private File tmp; private String plbwinINIFile; + private boolean withDebug; + private boolean withListing; public PLBCompiler() throws IOException { - tmp = File.createTempFile("PLBCompiler",".log"); - plbEnv = new Properties(); + tmp = File.createTempFile("PLBCompiler",".log"); + plbEnv = new Properties(); } public void usePlbWinINIFile(String wini) throws Exception { - plbwinINIFile = wini; + plbwinINIFile = wini; } - + public void usePlbCompilerProperties(String cmpprops) throws Exception { - Properties cmpenv = new Properties(); - cmpenv.load(new FileInputStream(cmpprops)); - Enumeration keys = cmpenv.propertyNames(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - if (StringUtils.isNotBlank(cmpenv.getProperty(key))) { - plbEnv.setProperty(key.toUpperCase(), cmpenv.getProperty(key)); - } - } + Properties cmpenv = new Properties(); + cmpenv.load(new FileInputStream(cmpprops)); + Enumeration keys = cmpenv.propertyNames(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + if (StringUtils.isNotBlank(cmpenv.getProperty(key))) { + plbEnv.setProperty(key.toUpperCase(), cmpenv.getProperty(key)); + } + } + } + + public void setDebug(boolean debug) { + withDebug = debug; + } + + public void setListing(boolean listing) { + withListing = listing; } public int compile(File plbSource) throws Exception { - if (plbSource == null || !plbSource.exists()) { - throw new IllegalArgumentException("PLB Source does not exist "); - } - final File workingDir = plbSource.getParentFile(); - final String name = plbSource.getName(); + if (plbSource == null || !plbSource.exists()) { + throw new IllegalArgumentException("PLB Source does not exist "); + } + final File workingDir = plbSource.getParentFile(); + final String name = plbSource.getName(); - - String[] cmd; - int i = -1; - final int ANZ_OPTS=14; - if (StringUtils.isNotBlank(plbwinINIFile)) { - cmd = new String[ANZ_OPTS+3]; - cmd[++i] = plbEnv.getProperty("RSI_PLBCMD","plb"); - cmd[++i] = "-h"; - cmd[++i] = "-i"; - cmd[++i] = plbwinINIFile; - } else { - cmd = new String[ANZ_OPTS]; - cmd[++i] = plbEnv.getProperty("RSI_PLBCMD","plb"); - } - cmd[++i] = "plbcmp"; - cmd[++i] = plbSource.getAbsolutePath(); - cmd[++i] = plbEnv.getProperty("RSI_PLCDIR") + File.separator + StringUtils.replace(name, ".dbs", ".plc"); - cmd[++i] = "-E=dbs"; - cmd[++i] = "E"; - cmd[++i] = "P"; - if (File.separator.equals("/")) { - cmd[++i] = "\"x header\""; - } else { - cmd[++i] = "\"x header\""; - } - cmd[++i] = "99999"; - cmd[++i] = "S"; - cmd[++i] = "ZH"; - cmd[++i] = "ZT"; - cmd[++i] = "ZG"; - cmd[++i] = "ZV"; - - PrintStream devnull = new PrintStream(tmp); - if (!Boolean.parseBoolean(plbEnv.getProperty("RSI_DEBUG","false"))) { - tmp.deleteOnExit(); - } - return ProcessRunner.exec(cmd, plbEnv, workingDir, devnull, devnull); + + String[] cmd; + int i = -1; + int ANZ_OPTS; + if (withDebug) { + ANZ_OPTS =14; + } else { + ANZ_OPTS =13; + } + if (StringUtils.isNotBlank(plbwinINIFile)) { + cmd = new String[ANZ_OPTS+3]; + cmd[++i] = plbEnv.getProperty("RSI_PLBCMD","plb"); + cmd[++i] = "-h"; + cmd[++i] = "-i"; + cmd[++i] = plbwinINIFile; + } else { + cmd = new String[ANZ_OPTS]; + cmd[++i] = plbEnv.getProperty("RSI_PLBCMD","plb"); + } + cmd[++i] = "plbcmp"; + cmd[++i] = plbSource.getAbsolutePath(); + cmd[++i] = plbEnv.getProperty("RSI_PLCDIR") + File.separator + StringUtils.replace(name, ".dbs", ".plc"); + cmd[++i] = "-E=dbs"; + if (withListing) { + cmd[++i] = "L"; + } else { + cmd[++i] = "E"; + } + cmd[++i] = "P"; + if (File.separator.equals("/")) { + cmd[++i] = "\"x header\""; + } else { + cmd[++i] = "\"x header\""; + } + cmd[++i] = "99999"; + if (withDebug) { + cmd[++i] = "S"; + } + cmd[++i] = "ZH"; + cmd[++i] = "ZT"; + cmd[++i] = "ZG"; + cmd[++i] = "ZV"; + + PrintStream devnull = new PrintStream(tmp); + if (!Boolean.parseBoolean(plbEnv.getProperty("RSI_DEBUG","false"))) { + tmp.deleteOnExit(); + } + return ProcessRunner.exec(cmd, plbEnv, workingDir, devnull, devnull); } - + public void analyzeListing(File plbSource) throws Exception { - String listing = plbEnv.getProperty("RSI_PLCDIR") + File.separator + StringUtils.replace(plbSource.getName(), ".dbs", ".lst"); - ListingAnalyzer analyzer = new ListingAnalyzer(listing, plbSource.getAbsolutePath()); - analyzer.printGeneric(); + String listing = plbEnv.getProperty("RSI_PLCDIR") + File.separator + StringUtils.replace(plbSource.getName(), ".dbs", ".lst"); + ListingAnalyzer analyzer = new ListingAnalyzer(listing, plbSource.getAbsolutePath()); + analyzer.printGeneric(); } public static void main(String[] args) throws Exception { - CommandLineParser parser = new GnuParser(); - Options options = new Options(); - Option plbwinIni = OptionBuilder.withArgName("properties-file") - .hasArg() - .withDescription( "plbwin ini File") - .create( "plbwini"); - - Option plbcmp = OptionBuilder.withArgName( "properties-file" ) - .hasArg() - .withDescription( "Configuration Properties for the PLBCompiler") - .create( "plbcmp"); - - options.addOption(plbwinIni); - options.addOption(plbcmp); - - CommandLine line = parser.parse( options, args ); - PLBCompiler compiler = new PLBCompiler(); - - if (line.hasOption("plbwini")) { - compiler.usePlbWinINIFile(line.getOptionValue("plbwini")); - } - if (line.hasOption("plbcmp")) { - compiler.usePlbCompilerProperties(line.getOptionValue("plbcmp")); - } - - args = line.getArgs(); - - for (int i = 0; i < args.length; i++) { - System.out.println("Compiling " + args[i]); - File plbSource = new File(args[i]); - int returnCode = compiler.compile(plbSource); - if (returnCode != 0) { - System.err.println("PLB Compiler returned errorcode '" + returnCode + "'"); - } - compiler.analyzeListing(plbSource); - } + CommandLineParser parser = new GnuParser(); + Options options = new Options(); + Option plbwinIni = OptionBuilder.withArgName("properties-file") + .hasArg() + .withDescription( "plbwin ini File") + .create( "plbwini"); + + Option plbcmp = OptionBuilder.withArgName( "properties-file" ) + .hasArg() + .withDescription( "Configuration Properties for the PLBCompiler") + .create( "plbcmp"); + + Option debug = new Option( "debug", "print debugging information" ); + Option listing = new Option( "withListing", "create debug listing" ); + + options.addOption(plbwinIni); + options.addOption(plbcmp); + options.addOption(debug); + options.addOption(listing); + + CommandLine line = parser.parse( options, args ); + PLBCompiler compiler = new PLBCompiler(); + + if (line.hasOption("plbwini")) { + compiler.usePlbWinINIFile(line.getOptionValue("plbwini")); + } + if (line.hasOption("plbcmp")) { + compiler.usePlbCompilerProperties(line.getOptionValue("plbcmp")); + } + compiler.setDebug(line.hasOption("debug")); + compiler.setListing(line.hasOption("withListing")); + + args = line.getArgs(); + + for (int i = 0; i < args.length; i++) { + System.out.println("Compiling " + args[i]); + File plbSource = new File(args[i]); + int returnCode = compiler.compile(plbSource); + if (returnCode != 0) { + System.err.println("PLB Compiler returned errorcode '" + returnCode + "'"); + } + compiler.analyzeListing(plbSource); + } } } |