quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [PATCH 2/2] compat/getopt: Support options with optional par


From: Jean Delvare
Subject: [Quilt-dev] [PATCH 2/2] compat/getopt: Support options with optional parameters
Date: Fri, 11 Mar 2011 10:52:55 +0100
User-agent: KMail/1.12.4 (Linux/2.6.32.27-0.2-pae; KDE/4.3.5; i686; ; )

Add support of options with optional parameters to compat/getopt.
Both short and long options are supported. This is required to pass
the test suite, if nothing else.

Signed-off-by: Jean Delvare <address@hidden>
---
I'll commit this soon unless someone objects.

 compat/getopt.in |   20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

--- a/compat/getopt.in
+++ b/compat/getopt.in
@@ -83,6 +83,20 @@ foreach my $word (@words) {
                        my $found = grep(/$letter/, $short_opts);
                        push @options, '-'.$letter;
                        die "illegal option: $letter" if !$found;
+
+                       # handle options with optional parameters
+                       if (grep(/${letter}::/, $short_opts)) {
+                               if (scalar(@letters) == 0) {
+                                       push @options, quote_word('');
+                               } else {
+                                       # what looked like more short options
+                                       # are in fact the optional parameters
+                                       push @options, quote_word(join('', 
reverse @letters));
+                               }
+                               last;
+                       }
+
+                       # handle options with mandatory parameters
                        if (grep(/$letter:/, $short_opts)) {
                                if (scalar(@letters) == 0) {
                                        $need_param = $letter;
@@ -107,13 +121,13 @@ foreach my $word (@words) {
                        $word = $1;
                        $param = $2;
                }
-               my ($found) = grep(/^$word:?$/,@long_opts);
+               my ($found) = grep(/^$word:{0,2}$/,@long_opts);
                die "illegal option: $word" if !$found;
                die "$word: unexpected paramater $param" if $found !~ /:$/ && 
$param ne '';
 
-               $need_param = $word if $found =~ /:$/ && $param eq '';
+               $need_param = $word if $found =~ /[^:]:$/ && $param eq '';
                push @options, "--$word";
-               push @options, quote_word($param) if $param;
+               push @options, quote_word($param) if $param || $found =~ /::$/;
        }
 }
 

-- 
Jean Delvare
Suse L3



reply via email to

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