• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#
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.
23use strict;
24use warnings;
25
26open NAMES, "<CSSPropertyNames.in" || die "Could not find CSSPropertyNames.in";
27my @names = ();
28while (<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}
34close(NAMES);
35
36open GPERF, ">CSSPropertyNames.gperf" || die "Could not open CSSPropertyNames.gperf for writing";
37print GPERF << "EOF";
38%{
39/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
40#include \"CSSPropertyNames.h\"
41%}
42struct props {
43    const char* name;
44    int id;
45};
46%%
47EOF
48
49foreach my $name (@names) {
50  my $id = $name;
51  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
52  print GPERF $name . ", CSSProperty" . $id . "\n";
53}
54print GPERF "%%\n";
55close GPERF;
56
57open HEADER, ">CSSPropertyNames.h" || die "Could not open CSSPropertyNames.h for writing";
58print HEADER << "EOF";
59/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
60
61#ifndef CSSPropertyNames_h
62#define CSSPropertyNames_h
63
64enum CSSPropertyID {
65    CSSPropertyInvalid = 0,
66EOF
67
68my $first = 1001;
69my $i = 1001;
70my $maxLen = 0;
71foreach my $name (@names) {
72  my $id = $name;
73  $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
74  print HEADER "    CSSProperty" . $id . " = " . $i . ",\n";
75  $i = $i + 1;
76  if (length($name) > $maxLen) {
77    $maxLen = length($name);
78  }
79}
80my $num = $i - $first;
81
82print HEADER "};\n\n";
83print HEADER "const int firstCSSProperty = $first;\n";
84print HEADER "const int numCSSProperties = $num;\n";
85print HEADER "const size_t maxCSSPropertyNameLength = $maxLen;\n";
86
87print HEADER << "EOF";
88
89const char* getPropertyName(CSSPropertyID);
90
91#endif
92EOF
93
94close HEADER;
95
96system("gperf -a -L ANSI-C -E -C -c -o -t --key-positions=\"*\" -NfindProp -Hhash_prop -Wwordlist_prop -D -s 2 CSSPropertyNames.gperf > CSSPropertyNames.cpp") == 0 || die "calling gperf failed: $?";
97
98open C, ">>CSSPropertyNames.cpp" || die "Could not open CSSPropertyNames.cpp for writing";
99print C "static const char * const propertyNameStrings[$num] = {\n";
100
101foreach my $name (@names) {
102  print C "\"$name\",\n";
103}
104
105print C << "EOF";
106};
107const 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}
116EOF
117
118close C;
119
120