#!/usr/local/perl5.005_56.Mar06/bin/perl -w ######################### -*- Mode: Perl -*- ######################### ## ## $Basename: pmakewhatis $ ## $Revision: 1.7 $ ## ## Author : Ulrich Pfeifer ## Created On : Mon Sep 2 12:57:12 1996 ## ## Last Modified By : Ulrich Pfeifer ## Last Modified On : Sun Nov 22 18:44:35 1998 ## ## Copyright (c) 1996-1997, Ulrich Pfeifer ## ## ###################################################################### eval 'exec perl -S $0 "$@"' if 0; use strict; use FileHandle; use File::Path; use DB_File; use Getopt::Long; require WAIT::Config; require WAIT::Database; require WAIT::Parse::Pod; require WAIT::Document::Find; my %OPT = (database => 'DB', dir => $WAIT::Config->{WAIT_home} || '/tmp', table => 'pod', clean => 0, remove => 0, ); GetOptions(\%OPT, 'database=s', 'dir=s', 'table=s', 'clean!', 'remove', ) || die "Usage: ...\n"; my $db; if ($OPT{clean} and -d "$OPT{dir}/$OPT{database}/$OPT{table}") { eval { my $tmp = WAIT::Database->open(name => $OPT{database}, 'directory' => $OPT{dir}) or die "Could not open table $OPT{table}: $@"; my $tbl = $tmp->table(name => $OPT{table}); $tbl->drop if $tbl; $tmp->close; rmtree("$OPT{dir}/$OPT{database}/$OPT{table}",1,1) if -d "$OPT{dir}/$OPT{database}/$OPT{table}"; }; } unless (-d "$OPT{dir}/$OPT{database}") { $db = WAIT::Database->create(name => $OPT{database}, 'directory' => $OPT{dir}) or die "Could not open database $OPT{database}: $@"; } else { $db = WAIT::Database->open(name => $OPT{database}, 'directory' => $OPT{dir}) or die "Could not open table $OPT{table}: $@"; } my $layout= new WAIT::Parse::Pod; my $stem = [{ 'prefix' => ['isotr', 'isolc'], 'intervall' => ['isotr', 'isolc'], }, 'isotr', 'isolc', 'split2', 'stop', 'Stem']; my $text = [{ 'prefix' => ['isotr', 'isolc'], 'intervall' => ['isotr', 'isolc'], }, 'isotr', 'isolc', 'split2', 'stop']; my $sound = ['isotr', 'isolc', 'split2', 'Soundex'],; my %D; my @DIRS; if (@ARGV) { @DIRS = @ARGV; } else { @DIRS = grep $_ !~ /^\./, @INC; } my $access = tie %D, 'WAIT::Document::Find', sub { $_[0] =~ /\.(pod|pm)$/}, @DIRS; die $@ unless defined $access; my $tb = $db->table(name => $OPT{table}) || $db->create_table (name => $OPT{table}, attr => ['docid', 'headline', 'size'], keyset => [['docid']], layout => $layout, access => $access, invindex => [ 'name' => $stem, 'synopsis' => $stem, 'bugs' => $stem, 'description' => $stem, 'text' => $stem, 'environment' => $text, 'example' => $text, 'example' => $stem, 'author' => $sound, 'author' => $stem, ] ); die unless $tb; my $podfile = $access->FIRSTKEY; do { unless ($podfile =~ /^$OPT{dir}/o) { &index($podfile); } } while ($podfile = $access->NEXTKEY); $db->close(); exit; my $NO; sub index { my $did = shift; if ($tb->have('docid' => $did)) { #die "$@" if $2 ne ''; if (!$OPT{remove}) { print "duplicate\n"; return; } } elsif ($OPT{remove}) { print "missing\n"; return; } my $value = $D{$did}; unless (defined $value) { print "unavailable\n"; } printf STDERR "ok [%d] ", ++$NO; my $record = $layout->split($value); $record->{size} = length($value); my $headline = $record->{name} || $did; $headline =~ s/\s+/ /g; $headline =~ s/^\s+//; printf "%s\n", substr($headline,0,70); if ($OPT{remove}) { $tb->delete('docid' => $did, headline => $headline, %{$record}); } else { $tb->insert('docid' => $did, headline => $headline, %{$record}); } } __END__ ## ################################################################### ## pod ## ################################################################### =head1 NAME pmakewhatis - generate a manual database for sman =head1 SYNOPSIS B [B<-database> I] [B<-dir> I] [B<-table> I] [B<-remove>] [I ...] =head1 DESCRIPTION B generates/updates databases for B(1). If Is are specified, these are used. Otherwise directories in C<@INC> are indexed. =head2 OPTIONS =over 10 =item B<-database> I Change the default database name to I. =item B<-dir> I Change the default database directory to I. =item B<-table> I Use I instead of C as table name. =item B<-clean> Clean B before indexing. =item B<-remove> Remove the selected directories from the database instead of adding/updating. This works only for the pod files which are unchanged since the indexing. =head1 SEE ALSO L. =head1 AUTHOR Ulrich Pfeifer EFE