#!/usr/bin/perl
system(cls);
print "***** WNT_Parse.pl, copyright 1998, Microsoft Corp. *****\n";
print "\n\tWritten by : Greg Neumiller (a-gneumi\@microsoft.com)\n";

$True = 1;
$False = 0;

$version = `ver`;

if($version=~/Windows NT Version 4/i){
    $VerNumber = 5;
    print "Inside Version NT4 IF statement\n";
}
elsif($version=~/Windows NT Version 5/i){
    $VerNumber =5 ;
    print "Inside Version NT5 IF statement\n";
}
else{
#     $VerNumber = 4;
    $version=~s/(\t|\n|\n\n)//g;
    print "\n***** There is an emergency going on. *****\n\tThis is $version!\n\tI need to be run on NT4 or Win2K to do my thing.\n\n";
    exit 0;
}

#print "The VerNumber is : ", $VerNumber, "\n";

$InFile   = "C:/TROLL5/WNT" . $VerNumber . "PART.LOG";
$OutFile  = "C:/WNT" . $VerNumber . "PART.LO_";
$CopyFile = "C:/WNT" . $VerNumber . "PART.LOG";

open IN, "<$InFile", or die "Cannot open $InFile for Reading :$!";
open OUT, ">$OutFile", or die "Cannot open $OutFile for Writing :$!";
open COPY, ">$CopyFile", or die "Cannot open $CopyFile for Writing :$!";

LINE: while (<IN>) {
    print COPY;

      $SystemLine = "\n\n\t $version \n";

      if($_ =~/NTLOG REPORT/i){
          print OUT $SystemLine;
          print OUT $_;
          $NTLogSection = $True;        
          next LINE;
      }
                   

      if($_ =~/Tests Aborted/i){
          print OUT $_;
          print OUT "\n--------------- Failure Summary ---------------\n";
          $NTLogSection = $False;        
          next LINE;
      }
  
      if($NTLogSection){print OUT $_; next LINE;}
      if($_=~/VAR\[SEV1]/i){push(@Failures1, $_); next LINE;}
      if($_=~/VAR\[SEV2]/i){push(@Failures2, $_); next LINE;}
      if($_=~/VAR\[SEV3]/i){push(@Failures3, $_); next LINE;}
}

foreach(@Failures1){print OUT;}
foreach(@Failures2){print OUT;}
foreach(@Failures3){print OUT;}

print OUT "\n\n";

print "\n\n\tParsing Completed\n";

if ($VerNumber == 5){
    $InFile2 = "C:/WNT4PART\.LO_";
    $InFile1 = "C:/WNT5PART\.LO_";
    $OutFile2 = "C:/MERGE_WNT5PART.LOG";

    open IN2, "<$InFile2", or die "Cannot open $InFile for Reading :$!";
    open IN1, "<$InFile1", or die "Cannot open $InFile for Reading :$!";
    open OUT2, ">$OutFile2", or die "Cannot open $OutFile for Writing :$!";

    while(<IN1>){print OUT2;}
    while(<IN2>){print OUT2;}
}
close Out2;
print "\n\n\tThe following files have been written to C:\\ \n";
print "\n\t $CopyFile \n\t $OutFile \n\t $OutFile2 \n";
