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);
+use vars qw($VERSION $BRANCH $maxmonths);
$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;
+$maxmonths = 36;
+
#
# print some items from the log backwards in time
#
{
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;
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;
$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);
return @out;
}
+
#
# the standard log printing interpreting routine.
#