#!/usr/bin/perl

#
#	$B%U%!%$%k%U%)!<%^%C%H(B
#
#	1$B9TL\(B	$B%?%$%H%k(B
#	2$B9TL\!A(B	$B%5%V%?%$%H%k(B
#	$B6u9T(B+
#	$B<!$N9T(B	$BF|;~(B
#	$B<!$N9T(B	$B;aL>(B
#	$B6u9T(B+
#	$B:G=i$N%Z!<%8$NK\J8(B
#	$B6u9T(B
#	$B6u9T(B
#	2$B%Z!<%8L\$NK\J8(B
#
#
use	strict;

my	$title;
my	$subtitle;
my	$date;
my	$name;
my	$blankline = 0;
my	$n;
my	@text = grep(!/^#/,<>);

$title = shift(@text);
while ($text[0] !~ /^$/) {
	$subtitle .= shift(@text) . "\n";
}
while (@text>0 && $text[0] =~ /^$/) {
	shift(@text);
}
$date = shift(@text);
$name = shift(@text);
while (@text>0 && $text[0] =~ /^$/) {
	shift(@text);
}

&header($title,$subtitle,$date,$name);

while ($_ = shift(@text)) {
	chop;
	unless (/^$/) {
		if ($blankline==1) {
			print "\n";
		}
		print "$_\n";
		$blankline = 0;
		next;
	}
	$blankline++;
	if ($blankline == 2) {
		print 	"\n%page\n\n";
	}
}

exit 0;
		

sub	header {
	my ($title,$subtitle,$date,$name) = @_;

print <<"__EOF__"
%include "default.mgp"
%default 1 bgrad
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
%center, size 8, font "standard", fore "white", vgap 20

$title
%size 6, fore "white", xfont "times-medium-r", xfont "mincho-medium-r" "jisx0208.1983-0"
$subtitle
%size 5, fore "white", xfont "times-medium-r", xfont "mincho-medium-r" "jisx0208.1983-0"
$date
$name

%page

__EOF__
}
