Fixed bug #34958: --pipe with --record size measured in lines.

This commit is contained in:
Ole Tange 2012-06-14 23:13:11 +02:00
parent 7a76e79185
commit 05e66ecaa5
5 changed files with 92 additions and 2159 deletions

View file

@ -295,8 +295,20 @@ sub spreadstdin {
# Force the while-loop once if everything was read by header reading
my $force_one_time_through = 0;
for my $in (@fhlist) {
while(!$force_one_time_through++ or read($in,substr($buf,length $buf,0),$::opt_blocksize)) {
piperead: while(1) {
if(!$force_one_time_through) {
$force_one_time_through++;
} elsif($Global::max_lines) {
# Read $Global::max_lines lines
eof($in) and last piperead;
for(my $t = 0; !eof($in) and
substr($buf,length $buf,0) = <$in> and $t < $Global::max_lines;
$t++) {}
} else {
# Read a block
read($in,substr($buf,length $buf,0),$::opt_blocksize) or last;
# substr above = append to $buf
}
if($::opt_r) {
# Remove empty lines
$buf=~s/^\s*\n//gm;
@ -336,7 +348,7 @@ sub spreadstdin {
}
}
}
}
}
# If there is anything left in the buffer write it
substr($buf,0,0) = "";

View file

@ -636,24 +636,28 @@ to see the difference:
=item B<-L> I<max-lines>
Use at most I<max-lines> nonblank input lines per command line.
Trailing blanks cause an input line to be logically continued on the
next input line.
When used with B<--pipe>: Read records of I<max-lines>.
When used otherwise: Use at most I<max-lines> nonblank input lines per
command line. Trailing blanks cause an input line to be logically
continued on the next input line.
B<-L 0> means read one line, but insert 0 arguments on the command
line.
Implies B<-X> unless B<-m> or B<--xargs> is set.
Implies B<-X> unless B<-m>, B<--xargs>, or B<--pipe> is set.
=item B<--max-lines>[=I<max-lines>]
=item B<-l>[I<max-lines>]
Synonym for the B<-L> option. Unlike B<-L>, the I<max-lines> argument
is optional. If I<max-lines> is not specified, it defaults to one.
The B<-l> option is deprecated since the POSIX standard specifies
B<-L> instead.
When used with B<--pipe>: Read records of I<max-lines>.
When used otherwise: Synonym for the B<-L> option. Unlike B<-L>, the
I<max-lines> argument is optional. If I<max-lines> is not specified,
it defaults to one. The B<-l> option is deprecated since the POSIX
standard specifies B<-L> instead.
B<-l 0> is an alias for B<-l 1>.

File diff suppressed because it is too large Load diff

View file

@ -41,4 +41,10 @@ echo "bug #36657: --load does not work with custom ssh"
export -f ssh;
parallel --load=1000% -S "/usr/bin/ssh localhost" echo ::: OK
echo "bug #34958: --pipe with record size measured in lines"
seq 10 | parallel --pipe -L 4 cat\;echo FOO
echo "bug #34958: --pipe with record size measured in lines"
seq 10 | parallel --pipe -l 4 cat\;echo FOO
EOF

View file

@ -88,3 +88,18 @@ OK
OK
bug #36657: --load does not work with custom ssh
OK
bug #34958: --pipe with --record size measured in lines
1
2
3
4
FOO
5
6
7
8
FOO
9
10
FOO
FOO