teetime: Added --factor and --maxwait.
This commit is contained in:
parent
eeca10eda9
commit
c61c402612
|
@ -11,7 +11,7 @@ teetime - Save stdin including timing
|
|||
|
||||
... | teetime [-a] I<file> | ...
|
||||
|
||||
teetime -i I<file>
|
||||
teetime [-f <factor>] [-m <maxwait>] -i I<file>
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
@ -26,6 +26,20 @@ back with the same pauses.
|
|||
|
||||
=over 4
|
||||
|
||||
=item B<--append>
|
||||
|
||||
=item B<-a>
|
||||
|
||||
Instead of overwriting I<file>, append to I<file>.
|
||||
|
||||
|
||||
=item B<--factor> I<factor>
|
||||
|
||||
=item B<-f> I<factor>
|
||||
|
||||
Play back I<factor> times faster. 1.0 = actual speed.
|
||||
|
||||
|
||||
=item B<--input>
|
||||
|
||||
=item B<-i>
|
||||
|
@ -33,11 +47,12 @@ back with the same pauses.
|
|||
Read I<file> as input.
|
||||
|
||||
|
||||
=item B<--append>
|
||||
=item B<--maxwait> I<maxwait>
|
||||
|
||||
=item B<-a>
|
||||
=item B<-m> I<maxwait>
|
||||
|
||||
Wait at most I<maxwait> seconds.
|
||||
|
||||
Instead of overwriting I<file>, append to I<file>.
|
||||
|
||||
|
||||
=back
|
||||
|
@ -133,13 +148,28 @@ sub readstdin {
|
|||
close $fh;
|
||||
}
|
||||
|
||||
sub min(@) {
|
||||
# Returns:
|
||||
# Minimum value of array
|
||||
my $min;
|
||||
for (@_) {
|
||||
# Skip undefs
|
||||
defined $_ or next;
|
||||
defined $min or do { $min = $_; next; }; # Set $_ to the first non-undef
|
||||
$min = ($min < $_) ? $min : $_;
|
||||
}
|
||||
return $min;
|
||||
}
|
||||
|
||||
sub readfile {
|
||||
my $file = shift;
|
||||
open(my $fh, "<", $file) || die;
|
||||
while(1) {
|
||||
my $in;
|
||||
if(sysread($fh,$in,8)) {
|
||||
# time in ms, length in bytes
|
||||
my ($delta,$length) = unpack("L*",$in);
|
||||
$delta = min($delta/$opt::factor,$opt::maxwait*1000);
|
||||
select(undef,undef,undef,$delta/1000);
|
||||
sysread($fh,$in,$length);
|
||||
print $in;
|
||||
|
@ -173,10 +203,12 @@ sub help() {
|
|||
"Usage:",
|
||||
"",
|
||||
"... | teetime [-a] file | ...",
|
||||
"teetime -i file",
|
||||
"teetime [-m max] [-f factor] -i file",
|
||||
"",
|
||||
"-a append to file",
|
||||
"-f playback speed",
|
||||
"-i read from file",
|
||||
"-m max wait seconds",
|
||||
"",
|
||||
"See 'man $Global::progname' for details",
|
||||
"",);
|
||||
|
@ -193,10 +225,12 @@ sub debug {
|
|||
|
||||
$|=1;
|
||||
$Global::progname = "teetime";
|
||||
$Global::version = "20200721";
|
||||
$Global::version = "20221108";
|
||||
if(GetOptions("debug|D=s" => \$opt::D,
|
||||
"append|a" => \$opt::append,
|
||||
"factor|f=s" => \$opt::factor,
|
||||
"input|i" => \$opt::input,
|
||||
"maxwait|m=s" => \$opt::maxwait,
|
||||
"help|h" => \$opt::help,
|
||||
"version|V" => \$opt::version)) {
|
||||
if($opt::help) {
|
||||
|
@ -208,6 +242,8 @@ if(GetOptions("debug|D=s" => \$opt::D,
|
|||
exit(1);
|
||||
}
|
||||
if($opt::input) {
|
||||
$opt::maxwait ||= 1000000;
|
||||
$opt::factor ||= 1;
|
||||
readfile(@ARGV);
|
||||
} else {
|
||||
readstdin(@ARGV);
|
||||
|
|
Loading…
Reference in a new issue