summaryrefslogtreecommitdiffstats
path: root/scripts/configdiff.pl
blob: 848d8df0fb2c0a9c4e43331192eca15b8def5503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/perl

my @args=@ARGV;
my @configoptions;
my @configvalues;
my @alreadyprinted;
my $configcounter = 0;

# first, read the override file

open (FILE,"$args[0]") || die "Could not open $args[0]";
while (<FILE>) {
	my $str = $_;
	if (/\# ([\w]+) is not set/) {
		$configoptions[$configcounter] = $1;
		$configvalues[$configcounter] = $str;
		$alreadprinted[$configcounter] = 0;
		$configcounter ++;
	} else {
		if (/([\w]+)=/) {
			$configoptions[$configcounter] = $1;
			$configvalues[$configcounter] = $str;
			$alreadprinted[$configcounter] = 0;
			$configcounter ++;
		} else {
			$configoptions[$configcounter] = "$_";
			$configvalues[$configcounter] = $str;
			$alreadprinted[$configcounter] = 0;
			$configcounter ++;
		}
	}
};

# now, read and output the entire configfile, except for the overridden
# parts... for those the new value is printed.
# O(N^2) algorithm so if this is slow I need to look at it later

open (FILE2,"$args[1]") || die "Could not open $args[1]";
while (<FILE2>) {
	my $nooutput;
	my $counter;
	my $configname="$_";
	my $match;

	if (/\# ([\w]+) is not set/) {
		$configname = $1;
	} else {
		if (/([\w]+)=/) {
			$configname  = $1;
		} 
	}

	$counter = 0;
	$nooutput = 0;
	$match = 0;
#	print "C : $configname";
	while ($counter < $configcounter) {	
		if ("$configname" eq "$configoptions[$counter]") {	
			if ( ("$_" eq "$configvalues[$counter]") || ("$configname" eq "") ) {
				$match = 1;
			} else {
				$alreadyprinted[$configcounter] = 1;
				print "$_";
				$match = 1;
			}
		}
		$counter++;
	}
	if ($match == 0) {
		print "$_";
	}

}


1;