makevalues   [plain text]


#   This file is part of the KDE libraries
#
#   Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
#
#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Library General Public
#   License as published by the Free Software Foundation; either
#   version 2 of the License, or (at your option) any later version.
#
#   This library is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   Library General Public License for more details.
#
#   You should have received a copy of the GNU Library General Public License
#   along with this library; see the file COPYING.LIB.  If not, write to
#   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#   Boston, MA 02111-1307, USA.
#
#----------------------------------------------------------------------------
#
#  KDE HTML Widget -- Script to generate CSSValueKeywords.c and CSSValueKeywords.h
#
grep "^[^\#]" CSSValueKeywords.in > CSSValueKeywords.strip

echo '%{' > CSSValueKeywords.gperf
echo '/* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */' >> CSSValueKeywords.gperf
echo '/* Copyright 1999 W. Bastian */' >> CSSValueKeywords.gperf
echo '#include "CSSValueKeywords.h"' >> CSSValueKeywords.gperf
echo '%}' >> CSSValueKeywords.gperf
echo 'struct css_value {' >> CSSValueKeywords.gperf
echo '    const char *name;' >> CSSValueKeywords.gperf
echo '    int id;' >> CSSValueKeywords.gperf
echo '};' >> CSSValueKeywords.gperf
echo '%%' >> CSSValueKeywords.gperf

cat CSSValueKeywords.strip | awk '{ do { prop = $0; gsub("-", "_"); print prop ", CSS_VAL_" toupper($0) } while (getline) }' >> CSSValueKeywords.gperf

echo '%%' >> CSSValueKeywords.gperf

echo '/* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */' > CSSValueKeywords.h
echo '/* Copyright 1998 W. Bastian */' >> CSSValueKeywords.h
echo '#ifndef CSSVALUES_H' >> CSSValueKeywords.h
echo '#define CSSVALUES_H' >> CSSValueKeywords.h
echo 'WebCore::String getValueName(unsigned short id);' >> CSSValueKeywords.h

cat CSSValueKeywords.strip | awk '{ \
i=1; \
print "#define CSS_VAL_INVALID 0"; \
print "#define CSS_VAL_MIN 1"; \
do { gsub("-", "_"); print "#define CSS_VAL_" toupper($0) " " i; i = i + 1 } while (getline); \
print ""; \
print "#define CSS_VAL_TOTAL " i \
}' >> CSSValueKeywords.h

gperf -L 'ANSI-C' -E -C -n -o -t -k '*' -NfindValue -Hhash_val -Wwordlist_value -D CSSValueKeywords.gperf > CSSValueKeywords.c || exit 1

echo '#endif' >> CSSValueKeywords.h

cat CSSValueKeywords.strip | awk '{ \
i=1; \
print "static const char * const valueList[] = {"; \
print "\"\","; \
do { print "\"" $0 "\", "; i = i + 1 } while (getline); \
print "    0"; \
print "};"; \
print "String getValueName(unsigned short id)"; \
print "{"; \
print "    if(id >= CSS_VAL_TOTAL || id == 0)"; \
print "      return String();";\
print "    else";\
print "      return String(valueList[id]);"; \
print "};"; \
print ""; \
}' >> CSSValueKeywords.c