Debian Codegraph @

etc/specs

raw
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 =head1 specs
7
8 Turns http://www.loc.gov/marc/bibliographic/ecbdist.html into the format
9 used by MARC::Lint.pm
10
11 Takes ecbdist.html as input. Skips fixed fields and data marked
12 "[OBSOLETE]" Also, the HTML file doesn't include the 841-88X tags,
13 so those are hardcoded here.
14
15 =head1 AUTHOR
16
17 Originally written by Colin Campbell at Sirsi, and taken over and modified
18 by Andy Lester.
19
20 =cut
21
22 open( my $fh, '<', "../lib/MARC/Lint.pm" ) or die "Can't open module";
23 while ( <$fh> ) {
24 print;
25 last if /^__DATA__/;
26 }
27 close $fh;
28
29 local $/ = undef;
30 my $text = <>;
31 $text =~ s/(<BR>|\r|\n)+/\n/ig;
32 my @lines = split( /\n/, $text );
33
34
35 my $in_tag = undef;
36 my $i1;
37 my $i2;
38 my $curr_indicator;
39 my $ntags;
40 my $desc1;
41 my $desc2;
42
43 my $started = 0;
44 for ( @lines ) {
45 unless ($started) {
46 $started=1 if /Number and Code Fields/;
47 next;
48 }
49 s/^\s+//;
50 s/\s+$//;
51 next if $_ eq "";
52
53 if ( /^(\d\d\d)/ ) {
54 my $tag = $1;
55 if (/OBSOLETE/) {
56 $in_tag = 0;
57 next;
58 }
59
60 /$tag - (.+) \((N?R)\)/ or die "Tag $tag is invalid format";
61 my $desc = $1;
62 my $nr = $2;
63 ++$ntags;
64 $in_tag = 1;
65 print "\n" if $ntags > 1;
66 print "$tag\t$nr\t$desc\n";
67 $i1 = $i2 = "";
68 next;
69 }
70
71 next unless $in_tag;
72 next if /OBSOLETE/;
73
74 if (/^First - (.+)/) {
75 $curr_indicator = 1;
76 $desc1 = $1;
77 } elsif (/^Second - (.+)/) {
78 print_indicator( 1, $i1, $desc1 );
79 undef $desc1;
80 $curr_indicator = 2;
81 $desc2 = $1;
82 } elsif (/^Subfield/) {
83 print_indicator( 2, $i2, $desc2 );
84 undef $desc2;
85 $curr_indicator = 0;
86 } else {
87 if ($curr_indicator) {
88 my $data = '';
89 if (/^(\d-\d)/) {
90 $data = $1;
91 } elsif (/^([#0123456789])/) {
92 $data = $1;
93 }
94 $data = "b" if $data eq "#";
95 if ($curr_indicator == 1) {
96 $i1 .= $data;
97 } elsif ($curr_indicator == 2) {
98 $i2 .= $data;
99 }
100
101 } else {
102 if ( /^\$(.) - (.+)\s*\((N?R)\)/ ) {
103 my ($sub,$desc,$nr) = ($1,$2,$3);
104 print "$sub\t$nr\t$desc\n";
105 }
106 }
107 }
108 } # main while
109
110 sub print_indicator {
111 my $n = shift;
112 my $val = shift;
113 my $desc = shift;
114
115 $val = "blank" if $val eq "b";
116
117 print "ind$n\t$val\t$desc\n";
118 }