my $changed_since_last_save = 0;
+my @window_thresholds;
+my @channel_thresholds;
+my @query_thresholds;
+my %THRESHOLDARRAYS = ('window' => \@window_thresholds,
+ 'channel' => \@channel_thresholds,
+ 'query' => \@query_thresholds
+ );
+
my @DATALEVEL_KEYWORDS = ('all', 'messages', 'hilights', 'none');
### HELPERS ####################################################################
say("ERROR: ".$msg, MSGLEVEL_CLIENTERROR, $inwin);
}
-my @window_thresholds;
-my @channel_thresholds;
-my @query_thresholds;
-
sub match {
my ($pat, $text) = @_;
if ($pat =~ m/^(\W)(.+)\1$/) {
sub get_specific_threshold {
my ($type, $name, $net) = @_;
$type = lc($type);
- if ($type eq 'window') {
- return walk_match_array($name, $net, $type, \@window_thresholds);
- }
- elsif ($type eq 'channel') {
- return walk_match_array($name, $net, $type, \@channel_thresholds);
- }
- elsif ($type eq 'query') {
- return walk_match_array($name, $net, $type, \@query_thresholds);
+ if (exists $THRESHOLDARRAYS{$type}) {
+ return walk_match_array($name, $net, $type, $THRESHOLDARRAYS{$type});
}
else {
croak "ctrlact: can't look up threshold for type: $type";
next if m/^\s*(?:#|$)/;
my ($type, @matchers) = m/$linesplitter/;
@matchers = ['*', @matchers] if ($version eq "1.0");
- push @matchers, $l;
- push @window_thresholds, [@matchers] if match($type, 'window');
- push @channel_thresholds, [@matchers] if match($type, 'channel');
- push @query_thresholds, [@matchers] if match($type, 'query');
- $cnt += 1;
+ push @matchers, sprintf('line %3d', $l);
+ if (exists $THRESHOLDARRAYS{$type}) {
+ push @{$THRESHOLDARRAYS{$type}}, [@matchers];
+ $cnt += 1;
+ }
}
close($fh) || croak "Cannot close mappings file: $!";
return $cnt;
# type server name min.level
EOF
- my %types = ( 'window' => \@window_thresholds,
- 'channel' => \@channel_thresholds,
- 'query' => \@query_thresholds
- );
- while (my ($type, $arr) = each %types) {
- while (my ($idx, $elem) = each @{$arr}) {
+ foreach my $type (sort keys %THRESHOLDARRAYS) {
+ foreach my $arr (@{$THRESHOLDARRAYS{$type}}) {
print FH "$type\t";
- print FH join "\t", @{$elem}[0..2];
+ print FH join "\t", @{$arr}[0..2];
print FH "\n";
}
}