From 43345813f1fec59679cd6dd7dcf519e2740bdb19 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 28 Dec 2004 01:41:45 +0000 Subject: [PATCH] first working version: - add support for repeatable fields (so all hash values becomed arrays, even with single element) - scripts to dump CDS/ISIS database using this module and OpenIsis - to_ascii method which dumps ascii output of record git-svn-id: file:///home/dpavlin/svn/Biblio-Isis/trunk@2 4670fa4d-42ec-0310-ab5b-a66af6943492 --- IsisDB.pm | 62 +++++++++++++++++++++++++++++++++++----- MANIFEST | 3 +- scripts/dump_isis.pl | 17 +++++++++++ scripts/dump_openisis.pl | 23 +++++++++++++++ t/001_load.t | 2 +- 5 files changed, 98 insertions(+), 9 deletions(-) create mode 100755 scripts/dump_isis.pl create mode 100755 scripts/dump_openisis.pl diff --git a/IsisDB.pm b/IsisDB.pm index 444fa0e..26cc11f 100644 --- 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 of debugging output. +=back + +It will also set C<$isis-E{'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,39 @@ 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); + +print STDERR Dumper($rec); + + 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. diff --git a/MANIFEST b/MANIFEST index 27cdc3c..57708fa 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,8 +1,9 @@ MANIFEST LICENSE README -Todo Changes IsisDB.pm t/001_load.t Makefile.PL +scripts/dump_isis.pl +scripts/dump_openisis.pl diff --git a/scripts/dump_isis.pl b/scripts/dump_isis.pl new file mode 100755 index 0000000..5e2942d --- /dev/null +++ b/scripts/dump_isis.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl -w + +use strict; +use blib; + +use IsisDB; +use Data::Dumper; + +my $isis = IsisDB->new ( + isisdb => '/data/isis_data/ps/LIBRI/LIBRI', +); + +for(my $mfn = 1; $mfn <= $isis->{'maxmfn'}; $mfn++) { + print $isis->to_ascii($mfn),"\n"; + +} + diff --git a/scripts/dump_openisis.pl b/scripts/dump_openisis.pl new file mode 100755 index 0000000..32adb0f --- /dev/null +++ b/scripts/dump_openisis.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl -w + +# this utility emulates output of openisis -db "database" +# so you can test if perl can read your isis file + +#use strict; +use OpenIsis; + +my $db = OpenIsis::open( shift @ARGV || '/data/isis_data/ps/LIBRI/LIBRI' ); +my $maxmfn = OpenIsis::maxRowid( $db ) || 1; + +print "rows: $maxmfn\n\n"; + +for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) { + print "0\t$mfn\n"; + my $row = OpenIsis::read( $db, $mfn ); + foreach my $k (sort keys %{$row}) { + next if ($k eq 'mfn'); + print "$k\t",join("\n$k\t",@{$row->{$k}}),"\n"; + } + print "\n"; +} + diff --git a/t/001_load.t b/t/001_load.t index 51a937d..0d1c9a9 100755 --- a/t/001_load.t +++ b/t/001_load.t @@ -9,8 +9,8 @@ BEGIN { use_ok( 'IsisDB' ); } my $object = IsisDB->new ( isisdb => '/data/isis_data/ps/LIBRI/LIBRI', - ); + isa_ok ($object, 'IsisDB'); -- 2.20.1