In my e-mail to fop-users (see
<http://www.mail-archive.com/fop-users%40xmlgraphics.apache.org/msg11324.html>)
I complained about a couple of minor issues:

1.  Running 'fop' with no arguments throws an exception after printing
a usage statement.

2.  Running 'fop -v' throws an exception after printing the version.

3.  Another  issue, not complained about in the cited message, is that
the current usage and help messages refer to 'Fop' while the user
executes 'fop'.

The attached patch was generated by running 'svn diff' at the top of
the working directory of a checked-out fop trunk at revision 698670.

It affects the following files:

  src/java/org/apache/fop/cli/CommandLineOptions.java
  src/java/org/apache/fop/cli/Main.java

It corrects all three issues listed above.

Thanks for your attention.

Regards.

-Tom
Index: src/java/org/apache/fop/cli/CommandLineOptions.java
===================================================================
--- src/java/org/apache/fop/cli/CommandLineOptions.java	(revision 699531)
+++ src/java/org/apache/fop/cli/CommandLineOptions.java	(working copy)
@@ -234,6 +234,11 @@ public class CommandLineOptions {
      * @exception FOPException if there was an error in the format of the options
      */
     private boolean parseOptions(String[] args) throws FOPException {
+	// do not throw an exception for no args
+	if (args.length == 0) {
+	    printUsage();
+	    System.exit(1);
+	}
         for (int i = 0; i < args.length; i++) {
             if (args[i].equals("-x")
                        || args[i].equals("--dump-config")) {
@@ -305,6 +310,7 @@ public class CommandLineOptions {
                 i = i + parseAreaTreeOption(args, i);
             } else if (args[i].equals("-v")) {
                 System.out.println("FOP Version " + Version.getVersion());
+		System.exit(1);
             } else if (args[i].equals("-param")) {
                   if (i + 2 < args.length) {
                       String name = args[++i];
@@ -331,6 +337,7 @@ public class CommandLineOptions {
                 i = i + parseUnknownOption(args, i);
             } else {
                 printUsage();
+		System.exit(1);
                 return false;
             }
         }
@@ -1033,8 +1040,9 @@ public class CommandLineOptions {
      * shows the commandline syntax including a summary of all available options and some examples
      */
     public static void printUsage() {
+	// Remember that the user executes 'fop', not Fop.
         System.err.println(
-              "\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] "
+              "\nUSAGE\nfop [options] [-fo|-xml] infile [-xsl file] "
                     + "[-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] <outfile>\n"
             + " [OPTIONS]  \n"
             + "  -d                debug mode   \n"
@@ -1095,28 +1103,29 @@ public class CommandLineOptions {
             + "                    XSL-FO file is saved and no rendering is performed. \n"
             + "                    (Only available if you use -xml and -xsl parameters)\n\n"
             + "\n"
-            + " [Examples]\n" + "  Fop foo.fo foo.pdf \n"
-            + "  Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
-            + "  Fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf\n"
-            + "  Fop -xml foo.xml -xsl foo.xsl -foout foo.fo\n"
-            + "  Fop -xml - -xsl foo.xsl -pdf -\n"
-            + "  Fop foo.fo -mif foo.mif\n"
-            + "  Fop foo.fo -rtf foo.rtf\n"
-            + "  Fop foo.fo -print\n"
-            + "  Fop foo.fo -awt\n");
+            + " [Examples]\n" + "  fop foo.fo foo.pdf \n"
+            + "  fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
+            + "  fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf\n"
+            + "  fop -xml foo.xml -xsl foo.xsl -foout foo.fo\n"
+            + "  fop -xml - -xsl foo.xsl -pdf -\n"
+            + "  fop foo.fo -mif foo.mif\n"
+            + "  fop foo.fo -rtf foo.rtf\n"
+            + "  fop foo.fo -print\n"
+            + "  fop foo.fo -awt\n");
     }
 
     /**
      * shows the options for print output
      */
     private void printUsagePrintOutput() {
+	// Remember that the user sees /fop', not Fop.
         System.err.println("USAGE: -print [from[-to][,even|odd]] [-copies numCopies]\n\n"
            + "Example:\n"
-           + "all pages:                        Fop infile.fo -print\n"
-           + "all pages with two copies:        Fop infile.fo -print -copies 2\n"
-           + "all pages starting with page 7:   Fop infile.fo -print 7\n"
-           + "pages 2 to 3:                     Fop infile.fo -print 2-3\n"
-           + "only even page between 10 and 20: Fop infile.fo -print 10-20,even\n");
+           + "all pages:                        fop infile.fo -print\n"
+           + "all pages with two copies:        fop infile.fo -print -copies 2\n"
+           + "all pages starting with page 7:   fop infile.fo -print 7\n"
+           + "pages 2 to 3:                     fop infile.fo -print 2-3\n"
+           + "only even page between 10 and 20: fop infile.fo -print 10-20,even\n");
     }
 
     /**
Index: src/java/org/apache/fop/cli/Main.java
===================================================================
--- src/java/org/apache/fop/cli/Main.java	(revision 699531)
+++ src/java/org/apache/fop/cli/Main.java	(working copy)
@@ -142,6 +142,15 @@ public class Main {
      * Executes FOP with the given ClassLoader setup.
      * @param args command-line arguments
      */
+
+    // When Fop is started without arguments, it should return its version
+    // number as well as a short usage statement.
+
+    // When Fop is started with a '-v' argument, it should return its version
+    // number alone.
+
+    // When Fop is started with an '-h' argument, it should return its short
+    // help message.
     public static void startFOP(String[] args) {
         //System.out.println("static CCL: "
         //    + Thread.currentThread().getContextClassLoader().toString());
@@ -184,6 +193,7 @@ public class Main {
             }
         } catch (Exception e) {
             if (options != null) {
+		System.out.println("debug: ");
                 options.getLogger().error("Exception", e);
                 if (options.getOutputFile() != null) {
                     options.getOutputFile().delete();

Reply via email to