change build number calculation to be more accurate
[spider.git] / perl / DXLogPrint.pm
index 3c0203575d978e3355bd95b41df023268080a98f..ad0b1970017d639ae60f8e7c2e5aba1e10e2947a 100644 (file)
@@ -10,14 +10,19 @@ package DXLog;
 
 use IO::File;
 use DXVars;
-use DXDebug ();
+#use DXDebug ();
 use DXUtil;
 use DXLog;
 use Julian;
-use Carp;
 
 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,55 +30,64 @@ use strict;
 #
 sub print
 {
-       my $self = $DXLog::log;
-       my $from = shift;
-       my $to = shift;
-       my @date = $self->unixtoj(shift);
+       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;
        my $search;
        my @in;
-       my @out;
+       my @out = ();
        my $eval;
-       my $count;
+       my $tot = $from + $to;
+       my $hint = "";
            
-       $search = '1' unless $pattern || $who;
-       $search = "\$ref->[1] =~ /$pattern/" if $pattern;
-       $search .= ' && ' if $pattern && $who;
-       $search .= "(\$ref->[2] =~ /$who/ || \$ref->[3] =~ /$who/)" 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;
+                          }
+                  );
        
-       $self->close;                                      # close any open files
+       $fcb->close;                                      # close any open files
 
-       my $fh = $self->open(@date); 
-       for ($count = 0; $count < $to; ) {
-               my @spots = ();
+       my $fh = $fcb->open($jdate); 
+       L1: for ($count = 0; $count < $to; ) {
+               my $ref;
                if ($fh) {
-                       while (<$fh>) {
-                               chomp;
-                               push @in, [ split '\^' ];
-                       }
                        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 = $self->openprev();      # get the next file
+               $fh = $fcb->openprev();      # get the next file
                last if !$fh;
        }
        
-       return @out if defined @out;
+       return @out;
 }
 
 #