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 <[email protected]> --- 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 (!@words) { + 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 _______________________________________________ Quilt-dev mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/quilt-dev
