Blame scripts/configdiff.pl
|
Roland McGrath |
11487c5 |
#! /usr/bin/perl
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
my @args=@ARGV;
|
|
Roland McGrath |
11487c5 |
my @configoptions;
|
|
Roland McGrath |
11487c5 |
my @configvalues;
|
|
Roland McGrath |
11487c5 |
my @alreadyprinted;
|
|
Roland McGrath |
11487c5 |
my $configcounter = 0;
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
# first, read the override file
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
open (FILE,"$args[0]") || die "Could not open $args[0]";
|
|
Roland McGrath |
11487c5 |
while (<FILE>) {
|
|
Roland McGrath |
11487c5 |
my $str = $_;
|
|
Roland McGrath |
11487c5 |
if (/\# ([\w]+) is not set/) {
|
|
Roland McGrath |
11487c5 |
$configoptions[$configcounter] = $1;
|
|
Roland McGrath |
11487c5 |
$configvalues[$configcounter] = $str;
|
|
Roland McGrath |
11487c5 |
$alreadprinted[$configcounter] = 0;
|
|
Roland McGrath |
11487c5 |
$configcounter ++;
|
|
Roland McGrath |
11487c5 |
} else {
|
|
Roland McGrath |
11487c5 |
if (/([\w]+)=/) {
|
|
Roland McGrath |
11487c5 |
$configoptions[$configcounter] = $1;
|
|
Roland McGrath |
11487c5 |
$configvalues[$configcounter] = $str;
|
|
Roland McGrath |
11487c5 |
$alreadprinted[$configcounter] = 0;
|
|
Roland McGrath |
11487c5 |
$configcounter ++;
|
|
Roland McGrath |
11487c5 |
} else {
|
|
Roland McGrath |
11487c5 |
$configoptions[$configcounter] = "$_";
|
|
Roland McGrath |
11487c5 |
$configvalues[$configcounter] = $str;
|
|
Roland McGrath |
11487c5 |
$alreadprinted[$configcounter] = 0;
|
|
Roland McGrath |
11487c5 |
$configcounter ++;
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
};
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
# now, read and output the entire configfile, except for the overridden
|
|
Roland McGrath |
11487c5 |
# parts... for those the new value is printed.
|
|
Roland McGrath |
11487c5 |
# O(N^2) algorithm so if this is slow I need to look at it later
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
open (FILE2,"$args[1]") || die "Could not open $args[1]";
|
|
Roland McGrath |
11487c5 |
while (<FILE2>) {
|
|
Roland McGrath |
11487c5 |
my $nooutput;
|
|
Roland McGrath |
11487c5 |
my $counter;
|
|
Roland McGrath |
11487c5 |
my $configname="$_";
|
|
Roland McGrath |
11487c5 |
my $match;
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
if (/\# ([\w]+) is not set/) {
|
|
Roland McGrath |
11487c5 |
$configname = $1;
|
|
Roland McGrath |
11487c5 |
} else {
|
|
Roland McGrath |
11487c5 |
if (/([\w]+)=/) {
|
|
Roland McGrath |
11487c5 |
$configname = $1;
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
$counter = 0;
|
|
Roland McGrath |
11487c5 |
$nooutput = 0;
|
|
Roland McGrath |
11487c5 |
$match = 0;
|
|
Roland McGrath |
11487c5 |
# print "C : $configname";
|
|
Roland McGrath |
11487c5 |
while ($counter < $configcounter) {
|
|
Roland McGrath |
11487c5 |
if ("$configname" eq "$configoptions[$counter]") {
|
|
Roland McGrath |
11487c5 |
if ( ("$_" eq "$configvalues[$counter]") || ("$configname" eq "") ) {
|
|
Roland McGrath |
11487c5 |
$match = 1;
|
|
Roland McGrath |
11487c5 |
} else {
|
|
Roland McGrath |
11487c5 |
$alreadyprinted[$configcounter] = 1;
|
|
Roland McGrath |
11487c5 |
print "$_";
|
|
Roland McGrath |
11487c5 |
$match = 1;
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
$counter++;
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
if ($match == 0) {
|
|
Roland McGrath |
11487c5 |
print "$_";
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
}
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
|
|
Roland McGrath |
11487c5 |
1;
|