#!/usr/bin/perl -i.bak

use English;

## get input
undef $INPUT_RECORD_SEPARATOR;
$file = <>;

#print STDERR $file;

## transform it

if ($file =~ /\\documentclass(\[[^\]]*\])?{seminar}/ 
     &&  
    $file =~ /\\flushheadingstop/)
{
    $file =~ s/\\flushheadingstop//g;
    $file =~ s/(\\begin{slide}\s*)(\\slideheading{.*?}.*?)(\\end{slide})/$1 . processSlide($2) . $3/egs;
}



# print output
print $file; 



sub processSlide {
    ($slide) = @_;

#    print STDERR "Got slide: $slide\n";

    if ($slide =~ /((?:\\slideheading{[^\n]+}\s*)+)(.*)/s) {
	return "$1\n" . '\vspace*{\fill}' . "\n" . "$2\n" . '\vspace*{\fill}' . "\n";
    }

    else {
	return $slide;
    }
}
