#! /usr/bin/perl
#
# This Perl sciprt summarizes the number of errors and warnings in the set of 
# *.res files of qatesttool.
#
# License: LGPL
# Author:  Takamichi Akiyama <tora@openoffice.org>
# Revision:  1.1, October 24, 2006
#

format STDOUT_TOP =
Filename                      Errors    Warnings  Warnings_during_initialization
============================  ======    ========  ==============================
.

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<  @>>>>>     @>>>>>>      @>>>>>
$file,                        $error,    $warning,    $warning_init
.

$num_of_files = 0;
$errors = 0;
$warnings = 0;
$wanrnings_init = 0;

sub footer {
    print "================================================================================\n";
    printf("Total %2d files                    %2d          %2d          %2d\n",
	   $num_of_files, $errors, $warnings, $wanrnings_init);
}

sub work {
    my $file = shift;
    my ($line, $lineno);
    open FH, "$file" or die "$!: $file, stopped";
    while (<FH>) {
	if (m/\%ResId=([0-9]+)\%(?:\%Arg1=(.+?)\%)?/) {
	    $id = $1;
	    $arg1 = $2;

	    # http://qa.openoffice.org/qatesttool/resultfile.html

	    # String 20014    Text[ en-US ] = "** ($Arg1) errors occurred";
	    # String 20015    Text[ en-US ] = "** No errors have occurred";
	    # String 20016    Text[ en-US ] = "** ($Arg1) warnings occurred";
	    # String 20017    Text[ en-US ] = "** No warnings have occurred";
	    # String 20023    Text[ en-US ] = "** ($Arg1) warnings occurred during initialization";
	    # String 20024    Text[ en-US ] = "** No warnings occurred during initialization";

	    $error = $arg1 + 0 if ($id eq 20014);
	    $error = 0         if ($id eq 20015);
	    $warning = $arg1 + 0 if ($id eq 20016);
	    $warning = 0         if ($id eq 20017);
	    $warning_init = $arg1 + 0 if ($id eq 20023);
	    $warning_init = 0         if ($id eq 20024);
	}
    }
    close FH;
    write;
    $num_of_files ++;
    $errors += $error;
    $warnings += $warning;
    $wanrnings_init += $warning_init;
}

sub main {
    foreach $file (@ARGV) {
	work($file);
    }
    footer();
}

main();

__END__
