webengine/osswebengine/WebCore/css/makevalues.pl
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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) 2007 Trolltech ASA
       
     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/#/);
       
    30   chomp $_;
       
    31   next if ($_ eq "");
       
    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/-/_/g;
       
    53   print GPERF $name . ", CSS_VAL_" . uc($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 WebCore::String getValueName(unsigned short id);
       
    66 
       
    67 #define CSS_VAL_INVALID 0
       
    68 #define CSS_VAL_MIN 1
       
    69 EOF
       
    70 
       
    71 my $i = 1;
       
    72 my $maxLen = 0;
       
    73 foreach my $name (@names) {
       
    74   my $id = $name;
       
    75   $id =~ s/-/_/g;
       
    76   print HEADER "#define CSS_VAL_" . uc($id) . " " . $i . "\n";
       
    77   $i = $i + 1;
       
    78   if (length($name) > $maxLen) {
       
    79     $maxLen = length($name);
       
    80   }
       
    81 }
       
    82 print HEADER "#define CSS_VAL_TOTAL " . $i . "\n";
       
    83 print HEADER "#endif\n";
       
    84 close HEADER;
       
    85 
       
    86 system("gperf -L ANSI-C -E -C -n -o -t --key-positions=\"*\" -NfindValue -Hhash_val -Wwordlist_value -D CSSValueKeywords.gperf > CSSValueKeywords.c");
       
    87 
       
    88 open C, ">>CSSValueKeywords.c" || die "Could not open CSSValueKeywords.c for writing";
       
    89 print C  "static const char * const valueList[] = {\n";
       
    90 print C  "\"\",\n";
       
    91 foreach my $name (@names) {
       
    92   print C  "\"" . $name . "\", \n";
       
    93 }
       
    94 print C << "EOF";
       
    95     0
       
    96 };
       
    97 String getValueName(unsigned short id)
       
    98 {
       
    99     if (id >= CSS_VAL_TOTAL || id <= 0)
       
   100         return String();
       
   101     return String(valueList[id]);
       
   102 }
       
   103 EOF
       
   104 
       
   105 close C;
       
   106