| 1 | #!/usr/local/bin/perl | ||
| 2 | use strict; | ||
| 3 | use utf8; | ||
| 4 | use open qw(:std :utf8); | ||
| 5 | use Getopt::Long; | ||
| 6 | use FB3::Validator; | ||
| 7 | use File::ShareDir qw/dist_dir/; | ||
| 8 | |||
| 9 | my ($Help, $Verbose, $XsdDir, $File); | ||
| 10 | GetOptions( | ||
| 11 | 'help|h' => \$Help, | ||
| 12 | 'verbose|v' => \$Verbose, | ||
| 13 | 'xsd=s' => \$XsdDir, | ||
| 14 | 'fb3=s' => \$File, | ||
| 15 | ) or usage ("Incorrect usage!"); | ||
| 16 | |||
| 17 | $XsdDir ||= FB3::SchemasDirPath(); | ||
| 18 | |||
| 19 | usage() if (defined $Help); | ||
| 20 | usage(qq{File $File doesn't exist or empty!}) unless ( -e $File ); | ||
| 21 | usage(qq{--xsd option is required!}) unless $XsdDir; | ||
| 22 | |||
| 23 | sub usage { | ||
| 24 | my $message = $_[0]; | ||
| 25 | if (defined $message && length $message) { | ||
| 26 | $message .= "\n" unless $message =~ /\n$/; | ||
| 27 | } | ||
| 28 | |||
| 29 | my $command = $0; | ||
| 30 | $command =~ s#^.*/##; | ||
| 31 | |||
| 32 | print STDERR ( | ||
| 33 | $message, | ||
| 34 | qq{usage: $command | ||
| 35 | --help -h => this help | ||
| 36 | --verbose -v => debug messages | ||
| 37 | --fb3="path" => path to FB3 file | ||
| 38 | --xsd="path" => path to directory with FB3 xsd files | ||
| 39 | if omitted, internal schemes will be used | ||
| 40 | (convenient in most cases)} | ||
| 41 | ); | ||
| 42 | |||
| 43 | die("\n") | ||
| 44 | } | ||
| 45 | |||
| 46 | my $Validator = FB3::Validator->new( $XsdDir ); | ||
| 47 | my $ValidationError = $Validator->Validate( $File ); | ||
| 48 | if ($ValidationError) { | ||
| 49 | print "File $File is not valid: $ValidationError"; | ||
| 50 | } else { | ||
| 51 | print "File $File is valid FB3 file\n"; | ||
| 52 | } | ||
| 53 | |||
| 54 |