-
Notifications
You must be signed in to change notification settings - Fork 7
/
make-help-index.pl
65 lines (60 loc) · 1.95 KB
/
make-help-index.pl
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
#! perl -w
use strict;
sub unhtmlize {
my ($str) = @_;
$str =~ s/</</g;
$str =~ s/>/>/g;
$str =~ s/—/-/g;
$str =~ s|\\|\\\\|g;
return $str;
}
sub scan_command_index {
my ($index_file) = @_;
open INFILE, $index_file or die "Cannot open file $index_file ($!)";
my $result = {};
my $line;
while ($line = <INFILE>) {
if ($line =~ m|<tr><td></td><td valign="top"><a href="([^"]+)"><code>([^<]+)</code></a></td><td valign="top"><a href="([^"]+)">([^<]+)</a></td></tr>|) {
my $entry = $2;
my $entry_link = $1;
my $section = $4;
my $section_link = $3;
$entry = unhtmlize ($entry);
$section = unhtmlize ($section);
my $entry_data = {};
$entry_data->{link} = $entry_link;
$entry_data->{section} = $section;
$entry_data->{section_link} = $section_link;
push @{$result->{$entry}}, $entry_data;
}
}
close INFILE;
return $result;
}
sub write_elisp_index {
my ($output_file, $index, $url_base) = @_;
open OUTFILE, ">$output_file" or die "Cannot write file '$output_file' ($!)";
print OUTFILE "(defconst lyqi:help-url-base \"$url_base\")\n\n";
print OUTFILE "(defconst lyqi:help-index\n '(";
my $first_entry = 1;
foreach my $entry (sort keys %$index) {
print OUTFILE "\n " unless $first_entry;
print OUTFILE "(\"$entry\" ";
my $first_data = 1;
foreach my $entry_data (reverse @{$index->{$entry}}) {
print OUTFILE "\n " unless $first_data;
print OUTFILE "(\"", $entry_data->{link}, "\" \"", $entry_data->{section}, "\" \"", $entry_data->{section_link}, "\")";
$first_data = 0;
}
print OUTFILE ")";
$first_entry = 0;
}
print OUTFILE "))\n\n";
my $feature = $output_file;
$feature =~ s|(.*/)?([^/]+)\.el|$2|;
print OUTFILE "(provide '$feature)\n";
close OUTFILE;
}
my ($index_file, $url_base, $output_file) = @ARGV;
my $index = scan_command_index ($index_file);
write_elisp_index ($output_file, $index, $url_base);