* Scripts/do-webcore-rename: Another cut at renames. About ready to go (later...
[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, "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     "KHTMLSettings" => "Settings",
70     "KSSLKeyGen" => "SSLKeyGenerator",
71     "KWQCString" => "DeprecatedCString",
72     "KWQComboBox" => "PopUpButton",
73     "KWQComboBoxAdapter" => "WebCorePopUpButtonAdapter",
74     "KWQEditCommand" => "WebCoreEditCommand",
75     "KWQFileButton" => "FileButton",
76     "KWQFileButtonAdapter" => "WebCoreFileButtonAdapter",
77     "KWQFormData" => "FormDataMac",
78     "KWQKHTMLSettings" => "Settings",
79     "KWQKSSLKeyGen" => "SSLKeyGenerator",
80     "KWQLineEdit" => "TextField",
81     "KWQListBox" => "ListBox",
82     "KWQListBoxGroupLabel" => "ListBoxGroupLabel",
83     "KWQListBoxItem" => "ListBoxItem",
84     "KWQListBoxItemType" => "ListBoxItemType",
85     "KWQListBoxOption" => "ListBoxOption",
86     "KWQListBoxScrollView" => "WebCoreListBoxScrollView",
87     "KWQListBoxSeparator" => "ListBoxSeparator",
88     "KWQListBoxSeparator" => "ListBoxSeparator",
89     "KWQListNode" => "DeprecatedListNode",
90     "KWQNSControlSizeForFont" => "ControlSizeForFont",
91     "KWQNSTextAlignment" => "TextAlignment",
92     "KWQPTRQUEUE_H_" => "DeprecatedPtrQueue_h",
93     "KWQPageState" => "WebCorePageState",
94     "KWQPopUpButton" => "WebCorePopUpButton",
95     "KWQPopUpButtonCell" => "WebCorePopUpButtonCell",
96     "KWQPtrQueue" => "DeprecatedPtrQueue",
97     "KWQRegExpPrivate" => "Private",
98     "KWQRelease" => "HardRelease",
99     "KWQRetain" => "HardRetain",
100     "KWQSCROLLBAR_H_" => "ScrollBar_h",
101     "KWQScrollBar" => "WebCoreScrollBar",
102     "KWQScrollDirection" => "ScrollDirection",
103     "KWQScrollDocument" => "ScrollByDocument",
104     "KWQScrollDown" => "ScrollDown",
105     "KWQScrollGranularity" => "ScrollGranularity",
106     "KWQScrollLeft" => "ScrollLeft",
107     "KWQScrollLine" => "ScrollByLine",
108     "KWQScrollPage" => "ScrollByPage",
109     "KWQScrollRight" => "ScrollRight",
110     "KWQScrollUp" => "ScrollUp",
111     "KWQScrollWheel" => "ScrollByWheel",
112     "KWQSearchField" => "WebCoreSearchField",
113     "KWQSearchFieldCell" => "WebCoreSearchFieldCell",
114     "KWQSecureTextField" => "WebCoreSecureTextField",
115     "KWQSecureTextFieldCell" => "WebCoreSecureTextFieldCell",
116     "KWQSelectingNext" => "SelectingNext",
117     "KWQSelectingPrevious" => "SelectingPrevious",
118     "KWQSelectionDirection" => "SelectionDirection",
119     "KWQSlider" => "WebCoreSlider",
120     "KWQStringData" => "DeprecatedStringData",
121     "KWQTableView" => "WebCoreTableView",
122     "KWQTextEdit" => "TextBox",
123     "KWQTextFieldController" => "WebCoreTextFieldController",
124     "KWQTextFieldFormatter" => "WebCoreTextFieldFormatter",
125     "KWQTextStream" => "TextStream",
126     "KWQValueListPrivate" => "Private",
127     "KWQWMatrix" => "AffineTransform",
128     "KWQ_LIST_IMPL_H" => "DeprecatedPtrListImpl_h",
129     "MouseEventMac" => "PlatformMouseEventMac",
130     "QChar" => "DeprecatedChar",
131     "Q3CString" => "DeprecatedCString",
132     "Q3PtrList" => "DeprecatedPtrList",
133     "Q3PtrListIterator" => "DeprecatedPtrListIterator",
134     "Q3ValueList" => "DeprecatedValueList",
135     "QComboBox" => "PopUpButton",
136     "QConstString" => "DeprecatedConstString",
137     "QLineEdit" => "TextField",
138     "QListBox" => "ListBox",
139     "QMatrix" => "AffineTransform",
140     "QSTRING_H_" => "DeprecatedString_h",
141     "QScrollBar" => "ScrollBar",
142     "QSlider" => "Slider",
143     "QStringListMac" => "DeprecatedStringListMac",
144     "QStringMac" => "DeprecatedStringMac",
145     "QTextEdit" => "TextBox",
146     "QTextStream" => "TextStream",
147     "QTextStreamManipulator" => "TextStreamManipulator",
148     "QTextStreamSeparator" => "TextStreamSeparator",
149     "QWMatrix" => "AffineTransform",
150     "detachQSlider" => "detachSlider",
151     "initWithQSlider" => "initWithSlider",
152     "qmatrix" => "matrix",
153     "render_button" => "RenderButton",
154     "KCanvasContainer" => "RenderSVGContainer",
155     "RenderTextField" => "RenderTextControl",
156     "HTMLTextControlInnerElement" => "HTMLTextFieldInnerElement",
157     "KWQTextFieldKnowsAppKitSecrets" => "WebCoreTextField",
158     "KWQTextFieldAppKitSecrets" => "WebCoreTextField",
159     "_KWQ_numComposedCharacterSequences" => "_webcore_numComposedCharacterSequences",
160     "_KWQ_truncateToNumComposedCharacterSequences" => "_webcore_truncateToNumComposedCharacterSequences",
161     "_KWQ_currentEditor" => "_webcore_currentEditor",
162     "KWQInternal" => "WebCoreInternal",
163     "KWQLoader" => "LoaderFunctions",
164     "KWQFILEBUTTON_H" => "FileButton_h",
165     "KWQLISTBOX_H_" => "ListBox_h",
166     "KWQComboBoxKnowsAppKitSecrets" => "WebCorePopUpButtonKnowsAppKitSecrets",
167     "KWQServeSynchronousRequest" => "ServeSynchronousRequest",
168     "KWQCheckCacheObjectStatus" => "CheckCacheObjectStatus",
169     "KWQCheckIfReloading" => "CheckIfReloading",
170     "KWQIsResponseURLEqualToURL" => "IsResponseURLEqualToURL",
171     "KWQResponseURL" => "ResponseURL",
172     "KWQResponseMIMEType" => "ResponseMIMEType",
173     "KWQResponseIsMultipart" => "ResponseIsMultipart",
174     "KWQNumberOfPendingOrLoadingRequests" => "NumberOfPendingOrLoadingRequests",
175     "KWQCacheObjectExpiresTime" => "CacheObjectExpiresTime",
176     "KWQHeaderStringFromDictionary" => "HeaderStringFromDictionary",
177     "KWQResourceLoader" => "WebCoreResourceLoaderImp",
178     "KWQTableViewTypeSelectCallback" => "ListBoxTypeSelectCallback",
179     "KWQKIOGlobal" => "CacheControl",
180     "KWQVALUELIST_H_" => "DeprecatedValueListImpl_h",
181     "KWQCLIPBOARD_H_" => "ClipboardMac_h",
182     "KWQRetainNSRelease" => "HardRetainWithNSRelease",
183     "KWQCFAutorelease" => "HardAutorelease",
184     "QWMATRIX_H_" => "AffineTransform_h",
185     "QCOMBOBOX_H_" => "PopUpButton_h",
186     "QTEXTEDIT_H_" => "TextBox_h",
187     "QLineEdit_H" => "TextField_h",
188     "QTextStream_H" => "TextStream_h",
189     "ALLOC_QCHAR" => "WEBCORE_ALLOCATE_CHARACTERS",
190     "REALLOC_QCHAR" => "WEBCORE_REALLOCATE_CHARACTERS",
191     "QLIST_H_" => "DeprecatedPtrList_h",
192     "QS_INTERNAL_BUFFER_SIZE" => "WEBCORE_DS_INTERNAL_BUFFER_SIZE",
193     "QS_INTERNAL_BUFFER_CHARS" => "WEBCORE_DS_INTERNAL_BUFFER_CHARS",
194     "QS_INTERNAL_BUFFER_UCHARS" => "WEBCORE_DS_INTERNAL_BUFFER_UCHARS",
195     "QSTRING_DEBUG_ALLOCATIONS" => "WEBCORE_DS_DEBUG_ALLOCATIONS",
196     "QSTRINGLIST_H_" => "DeprecatedStringList_h",
197     "QVALUELIST_H_" => "DeprecatedValueList_h",
198     "QSIZEF_H_" => "FloatSize_h",
199     "QREGEXP_H_" => "RegularExpression_h",
200 );
201
202 # rename files
203
204 my %newFile;
205 for my $file (sort @paths) {
206     my $f = $file;
207     $f = "$1$renames{$2}$3" if $f =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
208     if ($f ne $file) {
209         $newFile{$file} = $f;
210     }
211 }
212
213 for my $file (sort @paths) {
214     if ($newFile{$file}) {
215         my $newFile = $newFile{$file};
216         print "Renaming $file to $newFile\n";
217         system "svn move $file $newFile";
218     }
219 }
220
221 # change all file contents
222
223 for my $file (sort @paths) {
224     $file = $newFile{$file} if $newFile{$file};
225     my $contents;
226     {
227         local $/;
228         open FILE, $file or die;
229         $contents = <FILE>;
230         close FILE;
231     }
232     my $newContents = $contents;
233
234     $newContents =~ s/\n\s*class\s+AffineTransform;\s*\n/\n/g;
235
236     for my $from (keys %renames) {
237         $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
238     }
239     $newContents =~ s/_KWQ_/_webcore_/g;
240
241     if ($newContents ne $contents) {
242         open FILE, ">", $file or die;
243         print FILE $newContents;
244         close FILE;
245     }
246 }