mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
Fixing bug, when the logfile consists of one line only. Reported by Schuggi
git-svn-id: https://svn.fhem.de/fhem/trunk@3241 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
782494fbb4
commit
c31bf880ac
@ -619,6 +619,25 @@ RESCAN:
|
||||
return ($outf eq "-") ? $ret : join(" ", @fname);
|
||||
}
|
||||
|
||||
###############
|
||||
# this is not elegant
|
||||
sub
|
||||
seekBackOneLine($$)
|
||||
{
|
||||
my ($fh, $pos) = @_;
|
||||
my $buf;
|
||||
$pos -= 2; # skip current CR/NL
|
||||
$fh->seek($pos, 0);
|
||||
while($pos > 0 && $fh->read($buf, 1)) {
|
||||
if($buf eq "\n" || $buf eq "\r") {
|
||||
$fh->seek(++$pos, 0);
|
||||
return $pos;
|
||||
}
|
||||
$fh->seek(--$pos, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
seekTo($$$$)
|
||||
@ -647,7 +666,7 @@ seekTo($$$$)
|
||||
$next = $fh->tell;
|
||||
$data = <$fh>;
|
||||
if(!$data) {
|
||||
$last = $next;
|
||||
$last = seekBackOneLine($fh, $next);
|
||||
last;
|
||||
}
|
||||
|
||||
|
@ -256,11 +256,13 @@ wl_getRegFromFile($)
|
||||
$fh->seek(0, 2); # Go to the end
|
||||
my $sz = $fh->tell;
|
||||
$fh->seek($sz > 65536 ? $sz-65536 : 0, 0);
|
||||
my $data = <$fh>;
|
||||
my $data;
|
||||
$data = <$fh> if($sz > 65536); # discard the first/partial line
|
||||
my $maxcols = 0;
|
||||
my %h;
|
||||
while($data = <$fh>) {
|
||||
my @cols = split(" ", $data);
|
||||
next if(@cols < 3);
|
||||
$maxcols = @cols if(@cols > $maxcols);
|
||||
$cols[2] = "*" if($cols[2] =~ m/^[-\.\d]+$/);
|
||||
$h{"$cols[1].$cols[2]"} = $data;
|
||||
|
Loading…
Reference in New Issue
Block a user