#!/usr/bin/perl -w
use strict;

use IO::File;
use HTML::Entities;
use YAML;

my %title;
my $scene_title_h = IO::File->new("scene_title_short");
$scene_title_h->getline();
while (defined(my $line = $scene_title_h->getline())) {
	chomp $line;
	my ($scene, $title) = split /\t/, $line;
	$title{$scene} = $title;
}
$scene_title_h->close();

#	print Dump(\%title);

print "<html><body>\n";
print <<'MSOCRAPEND';
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List href="./cal_files/filelist.xml">
<link rel=Edit-Time-Data href="./cal_files/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Marney</o:Author>
  <o:LastAuthor>Marney</o:LastAuthor>
  <o:Revision>4</o:Revision>
  <o:TotalTime>9</o:TotalTime>
  <o:Created>2004-07-11T09:52:00Z</o:Created>
  <o:LastSaved>2004-07-11T10:08:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>501</o:Words>
  <o:Characters>2858</o:Characters>
  <o:Company>Marney's Computer</o:Company>
  <o:Lines>23</o:Lines>
  <o:Paragraphs>5</o:Paragraphs>
  <o:CharactersWithSpaces>3509</o:CharactersWithSpaces>
  <o:Version>9.2720</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Print</w:View>
  <w:Zoom>BestFit</w:Zoom>
 </w:WordDocument>
</xml><![endif]-->
<style>
<!--
 /* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
p
	{margin-right:0cm;
	mso-margin-top-alt:auto;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
@page Section1
	{size:595.3pt 841.9pt;
	margin:26.95pt 19.3pt 26.95pt 27.0pt;
	mso-header-margin:35.4pt;
	mso-footer-margin:35.4pt;
	mso-columns:3 even 17.85pt;
	mso-column-separator:solid;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
</head>

<body lang=EN-AU style='tab-interval:36.0pt'>

<div class=Section1 style='font-size:9.0pt;mso-bidi-font-size:12.0pt'>
MSOCRAPEND

my $count = 0;
my $timetable_h = IO::File->new("timetable");
$timetable_h->getline();
while (defined(my $line = $timetable_h->getline())) {
	if ($count ++) { print "<hr noshade>\n"; }
	chomp $line;
	my ($date, $scenes_lunch, $scenes_330, $other) = split /\t/, $line;
	for ($scenes_lunch, $scenes_330, $other) { $_ ||= ''; }
	my @scenes_330 = split /; /, $scenes_330;
	my @other = split /; /, $other;
	my ($month, $day) = split / /, $date;
	my $yyyymmdd = sprintf("2004%02d%02d", $month, $day);
	my $dow_month = `date -d $yyyymmdd +"%a %b"`; chomp $dow_month;
	my ($dow, $month_name) = split / /, $dow_month;
	print "<b>$month_name $day $dow</b>:<br>\n";
	if ($scenes_lunch) {
		my $title = encode_entities($title{$scenes_lunch});
		print "<b>Lunch</b> - <b><i>$scenes_lunch</i></b> $title<br>\n";
	}
	if (@scenes_330) {
		print "<b>3:30</b> - ";
		my $n=0;
		for my $scene (@scenes_330) {
			my $comment = "";
			if ($scene =~ /^(.*?)(\(.*?\))$/) {
				$scene = $1; $comment = " $2";
			}
			if ($n++) { print "&nbsp;"x2; }
			my $title = encode_entities($title{$scene});
			$comment = encode_entities($comment);
			print "<b><i>$scene</i></b> $title$comment<br>\n";
		}
	}
	for (@other) {
		print "$_<br>\n";
	}
}
$timetable_h->close();
print <<'MSOCRAPEND';
</div>
</body>
</html>
MSOCRAPEND
