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