fix logic
[personal-kdelibs.git] / khtml / css / makeprop
blobdc4cf8544f9f81680cdc5cb6fda18ab91cc04873
1 #!/bin/sh
3 # This file is part of the KDE libraries
5 # Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
6 # (c) 2006 Nikolas Zimmermann <zimmermann@kde.org>
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Library General Public
10 # License as published by the Free Software Foundation; either
11 # version 2 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Library General Public License for more details.
18 # You should have received a copy of the GNU Library General Public License
19 # along with this library; see the file COPYING.LIB. If not, write to
20 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 # Boston, MA 02110-1301, USA.
23 #----------------------------------------------------------------------------
25 # KDE HTML Widget -- Script to generate cssproperties.c and cssproperties.h
27 num=1
28 NS=""
30 if [ -n "$1" ] # Eventually specified namespace prefix (ie. SVG)
31 then
32 num=10001 # Bigger than all properties from HTML CSS
33 NS=$1
36 prefix=`echo $NS | awk '{ do { print tolower($0) } while (getline) }'`
38 grep "^[^\#]" "$prefix"cssproperties.in > "$prefix"cssproperties.strip
40 echo -e '%{\n/* This file is automatically generated from '$prefix'cssproperties.in by makeprop, do not edit */\n/* Copyright 1999 W. Bastian */\n#include "'$prefix'cssproperties.h"\n%}\nstruct css_prop'$prefix' {\n const char *name;\n int id;\n};\n\nstatic const struct css_prop'$prefix' * findProp'$NS' (register const char *str, register unsigned int len);\n\n%%' > "$prefix"cssproperties.gperf
41 cat "$prefix"cssproperties.strip | awk '{ do { prop = $0; gsub("-", "_"); print prop ", '$NS'CSS_PROP_" toupper($0) } while (getline) }' >> "$prefix"cssproperties.gperf
42 echo '%%' >> "$prefix"cssproperties.gperf
43 echo -e '/* This file is automatically generated from '$prefix'cssproperties.in by makeprop, do not edit */\n/* Copyright 1998 W. Bastian */\n\n#ifndef '$NS'CSSPROPERTIES_H\n#define '$NS'CSSPROPERTIES_H\n\nDOM::DOMString get'$NS'PropertyName(unsigned short id) KDE_NO_EXPORT;\n' > "$prefix"cssproperties.h
44 cat "$prefix"cssproperties.strip | awk '{ \
45 i='$num'; \
46 print "#define '$NS'CSS_PROP_INVALID 0"; \
47 print "#define '$NS'CSS_PROP_MIN '$num'"; \
48 do { gsub("-", "_"); print "#define '$NS'CSS_PROP_" toupper($0) " " i; i = i + 1 } while (getline); \
49 print ""; \
50 print "#define '$NS'CSS_PROP_TOTAL " (i + 1 - '$num') \
51 }' >> "$prefix"cssproperties.h
52 perl -e 'my $max = 0; while (<>) { chomp; $max = length if $max < length; } print "const size_t max'$NS'CSSPropertyNameLength = $max;\n"' < "$prefix"cssproperties.strip >> "$prefix"cssproperties.h
54 gperf -a -L 'ANSI-C' -E -C -c -o -t -k '*' -NfindProp"$NS" -Hhash_prop"$prefix" -Wwordlist_prop"$prefix" -D -s 2 "$prefix"cssproperties.gperf > "$prefix"cssproperties.c || exit 1
55 echo -e '#endif\n' >> "$prefix"cssproperties.h
57 cat "$prefix"cssproperties.strip | awk '{ \
58 i=1; \
59 print "static const char * const propertyList'$NS'[] = {"; \
60 print "\"\","; \
61 do { print "\"" $0 "\", "; i = i + 1 } while (getline); \
62 print " 0"; \
63 print "};"; \
64 print "DOMString get'$NS'PropertyName(unsigned short id)"; \
65 print "{"; \
66 print " if(id >= '$NS'CSS_PROP_TOTAL || id == 0)"; \
67 print " return DOMString();";\
68 print " else";\
69 print " return DOMString(propertyList'$NS'[id - "('$num' - 1)"]);"; \
70 print "}"; \
71 print ""; \
72 }' >> "$prefix"cssproperties.c
74 perl -pi -e "s/id\ -\ 0/id/" "$prefix"cssproperties.c
75 perl -pi -e "s/TOTAL_KEYWORDS/${NS}TOTAL_KEYWORDS/g" "$prefix"cssproperties.c
76 perl -pi -e "s/MIN_WORD_LENGTH/${NS}MIN_WORD_LENGTH/g" "$prefix"cssproperties.c
77 perl -pi -e "s/MAX_WORD_LENGTH/${NS}MAX_WORD_LENGTH/g" "$prefix"cssproperties.c
78 perl -pi -e "s/MIN_HASH_VALUE/${NS}MIN_HASH_VALUE/g" "$prefix"cssproperties.c
79 perl -pi -e "s/MAX_HASH_VALUE/${NS}MAX_HASH_VALUE/g" "$prefix"cssproperties.c