9 |
BEGIN { |
BEGIN { |
10 |
use Exporter (); |
use Exporter (); |
11 |
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
12 |
$VERSION = 0.07; |
$VERSION = 0.08; |
13 |
@ISA = qw (Exporter); |
@ISA = qw (Exporter); |
14 |
#Give a hoot don't pollute, do not export more than needed by default |
#Give a hoot don't pollute, do not export more than needed by default |
15 |
@EXPORT = qw (); |
@EXPORT = qw (); |
37 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
38 |
|
|
39 |
This module will read ISIS databases created by DOS CDS/ISIS, WinIsis or |
This module will read ISIS databases created by DOS CDS/ISIS, WinIsis or |
40 |
IsisMarc. It can be used as perl-only alternative to OpenIsis module. |
IsisMarc. It can be used as perl-only alternative to OpenIsis module which |
41 |
|
seems to depriciate it's old C<XS> bindings for perl. |
42 |
|
|
43 |
It can create hash values from data in ISIS database (using C<to_hash>), |
It can create hash values from data in ISIS database (using C<to_hash>), |
44 |
ASCII dump (using C<to_ascii>) or just hash with field names and packed |
ASCII dump (using C<to_ascii>) or just hash with field names and packed |
51 |
It also has support for identifiers (only if ISIS database is created by |
It also has support for identifiers (only if ISIS database is created by |
52 |
IsisMarc), see C<to_hash>. |
IsisMarc), see C<to_hash>. |
53 |
|
|
54 |
This will module will always be slower than OpenIsis module which use C |
This module will always be slower than OpenIsis module which use C |
55 |
library. However, since it's written in perl, it's platform independent (so |
library. However, since it's written in perl, it's platform independent (so |
56 |
you don't need C compiler), and can be easily modified. I hope that it |
you don't need C compiler), and can be easily modified. I hope that it |
57 |
creates data structures which are easier to use than ones created by |
creates data structures which are easier to use than ones created by |
215 |
|
|
216 |
=head2 read_cnt |
=head2 read_cnt |
217 |
|
|
218 |
This function is not really used by module, but can be useful to find info |
Read content of C<.CNT> file and return hash containing it. |
|
about your index (if debugging it for example). |
|
219 |
|
|
220 |
print Dumper($isis->read_cnt); |
print Dumper($isis->read_cnt); |
221 |
|
|
222 |
|
This function is not used by module (C<.CNT> files are not required for this |
223 |
|
module to work), but it can be useful to examine your index (while debugging |
224 |
|
for example). |
225 |
|
|
226 |
=cut |
=cut |
227 |
|
|
228 |
sub read_cnt { |
sub read_cnt { |
300 |
|
|
301 |
# is mfn allready in memory? |
# is mfn allready in memory? |
302 |
my $old_mfn = $self->{'current_mfn'} || -1; |
my $old_mfn = $self->{'current_mfn'} || -1; |
303 |
return if ($mfn == $old_mfn); |
return $self->{record} if ($mfn == $old_mfn); |
304 |
|
|
305 |
print STDERR "## fetch: $mfn\n" if ($self->{debug}); |
print STDERR "## fetch: $mfn\n" if ($self->{debug}); |
306 |
|
|
312 |
|
|
313 |
my $buff; |
my $buff; |
314 |
|
|
315 |
|
# delete old record |
316 |
|
delete $self->{record}; |
317 |
|
|
318 |
# read XRFMFB abd XRFMFP |
# read XRFMFB abd XRFMFP |
319 |
read($self->{'fileXRF'}, $buff, 4); |
read($self->{'fileXRF'}, $buff, 4); |
320 |
my $pointer=unpack("l",$buff) || carp "pointer is null"; |
my $pointer=unpack("l",$buff) || carp "pointer is null"; |
321 |
|
|
322 |
|
# check for logically deleted record |
323 |
|
if ($pointer < 0) { |
324 |
|
print STDERR "## record $mfn is logically deleted\n" if ($self->{debug}); |
325 |
|
$self->{deleted} = $mfn; |
326 |
|
|
327 |
|
return unless $self->{include_deleted}; |
328 |
|
|
329 |
|
$pointer = abs($pointer); |
330 |
|
} |
331 |
|
|
332 |
my $XRFMFB = int($pointer/2048); |
my $XRFMFB = int($pointer/2048); |
333 |
my $XRFMFP = $pointer - ($XRFMFB*2048); |
my $XRFMFP = $pointer - ($XRFMFB*2048); |
334 |
|
|
|
|
|
335 |
# (XRFMFB - 1) * 512 + XRFMFP |
# (XRFMFB - 1) * 512 + XRFMFP |
336 |
# why do i have to do XRFMFP % 1024 ? |
# why do i have to do XRFMFP % 1024 ? |
337 |
|
|
338 |
my $blk_off = (($XRFMFB - 1) * 512) + ($XRFMFP % 1024); |
my $blk_off = (($XRFMFB - 1) * 512) + ($XRFMFP % 512); |
339 |
|
|
340 |
print STDERR "## pointer: $pointer XRFMFB: $XRFMFB XRFMFP: $XRFMFP offset: $blk_off\n" if ($self->{'debug'}); |
print STDERR "## pointer: $pointer XRFMFB: $XRFMFB XRFMFP: $XRFMFP offset: $blk_off\n" if ($self->{'debug'}); |
341 |
|
|
349 |
print STDERR "## offset for rowid $value is $blk_off (blk $XRFMFB off $XRFMFP)\n" if ($self->{debug}); |
print STDERR "## offset for rowid $value is $blk_off (blk $XRFMFB off $XRFMFP)\n" if ($self->{debug}); |
350 |
|
|
351 |
if ($value!=$mfn) { |
if ($value!=$mfn) { |
352 |
carp "Error: MFN ".$mfn." not found in MST(".$value.")"; |
if ($value == 0) { |
353 |
#return; # XXX deleted record? |
print STDERR "## record $mfn is physically deleted\n" if ($self->{debug}); |
354 |
} |
$self->{deleted} = $mfn; |
355 |
|
return; |
356 |
|
} |
357 |
|
|
358 |
# $MFRL=$self->Read16($fileMST); |
carp "Error: MFN ".$mfn." not found in MST file, found $value"; |
359 |
# $MFBWB=$self->Read32($fileMST); |
return; |
360 |
# $MFBWP=$self->Read16($fileMST); |
} |
|
# $BASE=$self->Read16($fileMST); |
|
|
# $NVF=$self->Read16($fileMST); |
|
|
# $STATUS=$self->Read16($fileMST); |
|
361 |
|
|
362 |
read($self->{'fileMST'}, $buff, 14); |
read($self->{'fileMST'}, $buff, 14); |
363 |
|
|
365 |
|
|
366 |
print STDERR "## MFRL: $MFRL MFBWB: $MFBWB MFBWP: $MFBWP BASE: $BASE NVF: $NVF STATUS: $STATUS\n" if ($self->{debug}); |
print STDERR "## MFRL: $MFRL MFBWB: $MFBWB MFBWP: $MFBWP BASE: $BASE NVF: $NVF STATUS: $STATUS\n" if ($self->{debug}); |
367 |
|
|
368 |
# delete old record |
warn "MFRL $MFRL is not even number" unless ($MFRL % 2 == 0); |
|
delete $self->{record}; |
|
|
|
|
|
## FIXME this is a bug |
|
|
if (! $self->{'include_deleted'} && $MFRL < 0) { |
|
|
print "## logically deleted record $mfn, skipping...\n" if ($self->{debug}); |
|
|
return; |
|
|
} |
|
369 |
|
|
370 |
warn "BASE is not 18+6*NVF" unless ($BASE == 18 + 6 * $NVF); |
warn "BASE is not 18+6*NVF" unless ($BASE == 18 + 6 * $NVF); |
371 |
|
|
381 |
|
|
382 |
for (my $i = 0 ; $i < $NVF ; $i++) { |
for (my $i = 0 ; $i < $NVF ; $i++) { |
383 |
|
|
|
# $TAG=$self->Read16($fileMST); |
|
|
# $POS=$self->Read16($fileMST); |
|
|
# $LEN=$self->Read16($fileMST); |
|
|
|
|
384 |
my ($TAG,$POS,$LEN) = unpack("sss", substr($buff,$i * 6, 6)); |
my ($TAG,$POS,$LEN) = unpack("sss", substr($buff,$i * 6, 6)); |
385 |
|
|
386 |
print STDERR "## TAG: $TAG POS: $POS LEN: $LEN\n" if ($self->{debug}); |
print STDERR "## TAG: $TAG POS: $POS LEN: $LEN\n" if ($self->{debug}); |
417 |
|
|
418 |
$self->{'current_mfn'} = $mfn; |
$self->{'current_mfn'} = $mfn; |
419 |
|
|
420 |
print Dumper($self),"\n" if ($self->{debug}); |
print STDERR Dumper($self),"\n" if ($self->{debug}); |
421 |
|
|
422 |
return $self->{'record'}; |
return $self->{'record'}; |
423 |
} |
} |
424 |
|
|
425 |
=head2 to_ascii |
=head2 to_ascii |
426 |
|
|
427 |
Dump ASCII output of record with specified MFN |
Returns ASCII output of record with specified MFN |
428 |
|
|
429 |
print $isis->to_ascii(42); |
print $isis->to_ascii(42); |
430 |
|
|
431 |
It outputs something like this: |
This outputs something like this: |
432 |
|
|
433 |
210 ^aNew York^cNew York University press^dcop. 1988 |
210 ^aNew York^cNew York University press^dcop. 1988 |
434 |
990 2140 |
990 2140 |
465 |
|
|
466 |
my $hash = $isis->to_hash($mfn); |
my $hash = $isis->to_hash($mfn); |
467 |
|
|
468 |
It has ability to convert characters (using C<hash_filter> from ISIS |
It has ability to convert characters (using C<hash_filter>) from ISIS |
469 |
database before creating structures enabling character re-mapping or quick |
database before creating structures enabling character re-mapping or quick |
470 |
fix-up of data. |
fix-up of data. |
471 |
|
|
561 |
|
|
562 |
=head1 BUGS |
=head1 BUGS |
563 |
|
|
564 |
This module has been very lightly tested. Use with caution and report bugs. |
Some parts of CDS/ISIS documentation are not detailed enough to exmplain |
565 |
|
some variations in input databases which has been tested with this module. |
566 |
|
When I was in doubt, I assumed that OpenIsis's implementation was right |
567 |
|
(except for obvious bugs). |
568 |
|
|
569 |
|
However, every effort has been made to test this module with as much |
570 |
|
databases (and programs that create them) as possible. |
571 |
|
|
572 |
|
I would be very greatful for success or failure reports about usage of this |
573 |
|
module with databases from programs other than WinIsis and IsisMarc. I had |
574 |
|
tested this against ouput of one C<isis.dll>-based application, but I don't |
575 |
|
know any details about it's version. |
576 |
|
|
577 |
=head1 AUTHOR |
=head1 AUTHOR |
578 |
|
|