fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / khtml / misc / makeattrs
blob48a02c045b57ca38bfe864ebbabe528a455dd42f
1 #!/usr/bin/perl
3 # This file is part of the KDE libraries
5 # Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de)
6 # Copyright (C) 2003 Dirk Mueller (mueller@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 khtmlattrs.c and khtmlattrs.h
27 open IN, "htmlattrs.in"
28 or die "Can't open in\n";
29 open header, ">htmlattrs.h"
30 or die "Can't open header\n";
31 open out, ">htmlattrs.gperf"
32 or die "Can't open out\n";
34 print out "%{\n/* This file is automatically generated from
35 #htmlattrs.in by makeattrs, do not edit */\n#include \"htmlattrs.h\"\n%}\n";
36 print out "struct attrs {\n int name;\n int id;\n};\n%%\n";
38 print header "/* This file is automatically generated from
39 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";
41 my %amap = ();
42 my $last_ci_attr = 0;
43 $num = 0;
44 while (<IN>) {
45 next if /^#/;
46 next if /^\s*$/;
47 /END_CI_ATTR/ and $last_ci_attr = $num and next;
49 chomp;
50 $attr = $_;
51 $num = $num + 1;
53 $up = uc($attr);
54 $amap{$up} = $num;
55 push(@a, $up);
56 $up =~ s/-/_/;
57 print out $attr . ", ATTR_" . $up . "\n";
59 print header "#define ATTR_" . $up . " " . $num . "\n";
62 close(IN);
64 print header "#define ATTR_LAST_ATTR $num\n";
65 print header "#define ATTR_LAST_CI_ATTR $last_ci_attr\n";
67 print out "%%\n";
68 close out;
70 print header "const char* getAttrName(unsigned short id) KDE_NO_EXPORT;\n";
72 print header "\n#endif\n";
73 close header;
75 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");
76 if ($result) {
77 unlink "htmlattrs.c";
78 exit $result;
80 system("/bin/sh", "-c", 'perl -pi -e "s/\"\"}/\"\", 0}/g" htmlattrs.c');
82 # read the hash mappings (is there a better way?)
83 my %hmap = ();
84 open(IN, "<htmlattrs.c");
85 while(<IN>) {
86 if (/spool_attr_str(\d+), ATTR_([\w_]+)/) {
87 $hmap{$amap{$2}} = $1;
90 close(IN);
92 open(OUT, ">>htmlattrs.c");
93 print OUT "\n\nstatic const unsigned short attrList[] = {\n";
94 print OUT " 65535,\n";
96 while(defined ($line = shift @a))
98 my $l = $line;
99 $l =~ y/-/_/;
101 die if !length($hmap{$amap{$l}});
103 print OUT " " .$hmap{$amap{$l}}.",\n";
105 print OUT " 65535\n};\n\n";
106 print OUT "const char* KDE_NO_EXPORT getAttrName(unsigned short id)\n{\n";
107 print OUT " if (!id || id > TOTAL_KEYWORDS) return \"\";\n";
108 print OUT " return spool_attr + wordlist_attr[attrList[id]].name;\n";
109 print OUT "}\n";