diff --git a/teetime/teetime b/teetime/teetime index 297566c..432891e 100755 --- a/teetime/teetime +++ b/teetime/teetime @@ -11,7 +11,7 @@ teetime - Save stdin including timing ... | teetime [-a] I | ... -teetime -i I +teetime [-f ] [-m ] -i I =head1 DESCRIPTION @@ -26,6 +26,20 @@ back with the same pauses. =over 4 +=item B<--append> + +=item B<-a> + +Instead of overwriting I, append to I. + + +=item B<--factor> I + +=item B<-f> I + +Play back I times faster. 1.0 = actual speed. + + =item B<--input> =item B<-i> @@ -33,11 +47,12 @@ back with the same pauses. Read I as input. -=item B<--append> +=item B<--maxwait> I -=item B<-a> +=item B<-m> I + +Wait at most I seconds. -Instead of overwriting I, append to I. =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);