bug-automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in option parsing


From: Eric Blake
Subject: Re: bug in option parsing
Date: Tue, 23 Nov 2004 07:20:08 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8a3) Gecko/20040817

Alexandre Duret-Lutz wrote:
"Eric" == Eric Blake <address@hidden> writes:

Thanks, I'm checking this in on HEAD.

2004-11-21  Alexandre Duret-Lutz  <address@hidden>

        * automake.in (parse_arguments): Diagnose empty arguments, options
        with missing argument, and support `--'.
        * aclocal.in (parse_arguments): Diagnose options with missing
        argument.
        * tests/aclocal.test: More checks.
        * tests/automake.test: New file.
        * tests/postprog.test: Use `--' for fun.
        * tests/Makefile.am (TESTS): Add automake.test.
        Report from Eric Blake.

@@ -666,8 +666,25 @@
if (@ARGV)
     {
-      fatal ("unrecognized option `$ARGV[0]'\n"
-            . "Try `$0 --help' for more information.");
+      my %argopts;
+      for my $k (keys %cli_options)
+       {
+         if ($k =~ /(.*)=s$/)
+           {
+             map { $argopts{(length ($_) == 1)
+                            ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
+           }
+       }
+      if (exists $argopts{$ARGV[0]})
+       {
+         fatal ("option `$ARGV[0]' requires an argument\n"
+                . "Try `$0 --help' for more information.");
+       }
+      else
+       {
+         fatal ("unrecognized option `$ARGV[0]'\n"
+                . "Try `$0 --help' for more information.");
+       }
     }

This hunk leaves some odd behavior on abbreviated options:
$ automake --warnings
automake: option `--warnings' requires an argument
automake: Try `/usr/local/bin/automake --help' for more information.
# good, I expected that

$ automake --warnings ''
# no messages, no changes in warning levels, I guess that's okay

$ automake --warnings=
automake: unrecognized option `--warnings='.
automake: Try `/usr/local/bin/automake --help' for more information.
# oops, shouldn't that have been the same as --warnings ''?

$ automake --warn ''
# no messages, so auto-abbrev kicked in

$ automake --warn
automake: unrecognized option `--warn'.
automake: Try `/usr/local/bin/automake --help' for more information.
# oops, --warn is a recognized abbreviated option, but missing an argument


Also, do you really want case-insensitive long options, and support for +option?
$ automake +vErSiOn
automake (GNU automake) 1.9a
[...]

You may want to consider enabling the Getopt::Long options gnu_getopt and no_ignore_case, or have a look at perldoc Getopt::Long for some of the other configuration options that may improve option handling in accordance with GNU standards.

One last comment on options: `automake --help' fails to document -o/--output-dir, and aclocal -I does not have a corresponding long option.

--
Someday, I might put a cute statement here.

Eric Blake             address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]