From: ianmdlvl Date: Sun, 29 Jun 2003 16:42:01 +0000 (+0000) Subject: @@ -1,6 +1,7 @@ X-Git-Tag: debian_version_3_99_1~2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=commitdiff_plain;h=5423f5e4e9e14f0b8ed6fa0ba489d460c88f0622 @@ -1,6 +1,7 @@ + * added palm-datebook-reminders --- diff --git a/debian/changelog b/debian/changelog index 46df982..aa38b0f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ chiark-utils (3.99.1) unstable; urgency=low * grungily add prototypes for everything to chiark-named-conf. + * added palm-datebook-reminders -- diff --git a/scripts/Makefile b/scripts/Makefile index 30a48bb..c843f6a 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -21,19 +21,26 @@ include ../settings.make -SCRIPTS= named-conf -MANPAGES8= named-conf +SCRIPTS= palm-datebook-reminders +MANPAGES1= palm-datebook-reminders + +CSCRIPTS= named-conf +CMANPAGES8= named-conf all: install: $(INSTALL_DIRECTORY) $(bindir) set -e; for f in $(SCRIPTS); do \ + $(INSTALL_SCRIPT) $$f $(bindir)/$$f; done + set -e; for f in $(CSCRIPTS); do \ $(INSTALL_SCRIPT) $$f $(bindir)/chiark-$$f; done install-docs: $(INSTALL_DIRECTORY) $(man8dir) - set -e; for f in $(MANPAGES8); do \ + set -e; for f in $(MANPAGES1); do \ + $(INSTALL_SCRIPT) $$f.1 $(man1dir)/$$f.1; done + set -e; for f in $(CMANPAGES8); do \ $(INSTALL_SCRIPT) $$f.8 $(man8dir)/chiark-$$f.8; done install-examples: diff --git a/scripts/palm-datebook-reminders b/scripts/palm-datebook-reminders new file mode 100755 index 0000000..036c44b --- /dev/null +++ b/scripts/palm-datebook-reminders @@ -0,0 +1,140 @@ +#!/usr/bin/perl + +use Palm::PDB; +use Palm::Datebook; +use Time::Local; +use POSIX; + +$us= $0 =~ m,[^/]+$, ? $& : $0; + +$detail= 86400*2; +$lookforward= 86400*(7*4+1); +# run at 15:00 daily + +sub setfilename($) { + die "$us: only one filename at a time please\n" if defined $filename; + $filename= $_[0]; +} + +while (@ARGV) { + $_= shift @ARGV; + if (m,^(?:\-t)?(\d+)/(\d+)$,) { + ($detail,$lookforward)=($1+0,$2+0); + } elsif (m,^[./],) { + setfilename($_); + } elsif (m/^\-f/) { + setfilename($'); + } else { + die "$us: unknown argument/option \`$_'\n"; + } +} + +$filename= "DatebookDB.pdb" if !defined $filename; + +defined($now= time) or die $!; +stat $filename or die "$us: $filename: $!\n"; +$backuptime= (stat _)[9]; + +$pdb = new Palm::PDB or die $!; +$pdb->Load($filename) or die $!; + + + +foreach $record (@{ $pdb->{records} }) { + if ($record->{start_hour} != 255) { + $timestr= sprintf("%02d:%02d-%02d:%02d", + $record->{start_hour}, + $record->{start_minute}, + $record->{end_hour}, + $record->{end_minute}); + @lt=(0, $record->{start_minute}, $record->{start_hour}); + } else { + @lt=(0, 0, 9); + $timestr= " "; + } + if ($record->{repeat}{type}) { + $timestr= "onwards "; + } + + push @lt, $record->{day}, $record->{month}-1, $record->{year}-1900; + defined($ettt= timelocal @lt) or die $!; + + next if ($ettt < $now - 86400 || + $ettt > $now + $lookforward); + + @lt2= localtime($ettt) or die $!; + defined($dowstr= strftime "%a", @lt2) or die $!; + + $datestr= sprintf("%04d-%02d-%02d", + $record->{year}, + $record->{month}, + $record->{day}); + + $timesortkey= "$datestr $timestr"; + $evhead= "$datestr $dowstr $timestr"; + + $desc= $record->{description}; + $desc =~ s/\x93/\~/g; + $desc =~ s/\xa3/L/g; + $desc =~ s/[^\n -\176]/ sprintf "\\x%02x", ord $& /eg; + $desc =~ s/^ +//; + $desc =~ s/\n+$//; + $desc .= "\n"; + + if ($desc =~ m/^(.{0,51})\n/) { + $descsumm= $1; + } elsif ($desc =~ m/^.{48}/) { + $descsumm= $&.'...'; + } else { + $descsumm= " --- no description ?! ---"; + } + $kind= $ettt < $now + $detail ? 'detail' : 'forward'; + + push @{ $events{$kind} }, { + TSK => $timesortkey, + Headline => sprintf("%s %s", $evhead, $descsumm), + Desc => $desc + }; +} + +sub sectline_detail(){ return "Imminent events"; } +sub sectline_forward(){ return "Forthcoming events"; } + +sub headline(){ + printf("%s\n", $ev->{Headline}) + or die $!; +} + +sub print_forward(){ headline(); } +sub print_detail(){ + print "\n" or die $!; + headline(); + $_= $ev->{Desc}; + s/^/ /gm; + print $_ or die $!; +} + +foreach $kind (qw(detail forward)) { + $sectline= &{"sectline_$kind"}; + printf("%s\n%s\n", + $sectline, + '-'x(length $sectline)) + or die $!; + if (!@{ $events{$kind} }) { + printf("None scheduled.\n") + or die $!; + } + foreach $ev (sort { $a->{TSK} cmp $b->{TSK} } @{ $events{$kind} }) { + &{"print_$kind"}; + } + print "\n" or die $!; +} + +@lt2= localtime $backuptime or die $!; +defined ($syncstr= strftime "%Y-%m-%d %a %H:%M", @lt2) or die $!; + +print("Date of last synch: $syncstr\n". + "Events entered on PDA after this date are omitted.\n") + or die $!; + +close STDOUT or die $!; diff --git a/scripts/palm-datebook-reminders.1 b/scripts/palm-datebook-reminders.1 new file mode 100644 index 0000000..1f49651 --- /dev/null +++ b/scripts/palm-datebook-reminders.1 @@ -0,0 +1,66 @@ +.\" Hey, Emacs! This is an -*- nroff -*- source file. +.TH PALM\-DATEBOOK\-REMINDERS 8 "12th January 2002" "Greenend" "chiark utilities" +.SH NAME +palm\-datebook\-reminders \- generate simple report from Palm Datebook DB +.SH SYNOPSIS +.BR PALM\-DATEBOOK\-REMINDERS " [\fIoptions\fP] +.SH DESCRIPTION +.B palm\-datebook\-reminders +reads a Palm Datebook database and prints out a list of events in the +near future in a reasonably easy to read format. +.PP +Immiment events (ones in approximately the next 48 hours by default) +are listed with complete item text. Forthcoming events (approximately +the next 4 weeks by default) are listed in summary form. +.SH OPTIONS +.TP +.IR imminent \fB/\fR forthcoming " | " \fB-t\fR imminent \fB/\fR forthcoming +Specifies that imminent and forthcoming events are ones within the next +.I immiment +and +.I forthcoming +seconds, respectively. +.TP +.IR filename " | \fB-f\fR" filename +Reads the file +.I filename +instead of +.BR ./DatebookDB.pdb . +If the bare form is used, +.I filename +must start with a +.B . +or +.B / +(dot or slash). +.SH BUGS +The program is not configurable enough. + +The option parsing is very grotty. + +Proper character set conversion is not performed. +.SH FILES +.TP +.BR DatebookDB.pdb +Default input file. +.SH AUTHOR +.B PALM\-DATEBOOK\-REMINDERS +and this manpage were written by Ian Jackson +. They are Copyright 2003 Ian Jackson. + +palm\-datebook\-reminders and this manpage are free software; you can +redistribute it and/or modify it under the terms of the GNU General +Public License as published by the Free Software Foundation; either +version 2, or (at your option) any later version. + +This is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +Palm Datebook is a piece of proprietary software supplied with Palm +organisers. Palm and Datebook are probably trademarks.