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. 23use strict; 24use warnings; 25 26open NAMES, "<CSSValueKeywords.in" || die "Could not open CSSValueKeywords.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, ">CSSValueKeywords.gperf" || die "Could not open CSSValueKeywords.gperf for writing"; 37print GPERF << "EOF"; 38%{ 39/* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */ 40 41#include \"CSSValueKeywords.h\" 42%} 43struct css_value { 44 const char* name; 45 int id; 46}; 47%% 48EOF 49 50foreach my $name (@names) { 51 my $id = $name; 52 $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge; 53 print GPERF $name . ", CSSValue" . $id . "\n"; 54} 55print GPERF "%%\n"; 56close GPERF; 57 58open HEADER, ">CSSValueKeywords.h" || die "Could not open CSSValueKeywords.h for writing"; 59print 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 65const int CSSValueInvalid = 0; 66EOF 67 68my $i = 1; 69my $maxLen = 0; 70foreach 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} 79print HEADER "const int numCSSValueKeywords = " . $i . ";\n"; 80print HEADER "const size_t maxCSSValueKeywordLength = " . $maxLen . ";\n"; 81print HEADER << "EOF"; 82 83const char* getValueName(unsigned short id); 84 85#endif 86EOF 87close HEADER; 88 89system("gperf -L ANSI-C -E -C -n -o -t --key-positions=\"*\" -NfindValue -Hhash_val -Wwordlist_value -D CSSValueKeywords.gperf > CSSValueKeywords.c"); 90 91open C, ">>CSSValueKeywords.c" || die "Could not open CSSValueKeywords.c for writing"; 92print C "static const char * const valueList[] = {\n"; 93print C "\"\",\n"; 94foreach my $name (@names) { 95 print C "\"" . $name . "\", \n"; 96} 97print C << "EOF"; 98 0 99}; 100const char* getValueName(unsigned short id) 101{ 102 if (id >= numCSSValueKeywords || id <= 0) 103 return 0; 104 return valueList[id]; 105} 106EOF 107 108close C; 109