only ignore interrupt signal after input
[barcat.git] / barcat
diff --git a/barcat b/barcat
index 1818493a8af4603898a2e4b7f1265c6bcfda948d..2f73fa5ab2c59e3e8be6ce6b0b57fd235641587a 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -83,13 +83,14 @@ $opt{'value-length'} = 1 if $opt{unmodified};
 
 my (@lines, @values, @order);
 
+$SIG{ALRM} = sub {
+       show_lines();
+       alarm $opt{interval} if defined $opt{interval} and $opt{interval} > 0;
+};
+
 if (defined $opt{interval}) {
        $opt{interval} ||= 1;
-       $SIG{ALRM} = sub {
-               show_lines();
-               alarm $opt{interval};
-       };
-       alarm $opt{interval};
+       alarm $opt{interval} if $opt{interval} > 0;
 
        eval {
                require Tie::Array::Sorted;
@@ -99,6 +100,7 @@ if (defined $opt{interval}) {
 
 $SIG{INT} = sub {
        $SIG{INT} = 'DEFAULT';  # reset for subsequent attempts
+       exit if !$.;
        'IGNORE' # continue after assumed eof
 };
 
@@ -119,6 +121,8 @@ while (readline) {
                }
        }
        push @lines, $_;
+       show_lines() if defined $opt{interval} and $opt{interval} < 0
+               and $. % $opt{interval} == 0;
 }
 
 $SIG{INT} = 'DEFAULT';
@@ -283,9 +287,10 @@ turning long numbers like I<12356789> into I<12.4M>.
 Also changes an exponent I<1.602176634e-19> to I<160.2z>.
 Short integers are aligned but kept without decimal point.
 
-=item -t, --interval[=<seconds>]
+=item -t, --interval[=(<seconds>|-<lines>)]
 
-Interval time to output partial progress.
+Output partial progress every given number of seconds or input lines.
+An update can also be forced by sending a I<SIGALRM> alarm signal.
 
 =item -l, --length=[-]<size>[%]