| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
marclint - MARC record linting utility |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
B<marclint> [options] file(s) |
| 10 |
|
| 11 |
=over 4 |
| 12 |
|
| 13 |
=item options |
| 14 |
|
| 15 |
=over 4 |
| 16 |
|
| 17 |
=item --help |
| 18 |
|
| 19 |
Print a summary of commands |
| 20 |
|
| 21 |
=item --[no]stats |
| 22 |
|
| 23 |
Print a statistical summary by file at the end. (Default: on) |
| 24 |
|
| 25 |
=back |
| 26 |
|
| 27 |
=back |
| 28 |
|
| 29 |
=cut |
| 30 |
|
| 31 |
use strict; |
| 32 |
use integer; |
| 33 |
|
| 34 |
use MARC::File::USMARC; |
| 35 |
use MARC::Lint; |
| 36 |
use Getopt::Long; |
| 37 |
|
| 38 |
use constant USAGE => <<"END"; |
| 39 |
Usage: marclint [options] file(s) |
| 40 |
options |
| 41 |
--help |
| 42 |
Print a summary of commands |
| 43 |
--version |
| 44 |
Print version |
| 45 |
--[no]quiet |
| 46 |
Suppress status messages |
| 47 |
--[no]stats |
| 48 |
Print a statistical summary by file at the end |
| 49 |
END |
| 50 |
|
| 51 |
my $stats = 1; |
| 52 |
my $help = 0; |
| 53 |
my $quiet = 0; |
| 54 |
|
| 55 |
my $rc = GetOptions( |
| 56 |
"stats!" => \$stats, |
| 57 |
"quiet!" => \$quiet, |
| 58 |
"help" => \$help, |
| 59 |
"version" => sub { print "$0, using MARC::Record v$MARC::Record::VERSION\n"; exit 1; }, |
| 60 |
); |
| 61 |
|
| 62 |
my @files = @ARGV; |
| 63 |
|
| 64 |
die USAGE if $help or (not $rc) or (@files == 0); |
| 65 |
|
| 66 |
my $linter = new MARC::Lint; |
| 67 |
my %counts; |
| 68 |
my %errors; |
| 69 |
|
| 70 |
for my $filename ( @files ) { |
| 71 |
$counts{$filename} = 0; |
| 72 |
$errors{$filename} = 0; |
| 73 |
|
| 74 |
my $file = MARC::File::USMARC->in( $filename ) or die $MARC::File::ERROR; |
| 75 |
warn "$filename\n" unless $quiet; |
| 76 |
|
| 77 |
while ( my $marc = $file->next() ) { |
| 78 |
if ( not $marc ) { |
| 79 |
warn $MARC::Record::ERROR; |
| 80 |
++$errors{$filename}; |
| 81 |
} else { |
| 82 |
++$counts{$filename}; |
| 83 |
} |
| 84 |
|
| 85 |
#store warnings in @warningstoreturn |
| 86 |
my @warningstoreturn = (); |
| 87 |
|
| 88 |
#retrieve any decoding errors |
| 89 |
#get any warnings from decoding the raw MARC |
| 90 |
push @warningstoreturn, $marc->warnings(); |
| 91 |
|
| 92 |
$linter->check_record( $marc ); |
| 93 |
|
| 94 |
#add any warnings from MARC::Lint |
| 95 |
push @warningstoreturn, $linter->warnings; |
| 96 |
|
| 97 |
if ( @warningstoreturn ) { |
| 98 |
print join( "\n", |
| 99 |
$marc->title, |
| 100 |
@warningstoreturn, |
| 101 |
"", |
| 102 |
"", |
| 103 |
); |
| 104 |
++$errors{$filename}; |
| 105 |
} |
| 106 |
} # while |
| 107 |
$file->close(); |
| 108 |
} # for |
| 109 |
|
| 110 |
if ( $stats ) { |
| 111 |
print "\n\n"; |
| 112 |
print " Recs Errs Filename\n"; |
| 113 |
print "----- ----- --------\n"; |
| 114 |
for my $key ( sort keys %counts ) { |
| 115 |
printf( "%5d %5d %s\n", $counts{$key}, $errors{$key}, $key ); |
| 116 |
} # for |
| 117 |
} # if stats |
| 118 |
|