fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / khtml / misc / maketags
blobb31a539d593fc192058a523854bc986a3e104717
1 #!/usr/bin/perl
2 # This file is part of the KDE libraries
4 # Copyright (C) 1998 Waldo Bastian (bastian@kde.org)
5 # 1999 Lars Knoll (knoll@kde.org)
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Library General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Library General Public License for more details.
17 # You should have received a copy of the GNU Library General Public License
18 # along with this library; see the file COPYING.LIB. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 # Boston, MA 02110-1301, USA.
22 #----------------------------------------------------------------------------
24 # KDE HTML Widget -- Script to generate htmltags.c and htmltags.h
26 open IN, "htmltags.in"
27 or die "Can't open in\n";
28 open header, ">htmltags.h"
29 or die "Can't open header\n";
30 open out, ">htmltags.gperf"
31 or die "Can't open out\n";
33 print out "%{\n/* This file is automatically generated from htmltags.in by maketags, do not edit */\n/* Copyright 1999 Lars Knoll */\n#include \"htmltags.h\"\n%}\n";
34 print out "struct tags {\n int name;\n int id;\n};\n%%\n";
36 print header <<EOF;
37 /* This file is automatically generated from htmltags.in by maketags, do not edit */
38 /* Copyright 1999 Lars Knoll */
40 #ifndef KHTML_TAGS_H
41 #define KHTML_TAGS_H
43 #include "dom/dom_string.h"
44 #include <kglobal.h>
46 KDE_NO_EXPORT const char* getTagName(unsigned short id);
48 EOF
50 my @tags = ();
51 $num = 0;
52 while (<IN>) {
53 chomp;
54 $attr = $_;
55 $num = $num + 1;
56 push(@tags, $attr);
57 push(@a, " \"$attr\",");
58 push(@b, " \"/$attr\",");
59 $up = uc($attr);
60 $up =~ s/-/_/;
61 print out $attr . ", ID_" . $up . "\n";
62 print header "#define ID_" . $up . " " . $num . "\n";
64 print out "anchor, ID_A\n";
65 print out "image, ID_IMG\n";
66 print out "listing, ID_PRE\n";
67 $num = $num+1;
68 print header "#define ID_TEXT $num\n";
69 $num = $num+1;
70 print header "#define ID_COMMENT $num\n";
71 print header "#define ID_LAST_TAG $num\n";
72 print header "#define ID_CLOSE_TAG 16384\n";
74 print out "%%\n";
75 close out;
76 print header "\n#endif\n";
77 close header;
79 my $result = system("/bin/sh", "-c", "gperf -a -L 'ANSI-C' -P -D -E -C -l -o -t -k '*' -NfindTag -Hhash_tag -Wwordlist_tag -Qspool_Tag htmltags.gperf > htmltags.c");
80 if ($result) {
81 unlink "htmltags.c";
82 exit $result;
85 open(OUT, ">>htmltags.c");
86 print OUT "\n\nstatic const char tagStable[] = {\n \"";
87 push (@tags, "text");
88 push (@tags, "comment");
89 my %stable = ();
90 my $l = 1;
91 my $line = 5;
92 foreach my $k(@tags) {
93 if ($line > 65) {
94 print OUT "\"\n \"";
95 $line = 5;
97 #print OUT " \"\\000/$k\"\n";
98 print OUT "\\000/$k";
99 $stable{$k} = $l;
100 $l += length($k) + 2;
101 $line += length($k) + 5;
103 print OUT "\\000\"\n};\n";
105 print OUT "\nstatic const unsigned short tagSList[] = {\n";
106 print OUT " 0,\n";
107 my $c = 0;
108 foreach my $line (@tags)
110 printf OUT "\n " if (($c % 12) == 0);
111 printf OUT "%4d,", ($stable{$line}+1) ;
112 ++$c;
114 foreach my $line (@tags)
116 printf OUT "\n " if (($c % 12) == 0);
117 printf OUT "%4d,", ($stable{$line}) ;
118 ++$c;
120 print OUT " 0\n};\n\n";
121 print OUT "const char* KDE_NO_EXPORT getTagName(unsigned short id)\n{\n";
122 print OUT " if(id > ID_CLOSE_TAG*2) id = ID_CLOSE_TAG+1;\n";
123 print OUT " return &tagStable[tagSList[id]];\n}\n";