1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use strict; |
4 |
use MARC; |
5 |
use URI::Escape; |
6 |
require "../common.pm"; |
7 |
|
8 |
my $file = shift @ARGV; |
9 |
my $index = shift @ARGV|| die "Usage: $0 [marc file] [index dir]"; |
10 |
|
11 |
my %id_stored; # to aviod duplicates |
12 |
|
13 |
my $x = new MARC; |
14 |
my $nr = $x->openmarc( { file => $file, format => 'usmarc' }) || |
15 |
die "Can't open MARC file '$file'"; |
16 |
|
17 |
print "file '$file' with '",$x->marc_count(),"' records...\n"; |
18 |
|
19 |
my $dir = open_data_files($index); |
20 |
my $last_tell=0; |
21 |
|
22 |
print MPS "M working...\n"; |
23 |
|
24 |
my $rec; |
25 |
|
26 |
while ($x->nextmarc(1)) { |
27 |
# print $x->output({format=>'ascii'}); # FIX |
28 |
|
29 |
$rec = $x->marc_count(); |
30 |
# print $x->getfirstvalue({record=>$rec,field=>245,subfield=>'a',delimiter=>" "}),"<--\n"; |
31 |
my $bib = ""; |
32 |
my $mps = ""; |
33 |
|
34 |
sub getfld { |
35 |
my ($f,$s) = @_; |
36 |
my $out = $x->getfirstvalue({record=>$rec,field=>$f,subfield=>$s,delimiter=>" "}); |
37 |
# print "$f/$s:$out\n"; |
38 |
return $out; |
39 |
} |
40 |
|
41 |
|
42 |
my $id = getfld(856,'u'); |
43 |
|
44 |
$bib .= "%tip Èasopis\n"; |
45 |
$bib .= "%tip on-line\n"; |
46 |
# url |
47 |
$bib .= "%856 ".getfld(856,'u')."\n"; |
48 |
|
49 |
# naslov |
50 |
$bib .= "%200+ ".getfld(245,'a')."\n"; |
51 |
$mps .= mps_expand(2,getfld(245,'a')); |
52 |
|
53 |
# izdavanje |
54 |
$bib .= "%210+ ".getfld(773,'d')."\n"; |
55 |
$mps .= mps_expand(3,getfld(773,'d')); |
56 |
|
57 |
# issn |
58 |
my $issn = getfld('022','a'); |
59 |
if ($issn) { # ISSN can be missing? |
60 |
$bib .= "%ISSN $issn\n"; |
61 |
$mps .= mps_expand(13,$issn); |
62 |
} |
63 |
|
64 |
$bib .= "%992 ".getfld(856,'3')."\n"; |
65 |
|
66 |
# tip |
67 |
$mps .= mps_expand(17,"on-line casopis"); |
68 |
|
69 |
$mps .= "H ".getfld(245,'a')." <i>(on-line, ".getfld(773,'t').")</i>\n"; |
70 |
|
71 |
if (defined $id && ! defined $id_stored{$id}) { |
72 |
|
73 |
print R $bib."\n"; |
74 |
$mps .= "T document text/plain ".(tell(R) - $last_tell)." $dir/bib $last_tell ".tell(R)."\n"; |
75 |
$last_tell=tell(R); |
76 |
print R "\n"; |
77 |
$mps .= "E\n"; |
78 |
print S $mps; |
79 |
print MPS $mps; |
80 |
|
81 |
$id_stored{$id}++; |
82 |
} else { |
83 |
print "."; |
84 |
} |
85 |
} |
86 |
|
87 |
print S "M over and out\nX\n"; |
88 |
print MPS "M over and out\nX\n"; |
89 |
close(MPS); |