#!/usr/bin/env perl
use strict;

# update md5 checksums
# to be used after creation of new reference files

# PROCEDURE:
#
# create a testcase: t/test_xxx.t with t/test_xxx.pp
# The t/test_xxx.t script calls pp2html with --slide_prefix xxx_
# This results in t/xxx_nnnn.htm files
# These files are normally deleted after the test unless PP_DEBUG
# environment variable is set to 1.
#
# upd_md5 xxx_  will then update the t_md5_sums.txt file with
# the md5 sums from these files.
# Make sure to check the t/xxx_nnnn.htm before!!!
#
# setenv PP_DEBUG 1
# will prevent the t/xxx_nnnn.htm files from being deleted ...
#
#

use pptest;


my $testname = shift;
my $md5_file = "t_md5_sums.txt";

my %MD_SUM;

open(MD, "< $md5_file") or die "$!";
while(<MD>){
  m/(\w+) (\w+)/;
  $MD_SUM{$2} = $1;
}
close MD;

while(<$testname*.htm $testname*.html $testname*.tex>){
  my $slide = $_;
  my $ref = $slide;
  $ref =~ s/\.html?//;
  $ref =~ s/\.tex//;
  $MD_SUM{$ref} = pptest::calc_md5($slide);
}

open(MD, "> $md5_file") or die "$!";
  foreach my $k (sort keys %MD_SUM){
    print MD "$MD_SUM{$k} $k\n";
  }
close MD;
