wrapping some calls in eval to safeguard bad records crashing load
[migration-tools.git] / marc_cleanup
1 #!/usr/bin/perl
2
3 # Copyright 2009-2012, Equinox Software, Inc.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19 require 5.10.0;
20
21 use strict;
22 use warnings;
23
24 use Getopt::Long;
25 use Term::ReadLine;
26 use Equinox::Migration::SimpleTagList;
27
28 my $term = new Term::ReadLine 'yaz-cleanup';
29 my $OUT = $term->OUT || \*STDOUT;
30 binmode STDOUT, ":utf8";
31 binmode $OUT, ":utf8";
32
33 $| = 1;
34
35 # initialization and setup
36 my $c = {};
37 initialize($c);
38
39 # set up files, since everything appears to be in order
40 open MARC, '<:utf8', $c->{marcfile}
41   or die "Can't open input file $!\n";
42 open my $NUMARC, '>:utf8', $c->{output}
43   or die "Can't open output file $!\n";
44 open my $OLD2NEW, '>', 'old2new.map'
45   if ($c->{'renumber-from'} and $c->{'original-tag'});
46 my $EXMARC = 'EX';
47 print $NUMARC "<collection xmlns=\"http://www.loc.gov/MARC21/slim\">\n";
48
49 $c->{totalrecs} = `grep -c '<record' $c->{marcfile}`;
50 chomp $c->{totalrecs};
51 $c->{percent}   = 0;
52
53 my @record;  # current record storage
54 my %recmeta; # metadata about current record
55 my $ptr = 0; # record index pointer
56
57 # this is the dispatch table which drives command selection in
58 # edit(), below
59 my %commands = ( c => \&print_fullcontext,
60                  n => \&next_line,
61                  p => \&prev_line,
62                  '<' => \&widen_window,
63                  '>' => \&narrow_window,
64                  d => \&display_lines,
65                  o => \&insert_original,
66                  k => \&kill_line,
67                  y => \&yank_line,
68                  f => \&flip_line,
69                  m => \&merge_lines,
70                  s => \&substitute,
71                  t => \&commit_edit,
72                  x => \&dump_record,
73                  q => \&quit,
74                  '?' => \&help,
75                  h   => \&help,
76                  help => \&help,
77                );
78
79 my @spinner = qw(- \\ | /);
80 my $sidx = 0;
81
82 while ( buildrecord() ) {
83     unless ($c->{ricount} % 50) {
84         $c->{percent} = int(($c->{ricount} / $c->{totalrecs}) * 100);
85         print "\rWorking (",$c->{percent},"%) ", $spinner[$sidx];
86         $sidx = ($sidx == $#spinner) ? 0 : $sidx + 1;
87     }
88
89     my $rc = do_automated_cleanups();
90     next if $rc;
91
92     $ptr = 0;
93     until ($ptr == $#record) {
94         # get datafield/tag data if we have it
95         $rc = stow_record_data() if ($c->{'renumber-from'} and $c->{'original-tag'});
96         next if $rc;
97
98         # naked ampersands
99         if ($record[$ptr] =~ /&/ && $record[$ptr] !~ /&\w+?;/)
100           { edit("Naked ampersand"); $ptr= 0; next }
101
102         if ($record[$ptr] =~ /<datafield tag="(.+?)"/) {
103             my $match = $1;
104             # tags must be numeric
105             if ($match =~ /\D/) {
106                 edit("Non-numerics in tag") unless $c->{autoscrub};
107                 next;
108             }
109         }
110
111         # subfields can't be non-alphanumeric
112         if ($record[$ptr] =~ /<subfield code="(.*?)"/) {
113             if ($1 =~ /\P{IsAlnum}/ or $1 eq '') {
114                 edit("Junk in subfield code/Null subfield code ($1)");
115                 next;
116             }
117         }
118         # subfields can't be larger than 1 char (technically you could make the MARC format accomodate that:)
119         if ($record[$ptr] =~ /<subfield code="(\w{2,})"/) {
120             edit("Subfield code larger than 1 char");
121             next;
122         }
123
124         $ptr++;
125     }
126     write_record($NUMARC);
127 }
128 print $NUMARC "</collection>\n";
129 print $OUT "\nDone. ",$c->{ricount}," in; ",$c->{rocount}," dumped          \n";
130
131
132 #-----------------------------------------------------------------------------------
133 # cleanup routines
134 #-----------------------------------------------------------------------------------
135
136 sub do_automated_cleanups {
137     $ptr = 0;
138     until ($ptr == $#record) {
139
140         # catch empty datafield elements
141         if ($record[$ptr] =~ m/<datafield tag="..."/) {
142             if ($record[$ptr + 1] =~ m|</datafield>|) {
143                 my @a = @record[0 .. $ptr - 1];
144                 my @b = @record[$ptr + 2 .. $#record];
145                 @record = (@a, @b);
146                 @a = undef; @b = undef;
147                 message("Empty datafield scrubbed");
148                 $ptr = 0;
149                 next;
150             }
151         }
152         # and quasi-empty subfields
153         if ($record[$ptr] =~ m|<subfield code="(.*?)">(.*?)</sub|) {
154             my $code = $1; my $content = $2;
155             if ($code =~ /\W/ and ($content =~ /\s+/ or $content eq '')) {
156                 my @a = @record[0 .. $ptr - 1];
157                 my @b = @record[$ptr + 1 .. $#record];
158                 @record = (@a, @b);
159                 @a = undef; @b = undef;
160                 message("Empty subfield scrubbed");
161                 $ptr = 0;
162                 next;
163             }
164         }
165         $ptr++;
166     }
167
168     # single-line fixes
169     for $ptr (0 .. $#record) {
170         # pad short leaders
171         if ($record[$ptr] =~ m|<leader>(.+?)</leader>|) {
172             my $leader = $1;
173             if (length $leader < 24) {
174                 $leader .= ' ' x (20 - length($leader));
175                 $leader .= "4500";
176                 $record[$ptr] = "<leader>$leader</leader>\n";
177                 message("Short leader padded");
178             }
179         }
180         if ($c->{'force-utf8'}) {
181             if ($record[$ptr] =~ m|<leader>(.........).(.+)</leader>|) {
182                 $record[$ptr] = "<leader>$1a$2</leader>\n";
183             }
184         }
185         if ($record[$ptr] =~ m|<controlfield tag="008">(.+?)</control|) {
186             #pad short 008
187             my $content = $1;
188             if (length $content < 40) {
189                 $content .= ' ' x (40 - length($content));
190                 $record[$ptr] = "<controlfield tag=\"008\">$content</controlfield>\n";
191                 message("Short 008 padded");
192             }
193         }
194
195         # clean misplaced dollarsigns
196         if ($record[$ptr] =~ m|<subfield code="\$">c?\d+\.\d{2}|) {
197             $record[$ptr] =~ s|"\$">c?(\d+\.\d{2})|"c">\$$1|;
198             message("Dollar sign corrected");
199         }
200
201         # excessive trailing whitespace in subfield contents
202         if ($record[$ptr] =~ m|\s{10,}</subfield>|) {
203             $record[$ptr] =~ s|\s{10,}</subfield>|</subfield>|;
204             message("Trailing whitespace trimmed from subfield contents");
205         }
206
207         # automatable subfield maladies
208         if ($record[$ptr] =~ /code=" ">c/) {
209             message('Fixing probable subfield c, scenario 1');
210             $record[$ptr] =~ s/code=" ">c/code="c">/;
211         }
212         if ($record[$ptr] =~ /code=" ">\$/) {
213             message('Fixing probable subfield c, scenario 2');
214             $record[$ptr] =~ s/code=" ">\$/code="c">\$/;
215         }
216
217         if ($c->{'fix-subfield'}) {
218             if ($record[$ptr] =~ /code="&amp;">/) {
219                 message('Fixing &amp; for subfield code');
220                 $record[$ptr] =~ s/code="&amp;">/code="$c->{'fix-subfield'}">/;
221             }
222             if ($record[$ptr] =~ /code="(.*?\P{IsAlnum}.*?)">/) {
223                 message("Fixing non-alphanumeric subfield code: $1 -> " . $c->{'fix-subfield'});
224                 $record[$ptr] =~ s/code=".*?\P{IsAlnum}.*?">/code="$c->{'fix-subfield'}">/;
225             }
226             if ($record[$ptr] =~ /code="">/) {
227                 message('Fixing null subfield code');
228                 $record[$ptr] =~ s/code="">/code="$c->{'fix-subfield'}">/;
229             }
230         }
231     }
232     return 0;
233 }
234
235 sub stow_record_data {
236     # get tag data if we're looking at it
237     my $tag = 0;
238     if ($record[$ptr] =~ m/<(?:control|data)field tag="(.{3})"/) {
239         $recmeta{tag} = $1;
240         $tag = $recmeta{tag};
241         $record[$ptr] =~ m/ind1="(.)"/;
242         $recmeta{ind1} = $1 || '';
243         $record[$ptr] =~ m/ind2="(.)"/;
244         $recmeta{ind2} = $1 || '';
245
246         unless ($tag) {
247             message("Autokill record: no detectable tag");
248             dump_record("No detectable tag") ;
249             return 1;
250         }
251
252         # and since we are looking at a tag, see if it's the original id
253         if ($tag == $c->{'original-tag'}) {
254             my $oid = 0;
255             if ($tag < 10) {
256                 # controlfield
257                 if ($record[$ptr] =~ m|<controlfield tag="$tag">(.+?)</controlfield>|)
258                       { $oid = $1; print $OLD2NEW "$oid\t", $recmeta{nid}, "\n" }
259             } elsif ($tag >= 10 and $c->{'original-subfield'}) {
260                 # datafield
261                 my $line = $record[$ptr]; my $lptr = $ptr;
262                 my $osub = $c->{'original-subfield'};
263                 # skim to end of this tag
264                 until ($line =~ m|</datafield>|) {
265                     if ($line =~ /<subfield code="$osub">(.+?)</)
266                       { $oid = $1; print $OLD2NEW "$oid\t", $recmeta{nid}, "\n" }
267                     $lptr++;
268                     $line = $record[$lptr];
269                 }
270             } else {
271                 return 0;
272             }
273
274             # didn't find the old id!
275             unless ($oid) {
276                 message("Autokill record: no oldid when old2new mapping requested");
277                 dump_record("No old id found");
278                 return 1;
279             }
280
281             # got it; write to old->new map file
282             if ($c->{'renumber-from'} and $c->{'original-subfield'}) {
283             }
284
285         }
286     }
287     return 0;
288 }
289
290 #-----------------------------------------------------------------------------------
291 # driver routines
292 #-----------------------------------------------------------------------------------
293
294 =head2 edit
295
296 Handles the Term::ReadLine loop
297
298 =cut
299
300 sub edit {
301     my ($msg) = @_;
302
303     return if $c->{trash}->has( $recmeta{tag} );
304     if ( $c->{fullauto} )
305     { dump_record($msg); return }
306
307     $c->{editmsg} = $msg;
308     print_fullcontext();
309
310     # stow original problem line
311     $recmeta{origline} = $record[$ptr];
312
313     while (1) {
314         my $line = $term->readline('marc-cleanup>');
315         my @chunks = split /\s+/, $line;
316
317         # lines with single-character first chunks are commands.
318         # make sure they exist.
319         if (length $chunks[0] == 1) {
320             unless (defined $commands{$chunks[0]}) {
321                 print $OUT "No such command '", $chunks[0], "'\n";
322                 next;
323             }
324         }
325
326         if (defined $commands{$chunks[0]}) {
327             my $term = $commands{$chunks[0]}->(@chunks[1..$#chunks]);
328             last if $term;
329         } else {
330             $recmeta{prevline} = $record[$ptr];
331             $record[$ptr] = "$line\n";
332             print_context();
333         }
334     }
335     # set pointer to top on the way out
336     $ptr = 0;
337 }
338
339 =head2 buildrecord
340
341 Constructs record arrays from the incoming MARC file and returns them
342 to the driver loop.
343
344 =cut
345
346 sub buildrecord {
347     my $l = '';
348     my $istrash = 0;
349     my $trash = $c->{trash};
350
351     $l = <MARC> while (defined $l and $l !~ /<record/);
352     return $l unless defined $l;
353     $c->{ricount}++;
354
355     for (keys %recmeta) { $recmeta{$_} = undef }
356     for (0 .. @record)  { delete $record[$_] }
357
358     my $i = 0;
359     until ($l =~ m|</record>|) {
360         # clean up tags with spaces in them
361         $l =~ s/tag="  /tag="00/g;
362         $l =~ s/tag=" /tag="0/g;
363         $l =~ s/tag="-/tag="0/g;
364         $l =~ s/tag="(\d\d) /tag="0$1/g;
365
366         # excise unwanted tags
367         if ($istrash) {
368             $istrash = 0 if ($l =~ m|</datafield|);
369             $l = <MARC>;
370             next;
371         }
372         if ($l =~ m/<datafield tag="(.{3})"/) {
373             if ($trash->has($1) or ($c->{autoscrub} and $1 =~ /\D/))
374               { $istrash = 1; next }
375         }
376
377         push @record, $l;
378         $l = <MARC>;
379         $i++;
380     }
381
382     # add 903(?) with new record id
383     if ($c->{'renumber-from'}) {
384         $recmeta{nid} = $c->{'renumber-from'};
385         push @record, join('', ' <datafield tag="', $c->{'renumber-tag'},
386                            '" ind1=" " ind2=" "> <subfield code="',
387                            $c->{'renumber-subfield'},
388                            '">',
389                            $recmeta{nid},
390                            "</subfield></datafield>\n");
391         $c->{'renumber-from'}++;
392     }
393     $i++;
394
395     push @record, $l;
396     return 1;
397 }
398
399 sub write_record {
400     my ($FH) = @_;
401
402     if ($FH eq 'EX') {
403         $EXMARC = undef;
404         open $EXMARC, '>:utf8', $c->{exception}
405           or die "Can't open exception file $!\n";
406         $FH = $EXMARC;
407     }
408
409     print $FH '<!-- ', $recmeta{explanation}, " -->\n"
410       if(defined $recmeta{explanation});
411
412     # scrub newlines (unless told not to or writing exception record)
413     unless ($c->{nocollapse} or $FH eq $EXMARC)
414       { s/\n// for (@record) }
415
416     # actually write the record
417     print $FH @record,"\n";
418
419     # increment output record count (if not exception)
420     $c->{rocount}++ if ($FH eq $EXMARC);
421
422     # if we were dumping to exception file, nuke the record and set ptr
423     # to terminate processing loop
424     @record = ('a');
425     $ptr = 0;
426 }
427
428 sub print_fullcontext {
429     print $OUT "\r", ' ' x 72, "\n";
430     print $OUT $c->{editmsg},"\n";
431     print $OUT "\r    Tag:",$recmeta{tag}, " Ind1:'",
432       $recmeta{ind1},"' Ind2:'", $recmeta{ind2}, "'";
433     print $OUT " @ ", $c->{ricount}, "/", $c->{totalrecs};
434     print_context();
435     return 0;
436 }
437
438 sub print_context {
439     my $upper = int($c->{window} / 2) + 1;
440     my $lower = int($c->{window} / 2) - 1;
441     my $start = ($ptr - $upper < 0) ? 0 : $ptr - $upper;
442     my $stop  = ($ptr + $lower > $#record) ? $#record : $ptr + $lower;
443     print $OUT "\n";
444     print $OUT '    |', $record[$_] for ($start .. $ptr - 1);
445     print $OUT '==> |', $record[$ptr];
446     print $OUT '    |', $record[$_] for ($ptr + 1 .. $stop);
447     print $OUT "\n";
448     return 0;
449 }
450
451 sub message {
452     my ($msg) = @_;
453     print $OUT "\r$msg at ",$c->{ricount},"/",$c->{totalrecs}, "\n";
454 }
455
456 #-----------------------------------------------------------------------------------
457 # command routines
458 #-----------------------------------------------------------------------------------
459
460 sub substitute {
461     my (@chunks) = @_;
462
463     my $ofrom = shift @chunks;
464     if ($ofrom =~ /^'/) {
465         until ($ofrom =~ /'$/ or !@chunks)
466           { $ofrom .= join(' ','',shift @chunks) }
467         $ofrom =~ s/^'//; $ofrom =~ s/'$//;
468     }
469     my $to = shift @chunks;
470     if ($to =~ /^'/) {
471         until ($to =~ /'$/ or !@chunks)
472           { $to .= join(' ','',shift @chunks) }
473         $to =~ s/^'//; $to =~ s/'$//;
474     }
475
476     my $from = '';
477     for my $char (split(//,$ofrom)) {
478         $char = "\\" . $char if ($char =~ /\W/);
479         $from = join('', $from, $char);
480     }
481
482     $recmeta{prevline} = $record[$ptr];
483     $record[$ptr] =~ s/$from/$to/;
484     $ofrom = undef; $to = undef; $from = undef;
485     print_context();
486     return 0;
487 }
488
489 sub merge_lines {
490     $recmeta{prevline} = $record[$ptr];
491     # remove <subfield stuff; extract (probably wrong) subfield code
492     $record[$ptr] =~ s/^\s*<subfield code="(.*?)">//;
493     # and move to front of line
494     $record[$ptr] = join(' ', $1 , $record[$ptr]);
495     # tear off trailing subfield tag from preceeding line
496     $record[$ptr - 1] =~ s|</subfield>\n||;
497     # join current line onto preceeding line
498     $record[$ptr - 1] = join('', $record[$ptr - 1], $record[$ptr]);
499     # erase current line
500     my @a = @record[0 .. $ptr - 1];
501     my @b = @record[$ptr + 1 .. $#record];
502     @record = (@a, @b);
503     # move record pointer to previous line
504     prev_line();
505     print_context();
506     return 0;
507 }
508
509 sub flip_line {
510     unless ($recmeta{prevline})
511       { print $OUT "No previously edited line to flip\n"; return }
512     my $temp = $record[$ptr];
513     $record[$ptr] = $recmeta{prevline};
514     $recmeta{prevline} = $temp;
515     $temp = undef;
516     print_context();
517     return 0;
518 }
519
520 sub kill_line {
521     $recmeta{killline} = $record[$ptr];
522     my @a = @record[0 .. $ptr - 1];
523     my @b = @record[$ptr + 1 .. $#record];
524     @record = (@a, @b);
525     @a = undef; @b = undef;
526     print_context();
527     return 0;
528 }
529
530 sub yank_line {
531     unless ($recmeta{killline})
532       { print $OUT "No killed line to yank\n"; return }
533     my @a = @record[0 .. $ptr - 1];
534     my @b = @record[$ptr .. $#record];
535     @record = (@a, $c->{killline}, @b);
536     @a = undef; @b = undef;
537     print_context();
538     return 0;
539 }
540
541 sub insert_original {
542     $record[$ptr] = $recmeta{origline};
543     print_context();
544     return 0;
545 }
546
547 sub display_lines {
548     print $OUT "\nOrig. edit line  :", $recmeta{origline};
549     print $OUT "Current flip line:", $recmeta{prevline} if $recmeta{prevline};
550     print $OUT "Last killed line :", $recmeta{killline} if $recmeta{killline};
551     print $OUT "\n";
552     return 0;
553 }
554
555 sub dump_record {
556     my (@explanation) = @_;
557     $recmeta{explanation} = join(' ', 'DUMPING RECORD: Tag', $recmeta{tag}, @explanation);
558     message( $recmeta{explanation} );
559     write_record($EXMARC);
560     return 1;
561 }
562
563 sub next_line {
564     $ptr++ unless ($ptr == $#record);;
565     print_context();
566     return 0;
567 }
568
569 sub prev_line {
570     $ptr-- unless ($ptr == 0);
571     print_context();
572     return 0;
573 }
574
575 sub commit_edit { return 1 }
576
577 sub widen_window {
578     if ($c->{window} == 15)
579       { print $OUT "Window can't be bigger than 15 lines\n"; return }
580     $c->{window} += 2;
581     print_context;
582 }
583
584 sub narrow_window {
585     if ($c->{window} == 5)
586       { print $OUT "Window can't be smaller than 5 lines\n"; return }
587     $c->{window} -= 2;
588     print_context;
589 }
590
591 sub help {
592 print $OUT <<HELP;
593 Type a replacement for the indicated line, or enter a command.
594
595 DISPLAY COMMANDS             | LINE AUTO-EDIT COMMANDS
596 <  Expand context window     | k  Kill current line
597 >  Contract context window   | y  Yank last killed line
598 p  Move pointer to prev line | m  Merge current line into preceding line
599 n  Move pointer to next line | o  Insert original line
600 c  Print line context        | f  Flip current line and last edited line
601 d  Print current saved lines |
602 -----------------------------+-------------------------------------------
603 s  Subtitute; replace ARG1 in current line with ARG2. If either ARG
604    contains spaces, it must be single-quoted
605 t  Commit changes and resume automated operations
606 x  Dump record to exception file
607 q  Quit
608
609 HELP
610 return 0;
611 }
612
613 sub quit { exit }
614
615 #-----------------------------------------------------------------------
616
617 =head2 initialize
618
619 Performs boring script initialization. Handles argument parsing,
620 mostly.
621
622 =cut
623
624 sub initialize {
625     my ($c) = @_;
626     my @missing = ();
627
628     # set mode on existing filehandles
629     binmode(STDIN, ':utf8');
630
631     my $rc = GetOptions( $c,
632                          'autoscrub|a',
633                          'fullauto',
634                          'exception|x=s',
635                          'output|o=s',
636                          'marcfile|m=s',
637                          'prefix|p=s',
638                          'nocollapse|n',
639                          'renumber-from|rf=i',
640                          'renumber-tag|rt=i',
641                          'renumber-subfield|rs=s',
642                          'original-tag|ot=i',
643                          'original-subfield|os=s',
644                          'fix-subfield|fs=s',
645                          'force-utf8',
646                          'script',
647                          'no-strip9',
648                          'trashfile|t=s',
649                          'trashhelp',
650                          'help|h',
651                        );
652     show_help() unless $rc;
653     show_help() if ($c->{help});
654     show_trashhelp() if ($c->{trashhelp});
655
656     # defaults
657     my $pfx = defined($c->{prefix}) ? $c->{prefix} : "bibs";
658     $c->{ricount} = 0;
659     $c->{rocount} = 0;
660     $c->{'renumber-tag'} = 903 unless defined $c->{'renumber-tag'};
661     $c->{'renumber-subfield'} = 'a' unless defined $c->{'renumber-subfield'};
662     $c->{window} = 9;
663     if ($c->{prefix}) {
664         $c->{output} = join('.',$c->{prefix},'clean','marc','xml')
665           unless $c->{output};
666         $c->{exception} = join('.',$c->{prefix},'exception','marc','xml')
667           unless $c->{exception};
668         $c->{marcfile} = $c->{prefix} . '.marc.xml'
669           unless $c->{marcfile};
670     }
671     show_help() unless ($c->{marcfile} and $c->{output});
672
673     if ($c->{trashfile}) {
674         $c->{trash} = Equinox::Migration::SimpleTagList->new(file => $c->{trashfile})
675     } else {
676         $c->{trash} = Equinox::Migration::SimpleTagList->new;
677     }
678     # autotrash 901, 903 unless no strip-nines
679     unless ($c->{'no-strip9'}) {
680         $c->{trash}->add_tag(901);
681         $c->{trash}->add_tag(903);
682     }
683     # remove original id sequence tag from trash hash if we know it
684     $c->{trash}->remove_tag($c->{'original-tag'})
685       if ( $c->{'original-tag'} and $c->{trash}->has($c->{'original-tag'}) );
686 }
687
688 sub show_help {
689     print <<HELP;
690 Usage is: marc_cleanup [OPTIONS] <filelist>
691 Options
692   --output     -o  Cleaned MARCXML output filename
693   --exception  -x  Exception (dumped records) MARCXML filename
694        or
695   --prefix=<PREFIX>    -p  Shared prefix for output/exception files. Will produce
696                            PREFIX.clean.marc.xml and PREFIX.exception.marc.xml
697
698   --marcfile  -m  Input filename. Defaults to PREFIX.marc.xml
699
700   --renumber-from     -rf  Begin renumbering id sequence with this number
701   --renumber-tag      -rt  Tag to use in renumbering (default: 903)
702   --renumber-subfield -rs  Subfield code to use in renumbering (default: a)
703   --original-tag      -ot  Original id tag; will be kept in output even if
704                            it appears in the trash file
705   --original-subfield -os  Original id subfield code. If this is specified
706                            and renumbering is in effect, an old-to-new mapping
707                            file (old2new.map) will be generated.
708
709   --force-utf8             Rewrite each record so that they describe themselves as
710                            UTF-8 encoded
711   --autoscrub         -a   Automatically remove non-numeric tags in data
712   --fix-subfield      -fs  Subfield code to use in place of non-alphanumeric
713                            or empty subfield codes
714   --nocollapse        -n   Don't compress records to one line on output
715   --no-strip9              Don't autoremove 901/903 tags in data
716   --trashfile         -t   File containing trash tag data (see --trashhelp)
717
718   --fullauto               No manual edits. All problematic records dumped to
719                            exception file.
720
721 HELP
722 exit;
723 }
724
725 sub show_trashhelp {
726     print <<HELP;
727 See
728
729 http://intra.lan.hq.esilibrary.com/dokuwiki/doku.php?id=migration:tag_files
730
731 for tag file syntax information.
732 HELP
733 exit;
734 }