Update contrib.
2 # Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 # This component and the accompanying materials are made available
5 # under the terms of the License "Eclipse Public License v1.0"
6 # which accompanies this distribution, and is available
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 # Initial Contributors:
10 # Nokia Corporation - initial contribution.
15 # Created by Relja Arandjelovic
16 # relja.arandjelovic@symbian.com
17 # Used to check for occurrences of "C: , EDriveC and [<index>]='C' and report warnings about it into HTML file
19 # cdrive.pl -exclude=exclude.txt -excludedir=/common/generic/security/caf2/ -log=logfilename.htm path1 path2 ...
20 # log is created in $ENV{EPOCROOT}epoc32\\winscw\\c\\
21 # add -mytest option if the log should be stored in the execution directory
22 # (for example, if you are not using the script during overnight builds)
23 # exclude contains items formated as as follows (new line corresponds to new line in file):
26 # comment about why the warning should be excluded (may be in several lines, but with no line with only whice characters)
27 # line with only white characters
28 # NB: paths in cdrive.pl argumetns and filename in exclude list should be absolute paths
42 my $excludedir="_no_dir_";
49 sub TypeOfWarning($$$$){
50 my ($FileName,$FileIsTest,$linetext,$Warning)=@_;
52 $linetext=~ s/^\s*//; $linetext=~ s/\s*$//;
59 # check if in include list
62 foreach $ExcludeLine (@{$Exclude{$FileName}}){
63 if ($linetext eq $ExcludeLine) {
64 $$Warning="ignoredwarning";
79 my $PrevFileName="_no_file_";
82 my ($FileName,$linenumber,$linetext,$Warning)=@_;
85 $linetext=~ s/^\s*//; $linetext=~ s/\s*$//;
87 # convert special characters to HTML format
88 $linetext=~ s/&/&/sg;
89 $linetext=~ s/</</sg;
90 $linetext=~ s/>/>/sg;
93 if ($FileName ne $PrevFileName){
95 <tr><td colspan=\"4\" height=\"20\"> </td></tr>
96 <tr><td width=\"20\"></td><td colspan=\"3\">
103 <tr><td colspan=\"4\" height=\"10\"> </td></tr>
104 <tr class=\"$Warning\"><td width=\"20\"></td><td width=\"60\"></td><td colspan=\"2\">
105 Line number: $linenumber
107 <tr class=\"$Warning\"><td width=\"20\"></td><td width=\"60\"></td><td width=\"80\"></td><td>
112 $PrevFileName=$FileName;
118 my $prevDir="_no_previous_dir_";
124 if (lc($File::Find::dir) =~ /^$excludedir/) { return; }
125 if (lc($File::Find::dir) =~ /test/i) { return; }
126 if (lc($File::Find::dir) =~ /examples/i) { return; }
127 if (lc($File::Find::dir) =~ /tpkcs10/i) { return; }
128 if (lc($File::Find::dir) =~ /tocsp/i) { return; }
129 if (lc($File::Find::dir) =~ /referencedrmagent/i) { return; }
130 if (lc($File::Find::dir) =~ /dumpswicertstoretool/i) { return; }
131 if (!(lc($File::Find::name) =~ /\.(cpp|cxx|c\+\+|c|h)$/)){ return; }
133 # include in list of files to be searched only if not test code
134 # ie distribution policy doesn't include Reference/Test
135 if ($prevDir ne lc($File::Find::dir)){ # new dir => search for distribution.policy
137 my $policy="".($File::Find::dir)."/distribution.policy";
140 open (POLICY , "<$policy" );
142 if ($_ =~ /Reference\/Test/){
151 push(@ListOfFiles,lc($File::Find::name));
152 push(@FileIsTest,$isTest);
153 if ($isTest) { $nTests++; }
155 $prevDir=lc($File::Find::dir);
161 my ($FileName,$FileIsTest,$count,$countunique)=@_;
163 open(SOURCE,"<$FileName") or die ("Could not open file: $FileName");
165 my $prevCount=$$count;
166 my $line; my $templine; my $linenumber=1;
167 my $MultiLineComment=0;
168 my $MadeChangeDueToComments;
171 my $HTMLFirstWarning=1;
173 while ($line=<SOURCE>){
182 $MadeChangeDueToComments=0;
184 if ($MultiLineComment==0){
186 # remove text in // coments
187 $templine=~ s/(.*?)\/\/.*$/$1/;
188 # remove /* */ comments found in one line
189 $templine=~ s/\/\*.*\*\///g;
191 # if only /* then remove text after it and mark the start of comment
192 if ($templine=~ /^(.*?)\/\*/){
195 $MadeChangeDueToComments=1;
199 } else { # $MultiLineComment==1
202 if ($templine=~ /\*\/(.*)$/){
205 $MadeChangeDueToComments=1;
210 } while ($MadeChangeDueToComments==1);
211 # end of processing comments
214 if ($MultiLineComment==1 && $FirstLine==0) { next; } # skip checking if in comment
218 $templine=~ /["'][cC]:/ || # '" # need comment for correct highlighting in codewarrior
219 $templine=~ /EDriveC/ ||
220 $templine=~ /\[.+\]\s*=\s*'[cC]':/
224 TypeOfWarning($FileName,$FileIsTest,$line,\$Warning);
225 printHTML($FileName,$linenumber,$line,$Warning);
226 if ($Warning eq "warning") { $$count++; }
234 if ($prevCount<$$count) { $$countunique++; }
239 sub ReadExcludeList(){
245 #print "Exclude list file not specified\nCarrying on without an exclude list\n";
247 } elsif (!(-e $exclude)){
248 #print "Exclude list file doesn't exist!\nCarrying on without an exclude list\n";
253 my $line; my $FileName; my $LineText; my $justification;
255 open (EXCLUDE,"<$exclude");
258 $line=<EXCLUDE> or last;
259 $line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
263 $line=<EXCLUDE>; $line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
267 while($line=<EXCLUDE>){
268 $line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
269 if ($line eq "") { last;}
273 if ($justification==0){
274 #print "Not added to the excludion list since no justification found for:\n$FileName\n$LineText\n";
276 push(@{$Exclude{$FileName}},$LineText);
291 "exclude=s" => \$exclude ,
292 "excludedir=s" => \$excludedir, # one dir to be excluded from scaning (along wih its subdirs)
293 "log=s" => \$LogFileName,
294 "mytest" => \$MyTest # inteded for my personal testing (so that path is not the one for overnight testing)
297 $excludedir=~ s/\\/\//g; # convert \ into / so that it matches perl's path form
302 if ($MyTest==0){ # overnight
303 $LogFileName = "$ENV{EPOCROOT}epoc32\\winscw\\c\\".$LogFileName;
308 for ($iArgv=0;$iArgv<@ARGV;$iArgv++){
309 $ARGV[$iArgv]=~ s/\\/\//g; # convert \ into / so that it matches perl's path form
310 find(\&MakeList, ($ARGV[$iArgv]) );
314 open(HTML,">$LogFileName");
319 <title>CDrive warnings</title>
321 <style type=\'text/css\'>
323 background-color: #FFAAAA;
326 background-color: #90ffff;
329 background-color: #ffc060;
334 <table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">
338 my $count=0; my $countunique=0;
339 my $iList; my $nList=@ListOfFiles;
340 for ($iList=0;$iList<$nList;$iList++){
341 FindC($ListOfFiles[$iList],$FileIsTest[$iList],\$count,\$countunique);
345 print HTML "\n</table>\n";
347 my $total=$nList-$nTests;
348 # workaround in order to be reported to the standardised system
349 print HTML "<br><center>$countunique tests failed out of $total\n</center>\n";
356 #print "\n\tNumber of files:\t$nList\n";
357 #print "\n\tNumber of warnings:\t$count\n";
358 #print "\n\tNumber of unique warnings:\t$countunique\n";