1. protect against PC41s with field[3] == field[2]
[spider.git] / perl / DXLogPrint.pm
index 8a12b05c2791aa3f137fc13ce4f821f1dde5e528..c2434aba48f8f5eda22edc3c2c909e7371ffc095 100644 (file)
@@ -8,13 +8,12 @@
 
 package DXLog;
 
-use FileHandle;
+use IO::File;
 use DXVars;
-use DXDebug ();
+#use DXDebug ();
 use DXUtil;
 use DXLog;
 use Julian;
-use Carp;
 
 use strict;
 
@@ -25,54 +24,69 @@ use strict;
 #
 sub print
 {
-       my $self = $DXLog::log;
+       my $fcb = $DXLog::log;
        my $from = shift;
        my $to = shift;
-       my @date = $self->unixtoj(shift);
+       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 $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) {
+               $search = "\$ref->[1] =~ m{^$pattern}i";
+               $hint = "m{$pattern}i";
+       }
+       if ($who) {
+               if ($search) {
+                       $search .= ' && ';
+                       $hint .= ' && ';
+               }
+               $search .= "(\$ref->[2] =~ m{$who}i || \$ref->[3] =~ m{$who}i)";
+               $hint .= 'm{$who}i';
+       }
+       $hint = "next unless $hint" if $hint;
+       $search = "1" unless $search;
+       
        $eval = qq(
+                          \@in = ();
+                          while (<\$fh>) {
+                                  $hint;
+                                  chomp;
+                                  \$ref = [ split '\\^' ];
+                                  push \@\$ref, "" unless \@\$ref >= 4;
+                                  push \@in, \$ref;
+                          }
                           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 LOOP if \$count >= \$to;                  # stop after n
+                                               unshift \@out, print_item(\$ref);
+                                               last if \$count >= \$to;                  # stop after n
                                        }
                                }
                          );
        
-       $self->close;                                      # close any open files
+       $fcb->close;                                      # close any open files
 
-       my $fh = $self->open(@date); 
-LOOP:
-       while ($count < $to) {
-               my @spots = ();
+       my $fh = $fcb->open($jdate); 
+       for ($count = 0; $count < $to; ) {
+               my $ref;
                if ($fh) {
-                       while (<$fh>) {
-                               chomp;
-                               push @in, [ split '\^' ];
-                       }
                        eval $eval;               # do the search on this file
-                       return ("Spot search error", $@) if $@;
+                       last if $count >= $to;                  # stop after n
+                       return ("Log search error", $@) if $@;
                }
-               $fh = $self->openprev();      # get the next file
+               $fh = $fcb->openprev();      # get the next file
                last if !$fh;
        }
-
+       
        return @out;
 }