diff options
author | B. Watson <urchlay@slackware.uk> | 2024-04-13 16:09:46 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-04-13 16:09:46 -0400 |
commit | 59ea1d3988599b49cff516ae0516fb2c6456ec21 (patch) | |
tree | bac2b57b29d30a5e987af01985e9e928415ba00a | |
parent | 50c4513911aa12cb21d4c49a5f9f2050595ee8f2 (diff) | |
download | soxdial-59ea1d3988599b49cff516ae0516fb2c6456ec21.tar.gz |
soxdial: add --input and --stdin options.
-rwxr-xr-x | soxdial | 40 |
1 files changed, 39 insertions, 1 deletions
@@ -211,6 +211,16 @@ Switch to bluebox dialling mode. See B<BLUEBOX MODE> below for details. Switch to normal touchtone dialling mode. This is the default; this option exists to turn off a prior B<-B>, B<--bluebox>. +=item B<-i>, B<--input> I<file> + +Read dial strings from I<file>. Use B<-> to read from standard input. +This option can be used more than once, and can be mixed with dial +string arguments. + +=item B<--stdin> + +Read dial strings from standard input. Same as B<--input ->. + =back =head2 Dial Strings @@ -577,6 +587,18 @@ sub check_stereo { die "$SELF: can't enable stereo after a dial string.\n" if @sox_subcmds; } +sub read_file { + my $file = shift; + my $result = shift; + + open my $fh, "<$file" or die "$SELF: $file: $!\n"; + while(<$fh>) { + chomp; + push @$result, split ""; + } + close $fh; +} + # main() $SOX = $ENV{SOX} || "sox"; @@ -607,7 +629,18 @@ if(!@ARGV) { # preprocess @ARGV, convert e.g. -b16 to -b 16, --foo=bar to --foo bar. @newargv = (); for(@ARGV) { - if(/^(--?\w+)=(.+)$/) { + if($input_seen) { + read_file($_, \@newargv); + $input_seen = 0; + } elsif(/^--?stdin$/) { + read_file("-", \@newargv); + } elsif(/^--?i(?:nput)?=?(.+)?$/) { + if($1) { + read_file($1, \@newargv); + } else { + $input_seen = 1; + } + } elsif(/^(--?\w+)=(.+)$/) { push @newargv, $1, $2; } elsif(/^(--?[blcdts])([\d.]+(?:ms)?)$/i) { push @newargv, $1, $2; @@ -622,10 +655,15 @@ for(@ARGV) { push @newargv, $1, $2; } } else { + warn "got here: $_\n"; push @newargv, $_; } } +if($input_seen) { + die "$SELF: missing file argument for -i/--input.\n"; +} + @ARGV = @newargv; # this is a big ugly mess. should be refactored. works, though. |