add three wind dials
[dweather.git] / logf
diff --git a/logf b/logf
index 0fdb946b6777ad910dab7062e7437881e4a02fb8..5b33de5fb1ca6c9fe69f4d2b4e271e1324b2879b 100755 (executable)
--- a/logf
+++ b/logf
@@ -101,34 +101,28 @@ while (!$end) {
        # open the file, seek to the end, then seek backward from the end a bit and start reading
        # but ignore the first line 'cos it will be incomplete. 
        open I, $fn or die "cannot open $fn ($!)\n";
-       seek(I, 0, 2);
-       my $pos = tell(I);
+       my $pos = sysseek(I, 0, 2);
        if ($pos <= int(abs($lines * 80))) {
-               seek(I, 0, 0);
+               sysseek(I, 0, 0);
        } else {
-               seek(I, $pos + ($lines * 80), 0);     # remember lines is (-)ve
+               sysseek(I, $pos + ($lines * 80), 0);     # remember lines is (-)ve
        }
 
-       my $buf;                                                # input overflow buffer
        my $count;
        while (!$end) {
 
                if ($state) {
-                       my $l = <I>;
-                       if (defined $l) {
-                               if ($l =~ /\cJ$/) {
-                                       my $s = "$buf$l";
+                       my $l;
+                       my $r = sysread(I, $l, 4096);
+                       if (defined $r && length $l) {
+                               my @lines = split /\cM?\cJ/, $l;
+                               foreach my $s (@lines) {
                                        if (@pattern) {
                                                unless (match($s)) {
-                                                       $buf = '';
                                                        next;
                                                }
                                        }
-                                       print $s;
-                                       $buf = '';
-                                       next;
-                               } else {
-                                       $buf .= $l;
+                                       print "\n".$s;
                                }
                        }
                        $count = 0;
@@ -138,20 +132,9 @@ while (!$end) {
                        $state ^= 1;
                        print $state ? "\nRunning..." : "\nStopped...";
                }
-               seek(I, 0, 1);
+               sysseek(I, 0, 1);
                STDOUT->flush;
 
-               # runout any stored stuff if we haven't seen anything recently
-               if ($state && length $buf && ++$count > 2) {
-                       if (@pattern) {
-                               print $buf if match($buf);scalar @pattern == grep $buf =~ m{$_}i, @pattern;
-                       } else {
-                               print $buf;
-                       }
-#                      print " *** XTRA! ***";
-                       $buf = '';
-               }
-
                # move onto the next file if we roll over midnight
                my ($d) = (gmtime)[3];
                last if ($d != $dd);
@@ -159,6 +142,9 @@ while (!$end) {
        close I;
 }
 
+print "\n";
+exit(0);
+
 sub match
 {
        my $count = 0;
@@ -188,6 +174,4 @@ sub wait_for_stdin
        return 0;
 }
 
-exit(0);
-