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 = ();
29while (<NAMES>) {
30  next if (m/(^#)|(^\s*$)/);
31  # Input may use a different EOL sequence than $/, so avoid chomp.
32  $_ =~ s/[\r\n]+$//g;
33  push @names, $_;
34}
35close(NAMES);
36
37open GPERF, ">CSSPropertyNames.gperf" || die "Could not open CSSPropertyNames.gperf for writing";
38print GPERF << "EOF";
39%{
40/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
41#include \"CSSPropertyNames.h\"
42#include \"HashTools.h\"
43#include <string.h>
44
45namespace WebCore {
46%}
47%struct-type
48struct Property;
49%omit-struct-type
50%language=C++
51%readonly-tables
52%global-table
53%compare-strncmp
54%define class-name CSSPropertyNamesHash
55%define lookup-function-name findPropertyImpl
56%define hash-function-name propery_hash_function
57%define word-array-name property_wordlist
58%enum
59%%
60EOF
61
62foreach my $name (@names) {
63  my $id = $name;
64  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
65  print GPERF $name . ", CSSProperty" . $id . "\n";
66}
67
68print GPERF<< "EOF";
69%%
70const Property* findProperty(register const char* str, register unsigned int len)
71{
72    return CSSPropertyNamesHash::findPropertyImpl(str, len);
73}
74
75const char* getPropertyName(CSSPropertyID id)
76{
77    if (id < firstCSSProperty)
78        return 0;
79    int index = id - firstCSSProperty;
80    if (index >= numCSSProperties)
81        return 0;
82    return propertyNameStrings[index];
83}
84
85} // namespace WebCore
86EOF
87
88open HEADER, ">CSSPropertyNames.h" || die "Could not open CSSPropertyNames.h for writing";
89print HEADER << "EOF";
90/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
91
92#ifndef CSSPropertyNames_h
93#define CSSPropertyNames_h
94
95#include <string.h>
96
97namespace WebCore {
98
99enum CSSPropertyID {
100    CSSPropertyInvalid = 0,
101EOF
102
103my $first = 1001;
104my $i = 1001;
105my $maxLen = 0;
106foreach my $name (@names) {
107  my $id = $name;
108  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
109  print HEADER "    CSSProperty" . $id . " = " . $i . ",\n";
110  $i = $i + 1;
111  if (length($name) > $maxLen) {
112    $maxLen = length($name);
113  }
114}
115my $num = $i - $first;
116
117print HEADER "};\n\n";
118print HEADER "const int firstCSSProperty = $first;\n";
119print HEADER "const int numCSSProperties = $num;\n";
120print HEADER "const size_t maxCSSPropertyNameLength = $maxLen;\n";
121
122print HEADER "const char* const propertyNameStrings[$num] = {\n";
123foreach my $name (@names) {
124  print HEADER "\"$name\",\n";
125}
126print HEADER "};\n";
127
128print HEADER << "EOF";
129
130const char* getPropertyName(CSSPropertyID);
131
132} // namespace WebCore
133
134#endif // CSSPropertyNames_h
135
136EOF
137
138close HEADER;
139
140system("gperf --key-positions=\"*\" -D -n -s 2 CSSPropertyNames.gperf > CSSPropertyNames.cpp") == 0 || die "calling gperf failed: $?";
141