Re: [cp-patches] RFC: @file support for gjavah gjar
Hi Andrew, thanks a lot for fixing the remaining issues and committing this. Regards Robert Andrew John Hughes schrieb: Committed with the amendments suggested by Tom and Mario: 2008-06-06 Andrew John Hughes [EMAIL PROTECTED] * tools/gnu/classpath/tools/common/ClasspathToolParser.java: Fixed indentation and changed to use OptionException. * tools/gnu/classpath/tools/getopt/OptionException.java: (OptionException(String,Throwable)): Added. 2008-06-03 Robert Schuster [EMAIL PROTECTED] * tools/gnu/classpath/tools/jar/Main.java: (run): Call different ClasspathToolParser.parse() variant. (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/javah/GcjhMain.java: (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/javah/Main.java: (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/getopt/Parser.java: Make 'programName' protected. * tools/gnu/classpath/tools/common/ClasspathToolParser.java: (parse(String[], FileArgumentCallback,boolean): New method. (parse(String[], boolean): New method. (parseFileList): New method. (parseLine): New method. (AtFileArgumentCallback): New inner class. signature.asc Description: OpenPGP digital signature
Re: [cp-patches] RFC: @file support for gjavah gjar
On 04/06/2008, Mario Torre [EMAIL PROTECTED] wrote: Il giorno mer, 04/06/2008 alle 09.08 -0600, Tom Tromey ha scritto: Some of the indentation seems wrong to me, though I always find it a bit hard to tell due to diffs making tabs look weird. I don't know if I say a popular thing or not, but please, expand your tabs into spaces, it makes the whole code readable when I look at it using cat and less, sometime is quite hard to understand, especially when we have no brace code like: if (true) doWhatever(); else someThingSeriouslyScrewedIfImHere(); It becomes sometime, for example like: if (true) doWhatever(); else someThingSeriouslyScrewedIfImHere(); due to werid mix of tabs and spaces Thanks, Mario Committed with the amendments suggested by Tom and Mario: 2008-06-06 Andrew John Hughes [EMAIL PROTECTED] * tools/gnu/classpath/tools/common/ClasspathToolParser.java: Fixed indentation and changed to use OptionException. * tools/gnu/classpath/tools/getopt/OptionException.java: (OptionException(String,Throwable)): Added. 2008-06-03 Robert Schuster [EMAIL PROTECTED] * tools/gnu/classpath/tools/jar/Main.java: (run): Call different ClasspathToolParser.parse() variant. (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/javah/GcjhMain.java: (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/javah/Main.java: (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/getopt/Parser.java: Make 'programName' protected. * tools/gnu/classpath/tools/common/ClasspathToolParser.java: (parse(String[], FileArgumentCallback,boolean): New method. (parse(String[], boolean): New method. (parseFileList): New method. (parseLine): New method. (AtFileArgumentCallback): New inner class. -- Andrew :-) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint: F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8 Index: tools/gnu/classpath/tools/common/ClasspathToolParser.java === RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/common/ClasspathToolParser.java,v retrieving revision 1.1 diff -u -u -r1.1 ClasspathToolParser.java --- tools/gnu/classpath/tools/common/ClasspathToolParser.java 22 Sep 2006 01:01:26 - 1.1 +++ tools/gnu/classpath/tools/common/ClasspathToolParser.java 5 Jun 2008 23:47:14 - @@ -38,9 +38,16 @@ package gnu.classpath.tools.common; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.Reader; import java.text.MessageFormat; +import java.util.ArrayList; import gnu.classpath.Configuration; +import gnu.classpath.tools.getopt.FileArgumentCallback; import gnu.classpath.tools.getopt.Option; import gnu.classpath.tools.getopt.OptionException; import gnu.classpath.tools.getopt.Parser; @@ -84,4 +91,149 @@ } }); } + + public void parse(String[] inArgs, FileArgumentCallback files, + boolean handleFileLists) + { +FileArgumentCallback cb; + +if (handleFileLists) + cb = new AtFileArgumentCallback(files); +else + cb = files; + +parse(inArgs, cb); + } + + public String[] parse(String[] inArgs, boolean handleFileLists) + { +final ArrayListString fileResult = new ArrayListString(); + +final FileArgumentCallback cb = new FileArgumentCallback() + { + public void notifyFile(String fileArgument) + { + fileResult.add(fileArgument); + } + }; + +if (handleFileLists) + parse(inArgs, new AtFileArgumentCallback(cb)); +else + parse(inArgs, cb); + +return fileResult.toArray(new String[fileResult.size()]); + } + + + /** + * Simple function that takes the given [EMAIL PROTECTED] Reader}, treats it like + * a textfile and reads all the whitespace separated entries from it + * and adds them to the @{link FileArgumentCallback} instance. + * + * @param reader the reader to read from. + * @param cb the callback to post the filenames to. + * @throws OptionException if an error occurs reading the list. + */ + public void parseFileList(Reader reader, FileArgumentCallback cb) + throws OptionException + { +BufferedReader breader = new BufferedReader(reader); +String line = null; + +try + { +while ((line = breader.readLine()) != null) + parseLine(line, cb); + +reader.close(); + } +catch (IOException ioe) + { +throw new OptionException(I/O error while reading a file list, ioe); + } + + } + + /** + *
Re: [cp-patches] RFC: @file support for gjavah gjar
Robert == Robert Schuster [EMAIL PROTECTED] writes: Robert The other tools are not affected by this change nor does this modify the Robert core getopt functionality (except that I made the 'programName' field Robert protected - was private). I don't think we need this to be protected. Instead I think parseFileList and notifyFile can throw an OptionException. Parser will emit the proper error message in this case. At least, I think that should work, since that was the idea behind the OptionException design -- clients can throw an exception and only the parser framework needs to know how to format an error message. If that does not work perhaps we can add a new method to Parser -- I'd rather avoid exposing a field. Some of the indentation seems wrong to me, though I always find it a bit hard to tell due to diffs making tabs look weird. Aside from those things this looks good to me. Robert + // While not reached end of line ... Robert +while (start length) E.g., this comment seems indented improperly. Robert + public void notifyFile(String fileArgument) Robert + throws OptionException In context this looks like it should be further to the right. Robert + { Robert + if (fileArgument.codePointAt(0) == '@') Robert + { Likewise this brace. Tom
Re: [cp-patches] RFC: @file support for gjavah gjar
Il giorno mer, 04/06/2008 alle 09.08 -0600, Tom Tromey ha scritto: Some of the indentation seems wrong to me, though I always find it a bit hard to tell due to diffs making tabs look weird. I don't know if I say a popular thing or not, but please, expand your tabs into spaces, it makes the whole code readable when I look at it using cat and less, sometime is quite hard to understand, especially when we have no brace code like: if (true) doWhatever(); else someThingSeriouslyScrewedIfImHere(); It becomes sometime, for example like: if (true) doWhatever(); else someThingSeriouslyScrewedIfImHere(); due to werid mix of tabs and spaces Thanks, Mario
[cp-patches] RFC: @file support for gjavah gjar
Hi, the following patch adds @file support to gjavah and gjar by enhancing ClasspathToolParser with a few methods and making both tools use those. The other tools are not affected by this change nor does this modify the core getopt functionality (except that I made the 'programName' field protected - was private). I originally wanted to use StreamTokenizer or StringTokenizer but I think those are to complex for the task. 2008-06-03 Robert Schuster [EMAIL PROTECTED] * tools/gnu/classpath/tools/jar/Main.java: (run): Call different ClasspathToolParser.parse() variant. (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/javah/GcjhMain.java: (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/javah/Main.java: (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/getopt/Parser.java: Make 'programName' protected. * tools/gnu/classpath/tools/common/ClasspathToolParser.java: (parse(String[], FileArgumentCallback,boolean): New method. (parse(String[], boolean): New method. (parseFileList): New method. (parseLine): New method. (AtFileArgumentCallback): New inner class. Regards Robert ? tools/generated Index: tools/gnu/classpath/tools/common/ClasspathToolParser.java === RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/common/ClasspathToolParser.java,v retrieving revision 1.1 diff -u -r1.1 ClasspathToolParser.java --- tools/gnu/classpath/tools/common/ClasspathToolParser.java 22 Sep 2006 01:01:26 - 1.1 +++ tools/gnu/classpath/tools/common/ClasspathToolParser.java 3 Jun 2008 16:34:45 - @@ -38,9 +38,16 @@ package gnu.classpath.tools.common; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.Reader; import java.text.MessageFormat; +import java.util.ArrayList; import gnu.classpath.Configuration; +import gnu.classpath.tools.getopt.FileArgumentCallback; import gnu.classpath.tools.getopt.Option; import gnu.classpath.tools.getopt.OptionException; import gnu.classpath.tools.getopt.Parser; @@ -84,4 +91,137 @@ } }); } + + public void parse(String[] inArgs, FileArgumentCallback files, + boolean handleFileLists) + { + FileArgumentCallback cb; + + if (handleFileLists) + cb = new AtFileArgumentCallback(files); + else + cb = files; + + parse(inArgs, cb); + } + + public String[] parse(String[] inArgs, boolean handleFileLists) + { +final ArrayList fileResult = new ArrayList(); + + final FileArgumentCallback cb = new FileArgumentCallback() + { + public void notifyFile(String fileArgument) + { + fileResult.add(fileArgument); + } +}; + + if (handleFileLists) + parse(inArgs, new AtFileArgumentCallback(cb)); + else + parse(inArgs, cb); + +return (String[]) fileResult.toArray(new String[0]); + } + + + /** Simple function that takes the given [EMAIL PROTECTED] Reader}, treats it like + * a textfile and reads all the whitespace separated entries from it + * and adds them to the @{link FileArgumentCallback} instance. + */ + public void parseFileList(Reader reader, FileArgumentCallback cb) + throws OptionException + { +BufferedReader breader = new BufferedReader(reader); +String line = null; + +try + { +while ((line = breader.readLine()) != null) + parseLine(line, cb); + +reader.close(); + } +catch (IOException ioe) + { +System.err.println(programName + : IO error while reading from inputstream); +System.exit(1); + } + + } + + /** Parses whitespace separated file entries. + * + * Note: This is not coping with whitespace in files or quoting. + */ + private void parseLine(String line, FileArgumentCallback cb) +throws IOException, OptionException + { +final int length = line.length(); +int start = 0; +int end = 0; + + // While not reached end of line ... +while (start length) + { +// Search for first non-whitespace character for the start of a word. +while (Character.isWhitespace(line.codePointAt(start))) + { +start++; + +if (start == length) + return; + } + +end = start + 1; + +// Search for first whitespace character for the end of a word. +while (end length !Character.isWhitespace(line.codePointAt(end))) + end++; + +cb.notifyFile(line.substring(start, end)); + +start = end + 1; + } + } + + /** Implementation of [EMAIL PROTECTED] FileArgumentCallback} that handles + * file arguments in [EMAIL PROTECTED] #notifyFile} starting with a code@/code + * through [EMAIL PROTECTED] ClasspathToolParser#parseFileList}. + */ + class AtFileArgumentCallback extends