* Scripts/do-webcore-rename: Prepare for another round of renaming.
[WebKit-https.git] / WebKitTools / Scripts / do-webcore-rename
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #
9 # 1.  Redistributions of source code must retain the above copyright
10 #     notice, this list of conditions and the following disclaimer. 
11 # 2.  Redistributions in binary form must reproduce the above copyright
12 #     notice, this list of conditions and the following disclaimer in the
13 #     documentation and/or other materials provided with the distribution. 
14 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 #     its contributors may be used to endorse or promote products derived
16 #     from this software without specific prior written permission. 
17 #
18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 # Script to do a rename in WebCore. It's sort of a "one time use" script,
30 # but we might change it around for other uses later.
31
32 use strict;
33 use FindBin;
34 use lib $FindBin::Bin;
35 use webkitdirs;
36 use File::Find;
37
38 setConfiguration();
39 chdirWebKit();
40
41 my %words;
42
43 # find all files in WebCore we want to process
44
45 my @paths;
46 find(\&wanted, "JavaScriptCore");
47 find(\&wanted, "WebCore");
48
49 sub wanted
50 {
51     my $file = $_;
52
53     if ($file eq "icu") {
54         $File::Find::prune = 1;
55         return;
56     }
57
58     if ($file =~ /^\../) {
59         $File::Find::prune = 1;
60         return;
61     }
62
63     return if $file =~ /^ChangeLog/;
64     return if -d $file;
65
66     push @paths, $File::Find::name;
67 }
68
69 my %renames = (
70     "KHTML_NO_XBL" => "WEBKIT_NO_XBL",
71     "KHTML_XSLT" => "WEBKIT_XSLT",
72     "KURL" => "PlatformURL",
73     "KURLMac" => "PlatformURLMac",
74     "KURL_H_" => "PlatformURL_h",
75     "KXMLCORE_ASSERTIONS_H" => "WTF_Assertions_h",
76     "KXMLCORE_COMPILER_" => "WTF_COMPILER_",
77     "KXMLCORE_COMPILER_BORLAND" => "WTF_COMPILER_BORLAND",
78     "KXMLCORE_COMPILER_CYGWIN" => "WTF_COMPILER_CYGWIN",
79     "KXMLCORE_COMPILER_GCC" => "WTF_COMPILER_GCC",
80     "KXMLCORE_COMPILER_MSVC" => "WTF_COMPILER_MSVC",
81     "KXMLCORE_FAST_MALLOC_H" => "WTF_FastMalloc_h",
82     "KXMLCORE_FAST_MALLOC_INTERNAL_H" => "WTF_FastMallocInternal_h",
83     "KXMLCORE_FORWARD_H" => "WTF_Forward_h",
84     "KXMLCORE_HASH_COUNTED_SET_H" => "WTF_HashCountedSet_h",
85     "KXMLCORE_HASH_FUNCTIONS_H" => "WTF_HashFunctions_h",
86     "KXMLCORE_HASH_MAP_H" => "WTF_HashMap_h",
87     "KXMLCORE_HASH_SET_H" => "WTF_HashSet_h",
88     "KXMLCORE_HASH_TABLE_H" => "WTF_HashTable_h",
89     "KXMLCORE_HASH_TRAITS_H" => "WTF_HashTraits_h",
90     "KXMLCORE_LIST_REF_PTR_H" => "WTF_ListRefPtr_h",
91     "KXMLCORE_NONCOPYABLE" => "WTF_Noncopyable_h",
92     "KXMLCORE_OWN_ARRAY_PTR_H" => "WTF_OwnArrayPtr_h",
93     "KXMLCORE_OWN_PTR_H" => "WTF_OwnPtr_h",
94     "KXMLCORE_PASS_REF_PTR_H" => "WTF_PassRefPtr_h",
95     "KXMLCORE_PLATFORM_" => "WTF_PLATFORM_",
96     "KXMLCORE_PLATFORM_ARM" => "WTF_PLATFORM_ARM",
97     "KXMLCORE_PLATFORM_BIG_ENDIAN" => "WTF_PLATFORM_BIG_ENDIAN",
98     "KXMLCORE_PLATFORM_DARWIN" => "WTF_PLATFORM_DARWIN",
99     "KXMLCORE_PLATFORM_GDK" => "WTF_PLATFORM_GDK",
100     "KXMLCORE_PLATFORM_H" => "WTF_PLATFORM_H",
101     "KXMLCORE_PLATFORM_KDE" => "WTF_PLATFORM_KDE",
102     "KXMLCORE_PLATFORM_MAC" => "WTF_PLATFORM_MAC",
103     "KXMLCORE_PLATFORM_MIDDLE_ENDIAN" => "WTF_PLATFORM_MIDDLE_ENDIAN",
104     "KXMLCORE_PLATFORM_PPC" => "WTF_PLATFORM_PPC",
105     "KXMLCORE_PLATFORM_PPC64" => "WTF_PLATFORM_PPC64",
106     "KXMLCORE_PLATFORM_UNIX" => "WTF_PLATFORM_UNIX",
107     "KXMLCORE_PLATFORM_WIN" => "WTF_PLATFORM_WIN",
108     "KXMLCORE_PLATFORM_WIN_OS" => "WTF_PLATFORM_WIN_OS",
109     "KXMLCORE_PLATFORM_X86" => "WTF_PLATFORM_X86",
110     "KXMLCORE_PLATFORM_X86_64" => "WTF_PLATFORM_X86_64",
111     "KXMLCORE_PRETTY_FUNCTION" => "WTF_PRETTY_FUNCTION",
112     "KXMLCORE_PRIVATE_INLINE" => "WTF_PRIVATE_INLINE",
113     "KXMLCORE_REF_PTR_H" => "WTF_REF_PTR_H",
114     "KXMLCORE_UNUSED_PARAM" => "WTF_UNUSED_PARAM",
115     "KXMLCORE_USE_" => "WTF_USE_",
116     "KXMLCORE_USE_ICU_UNICODE" => "WTF_USE_ICU_UNICODE",
117     "KXMLCORE_USE_MULTIPLE_THREADS" => "WTF_USE_MULTIPLE_THREADS",
118     "KXMLCORE_USE_QT4_UNICODE" => "WTF_USE_QT4_UNICODE",
119     "KXMLCORE_VECTOR_H" => "WTF_Vector_h",
120     "KXMLCORE_VECTOR_TRAITS_H" => "WTF_VectorTraits_h",
121     "KX_FEATURE" => "WTF_FEATURE",
122     "allCachedObjects" => "allCachedResources",
123     "cachedObject" => "cachedResource",
124     "m_docObjects" => "m_resources",
125     "removeCachedObject" => "remove",
126 );
127
128 # rename files
129
130 my %newFile;
131 for my $file (sort @paths) {
132     my $f = $file;
133     $f = "$1$renames{$2}$3" if $f =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
134     if ($f ne $file) {
135         $newFile{$file} = $f;
136     }
137 }
138
139 for my $file (sort @paths) {
140     if ($newFile{$file}) {
141         my $newFile = $newFile{$file};
142         print "Renaming $file to $newFile\n";
143         system "svn move $file $newFile";
144     }
145 }
146
147 # change all file contents
148
149 for my $file (sort @paths) {
150     $file = $newFile{$file} if $newFile{$file};
151     my $contents;
152     {
153         local $/;
154         open FILE, $file or die;
155         $contents = <FILE>;
156         close FILE;
157     }
158     my $newContents = $contents;
159
160     for my $from (keys %renames) {
161         $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
162     }
163
164     if ($newContents ne $contents) {
165         open FILE, ">", $file or die;
166         print FILE $newContents;
167         close FILE;
168     }
169 }