1#! /usr/bin/perl
2#
3#   This file is part of the WebKit project
4#
5#   Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
6#   Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
7#   Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8#   Copyright (C) 2010 Andras Becsi (abecsi@inf.u-szeged.hu), University of Szeged
9#
10#   This library is free software; you can redistribute it and/or
11#   modify it under the terms of the GNU Library General Public
12#   License as published by the Free Software Foundation; either
13#   version 2 of the License, or (at your option) any later version.
14#
15#   This library is distributed in the hope that it will be useful,
16#   but WITHOUT ANY WARRANTY; without even the implied warranty of
17#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18#   Library General Public License for more details.
19#
20#   You should have received a copy of the GNU Library General Public License
21#   along with this library; see the file COPYING.LIB.  If not, write to
22#   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23#   Boston, MA 02110-1301, USA.
24use strict;
25use warnings;
26
27open NAMES, "<CSSPropertyNames.in" || die "Could not find CSSPropertyNames.in";
28my @names = ();
29my @aliases = ();
30while (<NAMES>) {
31  next if (m/(^#)|(^\s*$)/);
32  # Input may use a different EOL sequence than $/, so avoid chomp.
33  $_ =~ s/[\r\n]+$//g;
34  if ($_ =~ /=/) {
35    push @aliases, $_;
36  } else {
37    push @names, $_;
38  }
39}
40close(NAMES);
41
42open GPERF, ">CSSPropertyNames.gperf" || die "Could not open CSSPropertyNames.gperf for writing";
43print GPERF << "EOF";
44%{
45/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
46#include \"CSSPropertyNames.h\"
47#include \"HashTools.h\"
48#include <string.h>
49
50namespace WebCore {
51%}
52%struct-type
53struct Property;
54%omit-struct-type
55%language=C++
56%readonly-tables
57%global-table
58%compare-strncmp
59%define class-name CSSPropertyNamesHash
60%define lookup-function-name findPropertyImpl
61%define hash-function-name propery_hash_function
62%define word-array-name property_wordlist
63%enum
64%%
65EOF
66
67foreach my $name (@names) {
68  my $id = $name;
69  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
70  print GPERF $name . ", CSSProperty" . $id . "\n";
71}
72
73foreach my $alias (@aliases) {
74  $alias =~ /^([^\s]*)[\s]*=[\s]*([^\s]*)/;
75  my $name = $1;
76  my $id = $2;
77  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
78  print GPERF $name . ", CSSProperty" . $id . "\n";
79}
80
81print GPERF<< "EOF";
82%%
83const Property* findProperty(register const char* str, register unsigned int len)
84{
85    return CSSPropertyNamesHash::findPropertyImpl(str, len);
86}
87
88const char* getPropertyName(CSSPropertyID id)
89{
90    if (id < firstCSSProperty)
91        return 0;
92    int index = id - firstCSSProperty;
93    if (index >= numCSSProperties)
94        return 0;
95    return propertyNameStrings[index];
96}
97
98} // namespace WebCore
99EOF
100
101open HEADER, ">CSSPropertyNames.h" || die "Could not open CSSPropertyNames.h for writing";
102print HEADER << "EOF";
103/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
104
105#ifndef CSSPropertyNames_h
106#define CSSPropertyNames_h
107
108#include <string.h>
109
110namespace WebCore {
111
112enum CSSPropertyID {
113    CSSPropertyInvalid = 0,
114EOF
115
116my $first = 1001;
117my $i = 1001;
118my $maxLen = 0;
119foreach my $name (@names) {
120  my $id = $name;
121  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
122  print HEADER "    CSSProperty" . $id . " = " . $i . ",\n";
123  $i = $i + 1;
124  if (length($name) > $maxLen) {
125    $maxLen = length($name);
126  }
127}
128my $num = $i - $first;
129
130print HEADER "};\n\n";
131print HEADER "const int firstCSSProperty = $first;\n";
132print HEADER "const int numCSSProperties = $num;\n";
133print HEADER "const size_t maxCSSPropertyNameLength = $maxLen;\n";
134
135print HEADER "const char* const propertyNameStrings[$num] = {\n";
136foreach my $name (@names) {
137  print HEADER "\"$name\",\n";
138}
139print HEADER "};\n";
140
141print HEADER << "EOF";
142
143const char* getPropertyName(CSSPropertyID);
144
145} // namespace WebCore
146
147#endif // CSSPropertyNames_h
148
149EOF
150
151close HEADER;
152
153system("gperf --key-positions=\"*\" -D -n -s 2 CSSPropertyNames.gperf > CSSPropertyNames.cpp") == 0 || die "calling gperf failed: $?";
154