1#!/usr/local/bin/perl -w
2
3use strict;
4
5use XMLTV::Version '$Id: tv_validate_file.in,v 1.4 2015/07/12 00:46:37 knowledgejunkie Exp $';
6use XMLTV::ValidateFile qw/LoadDtd ValidateFile/;
7use Getopt::Long;
8
9=pod
10
11=head1 NAME
12
13tv_validate_file - Validate that a file contains valid xmltv data.
14
15=head1 SYNOPSIS
16
17tv_validate_file --help
18
19tv_validate_grabber [--dtd-file <dtdfile>] <file>
20
21=head1 DESCRIPTION
22
23=head1 OPTIONS
24
25B<--dtd <dtdfile>> Use the specified file as the xmltv dtd instead of
26downloading it from the web.
27
28=head1 AUTHOR
29
30Mattias Holmlund, mattias -at- holmlund -dot- se.
31
32=cut
33
34my $opt = { "dtd-file" => undef,
35            help => 0,
36          };
37
38my $res = GetOptions( $opt, qw/
39                      dtd-file=s
40                      help|h
41                      / );
42
43if ((not $res) or $opt->{help} or scalar( @ARGV ) != 1) {
44    print << "EOHELP";
45Usage: $0 [options] <file>
46
47EOHELP
48
49    exit 1;
50}
51
52my( $file ) = @ARGV;
53
54if( defined( $opt->{'dtd-file'}) ) {
55    if (not LoadDtd( $opt->{'dtd-file'} )) {
56        print STDERR "Failed to load dtd from $opt->{'dtd-file'}.\n" .
57          "Use the --dtd-file option to specify another path to the dtd.\n";
58    exit 1;
59  }
60}
61
62my @errors = ValidateFile( $file );
63
64if (scalar @errors) {
65    if (grep(/^not(well|valid)$/, @errors)) {
66      print "The file did not validate as well-formed XML, so no further\nprocessing was performed.\n";
67      exit 1;
68    }
69
70    my $errors = scalar @errors;
71    print "$errors error" . ($errors > 1 ? "s" : "") . " found.\n";
72    exit 1;
73}
74else {
75    print "Validated ok.\n";
76    exit 0;
77}
78
79=head1 COPYRIGHT
80
81Copyright (C) 2005, 2007 Mattias Holmlund.
82
83This program is free software; you can redistribute it and/or
84modify it under the terms of the GNU General Public License
85as published by the Free Software Foundation; either version 2
86of the License, or (at your option) any later version.
87
88This program is distributed in the hope that it will be useful,
89but WITHOUT ANY WARRANTY; without even the implied warranty of
90MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
91GNU General Public License for more details.
92
93You should have received a copy of the GNU General Public License
94along with this program; if not, write to the Free Software
95Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
96
97=cut
98
99### Setup indentation in Emacs
100## Local Variables:
101## perl-indent-level: 4
102## perl-continued-statement-offset: 4
103## perl-continued-brace-offset: 0
104## perl-brace-offset: -4
105## perl-brace-imaginary-offset: 0
106## perl-label-offset: -2
107## cperl-indent-level: 4
108## cperl-brace-offset: 0
109## cperl-continued-brace-offset: 0
110## cperl-label-offset: -2
111## cperl-extra-newline-before-brace: t
112## cperl-merge-trailing-else: nil
113## cperl-continued-statement-offset: 2
114## indent-tabs-mode: t
115## End:
116