#! /usr/bin/perl -w

# Split a large VCALENDAR into unit VCALENDAR containing
# only one VEVENT

use strict;

my $cnt = 0;

while (<>) {
    last if /^BEGIN:VEVENT/;
}
my $data;
while (<>) {
    if (/^END:VEVENT/) {
        my $filename = "ics_split_$cnt.ics";
        open my $fh, "> $filename" or die "$filename: $!\n";
        $cnt++;

        chop $data;
        print $fh <<EOF;
BEGIN:VCALENDAR
PRODID:ics_split
VERSION:2.0
$data
END:VEVENT
END:VCALENDAR
EOF

        $data = "";
    } else {
        $data .= $_;
    }
}
