#!/usr/bin/perl

@content=<STDIN>;
chomp @content;

@slide=();

@actions=( "",
			    "slide top",
				"slide top right",
				"slide top left",
				"slide bottom",
				"slide bottom left",
				"slide bottom right",
				"slide left",
				"slide right");

print "<?xml version='1.0' encoding='iso-8859-1'?>\n";
print "\n<slides bgcolor=\"#222266\" fgcolor=\"#9999ff\" 
        face=\"../ttf/decker.ttf\" size=\"15\"
        bullet=\"../img/bullet.png\"
        screen_width=\"1024\" screen_height=\"768\">\n";

open(IN,"../head2xml header|") or die "no head2xml / header!!\n";
while(<IN>) {
	print $_;
}
close(IN);

@topics=();

foreach(@content) {
	if((/^\d/) or (/^ \d/)) {
		push(@topics,$_);
	}
}

print "\n<slide effect=\"slide top left, blend\">\n";
print "<header size=\"20\" fgcolor=\"#22FF22\">Inhalt</header>\n<text></text>\n";
foreach(@topics) {
	if(/^\d/) {
		print "<text></text>\n";
		$add="fgcolor=\"#ff00cc\"";
	}
	else {
		$add="";
	}
	print "<text $add>$_</text>\n";
}
print "</slide>\n\n";

$topic=0;

push(@content," 23");

foreach(@content) {
	s/\#.*//;
	s/&/&amp;/g;
	s/</&lt;/;
	s/>/&gt;/;
	
	#s/ue/ü/g;
	#s/ae/ä/g;
	#s/oe/ö/g;
	
	s/Ue/Ü/g;
	s/Ae/Ä/g;
	s/Oe/Ö/g;
	# unterpunkt
	if(/^ \d/) {
		if(@slide) {
			$action=$actions[int(rand($#actions))];
			if(length($action)>0) {
				if(int(rand(2))==1) {
					$action.=", blend";
				}
			}
			else {
				if(int(rand(2))==1) {
					$action.="blend";
				}
			}
			if(length($action)>0) {
				$action=" effect=\"$action\"";
			}
			print "<slide$action>\n";
			print STDERR "$topics[$topic] $action\n";
			print "<header size=\"20\" fgcolor=\"#22FF22\">$topics[$topic]</header>\n<text></text>\n";
			foreach(@slide) {
				if(/^  \+ /) {
					s/\+//;
					print "<text></text>\n<listitem fgcolor=\"#ff00cc\" size=\"20\">$_</listitem>\n";
				}
				elsif(/ \+ /) {
					s/\+//;
					print "<text></text>\n<listitem size=\"20\">$_</listitem>\n";
				}
				else {
					print "<text>$_</text>\n";
				}
			}
			print "</slide>\n\n";
			#$topic++;
		}
		@slide=();
		$topic++;
		$_=$topics[$topic];
		if(/^\d/) {
			$topic++;
		}
	}
	# ueberpunkt
	elsif (/^\d/) {
		
	}
	# normaler content
	else {
		push(@slide,$_);
	}
}

print "</slides>\n";