test for existing DBMD file; die
[migration-tools.git] / Equinox-Migration / lib / Equinox / Migration / MapDrivenMARCXMLProc.pm
index ee37e78..d78c528 100644 (file)
@@ -23,6 +23,9 @@ our $VERSION = '1.002';
 my $dstore;
 my $sfmap;
 my @mods = qw( multi bib required );
+my $reccount;
+my $verbose = 0;
+
 
 =head1 SYNOPSIS
 
@@ -48,6 +51,8 @@ and C<marcfile> (the MARC data to be processed).
 sub new {
     my ($class, %args) = @_;
 
+    $verbose = 1 if $args{verbose};
+
     my $self = bless { 
                      }, $class;
 
@@ -57,9 +62,11 @@ sub new {
                                                       mods => \@mods );
 
     # initialize datastore
+    die "Datastore file 'EMMXSSTORAGE.dbmd' already exists. Exiting.\n"
+      if (-e "EMMXSSTORAGE.dbmd");
     $dstore = DBM::Deep->new( file => "EMMXSSTORAGE.dbmd",
                               data_sector_size => 256 );
-    $dstore->{rptr} = 0;            # next record ptr
+    $reccount = 0;            # next record ptr
     $dstore->{tags} = $sfmap->tags; # list of all tags
     $self->{data} = $dstore;
 
@@ -93,11 +100,14 @@ sub parse_record {
 
     # cleanup memory and increment pointer
     $record->purge;
-    $dstore->{rptr}++;
+    $reccount++;
 
     # check for required fields
     check_required();
     push @{ $dstore->{recs} }, $crec;
+
+    print STDERR "$reccount\n"
+      if ($verbose and !($reccount % 1000));
 }
 
 sub process_field {
@@ -163,7 +173,7 @@ sub process_subs {
 
     # if this were a multi field, it would be handled already. make sure its a singleton
     die "Multiple occurances of a non-multi field: $tag$code at rec ",
-      ($dstore->{rptr} + 1),"\n" if (defined $dataf->{uni}{$code});
+      ($reccount + 1),"\n" if (defined $dataf->{uni}{$code});
 
     # everything seems okay
     $dataf->{uni}{$code} = $sub->text;
@@ -183,7 +193,7 @@ sub check_required {
                 $found = 1 if ($tag->{uni}{$code});
             }
 
-            die "Required mapping $tag_id$code not found in rec ",$dstore->{rptr},"\n"
+            die "Required mapping $tag_id$code not found in rec ",$reccount,"\n"
               unless ($found);
         }
     }
@@ -196,7 +206,7 @@ Returns current record number (starting from zero)
 
 =cut
 
-sub recno { my ($self) = @_; return $self->{data}{rptr} }
+sub recno { my ($self) = @_; return $self->{data}{rcnt} }
 
 =head2 name