summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2011-03-15 13:48:47 +0100
committerJean Delvare <jdelvare@suse.de>2011-03-15 13:48:47 +0100
commit059368febe2bd83a4622f35187b55f3878069123 (patch)
treecde3c58bf844cae5ef126bd663e7ec0277c49ceb
parent1c86e6c9dedc9ada9c785194b6942a7240855077 (diff)
downloadquilt-059368febe2bd83a4622f35187b55f3878069123.tar.gz
compat/getopt.in: Add support of options with optional parameters
Both short and long options are supported. This is required to pass the test suite, if nothing else.
-rw-r--r--compat/getopt.in20
-rw-r--r--quilt.changes7
2 files changed, 24 insertions, 3 deletions
diff --git a/compat/getopt.in b/compat/getopt.in
index dfba72a..878728b 100644
--- 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 =~ /::$/;
}
}
diff --git a/quilt.changes b/quilt.changes
index 984485f..edbb3c4 100644
--- a/quilt.changes
+++ b/quilt.changes
@@ -1,4 +1,11 @@
-------------------------------------------------------------------
+Tue Mar 15 13:47:41 CET 2011 - jdelvare@suse.de
+
+- compat/getopt.in: Add support of options with optional
+ parameters. Both short and long options are supported. This is
+ required to pass the test suite, if nothing else.
+
+-------------------------------------------------------------------
Tue Mar 15 13:44:51 CET 2011 - jdelvare@suse.de
- compat/getopt.in: Fix quoting and spacing. This way the output