X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXLogPrint.pm;h=ad0b1970017d639ae60f8e7c2e5aba1e10e2947a;hb=2b58ccdf81685a1167a43c38705a0d84b9d8d661;hp=58f18ffdd7604eae03239eb7fb48cbecbb793270;hpb=97fa4618141c1e20858660a6732d94ea3f431dd9;p=spider.git diff --git a/perl/DXLogPrint.pm b/perl/DXLogPrint.pm index 58f18ffd..ad0b1970 100644 --- a/perl/DXLogPrint.pm +++ b/perl/DXLogPrint.pm @@ -17,6 +17,12 @@ use Julian; 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; +$main::build += $VERSION; +$main::branch += $BRANCH; + # # print some items from the log backwards in time # @@ -25,31 +31,27 @@ use strict; sub print { my $fcb = $DXLog::log; - my $from = shift; - my $to = shift; - my @date = Julian::unixtojm(shift); + my $from = shift || 0; + my $to = shift || 20; + my $count; + my $jdate = $fcb->unixtoj(shift); my $pattern = shift; my $who = uc shift; my $search; my @in; my @out = (); my $eval; - my $count; + my $tot = $from + $to; my $hint = ""; - $search = '1' unless $pattern || $who; if ($pattern) { - $search = "\$ref->[1] =~ m{$pattern}i"; - $hint = "m{$pattern}i"; + $hint = "m{\\Q$pattern\\E}i"; } - if ($who) { - if ($search) { - $search .= ' && '; + if ($hint) { $hint .= ' && '; } - $search .= "(\$ref->[2] =~ m{$who}i || \$ref->[3] =~ m{$who}i)"; - $hint .= 'm{$who}i'; + $hint .= 'm{\\Q$who\\E}i'; } $hint = "next unless $hint" if $hint; @@ -58,31 +60,28 @@ sub print while (<\$fh>) { $hint; chomp; - \$ref = [ split '\\^' ]; - push \@\$ref, "" unless \@\$ref >= 4; - push \@in, \$ref; + push \@in, \$_; + shift \@in, if \@in > $tot; } - my \$c; - for (\$c = \$#in; \$c >= 0; \$c--) { - \$ref = \$in[\$c]; - if ($search) { - \$count++; - next if \$count < $from; - push \@out, print_item(\$ref); - last if \$count >= \$to; # stop after n - } - } - ); + ); $fcb->close; # close any open files - my $fh = $fcb->open(@date); - for ($count = 0; $count < $to; ) { + my $fh = $fcb->open($jdate); + L1: for ($count = 0; $count < $to; ) { my $ref; if ($fh) { eval $eval; # do the search on this file - last if $count >= $to; # stop after n return ("Log search error", $@) if $@; + my @tmp; + while (@in) { + last L1 if $count >= $to; + my $ref = [ split /\^/, shift @in ]; + next if defined $pattern && $ref->[1] ne $pattern; + push @tmp, print_item($ref); + $count++; + } + @out = (@tmp, @out); } $fh = $fcb->openprev(); # get the next file last if !$fh;