|
1 #!/usr/bin/perl |
|
2 |
|
3 # Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 # All rights reserved. |
|
5 # This component and the accompanying materials are made available |
|
6 # under the terms of "Eclipse Public License v1.0" |
|
7 # which accompanies this distribution, and is available |
|
8 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 # |
|
10 # Initial Contributors: |
|
11 # Nokia Corporation - initial contribution. |
|
12 # |
|
13 # Contributors: |
|
14 # |
|
15 # Description: |
|
16 # diffold.pl - Takes the output of testold.pl (or multiple concatenated outputs) and removed |
|
17 # entries from it which are present in a second output of testold.pl (or multiple |
|
18 # concatenated outputs). |
|
19 # |
|
20 # |
|
21 |
|
22 my ($file, $basefile) = readOpts(@ARGV); |
|
23 |
|
24 diffOld($file, $basefile); |
|
25 |
|
26 exit 0; |
|
27 |
|
28 sub readOpts(@) |
|
29 { |
|
30 my (@args) = @_; |
|
31 |
|
32 my @paths = (); |
|
33 |
|
34 foreach my $arg (@args) |
|
35 { |
|
36 if ($arg =~ /^-/) |
|
37 { |
|
38 if ((lc($arg) eq "--help") |
|
39 ||(lc($arg) eq "-h") |
|
40 ) |
|
41 { |
|
42 showHelp(); |
|
43 exit 0; |
|
44 } |
|
45 else |
|
46 { |
|
47 print STDERR "Option '$arg' not recognised.\n\n"; |
|
48 print STDERR "Try 'mergeold.pl --help' for help.\n"; |
|
49 exit 1; |
|
50 } |
|
51 } |
|
52 else |
|
53 { |
|
54 if (scalar(@paths)>=2) |
|
55 { |
|
56 print STDERR "Diffold accepts only two arguments.\n\n"; |
|
57 print STDERR "Try 'mergeold.pl --help' for help.\n"; |
|
58 exit 1; |
|
59 } |
|
60 else |
|
61 { |
|
62 push @paths, $arg; |
|
63 } |
|
64 } |
|
65 } |
|
66 |
|
67 if (scalar(@paths)<2) |
|
68 { |
|
69 print STDERR "Diffold must be given two files to compare.\n\n"; |
|
70 print STDERR "Try 'diffold.pl --help' for help.\n"; |
|
71 exit 1; |
|
72 } |
|
73 |
|
74 return ($paths[0], $paths[1]); |
|
75 } |
|
76 |
|
77 sub diffOld($$) |
|
78 { |
|
79 my ($file, $base) = @_; |
|
80 |
|
81 # Load $file |
|
82 |
|
83 my %files = (); |
|
84 |
|
85 open(FILE, $file); |
|
86 |
|
87 my $dir = undef; |
|
88 |
|
89 foreach my $line (<FILE>) |
|
90 { |
|
91 chomp($line); |
|
92 |
|
93 if ($line =~ /^\*/) |
|
94 { |
|
95 if ($line =~ /^\*DIR:/) |
|
96 { |
|
97 $dir = $line; |
|
98 $dir =~ s/^\*DIR:\s*//; |
|
99 |
|
100 $dir =~ s/[\/\\]*$//; # Remove trailing \/ |
|
101 } |
|
102 else |
|
103 { |
|
104 close(FILE); |
|
105 die "'$file' is not a valid input.\n('$line' not recognised)\n"; |
|
106 } |
|
107 } |
|
108 else |
|
109 { |
|
110 if (defined($dir)) |
|
111 { |
|
112 $line =~ s/^[\/\\]*//; # Remove preceding \/ |
|
113 |
|
114 $files{$dir."\\".$line}=1; |
|
115 } |
|
116 else |
|
117 { |
|
118 close(FILE); |
|
119 die "'$file' is not a valid input.\n(DIR must be set before '$line')\n"; |
|
120 } |
|
121 } |
|
122 } |
|
123 |
|
124 close(FILE); |
|
125 |
|
126 # Compare against $base |
|
127 |
|
128 open (BASE, $base); |
|
129 |
|
130 $dir = undef; |
|
131 |
|
132 foreach my $line (<BASE>) |
|
133 { |
|
134 chomp($line); |
|
135 |
|
136 if ($line =~ /^\*/) |
|
137 { |
|
138 if ($line =~ /^\*DIR:/) |
|
139 { |
|
140 $dir = $line; |
|
141 $dir =~ s/^\*DIR:\s*//; |
|
142 |
|
143 $dir =~ s/[\/\\]*$//; # Remove trailing \/ |
|
144 } |
|
145 else |
|
146 { |
|
147 close(BASE); |
|
148 die "'$base' is not a valid input.\n('$line' not recognised)\n"; |
|
149 } |
|
150 } |
|
151 else |
|
152 { |
|
153 if (defined($dir)) |
|
154 { |
|
155 $line =~ s/^[\/\\]*//; # Remove preceding \/ |
|
156 |
|
157 delete $files{$dir."\\".$line}; |
|
158 } |
|
159 else |
|
160 { |
|
161 close(BASE); |
|
162 die "'$base' is not a valid input.\n(DIR must be set before '$line')\n"; |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 close(BASE); |
|
168 |
|
169 # Output comparison |
|
170 |
|
171 my $root = undef; |
|
172 |
|
173 foreach my $file (keys(%files)) |
|
174 { |
|
175 if (defined($root)) |
|
176 { |
|
177 do |
|
178 { |
|
179 $file =~ s/[^\/\\]*[\/\\]?$//; # Remove last dir/filename |
|
180 } |
|
181 until ((index($root, $file) == 0) || ($file !~ /[\/\\]/)); |
|
182 |
|
183 if (index($root, $file) == 0) |
|
184 { |
|
185 $root = $file; |
|
186 } |
|
187 else |
|
188 { |
|
189 $root = ""; |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 $root = $file; |
|
195 $root =~ s/[^\/\\]*$// # Remove filename to leave path |
|
196 } |
|
197 } |
|
198 |
|
199 print "*DIR:$root\n"; |
|
200 |
|
201 my $lenroot = length($root); |
|
202 |
|
203 foreach my $file (sort(keys(%files))) |
|
204 { |
|
205 print substr($file, $lenroot)."\n"; |
|
206 } |
|
207 } |
|
208 |
|
209 sub showHelp() |
|
210 { |
|
211 print "diffold.pl [options] File Base-file\n"; |
|
212 print " - Takes file and removes any entries which are also\n"; |
|
213 print " in the base-file. Both files are assumed to be\n"; |
|
214 print " the output (or a concatenation of outputs) of testold.pl\n\n"; |
|
215 print "Options:\n"; |
|
216 print " --help or -h - Display this message\n\n"; |
|
217 } |
|
218 |