1#!/usr/bin/perl -w 2 3# Copyright (C) 2006, 2007, 2008 Apple 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 JavaScriptCore, WebCore, and WebKit. 30 31use strict; 32use FindBin; 33use lib $FindBin::Bin; 34use webkitdirs; 35use File::Find; 36 37setConfiguration(); 38chdirWebKit(); 39 40my %words; 41 42# find all files we want to process 43 44my @paths; 45find(\&wanted, "JavaScriptCore"); 46find(\&wanted, "JavaScriptGlue"); 47find(\&wanted, "WebCore"); 48find(\&wanted, "WebKit"); 49 50sub wanted 51{ 52 my $file = $_; 53 54 if ($file eq "icu") { 55 $File::Find::prune = 1; 56 return; 57 } 58 59 if ($file =~ /^\../) { 60 $File::Find::prune = 1; 61 return; 62 } 63 64 return if $file =~ /^ChangeLog/; 65 return if -d $file; 66 67 push @paths, $File::Find::name; 68} 69 70my %renames = ( 71 "parseURL" => "deprecatedParseURL" 72); 73 74my %renamesContemplatedForTheFuture = ( 75 "DOMObject" => "JSDOMObject", 76 77 "runtimeObjectGetter" => "pluginElementGetter", 78 "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter", 79 "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot", 80 "runtimeObjectCustomPut" => "pluginElementCustomPut", 81 "runtimeObjectImplementsCall" => "pluginElementImplementsCall", 82 "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction", 83 84 "CLONE_CONTENTS" => "Clone", 85 "DELETE_CONTENTS" => "Delete", 86 "EXTRACT_CONTENTS" => "Extract", 87 88 "DateInstance" => "JSDate", 89 "ErrorInstance" => "JSError", 90 91 "KURL" => "URL", 92 "KURLCFNet" => "URLCF", 93 "KURLHash" => "URLHash", 94 "KURLMac" => "URLMac", 95 "KURL_h" => "URL_h", 96 97 "ThreadSafeSharedBase" => "ThreadSafeRefCountedBase", 98 "ThreadSafeShared" => "ThreadSafeRefCounted", 99 "TreeShared" => "TreeRefCounted", 100 101 "StringImpl" => "SharedString", 102 103 "RenderView" => "RenderViewport", 104 105 "ObjcFallbackObjectImp" => "ObjCFallbackObject", 106 "RuntimeObjectImp" => "ForeignObject", 107 108 "runtime_array" => "BridgedArray", 109 "runtime_method" => "BridgedFunction", 110 "runtime_object" => "BridgedObject", 111 "objc_runtime" => "ObjCBridge", 112 113 "equalIgnoringCase" => "equalFoldingCase", 114 115 "FTPDirectoryTokenizer" => "FTPDirectoryDocumentBuilder", 116 "HTMLTokenizer" => "HTMLDocumentBuilder", 117 "ImageTokenizer" => "ImageDocumentBuilder", 118 "PluginTokenizer" => "PluginDocumentBuilder", 119 "TextTokenizer" => "TextDocumentBuilder", 120 "Tokenizer" => "DocumentBuilder", 121 "Tokenizer_h" => "DocumentBuilder_h", 122 "XMLTokenizer" => "XMLDocumentBuilder", 123 "isHTMLTokenizer" => "isHTMLDocumentBuilder", 124 "m_tokenizer" => "m_builder", 125 "createTokenizer" => "createBuilder", 126 "tokenizerProcessedData" => "documentBuilderProcessedData", 127 128 "WTF_UNICODE_H" => "Unicode_h", 129 "WTF_UNICODE_ICU_H" => "UnicodeICU_h", 130 "WTF_UNICODE_QT4_H" => "UnicodeQt4_h", 131 "UnicodeIcu" => "UnicodeICU", 132 133 "m_invertibleCTM" => "m_transformIsInvertible", 134 135 "NativeFunctionWrapper_h" => "JSHostFunction_h", 136 "NativeFunctionWrapper" => "JSHostFunction", 137 "nativeFunctionThunk" => "hostFunctionThunk", 138 "nativeFunction" => "hostFunction", 139 "NativeFunction" => "HostFunction", 140); 141 142# rename files 143 144my %newFile; 145for my $file (sort @paths) { 146 my $f = $file; 147 $f = "$1$renames{$2}$3" if $f =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2}; 148 if ($f ne $file) { 149 $newFile{$file} = $f; 150 } 151} 152 153for my $file (sort @paths) { 154 if ($newFile{$file}) { 155 my $newFile = $newFile{$file}; 156 print "Renaming $file to $newFile\n"; 157 system "svn move $file $newFile"; 158 } 159} 160 161# change all file contents 162 163for my $file (sort @paths) { 164 $file = $newFile{$file} if $newFile{$file}; 165 my $contents; 166 { 167 local $/; 168 open FILE, $file or die; 169 $contents = <FILE>; 170 close FILE; 171 } 172 my $newContents = $contents; 173 174 for my $from (keys %renames) { 175 $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting 176 } 177 178 if ($newContents ne $contents) { 179 open FILE, ">", $file or die; 180 print FILE $newContents; 181 close FILE; 182 } 183} 184