Skip to content

Commit

Permalink
unexpand: -- option terminator (#499)
Browse files Browse the repository at this point in the history
* 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"
  • Loading branch information
mknos committed Mar 13, 2024
1 parent 2289976 commit 99224af
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions bin/unexpand
Expand Up @@ -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;
Expand Down

0 comments on commit 99224af

Please sign in to comment.