X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FPrefix.pm;h=a08f5a4498820e124ef3145743fab9ab2c560439;hb=b9d0612ccca9f17d88469c17fa72441c248ac091;hp=954490fcf41e2798ad39ba6c6951b89002922dd5;hpb=2b58ccdf81685a1167a43c38705a0d84b9d8d661;p=spider.git diff --git a/perl/Prefix.pm b/perl/Prefix.pm index 954490fc..a08f5a44 100644 --- a/perl/Prefix.pm +++ b/perl/Prefix.pm @@ -140,51 +140,79 @@ sub next sub extract { - my $call = uc shift; + my $calls = uc shift; my @out; - my @nout; my $p; my @parts; - my ($sp, $i); + my ($call, $sp, $i); - # first check if the whole thing succeeds - @out = get($call); - return @out if @out > 0 && $out[0] eq $call; - - # now split the call into parts if required - @parts = ($call =~ '/') ? split('/', $call) : ($call); - - # remove any /0-9 /P /A /M /MM /AM suffixes etc - if (@parts > 1) { - $p = $parts[0]; - shift @parts if $p =~ /^(WEB|NET)$/o; - $p = $parts[$#parts]; - pop @parts if $p =~ /^(\d+|[JPABM]|AM|MM|BCN|JOTA|SIX|WEB|NET|Q\w+)$/o; - $p = $parts[$#parts]; - pop @parts if $p =~ /^(\d+|[JPABM]|AM|MM|BCN|JOTA|SIX|WEB|NET|Q\w+)$/o; - - # can we resolve them by direct lookup - foreach $p (@parts) { - @out = get($p); - return @out if @out > 0 && $out[0] eq $call; + foreach $call (split /,/, $calls) { + # first check if the whole thing succeeds + my @nout = get($call); + if (@nout && $nout[0] eq $call) { + dbg("got exact prefix: $nout[0]") if isdbg('prefix'); + push @out, @nout; + next; + } + + # now split the call into parts if required + @parts = ($call =~ '/') ? split('/', $call) : ($call); + + # remove any /0-9 /P /A /M /MM /AM suffixes etc + if (@parts > 1) { + $p = $parts[0]; + shift @parts if $p =~ /^(WEB|NET)$/o; + $p = $parts[$#parts]; + pop @parts if $p =~ /^(\d+|[JPABM]|AM|MM|BCN|JOTA|SIX|WEB|NET|Q\w+)$/o; + $p = $parts[$#parts]; + pop @parts if $p =~ /^(\d+|[JPABM]|AM|MM|BCN|JOTA|SIX|WEB|NET|Q\w+)$/o; + + # can we resolve them by direct lookup + foreach $p (@parts) { + @nout = get($p); + if (@nout && $nout[0] eq $call) { + dbg("got exact prefix: $nout[0]") if isdbg('prefix'); + push @out, @nout; + next; + } + } } - } - # which is the shortest part (first if equal)? - $sp = $parts[0]; - foreach $p (@parts) { - $sp = $p if length $sp > length $p; + # which is the shortest part (first if equal)? + dbg("Parts: $call = " . join('|', @parts)) if isdbg('prefix'); + + # try ALL the parts +L1: for (;@parts;) { + $sp = $parts[0]; + foreach $p (@parts) { + $sp = $p if length $p < length $sp; + } + @parts = grep { $_ ne $sp } @parts; # remove it from the list + $sp =~ s/-\d+$//; # remove any SSID + + # # now start to resolve it from the left hand end + # for ($i = 1; $i <= length $sp; ++$i) { + # now start to resolve it from the right hand end + for ($i = length $sp; $i >= 1; --$i) { + my $ssp = substr($sp, 0, $i); + my @wout = get($ssp); + if (isdbg('prefix')) { + my $part = $wout[0] || "*"; + $part .= '*' unless $part eq '*' || $part eq $ssp; + dbg("Partial prefix: $sp $ssp $part" ); + } + next if @wout > 0 && $wout[0] gt $ssp; + # last if @wout == 0; + push @out, @wout; + last L1 if @wout; + } + } } - # now start to resolve it from the left hand end - for (@out = (), $i = 1; $i <= length $sp; ++$i) { - @nout = get(substr($sp, 0, $i)); - last if @nout > 0 && $nout[0] gt $sp; - last if @nout == 0; - @out = @nout; + if (isdbg('prefix')) { + my $dd = new Data::Dumper([ \@out ], [qw(@out)]); + dbg($dd->Dumpxs); } - - # not found - return (@out > 0) ? @out : (); + return @out; } my %valid = (