From 92f1d2bf301ae3a4dab411d1fc3b8afff40b27bf Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 9 Apr 2024 15:34:12 -0400 Subject: soxdial: support GNU --option=value and options with no space before their args. --- soxdial | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/soxdial b/soxdial index 357da0b..d1e58f1 100755 --- a/soxdial +++ b/soxdial @@ -40,11 +40,11 @@ option. =head1 OPTIONS -Note that option bundling is not supported. Use e.g. B<-v -n>, not B<-vn>. Also, -spaces are required between options and their arguments. Use e.g. B<-b 16>, -not B<-b16>. - -Also, GNU style --option=value is not supported (use B<--bits 16>, not B<--bits=16>). +Note that option bundling is not supported. Use e.g. B<-v -n>, +not B<-vn>. Spaces are allowed but not required between options and +their arguments: B<-b16> and B<-b 16> are equivalent. Also, GNU-style +B<--option=value> is supported (and works the same as B<--option +value>). =head2 Global Options @@ -455,13 +455,35 @@ if(!@ARGV) { exit 1; } +# preprocess @ARGV, convert e.g. -b16 to -b 16, --foo=bar to --foo bar. +@newargv = (); +for(@ARGV) { + if(/^(--?\w+)=(\S+)$/) { + push @newargv, $1, $2; + } elsif(/^(--?[blcdts])(\d+(?:ms)?)/i) { + push @newargv, $1, $2; + } elsif(/^(--?[r])(\d+(?:k)?)/i) { + push @newargv, $1, $2; + } elsif(/^(--?[D])(\w\w)/i) { + push @newargv, $1, $2; + } elsif(/^(--?o)(\S+)/) { + if($2 eq 'utput') { + push @newargv, $_; + } else { + push @newargv, $1, $2; + } + } else { + push @newargv, $_; + } +} + +@ARGV = @newargv; + # this is a big ugly mess. should be refactored. works, though. for ($argc = 0; $argc < @ARGV; $argc++) { $_ = $ARGV[$argc]; - if(/=/) { - die "$SELF: GNU-style --option=value not supported, use --option value.\n"; - } elsif(/--?(?:V|version)$/) { + if(/--?(?:V|version)$/) { print "$SELF $VERSION\n"; exit 0; } elsif(/^--?man$/) { -- cgit v1.2.3