* Makefile: Build DumpRenderTree too.
[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.
30
31 use strict;
32 use FindBin;
33 use lib $FindBin::Bin;
34 use webkitdirs;
35 use File::Find;
36
37 setConfiguration();
38 chdirWebKit();
39
40 my %words;
41
42 # find all files in WebCore we want to process
43
44 my @paths;
45 find(\&wanted, "JavaScriptCore");
46 find(\&wanted, "WebCore");
47
48 sub wanted
49 {
50     my $file = $_;
51
52     if ($file eq "icu") {
53         $File::Find::prune = 1;
54         return;
55     }
56
57     if ($file =~ /^\../) {
58         $File::Find::prune = 1;
59         return;
60     }
61
62     return if $file =~ /^ChangeLog/;
63     return if -d $file;
64
65     push @paths, $File::Find::name;
66 }
67
68 my %renames = (
69     "KHTML_NO_XBL" => "WEBKIT_NO_XBL",
70     "KHTML_XSLT" => "WEBKIT_XSLT",
71     "KURL" => "PlatformURL",
72     "KURLMac" => "PlatformURLMac",
73     "KURL_H_" => "PlatformURL_h",
74     "KXMLCORE_ASSERTIONS_H" => "WTF_Assertions_h",
75     "KXMLCORE_COMPILER_" => "WTF_COMPILER_",
76     "KXMLCORE_COMPILER_BORLAND" => "WTF_COMPILER_BORLAND",
77     "KXMLCORE_COMPILER_CYGWIN" => "WTF_COMPILER_CYGWIN",
78     "KXMLCORE_COMPILER_GCC" => "WTF_COMPILER_GCC",
79     "KXMLCORE_COMPILER_MSVC" => "WTF_COMPILER_MSVC",
80     "KXMLCORE_FAST_MALLOC_H" => "WTF_FastMalloc_h",
81     "KXMLCORE_FAST_MALLOC_INTERNAL_H" => "WTF_FastMallocInternal_h",
82     "KXMLCORE_FORWARD_H" => "WTF_Forward_h",
83     "KXMLCORE_HASH_COUNTED_SET_H" => "WTF_HashCountedSet_h",
84     "KXMLCORE_HASH_FUNCTIONS_H" => "WTF_HashFunctions_h",
85     "KXMLCORE_HASH_MAP_H" => "WTF_HashMap_h",
86     "KXMLCORE_HASH_SET_H" => "WTF_HashSet_h",
87     "KXMLCORE_HASH_TABLE_H" => "WTF_HashTable_h",
88     "KXMLCORE_HASH_TRAITS_H" => "WTF_HashTraits_h",
89     "KXMLCORE_LIST_REF_PTR_H" => "WTF_ListRefPtr_h",
90     "KXMLCORE_NONCOPYABLE" => "WTF_Noncopyable_h",
91     "KXMLCORE_OWN_ARRAY_PTR_H" => "WTF_OwnArrayPtr_h",
92     "KXMLCORE_OWN_PTR_H" => "WTF_OwnPtr_h",
93     "KXMLCORE_PASS_REF_PTR_H" => "WTF_PassRefPtr_h",
94     "KXMLCORE_PLATFORM_" => "WTF_PLATFORM_",
95     "KXMLCORE_PLATFORM_ARM" => "WTF_PLATFORM_ARM",
96     "KXMLCORE_PLATFORM_BIG_ENDIAN" => "WTF_PLATFORM_BIG_ENDIAN",
97     "KXMLCORE_PLATFORM_DARWIN" => "WTF_PLATFORM_DARWIN",
98     "KXMLCORE_PLATFORM_GDK" => "WTF_PLATFORM_GDK",
99     "KXMLCORE_PLATFORM_H" => "WTF_PLATFORM_H",
100     "KXMLCORE_PLATFORM_KDE" => "WTF_PLATFORM_KDE",
101     "KXMLCORE_PLATFORM_MAC" => "WTF_PLATFORM_MAC",
102     "KXMLCORE_PLATFORM_MIDDLE_ENDIAN" => "WTF_PLATFORM_MIDDLE_ENDIAN",
103     "KXMLCORE_PLATFORM_PPC" => "WTF_PLATFORM_PPC",
104     "KXMLCORE_PLATFORM_PPC64" => "WTF_PLATFORM_PPC64",
105     "KXMLCORE_PLATFORM_UNIX" => "WTF_PLATFORM_UNIX",
106     "KXMLCORE_PLATFORM_WIN" => "WTF_PLATFORM_WIN",
107     "KXMLCORE_PLATFORM_WIN_OS" => "WTF_PLATFORM_WIN_OS",
108     "KXMLCORE_PLATFORM_X86" => "WTF_PLATFORM_X86",
109     "KXMLCORE_PLATFORM_X86_64" => "WTF_PLATFORM_X86_64",
110     "KXMLCORE_PRETTY_FUNCTION" => "WTF_PRETTY_FUNCTION",
111     "KXMLCORE_PRIVATE_INLINE" => "WTF_PRIVATE_INLINE",
112     "KXMLCORE_REF_PTR_H" => "WTF_REF_PTR_H",
113     "KXMLCORE_UNUSED_PARAM" => "WTF_UNUSED_PARAM",
114     "KXMLCORE_USE_" => "WTF_USE_",
115     "KXMLCORE_USE_ICU_UNICODE" => "WTF_USE_ICU_UNICODE",
116     "KXMLCORE_USE_MULTIPLE_THREADS" => "WTF_USE_MULTIPLE_THREADS",
117     "KXMLCORE_USE_QT4_UNICODE" => "WTF_USE_QT4_UNICODE",
118     "KXMLCORE_VECTOR_H" => "WTF_Vector_h",
119     "KXMLCORE_VECTOR_TRAITS_H" => "WTF_VectorTraits_h",
120     "KX_FEATURE" => "WTF_FEATURE",
121     "allCachedObjects" => "allCachedResources",
122     "cachedObject" => "cachedResource",
123     "jScript" => "scriptProxy",
124     "jScriptEnabled" => "javaScriptEnabled",
125     "m_docObjects" => "m_resources",
126     "removeCachedObject" => "remove",
127     "StreamingTextDecoder" => "TextCodec",
128     "StreamingTextDecoderMac" => "TextCodecMac",
129     "StreamingTextDecoderICU" => "TextCodecICU",
130     "StreamingTextDecoder_h" => "TextCodec_h",
131     "StreamingTextDecoderMac_H" => "TextCodecMac_h",
132     "StreamingTextDecoderICU_H" => "TextCodecICU_h",
133     "Decoder" => "TextResourceDecoder",
134     "Decoder_h" => "TextResourceDecoder_h",
135 );
136
137 # rename files
138
139 my %newFile;
140 for my $file (sort @paths) {
141     my $f = $file;
142     $f = "$1$renames{$2}$3" if $f =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
143     if ($f ne $file) {
144         $newFile{$file} = $f;
145     }
146 }
147
148 for my $file (sort @paths) {
149     if ($newFile{$file}) {
150         my $newFile = $newFile{$file};
151         print "Renaming $file to $newFile\n";
152         system "svn move $file $newFile";
153     }
154 }
155
156 # change all file contents
157
158 for my $file (sort @paths) {
159     $file = $newFile{$file} if $newFile{$file};
160     my $contents;
161     {
162         local $/;
163         open FILE, $file or die;
164         $contents = <FILE>;
165         close FILE;
166     }
167     my $newContents = $contents;
168
169     for my $from (keys %renames) {
170         $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
171     }
172
173     if ($newContents ne $contents) {
174         open FILE, ">", $file or die;
175         print FILE $newContents;
176         close FILE;
177     }
178 }