X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXLogPrint.pm;h=153f8f06e4941772729cba258bb968b979cede1a;hb=06cf973726ecfc228d68bc82b63feb026d897a68;hp=185912cda4948abefe7d3408da3d371651921417;hpb=c20a2c1e01d707d6c3fa25067df93d491aba8fff;p=spider.git diff --git a/perl/DXLogPrint.pm b/perl/DXLogPrint.pm index 185912cd..153f8f06 100644 --- a/perl/DXLogPrint.pm +++ b/perl/DXLogPrint.pm @@ -25,51 +25,57 @@ 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; - $search = "\$ref->[1] =~ /$pattern/i" if $pattern; - $search .= ' && ' if $pattern && $who; - $search .= "(\$ref->[2] =~ /$who/i || \$ref->[3] =~ /$who/i)" if $who; + if ($pattern) { + $hint = "m{\\Q$pattern\\E}i"; + } + if ($who) { + if ($hint) { + $hint .= ' && '; + } + $hint .= 'm{\\Q$who\\E}i'; + } + $hint = "next unless $hint" if $hint; + $eval = qq( - my \$c; - my \$ref; - 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 - } - } - ); + \@in = (); + while (<\$fh>) { + $hint; + chomp; + push \@in, \$_; + shift \@in, if \@in > $tot; + } + ); $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) { - @in = (); - while (<$fh>) { - chomp; - $ref = [ split '\^' ]; - push @{$ref}, "" unless @{$ref} >= 4; - push @in, $ref; - } 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;