| 1 |
#!/usr/bin/perl
|
| 2 |
# reduces the config file given as the first parameter, to contain only
|
| 3 |
# entries for the modules listd as the rest of the parameters.
|
| 4 |
my $file = shift;
|
| 5 |
my %modules = map { s/.*\///; s/\.k?o$//; $_ => 1} @ARGV;
|
| 6 |
open (IN, $file) || die "open $file: $!";
|
| 7 |
$/="\n\n";
|
| 8 |
my %devices;
|
| 9 |
while (<IN>) {
|
| 10 |
s/\s*#.*//g;
|
| 11 |
if (/device\s+\"([^"]+)\"/) {
|
| 12 |
# This assumes the device entries come first, and the card
|
| 13 |
# entries after.
|
| 14 |
my $device=$1;
|
| 15 |
if (/module\s+("[^"]+"(?:,\s+"[^"]+")*)/) {
|
| 16 |
my $modules=$1;
|
| 17 |
$modules=~s/"//g;
|
| 18 |
$modules=~y/ / /s;
|
| 19 |
my @modules=split(' ', $modules);
|
| 20 |
my $ok=0;
|
| 21 |
foreach (@modules) {
|
| 22 |
$ok=1 if $modules{$_};
|
| 23 |
}
|
| 24 |
next unless $ok;
|
| 25 |
$devices{$device}=1;
|
| 26 |
}
|
| 27 |
else {
|
| 28 |
print STDERR "warning: cannot find modules for device $device\n";
|
| 29 |
next;
|
| 30 |
}
|
| 31 |
}
|
| 32 |
elsif (/card\s+/) {
|
| 33 |
if (/bind\s+(.*)/) {
|
| 34 |
my $bindline=$1;
|
| 35 |
# support multi-purpose cards
|
| 36 |
my $used=0;
|
| 37 |
while ($bindline=~m/\"([^"]+)\"/g) {
|
| 38 |
$used=1 if $devices{$1};
|
| 39 |
}
|
| 40 |
next unless $used;
|
| 41 |
}
|
| 42 |
else {
|
| 43 |
print STDERR "warning: cannot determine bind of card in $_\n";
|
| 44 |
next;
|
| 45 |
}
|
| 46 |
}
|
| 47 |
elsif (/region\s+/) {
|
| 48 |
# memory technology drivers, always skipped for now
|
| 49 |
next;
|
| 50 |
}
|
| 51 |
elsif (/^source\s+/) {
|
| 52 |
# keep as-is
|
| 53 |
}
|
| 54 |
else {
|
| 55 |
next if /^\s*$/;
|
| 56 |
print STDERR "warning: unknown stanza: $_\n";
|
| 57 |
}
|
| 58 |
|
| 59 |
print $_;
|
| 60 |
}
|
| 61 |
close IN;
|