-
Notifications
You must be signed in to change notification settings - Fork 0
/
palmcalfrom
executable file
·53 lines (44 loc) · 1.4 KB
/
palmcalfrom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -W
# Print entries from iCalendar file which are greater than start-
# and lower than end-date.
# Options:
# -s <date> start date
# -e <date> end date
# Elmar Klausmeier, 16-Nov-2010
# Elmar Klausmeier, 30-Aug-2013, 1st argument may have variable length
# Elmar Klausmeier, 18-Mar-2015, allow start- and end-date arguments
use strict;
use Getopt::Std;
my %opts;
getopts('s:e:',\%opts);
my ($dtstart,$dtend) = ("00000000","99999999");
$dtstart = $opts{'s'} if (defined($opts{'s'}));
$dtend = $opts{'e'} if (defined($opts{'e'}));
my @stack = ();
my ($beginv, $i, $flag) = (0,0,0);
$dtstart = (length($dtstart) < 8) ?
$dtstart . substr("00000000",0,8 - length($dtstart)) : substr($dtstart,0,8);
$dtstart = "DTSTART:${dtstart}T000000";
$dtend = (length($dtend) < 8) ?
$dtend . substr("00000000",0,8 - length($dtend)) : substr($dtend,0,8);
$dtend = "DTSTART:${dtend}T000000";
print "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Judd Montgomery//NONSGML J-Pilot 1.8.1.2//EN\n";
while (<>) {
next if (/^UID:/); # Google does not need the UID, so drop it
$beginv = 1 if (/^BEGIN:VEVENT/);
$beginv = 0 if (/^END:VEVENT/);
if ($beginv == 1) {
$stack[++$#stack] = $_;
$flag = 1 if (/^DTSTART:/ && $_ ge $dtstart && $_ le $dtend);
} elsif ($beginv == 0) {
if ($flag == 1) {
for ($i=0; $i<=$#stack; ++$i) {
print $stack[$i];
}
print;
}
$flag = 0;
@stack = ();
}
}
print "END:VCALENDAR\n";