-
Notifications
You must be signed in to change notification settings - Fork 3
/
linux-config-diff
executable file
·142 lines (127 loc) · 2.64 KB
/
linux-config-diff
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/perl -w
#
# © Copyright 2008 by Geert Uytterhoeven
#
# This file is subject to the terms and conditions of the GNU General Public
# License.
#
sub usage()
{
my $name = $0;
$name =~ s@.*/@@g;
die <<EOF;
Usage: $name [options] <config> ...
Valid options:
-h, --help Display this help
-s, --strict Do not treat unselectable as unselected
EOF
}
%symbols = ();
%settings = ();
%versions = ();
sub read_config()
{
my $file = $_[0];
open(IN, "<$file") or die "Cannot open config file $file,";
while (defined($line = <IN>)) {
chomp($line);
if (($symbol, $val) = $line =~ /(CONFIG_[A-Za-z0-9_]+)(.*)/) {
$val =~ s/^=//;
$val =~ s/ is not set/n/;
$symbols{$symbol} = $symbol;
$settings{$file}{$symbol} = $val;
} elsif (($version) = $line =~/([^\s]+) Kernel Configuration/) {
$versions{$file} = $version;
}
}
close(IN);
}
@files = ();
while (defined($ARGV[0])) {
$option = $ARGV[0];
last if not $option =~ /^-/;
if ($option eq '-h' or $option eq '--help') {
&usage();
} elsif ($option eq '-s' or $option eq '--strict') {
$strict = 1;
} elsif ($option eq '--') {
shift @ARGV;
last;
} else {
print STDERR "Unknown option $option\n";
&usage();
}
shift @ARGV;
}
$files = scalar(@ARGV);
&usage if !$files;
for $file (@ARGV) {
&read_config($file);
}
for $file (@ARGV) {
next if !defined($versions{$file});
$version = $versions{$file};
last;
}
if (defined($version)) {
for $file (@ARGV) {
next if !defined($versions{$file});
if ($versions{$file} ne $version) {
print "! $file: version $versions{$file} != $version\n";
}
}
}
$maxlen = 0;
for $symbol (keys %symbols) {
$len = length $symbol;
$maxlen = $len if $len > $maxlen;
}
for $file (@ARGV) {
$len = length $file;
$maxlen = $len if $len > $maxlen;
}
$i = 0;
for $file (reverse @ARGV) {
$dashes = "-" x ($maxlen + 2*($files - $i) - 1 - length $file);
print "! $file $dashes+";
print " |" x $i;
print "\n";
$i++;
}
print "!";
print " " x ($maxlen + 2);
for $file (reverse @ARGV) {
print " |";
}
print "\n";
for $symbol (sort keys %symbols) {
$same = ' ';
$val0 = $settings{$ARGV[0]}{$symbol};
if (!defined($val0)) {
$val0 = 'n';
}
for $file (@ARGV) {
$val = $settings{$file}{$symbol};
if (!defined($val)) {
if ($strict) {
$same = '!';
last;
}
$val = 'n';
}
if ($val ne $val0) {
$same = '!';
last;
}
}
printf "%s %-*s:", $same, $maxlen, $symbol;
for $file (@ARGV) {
if (defined($settings{$file}{$symbol})) {
$val = $settings{$file}{$symbol};
print " $val";
} else {
print " .";
}
}
print "\n";
}