linuxtorvalds / rpms / kernel

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