blob: 7564787aeda353dd3bbac3def5db61a50a7cdc25 (
plain)
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
|
#!/usr/bin/perl
use Getopt::Long;
my $prefix = '';
GetOptions( 'prefix=s' => \$prefix,
'title=s' => \$title,
'main=s' => \$main ) || die "Wrong options\n";
$file = $ARGV[0];
open(FILE, "$file") || die "File not found: $file\n";
$prevdepth = 1;
$depth = 1;
print "<tocsect${depth} name=\"$title\" url=\"$main.html\"";
while (<FILE>) {
if (/^\s*href/ && !/.*\<\/A\>$/i) {
chop;
$_ = $_ . <FILE>;
}
if (/\<UL\>/i) {
$depth++;
} elsif (/\<\/UL\>/i) {
print "/" if ($prevdepth == $depth);
$depth--;
print ">\n</tocsect${depth}";
} elsif (/^\s*href=\"([^\"]+)\"\>(.+)\<\/A\>$/i) {
$url = "$prefix/$1";
$name = dehtml($2);
$name =~ s/\s+/ /g;
print "/" if ($prevdepth == $depth);
print ">\n<tocsect${depth} name=\"$name\" url=\"$url\"";
$prevdepth = $depth;
}
}
print ">\n";
close(FILE);
sub dehtml
{
my ( $str ) = @_;
$str =~ s/\<(tt|b) class=\"([^\"]*)\"\>//g;
$str =~ s/\<\/(tt|b)\>//g;
$str =~ s/\<i\>//g;
$str =~ s/\<\/i\>//g;
return $str;
}
|