documentation and dependency improvements, inline Read32 to get some more
[Biblio-Isis] / IsisDB.pm
index ac0e051..b7b4ba1 100644 (file)
--- a/IsisDB.pm
+++ b/IsisDB.pm
@@ -22,16 +22,29 @@ IsisDB - Read CDS/ISIS database
 
 =head1 SYNOPSIS
 
-  use IsisDB
+  use IsisDB;
+
   my $isis = new IsisDB(
        isisdb => './cds/cds',
   );
 
+  for(my $mfn = 1; $mfn <= $isis->{'maxmfn'}; $mfn++) {
+       print $isis->to_ascii($mfn),"\n";
+  }
+
 =head1 DESCRIPTION
 
 This module will read CDS/ISIS databases and create hash values out of it.
 It can be used as perl-only alternative to OpenIsis module.
 
+This will module will always be slower that OpenIsis module which use C
+library. However, since it's written in perl, it's platform independent (so
+you don't need C compiler), and can be easily modified.
+
+Unique feature of this module is ability to C<include_deleted> records.
+It will also skip zero sized fields (OpenIsis has a bug in XS bindings, so
+fields which are zero sized will be filled with random junk from memory).
+
 =head1 METHODS
 
 =cut
@@ -50,14 +63,6 @@ It can be used as perl-only alternative to OpenIsis module.
 # some binary reads
 #
 
-sub Read32 {
-       my $self = shift;
-
-       my $f = shift || die "Read32 needs file handle";
-       read($$f,$b,4) || die "can't read 4 bytes from $$f from position ".tell($f);
-       return unpack("l",$b);
-}
-
 =head2 new
 
 Open CDS/ISIS database
@@ -89,7 +94,7 @@ Dump a C<lot> of debugging output.
 
 =item include_deleted
 
-Don't skip logically deleted records.
+Don't skip logically deleted records in ISIS.
 
 =back
 
@@ -147,7 +152,11 @@ sub new {
        # NXTMFP        offset to next available position in last block
        # MFTYPE        always 0 for user db file (1 for system)
        seek(fileMST,4,0);
-       $self->{'NXTMFN'}=$self->Read32(\*fileMST) || carp "NXTNFN is zero";
+
+       my $buff;
+
+       read(fileMST, $buff, 4);
+       $self->{'NXTMFN'}=unpack("l",$buff) || carp "NXTNFN is zero";
 
        # save maximum MFN
        $self->{'maxmfn'} = $self->{'NXTMFN'} - 1;
@@ -188,7 +197,6 @@ sub new {
                }
        }
 
-       my $buff;
        read(fileCNT, $buff, 26);
        $self->unpack_cnt($buff);
 
@@ -232,8 +240,11 @@ sub fetch {
        print "seeking to $mfnpos in file '$self->{isisdb}.XRF'\n" if ($self->{debug});
        seek($self->{'fileXRF'},$mfnpos,0);
 
+       my $buff;
+
        # read XRFMFB abd XRFMFP
-       my $pointer=$self->Read32(\*{$self->{'fileXRF'}});
+       read($self->{'fileXRF'}, $buff, 4);
+       my $pointer=unpack("l",$buff) || carp "pointer is null";
 
        my $XRFMFB = int($pointer/2048);
        my $XRFMFP = $pointer - ($XRFMFB*2048);
@@ -258,7 +269,8 @@ sub fetch {
 
        seek($self->{'fileMST'},$offset4,0);
 
-       my $value=$self->Read32(\*{$self->{'fileMST'}});
+       read($self->{'fileMST'}, $buff, 4);
+       my $value=unpack("l",$buff);
 
        if ($value!=$mfn) {
 print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");    
@@ -272,7 +284,6 @@ print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");
 #      $NVF=$self->Read16($fileMST);
 #      $STATUS=$self->Read16($fileMST);
 
-       my $buff;
        read($self->{'fileMST'}, $buff, 14);
 
        my ($MFRL,$MFBWB,$MFBWP,$BASE,$NVF,$STATUS) = unpack("slssss", $buff);