25 |
|
|
26 |
my $usage = 0; |
my $usage = 0; |
27 |
my $debug = 0; |
my $debug = 0; |
28 |
|
my $quiet = 0; |
29 |
|
|
30 |
my $result = GetOptions( |
my $result = GetOptions( |
31 |
"database=s" => \$database, |
"database=s" => \$database, |
33 |
"user=s" => \$user, |
"user=s" => \$user, |
34 |
"password=s" => \$passwd, |
"password=s" => \$passwd, |
35 |
"debug!" => \$debug, |
"debug!" => \$debug, |
36 |
|
"verbose!" => \$debug, |
37 |
|
"quiet!" => \$quiet, |
38 |
"help!" => \$usage, |
"help!" => \$usage, |
39 |
); |
); |
40 |
|
|
113 |
while (!$skip && $directory =~ s/(\d{3})(\d{4})(\d{5})//) { |
while (!$skip && $directory =~ s/(\d{3})(\d{4})(\d{5})//) { |
114 |
my ($tag,$len,$addr) = ($1,$2,$3); |
my ($tag,$len,$addr) = ($1,$2,$3); |
115 |
|
|
|
print STDERR "tag/len/addr: $tag $len $addr\n" if ($debug); |
|
|
|
|
116 |
sub check_field($) { |
sub check_field($) { |
117 |
my $f = shift; |
my $f = shift; |
118 |
my $del = substr($f,0,1); |
my $del = substr($f,0,1); |
121 |
} |
} |
122 |
|
|
123 |
if (($addr+$len) > length($fields)) { |
if (($addr+$len) > length($fields)) { |
124 |
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); |
125 |
$skip = 1; |
$skip = 1; |
126 |
next; |
next; |
127 |
} |
} |
128 |
|
|
129 |
# take field |
# take field |
130 |
my $f = substr($fields,$addr,$len); |
my $f = substr($fields,$addr,$len); |
131 |
print STDERR "data $tag [$len] $addr: '$f'\n" if ($debug); |
print STDERR "tag/len/addr $tag [$len] $addr: '$f'\n" if ($debug); |
132 |
|
|
133 |
my $del = substr($fields,$addr+$len,1); |
my $del = substr($fields,$addr+$len,1); |
134 |
|
|
135 |
# check field delimiters... |
# check field delimiters... |
136 |
if ($del ne chr(30)) { |
if ($del ne chr(30)) { |
137 |
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); |
138 |
$skip = 1; |
$skip = 1; |
139 |
next; |
next; |
140 |
} |
} |
141 |
|
|
142 |
check_field($f); |
check_field($f); |
143 |
|
|
144 |
|
if (length($f) < 2) { |
145 |
|
print STDERR "WARNING: skipping field $tag from record $rec_nr because it's too short!\n" if (! $quiet); |
146 |
|
next; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
if ($tag =~ m/^00/) { |
if ($tag =~ m/^00/) { |
151 |
# fields 001-008 doesn't have indicators |
# fields 001-008 doesn't have indicators |
152 |
$new_dictionary .= sprintf("%03d%04d%05d",$tag,$len,$addr); |
$new_dictionary .= sprintf("%03d%04d%05d",$tag,$len,length($new_fields || '')); |
153 |
$new_fields.=$f; |
$new_fields.=$f; |
154 |
} else { |
} else { |
155 |
$new_dictionary .= sprintf("%03d%04d%05d",$tag,($len+2),($addr+$o)); |
$new_dictionary .= sprintf("%03d%04d%05d",$tag,($len+2),length($new_fields || '')); |
156 |
$new_fields.=chr(30)." ".substr($f,1); |
$new_fields.=chr(30)." ".substr($f,1); |
157 |
$o += 2; |
$o += 2; |
158 |
} |
} |
159 |
} |
} |
160 |
|
|
161 |
if (! $skip) { |
if (! $skip) { |
162 |
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); |
163 |
my $new_marc = $new_leader . $new_dictionary . $new_fields . chr(30); |
my $new_marc = $new_leader . $new_dictionary . $new_fields . chr(30); |
164 |
$new_marc .= chr(29); # end of record |
$new_marc .= chr(29); # end of record |
165 |
|
|
166 |
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); |
167 |
print "$new_marc"; |
print "$new_marc"; |
168 |
$count++; |
$count++; |
169 |
} |
} |