author | Zheng Shen <zheng.shen@nokia.com> |
Wed, 13 Oct 2010 16:27:55 +0800 | |
changeset 647 | 53d1ab72f5bc |
parent 626 | ac03b93ca9c4 |
permissions | -rw-r--r-- |
600 | 1 |
#!/usr/bin/perl |
2 |
||
3 |
use Getopt::Long; |
|
4 |
||
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
600
diff
changeset
|
5 |
use constant TOOL_VERSION=>"0.2"; |
600 | 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 = "checkepocroot.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 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
600
diff
changeset
|
68 |
if ($line =~ /[\\\/]epoc32[\\\/]/i) |
600 | 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"; |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
600
diff
changeset
|
74 |
if ($line =~ /EPOCROOT##[\\\/]?epoc32[\\\/]/i) |
600 | 75 |
{ |
76 |
print "Error: this line already contain EPOCROOT\n"; |
|
77 |
next; |
|
78 |
} |
|
79 |
if($convert) |
|
80 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
600
diff
changeset
|
81 |
$line =~ s-[\\\/]epoc32(?=[\\\/])-EPOCROOT##epoc32-ig; |
600 | 82 |
print "converted line is $line"; |
83 |
print LOG "converted line is $line"; |
|
84 |
} |
|
85 |
print "\n"; |
|
86 |
print LOG "\n"; |
|
87 |
} |
|
88 |
print DST $line if($convert); |
|
89 |
} |
|
90 |
close SRC; |
|
91 |
if($convert) |
|
92 |
{ |
|
93 |
close DST; |
|
94 |
||
95 |
unlink "$src"; |
|
96 |
rename ("$dst", "$src"); |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
sub print_usage |
|
101 |
{ |
|
102 |
print "\nCheckepocroot - Check epocroot tool V".TOOL_VERSION."\n"; |
|
103 |
print "Copyright (c) 2010 Nokia Corporation.\n\n"; |
|
104 |
print <<USAGE_EOF; |
|
105 |
Usage: |
|
106 |
checkepocroot.pl [-h] [-c] [-l <logfile>] <directory> |
|
107 |
||
108 |
Check oby/iby files cursively in the <directory>. |
|
109 |
When it find epoc32 without EPOCROOT## in the files, it will report the line in log file. If with -c option it will add EPOCROOT## to the epoc32. |
|
110 |
The <directory> is the directory contain all the oby/iby files. Usually it should be /epoc32/rom/ and it will be checked cursively. |
|
111 |
||
112 |
Options: |
|
113 |
-l <logfile> - the log file to record the log, |
|
114 |
if not specfied it is \"checkepocroot.log\" |
|
115 |
-h - displays this help |
|
116 |
-c - convert the back slash to forward slash. |
|
117 |
USAGE_EOF |
|
118 |
} |