3 # Copyright 2003 Ian Jackson <ian@chiark.greenend.org.uk>
5 # This script and its documentation (if any) are free software; you
6 # can redistribute it and/or modify them under the terms of the GNU
7 # General Public License as published by the Free Software Foundation;
8 # either version 3, or (at your option) any later version.
10 # chiark-named-conf and its manpage are distributed in the hope that
11 # it will be useful, but WITHOUT ANY WARRANTY; without even the
12 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 # PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, consult the Free Software Foundation's
17 # website at www.fsf.org, or the GNU Project website at www.gnu.org.
24 $us= $0 =~ m,[^/]+$, ? $& : $0;
27 $lookforward= 86400*(7*4+1);
31 die "$us: only one filename at a time please\n" if defined $filename;
37 if (m,^(?:\-t)?(\d+)/(\d+)$,) {
38 ($detail,$lookforward)=($1+0,$2+0);
44 die "$us: unknown argument/option \`$_'\n";
48 $filename= "DatebookDB.pdb" if !defined $filename;
50 defined($now= time) or die $!;
51 stat $filename or die "$us: $filename: $!\n";
52 $backuptime= (stat _)[10];
54 $pdb = new Palm::PDB or die $!;
55 $pdb->Load($filename) or die $!;
59 foreach $record (@{ $pdb->{records} }) {
60 if ($record->{start_hour} != 255) {
61 $timestr= sprintf("%02d:%02d-%02d:%02d",
62 $record->{start_hour},
63 $record->{start_minute},
65 $record->{end_minute});
66 @lt=(0, $record->{start_minute}, $record->{start_hour});
71 if ($record->{repeat}{type}) {
75 push @lt, $record->{day}, $record->{month}-1, $record->{year}-1900;
76 defined($ettt= timelocal @lt) or die $!;
78 next if ($ettt < $now - 86400 ||
79 $ettt > $now + $lookforward);
81 @lt2= localtime($ettt) or die $!;
82 defined($dowstr= strftime "%a", @lt2) or die $!;
84 $datestr= sprintf("%04d-%02d-%02d",
89 $timesortkey= "$datestr $timestr";
90 $evhead= "$datestr $dowstr $timestr";
92 $desc= $record->{description};
95 $desc =~ s/[^\n -\176]/ sprintf "\\x%02x", ord $& /eg;
100 if ($desc =~ m/^(.{0,51})\n/) {
102 } elsif ($desc =~ m/^.{48}/) {
105 $descsumm= " --- no description ?! ---";
107 $kind= $ettt < $now + $detail ? 'detail' : 'forward';
109 push @{ $events{$kind} }, {
111 Headline => sprintf("%s %s", $evhead, $descsumm),
116 sub sectline_detail(){ return "Imminent events"; }
117 sub sectline_forward(){ return "Forthcoming events"; }
120 printf("%s\n", $ev->{Headline})
124 sub print_forward(){ headline(); }
126 print "\n" or die $!;
133 foreach $kind (qw(detail forward)) {
134 $sectline= &{"sectline_$kind"};
137 '-'x(length $sectline))
139 if (!@{ $events{$kind} }) {
140 printf("None scheduled.\n")
143 foreach $ev (sort { $a->{TSK} cmp $b->{TSK} } @{ $events{$kind} }) {
146 print "\n" or die $!;
149 @lt2= localtime $backuptime or die $!;
150 defined ($syncstr= strftime "%Y-%m-%d %a %H:%M", @lt2) or die $!;
152 print("Date of last synch: $syncstr\n".
153 "Events entered on PDA after this date are omitted.\n")
156 close STDOUT or die $!;