#!/usr/bin/perl # $Id: vcsjoin 15 2008-08-25 06:12:59Z thk $ use strict; use warnings; use Data::ICal; use File::Basename; use Getopt::Std; sub caljoin(@) { my $outcal = Data::ICal->new(vcal10 => 1); for my $infname (@_) { my $incal = Data::ICal->new(filename => $infname, vcal10 => 1); unless ($incal) { print $infname, ": failed to read.\n"; next; } for (@{$incal->entries}) { $_->add_property("X-VCSJOIN-FILE" => basename $infname); $outcal->add_entry($_); } } return $outcal; } sub getprop($$) { $_[0]->property($_[1])->[0]->value; } sub HELP_MESSAGE { print "Usage: vcsjoin [vcsfile ...] Print to stdout a single vCalendar file containing all events in the vcsfiles. Each event is given an additional property X-VCSJOIN-FILE. Its value is the basename of the input file that contained the event. vcsjoin -l [vcsfile ...] Prints the events in the vcsfiles in human readable form. "; exit 1; } my %options; $Getopt::Std::STANDARD_HELP_VERSION = 1; getopts 'l', \%options or HELP_MESSAGE; # Format variables our ($fname, $date, $desc); my $cal = caljoin @ARGV; if ($options{l}) { my @entries = map([basename(getprop($_, "X-VCSJOIN-FILE"), ".vcs"), getprop($_, "DTSTART"), getprop($_, "DESCRIPTION")], @{$cal->entries}); for (sort {$a->[1] cmp $b->[1]} @entries) { ($fname, $date, $desc) = @$_; $date =~ s/^(....)(..)(..)T(..)(..)..$/$1-$2-$3 $4:$5/; write; } } else { print $cal->as_string; } format STDOUT_TOP = No Start time Description . format = @## @<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $fname, $date, $desc ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $desc .