[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH 1/2] compat/getopt: Fix quoting and spacing
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH 1/2] compat/getopt: Fix quoting and spacing |
Date: |
Fri, 11 Mar 2011 10:50:52 +0100 |
User-agent: |
KMail/1.12.4 (Linux/2.6.32.27-0.2-pae; KDE/4.3.5; i686; ; ) |
Fix quoting and spacing in compat/getopt output. This way the output
matches exactly the output of getopt from util-linux, and spaces and
other special characters in filenames are properly supported.
Signed-off-by: Jean Delvare <address@hidden>
---
I'll commit this soon unless someone objects.
compat/getopt.in | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
--- a/compat/getopt.in
+++ b/compat/getopt.in
@@ -28,8 +28,8 @@ foreach my $arg (@ARGV) {
# there is no reason to parse
# the opts if there are no args.
-if (! length(@words)) {
- print ' -- ';
+if (address@hidden) {
+ print " --\n";
exit;
}
@@ -49,22 +49,29 @@ if ($opts =~ /^\s*(?:-q\s+)?-o ([a-zA-Z:
}
}
-my @barewords;
+my @barewords = ('--');
my @options;
# set the previous option name when a param is required
my $need_param;
+sub quote_word
+{
+ my $word = shift;
+ $word =~ s/'/'\\''/;
+ return "'$word'";
+}
+
foreach my $word (@words) {
# allow '-' to be an option value
if (!$need_param && $word !~ /^-./) {
- push @barewords, $word;
+ push @barewords, quote_word($word);
next;
}
if ($need_param) {
die "expecting param for $need_param" if $word =~ /^-./;
- push @options, '"'.$word.'"';
+ push @options, quote_word($word);
$need_param = undef;
next;
}
@@ -88,7 +95,7 @@ foreach my $word (@words) {
while (scalar(@letters) &&
($letters[$#letters] =~ /[0-9]/)) {
push @digits, pop @letters;
}
- push @options, join('',reverse @digits);
+ push @options, quote_word(join('',
reverse @digits));
}
}
}
@@ -106,9 +113,9 @@ foreach my $word (@words) {
$need_param = $word if $found =~ /:$/ && $param eq '';
push @options, "--$word";
- push @options, '"'."$param".'"' if $param;
+ push @options, quote_word($param) if $param;
}
}
-print "@options -- @barewords"
+print " @options @barewords\n"
--
Jean Delvare
Suse L3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Quilt-dev] [PATCH 1/2] compat/getopt: Fix quoting and spacing,
Jean Delvare <=