From: Peter S. <sch...@us...> - 2007-12-14 13:24:21
|
Update of /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14840/Plb/src/java/net/sf/plb4jedit/plb Modified Files: ListingAnalyzer.java Log Message: fix: errors in includes in the same directory as the source were not handeled properly Index: ListingAnalyzer.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/ListingAnalyzer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ListingAnalyzer.java 25 Aug 2005 09:21:06 -0000 1.5 +++ ListingAnalyzer.java 14 Dec 2007 13:24:23 -0000 1.6 @@ -6,6 +6,7 @@ package net.sf.plb4jedit.plb; import java.io.BufferedReader; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -17,6 +18,9 @@ import java.util.regex.Pattern; /** * $Log$ + * Revision 1.6 2007/12/14 13:24:23 schaefep + * fix: errors in includes in the same directory as the source were not handeled properly + * * Revision 1.5 2005/08/25 09:21:06 ampeer * Added new RE for plb90-loop-error * @@ -27,18 +31,18 @@ * some refactorings in PlbSource and Include for better use in PlbRepository * Revision 1.2 2003/12/09 14:20:13 schaefep * format - * + * * Revision 1.1 2003/11/07 16:57:27 schaefep initial ps - * + * * program to analyze compile output from plbcmp - * + * * Analyze listings created by the plb compiler using options PE 999999 * Compiling a source xxxxxx.dbs with these options produce a xxxxxx.lst in the * directory where the xxxxxx.plc is stored. @autor Peter Schaefer */ public class ListingAnalyzer { public final static String cvsId = - "$Header$"; + "$Header$"; /** * stores the original listing; each entry one line of the listing as * String @@ -68,6 +72,7 @@ private Pattern fatalErrorPattern; private Pattern resultPattern; private String listName; + private String srcDir; /** * avoid construction without an listing @@ -81,219 +86,225 @@ * windows/dos you don't have to escape the double ticks ... */ public ListingAnalyzer(String listName, String sourceName) - throws IOException, FileNotFoundException { - if (sourceName == null || sourceName.length() == 0) { - throw new IllegalArgumentException("need sourceName (full path)"); - } - this.listName = listName; - programName = sourceName; - BufferedReader reader = - new BufferedReader( - new InputStreamReader(new FileInputStream(listName))); - listing = new Vector(); - errors = new Vector(); - warnings = new Vector(); - includes = new HashMap(); - String line = null; - int i = 0; - while ((line = reader.readLine()) != null) { - if (line.trim().length() > 0) { - listing.add(line); - } - } - reader.close(); - if (listing.size() == 0) { - throw new IllegalArgumentException( - "Error: listing is empty. (May happen " - + "if compilation failed, because debugger is executing program!"); - } - initPattern(); - for (i = 0; i < listing.size(); i++) { - analyze(i); - } + throws IOException, FileNotFoundException { + if (sourceName == null || sourceName.length() == 0) { + throw new IllegalArgumentException("need sourceName (full path)"); + } + File srcFile = new File(sourceName); + srcDir = srcFile.getParent(); + + this.listName = listName; + programName = sourceName; + BufferedReader reader = + new BufferedReader( + new InputStreamReader(new FileInputStream(listName))); + listing = new Vector(); + errors = new Vector(); + warnings = new Vector(); + includes = new HashMap(); + String line = null; + int i = 0; + while ((line = reader.readLine()) != null) { + if (line.trim().length() > 0) { + listing.add(line); + } + } + reader.close(); + if (listing.size() == 0) { + throw new IllegalArgumentException( + "Error: listing is empty. (May happen " + + "if compilation failed, because debugger is executing program!"); + } + initPattern(); + for (i = 0; i < listing.size(); i++) { + analyze(i); + } } private void initPattern() { - // 85.AC INCLUDE AD: /opt/rsi/plbsrc/incs/misc/rsistart.dbs - includePattern = - Pattern.compile( - ".*\\d.[ ,a-zA-Z]{0,2}\\s*INCLUDE ([ ,a-zA-Z]{1,2}):\\s*(.*)"); - //errorPattern = Pattern.compile("^\\s*(\\*)ERROR\\*.*$"); - errorPattern = Pattern.compile("^\\s*(\\*).*$"); - warningPattern = Pattern.compile("^\\s*(\\*)WARNING\\*.*$"); - // 91.AA moe spaces,#alausw - locateErrorPattern = - Pattern.compile("\\s*(\\d*)\\.([ ,a-zA-Z]{0,2})\\s*(.*)$"); - undefinedExecutionLabelPattern = - Pattern.compile("^(Undefined execution label:.*).*$"); - ifLoopSwitchNotTerminatedPattern = - Pattern.compile( - "^IF/LOOP/SWITCH statement at line \\((\\d+)(\\.([ ,a-zA-Z]{1,2}))?\\) not terminated\\..*$"); - ifLoopSwitchNotTerminatedPattern90 = - Pattern.compile( - "^IF/LOOP/SWITCH/FOR statement at line \\((\\d+)(\\.([ ,a-zA-Z]{1,2}))?\\) not terminated\\..*$"); - lastWordPattern = Pattern.compile("\\.*([a-zA-Z0-9#]+)$"); - fatalErrorPattern = Pattern.compile("\\.*FATAL ERROR ENCOUNTERED.*$"); - resultPattern = - Pattern.compile( - "^\\s*(\\d*) LINES;\\s*(\\d*) ERRORS;\\s*(\\d*) WARNINGS;.*$"); + // 85.AC INCLUDE AD: /opt/rsi/plbsrc/incs/misc/rsistart.dbs + includePattern = + Pattern.compile( + ".*\\d.[ ,a-zA-Z]{0,2}\\s*INCLUDE ([ ,a-zA-Z]{1,2}):\\s*(.*)"); + //errorPattern = Pattern.compile("^\\s*(\\*)ERROR\\*.*$"); + errorPattern = Pattern.compile("^\\s*(\\*).*$"); + warningPattern = Pattern.compile("^\\s*(\\*)WARNING\\*.*$"); + // 91.AA moe spaces,#alausw + locateErrorPattern = + Pattern.compile("\\s*(\\d*)\\.([ ,a-zA-Z]{0,2})\\s*(.*)$"); + undefinedExecutionLabelPattern = + Pattern.compile("^(Undefined execution label:.*).*$"); + ifLoopSwitchNotTerminatedPattern = + Pattern.compile( + "^IF/LOOP/SWITCH statement at line \\((\\d+)(\\.([ ,a-zA-Z]{1,2}))?\\) not terminated\\..*$"); + ifLoopSwitchNotTerminatedPattern90 = + Pattern.compile( + "^IF/LOOP/SWITCH/FOR statement at line \\((\\d+)(\\.([ ,a-zA-Z]{1,2}))?\\) not terminated\\..*$"); + lastWordPattern = Pattern.compile("\\.*([a-zA-Z0-9#]+)$"); + fatalErrorPattern = Pattern.compile("\\.*FATAL ERROR ENCOUNTERED.*$"); + resultPattern = + Pattern.compile( + "^\\s*(\\d*) LINES;\\s*(\\d*) ERRORS;\\s*(\\d*) WARNINGS;.*$"); } private void analyze(int i) { - String line = (String) listing.get(i); - Matcher matcher, errorMatcher; - matcher = includePattern.matcher(line); - if (matcher.matches()) { - int found = matcher.groupCount(); - if (found == 2) { - String key = matcher.group(1).trim(); - String includeName = matcher.group(2); - debug(found + ":" + key + ":" + includeName); - includes.put(key, includeName); - } - } + String line = (String) listing.get(i); + Matcher matcher, errorMatcher; + matcher = includePattern.matcher(line); + if (matcher.matches()) { + int found = matcher.groupCount(); + if (found == 2) { + String key = matcher.group(1).trim(); + String includeName = matcher.group(2); + if (includeName.indexOf(File.separator) < 0) { + includeName = srcDir + File.separator + includeName; + } + debug(found + ":" + key + ":" + includeName); + includes.put(key, includeName); + } + } - if ((errorMatcher = errorPattern.matcher(line)).matches()) { - if ((matcher = - locateErrorPattern.matcher((String) listing.get(i - 1))) - .matches()) { - String key = matcher.group(2).trim(); - //debug("key="+key+" " +includes.get(key.trim())); - String lineNo = matcher.group(1); - //String source = matcher.group(3); - String msg = ((String) listing.get(i + 1)).trim(); - String sourceName = programName; - if (key != null - && key.trim().length() > 0 - && includes.containsKey(key)) { - sourceName = (String) includes.get(key); - } - int col = line.indexOf("*"); - debug( - "errorPattern->" - + sourceName - + " " - + lineNo - + " column=" - + col - + " msg=" - + msg); - addError(new String(sourceName + ":" + lineNo + ":" + msg)); - if (col > 0) { - String prevLine = (String) listing.get(i - 1); - String location = prevLine; - if ((matcher = locateErrorPattern.matcher(location)) - .matches()) { - location = matcher.group(3); - } - appendError(new String("location: " + location)); - String symbol = null; - // cut up to position before error arised - if (col >= prevLine.length()) { - symbol = prevLine; - } else { - symbol = prevLine.substring(0, col); - } - if ((matcher = lastWordPattern.matcher(symbol)) - .matches()) { - symbol = matcher.group(1); - } else { - symbol = "at the end of the line"; - } - appendError(new String("symbol: " + symbol)); - } - } - debug("error: " + listing.get(i + 1) + " at " + listing.get(i - 1)); - debug("error starts at " + errorMatcher.group(1)); - } - if ((matcher = warningPattern.matcher(line)).matches()) { - if ((matcher = - locateErrorPattern.matcher((String) listing.get(i - 1))) - .matches()) { - String key = matcher.group(2).trim(); - debug(key + " " + includes.get(key.trim())); - String lineNo = matcher.group(1); - //String source = matcher.group(3); - String msg = ((String) listing.get(i + 1)).trim(); - String sourceName = programName; - if (key != null - && key.trim().length() > 0 - && includes.containsKey(key)) { - sourceName = (String) includes.get(key); - } - debug("Warning:" + sourceName + ":" + lineNo + ":" + msg); - warnings.add(new String(sourceName + ":" + lineNo + ":" + msg)); - } - debug( - "warning: " + listing.get(i + 1) + " at " + listing.get(i - 1)); - } - if ((matcher = undefinedExecutionLabelPattern.matcher(line)) - .matches()) { - addError( - new String(programName + ":" + 1 + ":" + matcher.group(0))); - } - if ((matcher = ifLoopSwitchNotTerminatedPattern.matcher(line)) - .matches()) { - String lineNumber = matcher.group(1); - String key = matcher.group(3); - //System.out.println("Key: "+key); - String sourceName = programName; - if (key != null - && key.trim().length() > 0 - && includes.containsKey(key)) { - sourceName = (String) includes.get(key); - } - addError( - new String( - sourceName - + ":" - + lineNumber - + ": if/Loop/Switch/ not terminated")); - } - if ((matcher = ifLoopSwitchNotTerminatedPattern90.matcher(line)) - .matches()) { - String lineNumber = matcher.group(1); - String key = matcher.group(3); - //System.out.println("Key: "+key); - String sourceName = programName; - if (key != null - && key.trim().length() > 0 - && includes.containsKey(key)) { - sourceName = (String) includes.get(key); - } - addError( - new String( - sourceName - + ":" - + lineNumber - + ": if/Loop/Switch/For not terminated")); - } - if ((matcher = fatalErrorPattern.matcher(line)).matches()) { - addError(new String(programName + ":1: FATAL ERROR ENCOUNTERED")); - } - if ((matcher = resultPattern.matcher(line)).matches()) { - resultMessage = line; - realErrors = Integer.parseInt(matcher.group(2)); - realWarnings = Integer.parseInt(matcher.group(3)); - } + if ((errorMatcher = errorPattern.matcher(line)).matches()) { + if ((matcher = + locateErrorPattern.matcher((String) listing.get(i - 1))) + .matches()) { + String key = matcher.group(2).trim(); + //debug("key="+key+" " +includes.get(key.trim())); + String lineNo = matcher.group(1); + //String source = matcher.group(3); + String msg = ((String) listing.get(i + 1)).trim(); + String sourceName = programName; + if (key != null + && key.trim().length() > 0 + && includes.containsKey(key)) { + sourceName = (String) includes.get(key); + } + int col = line.indexOf("*"); + debug( + "errorPattern->" + + sourceName + + " " + + lineNo + + " column=" + + col + + " msg=" + + msg); + addError(new String(sourceName + ":" + lineNo + ":" + msg)); + if (col > 0) { + String prevLine = (String) listing.get(i - 1); + String location = prevLine; + if ((matcher = locateErrorPattern.matcher(location)) + .matches()) { + location = matcher.group(3); + } + appendError(new String("location: " + location)); + String symbol = null; + // cut up to position before error arised + if (col >= prevLine.length()) { + symbol = prevLine; + } else { + symbol = prevLine.substring(0, col); + } + if ((matcher = lastWordPattern.matcher(symbol)) + .matches()) { + symbol = matcher.group(1); + } else { + symbol = "at the end of the line"; + } + appendError(new String("symbol: " + symbol)); + } + } + debug("error: " + listing.get(i + 1) + " at " + listing.get(i - 1)); + debug("error starts at " + errorMatcher.group(1)); + } + if ((matcher = warningPattern.matcher(line)).matches()) { + if ((matcher = + locateErrorPattern.matcher((String) listing.get(i - 1))) + .matches()) { + String key = matcher.group(2).trim(); + debug(key + " " + includes.get(key.trim())); + String lineNo = matcher.group(1); + //String source = matcher.group(3); + String msg = ((String) listing.get(i + 1)).trim(); + String sourceName = programName; + if (key != null + && key.trim().length() > 0 + && includes.containsKey(key)) { + sourceName = (String) includes.get(key); + } + debug("Warning:" + sourceName + ":" + lineNo + ":" + msg); + warnings.add(new String(sourceName + ":" + lineNo + ":" + msg)); + } + debug( + "warning: " + listing.get(i + 1) + " at " + listing.get(i - 1)); + } + if ((matcher = undefinedExecutionLabelPattern.matcher(line)) + .matches()) { + addError( + new String(programName + ":" + 1 + ":" + matcher.group(0))); + } + if ((matcher = ifLoopSwitchNotTerminatedPattern.matcher(line)) + .matches()) { + String lineNumber = matcher.group(1); + String key = matcher.group(3); + //System.out.println("Key: "+key); + String sourceName = programName; + if (key != null + && key.trim().length() > 0 + && includes.containsKey(key)) { + sourceName = (String) includes.get(key); + } + addError( + new String( + sourceName + + ":" + + lineNumber + + ": if/Loop/Switch/ not terminated")); + } + if ((matcher = ifLoopSwitchNotTerminatedPattern90.matcher(line)) + .matches()) { + String lineNumber = matcher.group(1); + String key = matcher.group(3); + //System.out.println("Key: "+key); + String sourceName = programName; + if (key != null + && key.trim().length() > 0 + && includes.containsKey(key)) { + sourceName = (String) includes.get(key); + } + addError( + new String( + sourceName + + ":" + + lineNumber + + ": if/Loop/Switch/For not terminated")); + } + if ((matcher = fatalErrorPattern.matcher(line)).matches()) { + addError(new String(programName + ":1: FATAL ERROR ENCOUNTERED")); + } + if ((matcher = resultPattern.matcher(line)).matches()) { + resultMessage = line; + realErrors = Integer.parseInt(matcher.group(2)); + realWarnings = Integer.parseInt(matcher.group(3)); + } } private void addError(String msg) { - errors.add(msg); - - errorNo++; - + errors.add(msg); + + errorNo++; + } - + private void appendError(String msg) { - String s = (String)errors.lastElement() + "\n" + msg; - errors.setElementAt(s, errors.size()-1); + String s = (String)errors.lastElement() + "\n" + msg; + errors.setElementAt(s, errors.size()-1); } - + private void debug(String s) { - if (DEBUG) { - System.out.println(s); - } + if (DEBUG) { + System.out.println(s); + } } /** @@ -302,57 +313,57 @@ * Console -> Error patterns */ public void printGeneric(PrintStream ps) { - for (int i = 0; i < errors.size(); i++) { - ps.println(errors.get(i).toString()); - } - for (int i = 0; i < warnings.size(); i++) { - ps.println(warnings.get(i).toString()); - } - if (realErrors != errors.size() || realWarnings != warnings.size()) { - ps.println( - "Error in ListingAnalyzer: there are errors/warnings in the listing file that I didn't realize! Check listing file " - + listName - + "\nrealErrors=" - + realErrors - + " found errors=" - + errors.size() - + "\nrealWarnings=" - + realWarnings - + " found warnings=" - + warnings.size()); - } - ps.println(resultMessage.replaceAll(":", " ")); + for (int i = 0; i < errors.size(); i++) { + ps.println(errors.get(i).toString()); + } + for (int i = 0; i < warnings.size(); i++) { + ps.println(warnings.get(i).toString()); + } + if (realErrors != errors.size() || realWarnings != warnings.size()) { + ps.println( + "Error in ListingAnalyzer: there are errors/warnings in the listing file that I didn't realize! Check listing file " + + listName + + "\nrealErrors=" + + realErrors + + " found errors=" + + errors.size() + + "\nrealWarnings=" + + realWarnings + + " found warnings=" + + warnings.size()); + } + ps.println(resultMessage.replaceAll(":", " ")); } public void printGeneric() { - printGeneric(System.out); + printGeneric(System.out); } public void printListing() { - for (int i = 0; i < listing.size(); i++) { - System.out.println((String) listing.get(i)); - } + for (int i = 0; i < listing.size(); i++) { + System.out.println((String) listing.get(i)); + } } public int numberOfErrors() { - return errorNo; + return errorNo; } public int numberOfWarnings() { - return warnings.size(); + return warnings.size(); } public static void main(String[] args) throws Exception { - if (args.length != 2) { - System.out.println("ListingAnalyzer xxxxxxxxx.lst sourceName"); - System.exit(0); - } - ListingAnalyzer analyzer = new ListingAnalyzer(args[0], args[1]); - //analyzer.printListing(); - analyzer.printGeneric(); - /*********************************************************************** + if (args.length != 2) { + System.out.println("ListingAnalyzer xxxxxxxxx.lst sourceName"); + System.exit(0); + } + ListingAnalyzer analyzer = new ListingAnalyzer(args[0], args[1]); + //analyzer.printListing(); + analyzer.printGeneric(); + /*********************************************************************** * Pattern p = Pattern.compile("^\\s*\\*ERROR\\*. - * + * * ERROR* "; Matcher m = p.matcher(s); */ } |