hiromitsuhanada / rpms / kernel-rt

Forked from rpms/kernel-rt 4 years ago
Clone

Blame SOURCES/merge.pl

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