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