Merge "[CherryPick] [WEBGL] Rename WEBKIT_WEBGL_compressed_texture_s3tc to WEBGL_comp...
[framework/web/webkit-efl.git] / Source / WebCore / css / makevalues.pl
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, 2012 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.
24 use Getopt::Long;
25 use preprocessor;
26 use strict;
27 use warnings;
28
29 my $defines;
30 my $preprocessor;
31 GetOptions('defines=s' => \$defines,
32            'preprocessor=s' => \$preprocessor);
33
34 my @NAMES = applyPreprocessor("CSSValueKeywords.in", $defines, $preprocessor);
35
36 my %namesHash;
37 my @duplicates = ();
38
39 my @names = ();
40 foreach (@NAMES) {
41   next if (m/(^\s*$)/);
42   next if (/^#/);
43
44   # Input may use a different EOL sequence than $/, so avoid chomp.
45   $_ =~ s/[\r\n]+$//g;
46   # CSS values need to be lower case.
47   $_ = lc $_;
48   if (exists $namesHash{$_}) {
49     push @duplicates, $_;
50   } else {
51     $namesHash{$_} = 1;
52   }
53   push @names, $_;
54 }
55
56 if (@duplicates > 0) {
57     die 'Duplicate CSS value keywords  values: ', join(', ', @duplicates) . "\n";
58 }
59
60 open GPERF, ">CSSValueKeywords.gperf" || die "Could not open CSSValueKeywords.gperf for writing";
61 print GPERF << "EOF";
62 %{
63 /* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
64
65 #include \"CSSValueKeywords.h\"
66 #include \"HashTools.h\"
67 #include <string.h>
68
69 namespace WebCore {
70 %}
71 %struct-type
72 struct Value;
73 %omit-struct-type
74 %language=C++
75 %readonly-tables
76 %compare-strncmp
77 %define class-name CSSValueKeywordsHash
78 %define lookup-function-name findValueImpl
79 %define hash-function-name value_hash_function
80 %define word-array-name value_word_list
81 %enum
82 %%
83 EOF
84
85 foreach my $name (@names) {
86   my $id = $name;
87   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
88   print GPERF $name . ", CSSValue" . $id . "\n";
89 }
90
91 print GPERF << "EOF";
92 %%
93 static const char* const valueList[] = {
94     "",
95 EOF
96
97 foreach my $name (@names) {
98   print GPERF "    \"" . $name . "\",\n";
99 }
100
101 print GPERF << "EOF";
102     0
103 };
104
105 const Value* findValue(register const char* str, register unsigned int len)
106 {
107     return CSSValueKeywordsHash::findValueImpl(str, len);
108 }
109
110 const char* getValueName(unsigned short id)
111 {
112     if (id >= numCSSValueKeywords || id <= 0)
113         return 0;
114     return valueList[id];
115 }
116
117 } // namespace WebCore
118 EOF
119 close GPERF;
120
121
122 open HEADER, ">CSSValueKeywords.h" || die "Could not open CSSValueKeywords.h for writing";
123 print HEADER << "EOF";
124 /* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
125
126 #ifndef CSSValueKeywords_h
127 #define CSSValueKeywords_h
128
129 #include <string.h>
130
131 namespace WebCore {
132
133 enum CSSValueID {
134     CSSValueInvalid = 0,
135 EOF
136
137 my $i = 1;
138 my $maxLen = 0;
139 foreach my $name (@names) {
140   my $id = $name;
141   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
142   print HEADER "    CSSValue" . $id . " = " . $i . ",\n";
143   $i = $i + 1;
144   if (length($name) > $maxLen) {
145     $maxLen = length($name);
146   }
147 }
148
149 print HEADER "};\n\n";
150 print HEADER "const int numCSSValueKeywords = " . $i . ";\n";
151 print HEADER "const size_t maxCSSValueKeywordLength = " . $maxLen . ";\n";
152 print HEADER << "EOF";
153
154 const char* getValueName(unsigned short id);
155
156 } // namespace WebCore
157
158 #endif // CSSValueKeywords_h
159
160 EOF
161 close HEADER;
162
163 my $gperf = $ENV{GPERF} ? $ENV{GPERF} : "gperf";
164 system("\"$gperf\" --key-positions=\"*\" -D -n -s 2 CSSValueKeywords.gperf --output-file=CSSValueKeywords.cpp") == 0 || die "calling gperf failed: $?";