<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#! /usr/bin/perl
# $Id: ConfigList.pm 82648 2008-08-21 06:55:54Z johnnyw $

package PerlACE::ConfigList;
use strict;
use FileHandle;

@PerlACE::ConfigList::Configs = ();
@PerlACE::ConfigList::Excludes = ();

my @new_argv = ();

for(my $i = 0; $i &lt;= $#ARGV; ++$i) {
    if ($ARGV[$i] eq '-Config') {
        if (defined $ARGV[$i + 1]) {
            push @PerlACE::ConfigList::Configs, $ARGV[++$i];
        }
        else {
            print STDERR "You must pass a configuration with -Config\n";
            exit(1);
        }
    }
    elsif ($ARGV[$i] eq '-Exclude') {
        if (defined $ARGV[$i + 1]) {
            push @PerlACE::ConfigList::Excludes, $ARGV[++$i];
        }
        else {
            print STDERR "You must pass an exclude pattern with -Exclude\n";
            exit(1);
        }
    }
    else {
        push @new_argv, $ARGV[$i];
    }
}
@ARGV = @new_argv;


sub new ()
{
    my $self = {};
    @{$self-&gt;{MY_CONFIGS}} = @PerlACE::ConfigList::Configs;
    bless $self;
    return $self;
}

sub my_config_list
{
    my $self = shift;
    if (@_) { @{$self-&gt;{MY_CONFIGS}} = @_; }
    return @{$self-&gt;{MY_CONFIGS}};
}

sub add_one_config ($)
{
    my $self = shift;
    my $newconfig = shift;
    push @{$self-&gt;{MY_CONFIGS}}, $newconfig;
}

sub check_config (@)
{
    my $self = shift;
    my @testconfigs = @_;
    my $the_config_allows_this = 1; # default case is true

    # Go though each ID on the line in turn...
    foreach my $config (@testconfigs) {
        my $required_found = !($config =~ /^\w/);
        foreach my $myconfig (@{$self-&gt;{MY_CONFIGS}}) {
            if ($config eq "!$myconfig") { $the_config_allows_this = 0; }
            if ($config eq $myconfig) { $required_found = 1; }
        }
        if (!$required_found) { $the_config_allows_this = 0; }
    }
    return $the_config_allows_this;
}

sub load ($)
{
    my $self = shift;
    my $filename = shift;

    my $fh = new FileHandle;
    if (!$fh-&gt;open ("&lt; $filename")) {
        print STDERR "Could not open $filename: $!\n";
        exit (1);
    }

    while (&lt;$fh&gt;) {
        chomp;
	       if (/^\s*$/ || /^#/) {
            next;
        }
        # compress white space
	      s/\s+/ /g;

        my $entry = '';
        my $configs = '';

        ($entry, $configs) = split /:/;

        # remove trailing white spaces
        $entry =~ s/\s+$//;

        push @{$self-&gt;{ENTRIES}}, $entry;
	      if (defined $configs) {
            @{$self-&gt;{CONFIGS}-&gt;{$entry}} =  split (" ", $configs);
        }
    }

    $fh-&gt;close ();
}

sub valid_entries ()
{
    my $self = shift;
    my @entries = ();
    my $exclude = 0;

    foreach my $entry (@{$self-&gt;{ENTRIES}}) {
        $exclude = 0;
        foreach my $expat (@PerlACE::ConfigList::Excludes) {
          if ($entry =~ /$expat/) {
            $exclude = 1;
            last;
          }
        }
        if (!$exclude &amp;&amp; $self-&gt;check_config (@{$self-&gt;{CONFIGS}-&gt;{$entry}})) {
            push @entries, $entry;
        }
    }
    return @entries;
}

sub list_configs ()
{
    my $self = shift;
    my %allconfigs = {};
    my $list = '';

    foreach my $entry (@{$self-&gt;{ENTRIES}}) {

        foreach my $config (@{$self-&gt;{CONFIGS}-&gt;{$entry}}) {
            $config =~ s/!//g;
            if ($allconfigs{$config} != 1) {
                $list .= $config.' ';
                $allconfigs{$config} = 1;
            }
        }
    }

    return $list;
}

sub dump ()
{
    my $self = shift;

    print "============================================================\n";
    print "Config\n";
    foreach my $config (@{$self-&gt;{MY_CONFIGS}}) {
        print $config, "\n";
    }
    print "\n";
    print "Entries\n";
    foreach my $entry (@{$self-&gt;{ENTRIES}}) {
        print "- ", $entry, ": ";
        foreach my $config (@{$self-&gt;{CONFIGS}-&gt;{$entry}}) {
            print $config, " ";
        }
        print "\n";
    }
    print "============================================================\n";
}

1;
</pre></body></html>