--- trunk/IsisDB.pm 2004/12/29 15:10:34 7 +++ trunk/IsisDB.pm 2004/12/29 16:04:07 10 @@ -7,7 +7,7 @@ BEGIN { use Exporter (); use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); - $VERSION = 0.02; + $VERSION = 0.03; @ISA = qw (Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw (); @@ -66,6 +66,7 @@ isisdb => './cds/cds', read_fdt => 1, debug => 1, + include_deleted => 1, ); Options are described below: @@ -86,6 +87,10 @@ Dump a C of debugging output. +=item include_deleted + +Don't skip logically deleted records. + =back It will also set C<$isis-E{'maxmfn'}> which is maximum MFN stored in database. @@ -97,9 +102,11 @@ my $self = {}; bless($self, $class); - $self->{isisdb} = {@_}->{isisdb} || croak "new needs database name as argument!"; + croak "new needs database name (isisdb) as argument!" unless ({@_}->{isisdb}); - $self->{debug} = {@_}->{debug}; + foreach my $v (qw{isisdb debug include_deleted}) { + $self->{$v} = {@_}->{$v}; + } # if you want to read .FDT file use read_fdt argument when creating class! if ({@_}->{read_fdt} && -e $self->{isisdb}.".FDT") { @@ -173,6 +180,8 @@ my $buff = shift || return; my @arr = unpack("ssssssllls", $buff); + print "unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'}); + my $IDTYPE = shift @arr; foreach (@flds) { $self->{$IDTYPE}->{$_} = abs(shift @arr); @@ -270,20 +279,31 @@ print "MFRL: $MFRL MFBWB: $MFBWB MFBWP: $MFBWP BASE: $BASE NVF: $NVF STATUS: $STATUS\n" if ($self->{debug}); + # delete old record + delete $self->{record}; + + if (! $self->{'include_deleted'} && $MFRL < 0) { + print "## logically deleted record $mfn, skipping...\n" if ($self->{debug}); + return; + } + # Get Directory Format my @FieldPOS; my @FieldLEN; my @FieldTAG; + read($self->{'fileMST'}, $buff, 6 * $NVF); + + my $fld_len = 0; + for (my $i = 0 ; $i < $NVF ; $i++) { # $TAG=$self->Read16($fileMST); # $POS=$self->Read16($fileMST); # $LEN=$self->Read16($fileMST); - read($self->{'fileMST'}, $buff, 6); - my ($TAG,$POS,$LEN) = unpack("sss", $buff); + my ($TAG,$POS,$LEN) = unpack("sss", substr($buff,$i * 6, 6)); print "TAG: $TAG POS: $POS LEN: $LEN\n" if ($self->{debug}); @@ -300,23 +320,21 @@ push @FieldTAG,$TAG; push @FieldPOS,$POS; push @FieldLEN,$LEN; + + $fld_len += $LEN; } # Get Variable Fields - delete $self->{record}; + read($self->{'fileMST'},$buff,$fld_len); for (my $i = 0 ; $i < $NVF ; $i++) { - my $rec; - read($self->{'fileMST'},$rec,$FieldLEN[$i]); - push @{$self->{record}->{$FieldTAG[$i]}}, $rec; - } - close(fileMST); + # skip zero-sized fields + next if ($FieldLEN[$i] == 0); - # The record is marked for deletion - if ($STATUS==1) { - return -1; + push @{$self->{record}->{$FieldTAG[$i]}}, substr($buff,$FieldPOS[$i],$FieldLEN[$i]); } + close(fileMST); print Dumper($self) if ($self->{debug});