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