#!/usr/bin/perl # mhc2visor.pl written by Akira Funahashi (funa@funa.org) 2001/05/02 # # Usage: mhc2visor.pl [month] # Add MHC entry to ~/.palm/install/Datebook.pdb. # - If month is not specified, add MHC entry of this month. # - If month is specified, add MHC entry of [month]. # Please hit sync button to install ~/.palm/install/Datebook.pdb. # # ex: % mhc2visor.pl 5 # - Add MHC entry of May to ~/.palm/install/Datebook.pdb. # use Palm::Datebook; my $pdb = new Palm::PDB; my $today = "/usr/local/bin/today.visor"; my $nkf2sjis = "/usr/local/bin/nkf -s "; my $nkf2euc = "/usr/local/bin/nkf -e "; my $db = "$ENV{HOME}/.palm/backup/DatebookDB.pdb"; my $installdb = "$ENV{HOME}/.palm/install/DatebookDB.pdb"; my $tmpdb = "$ENV{HOME}/.palm/DatebookDB.pdb.tmp"; my $todayargs = "--date=`date +%Y%m`"; if ($ARGV[0] > 0 && $ARGV[0] < 13) { if ($ARGV[0] < 10) { $todayargs = "--date=`date +%Y0$ARGV[0]`"; } else { $todayargs = "--date=`date +%Y$ARGV[0]`"; } } # Check if previous Datebook.pdb is not installed to Visor. if (-f $installdb) { system("mv $installdb $tmpdb"); $db = $tmpdb; } open(MHC, "$today $todayargs | $nkf2sjis |") || die "Can't open. $!.\n"; $pdb->Load("$db"); my $datebook; my $dayweek; chomp (my $year = `date +%Y`); # Read from DatebookDB.pdb foreach my $event ( @{$pdb->{records}} ) { my $evented = $event->{year}.$event->{month}.$event->{day}.$event->{description}; $datebook->{ $evented } = $event; } # Read from mhc schedules. while () { my $time, $desc, $month, $day, $start_time, $end_time; my $desckey, $desceuc, $message; my $note = ''; my $start_hour = 255; my $start_minute = 255; my $end_hour = 255; my $end_minute = 255; if (/^\s+/) { # Empty $month and $day(Use previous value). ($time, $desc) = split /;/, $_; } else { ($monthday, $dayweek, $time, $desc) = split /;/, $_; } chomp($desc); ($month, $day) = split /\//, $monthday; if ($month =~ /^0/) { $month =~ s/0//; } if ($day =~ /^0/) { $day =~ s/0//; } $time =~ s/\s+//g; if ($time =~ /^$/) { ; } elsif ($time =~ /-/) { ($start_time, $end_time) = split /-/, $time; ($start_hour, $start_minute) = split /:/, $start_time; ($end_hour, $end_minute) = split /:/, $end_time; } else { ($start_hour, $start_minute) = split /:/, $time; } # print "[$month][$day][$dayweek][$time]($desc)\n"; # print " >>($start_hour)($start_minute) to ($end_hour)($end_minute)\n"; $desckey = $year.$month.$day.$desc; next if ( defined ( $datebook->{$desckey} ) ); my $record = $pdb->append_Record; $record->{"day"} = $day; $record->{"month"} = $month; $record->{"year"} = $year; $record->{"start_hour"} = $start_hour; $record->{"start_minute"} = $start_minute; $record->{"end_hour"} = $end_hour; $record->{"end_minute"} = $end_minute; $record->{"description"} = $desc; # $record->{"note"} = "$note"; $record->{"attributes"}{"dirty"} = 1; # $record->{"category"} = 0; # $record->{'repeat'} = { 'frequency' => 1, # 'type' => 0, # 'unknown' => 0 }; $record->{'alarm'} = {}; chomp ($desceuc = `echo '$desc' | $nkf2euc`); if ($start_hour == 255 && $start_minute == 255) { $start_hour = ' '; $start_minute = ' '; } if ($end_hour == 255 && $end_minute == 255) { $end_hour = ' '; $end_minute = ' '; } $message = sprintf("%4d/%02d/%02d ", $year, $month, $day); $message .= sprintf("[%02s:%02s]-[%02s:%02s] (%s)",$start_hour, $start_minute, $end_hour, $end_minute, $desceuc); print "add $message\n"; } close(MHC); if (-f $tmpdb) { unlink($tmpdb); } print ">>\n"; $pdb->Write("$installdb");