my $usage = 0;
my $debug = 0;
+my $quiet = 0;
my $result = GetOptions(
"database=s" => \$database,
"user=s" => \$user,
"password=s" => \$passwd,
"debug!" => \$debug,
+ "verbose!" => \$debug,
+ "quiet!" => \$quiet,
"help!" => \$usage,
);
while (!$skip && $directory =~ s/(\d{3})(\d{4})(\d{5})//) {
my ($tag,$len,$addr) = ($1,$2,$3);
- print STDERR "tag/len/addr: $tag $len $addr\n" if ($debug);
-
sub check_field($) {
my $f = shift;
my $del = substr($f,0,1);
}
if (($addr+$len) > length($fields)) {
- print STDERR "WARNING: error in dictionary on record $rec_nr skipping...\n" if ($debug);
+ print STDERR "WARNING: error in dictionary on record $rec_nr skipping...\n" if (! $quiet);
$skip = 1;
next;
}
# take field
my $f = substr($fields,$addr,$len);
- print STDERR "data $tag [$len] $addr: '$f'\n" if ($debug);
+ print STDERR "tag/len/addr $tag [$len] $addr: '$f'\n" if ($debug);
my $del = substr($fields,$addr+$len,1);
# check field delimiters...
if ($del ne chr(30)) {
- print STDERR "WARNING: skipping record $rec_nr, can't find delimiters got: '$del'\n" if ($debug);
+ print STDERR "WARNING: skipping record $rec_nr, can't find delimiters got: '$del'\n" if (! $quiet);
$skip = 1;
next;
}
check_field($f);
-
+
+ if (length($f) < 2) {
+ print STDERR "WARNING: skipping field $tag from record $rec_nr because it's too short!\n" if (! $quiet);
+ next;
+ }
+
+
if ($tag =~ m/^00/) {
# fields 001-008 doesn't have indicators
- $new_dictionary .= sprintf("%03d%04d%05d",$tag,$len,$addr);
+ $new_dictionary .= sprintf("%03d%04d%05d",$tag,$len,length($new_fields || ''));
$new_fields.=$f;
} else {
- $new_dictionary .= sprintf("%03d%04d%05d",$tag,($len+2),($addr+$o));
+ $new_dictionary .= sprintf("%03d%04d%05d",$tag,($len+2),length($new_fields || ''));
$new_fields.=chr(30)." ".substr($f,1);
$o += 2;
}
}
if (! $skip) {
- my $new_leader = sprintf($leader_fmt,24+length($new_dictionary.$new_fields)+2,$base_addr);
+ my $new_leader = sprintf($leader_fmt,24+length($new_dictionary.$new_fields)+2,length($new_dictionary)+25);
my $new_marc = $new_leader . $new_dictionary . $new_fields . chr(30);
$new_marc .= chr(29); # end of record
- print STDERR "original and new marc: [$rec_nr]\n$marc\n$new_marc\n\n" if ($debug);
+ print STDERR "original and new marc: [$rec_nr/$count]\n$marc\n$new_marc\n\n" if ($debug);
print "$new_marc";
$count++;
}