0
|
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 |
#
|
|
9 |
# This library is free software; you can redistribute it and/or
|
|
10 |
# modify it under the terms of the GNU Library General Public
|
|
11 |
# License as published by the Free Software Foundation; either
|
|
12 |
# version 2 of the License, or (at your option) any later version.
|
|
13 |
#
|
|
14 |
# This library is distributed in the hope that it will be useful,
|
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 |
# Library General Public License for more details.
|
|
18 |
#
|
|
19 |
# You should have received a copy of the GNU Library General Public License
|
|
20 |
# along with this library; see the file COPYING.LIB. If not, write to
|
|
21 |
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
22 |
# Boston, MA 02110-1301, USA.
|
|
23 |
use strict;
|
|
24 |
use warnings;
|
|
25 |
|
|
26 |
open NAMES, "<CSSValueKeywords.in" || die "Could not open CSSValueKeywords.in";
|
|
27 |
my @names = ();
|
|
28 |
while (<NAMES>) {
|
|
29 |
next if (m/(^#)|(^\s*$)/);
|
|
30 |
# Input may use a different EOL sequence than $/, so avoid chomp.
|
|
31 |
$_ =~ s/[\r\n]+$//g;
|
|
32 |
push @names, $_;
|
|
33 |
}
|
|
34 |
close(NAMES);
|
|
35 |
|
|
36 |
open GPERF, ">CSSValueKeywords.gperf" || die "Could not open CSSValueKeywords.gperf for writing";
|
|
37 |
print GPERF << "EOF";
|
|
38 |
%{
|
|
39 |
/* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
|
|
40 |
|
|
41 |
#include \"CSSValueKeywords.h\"
|
|
42 |
%}
|
|
43 |
struct css_value {
|
|
44 |
const char* name;
|
|
45 |
int id;
|
|
46 |
};
|
|
47 |
%%
|
|
48 |
EOF
|
|
49 |
|
|
50 |
foreach my $name (@names) {
|
|
51 |
my $id = $name;
|
|
52 |
$id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
|
|
53 |
print GPERF $name . ", CSSValue" . $id . "\n";
|
|
54 |
}
|
|
55 |
print GPERF "%%\n";
|
|
56 |
close GPERF;
|
|
57 |
|
|
58 |
open HEADER, ">CSSValueKeywords.h" || die "Could not open CSSValueKeywords.h for writing";
|
|
59 |
print HEADER << "EOF";
|
|
60 |
/* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
|
|
61 |
|
|
62 |
#ifndef CSSValues_h
|
|
63 |
#define CSSValues_h
|
|
64 |
|
|
65 |
const int CSSValueInvalid = 0;
|
|
66 |
EOF
|
|
67 |
|
|
68 |
my $i = 1;
|
|
69 |
my $maxLen = 0;
|
|
70 |
foreach my $name (@names) {
|
|
71 |
my $id = $name;
|
|
72 |
$id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
|
|
73 |
print HEADER "const int CSSValue" . $id . " = " . $i . ";\n";
|
|
74 |
$i = $i + 1;
|
|
75 |
if (length($name) > $maxLen) {
|
|
76 |
$maxLen = length($name);
|
|
77 |
}
|
|
78 |
}
|
|
79 |
print HEADER "const int numCSSValueKeywords = " . $i . ";\n";
|
|
80 |
print HEADER "const size_t maxCSSValueKeywordLength = " . $maxLen . ";\n";
|
|
81 |
print HEADER << "EOF";
|
|
82 |
|
|
83 |
const char* getValueName(unsigned short id);
|
|
84 |
|
|
85 |
#endif
|
|
86 |
EOF
|
|
87 |
close HEADER;
|
|
88 |
|
|
89 |
system("gperf -L ANSI-C -E -C -n -o -t --key-positions=\"*\" -NfindValue -Hhash_val -Wwordlist_value -D CSSValueKeywords.gperf > CSSValueKeywords.c") == 0 || die "calling gperf failed: $?";
|
|
90 |
|
|
91 |
open C, ">>CSSValueKeywords.c" || die "Could not open CSSValueKeywords.c for writing";
|
|
92 |
print C "static const char * const valueList[] = {\n";
|
|
93 |
print C "\"\",\n";
|
|
94 |
foreach my $name (@names) {
|
|
95 |
print C "\"" . $name . "\", \n";
|
|
96 |
}
|
|
97 |
print C << "EOF";
|
|
98 |
0
|
|
99 |
};
|
|
100 |
const char* getValueName(unsigned short id)
|
|
101 |
{
|
|
102 |
if (id >= numCSSValueKeywords || id <= 0)
|
|
103 |
return 0;
|
|
104 |
return valueList[id];
|
|
105 |
}
|
|
106 |
EOF
|
|
107 |
|
|
108 |
close C;
|