From 11b4a8c79d864d6e708092b99125cd7a36d531b8 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Mon, 12 Aug 2013 10:59:23 +0000 Subject: [PATCH] FileLog: - fix seekTo bug (seeks to completely wrong position) - add "plain data get" without column filtering/reformatting git-svn-id: https://svn.fhem.de/fhem/trunk@3674 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/92_FileLog.pm | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/fhem/FHEM/92_FileLog.pm b/fhem/FHEM/92_FileLog.pm index a72a1fee4..026723813 100755 --- a/fhem/FHEM/92_FileLog.pm +++ b/fhem/FHEM/92_FileLog.pm @@ -367,12 +367,12 @@ FileLog_Get($@) { my ($hash, @a) = @_; - return "Usage: get $a[0] ...\n". + return "Usage: get $a[0] [...]\n". " where column_spec is :::\n" . " see the FileLogGrep entries in he .gplot files\n" . " is without direcory, - means the current file\n" . " is a prefix, - means stdout\n" - if(int(@a) < 5); + if(int(@a) < 4); shift @a; my $inf = shift @a; my $outf = shift @a; @@ -428,6 +428,18 @@ FileLog_Get($@) my $ifh = new IO::File $inf if($inf); seekTo($inf, $ifh, $hash, $from) if($ifh); + # Return the the plain file data, $outf is ignored + if(!@a) { + return "" if(!$ifh); + my $out = ""; + while(my $l = <$ifh>) { + next if($l lt $from); + last if($l gt $to); + $out .= $l; + } + return $out; + } + ############# # Digest the input. # last1: first delta value after d/h change @@ -687,7 +699,6 @@ seekTo($$$$) my $upper = $fh->tell; my ($lower, $next, $last) = (0, $upper/2, 0); - my $div = 2; while() { # Binary search $fh->seek($next, 0); my $data = <$fh>; @@ -705,9 +716,9 @@ seekTo($$$$) # If the second line is longer then the first, # binary search will never get it: - if($next eq $last && $data ge $ts && $div < 8192) { - $last = 0; - $div *= 2; + if($next eq $last && $data ge $ts) { + $last = seekBackOneLine($fh, $next); + last; } } if($next eq $last) { @@ -717,9 +728,9 @@ seekTo($$$$) $last = $next; if(!$data || $data lt $ts) { - ($lower, $next) = ($next, int(($next+$upper)/$div)); + ($lower, $next) = ($next, int(($next+$upper)/2)); } else { - ($upper, $next) = ($next, int(($lower+$next)/$div)); + ($upper, $next) = ($next, int(($lower+$next)/2)); } } $hash->{pos}{"$fname:$ts"} = $last;