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 -0000 1.1
+++ tools/gnu/classpath/tools/common/ClasspathToolParser.java 5 Jun 2008 23:47:14 -0000
@@ -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 ArrayList<String> fileResult = new ArrayList<String>();
+
+ 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);
+ }
+
+ }
+
+ /**
+ * Parses whitespace separated file entries.
+ *
+ * Note: This is not coping with whitespace in files or quoting.
+ *
+ * @param line the line of the file to parse.
+ * @param cb the callback to pass the parsed file to.
+ * @throws IOException if an I/O error occurs.
+ * @throws OptionException if an error occurs in the callback.
+ */
+ 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 FileArgumentCallback
+ {
+ FileArgumentCallback cb;
+
+ AtFileArgumentCallback(FileArgumentCallback cb)
+ {
+ this.cb = cb;
+ }
+
+ @Override
+ public void notifyFile(String fileArgument)
+ throws OptionException
+ {
+ if (fileArgument.codePointAt(0) == '@')
+ {
+ FileReader fr = null;
+
+ try
+ {
+ fr = new FileReader(fileArgument.substring(1));
+ }
+ catch (FileNotFoundException fnfe)
+ {
+ throw new OptionException("File not found: " + fileArgument.substring(1),
+ fnfe);
+ }
+
+ ClasspathToolParser.this.parseFileList(fr, cb);
+ }
+ else
+ cb.notifyFile(fileArgument);
+ }
+
+ }
+
}
Index: tools/gnu/classpath/tools/getopt/OptionException.java
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/getopt/OptionException.java,v
retrieving revision 1.3
diff -u -u -r1.3 OptionException.java
--- tools/gnu/classpath/tools/getopt/OptionException.java 3 Jun 2008 14:02:13 -0000 1.3
+++ tools/gnu/classpath/tools/getopt/OptionException.java 5 Jun 2008 23:47:14 -0000
@@ -49,4 +49,10 @@
{
super(message);
}
+
+ public OptionException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
}
Index: tools/gnu/classpath/tools/jar/Main.java
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/jar/Main.java,v
retrieving revision 1.11
diff -u -u -r1.11 Main.java
--- tools/gnu/classpath/tools/jar/Main.java 3 Jun 2008 14:02:13 -0000 1.11
+++ tools/gnu/classpath/tools/jar/Main.java 5 Jun 2008 23:47:15 -0000
@@ -172,9 +172,9 @@
}
}
- private Parser initializeParser()
+ private ClasspathToolParser initializeParser()
{
- Parser p = new JarParser("jar"); //$NON-NLS-1$
+ ClasspathToolParser p = new JarParser("jar"); //$NON-NLS-1$
p.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
OptionGroup grp = new OptionGroup(Messages.getString("Main.OpMode")); //$NON-NLS-1$
@@ -265,11 +265,11 @@
private void run(String[] args)
throws InstantiationException, IllegalAccessException, IOException
{
- Parser p = initializeParser();
+ ClasspathToolParser p = initializeParser();
// Special hack to emulate old tar-style commands.
if (args.length > 0 && args[0].charAt(0) != '-')
args[0] = '-' + args[0];
- p.parse(args, new HandleFile());
+ p.parse(args, new HandleFile(), true);
if (readNamesFromStdin)
readNames();
Action t = (Action) operationMode.newInstance();
Index: tools/gnu/classpath/tools/javah/GcjhMain.java
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/javah/GcjhMain.java,v
retrieving revision 1.1
diff -u -u -r1.1 GcjhMain.java
--- tools/gnu/classpath/tools/javah/GcjhMain.java 6 Mar 2007 18:52:34 -0000 1.1
+++ tools/gnu/classpath/tools/javah/GcjhMain.java 5 Jun 2008 23:47:15 -0000
@@ -38,10 +38,11 @@
package gnu.classpath.tools.javah;
+import gnu.classpath.tools.common.ClasspathToolParser;
+
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
-import gnu.classpath.tools.getopt.Parser;
import java.io.IOException;
import java.util.ArrayList;
@@ -60,9 +61,9 @@
return "gcjh";
}
- protected Parser getParser()
+ protected ClasspathToolParser getParser()
{
- Parser result = super.getParser();
+ ClasspathToolParser result = super.getParser();
result.setHeader("usage: gcjh [OPTION]... CLASS...");
Index: tools/gnu/classpath/tools/javah/Main.java
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/javah/Main.java,v
retrieving revision 1.10
diff -u -u -r1.10 Main.java
--- tools/gnu/classpath/tools/javah/Main.java 31 Jul 2007 16:15:53 -0000 1.10
+++ tools/gnu/classpath/tools/javah/Main.java 5 Jun 2008 23:47:15 -0000
@@ -188,7 +188,7 @@
return "javah";
}
- protected Parser getParser()
+ protected ClasspathToolParser getParser()
{
ClasspathToolParser result = new ClasspathToolParser(getName(), true);
result.setHeader("usage: javah [OPTIONS] CLASS...");
@@ -339,8 +339,8 @@
protected void run(String[] args) throws IOException
{
- Parser p = getParser();
- String[] classNames = p.parse(args);
+ ClasspathToolParser p = getParser();
+ String[] classNames = p.parse(args, true);
postParse(classNames);
loader = classpath.getLoader();