Jesse Keating 2f82dda
#! /usr/bin/perl
Jesse Keating 2f82dda
Jesse Keating 2f82dda
my @args=@ARGV;
Jesse Keating 2f82dda
my %configvalues;
Jesse Keating 2f82dda
my @configoptions;
Jesse Keating 2f82dda
my $configcounter = 0;
Jesse Keating 2f82dda
Jesse Keating 2f82dda
# optionally print out the architecture as the first line of our output
Jesse Keating 2f82dda
my $arch = $args[2];
Jesse Keating 2f82dda
if (defined $arch) {
Jesse Keating 2f82dda
	print "# $arch\n";
Jesse Keating 2f82dda
}
Jesse Keating 2f82dda
Jesse Keating 2f82dda
# first, read the override file
Jesse Keating 2f82dda
Jesse Keating 2f82dda
open (FILE,"$args[0]") || die "Could not open $args[0]";
Jesse Keating 2f82dda
while (<FILE>) {
Jesse Keating 2f82dda
	my $str = $_;
Jesse Keating 2f82dda
	my $configname;
Jesse Keating 2f82dda
Jesse Keating 2f82dda
	if (/\# ([\w]+) is not set/) {
Jesse Keating 2f82dda
		$configname = $1;
Jesse Keating 2f82dda
	} elsif (/([\w]+)=/) {
Jesse Keating 2f82dda
		$configname = $1;
Jesse Keating 2f82dda
	}
Jesse Keating 2f82dda
Jesse Keating 2f82dda
	if (defined($configname) && !exists($configvalues{$configname})) {
Jesse Keating 2f82dda
		$configvalues{$configname} = $str;
Jesse Keating 2f82dda
		$configoptions[$configcounter] = $configname;
Jesse Keating 2f82dda
		$configcounter ++;
Jesse Keating 2f82dda
	}
Jesse Keating 2f82dda
};
Jesse Keating 2f82dda
Jesse Keating 2f82dda
# now, read and output the entire configfile, except for the overridden
Jesse Keating 2f82dda
# parts... for those the new value is printed.
Jesse Keating 2f82dda
Jesse Keating 2f82dda
open (FILE2,"$args[1]") || die "Could not open $args[1]";
Jesse Keating 2f82dda
while (<FILE2>) {
Jesse Keating 2f82dda
	my $configname;
Jesse Keating 2f82dda
Jesse Keating 2f82dda
	if (/\# ([\w]+) is not set/) {
Jesse Keating 2f82dda
		$configname = $1;
Jesse Keating 2f82dda
	} elsif (/([\w]+)=/) {
Jesse Keating 2f82dda
		$configname  = $1;
Jesse Keating 2f82dda
	}
Jesse Keating 2f82dda
Jesse Keating 2f82dda
	if (defined($configname) && exists($configvalues{$configname})) {
Jesse Keating 2f82dda
		print "$configvalues{$configname}";
Jesse Keating 2f82dda
		delete($configvalues{$configname});
Jesse Keating 2f82dda
	} else {
Jesse Keating 2f82dda
		print "$_";
Jesse Keating 2f82dda
	}
Jesse Keating 2f82dda
}
Jesse Keating 2f82dda
Jesse Keating 2f82dda
# now print the new values from the overridden configfile
Jesse Keating 2f82dda
my $counter = 0;
Jesse Keating 2f82dda
Jesse Keating 2f82dda
while ($counter < $configcounter) {
Jesse Keating 2f82dda
	my $configname = $configoptions[$counter];
Jesse Keating 2f82dda
	if (exists($configvalues{$configname})) {
Jesse Keating 2f82dda
		print "$configvalues{$configname}";
Jesse Keating 2f82dda
	}
Jesse Keating 2f82dda
	$counter++;
Jesse Keating 2f82dda
}
Jesse Keating 2f82dda
Jesse Keating 2f82dda
1;