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