minor changes and cleanup, create Changes from Subversion repository log
[Biblio-Isis] / IsisDB.pm
index 444fa0e..b2bd43f 100644 (file)
--- a/IsisDB.pm
+++ b/IsisDB.pm
@@ -68,6 +68,10 @@ Open CDS/ISIS database
        debug => 1,
  );
 
+Options are described below:
+
+=over 5
+
 =item isisdb
 
 Prefix path to CDS/ISIS. It should contain full or relative path to database
@@ -82,6 +86,10 @@ by default.
 
 Dump a C<lot> of debugging output.
 
+=back
+
+It will also set C<$isis-E<gt>{'maxmfn'}> which is maximum MFN stored in database.
+
 =cut
 
 sub new {
@@ -91,7 +99,7 @@ sub new {
 
        $self->{isisdb} = {@_}->{isisdb} || croak "new needs database name as argument!";
 
-       $self->{debug} = {@_}->{debug} || 1;    # XXX remove debug always!
+       $self->{debug} = {@_}->{debug};
 
        # if you want to read .FDT file use read_fdt argument when creating class!
        if ({@_}->{read_fdt} && -e $self->{isisdb}.".FDT") {
@@ -134,6 +142,9 @@ sub new {
        seek(fileMST,4,0);
        $self->{'NXTMFN'}=$self->Read32(\*fileMST) || carp "NXTNFN is zero";
 
+       # save maximum MFN
+       $self->{'maxmfn'} = $self->{'NXTMFN'} - 1;
+
        close(fileMST);
 
        # Get the index information from $db.CNT
@@ -183,11 +194,16 @@ sub new {
        $self ? return $self : return undef;
 }
 
+=head2 GetMFN
+
+Read record with selected MFN
+
+  my $rec = $isis->GetMFN(55);
 
-# Get a record from the MFN
-# Return the number of fields in the record.
-# Return -1 if the record is marked for deletion
-# The record is then extracted with call to GETs
+Returns hash with keys which are field names and values are unpacked values
+for that field.
+
+=cut
 
 sub GetMFN {
        my $self = shift;
@@ -289,10 +305,12 @@ print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");
 
        # Get Variable Fields
 
+       delete $self->{record};
+
        for (my $i = 0 ; $i < $NVF ; $i++) {
                my $rec;
                read(fileMST,$rec,$FieldLEN[$i]);
-               $self->{record}->{$FieldTAG[$i]} = $rec;
+               push @{$self->{record}->{$FieldTAG[$i]}}, $rec;
        }
        close(fileMST);
 
@@ -303,9 +321,37 @@ print ("Error: The MFN:".$mfn." is not found in MST(".$value.")");
 
        print Dumper($self) if ($self->{debug});
 
-       return $NVF;
+       return $self->{'record'};
+}
+
+=head2 to_ascii
+
+Dump ascii output of selected MFN
+
+  print $isis->to_ascii(55);
+
+=cut
+
+sub to_ascii {
+       my $self = shift;
+
+       my $mfn = shift || croak "need MFN";
+
+       my $rec = $self->GetMFN($mfn);
+
+       my $out = "0\t$mfn";
+
+       foreach my $f (sort keys %{$rec}) {
+               $out .= "\n$f\t".join("\n$f\t",@{$self->{record}->{$f}});
+       }
+
+       $out .= "\n";
+
+       return $out;
 }
 
+################# old cruft which is not ported from php to perl
+
 =begin php
 
   # Load the dictionary from the $db.L0x files.