OSDN Git Service

am 3c54ece0: am 5dc34a85: activeDocumentLoader() causes crash in WebCoreFrameBridge.cpp
[android-x86/external-webkit.git] / 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 strict;
25 use warnings;
26
27 open NAMES, "<CSSValueKeywords.in" || die "Could not open CSSValueKeywords.in";
28 my @names = ();
29 while (<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 }
35 close(NAMES);
36
37 open GPERF, ">CSSValueKeywords.gperf" || die "Could not open CSSValueKeywords.gperf for writing";
38 print GPERF << "EOF";
39 %{
40 /* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
41
42 #include \"CSSValueKeywords.h\"
43 %}
44 %struct-type
45 struct Value {
46     const char* name;
47     int id;
48 };
49 %language=ANSI-C
50 %readonly-tables
51 %compare-strncmp
52 %define lookup-function-name findValue
53 %define hash-function-name value_hash_function
54 %define word-array-name value_word_list
55 %includes
56 %enum
57 %%
58 EOF
59
60 foreach my $name (@names) {
61   my $id = $name;
62   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
63   print GPERF $name . ", CSSValue" . $id . "\n";
64 }
65 print GPERF "%%\n";
66 close GPERF;
67
68 open HEADER, ">CSSValueKeywords.h" || die "Could not open CSSValueKeywords.h for writing";
69 print HEADER << "EOF";
70 /* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
71
72 #ifndef CSSValueKeywords_h
73 #define CSSValueKeywords_h
74
75 const int CSSValueInvalid = 0;
76 EOF
77
78 my $i = 1;
79 my $maxLen = 0;
80 foreach my $name (@names) {
81   my $id = $name;
82   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
83   print HEADER "const int CSSValue" . $id . " = " . $i . ";\n";
84   $i = $i + 1;
85   if (length($name) > $maxLen) {
86     $maxLen = length($name);
87   }
88 }
89 print HEADER "const int numCSSValueKeywords = " . $i . ";\n";
90 print HEADER "const size_t maxCSSValueKeywordLength = " . $maxLen . ";\n";
91 print HEADER << "EOF";
92
93 const char* getValueName(unsigned short id);
94
95 #endif // CSSValueKeywords_h
96 EOF
97 close HEADER;
98
99 system("gperf --key-positions=\"*\" -D -n -s 2 CSSValueKeywords.gperf > CSSValueKeywords.cpp") == 0 || die "calling gperf failed: $?";
100
101 open C, ">>CSSValueKeywords.cpp" || die "Could not open CSSValueKeywords.cpp for writing";
102 print C  "static const char * const valueList[] = {\n";
103 print C  "\"\",\n";
104 foreach my $name (@names) {
105   print C  "\"" . $name . "\", \n";
106 }
107 print C << "EOF";
108     0
109 };
110 const char* getValueName(unsigned short id)
111 {
112     if (id >= numCSSValueKeywords || id <= 0)
113         return 0;
114     return valueList[id];
115 }
116 EOF
117
118 close C;