#!/usr/bin/perl -w

eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
    if 0; # not running under some shell

use strict;

use XMLTV::Version '$Id: tv_validate_file.in,v 1.1 2006/01/30 20:43:28 mattiasholmlund Exp $';
use XMLTV::ValidateFile qw/LoadDtd ValidateFile/;
use Getopt::Long;

=pod

=head1 NAME

tv_validate_file - Validate that a file contains valid xmltv data.

=head1 SYNOPSIS

tv_validate_file --help

tv_validate_grabber [--dtd-file <dtdfile>] <file>
                
=head1 DESCRIPTION

=head1 OPTIONS

B<--dtd <dtdfile>> Use the specified file as the xmltv dtd. This is only
necessary if the xmltv dtd is not installed on the
system.

=head1 AUTHOR

Mattias Holmlund, mattias -at- holmlund -dot- se. 

=cut

my $SHARE_DIR='/usr/share/xmltv'; # by tools/tv_validate_file.PL

my $opt = { "dtd-file" => "$SHARE_DIR/xmltv.dtd",
            help => 0,
          };

my $res = GetOptions( $opt, qw/
                      dtd-file=s
                      help|h
                      / );

if ((not $res) or $opt->{help} or scalar( @ARGV ) != 1) {
    print << "EOHELP";
Usage: $0 [options] <file>

EOHELP

    exit 1;
}

my( $file ) = @ARGV;

if (not LoadDtd( $opt->{'dtd-file'} )) {
    print STDERR "Failed to load dtd from $opt->{'dtd-file'}.\n" .
	"Use the --dtd-file option to specify another path to the dtd.\n";
    exit 1;
}

my $errors = ValidateFile( $file );

if ($errors) {
    print "$errors errors found.\n";
    exit 1;
} 
else {
    print "Validated ok.\n";
    exit 0;
}
   
=head1 COPYRIGHT

Copyright (C) 2005 Mattias Holmlund.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

=cut

### Setup indentation in Emacs
## Local Variables:
## perl-indent-level: 4
## perl-continued-statement-offset: 4
## perl-continued-brace-offset: 0
## perl-brace-offset: -4
## perl-brace-imaginary-offset: 0
## perl-label-offset: -2
## cperl-indent-level: 4
## cperl-brace-offset: 0
## cperl-continued-brace-offset: 0
## cperl-label-offset: -2
## cperl-extra-newline-before-brace: t
## cperl-merge-trailing-else: nil
## cperl-continued-statement-offset: 2
## indent-tabs-mode: t
## End:
