+
+ # do the rest of the filter tokens
+ if (@f) {
+ my $tok = shift @f;
+
+ dbg("filter::parse: tok '$tok'") if isdbg('filter');
+
+ if ($tok eq 'all') {
+ $s .= '1';
+ $user .= $tok;
+ last;
+ } elsif (grep $tok eq $_, qw{and or not ( )}) {
+ $s .= ' && ' if $tok eq 'and';
+ $s .= ' || ' if $tok eq 'or';
+ $s .= ' !' if $tok eq 'not';
+ $s .= $tok if $tok eq '(' or $tok eq ')';
+ $user .= " $tok ";
+ next;
+ } elsif ($tok eq '') {
+ next;
+ }
+
+ if (@f) {
+ my $val = shift @f;
+ my @val = split /,/, $val;
+
+ dbg("filter::parse: tok '$tok' val '$val'") if isdbg('filter');
+ $user .= " $tok $val";
+
+ my $fref;
+ my $found;
+ foreach $fref (@$self) {
+
+ if ($fref->[0] eq $tok) {
+ if ($fref->[4]) {
+ my @nval;
+ for (@val) {
+ push @nval, split(',', &{$fref->[4]}($dxchan, $_));
+ }
+ @val = @nval;
+ }
+ if ($fref->[1] eq 'a' || $fref->[1] eq 't') {
+ my @t;
+ foreach my $v (@val) {
+ $v =~ s/\*//g; # remove any trailing *
+ if (my ($r) = $v =~ /^\{(.*)\}$/) { # we have a regex
+ dbg("Filter::parse regex b: '\{$r\}'") if isdbg('filter');
+ $v = decode_regex($v);
+ dbg("Filter::parse regex a: '$v'") if isdbg('filter');
+ return ('regex', $dxchan->msg('e38', $v)) unless (qr{$v});
+ push @t, "\$r->[$fref->[2]]=~m{$v}i";
+ $v = "{$r}"; # put it back together again for humans
+ } else {
+ push @t, "\$r->[$fref->[2]]=~m{$v}i";
+ }
+ }
+ $s .= "(" . join(' || ', @t) . ")";
+ dbg("filter parse: s '$s'") if isdbg('filter');
+ } elsif ($fref->[1] eq 'c') {
+ my @t;
+ for (@val) {
+ s/\*//g;
+ push @t, "\$r->[$fref->[2]]=~m{^\U$_}";
+ }
+ $s .= "(" . join(' || ', @t) . ")";
+ dbg("filter parse: s '$s'") if isdbg('filter');
+ } elsif ($fref->[1] eq 'n') {
+ my @t;
+ for (@val) {
+ return ('num', $dxchan->msg('e21', $_)) unless /^\d+$/;
+ push @t, "\$r->[$fref->[2]]==$_";
+ }
+ $s .= "(" . join(' || ', @t) . ")";
+ dbg("filter parse: s '$s'") if isdbg('filter');
+ } elsif ($fref->[1] =~ /^n[ciz]$/ ) { # for DXCC, ITU, CQ Zone
+ my $cmd = $fref->[1];
+ my @pre = Prefix::to_ciz($cmd, @val);
+ return ('numpre', $dxchan->msg('e27', $_)) unless @pre;
+ $s .= "(" . join(' || ', map {"\$r->[$fref->[2]]==$_"} @pre) . ")";
+ dbg("filter parse: s '$s'") if isdbg('filter');
+ } elsif ($fref->[1] =~ /^ns$/ ) { # for DXCC, ITU, CQ Zone
+ my $cmd = $fref->[1];
+ my @pre = Prefix::to_ciz($cmd, @val);
+ return ('numpre', $dxchan->msg('e27', $_)) unless @pre;
+ $s .= "(" . "!\$USDB::present || grep \$r->[$fref->[2]] eq \$_, qw(" . join(' ' ,map {uc} @pre) . "))";
+ dbg("filter parse: s '$s'") if isdbg('filter');
+ } elsif ($fref->[1] eq 'r') {
+ my @t;
+ for (@val) {
+ return ('range', $dxchan->msg('e23', $_)) unless /^(\d+)\/(\d+)$/;
+ push @t, "(\$r->[$fref->[2]]>=$1 && \$r->[$fref->[2]]<=$2)";
+ }
+ $s .= "(" . join(' || ', @t) . ")";
+ dbg("filter parse: s '$s'") if isdbg('filter');
+ } else {
+ confess("invalid filter function $fref->[1]");
+ }
+ ++$found;
+ last;
+ }
+ }
+ return (1, $dxchan->msg('e20', $lasttok)) unless $found;
+ } else {
+ my $s = '{' . decode_regex($tok) . '}' if $tok =~ /^{.*}$/;
+ return (1, $dxchan->msg('filter2', $s));
+ }
+ $lasttok = $tok;
+ }
+ }
+
+ # tidy up the user string (why I have to stick in an if statement when I have initialised it I have no idea! 5.28 bug?
+ if ($user) {
+ $user =~ s/\)\s*\(/ and /g;
+ $user =~ s/\&\&/ and /g;
+ $user =~ s/\|\|/ or /g;
+ $user =~ s/\!/ not /g;
+ $user =~ s/\s+/ /g;
+ $user =~ s/\{(.*?)\}/'{'. pack('H*', $1) . '}'/eg;
+ $user =~ s/^\s+//;
+ dbg("filter parse: user '$user'") if isdbg('filter');
+ }
+
+ if ($s) {
+ $s =~ s/\)\s*\(/ && /g;
+ dbg("filter parse: s '$s'") if isdbg('filter');