diff --git a/m1r4/dsv/bomshelf b/m1r4/dsv/bomshelf index 1bbdefe..f06c348 100755 --- a/m1r4/dsv/bomshelf +++ b/m1r4/dsv/bomshelf @@ -23,6 +23,29 @@ sub csv } + +sub lookup +{ + my $p = $_[0]; + my $add = $_[1]; + my @a; + + return $p if defined $cr{$p}; + @a = grep { $_ =~ /^$p/ } keys %cr; + die "key $p* is ambiguous" if scalar @a > 1; + if (!@a) { + @a = grep { $_ =~ /$p/ } keys %cr; + die "key *$p* is ambiguous" if scalar @a > 1; + if (!@a) { + die "key $p matches nothing" unless $add; + warn "adding $p as supplement"; + return $p; + } + } + return $a[0]; +} + + while (<>) { chop; @f = &csv($_); @@ -43,6 +66,15 @@ while () { chop; next if /^\s*#/; next if /^\s*$/; + if (/^[Xx]:\s*/) { + $p = &lookup($', 0); + delete $cr{$p}, $url{$p}, $dsc{$p}; + for (keys %r) { + delete $r{$_} if $r{$_} eq $p; + } + undef $p; + next; + } if (/^[Cc]:\s*/) { undef $p if $clear; $clear = 0; @@ -60,20 +92,8 @@ while () { next; } if (/^[Pp]:\s*/) { - $p = $'; + $p = &lookup($', 1); $clear = 0; - next if defined $cr{$p}; - @a = grep { $_ =~ /^$p/ } keys %cr; - die "key $p* is ambiguous" if scalar @a > 1; - if (!@a) { - @a = grep { $_ =~ /$p/ } keys %cr; - die "key *$p* is ambiguous" if scalar @a > 1; - if (!@a) { - warn "adding $p as supplement"; - next; - } - } - $p = $a[0]; next; } if (/^[Aa]:\s*/) {