summaryrefslogtreecommitdiffstats
path: root/khtml/misc/makeattrs
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /khtml/misc/makeattrs
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'khtml/misc/makeattrs')
-rw-r--r--khtml/misc/makeattrs113
1 files changed, 113 insertions, 0 deletions
diff --git a/khtml/misc/makeattrs b/khtml/misc/makeattrs
new file mode 100644
index 000000000..48a02c045
--- /dev/null
+++ b/khtml/misc/makeattrs
@@ -0,0 +1,113 @@
+#!/usr/bin/perl
+#
+# This file is part of the KDE libraries
+#
+# Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de)
+# Copyright (C) 2003 Dirk Mueller (mueller@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., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+#----------------------------------------------------------------------------
+#
+# KDE HTML Widget -- Script to generate khtmlattrs.c and khtmlattrs.h
+#
+open IN, "htmlattrs.in"
+ or die "Can't open in\n";
+open header, ">htmlattrs.h"
+ or die "Can't open header\n";
+open out, ">htmlattrs.gperf"
+ or die "Can't open out\n";
+
+print out "%{\n/* This file is automatically generated from
+#htmlattrs.in by makeattrs, do not edit */\n#include \"htmlattrs.h\"\n%}\n";
+print out "struct attrs {\n int name;\n int id;\n};\n%%\n";
+
+print header "/* This file is automatically generated from
+htmlattrs.in by makeattrs, do not edit */\n/* Copyright 1999 Lars Knoll */\n\n#ifndef HTML_ATTRS_H\n#define HTML_ATTRS_H\n\n#include \"dom/dom_string.h\"\n#include <kdemacros.h>\nusing namespace DOM;\n\n";
+
+my %amap = ();
+my $last_ci_attr = 0;
+$num = 0;
+while (<IN>) {
+ next if /^#/;
+ next if /^\s*$/;
+ /END_CI_ATTR/ and $last_ci_attr = $num and next;
+
+ chomp;
+ $attr = $_;
+ $num = $num + 1;
+
+ $up = uc($attr);
+ $amap{$up} = $num;
+ push(@a, $up);
+ $up =~ s/-/_/;
+ print out $attr . ", ATTR_" . $up . "\n";
+
+ print header "#define ATTR_" . $up . " " . $num . "\n";
+
+ }
+close(IN);
+
+print header "#define ATTR_LAST_ATTR $num\n";
+print header "#define ATTR_LAST_CI_ATTR $last_ci_attr\n";
+
+print out "%%\n";
+close out;
+
+print header "const char* getAttrName(unsigned short id) KDE_NO_EXPORT;\n";
+
+print header "\n#endif\n";
+close header;
+
+my $result = system("/bin/sh", "-c", "gperf -c -a -L 'ANSI-C' -P -G -D -E -C -o -t -k '*' -NfindAttr -Hhash_attr -Wwordlist_attr -Qspool_attr -s 2 htmlattrs.gperf > htmlattrs.c");
+if ($result) {
+ unlink "htmlattrs.c";
+ exit $result;
+}
+system("/bin/sh", "-c", 'perl -pi -e "s/\"\"}/\"\", 0}/g" htmlattrs.c');
+
+# read the hash mappings (is there a better way?)
+my %hmap = ();
+open(IN, "<htmlattrs.c");
+while(<IN>) {
+ if (/spool_attr_str(\d+), ATTR_([\w_]+)/) {
+ $hmap{$amap{$2}} = $1;
+ }
+}
+close(IN);
+
+open(OUT, ">>htmlattrs.c");
+print OUT "\n\nstatic const unsigned short attrList[] = {\n";
+print OUT " 65535,\n";
+
+while(defined ($line = shift @a))
+{
+ my $l = $line;
+ $l =~ y/-/_/;
+
+ die if !length($hmap{$amap{$l}});
+
+ print OUT " " .$hmap{$amap{$l}}.",\n";
+}
+print OUT " 65535\n};\n\n";
+print OUT "const char* KDE_NO_EXPORT getAttrName(unsigned short id)\n{\n";
+print OUT " if (!id || id > TOTAL_KEYWORDS) return \"\";\n";
+print OUT " return spool_attr + wordlist_attr[attrList[id]].name;\n";
+print OUT "}\n";
+
+
+
+