#!/usr/bin/perl

# Program to change Free Open Diary's export format
# into something importable by Movable Type

# distributed under the GPL (http://www.gnu.org/licenses/gpl.html)

# (C)2002-2003 Stewart Smith
# http://www.flamingspork.com

{
    open ODFILE,"< $ARGV[0]";
    @entries=();
    while($_ = <ODFILE>)
    {
	if(/^(.*?)\s+\- (\d\d?\/\d\d?\/\d\d\d\d)/)
	{
	    $entries[$#entries+1]=[$1,$2,''];
	    
	}
	else
	{
	    s/\x0d//g;
	    my $entry = $entries[$#entries];
	    ${@$entry}[2].=$_;
	}
    }
    close ODFILE;
}

my $i=0;
foreach my $entry (@entries)
{
    print "TITLE: ".@$entry[0]."\n\n";
    @date = split /\//,@$entry[1];
    print "DATE: $date[0]/$date[1]/$date[2] 00:00:00\n";
    print "-----\n";
    print "BODY:\n";
    print @$entry[2];
    print "--------\n";
    $i++;
}
