comparison kdiff3/admin/bcheck.pl @ 14:415083d043f3

KDiff3 version 0.9.70
author joachim99
date Mon, 06 Oct 2003 19:19:11 +0000
parents
children efe33e938730
comparison
equal deleted inserted replaced
13:266aeefa1b11 14:415083d043f3
1 #!/usr/bin/perl -w
2
3 use DB_File;
4 use Fcntl ':flock';
5
6 if (!defined($ARGV[0])) {
7 print "usage: requires .class dump as parameter!\n";
8 exit;
9 }
10
11 sub bailout
12 {
13 untie %bcheckdb if(defined(%bcheckdb));
14
15 if(defined(MYLOCK)) {
16 flock MYLOCK, LOCK_UN;
17 close(MYLOCK);
18 }
19
20 print @_;
21 exit 5;
22 }
23
24 sub ask_user
25 {
26 my ($dbkey, $dbchunk) = @_;
27
28 if (defined($ENV{"BCHECK_UPDATE"})) {
29 $bcheckdb{$dbkey} = $dbchunk;
30 return;
31 }
32
33 &bailout("BC problem detected") if (! -t STDIN);
34
35 print "(I)gnore / (Q)uit / (U)pdate: ";
36
37 my $key;
38 while(defined(read STDIN, $key, 1)) {
39 $key = lc($key);
40
41 print "got: >$key<\n";
42
43 return if ($key eq 'i');
44
45 &bailout("BC problem. aborted") if ($key eq 'q');
46
47 if ($key eq 'u') {
48 $bcheckdb{$dbkey} = $dbchunk;
49 return;
50 }
51 print "\n(I)gnore / (Q)uit / (U)pdate: ";
52 }
53 }
54
55 sub diff_chunk($$)
56 {
57 my ($oldl, $newl) = @_;
58 my @old = split /^/m, $oldl;
59 my @new = split /^/m, $newl;
60 my $haschanges = 0;
61 my $max = $#old > $#new ? $#old : $#new;
62
63 die "whoops. key different" if ($old[0] ne $new[0]);
64
65 if ($#old != $#new) {
66 warn ("Structural difference.\n");
67 print @old;
68 print "-----------------------------------------------\n";
69 print @new;
70 $haschanges = 1;
71 return;
72 }
73
74 print $old[0];
75
76 my ($class) = ($old[0] =~ /^(?:Class |Vtable for )(\S+)/);
77
78 my $c = 1;
79 while ($c < $max) {
80 my ($o, $n) = ($old[$c], $new[$c]);
81 chomp $o;
82 chomp $n;
83 $c++;
84 next if ($o eq $n);
85
86 if(defined($class) and $n =~ /^(\d+\s+)\w+(::\S+\s*.*)$/) {
87 print "comparing >$n< against >$1$class$2<\n";
88 next if ($n eq "$1$class$2");
89 }
90
91 $haschanges = 1;
92
93 print "-$o\n+$n\n\n";
94 }
95
96 return $haschanges;
97 }
98
99 local $dblock = $ENV{"HOME"} . "/bcheck.lock";
100 my $dbfile = $ENV{"HOME"} . "/bcheck.db";
101 my $cdump = $ARGV[0];
102
103 die "file $cdump is not readable: $!" if (! -f $cdump);
104
105 # make sure the advisory lock exists
106 open(MYLOCK, ">$dblock");
107 print MYLOCK "";
108
109 flock MYLOCK, LOCK_EX;
110
111 tie %bcheckdb, 'DB_File', $dbfile;
112
113 my $chunk = "";
114
115 open (IN, "<$cdump") or die "cannot open $cdump: $!";
116 while (<IN>) {
117
118 chop;
119
120 s/0x[0-9a-fA-F]+/0x......../g;
121
122 $chunk .= $_ . "\n";
123
124 if(/^\s*$/) {
125 my @lines = split /^/m, $chunk;
126 my $key = $lines[0];
127 chomp $key;
128
129 if($key !~ /<anonymous struct>/ &&
130 $key !~ /<anonymous union>/) {
131 if(defined($bcheckdb{$key})) {
132 my $dbversion = $bcheckdb{$key};
133
134 if($dbversion ne $chunk) {
135 &ask_user($key, $chunk) if(&diff_chunk($dbversion, $chunk));
136 }
137 }
138 else {
139 $bcheckdb{$key} = $chunk;
140 print "NEW: $key\n";
141 }
142 }
143
144 $chunk = "";
145 next;
146 }
147
148 }
149 close(IN);
150
151 untie %bcheckdb;
152 flock MYLOCK, LOCK_UN;
153 close(MYLOCK);
154
155 exit 0;