#!/bin/perl 
# dtbk2html Perl script, version 2.2, 06/01/2000
# A perl script for converting Pilot datebook .tsv files into HTML

# ========================================================================

undef $/  ;
$* = 1 ;

open(FILE, "Fudge:À voir:datebook.tsv") || die("cannot open À voir:datebook.tsv");
open(STDOUT, ">Fudge:À voir:plan.html") || die("cannot open À voir:plan.html");

$_ = <FILE> ;

# ========================================================================
# Treatment of entries
# Entry format: Label\tDateBeg\tDateEnd\tHoutBeg\tHourend\tCateg1\tCateg2
# Entries are delivered orderedly in the TSV in the order
# (exeption is outdated entries which are at the end)

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
$mon = $mon + 1;
# coding the year on to digit is not clever: problem in 2036 (if I remember)
$year = $year + 1900;

sub entriestodd {
# here also, coding the year on to digit is not clever: problem in 2100.
	s/^\*([^:]*):([^\t]*)\t([^\/]*)\/([^\/]*)\/([^\t]*)\t[^\t]*\t([^\t]*)\t([^\t]*).*$/<DT>$3\/$4\/20$5 ($6-$7)<DD>$1 : $2/og;
	s/^\#[^\t]*\t([^\/]*)\/([^\/]*)\/([^\t]*)\t[^\t]*\t([^\t]*)\t([^\t]*).*$/<DT>$1\/$2\/20$3 ($4-$5)<DD>Private/og;
	s/^\%([^:]*):[^\t]*\t([^\/]*)\/([^\/]*)\/([^\t]*)\t[^\t]*\t([^\t]*)\t([^\t]*).*$/<DT>$2\/$3\/20$4 ($5-$6)<DD>$1 : Unavailable/og;
	};

sub outdatedentries {
	# delete past and too far away entries (only <DT> entries can be printed)
	while(/^<DT>([^\/]*)\/([^\/]*)\/(....).*$/g) {
		if ((($3 > $year) && ($3 <= $year + 1))
			|| (($3 == $year) && ($2 > $mon))
			|| ($3 == $year && $2 == $mon && $1 >= $mday)
			) {
			print "$&\n";
			};
		};
	};

# ========================================================================
# here is the end

print <<EOF;
<HTML>
<HEAD><TITLE>J&eacute;r&ocirc;me Euzenat plan</TITLE></HEAD>
<BODY BGCOLOR="#dddeee">
<SMALL>
<H1>J&eacute;r&ocirc;me Euzenat plan</H1>
<B>Warning 1</B>: this plan is not updated very often (but you can use
it for pruning). For short term planning, you should rather
contact <A HREF="Welcome.html">me</A>.<BR>
<B>Warning 2</B>: dates are in french format DD/MM/YYYY<BR>
</SMALL>
<!--
<H2>Regular duties</H2>
<DL>
<DT>Tuesday morning (until 11h00)
<DD>team meeting
</DL>
-->
<H2>Plan</H2>
<DL>
EOF

&entriestodd();
&outdatedentries();

print <<EOF;
</DL>
<SMALL>
Gre=Grenoble/Montbonnot, Rocq=Rocquencourt<BR>
CP=Project comitee,<BR>
Cours=lecture, R&eacute;union/rencontre=meeting<BR>
</SMALL>
<HR>
<ADDRESS>Generated from his <A HREF="http://co4.inrialpes.fr/pilot/">Pilot datebook</A> by 
<A HREF="mailto:Jerome.Euzenat\@inrialpes.fr">J&eacute;r&ocirc;me Euzenat</A> on $mday/$mon/$year</ADDRESS>
</BODY>
</HTML>

EOF

close(STDOUT);
