projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add more code gradually
[spider.git]
/
perl
/
DXLogPrint.pm
diff --git
a/perl/DXLogPrint.pm
b/perl/DXLogPrint.pm
index 6d37cb415d16ddfba84d481aa69055e881f653d2..444e7c5f96e77af737939fa2d17033baad14c2f0 100644
(file)
--- a/
perl/DXLogPrint.pm
+++ b/
perl/DXLogPrint.pm
@@
-17,6
+17,12
@@
use Julian;
use strict;
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
#
#
# print some items from the log backwards in time
#
@@
-25,68
+31,60
@@
use strict;
sub print
{
my $fcb = $DXLog::log;
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
$jdate = $fcb->unixtoj
(shift);
my $pattern = shift;
my $who = uc shift;
my $search;
my @in;
my @out = ();
my $eval;
my $pattern = shift;
my $who = uc shift;
my $search;
my @in;
my @out = ();
my $eval;
- my $
count
;
+ my $
tot = $from + $to
;
my $hint = "";
if ($pattern) {
my $hint = "";
if ($pattern) {
- $search = "\$ref->[1] =~ m{^$pattern}i";
- $hint = "m{$pattern}i";
+ $hint = "m{\\Q$pattern\\E}i";
+ } else {
+ $hint = "!m{ann|rcmd|talk|chat}";
}
if ($who) {
}
if ($who) {
- if ($search) {
- $search .= ' && ';
- $hint .= ' && ';
- }
- $search .= "(\$ref->[2] =~ m{$who}i || \$ref->[3] =~ m{$who}i)";
- $hint .= 'm{$who}i';
- }
+ $hint .= ' && ' if $hint;
+ $hint .= 'm{\\Q$who\\E}i';
+ }
$hint = "next unless $hint" if $hint;
$hint = "next unless $hint" if $hint;
- $search = "1" unless $search;
+ $hint .= ";next unless /^\\d+\\^$pattern\\^/" if $pattern;
+ $hint ||= "";
- $eval = qq(
- \@in = ();
- while (<\$fh>) {
+ $eval = qq(while (<\$fh>) {
$hint;
chomp;
$hint;
chomp;
- \$ref = [ split '\\^' ];
- push \@\$ref, "" unless \@\$ref >= 4;
- push \@in, \$ref;
- }
- 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
- }
- }
- );
+ push \@tmp, \$_;
+ } );
$fcb->close; # close any open files
$fcb->close; # close any open files
- my $fh = $fcb->open(
@
date);
-
for ($count = 0; $count < $to;
) {
+ my $fh = $fcb->open(
$j
date);
+
L1: for (;@in < $to;
) {
my $ref;
if ($fh) {
my $ref;
if ($fh) {
+ my @tmp;
eval $eval; # do the search on this file
eval $eval; # do the search on this file
- last if $count >= $to; # stop after n
return ("Log search error", $@) if $@;
return ("Log search error", $@) if $@;
+ @in = (@tmp, @in);
+ if (@in > $to) {
+ @in = splice @in, -$to, $to;
+ last L1;
+ }
}
$fh = $fcb->openprev(); # get the next file
last if !$fh;
}
}
$fh = $fcb->openprev(); # get the next file
last if !$fh;
}
+ for (@in) {
+ my @line = split /\^/ ;
+ push @out, print_item(\@line);
+ }
return @out;
}
return @out;
}
@@
-103,22
+101,27
@@
sub print
sub print_item
{
my $r = shift;
sub print_item
{
my $r = shift;
- my @ref = @$r;
- my $d = atime($ref[0]);
+ my $d = atime($r->[0]);
my $s = 'undef';
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 {
} 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 {
} else {
- $s = "$ref[2]";
+ $r->[2] ||= "";
+ $s = "$r->[2]";
}
return "$d $s";
}
}
return "$d $s";
}