use strict;
open IN, "htmltags.in"
or die "Can't open in\n";
open header, ">htmltags.h"
or die "Can't open header\n";
open out, ">htmltags.gperf"
or die "Can't open out\n";
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";
print out "struct tags {\n const char *name;\n int id;\n};\n%%\n";
print header "/* This file is automatically generated from
htmltags.in by maketags, do not edit */\n/* Copyright 1999 Lars Knoll */\n/* Copyright 2004 Apple Computer, Inc. */\n\n#ifndef KHTML_TAGS_H\n#define KHTML_TAGS_H\n\n#include \"dom/dom_string.h\"\n\n";
print header "DOM::DOMString getTagName(unsigned short id);\n\n";
my $num = 0;
my $openTags = "";
my $closeTags = "";
while (<IN>) {
chomp;
my $attr = $_;
$num += 1;
my $up = uc($attr);
$openTags .= " \"$up\",\n";
$closeTags .= " \"/$up\",\n";
$up =~ s/-/_/;
print out $attr . ", ID_" . $up . "\n";
print header "const unsigned short ID_$up = $num;\n";
}
print out "anchor, ID_A\n";
print out "image, ID_IMG\n";
print out "listing, ID_PRE\n";
$num += 1;
print header "const unsigned short ID_TEXT = $num;\n";
$num += 1;
print header "const unsigned short ID_COMMENT = $num;\n";
print header "const unsigned short ID_LAST_TAG = $num;\n";
print header "const unsigned short ID_CLOSE_TAG = 32000;\n";
print out "%%\n";
close out;
print header "\n#endif\n";
close header;
my $result = system("/bin/sh", "-c", "gperf -a -L 'ANSI-C' -D -E -C -l -o -t -k '*' -NfindTag -Hhash_tag -Wwordlist_tag htmltags.gperf > htmltags.c");
if ($result) {
unlink "htmltags.c";
exit $result;
}
open IN, "htmltags.c" or die;
my $numLines = 0;
while (<IN>) {
$numLines++;
}
$numLines += 2;
chomp $openTags;
chomp $closeTags;
open OUT, ">>htmltags.c" or die;
print OUT <<END
using DOM::DOMString;
static const char * const openTagNames[] = {
0,
$openTags
"TEXT",
"COMMENT"
};
static const char * const closeTagNames[] = {
0,
$closeTags
};
DOMString getTagName(unsigned short id)
{
if (id > ID_CLOSE_TAG) {
int index = id - ID_CLOSE_TAG;
if (index >= ID_TEXT)
return DOMString();
return closeTagNames[index];
}
if (id > ID_LAST_TAG)
return DOMString();
return openTagNames[id];
}
END