From 99224af06fc41b0b5f06e170e49ac5ab09c4ef99 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:37:20 +0800 Subject: [PATCH] unexpand: -- option terminator (#499) * This was identified when testing against GNU version * Rewrite option parser to align with bin/expand; global $arg variable is not needed * Example valid usage: "perl unexpand -a -2 -- -a" --> tabstop=2, aflag=1, read file "-a" --- bin/unexpand | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/bin/unexpand b/bin/unexpand index 4185f943..2d8a64aa 100755 --- a/bin/unexpand +++ b/bin/unexpand @@ -39,19 +39,21 @@ my $opt_a = 0; my @tabstops; my @files; -my $arg; -while($arg = shift @ARGV) { - if($arg eq '-a') { - $opt_a = 1; - next; +while (@ARGV && $ARGV[0] =~ /\A\-(.+)/) { + my $val = $1; + if ($val eq '-') { # '--' terminator + shift @ARGV; + last; } - if($arg =~ /^-(.*)/) { - @tabstops = split(/,/, $1); + if ($val eq 'a') { + $opt_a = 1; + } else { + @tabstops = split /,/, $val; usage() if grep /\D/, @tabstops; - next; } - push @files, $arg; + shift @ARGV; } +@files = @ARGV; # $tabstop is used only if multiple tab stops have not been defined $tabstop = $tabstops[0] if scalar @tabstops == 1;