- my ($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+|[PABM]|AM|MM|BCN|SIX|WEB|NET|Q\w+)$/o;
- $p = $parts[$#parts];
- pop @parts if $p =~ /^(\d+|[PABM]|AM|MM|BCN|SIX|WEB|NET|Q\w+)$/o;
+ my ($call, $sp, $i);
+
+LM: foreach $call (split /,/, $calls) {
+
+ $matchtotal++;
+ $call =~ s/-\d+$//; # ignore SSIDs
+ my @nout;
+ my $ecall = "=$call";
+
+ # first check if this is a call (by prefixing it with an = sign)
+ my $p = $lru->get($ecall);
+ if ($p) {
+ $hits++;
+ if (isdbg('prefix')) {
+ my $percent = sprintf "%.1f", $hits * 100 / $misses;
+ dbg("Prefix Exact Cache Hit: $call Hits: $hits/$misses of $matchtotal = $percent\%");
+ }
+ push @out, @$p;
+ next;
+ }
+
+ # then check if the whole thing succeeds either because it is cached
+ # or because it simply is a stored prefix as callsign (or even a prefix)
+ $p = $lru->get($call);
+ if ($p) {
+ $hits++;
+ if (isdbg('prefix')) {
+ my $percent = sprintf "%.1f", $hits * 100 / $misses;
+ dbg("Prefix Cache Hit: $call Hits: $hits/$misses of $matchtotal = $percent\%");
+ }
+ push @out, @$p;
+ next;
+ }
+
+ # is it in the USDB, force a matchprefix to match?
+ my @s = USDB::get($call);
+ if (@s) {
+ @nout = get($call);
+ @nout = matchprefix($call) unless @nout;
+ $nout[0] = $ecall if @nout;
+ } else {
+
+ # try a straight get for an exact callsign
+ @nout = get($ecall);
+ }
+
+ # now store the exact prefix if it has been found
+ if (@nout && $nout[0] eq $ecall) {
+ $misses++;
+ $nout[0] = $call;
+ lru_put("=$call", \@nout);
+ dbg("got exact prefix: $nout[0]") if isdbg('prefix');
+ push @out, @nout;
+ next;
+ }
+
+ # now try a non-exact call/prefix
+ if ((@nout = get($call)) && $nout[0] eq $call) {
+ $misses++;
+ lru_put($call, \@nout);
+ 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);
+ dbg("Parts: $call = " . join(' ', @parts)) if isdbg('prefix');
+
+ # remove any /0-9 /P /A /M /MM /AM suffixes etc
+ if (@parts > 1) {
+ @parts = grep { !/^\d+$/ && !/^[PABM]$/ && !/^(?:|AM|MM|BCN|JOTA|SIX|WEB|NET|Q\w+)$/; } @parts;
+
+ # can we resolve them by direct lookup
+ my $s = join('/', @parts);
+ @nout = get($s);
+ if (@nout && $nout[0] eq $s) {
+ dbg("got exact multipart prefix: $call $s") if isdbg('prefix');
+ $misses++;
+ lru_put($call, \@nout);
+ push @out, @nout;
+ next;
+ }
+ }
+ dbg("Parts now: $call = " . join(' ', @parts)) if isdbg('prefix');