#!/usr/bin/perl -w # this code requires GNU date to be present on your system use strict; sub GetParam { my $record_txt = shift; my $sel = shift; my $prop = ""; if ($record_txt =~ /^${sel}(\;[^\:]*)*\:(.*((\n[ \t]+.*)|(\n[^:\n]*\n))*)/im) { $prop = $2; $prop =~ s/\n //g; $prop =~ s/\n//g; $prop =~ s/\=0D\=0A/\n/g; } $prop =~ s/^[ \t\n\r]*//g; $prop =~ s/[ \t\n\r]*$//g; return $prop; }; #assume a more flexible human-writable syntax -- makes it tricky to encode #arbitrary text, but can be done. sub GetLongParam { my $record_txt = shift; my $sel = shift; my $prop = ""; if ($record_txt =~ /^${sel}(\;[^\:]*)*\:((.|\n)*)/im) { $prop = $2; if ($prop =~ /\=0D\=0A/) { $prop =~ s/\n //g; $prop =~ s/\n//g; $prop =~ s/\=0D\=0A/\n/g; } else { if ($prop =~ /([\n|\r][^ \t]+\:[ \t]*[\n\r](.|\n)*)/m) { my $rep = quotemeta($1); $prop =~ s/$rep//m; } } } return $prop; }; # apologies for the cruftiness of the following code sub MakeCanonicalTime { my $txt = shift; my $format = shift; my $both = shift; my $talk_date; my $talk_time; my $talk_string = ""; my $okay = 0; if ($txt =~ /([0-9]+ *(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*[ \,]+[0-9][0-9][0-9][0-9])/i) { $talk_date = $1; if ($talk_date=~/.*\:.*:.*/) { undef $talk_date; } } elsif ($txt =~ /((jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*[ \,]+[0-9][^\n\r]*[0-9][0-9][0-9][0-9])/i) { $talk_date = $1; if ($talk_date=~/.*\:.*:.*/) { undef $talk_date; } } elsif ($txt =~ /((jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*[ \,]+[0-9][0-9]? *(st|nd|rd|th))/i) { $talk_date = $1; } elsif ($txt =~ /((jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*[ \,]+[0-9][0-9]? *)/i) { $talk_date = $1; } elsif ($txt =~ /([0-9]+\/[0-9]+(\/[0-9]+)?)/) { $talk_date = $1; } undef $talk_time; if ($txt =~ /([0-9][0-9]?\:[0-9][0-9] *((am)|(pm))?)/i) { $talk_time = $1; } elsif ($txt =~ /([0-9][0-9]? *((am)|(pm)))/i) { $talk_time = $1; } elsif ($txt =~ /time +([0-9]+)/) { $talk_time = $1; } $okay = 0; if ((defined($talk_date) && defined($talk_time))|| ((defined($talk_date) || defined($talk_time))&&(!$both))) { $okay = 1; if ($talk_date =~ /([0-9]+) +([a-z][a-z][a-z])[a-z]*/i) { my $month = $2; my $day = $1; my $year = ""; if ($txt =~ /([0-9][0-9][0-9][0-9])/) { $year = $1; } $talk_date = "$month $day $year"; } elsif ($talk_date =~ /([a-z][a-z][a-z])[a-z]* +([0-9]+)/i) { my $month = $1; my $day = $2; my $year = ""; if ($txt =~ /([0-9][0-9][0-9][0-9])/) { $year = $1; } $talk_date = "$month $day $year"; } if (!defined($talk_time)) { $talk_time = ""; } if ($talk_time =~ /([0-9][0-9]?)/) { my $hour = $1; my $minute = ""; my $half = ""; if ($talk_time =~ /\:([0-9][0-9])/) { $minute = ":$1"; } if ($talk_time =~ /((am)|(pm))/i) { $half = $1; } else { if ($hour<8) { $half = "pm"; } } $talk_time = "$hour$minute $half"; } else { if ($both) { $okay = 0; } } } if ($okay) { # next line requires GNU date to be installed $talk_string = `date -d '$talk_time $talk_date' +'$format'`; } $talk_string =~ s/^[ \t\n\r]*//g; $talk_string =~ s/[ \t\n\r]*$//g; return $talk_string; } ###################################################################### ###################################################################### my $event_txt = "\n\n"; while (<>) { $_ =~ s/[\n\r]//g; $event_txt .= "$_\n"; } $event_txt .= "\n\n"; my $title = GetParam($event_txt,"title"); my $key = GetParam($event_txt,"key"); my $site = GetParam($event_txt,"site"); my $source = GetParam($event_txt,"source"); my $notes = GetParam($event_txt,"notes"); my $out = ""; $out = $out . "title is [$title]\n"; $out = $out . "key is [$key]\n"; $out = $out . "site is [$site]\n"; $out = $out . "source is [$source]\n"; my $sequence = GetParam($event_txt,"sequence"); chomp($sequence); for my $s (split(/ /,$sequence)) { my $paperdue = GetParam($event_txt,$s); my $papercomment = ""; if ($paperdue =~ /\((.*)\)/) { $papercomment = "[comment: $1]"; } my $paperduedate = MakeCanonicalTime($paperdue,"%Y%m%d",0); my $verbosepaperduedate = MakeCanonicalTime($paperdue,"%B %d, %Y",0); $out = $out . " component $s [dated: $paperduedate ($verbosepaperduedate)]$papercomment"; $out = $out . "\n"; } $out = $out . "Notes follow --\n$notes\n"; print $out;