X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FFilter.pm;h=2b30c8cdea5c8484ca348e21442464cf50c9fe65;hb=c20a2c1e01d707d6c3fa25067df93d491aba8fff;hp=aefa922419ee94afac488101b11c184aba45a8eb;hpb=82de56e409a19a05761794c9588713160b51144e;p=spider.git diff --git a/perl/Filter.pm b/perl/Filter.pm index aefa9224..2b30c8cd 100644 --- a/perl/Filter.pm +++ b/perl/Filter.pm @@ -12,43 +12,24 @@ # # $Id$ # -# The INSTRUCTIONS +# The NEW INSTRUCTIONS +# +# use the commands accept/spot|ann|wwv|wcy and reject/spot|ann|wwv|wcy +# also show/filter spot|ann|wwv|wcy # # The filters live in a directory tree of their own in $main::root/filter # # Each type of filter (e.g. spot, wwv) live in a tree of their own so you # can have different filters for different things for the same callsign. # -# Each filter file has the same structure:- -# -# -# @in = ( -# [ action, fieldno, fieldsort, comparison, action data ], -# ... -# ); -# -# The action is usually 1 or 0 but could be any numeric value -# -# The fieldno is the field no in the list of fields that is presented -# to 'Filter::it' -# -# The fieldsort is the type of field that we are dealing with which -# currently can be 'a', 'n', 'r' or 'd'. 'a' is alphanumeric, 'n' is -# numeric, 'r' is ranges of pairs of numeric values and 'd' is default. -# -# Filter::it basically goes thru the list of comparisons from top to -# bottom and when one matches it will return the action and the action data as a list. -# The fields -# are the element nos of the list that is presented to Filter::it. Element -# 0 is the first field of the list. -# + package Filter; use DXVars; use DXUtil; use DXDebug; -use Carp; +use Data::Dumper; use strict; @@ -63,40 +44,6 @@ sub init } -# -# takes the reference to the filter (the first argument) and applies -# it to the subsequent arguments and returns the action specified. -# -sub it -{ - my $filter = shift; - my ($action, $field, $fieldsort, $comp, $actiondata); - my $ref; - - # default action is 1 - $action = 1; - $actiondata = ""; - return ($action, $actiondata) if !$filter; - - for $ref (@{$filter}) { - ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref}; - if ($fieldsort eq 'n') { - my $val = $_[$field]; - return ($action, $actiondata) if grep $_ == $val, @{$comp}; - } elsif ($fieldsort eq 'r') { - my $val = $_[$field]; - my $i; - my @range = @{$comp}; - for ($i = 0; $i < @range; $i += 2) { - return ($action, $actiondata) if $val >= $range[$i] && $val <= $range[$i+1]; - } - } elsif ($fieldsort eq 'a') { - return ($action, $actiondata) if $_[$field] =~ m{$comp}; - } else { - return ($action, $actiondata); # the default action - } - } -} # this reads in a filter statement and returns it as a list # @@ -121,17 +68,22 @@ sub read_in # load it if (-e $fn) { - do "$fn"; + $in = undef; + my $s = readfilestr($fn); + my $newin = eval $s; dbg('conn', "$@") if $@; - return $in; + return bless [ @$in ], 'Filter::Old' if $in; + return $newin; } return undef; } # this writes out the filter in a form suitable to be read in by 'read_in' # It expects a list of references to filter lines -sub write_out +sub write { + my $self = shift; + my $sort = shift; my $call = shift; my $fn = "$filterbasefn/$sort"; @@ -171,5 +123,74 @@ sub write_out close FILTER; } +package Filter::Old; + +use strict; +use vars qw(@ISA); +@ISA = qw(Filter); + +# the OLD instructions! +# +# Each filter file has the same structure:- +# +# +# @in = ( +# [ action, fieldno, fieldsort, comparison, action data ], +# ... +# ); +# +# The action is usually 1 or 0 but could be any numeric value +# +# The fieldno is the field no in the list of fields that is presented +# to 'Filter::it' +# +# The fieldsort is the type of field that we are dealing with which +# currently can be 'a', 'n', 'r' or 'd'. 'a' is alphanumeric, 'n' is +# numeric, 'r' is ranges of pairs of numeric values and 'd' is default. +# +# Filter::it basically goes thru the list of comparisons from top to +# bottom and when one matches it will return the action and the action data as a list. +# The fields +# are the element nos of the list that is presented to Filter::it. Element +# 0 is the first field of the list. +# + +# +# takes the reference to the filter (the first argument) and applies +# it to the subsequent arguments and returns the action specified. +# +sub it +{ + my $filter = shift; # this is now a bless ref of course but so what + + my ($action, $field, $fieldsort, $comp, $actiondata); + my $ref; + + # default action is 1 + $action = 1; + $actiondata = ""; + return ($action, $actiondata) if !$filter; + + for $ref (@{$filter}) { + ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref}; + if ($fieldsort eq 'n') { + my $val = $_[$field]; + return ($action, $actiondata) if grep $_ == $val, @{$comp}; + } elsif ($fieldsort eq 'r') { + my $val = $_[$field]; + my $i; + my @range = @{$comp}; + for ($i = 0; $i < @range; $i += 2) { + return ($action, $actiondata) if $val >= $range[$i] && $val <= $range[$i+1]; + } + } elsif ($fieldsort eq 'a') { + return ($action, $actiondata) if $_[$field] =~ m{$comp}; + } else { + return ($action, $actiondata); # the default action + } + } +} + + 1; __END__