WebCore/css/makeprop.pl
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 strict;
       
    25 use warnings;
       
    26 
       
    27 open NAMES, "<CSSPropertyNames.in" || die "Could not find CSSPropertyNames.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, ">CSSPropertyNames.gperf" || die "Could not open CSSPropertyNames.gperf for writing";
       
    38 print GPERF << "EOF";
       
    39 %{
       
    40 /* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
       
    41 #include \"CSSPropertyNames.h\"
       
    42 %}
       
    43 %struct-type
       
    44 struct Property {
       
    45     const char* name;
       
    46     int id;
       
    47 };
       
    48 %language=ANSI-C
       
    49 %readonly-tables
       
    50 %global-table
       
    51 %compare-strncmp
       
    52 %define lookup-function-name findProperty
       
    53 %define hash-function-name propery_hash_function
       
    54 %define word-array-name property_wordlist
       
    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 . ", CSSProperty" . $id . "\n";
       
    64 }
       
    65 print GPERF "%%\n";
       
    66 close GPERF;
       
    67 
       
    68 open HEADER, ">CSSPropertyNames.h" || die "Could not open CSSPropertyNames.h for writing";
       
    69 print HEADER << "EOF";
       
    70 /* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
       
    71 
       
    72 #ifndef CSSPropertyNames_h
       
    73 #define CSSPropertyNames_h
       
    74 
       
    75 enum CSSPropertyID {
       
    76     CSSPropertyInvalid = 0,
       
    77 EOF
       
    78 
       
    79 my $first = 1001;
       
    80 my $i = 1001;
       
    81 my $maxLen = 0;
       
    82 foreach my $name (@names) {
       
    83   my $id = $name;
       
    84   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
       
    85   print HEADER "    CSSProperty" . $id . " = " . $i . ",\n";
       
    86   $i = $i + 1;
       
    87   if (length($name) > $maxLen) {
       
    88     $maxLen = length($name);
       
    89   }
       
    90 }
       
    91 my $num = $i - $first;
       
    92 
       
    93 print HEADER "};\n\n";
       
    94 print HEADER "const int firstCSSProperty = $first;\n";
       
    95 print HEADER "const int numCSSProperties = $num;\n";
       
    96 print HEADER "const size_t maxCSSPropertyNameLength = $maxLen;\n";
       
    97 
       
    98 print HEADER << "EOF";
       
    99 
       
   100 const char* getPropertyName(CSSPropertyID);
       
   101 
       
   102 #endif // CSSPropertyNames_h
       
   103 
       
   104 EOF
       
   105 
       
   106 close HEADER;
       
   107 
       
   108 system("gperf --key-positions=\"*\" -D -n -s 2 CSSPropertyNames.gperf > CSSPropertyNames.cpp") == 0 || die "calling gperf failed: $?";
       
   109 
       
   110 open C, ">>CSSPropertyNames.cpp" || die "Could not open CSSPropertyNames.cpp for writing";
       
   111 print C "static const char * const propertyNameStrings[$num] = {\n";
       
   112 
       
   113 foreach my $name (@names) {
       
   114   print C "\"$name\",\n";
       
   115 }
       
   116 
       
   117 print C << "EOF";
       
   118 };
       
   119 const char* getPropertyName(CSSPropertyID id)
       
   120 {
       
   121     if (id < firstCSSProperty)
       
   122         return 0;
       
   123     int index = id - firstCSSProperty;
       
   124     if (index >= numCSSProperties)
       
   125         return 0;
       
   126     return propertyNameStrings[index];
       
   127 }
       
   128 EOF
       
   129 
       
   130 close C;
       
   131