projects
/
Biblio-Isis
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
clean up offset calculation (now works with ISIS databases from isis.dll),
[Biblio-Isis]
/
IsisDB.pm
diff --git
a/IsisDB.pm
b/IsisDB.pm
index
87709db
..
dd38c82
100644
(file)
--- a/
IsisDB.pm
+++ b/
IsisDB.pm
@@
-7,7
+7,7
@@
use Data::Dumper;
BEGIN {
use Exporter ();
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
BEGIN {
use Exporter ();
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
- $VERSION = 0.0
5
;
+ $VERSION = 0.0
6
;
@ISA = qw (Exporter);
#Give a hoot don't pollute, do not export more than needed by default
@EXPORT = qw ();
@ISA = qw (Exporter);
#Give a hoot don't pollute, do not export more than needed by default
@EXPORT = qw ();
@@
-210,7
+210,7
@@
sub new {
my $buff = shift || return;
my @arr = unpack("ssssssllls", $buff);
my $buff = shift || return;
my @arr = unpack("ssssssllls", $buff);
- print "unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'});
+ print
STDERR
"unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'});
my $IDTYPE = shift @arr;
foreach (@flds) {
my $IDTYPE = shift @arr;
foreach (@flds) {
@@
-227,7
+227,7
@@
sub new {
close(fileCNT);
close(fileCNT);
- print Dumper($self),"\n" if ($self->{debug});
+ print
STDERR
Dumper($self),"\n" if ($self->{debug});
# open files for later
open($self->{'fileXRF'}, $self->{isisdb}.".XRF") || croak "can't open '$self->{isisdb}.XRF': $!";
# open files for later
open($self->{'fileXRF'}, $self->{isisdb}.".XRF") || croak "can't open '$self->{isisdb}.XRF': $!";
@@
-258,12
+258,16
@@
sub fetch {
my $mfn = shift || croak "fetch needs MFN as argument!";
my $mfn = shift || croak "fetch needs MFN as argument!";
- print "fetch: $mfn\n" if ($self->{debug});
+ # is mfn allready in memory?
+ my $old_mfn = $self->{'current_mfn'} || -1;
+ return if ($mfn == $old_mfn);
+
+ print STDERR "## fetch: $mfn\n" if ($self->{debug});
# XXX check this?
my $mfnpos=($mfn+int(($mfn-1)/127))*4;
# XXX check this?
my $mfnpos=($mfn+int(($mfn-1)/127))*4;
- print
"
seeking to $mfnpos in file '$self->{isisdb}.XRF'\n" if ($self->{debug});
+ print
STDERR "##
seeking to $mfnpos in file '$self->{isisdb}.XRF'\n" if ($self->{debug});
seek($self->{'fileXRF'},$mfnpos,0);
my $buff;
seek($self->{'fileXRF'},$mfnpos,0);
my $buff;
@@
-275,32
+279,26
@@
sub fetch {
my $XRFMFB = int($pointer/2048);
my $XRFMFP = $pointer - ($XRFMFB*2048);
my $XRFMFB = int($pointer/2048);
my $XRFMFP = $pointer - ($XRFMFB*2048);
- print "XRFMFB: $XRFMFB XRFMFP: $XRFMFP\n" if ($self->{debug});
- #
XXX fix this to be more readable!!
- #
e.g. (XRFMFB - 1) * 512 + XRFMFP
+ #
(XRFMFB - 1) * 512 + XRFMFP
+ #
why do i have to do XRFMFP % 1024 ?
- my $offset = $pointer;
- my $offset2=int($offset/2048)-1;
- my $offset22=int($offset/4096);
- my $offset3=$offset-($offset22*4096);
- if ($offset3>512) {
- $offset3=$offset3-2048;
- }
- my $offset4=($offset2*512)+$offset3;
+ my $blk_off = (($XRFMFB - 1) * 512) + ($XRFMFP % 1024);
- print
"$offset - $offset2 - $offset3 - $offset4\n" if ($self->{debug
});
+ print
STDERR "## pointer: $pointer XRFMFB: $XRFMFB XRFMFP: $XRFMFP offset: $blk_off\n" if ($self->{'debug'
});
# Get Record Information
# Get Record Information
- seek($self->{'fileMST'},$
offset4
,0);
+ seek($self->{'fileMST'},$
blk_off
,0);
read($self->{'fileMST'}, $buff, 4);
my $value=unpack("l",$buff);
read($self->{'fileMST'}, $buff, 4);
my $value=unpack("l",$buff);
+ print STDERR "## offset for rowid $value is $blk_off (blk $XRFMFB off $XRFMFP)\n" if ($self->{debug});
+
if ($value!=$mfn) {
if ($value!=$mfn) {
-
print ("Error: The MFN:".$mfn." is not found in MST(".$value.")")
;
-
return -1;
# XXX deleted record?
+
carp "Error: MFN ".$mfn." not found in MST(".$value.")"
;
+
#return;
# XXX deleted record?
}
# $MFRL=$self->Read16($fileMST);
}
# $MFRL=$self->Read16($fileMST);
@@
-314,16
+312,19
@@
print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");
my ($MFRL,$MFBWB,$MFBWP,$BASE,$NVF,$STATUS) = unpack("slssss", $buff);
my ($MFRL,$MFBWB,$MFBWP,$BASE,$NVF,$STATUS) = unpack("slssss", $buff);
- print
"
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});
# delete old record
delete $self->{record};
# delete old record
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;
}
if (! $self->{'include_deleted'} && $MFRL < 0) {
print "## logically deleted record $mfn, skipping...\n" if ($self->{debug});
return;
}
+ warn "BASE is not 18+6*NVF" unless ($BASE == 18 + 6 * $NVF);
+
# Get Directory Format
my @FieldPOS;
# Get Directory Format
my @FieldPOS;
@@
-332,7
+333,7
@@
print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");
read($self->{'fileMST'}, $buff, 6 * $NVF);
read($self->{'fileMST'}, $buff, 6 * $NVF);
- my $
fld
_len = 0;
+ my $
rec
_len = 0;
for (my $i = 0 ; $i < $NVF ; $i++) {
for (my $i = 0 ; $i < $NVF ; $i++) {
@@
-342,7
+343,7
@@
print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");
my ($TAG,$POS,$LEN) = unpack("sss", substr($buff,$i * 6, 6));
my ($TAG,$POS,$LEN) = unpack("sss", substr($buff,$i * 6, 6));
- print
"
TAG: $TAG POS: $POS LEN: $LEN\n" if ($self->{debug});
+ print
STDERR "##
TAG: $TAG POS: $POS LEN: $LEN\n" if ($self->{debug});
# The TAG does not exists in .FDT so we set it to 0.
#
# The TAG does not exists in .FDT so we set it to 0.
#
@@
-358,12
+359,14
@@
print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");
push @FieldPOS,$POS;
push @FieldLEN,$LEN;
push @FieldPOS,$POS;
push @FieldLEN,$LEN;
- $
fld
_len += $LEN;
+ $
rec
_len += $LEN;
}
# Get Variable Fields
}
# Get Variable Fields
- read($self->{'fileMST'},$buff,$fld_len);
+ read($self->{'fileMST'},$buff,$rec_len);
+
+ print STDERR "## rec_len: $rec_len poc: ",tell($self->{'fileMST'})."\n" if ($self->{debug});
for (my $i = 0 ; $i < $NVF ; $i++) {
# skip zero-sized fields
for (my $i = 0 ; $i < $NVF ; $i++) {
# skip zero-sized fields
@@
-373,6
+376,8
@@
print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");
}
close(fileMST);
}
close(fileMST);
+ $self->{'current_mfn'} = $mfn;
+
print Dumper($self),"\n" if ($self->{debug});
return $self->{'record'};
print Dumper($self),"\n" if ($self->{debug});
return $self->{'record'};
@@
-467,7
+472,7
@@
sub to_hash {
my $mfn = shift || confess "need mfn!";
# init record to include MFN as field 000
my $mfn = shift || confess "need mfn!";
# init record to include MFN as field 000
- my $rec = { '000' =>
$mfn
};
+ my $rec = { '000' =>
[ $mfn ]
};
my $row = $self->fetch($mfn);
my $row = $self->fetch($mfn);