845 |
} |
} |
846 |
} elsif ($type_base eq "marc") { |
} elsif ($type_base eq "marc") { |
847 |
|
|
848 |
require MARC; |
require MARC::File::USMARC; |
849 |
|
|
850 |
$import2cp = Text::Iconv->new($config->{marc_codepage},$codepage); |
$import2cp = Text::Iconv->new($config->{marc_codepage},$codepage); |
851 |
my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!"; |
my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!"; |
852 |
|
|
853 |
# optional argument is format |
# optional argument is format |
854 |
my $format = x($config->{marc_format}) || 'usmarc'; |
warn "marc_format is no longer used!" if ($config->{marc_format}); |
|
|
|
855 |
print STDERR "Reading MARC file '$marc_file'\n"; |
print STDERR "Reading MARC file '$marc_file'\n"; |
856 |
|
|
857 |
my $marc = new MARC; |
my $marc = MARC::File::USMARC->in( $marc_file ) |
858 |
my $nr = $marc->openmarc({ |
|| die "Can't open MARC file '$marc_file': ".$MARC::File::ERROR; |
|
file=>$marc_file, format=>$format |
|
|
}) || die "Can't open MARC file '$marc_file' with format '$format'"; |
|
859 |
|
|
860 |
# read MARC file in memory |
# count records in MARC file |
861 |
$marc->nextmarc(-1); |
sub marc_count { |
862 |
|
my $filename = shift || die; |
863 |
|
my $file = MARC::File::USMARC->in($filename) || die $MARC::File::ERROR; |
864 |
|
my $count = 0; |
865 |
|
while ($file->skip()) { |
866 |
|
$count++; |
867 |
|
} |
868 |
|
return $count; |
869 |
|
} |
870 |
|
|
871 |
my $max_rec = $marc->marc_count(); |
my $count = marc_count($marc_file) || warn "no records in '$marc_file'?"; |
872 |
|
|
873 |
for(my $i=1; $i<=$max_rec; $i++) { |
my $i = 0; |
874 |
|
|
875 |
progress($i,$max_rec); |
while( my $rec = $marc->next() ) { |
876 |
|
|
877 |
# store value for marc_sf.pm |
progress($i++,$count); |
|
$main::cache->{marc_record} = $i; |
|
878 |
|
|
879 |
my $swishpath = $database."#".$i; |
my $swishpath = $database."#".$i; |
880 |
|
|
881 |
if (my $xml = data2xml($type_base,$marc,$add_xml,$cfg,$database)) { |
if (my $xml = data2xml($type_base,$rec,$add_xml,$cfg,$database)) { |
882 |
$xml = $cp2utf->convert($xml); |
$xml = $cp2utf->convert($xml); |
883 |
use bytes; # as opposed to chars |
use bytes; # as opposed to chars |
884 |
print "Path-Name: $swishpath\n"; |
print "Path-Name: $swishpath\n"; |