#!/usr/local/bin/perl -w

use strict;

use iCal::Parser::SAX;
use XML::SAX::Writer;
use Getopt::Std;

our $VERSION=sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);

our %opts=();
our $opts='f:t:m:z:TEdh';
our $usage=qq{usage: $0 {$opts} file ...
  -f yyyymmdd only output events from inclusive date
  -t yyyymmdd only output events until date
  -m num      only output num month of events
  -z tz       timezone to use (e.g "America/New_York")
  -T          don't output todos
  -E          don't output events
  -d          debug
  -h          the ususal
};
our %optmap=(f=>'start',
	     t=>'end',
	     m=>'months',
	     z=>'tz',
	     T=>'no_todos',
	     E=>'no_events',
	     d=>'debug',
	    );
getopts($opts,\%opts) || die $usage;
print $usage and exit 0 if $opts{h};
die $usage unless @ARGV;

my %args=();
map {$args{$optmap{$_}}=$opts{$_} if defined $opts{$_}} keys %optmap;

iCal::Parser::SAX->new(Handler=>XML::SAX::Writer->new(Escape=>{XXX=>'XXX'}),
		       %args)->parse_uris(@ARGV);
exit 0;

__END__

=head1 NAME

ical2xml - Convert iCalendar files to XML

=head1 SYNOPSIS

    ical2xml [options] file.ics ..

=head1 DESCRIPTION

This program uses L<iCal::Parser::SAX> to convert iCalendar files to XML.

The xml document generated is designed
for creating monthly calendars with weeks beginning on monday
(e.g., by passing the output through an xsl styleheet).

Multiple input files are merged into a single XML output stream.

=head1 OPTIONS

=over 4

=item -f yyyymmdd

only output events from inclusive date

=item -t yyyymmdd

only output events until date

=item m num

only output events num month from the start date

=item z tz

adjust dates to specified timezone (defaults to local timezone)

=item -T 

don't output todos

=item -E 

don't output events

=item -d 

debug

=item -h 

the ususal

=back

=head1 AUTHOR

Rick Frankel, cpan@rickster.com

=head1 COPYRIGHT

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.


=head1 SEE ALSO

L<iCal::Parser::SAX>
