summaryrefslogtreecommitdiffstats
path: root/compat
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2006-01-30 10:58:04 +0000
committerAndreas Gruenbacher <agruen@suse.de>2006-01-30 10:58:04 +0000
commit7a36d2442d18a764b3f88711c07bf29c2ef3c7d9 (patch)
tree3c7cd72043bf42c5ca3eb29f413014e5bed89358 /compat
parentca21147618240b2df107f184413c6a9aaefaf7c0 (diff)
downloadquilt-7a36d2442d18a764b3f88711c07bf29c2ef3c7d9.tar.gz
- Properly handle spaces in arguments to getopt.
Diffstat (limited to 'compat')
-rw-r--r--compat/getopt.in32
1 files changed, 24 insertions, 8 deletions
diff --git a/compat/getopt.in b/compat/getopt.in
index d66bb5c..9726249 100644
--- a/compat/getopt.in
+++ b/compat/getopt.in
@@ -8,11 +8,28 @@
use strict;
-my ($opts,$args) = split(/ -- /, join(' ',@ARGV));
+my $opts;
+my @words;
+my $found_sep = 0;
+
+foreach my $arg (@ARGV) {
+ $found_sep = 1 if $arg eq '--';
+ if ($arg eq '--') {
+ $found_sep = 1;
+ }
+ else {
+ if (!$found_sep) {
+ $opts .= ' ' . $arg;
+ }
+ else {
+ push @words, $arg;
+ }
+ }
+}
# there is no reason to parse
# the opts if there are no args.
-if (! $args) {
+if (! length(@words)) {
print ' -- ';
exit;
}
@@ -22,7 +39,7 @@ my @long_opts;
# nothing fancy to see here; this script provides minimal compatibility
# with the getopt from util-linux until a cross platform binary exists.
-if ($opts =~ /^-o ([a-zA-Z:]*)( --long .*)*/) {
+if ($opts =~ /^\s*-o ([a-zA-Z:]*)?(\s+--long .*)*/) {
$short_opts = $1;
if ($2) {
my $long_opts = $2;
@@ -32,15 +49,14 @@ if ($opts =~ /^-o ([a-zA-Z:]*)( --long .*)*/) {
}
}
-my @words=split(/\s+/,$args);
-
my @barewords;
my @options;
-# set the the previous option name when a param is required
+# set the previous option name when a param is required
my $need_param;
foreach my $word (@words) {
+
# allow '-' to be an option value
if (!$need_param && $word !~ /^-./) {
push @barewords, $word;
@@ -48,7 +64,7 @@ foreach my $word (@words) {
}
if ($need_param) {
die "expecting param for $need_param" if $word =~ /^-./;
- push @options, $word;
+ push @options, '"'.$word.'"';
$need_param = undef;
next;
}
@@ -90,7 +106,7 @@ foreach my $word (@words) {
$need_param = $word if $found =~ /:$/ && $param eq '';
push @options, "--$word";
- push @options, $param if $param;
+ push @options, '"'."$param".'"' if $param;
}
}