#!/usr/bin/perl
print "<html>\n<head>\n<title>Changelog "
      . `date`
      . "</title>\n"
      . "<style type=\"text/css\">\n"
      . "body { font-family: arial, helvetica; font-size: 10pt }"
      . "</style>"
      . "</head>\n<body>\n<h1>Usermanager Section</h1>\n";
$FILE = `cat DIFF-OUT`;
foreach $entry ( split /\n/, $FILE ) {
  $entry =~ /File ([^:]*): (.*)/;
  $action = $1;
  $filename = $2;
  if ($action eq "created") {
    if (-f "/tmp/new/$filename") {
      print "<h3>File created: $filename</h3>\n<pre>\n";
      print `cat "/tmp/new/$filename" | sed -e 's/\\&/\\&amp;/g' -e 's/</\\&lt;/g' -e 's/>/\\&gt;/'`;
      print "</pre>\n";
    }
    else {
      $DIRCONTENT = `find /tmp/new/$filename -type f | sed 's\@^/tmp/new/\@\@'`;
      foreach $dirfile (split /\n/, $DIRCONTENT) {
	print "<h3>File created: $dirfile</h3>\n<pre>\n";
	print `cat "/tmp/new/$dirfile" | sed -e 's/\\&/\\&amp;/g' -e 's/</\\&lt;/g' -e 's/>/\\&gt;/'`;
	print "</pre>\n";
      }
    }
  }
  elsif ($action eq "deleted") {
    if (-f "/tmp/new/$filename") {
      print "<h3>File deleted: $filename</h3>\n<pre>\n";
      print `cat "/tmp/old/$filename" | sed -e 's/\\&/\\&amp;/g' -e 's/</\\&lt;/g' -e 's/>/\\&gt;/'`;
      print "</pre>\n";
    }
    else {
      $DIRCONTENT = `find /tmp/old/$filename -type f | sed 's\@^/tmp/old/\@\@'`;
      foreach $dirfile (split /\n/, $DIRCONTENT) {
	print "<h3>File deleted: $dirfile</h3>\n<pre>\n";
	print `cat "/tmp/old/$dirfile" | sed -e 's/\\&/\\&amp;/g' -e 's/</\\&lt;/g' -e 's/>/\\&gt;/'`;
	print "</pre>\n";
      }
    }
  }
  elsif ($action eq "changed") {
    print "<h3>File changed: $filename</h3>\n<pre>\n";
    print `diff "/tmp/old/$filename" "/tmp/new/$filename" | sed -e 's/\\&/\\&amp;/g' -e 's/</\\&lt;/g' -e 's/>/\\&gt;/'`;
    print "</pre>\n";
  }
  else {
    die "Unkown action $action\n";
  }
}
print "</body>\n</html>\n";
