600
|
1 |
#!/usr/bin/perl
|
|
2 |
|
|
3 |
use Getopt::Long;
|
|
4 |
|
|
5 |
use constant TOOL_VERSION=>"0.1";
|
|
6 |
|
|
7 |
my $help;
|
|
8 |
my $dir;
|
|
9 |
my $convert;
|
|
10 |
my $logfile;
|
|
11 |
&processcmdline();
|
|
12 |
|
|
13 |
open (LOG, ">$logfile") or die "cannot open log file $logfile\n";
|
|
14 |
&checkdir($dir);
|
|
15 |
close LOG;
|
|
16 |
|
|
17 |
sub processcmdline
|
|
18 |
{
|
|
19 |
GetOptions("h" => \$help, "l=s" => \$logfile, "c" => \$convert);
|
|
20 |
|
|
21 |
if ($help)
|
|
22 |
{
|
|
23 |
print_usage();
|
|
24 |
exit 0;
|
|
25 |
}
|
|
26 |
$logfile = "checkincludeslash.log" if (!defined $logfile);
|
|
27 |
|
|
28 |
$dir = shift @ARGV;
|
|
29 |
if (!defined $dir || !-d $dir)
|
|
30 |
{
|
|
31 |
print_usage();
|
|
32 |
die "\nERROR: directory missing!!\n" if (!defined $dir);
|
|
33 |
die "\nERROR: directory $dir does not exist!!\n" if (!-d $dir);
|
|
34 |
}
|
|
35 |
}
|
|
36 |
|
|
37 |
sub checkdir
|
|
38 |
{
|
|
39 |
my $path = shift;
|
|
40 |
return if (!-d $path);
|
|
41 |
opendir(DIR,$path);
|
|
42 |
my @entries = readdir(DIR);
|
|
43 |
closedir(DIR);
|
|
44 |
my $entry;
|
|
45 |
foreach $entry (@entries) {
|
|
46 |
next if (($entry eq ".") || ($entry eq ".."));
|
|
47 |
my $item = "$path/$entry";
|
|
48 |
if (-d $item) {
|
|
49 |
&checkdir($item);
|
|
50 |
}else {
|
|
51 |
next if ($entry !~ /.*\.[a-z]by$/i);
|
|
52 |
|
|
53 |
&convobyfile($item, "$item.bak");
|
|
54 |
}
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
sub convobyfile
|
|
59 |
{
|
|
60 |
my $src = shift;
|
|
61 |
my $dst = shift;
|
|
62 |
open (SRC, "<$src");
|
|
63 |
open (DST, ">$dst") if($convert);
|
|
64 |
|
|
65 |
my $line;
|
|
66 |
while($line = <SRC>)
|
|
67 |
{
|
|
68 |
if ($line =~ /#\s*include\s*(<|\")(.*\\.*)(>|\")/)
|
|
69 |
{
|
|
70 |
print "Found content in file $src\n";
|
|
71 |
print LOG "Found content in file $src\n";
|
|
72 |
print "current line is $line";
|
|
73 |
print LOG "current line is $line";
|
|
74 |
if($convert)
|
|
75 |
{
|
|
76 |
my $path = $2;
|
|
77 |
my $pathorg = $path;
|
|
78 |
$pathorg =~ s-\\-\\\\-g;
|
|
79 |
$path =~ s-\\-\/-g;
|
|
80 |
$line =~ s-$pathorg-$path-g;
|
|
81 |
print "converted line is $line";
|
|
82 |
print LOG "converted line is $line";
|
|
83 |
}
|
|
84 |
print "\n";
|
|
85 |
print LOG "\n";
|
|
86 |
}
|
|
87 |
print DST $line if($convert);
|
|
88 |
}
|
|
89 |
close SRC;
|
|
90 |
if($convert)
|
|
91 |
{
|
|
92 |
close DST;
|
|
93 |
|
|
94 |
unlink "$src";
|
|
95 |
rename ("$dst", "$src");
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
sub print_usage
|
|
100 |
{
|
|
101 |
print "\nCheckincludeslash - Check back slash tool V".TOOL_VERSION."\n";
|
|
102 |
print "Copyright (c) 2010 Nokia Corporation.\n\n";
|
|
103 |
print <<USAGE_EOF;
|
|
104 |
Usage:
|
|
105 |
checkincludeslash.pl [-h] [-c] [-l <logfile>] <directory>
|
|
106 |
|
|
107 |
Check oby/iby files cursively in the <directory>.
|
|
108 |
When it find back slash in include line in the files like \"\#include <dir\\file>\",
|
|
109 |
it will report the line in log file. If with -c option it will convert the back slash
|
|
110 |
to forward slash like \"\#include <dir/file>\".
|
|
111 |
The <directory> is the directory contain all the oby/iby files.
|
|
112 |
Usually it should be /epoc32/rom/ and it will be checked cursively.
|
|
113 |
|
|
114 |
Options:
|
|
115 |
-l <logfile> - the log file to record the log,
|
|
116 |
if not specfied it is \"checkincludeslash.log\"
|
|
117 |
-h - displays this help
|
|
118 |
-c - convert the back slash to forward slash.
|
|
119 |
USAGE_EOF
|
|
120 |
} |