/[Biblio-Isis]/trunk/lib/Biblio/Isis.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Biblio/Isis.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 19 by dpavlin, Thu Dec 30 23:16:20 2004 UTC revision 27 by dpavlin, Sat Jan 1 22:29:35 2005 UTC
# Line 9  use Data::Dumper; Line 9  use Data::Dumper;
9  BEGIN {  BEGIN {
10          use Exporter ();          use Exporter ();
11          use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);          use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
12          $VERSION     = 0.07;          $VERSION     = 0.08;
13          @ISA         = qw (Exporter);          @ISA         = qw (Exporter);
14          #Give a hoot don't pollute, do not export more than needed by default          #Give a hoot don't pollute, do not export more than needed by default
15          @EXPORT      = qw ();          @EXPORT      = qw ();
# Line 37  IsisDB - Read CDS/ISIS, WinISIS and Isis Line 37  IsisDB - Read CDS/ISIS, WinISIS and Isis
37  =head1 DESCRIPTION  =head1 DESCRIPTION
38    
39  This module will read ISIS databases created by DOS CDS/ISIS, WinIsis or  This module will read ISIS databases created by DOS CDS/ISIS, WinIsis or
40  IsisMarc. It can be used as perl-only alternative to OpenIsis module.  IsisMarc. It can be used as perl-only alternative to OpenIsis module which
41    seems to depriciate it's old C<XS> bindings for perl.
42    
43  It can create hash values from data in ISIS database (using C<to_hash>),  It can create hash values from data in ISIS database (using C<to_hash>),
44  ASCII dump (using C<to_ascii>) or just hash with field names and packed  ASCII dump (using C<to_ascii>) or just hash with field names and packed
# Line 50  fields which are zero sized will be fill Line 51  fields which are zero sized will be fill
51  It also has support for identifiers (only if ISIS database is created by  It also has support for identifiers (only if ISIS database is created by
52  IsisMarc), see C<to_hash>.  IsisMarc), see C<to_hash>.
53    
54  This will module will always be slower than OpenIsis module which use C  This module will always be slower than OpenIsis module which use C
55  library. However, since it's written in perl, it's platform independent (so  library. However, since it's written in perl, it's platform independent (so
56  you don't need C compiler), and can be easily modified. I hope that it  you don't need C compiler), and can be easily modified. I hope that it
57  creates data structures which are easier to use than ones created by  creates data structures which are easier to use than ones created by
# Line 214  sub new { Line 215  sub new {
215    
216  =head2 read_cnt  =head2 read_cnt
217    
218  This function is not really used by module, but can be useful to find info  Read content of C<.CNT> file and return hash containing it.
 about your index (if debugging it for example).  
219    
220    print Dumper($isis->read_cnt);    print Dumper($isis->read_cnt);
221    
222    This function is not used by module (C<.CNT> files are not required for this
223    module to work), but it can be useful to examine your index (while debugging
224    for example).
225    
226  =cut  =cut
227    
228  sub read_cnt  {  sub read_cnt  {
# Line 296  sub fetch { Line 300  sub fetch {
300    
301          # is mfn allready in memory?          # is mfn allready in memory?
302          my $old_mfn = $self->{'current_mfn'} || -1;          my $old_mfn = $self->{'current_mfn'} || -1;
303          return if ($mfn == $old_mfn);          return $self->{record} if ($mfn == $old_mfn);
304    
305          print STDERR "## fetch: $mfn\n" if ($self->{debug});          print STDERR "## fetch: $mfn\n" if ($self->{debug});
306    
# Line 308  sub fetch { Line 312  sub fetch {
312    
313          my $buff;          my $buff;
314    
315            # delete old record
316            delete $self->{record};
317    
318          # read XRFMFB abd XRFMFP          # read XRFMFB abd XRFMFP
319          read($self->{'fileXRF'}, $buff, 4);          read($self->{'fileXRF'}, $buff, 4);
320          my $pointer=unpack("l",$buff) || carp "pointer is null";          my $pointer=unpack("l",$buff) || carp "pointer is null";
321    
322            # check for logically deleted record
323            if ($pointer < 0) {
324                    print STDERR "## record $mfn is logically deleted\n" if ($self->{debug});
325                    $self->{deleted} = $mfn;
326    
327                    return unless $self->{include_deleted};
328    
329                    $pointer = abs($pointer);
330            }
331    
332          my $XRFMFB = int($pointer/2048);          my $XRFMFB = int($pointer/2048);
333          my $XRFMFP = $pointer - ($XRFMFB*2048);          my $XRFMFP = $pointer - ($XRFMFB*2048);
334    
   
335          # (XRFMFB - 1) * 512 + XRFMFP          # (XRFMFB - 1) * 512 + XRFMFP
336          # why do i have to do XRFMFP % 1024 ?          # why do i have to do XRFMFP % 1024 ?
337    
338          my $blk_off = (($XRFMFB - 1) * 512) + ($XRFMFP % 1024);          my $blk_off = (($XRFMFB - 1) * 512) + ($XRFMFP % 512);
339    
340          print STDERR "## pointer: $pointer XRFMFB: $XRFMFB XRFMFP: $XRFMFP offset: $blk_off\n" if ($self->{'debug'});          print STDERR "## pointer: $pointer XRFMFB: $XRFMFB XRFMFP: $XRFMFP offset: $blk_off\n" if ($self->{'debug'});
341    
# Line 333  sub fetch { Line 349  sub fetch {
349          print STDERR "## offset for rowid $value is $blk_off (blk $XRFMFB off $XRFMFP)\n" if ($self->{debug});          print STDERR "## offset for rowid $value is $blk_off (blk $XRFMFB off $XRFMFP)\n" if ($self->{debug});
350    
351          if ($value!=$mfn) {          if ($value!=$mfn) {
352                  carp "Error: MFN ".$mfn." not found in MST(".$value.")";                      if ($value == 0) {
353                  #return;                # XXX deleted record?                          print STDERR "## record $mfn is physically deleted\n" if ($self->{debug});
354          }                          $self->{deleted} = $mfn;
355                            return;
356                    }
357    
358  #       $MFRL=$self->Read16($fileMST);                  carp "Error: MFN ".$mfn." not found in MST file, found $value";    
359  #       $MFBWB=$self->Read32($fileMST);                  return;
360  #       $MFBWP=$self->Read16($fileMST);          }
 #       $BASE=$self->Read16($fileMST);  
 #       $NVF=$self->Read16($fileMST);  
 #       $STATUS=$self->Read16($fileMST);  
361    
362          read($self->{'fileMST'}, $buff, 14);          read($self->{'fileMST'}, $buff, 14);
363    
# Line 350  sub fetch { Line 365  sub fetch {
365    
366          print STDERR "## 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});
367    
368          # delete old record          warn "MFRL $MFRL is not even number" unless ($MFRL % 2 == 0);
         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;  
         }  
369    
370          warn "BASE is not 18+6*NVF" unless ($BASE == 18 + 6 * $NVF);          warn "BASE is not 18+6*NVF" unless ($BASE == 18 + 6 * $NVF);
371    
# Line 373  sub fetch { Line 381  sub fetch {
381    
382          for (my $i = 0 ; $i < $NVF ; $i++) {          for (my $i = 0 ; $i < $NVF ; $i++) {
383    
 #               $TAG=$self->Read16($fileMST);  
 #               $POS=$self->Read16($fileMST);  
 #               $LEN=$self->Read16($fileMST);  
   
384                  my ($TAG,$POS,$LEN) = unpack("sss", substr($buff,$i * 6, 6));                  my ($TAG,$POS,$LEN) = unpack("sss", substr($buff,$i * 6, 6));
385    
386                  print STDERR "## TAG: $TAG POS: $POS LEN: $LEN\n" if ($self->{debug});                  print STDERR "## TAG: $TAG POS: $POS LEN: $LEN\n" if ($self->{debug});
# Line 413  sub fetch { Line 417  sub fetch {
417    
418          $self->{'current_mfn'} = $mfn;          $self->{'current_mfn'} = $mfn;
419    
420          print Dumper($self),"\n" if ($self->{debug});          print STDERR Dumper($self),"\n" if ($self->{debug});
421    
422          return $self->{'record'};          return $self->{'record'};
423  }  }
424    
425  =head2 to_ascii  =head2 to_ascii
426    
427  Dump ASCII output of record with specified MFN  Returns ASCII output of record with specified MFN
428    
429    print $isis->to_ascii(42);    print $isis->to_ascii(42);
430    
431  It outputs something like this:  This outputs something like this:
432    
433    210   ^aNew York^cNew York University press^dcop. 1988    210   ^aNew York^cNew York University press^dcop. 1988
434    990   2140    990   2140
# Line 461  Read record with specified MFN and conve Line 465  Read record with specified MFN and conve
465    
466    my $hash = $isis->to_hash($mfn);    my $hash = $isis->to_hash($mfn);
467    
468  It has ability to convert characters (using C<hash_filter> from ISIS  It has ability to convert characters (using C<hash_filter>) from ISIS
469  database before creating structures enabling character re-mapping or quick  database before creating structures enabling character re-mapping or quick
470  fix-up of data.  fix-up of data.
471    
# Line 520  sub to_hash { Line 524  sub to_hash {
524                          my $val;                          my $val;
525    
526                          # has identifiers?                          # has identifiers?
527                          ($val->{'i1'},$val->{'i2'}) = ($1,$2) if ($l =~ s/^([01 #])([01 #])//);                          ($val->{'i1'},$val->{'i2'}) = ($1,$2) if ($l =~ s/^([01 #])([01 #])\^/\^/);
528    
529                          # has subfields?                          # has subfields?
530                          if ($l =~ m/\^/) {                          if ($l =~ m/\^/) {
# Line 557  sub tag_name { Line 561  sub tag_name {
561    
562  =head1 BUGS  =head1 BUGS
563    
564  This module has been very lightly tested. Use with caution and report bugs.  Some parts of CDS/ISIS documentation are not detailed enough to exmplain
565    some variations in input databases which has been tested with this module.
566    When I was in doubt, I assumed that OpenIsis's implementation was right
567    (except for obvious bugs).
568    
569    However, every effort has been made to test this module with as much
570    databases (and programs that create them) as possible.
571    
572    I would be very greatful for success or failure reports about usage of this
573    module with databases from programs other than WinIsis and IsisMarc. I had
574    tested this against ouput of one C<isis.dll>-based application, but I don't
575    know any details about it's version.
576    
577  =head1 AUTHOR  =head1 AUTHOR
578    

Legend:
Removed from v.19  
changed lines
  Added in v.27

  ViewVC Help
Powered by ViewVC 1.1.26