|
1 # |
|
2 # Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "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". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 |
|
18 #------------------------------------------------------------------------------------ |
|
19 # Includes |
|
20 #------------------------------------------------------------------------------------ |
|
21 #use strict; |
|
22 use warnings; |
|
23 use Cwd; # for cwd |
|
24 use FindBin; # for FindBin:Bin |
|
25 use File::Path; # for mkpath |
|
26 use Date::Calc; |
|
27 |
|
28 my @files; |
|
29 |
|
30 FindFiles(".", "cpp", 1, \@files, ""); |
|
31 FindFiles(".", "h", 1, \@files, ""); |
|
32 |
|
33 foreach $file ( @files ) |
|
34 { |
|
35 my $found = 0; |
|
36 |
|
37 if(!open(FILE_HANDLE, "$file") ) |
|
38 { |
|
39 print("ERROR! Could not open file '$file'\n"); |
|
40 die; |
|
41 } |
|
42 |
|
43 my @array = <FILE_HANDLE>; |
|
44 close(FILE_HANDLE); |
|
45 |
|
46 foreach $line ( @array ) |
|
47 { |
|
48 if( $line =~ m/#include/ && $line =~ m/\\/ ) |
|
49 { |
|
50 print("\n\nCHANGING: $file\n"); |
|
51 $found = 1; |
|
52 if(!open(FILE_HANDLE2, ">$file") ) |
|
53 { |
|
54 print("ERROR! Could not open file for writing '$file'\n"); |
|
55 die; |
|
56 } |
|
57 |
|
58 rename $file,"$file.OLD"; |
|
59 # unlink $file; |
|
60 } |
|
61 |
|
62 } |
|
63 |
|
64 if( $found ) |
|
65 { |
|
66 foreach $line ( @array ) |
|
67 { |
|
68 if( $line =~ m/#include/ && $line =~ m/\\/ ) |
|
69 { |
|
70 print(" - old: $line"); |
|
71 $line =~ s/\\/\//g; |
|
72 print(" - new: $line"); |
|
73 } |
|
74 print FILE_HANDLE2 ($line); |
|
75 } |
|
76 |
|
77 close(FILE_HANDLE2); |
|
78 $found = 0; |
|
79 } |
|
80 |
|
81 } |
|
82 |
|
83 |
|
84 |
|
85 #------------------------------------------------------------------------------------ |
|
86 # FindFiles |
|
87 # Parameters: |
|
88 # $goDir, where to start finding |
|
89 # $fileSearch, filename search |
|
90 # $searchType, 0 = fullname search, 1 = filetype search |
|
91 # $refIncfiles, reference to array which will hold found files |
|
92 #------------------------------------------------------------------------------------ |
|
93 sub FindFiles |
|
94 { |
|
95 my ($godir, $fileSearch, $searchType, $refIncfiles, $fileFilter) = @_; |
|
96 |
|
97 my $startDir = cwd; |
|
98 |
|
99 chdir($godir); |
|
100 |
|
101 #print("Now in: " . cwd . "\n"); |
|
102 |
|
103 opendir(DIR, "."); |
|
104 my @filelist = sort(readdir(DIR)); |
|
105 closedir(DIR); |
|
106 |
|
107 foreach my $file(@filelist) |
|
108 { |
|
109 if($file eq "." or $file eq "..") {next}; |
|
110 |
|
111 if (-d $file) |
|
112 { |
|
113 FindFiles( $file, $fileSearch, $searchType, $refIncfiles, $fileFilter ); |
|
114 } else |
|
115 { |
|
116 if( ($file =~ m/$fileSearch/i and $searchType == 0 and $file =~m/$fileFilter/i) or ($file =~ m/$fileSearch$/i and $searchType == 1 and $file =~m/$fileFilter/i) ) |
|
117 { |
|
118 $file = cwd . "/" . $file; |
|
119 push @$refIncfiles, $file; |
|
120 #print("$file\n"); |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 chdir ($startDir); |
|
126 } |