| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 | #! /usr/bin/perl
#
# Compile list of HTML 4.0/XHTML entities.
my %ent=("amp" => 38, "lt" => 60, "gt" => 62);
foreach ("xhtml-lat1.ent", "xhtml-special.ent", "xhtml-symbol.ent")
{
    open(F, "<$_") or die "$_: $!\n";
    my $l;
    while (defined($l=<F>))
    {
	chomp $l;
	next unless $l =~ m/^<!ENTITY\s+([^\s]+)\s+"&#(\d+);">/;
	$ent{$1}=$2;
    }
}
print "static const char n[]={\n";
my $prev="\t";
foreach (sort keys %ent)
{
    my $n=$_;
    my $str="";
    print $prev;
    $prev="";
    foreach (0..length($n)-1)
    {
	$str .= $prev . ord(substr($n, $_, 1));
	$prev=", ";
    }
    print $str;
    $prev=",";
    $prev .= (" " x (40 - length($str)))
	if (length($str) < 40);
    $prev .= " /* $n */\n\t";
}
substr($prev, 0, 1)=" ";
$prev =~ s/\t//;
print "$prev};\n\nstatic const struct i ii[]={";
$prev="\n\t";
my $n=0;
foreach (sort keys %ent)
{
    print $prev . "{$n, " . length($_) . ", $ent{$_}" . "}";
    $n += length($_);
    $prev=",\n\t";
}
print "\n};\n";
 |