#!/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 <) { 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"}++; # N.B. we don't escape quotes here because 14.2's whatis # doesn't contain any double-quotes. When 15 is released, # better check again! print <