husy394 / rpms / kernel

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