| 1 |
#! /usr/bin/perl
|
| 2 |
|
| 3 |
my @args=@ARGV;
|
| 4 |
my @configoptions;
|
| 5 |
my @configvalues;
|
| 6 |
my @alreadyprinted;
|
| 7 |
my $configcounter = 0;
|
| 8 |
|
| 9 |
# first, read the override file
|
| 10 |
|
| 11 |
open (FILE,"$args[0]") || die "Could not open $args[0]";
|
| 12 |
while (<FILE>) {
|
| 13 |
my $str = $_;
|
| 14 |
if (/\# ([\w]+) is not set/) {
|
| 15 |
$configoptions[$configcounter] = $1;
|
| 16 |
$configvalues[$configcounter] = $str;
|
| 17 |
$alreadprinted[$configcounter] = 0;
|
| 18 |
$configcounter ++;
|
| 19 |
} else {
|
| 20 |
if (/([\w]+)=/) {
|
| 21 |
$configoptions[$configcounter] = $1;
|
| 22 |
$configvalues[$configcounter] = $str;
|
| 23 |
$alreadprinted[$configcounter] = 0;
|
| 24 |
$configcounter ++;
|
| 25 |
} else {
|
| 26 |
$configoptions[$configcounter] = "$_";
|
| 27 |
$configvalues[$configcounter] = $str;
|
| 28 |
$alreadprinted[$configcounter] = 0;
|
| 29 |
$configcounter ++;
|
| 30 |
}
|
| 31 |
}
|
| 32 |
};
|
| 33 |
|
| 34 |
# now, read and output the entire configfile, except for the overridden
|
| 35 |
# parts... for those the new value is printed.
|
| 36 |
# O(N^2) algorithm so if this is slow I need to look at it later
|
| 37 |
|
| 38 |
open (FILE2,"$args[1]") || die "Could not open $args[1]";
|
| 39 |
while (<FILE2>) {
|
| 40 |
my $nooutput;
|
| 41 |
my $counter;
|
| 42 |
my $configname="$_";
|
| 43 |
my $match;
|
| 44 |
|
| 45 |
if (/\# ([\w]+) is not set/) {
|
| 46 |
$configname = $1;
|
| 47 |
} else {
|
| 48 |
if (/([\w]+)=/) {
|
| 49 |
$configname = $1;
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
| 53 |
$counter = 0;
|
| 54 |
$nooutput = 0;
|
| 55 |
$match = 0;
|
| 56 |
# print "C : $configname";
|
| 57 |
while ($counter < $configcounter) {
|
| 58 |
if ("$configname" eq "$configoptions[$counter]") {
|
| 59 |
if ( ("$_" eq "$configvalues[$counter]") || ("$configname" eq "") ) {
|
| 60 |
$match = 1;
|
| 61 |
} else {
|
| 62 |
$alreadyprinted[$configcounter] = 1;
|
| 63 |
print "$_";
|
| 64 |
$match = 1;
|
| 65 |
}
|
| 66 |
}
|
| 67 |
$counter++;
|
| 68 |
}
|
| 69 |
if ($match == 0) {
|
| 70 |
print "$_";
|
| 71 |
}
|
| 72 |
|
| 73 |
}
|
| 74 |
|
| 75 |
|
| 76 |
1;
|