#!/mpkg/perl/5.6.0/bin/perl # $Id: whichman,v 1.2 2002/05/20 12:33:14 max Exp $ # Copyright (c) 2002 Max Zomborszki. All rights reserved. use Pod::Text; use Getopt::Long; my $printmatch = 0; my $section; GetOptions("version" => sub { print ' whichman $Revision: 1.2 $ ' . "\n"; exit; }, "printmatch!" => \$printmatch, "section=s" => \$section, "help" => \&help); $| = 1; if (defined $section && length $section > 1) { print "ERROR: Section must be one character long!\n"; exit(1); } if (scalar @ARGV) { if ( $ENV{"MANPATH"} ) { my @path = split /\:/, $ENV{"MANPATH"}; PATH: foreach my $p (@path) { if (opendir(DH, $p)) { my @subdirs = grep { $_ =~ /^((man)|(cat)).$/&& -d "$p/$_" } readdir(DH); SUBDIR: foreach my $s (@subdirs) { my $suffix = substr($s, length($s) - 1); next SUBDIR if (defined $section && ($section ne $suffix)); if (opendir(SDH, "$p/$s")) { my @files = grep { -f "$p/$s/$_" } readdir(SDH); PATTERN: foreach my $pattern (@ARGV) { my @match = grep { /^$pattern\.$suffix/} @files; if (scalar @match) { foreach my $m (@match) { print "$pattern: \t" if ($printmatch); print "$p/$s/$m\n"; } } } closedir(SDH); } } closedir(DH); } } } } else { print "Usage: whichman [options] command ...\n"; } # ========================================================================== # Help # ========================================================================== sub help { pod2text($0); exit; } __END__ =head1 NAME whichman - man page locator =head1 SYNOPSIS whichman [ options ] command ... =head1 DESCRIPTION Finds manpages in the directories contained within the MANPAGE environment variable. =head1 USAGE Just run wichman with the name(s) of the command(s) you wish to find the manpages for as the argument to whichman. =head1 OPTIONS You don not have to type out the entire name of the option, as long as it is unique. =over =item --printmatch Prepends the matching name on the beginnign of each row. =item --section Only matches the manpages found in section . =item --version Show the version of whichman. =item --help Show this help. =back =head1 AUTHOR This software is Copyright 2002 by Max Zomborszki. =head1 ACKNOWLEDGMENTS Larry Wall for creating Perl. =head1 SEE ALSO man(1) =head1 KNOWN PROBLEMS Users. =head1 BUGS Send bug reports to max@e.kth.se =cut