+ } elsif ($type_base eq "marc") {
+
+ require MARC;
+
+ $import2cp = Text::Iconv->new($config->{marc_codepage},$codepage);
+ my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!";
+
+ # optional argument is format
+ my $format = x($config->{marc_format}) || 'usmarc';
+
+ print STDERR "Reading MARC file '$marc_file'\n";
+
+ my $marc = new MARC;
+ my $nr = $marc->openmarc({
+ file=>$marc_file, format=>$format
+ }) || die "Can't open MARC file '$marc_file' with format '$format'";
+
+ # read MARC file in memory
+ $marc->nextmarc(-1);
+
+ my $max_rec = $marc->marc_count();
+
+ for(my $i=1; $i<=$max_rec; $i++) {
+
+ progress($i,$max_rec);
+
+ # store value for marc_sf.pm
+ $main::cache->{marc_record} = $i;
+
+ my $swishpath = $database."#".$i;
+
+ if (my $xml = data2xml($type_base,$marc,$add_xml,$cfg,$database)) {
+ $xml = $cp2utf->convert($xml);
+ use bytes; # as opposed to chars
+ print "Path-Name: $swishpath\n";
+ print "Content-Length: ".(length($xml)+1)."\n";
+ print "Document-Type: XML\n\n$xml\n";
+ }
+ }
+
+ print STDERR "\n";
+
+ } elsif ($type_base eq "feed") {
+
+ $import2cp = Text::Iconv->new($config->{feed_codepage},$codepage);
+ my $prog = x($config->{prog}) || die "$database doesn't have 'prog' defined!";
+
+ print STDERR "Reading feed from program '$prog'\n";
+
+ open(FEED,"feeds/$prog |") || die "can't start $prog: $!";
+
+ my $i=1; # record nr.
+
+ my $data;
+ my $line=1;
+
+ while (<FEED>) {
+ chomp;
+
+ if (/^$/) {
+ my $swishpath = $database."#".$i++;
+
+ if (my $xml = data2xml($type_base,$data,$add_xml,$cfg,$database)) {
+ $xml = $cp2utf->convert($xml);
+ use bytes; # as opposed to chars
+ print "Path-Name: $swishpath\n";
+ print "Content-Length: ".(length($xml)+1)."\n";
+ print "Document-Type: XML\n\n$xml\n";
+ }
+ $line = 1;
+ $data = {};
+ next;
+ }
+
+ $line = $1 if (s/^(\d+):\s*//);
+ $data->{$line++} = $_;
+
+ fakeprogress($i);
+
+ }
+ # close lookup
+ untie %lhash if (%lhash);