#!/usr/bin/perl -s
use POSIX qw(strftime mktime);
#
# Usage:
#
# plan2rem
#
# Initially written by Sacha Chua (sacha AT free.net.ph)
#
# 2004.10.13 - Dale Smith: Use DURATION instead of UNTIL. Use MSG.
# 2007.01.01 - Arthur Vanderbilt: Update regexp for .muse
$directory = $ARGV[0];
@months = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
opendir(DIR, $directory);
my @files = readdir(DIR);
closedir(DIR);
for $file (sort @files) {
$name = $file;
$name =~ s%.+/([^/]+)$%$1%;
# If this is a planner day page
if ($name =~ /^([0-9]{4})\.([0-9]+)\.([0-9]+)/) {
($year, $mon, $day) = ($1, $2, $3);
open (FILE, "$directory/$file") || die;
while () {
# rem doesn't like [, so we have to escape them
s/\[/["["]/g;
# If it is of the form hh:mm | hh:mm | activity, then it should be parsed as from | to | activity
if (/^\s*([0-9]+:[0-9]+)\s*\|\s*([0-9]+:[0-9]+)\s*\|\s*(.+)/)
{
printf ("REM %d %s %s AT %s DURATION %s - %s MSG %s\n",
int ($day), $months[int($mon) - 1], $year,
$1, $2, $1, $3);
}
elsif (/^\s*([0-9]+:[0-9]+)\s*\|\s*(.+?)(\s+\(([0-9]+:[0-9]+)\))?$/)
{
if ($4) {
printf ("REM %d %s %s AT %s DURATION %s MSG %s\n", int($day),
$months[int($mon) - 1], $year, $1, $4, $2);
} else {
printf ("REM %d %s %s AT %s MSG %s\n", int($day),
$months[int($mon) - 1], $year, $1, $2);
}
}
}
close (FILE);
}
}
system("touch", $ENV{HOME} . "/.reminders");