]> git.lyx.org Git - lyx.git/blobdiff - development/autotests/searchPatterns.pl
Typo spotted by Pavel
[lyx.git] / development / autotests / searchPatterns.pl
index 73a3572789626f8a34d99104a5283188cfe67c7c..4202a1446c4330fed40a24e9ef772aad0366002f 100755 (executable)
 use strict;
 use warnings;
 
-sub sexit($);                  # Print synax and exit
-sub readPatterns($);           # Process patterns file
-sub processLogFile($);         # 
-sub convertPattern($);         # check for regex, comment
+sub sexit($);                # Print synax and exit
+sub readPatterns($);         # Process patterns file
+sub processLogFile($);       #
+sub convertPattern($);       # check for regex, comment
 sub convertSimplePattern($);  # escape some chars, (e.g. ']' ==> '\]')
 sub printInvalid($$);        # display lines which should not match
 
+my ($logfile, $patternsfile, $basename, $newbase) = (undef, undef, undef);
 my %options = (
-  "log" => undef,
-  "patterns" => undef,
+  "log" => \$logfile,
+  "patterns" => \$patternsfile,
+  "base" => \$basename,
     );
 
 my @patterns = ();
@@ -33,11 +35,27 @@ for my $arg (@ARGV) {
   if ($arg =~ /^([^=]+)=(.+)$/) {
     my ($what, $val) = ($1, $2);
     if (exists($options{$what})) {
-      if (defined($options{$what})) {
-       print "Value for \"$what\" already defined\n";
-       &sexit(1);
+      if (defined(${$options{$what}})) {
+       print "Param \"$what\" already handled\n";
+       sexit(1);
+      }
+      ${$options{$what}} = $val;
+      if ($what ne "base") {
+       if ($what eq "log") {
+         if ($logfile =~ /^(.+)\.log[a-z]?\.txt$/) {
+           $newbase = $1;
+         }
+       }
+       elsif ($what eq "patterns") {
+         if ($patternsfile =~ /^(.+)\.ctrl$/) {
+           $newbase = $1;
+         }
+       }
+       else {
+         print "Software error, unhandled param \"$what\"\n";
+         &sexit(1);
+       }
       }
-      $options{$what} = $val;
     }
     else {
       print "Unknown param \"$what\"\n";
@@ -50,20 +68,38 @@ for my $arg (@ARGV) {
   }
 }
 
+$basename = $newbase if (! defined($basename));
+if (defined($basename)) {
+  for my $k (keys %options) {
+    next if ($k eq "base");
+    if (! defined(${$options{$k}})) {
+      if ($k eq "log") {
+       $logfile = $basename . ".loga.txt";
+      }
+      elsif ($k eq "patterns") {
+       $patternsfile = $basename . ".ctrl";
+      }
+    }
+  }
+}
 for my $k (keys %options) {
-  if (! defined($options{$k})) {
+  next if ($k eq "base");
+  if (! defined(${$options{$k}})) {
+    print "Param \"$k\" not defined\n";
     &sexit(1);
   }
-  if (! -r $options{$k}) {
-    print "File \"$options{$k}\" is not readable\n";
+  if (! -r ${$options{$k}}) {
+    print "File \"${$options{$k}}\" is not readable\n";
     &sexit(1);
   }
 }
 
 # Read patterns
-&readPatterns($options{"patterns"});
-if (&processLogFile($options{"log"}) > 0) {
-  print "Errors occured, exiting\n";
+print "\nControlfile\t= $patternsfile\n";
+print "Log-file\t= $logfile\n\n";
+&readPatterns($patternsfile);
+if (&processLogFile($logfile) > 0) {
+  print "Errors occurred, exiting\n";
   exit(1);
 }
 
@@ -74,7 +110,9 @@ sub syntax()
   print "Syntax:\n";
   print " $0";
   for my $k (keys %options) {
-    print " $k=<filename>";
+    my $type = "filename";
+    $type = "basename" if ($k eq "base");
+    print " \[$k=<$type>\]";
   }
   print "\n";
 }
@@ -199,6 +237,7 @@ sub processLogFile($)
       }
       #print "Searching for \"$pat\"\n";
       $found = 0;
+      my $invalidmessages = 0;
       my $prevlines = () = $pat =~ /\\n/g; # Number of lines in pattern
       $prevlines = $minprevlines if ($prevlines < $minprevlines);
       my @prevl = ();
@@ -231,8 +270,6 @@ sub processLogFile($)
        my $check = join("", @prevl);
        $line++;
        if ($check =~ /$pat/) {
-         @ErrPatterns = ();    # clean search for not wanted patterns
-         $minprevlines = 0;
          my $fline = $line - $prevlines;
          print "$fline:\tfound \"$pat\"\n";
          $found = 1;
@@ -252,16 +289,15 @@ sub processLogFile($)
        else {
          push(@savedlines, $l);
          # Check for not wanted patterns
-         my $errindex = 0;
          for my $ep (@ErrPatterns) {
            if ($check =~ /$ep/) {
              $errors++;
-             my $fline = $line - $prevlines;
-             printInvalid($fline, $check);
-             #splice(@ErrPatterns, $errindex, 1);
+             if ($invalidmessages++ < 10) {
+               my $fline = $line - $prevlines;
+               &printInvalid($fline, $check);
+             }
              last;
            }
-           $errindex++;
          }
        }
       }
@@ -270,6 +306,8 @@ sub processLogFile($)
        print "\tNOT found \"$pat\" in remainder of file\n";
        $readsavedlines = 1;
       }
+      @ErrPatterns = ();       # clean search for not wanted patterns
+      $minprevlines = 0;
     }
     close(FL);
   }