Hi Andrew,
I am not so happy with that patch. :)

I was trying to get Classpath to build PhoneME today and that requires
our javah to support @-style arguments as well. From my work for MIDPath
I know that we also lack that functionality in gjar that is why I tried
an implementation that can be used in all getopt using classpath tools.

What I am also unhappy is that a simple BufferedReader.readLine() is
used to get the filelist entries. The filelist the phoneme build
generates looks like this: "Bla Foo Baz". So a simple parser is needed
that splits at whitespace bounds. My suggested implementation does
exactly that.

What my implementation does not handle is whitespace inside filenames
and quoting. However I am not sure whether this is supported in filelist
 anyway.

It may be possible that some tools need @file support and some not (Does
anyone know more about this?). And such a case I would change the getopt
API to explicitly request @file support in parse().

Please have a look at the attached patch. :)

Regards
Robert

Andrew John Hughes schrieb:
> This adds support in gjar for the @file argument
> as used by the OpenJDK build.
> 
> ChangeLog:
> 
> 2008-06-02  Andrew John Hughes  <[EMAIL PROTECTED]>
> 
>       * tools/gnu/classpath/tools/getopt/OptionException.java:
>       (OptionException(String,Throwable)): New constructor.
>       * tools/gnu/classpath/tools/jar/Main.java:
>       (fileLists): New queue for streams containing lists of files.
>       (HandleFile.NotifyFile(String)): Check for '@' arguments
>       and add to stream queue.
>       (parsed(String)): Add stdin to queue instead of setting flag.
>       (readNames()): Work with the queue rather than just stdin.
>       (run(String[])): Always execute readNames().
> 
> 

? sun/security
? tools/generated
Index: ChangeLog
===================================================================
RCS file: /sources/classpath/classpath/ChangeLog,v
retrieving revision 1.9623
diff -u -r1.9623 ChangeLog
--- ChangeLog	1 Jun 2008 12:01:11 -0000	1.9623
+++ ChangeLog	2 Jun 2008 22:40:10 -0000
@@ -1,3 +1,10 @@
+2008-06-03  Robert Schuster  <[EMAIL PROTECTED]>
+
+  * tools/gnu/classpath/tools/getopt/Parser.java:
+  (parse): Added twos checks for '@' character and calls to parseFileList.
+  (parseFileList): New method.
+  (parseLine): New method.
+
 2008-06-01  Mark Wielaard  <[EMAIL PROTECTED]>
 
 	* gnu/java/awt/java2d/AbstractGraphics2D.java: Removed XDialogPeer
Index: tools/gnu/classpath/tools/getopt/Parser.java
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/getopt/Parser.java,v
retrieving revision 1.10
diff -u -r1.10 Parser.java
--- tools/gnu/classpath/tools/getopt/Parser.java	20 Mar 2008 18:04:44 -0000	1.10
+++ tools/gnu/classpath/tools/getopt/Parser.java	2 Jun 2008 22:40:11 -0000
@@ -38,6 +38,10 @@
 
 package gnu.classpath.tools.getopt;
 
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
 import java.io.PrintStream;
 import java.text.BreakIterator;
 import java.text.MessageFormat;
@@ -442,7 +446,12 @@
                 || args[currentIndex].charAt(0) != '-'
                 || "-".equals(args[currentIndex])) //$NON-NLS-1$
               {
-                files.notifyFile(args[currentIndex]);
+                // Treat file names starting with @ like a file containing a file list.
+    	        if (args[currentIndex].codePointAt(0) == '@')
+    	          parseFileList(args[currentIndex].substring(1), files);
+    	        else
+                  files.notifyFile(args[currentIndex]);
+                  
                 continue;
               }
             if ("--".equals(args[currentIndex])) //$NON-NLS-1$
@@ -456,7 +465,13 @@
           }
         // Add remaining arguments to leftovers.
         for (++currentIndex; currentIndex < args.length; ++currentIndex)
-          files.notifyFile(args[currentIndex]);
+    	  {
+    	    // Treat file names starting with @ like a file containing a file list.
+    	    if (args[currentIndex].codePointAt(0) == '@')
+    	      parseFileList(args[currentIndex].substring(1), files);
+    	    else
+              files.notifyFile(args[currentIndex]);
+          }
         // See if something went wrong.
         validate();
       }
@@ -492,4 +507,71 @@
     });
     return (String[]) fileResult.toArray(new String[0]);
   }
+  
+  /** Simple function that takes the given file, treats it as a textfile
+   * and reads all the whitespace separated entries from it notifying
+   * [EMAIL PROTECTED] FileArgumentCallback} instance each time.
+  */
+  private void parseFileList(String fileName, FileArgumentCallback files)
+    throws OptionException
+  {
+    BufferedReader reader = null;
+    String line = null;
+    
+    try
+      {
+        reader = new BufferedReader(new FileReader(fileName));
+      }
+    catch (FileNotFoundException fnfe)
+      {
+        System.err.println(programName + ": file not found " + fileName);
+        System.exit(1);
+      }
+
+    try
+      {
+        while ((line = reader.readLine()) != null)
+          parseLine(line, files);
+          
+        reader.close();
+      }
+    catch (IOException ioe)
+      {
+        System.err.println(programName + ": IO error while accessing " + fileName);
+        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 files)
+    throws OptionException, IOException
+  {
+    final int length = line.length();
+    int start = 0;
+    int end = 0;
+    while (start < length)
+      {
+        while (Character.isWhitespace(line.codePointAt(start)))
+          {
+            start++;
+        
+            if (start == length)
+              return;
+          }
+    
+        end = start + 1;
+	
+        while (end < length && !Character.isWhitespace(line.codePointAt(end)))
+          end++;
+      
+        files.notifyFile(line.substring(start, end));
+    
+        start = end + 1;
+      }
+  }
+  
 }

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to