Home | History | Annotate | Download | only in css
      1 #! /usr/bin/perl
      2 #
      3 #   This file is part of the WebKit project
      4 #
      5 #   Copyright (C) 1999 Waldo Bastian (bastian (at] 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 (at] 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 #include \"HashTools.h\"
     44 #include <string.h>
     45 
     46 namespace WebCore {
     47 %}
     48 %struct-type
     49 struct Value;
     50 %omit-struct-type
     51 %language=C++
     52 %readonly-tables
     53 %compare-strncmp
     54 %define class-name CSSValueKeywordsHash
     55 %define lookup-function-name findValueImpl
     56 %define hash-function-name value_hash_function
     57 %define word-array-name value_word_list
     58 %enum
     59 %%
     60 EOF
     61 
     62 foreach my $name (@names) {
     63   my $id = $name;
     64   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
     65   print GPERF $name . ", CSSValue" . $id . "\n";
     66 }
     67 
     68 print GPERF << "EOF";
     69 %%
     70 static const char* const valueList[] = {
     71     "",
     72 EOF
     73 
     74 foreach my $name (@names) {
     75   print GPERF "    \"" . $name . "\",\n";
     76 }
     77 
     78 print GPERF << "EOF";
     79     0
     80 };
     81 
     82 const Value* findValue(register const char* str, register unsigned int len)
     83 {
     84     return CSSValueKeywordsHash::findValueImpl(str, len);
     85 }
     86 
     87 const char* getValueName(unsigned short id)
     88 {
     89     if (id >= numCSSValueKeywords || id <= 0)
     90         return 0;
     91     return valueList[id];
     92 }
     93 
     94 } // namespace WebCore
     95 EOF
     96 close GPERF;
     97 
     98 
     99 open HEADER, ">CSSValueKeywords.h" || die "Could not open CSSValueKeywords.h for writing";
    100 print HEADER << "EOF";
    101 /* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
    102 
    103 #ifndef CSSValueKeywords_h
    104 #define CSSValueKeywords_h
    105 
    106 #include <string.h>
    107 
    108 namespace WebCore {
    109 
    110 const int CSSValueInvalid = 0;
    111 EOF
    112 
    113 my $i = 1;
    114 my $maxLen = 0;
    115 foreach my $name (@names) {
    116   my $id = $name;
    117   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
    118   print HEADER "const int CSSValue" . $id . " = " . $i . ";\n";
    119   $i = $i + 1;
    120   if (length($name) > $maxLen) {
    121     $maxLen = length($name);
    122   }
    123 }
    124 print HEADER "const int numCSSValueKeywords = " . $i . ";\n";
    125 print HEADER "const size_t maxCSSValueKeywordLength = " . $maxLen . ";\n";
    126 print HEADER << "EOF";
    127 
    128 const char* getValueName(unsigned short id);
    129 
    130 } // namespace WebCore
    131 
    132 #endif // CSSValueKeywords_h
    133 
    134 EOF
    135 close HEADER;
    136 
    137 system("gperf --key-positions=\"*\" -D -n -s 2 CSSValueKeywords.gperf > CSSValueKeywords.cpp") == 0 || die "calling gperf failed: $?";
    138