dingjian / rpms / kernel-rt

Forked from rpms/kernel-rt 3 years ago
Clone

Blame SOURCES/merge.pl

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