add logging of PC92A ip addresses
[spider.git] / perl / DXLogPrint.pm
index 752e72acd64aaa5470d0d3cae4cb619041d0ed4a..c2843ed579b22e580fc978bd81325b7ea144912b 100644 (file)
@@ -3,25 +3,23 @@
 #
 # Copyright (c) - 1998 Dirk Koopman G1TLH
 #
-# $Id$
+#
 #
 
 package DXLog;
 
 use IO::File;
 use DXVars;
-#use DXDebug ();
+use DXDebug qw(dbg isdbg);
 use DXUtil;
 use DXLog;
 use Julian;
+use RingBuf;
 
 use strict;
 
-use vars qw($VERSION $BRANCH);
-$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
-$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
-$main::build += $VERSION;
-$main::branch += $BRANCH;
+use vars qw($maxmonths);
+$maxmonths = 36;
 
 #
 # print some items from the log backwards in time
@@ -32,7 +30,7 @@ sub print
 {
        my $fcb = $DXLog::log;
        my $from = shift || 0;
-       my $to = shift || 20;
+       my $to = shift || 10;
        my $jdate = $fcb->unixtoj(shift);
        my $pattern = shift;
        my $who = uc shift;
@@ -46,7 +44,7 @@ sub print
        if ($pattern) {
                $hint = "m{\\Q$pattern\\E}i";
        } else {
-               $hint = "!m{ann|rcmd|talk|chat}";
+               $hint = "!m{\\^(?:ann|rcmd|talk|chat)\\^}";
        }
        if ($who) {
                $hint .= ' && ' if $hint;
@@ -59,27 +57,37 @@ sub print
        $eval = qq(while (<\$fh>) {
                                   $hint;
                                   chomp;
-                                  push \@tmp, \$_;
+                                  \$ring->write(\$_);
                           } );
        
+       if (isdbg('search')) {
+               dbg("sh/log hint: $hint");
+               dbg("sh/log eval: $eval");
+       }
+       
        $fcb->close;                                      # close any open files
 
+       my $months;
        my $fh = $fcb->open($jdate); 
- L1: for (;@in < $to;) {
+ L1: for ($months = 0; $months < $maxmonths && @in < $tot; $months++) {
                my $ref;
+               my $ring = RingBuf->new($tot);
+
                if ($fh) {
                        my @tmp;
                        eval $eval;               # do the search on this file
                        return ("Log search error", $@) if $@;
-                       @in = (@tmp, @in);
-                       if (@in > $to) {
-                               @in = splice @in, -$to, $to;
-                               last L1;
-                       } 
+                       
+                       @in = ($ring->readall, @in);
+                       last L1 if @in >= $tot;
                }
+
                $fh = $fcb->openprev();      # get the next file
                last if !$fh;
        }
+       
+       @in = splice @in, -$tot, $tot if @in > $tot;
+    
        for (@in) {
                my @line = split /\^/ ;
                push @out, print_item(\@line);
@@ -88,6 +96,7 @@ sub print
        return @out;
 }
 
+
 #
 # the standard log printing interpreting routine.
 #