X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXLogPrint.pm;h=752e72acd64aaa5470d0d3cae4cb619041d0ed4a;hb=43d8bcf5a429cdd1bb675a4c2793ffa2965cdb84;hp=153f8f06e4941772729cba258bb968b979cede1a;hpb=2a43619b670b8f9249558f814b0183262c3ba4f6;p=spider.git diff --git a/perl/DXLogPrint.pm b/perl/DXLogPrint.pm index 153f8f06..752e72ac 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,0)); +$main::build += $VERSION; +$main::branch += $BRANCH; + # # print some items from the log backwards in time # @@ -27,7 +33,6 @@ sub print my $fcb = $DXLog::log; my $from = shift || 0; my $to = shift || 20; - my $count; my $jdate = $fcb->unixtoj(shift); my $pattern = shift; my $who = uc shift; @@ -40,47 +45,46 @@ sub print if ($pattern) { $hint = "m{\\Q$pattern\\E}i"; + } else { + $hint = "!m{ann|rcmd|talk|chat}"; } if ($who) { - if ($hint) { - $hint .= ' && '; - } + $hint .= ' && ' if $hint; $hint .= 'm{\\Q$who\\E}i'; - } + } $hint = "next unless $hint" if $hint; + $hint .= ";next unless /^\\d+\\^$pattern\\^/" if $pattern; + $hint ||= ""; - $eval = qq( - \@in = (); - while (<\$fh>) { + $eval = qq(while (<\$fh>) { $hint; chomp; - push \@in, \$_; - shift \@in, if \@in > $tot; - } - ); + push \@tmp, \$_; + } ); $fcb->close; # close any open files my $fh = $fcb->open($jdate); - L1: for ($count = 0; $count < $to; ) { + L1: for (;@in < $to;) { my $ref; if ($fh) { + my @tmp; eval $eval; # do the search on this file 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); + @in = (@tmp, @in); + if (@in > $to) { + @in = splice @in, -$to, $to; + last L1; + } } $fh = $fcb->openprev(); # get the next file last if !$fh; } + for (@in) { + my @line = split /\^/ ; + push @out, print_item(\@line); + } return @out; } @@ -97,22 +101,27 @@ sub print sub print_item { my $r = shift; - my @ref = @$r; - my $d = atime($ref[0]); + my $d = atime($r->[0]); my $s = 'undef'; - if ($ref[1] eq 'rcmd') { - if ($ref[2] eq 'in') { - $s = "$ref[4] (priv: $ref[3]) rcmd: $ref[5]"; + if ($r->[1] eq 'rcmd') { + if ($r->[2] eq 'in') { + $r->[5] ||= ""; + $s = "$r->[4] (priv: $r->[3]) rcmd: $r->[5]"; } else { - $s = "$ref[3] reply: $ref[4]"; + $r->[4] ||= ""; + $s = "$r->[3] reply: $r->[4]"; } - } elsif ($ref[1] eq 'talk') { - $s = "$ref[3] -> $ref[2] ($ref[4]) $ref[5]"; - } elsif ($ref[1] eq 'ann') { - $s = "$ref[3] -> $ref[2] $ref[4]"; + } elsif ($r->[1] eq 'talk') { + $r->[5] ||= ""; + $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]"; + } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') { + $r->[4] ||= ""; + $r->[4] =~ s/^\#\d+ //; + $s = "$r->[3] -> $r->[2] $r->[4]"; } else { - $s = "$ref[2]"; + $r->[2] ||= ""; + $s = "$r->[2]"; } return "$d $s"; }