#!/usr/bin/perl

%monat = ( "Januar", 1, "Februar", 2, "Mrz", 3, "April", 4, "Mai", 5,
            "Juni", 6, "Juli", 7, "August", 8, "September", 9,
	    "Oktober", 10, "November", 11, "Dezember", 12 );

sub produce_link
{
  $author = '';
  $date = '';
  while ($zw = <IN>)
  {
      if ($zw =~ /<author>(.*)/)
      {
	  $author = $1;
          $author =~ s/\((.*?)\)//g;
	  $author =~ s/^von //;
      } 

      if ($zw =~ /<date>.*\, (.*)/)
      {
	  $date = $1;
          $date =~ /^(.*?)\. (.*?) (.*?)$/;
          $d_1 = $3;
          $d_3 = $1;
          $d_2 = $monat{$2};
	  $d_2 = "0$d_2" if ($d_2 =~ /^.$/);
          $d_3 = "0$d_3" if ($d_3 =~ /^.$/);
          $date = $d_1 . '-' . $d_2 . '-' . $d_3; 
      }

      if ($zw =~ /<abstract>/)
      {
        $zw = <IN>;
        $descrip = '';
        while ($zw !~ /<\/abstract>/)
        {
	    chop ($zw);
	    $descrip .= "$zw ";
	    $zw = <IN>;
 
        }       
      }

  }

  $head = '';
  $head = "<META NAME=\"DC.Creator\" CONTENT=\"$author\">\n" if $author;
  $head .= "<META NAME=\"DC.Date\" CONTENT=\"$date\">\n" if $date;
  $head .= "<META NAME=\"DC.Description\" CONTENT=\"$descrip\">\n" if $descrip;
  $head .= "<META NAME=\"DC.Publisher\" CONTENT=\"DLHP\">\n";
  $file =~ /(.*)\.sgml/;
  $head .= "<META NAME=\"DC.Identifier\" CONTENT=\"DLHP $1\.html\">\n";

#  print $head;
}


foreach $file (@ARGV)
{
  if ($file =~ /^(.*)\.sgml$/)
  {
    $filehtml = $1 . '.html';
    open (IN, "< $file");
    &produce_link;
    close (IN);

    open (IN, "< $filehtml");
    $ch_file = '';
    while ($zw = <IN>)
    {
      $ch_file .= $head if ($zw =~ /<\/HEAD>/);
      $ch_file .= $zw;
    }
    close (IN);

    open (IN, "> $filehtml");
    print IN $ch_file;
    close (IN);
  }
}
