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 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, "<CSSValueKeywords.in" || die "Could not open CSSValueKeywords.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, ">CSSValueKeywords.gperf" || die "Could not open CSSValueKeywords.gperf for writing";
38print GPERF << "EOF";
39%{
40/* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
41
42#include \"CSSValueKeywords.h\"
43#include \"HashTools.h\"
44#include <string.h>
45
46namespace WebCore {
47%}
48%struct-type
49struct Value;
50%omit-struct-type
51%language=C++
52%readonly-tables
53%compare-strncmp
54%define class-name CSSValueKeywordsHash
55%define lookup-function-name findValueImpl
56%define hash-function-name value_hash_function
57%define word-array-name value_word_list
58%enum
59%%
60EOF
61
62foreach my $name (@names) {
63  my $id = $name;
64  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
65  print GPERF $name . ", CSSValue" . $id . "\n";
66}
67
68print GPERF << "EOF";
69%%
70static const char* const valueList[] = {
71    "",
72EOF
73
74foreach my $name (@names) {
75  print GPERF "    \"" . $name . "\",\n";
76}
77
78print GPERF << "EOF";
79    0
80};
81
82const Value* findValue(register const char* str, register unsigned int len)
83{
84    return CSSValueKeywordsHash::findValueImpl(str, len);
85}
86
87const char* getValueName(unsigned short id)
88{
89    if (id >= numCSSValueKeywords || id <= 0)
90        return 0;
91    return valueList[id];
92}
93
94} // namespace WebCore
95EOF
96close GPERF;
97
98
99open HEADER, ">CSSValueKeywords.h" || die "Could not open CSSValueKeywords.h for writing";
100print HEADER << "EOF";
101/* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
102
103#ifndef CSSValueKeywords_h
104#define CSSValueKeywords_h
105
106#include <string.h>
107
108namespace WebCore {
109
110const int CSSValueInvalid = 0;
111EOF
112
113my $i = 1;
114my $maxLen = 0;
115foreach my $name (@names) {
116  my $id = $name;
117  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
118  print HEADER "const int CSSValue" . $id . " = " . $i . ";\n";
119  $i = $i + 1;
120  if (length($name) > $maxLen) {
121    $maxLen = length($name);
122  }
123}
124print HEADER "const int numCSSValueKeywords = " . $i . ";\n";
125print HEADER "const size_t maxCSSValueKeywordLength = " . $maxLen . ";\n";
126print HEADER << "EOF";
127
128const char* getValueName(unsigned short id);
129
130} // namespace WebCore
131
132#endif // CSSValueKeywords_h
133
134EOF
135close HEADER;
136
137system("gperf --key-positions=\"*\" -D -n -s 2 CSSValueKeywords.gperf > CSSValueKeywords.cpp") == 0 || die "calling gperf failed: $?";
138