1563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#!/usr/bin/perl -w
2563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
3563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
4563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
5563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Redistribution and use in source and binary forms, with or without
6563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# modification, are permitted provided that the following conditions
7563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# are met:
8563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
9563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 1.  Redistributions of source code must retain the above copyright
10563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     notice, this list of conditions and the following disclaimer. 
11563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 2.  Redistributions in binary form must reproduce the above copyright
12563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     notice, this list of conditions and the following disclaimer in the
13563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     documentation and/or other materials provided with the distribution. 
14563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     its contributors may be used to endorse or promote products derived
16563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     from this software without specific prior written permission. 
17563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
18563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
29563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Script to do file renaming.
30563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
31563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse strict;
32a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochuse File::Find;
33563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse FindBin;
34563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse lib $FindBin::Bin;
35563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse webkitdirs;
36a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochuse VCSUtils;
37563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
38563af33bc48281d19dce701398dbb88cb54fd7ecCary ClarksetConfiguration();
39563af33bc48281d19dce701398dbb88cb54fd7ecCary ClarkchdirWebKit();
40563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
41563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy %words;
42563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
43563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# find all files we want to process
44563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
45563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy @paths;
46cad810f21b803229eb11403f9209855525a25d57Steve Blockfind(\&wanted, "Source/JavaScriptCore");
47cad810f21b803229eb11403f9209855525a25d57Steve Blockfind(\&wanted, "Source/JavaScriptGlue");
48cad810f21b803229eb11403f9209855525a25d57Steve Blockfind(\&wanted, "Source/WebCore");
49563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkfind(\&wanted, "WebKit");
5065f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdochfind(\&wanted, "Source/WebKit2");
51563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
52563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarksub wanted
53563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark{
54563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    my $file = $_;
55563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
56563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    if ($file eq "icu") {
57563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        $File::Find::prune = 1;
58563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        return;
59563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    }
60563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
61563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    if ($file =~ /^\../) {
62563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        $File::Find::prune = 1;
63563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        return;
64563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    }
65563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
66563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    return if $file =~ /^ChangeLog/;
67563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    return if -d $file;
68563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
69563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    push @paths, $File::Find::name;
70563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
71563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
72563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy %renames = (
73563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark);
74563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
75563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy %renamesContemplatedForTheFuture = (
76563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark);
77563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
78563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# rename files
79563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
80563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy %newFile;
81563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkfor my $file (sort @paths) {
82563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    my $f = $file;
83563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    $f = "$1$renames{$2}" if $f =~ /^(.*\/)(\w+\.\w+)$/ && $renames{$2};
84563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    $newFile{$file} = $f if $f ne $file;
85563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
86563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
87563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkfor my $file (sort @paths) {
88563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    if ($newFile{$file}) {
89563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        my $newFile = $newFile{$file};
90563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        print "Renaming $file to $newFile\n";
91a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        scmMoveOrRenameFile($file, $newFile);
92563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    }
93563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
94563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
95563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# change all file contents
96563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
97563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkfor my $file (sort @paths) {
98563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    $file = $newFile{$file} if $newFile{$file};
99563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    my $contents;
100563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    {
101563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        local $/;
102563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        open FILE, $file or die;
103563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        $contents = <FILE>;
104563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        close FILE;
105563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    }
106563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    my $newContents = $contents;
107563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
108563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    for my $from (keys %renames) {
109563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        $newContents =~ s/\b\Q$from\E(?!\w)/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
110563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    }
111563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
112563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    if ($newContents ne $contents) {
113563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        open FILE, ">", $file or die;
114563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        print FILE $newContents;
115563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        close FILE;
116563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    }
117563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
118