Roland McGrath 11487c5
#! /usr/bin/perl
Roland McGrath 11487c5
Roland McGrath 11487c5
my @args=@ARGV;
Roland McGrath 11487c5
my @configoptions;
Roland McGrath 11487c5
my @configvalues;
Roland McGrath 11487c5
my @common;
Roland McGrath 11487c5
my $configcounter = 0;
Roland McGrath 11487c5
Roland McGrath 11487c5
# first, read the 1st file
Roland McGrath 11487c5
Roland McGrath 11487c5
open (FILE,"$args[0]") || die "Could not open $args[0]";
Roland McGrath 11487c5
while (<FILE>) {
Roland McGrath 11487c5
	my $str = $_;
Roland McGrath 11487c5
	if (/\# ([\w]+) is not set/) {
Roland McGrath 11487c5
		$configoptions[$configcounter] = $1;
Roland McGrath 11487c5
		$configvalues[$configcounter] = $str;
Roland McGrath 11487c5
		$common[$configcounter] = 1;
Roland McGrath 11487c5
		$configcounter ++;
Roland McGrath 11487c5
	} else {
Roland McGrath 11487c5
		if (/([\w]+)=/) {
Roland McGrath 11487c5
			$configoptions[$configcounter] = $1;
Roland McGrath 11487c5
			$configvalues[$configcounter] = $str;
Roland McGrath 11487c5
			$common[$configcounter] = 1;
Roland McGrath 11487c5
			$configcounter ++;
Roland McGrath 11487c5
		} else {
Roland McGrath 11487c5
			$configoptions[$configcounter] = "foobarbar";
Roland McGrath 11487c5
			$configvalues[$configcounter] = $str;
Roland McGrath 11487c5
			$common[$configcounter] = 1;
Roland McGrath 11487c5
			$configcounter ++;
Roland McGrath 11487c5
		}
Roland McGrath 11487c5
	}
Roland McGrath 11487c5
};
Roland McGrath 11487c5
Roland McGrath 11487c5
# now, read all configfiles and see of the options match the initial one.
Roland McGrath 11487c5
# if not, mark it not common
Roland McGrath 11487c5
my $cntr=1;
Roland McGrath 11487c5
Roland McGrath 11487c5
Roland McGrath 11487c5
while ($cntr < @ARGV) {
Roland McGrath 11487c5
	open (FILE,$args[$cntr]) || die "Could not open $args[$cntr]";	
Roland McGrath 11487c5
	while (<FILE>) {
Roland McGrath 11487c5
		my $nooutput;
Roland McGrath 11487c5
		my $counter;
Roland McGrath 11487c5
		my $configname;
Roland McGrath 11487c5
Roland McGrath 11487c5
		if (/\# ([\w]+) is not set/) {
Roland McGrath 11487c5
			$configname = $1;
Roland McGrath 11487c5
		} else {
Roland McGrath 11487c5
			if (/([\w]+)=/) {
Roland McGrath 11487c5
				$configname  = $1;
Roland McGrath 11487c5
			} 
Roland McGrath 11487c5
		}
Roland McGrath 11487c5
Roland McGrath 11487c5
		$counter = 0;
Roland McGrath 11487c5
		$nooutput = 0;
Roland McGrath 11487c5
		while ($counter < $configcounter) {	
Roland McGrath 11487c5
			if ("$configname" eq "$configoptions[$counter]") {	
Roland McGrath 11487c5
				if ("$_" eq "$configvalues[$counter]") {
Roland McGrath 11487c5
					1;
Roland McGrath 11487c5
				} else {
Roland McGrath 11487c5
					$common[$counter] = 0;
Roland McGrath 11487c5
				}
Roland McGrath 11487c5
			}
Roland McGrath 11487c5
			$counter++;
Roland McGrath 11487c5
		}
Roland McGrath 11487c5
	}
Roland McGrath 11487c5
Roland McGrath 11487c5
	$cntr++;
Roland McGrath 11487c5
}
Roland McGrath 11487c5
Roland McGrath 11487c5
# now print the common values
Roland McGrath 11487c5
my $counter = 0;
Roland McGrath 11487c5
Roland McGrath 11487c5
while ($counter < $configcounter) {	
Roland McGrath 11487c5
	if ($common[$counter]!=0) {
Roland McGrath 11487c5
		print "$configvalues[$counter]";
Roland McGrath 11487c5
	}
Roland McGrath 11487c5
	$counter++;
Roland McGrath 11487c5
}
Roland McGrath 11487c5
Roland McGrath 11487c5
1;
Roland McGrath 11487c5