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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/usr/bin/perl -w
# whatis2sqlite.pl - create sqlite3 whatis database for use with
# limnoria Manpages plugin.
# Usage:
# $ rm -f /path/to/Manpages.sqlite3
# $ perl whatis2sqlite.pl [whatis-file] | sqlite /path/to/Manpages.sqlite3
# then reload the Manpages plugin in the bot.
# For Slackware 14.2, the whatis-file comes from /usr/man/whatis.
# For 15.0, we'll have to generate it according to the directions
# in "man whatis":
# /etc/cron.daily/man-db
# whatis -w '*' | sort -u > whatis
push @ARGV, 'whatis' unless @ARGV;
print <<EOF;
pragma journal_mode = memory;
begin transaction;
create table whatis (
id integer primary key not null,
page varchar not null,
section char(5) not null,
desc varchar not null
);
EOF
while(<>) {
my($name, $desc, $sect, $alias);
chomp;
# 14.2's whatis has some garbage entries, skip them.
#next if /^struct/;
#next if /^and (put|with)/;
#next if /bernd\.warken/;
s/\s+$//g;
($name, $desc) = split /\s+-\s+/, $_, 2;
$name =~ s/\s+/ /g;
($sect) = $name =~ /\(([^)]+)\)/;
next if $sect eq '3p'; # symlink
$alias = 0;
if($name =~ /\[([^]]+)\]/) {
$alias = $1;
}
$name =~ s,\s.*,,;
$sect =~ s/^(.).*$/$1/; # no "3x", etc.
# 14.2's whatis has some wrong sections, fix them.
#$sect = '8' if $sect eq 'v'; # ebtables
#$sect = '1' if $sect eq 'P'; # cdparanoia
#$sect = '1' if $sect eq 'o'; # rclock, rxvt
#print "$sect, $name, '$alias' => $desc\n";
make_sql($name, $sect, $desc);
make_sql($alias, $sect, $desc) if $alias;
}
print "COMMIT;\n";
sub make_sql {
my $page = shift;
my $sect = shift;
my $desc = shift;
return if $seen{"$page^^$sect"}++;
# 15.0 has double-quotes in some descriptions.
$desc =~ s/"/""/g;
print <<EOF
insert into whatis values (null, "$page", "$sect", "$desc");
EOF
}
|