1563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#!/usr/bin/perl
2563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
3563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Copyright (C) 2007 Apple Inc.  All rights reserved.
4dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# Copyright (C) 2010 Holger Hans Peter Freyther
5563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
6563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Redistribution and use in source and binary forms, with or without
7563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# modification, are permitted provided that the following conditions
8563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# are met:
9563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
10563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 1.  Redistributions of source code must retain the above copyright
11563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     notice, this list of conditions and the following disclaimer. 
12563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 2.  Redistributions in binary form must reproduce the above copyright
13563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     notice, this list of conditions and the following disclaimer in the
14563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     documentation and/or other materials provided with the distribution. 
15563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 3.  Neither the name of Apple Inc. ("Apple") nor the names of
16563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     its contributors may be used to endorse or promote products derived
17563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     from this software without specific prior written permission. 
18563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
19563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
30cad810f21b803229eb11403f9209855525a25d57Steve Block# This script updates Tools/iExploder/iExploder-1.3.2/htdocs/*.in based on
31dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# WebCore/css/CSSPropertyNames.in, WebCore/html/HTMLTagNames.in
32dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# and WebCore/html/HTMLAttributeNames.in
33563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
34563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse warnings;
35563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse strict;
36563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
37563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse FindBin;
38563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse lib $FindBin::Bin;
39dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockuse VCSUtils;
40563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse webkitdirs;
41563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
42563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse File::Spec;
43563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
44dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blocksub generateEntityListFromFile($);
45dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blocksub readiExploderFile($);
46dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blocksub update($$);
47dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blocksub writeiExploderFile($@);
48563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
49dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockupdate("cssproperties.in", "css/CSSPropertyNames.in");
50dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockupdate("htmlattrs.in", "html/HTMLAttributeNames.in");
51dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockupdate("htmltags.in", "html/HTMLTagNames.in");
52563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkprint "Successfully updated!\n";
53563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
54563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkexit 0;
55563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
56dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blocksub generateEntityListFromFile($)
57563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark{
58dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my ($filename) = @_;
59dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
60dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my $revision = svnRevisionForDirectory(dirname($filename));
61dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my $path = File::Spec->abs2rel($filename, sourceDir());
62563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    my $result = "# From WebKit svn r" . $revision . " (" . $path . ")\n";
63563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
64dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my @entities = ();
65dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my $in_namespace = 0;
66563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
67dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    open(IN, $filename) || die "$!";
68563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    while (my $l = <IN>) {
69563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        chomp $l;
70dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        if ($l =~ m/^namespace=\"/) {
71dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            $in_namespace = 1;
72dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        } elsif ($in_namespace && $l =~ m/^$/) {
73dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            $in_namespace = 0;
74dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        }
75dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
76dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        next if $in_namespace;
77563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark        next if $l =~ m/^\s*#/ || $l =~ m/^\s*$/;
78dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
79dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        # For HTML Tags that can have additional information
80dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        if ($l =~ m/ /) {
81dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            my @split = split / /, $l;
82dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            $l = $split[0]
83dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        }
84dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
85dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        push(@entities, $l);
86563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    }
87563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    close(IN);
88563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
89dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    $result .= join("\n", sort { $a cmp $b } @entities) . "\n\n";
90563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
91563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    return $result;
92563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
93563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
94dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blocksub readiExploderFile($)
95563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark{
96dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my ($filename) = @_;
97dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
98563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    my @sections = ();
99563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    local $/ = "\n\n";
100563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
101dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    open(IN, $filename) || die "$!";
102563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    @sections = <IN>;
103563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    close(IN);
104563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
105563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    return @sections;
106563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
107563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
108dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blocksub update($$)
109563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark{
110dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my ($iexploderPath, $webcorePath) = @_;
111563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
112cad810f21b803229eb11403f9209855525a25d57Steve Block    $iexploderPath = File::Spec->catfile(sourceDir(), "Tools", "iExploder", "iExploder-1.3.2", "htdocs", split("/", $iexploderPath));
113cad810f21b803229eb11403f9209855525a25d57Steve Block    $webcorePath = File::Spec->catfile(sourceDir(), "Source", "WebCore", split("/", $webcorePath));
114563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
115dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my @sections = readiExploderFile($iexploderPath);
116dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    $sections[0] = generateEntityListFromFile($webcorePath);
117dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    writeiExploderFile($iexploderPath, @sections);
118563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
119563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
120dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
121dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blocksub writeiExploderFile($@)
122563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark{
123dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    my ($filename, @sections) = @_;
124dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
125dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    open(OUT, "> $filename") || die "$!";
126563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    print OUT join("", @sections);
127563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    close(OUT);
128563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
129dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
130