BEGIN {
use Exporter ();
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
- $VERSION = 0.05;
+ $VERSION = 0.06;
@ISA = qw (Exporter);
#Give a hoot don't pollute, do not export more than needed by default
@EXPORT = qw ();
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) {
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': $!";
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;
- 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;
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
- seek($self->{'fileMST'},$offset4,0);
+ seek($self->{'fileMST'},$blk_off,0);
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) {
-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);
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};
+ ## FIXME this is a bug
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;
read($self->{'fileMST'}, $buff, 6 * $NVF);
- my $fld_len = 0;
+ my $rec_len = 0;
for (my $i = 0 ; $i < $NVF ; $i++) {
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.
#
push @FieldPOS,$POS;
push @FieldLEN,$LEN;
- $fld_len += $LEN;
+ $rec_len += $LEN;
}
# 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
}
close(fileMST);
+ $self->{'current_mfn'} = $mfn;
+
print Dumper($self),"\n" if ($self->{debug});
return $self->{'record'};
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);