1995-01-11 09:21:29 +00:00
|
|
|
|
#!/usr/bin/perl
|
|
|
|
|
#
|
1996-08-27 20:04:45 +00:00
|
|
|
|
# Copyright (c) 1994-1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
|
|
|
|
|
# All rights reserved.
|
1995-01-11 09:21:29 +00:00
|
|
|
|
#
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
|
# are met:
|
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
|
#
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
|
#
|
|
|
|
|
# makewhatis -- update the whatis database in the man directories.
|
|
|
|
|
#
|
1999-08-27 23:37:10 +00:00
|
|
|
|
# $FreeBSD$
|
1996-05-22 00:57:42 +00:00
|
|
|
|
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
|
|
|
|
|
|
warn <<EOF;
|
1998-08-05 03:44:46 +00:00
|
|
|
|
usage: makewhatis [-a|-append ] [-h|-help] [-i|-indent column]
|
1996-05-22 00:57:42 +00:00
|
|
|
|
[-n|-name name] [-o|-outfile file] [-v|-verbose]
|
|
|
|
|
[directories ...]
|
1995-01-11 09:21:29 +00:00
|
|
|
|
EOF
|
|
|
|
|
exit 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Format output
|
|
|
|
|
sub open_output {
|
|
|
|
|
local($dir) = @_;
|
|
|
|
|
|
|
|
|
|
die "Name for whatis is empty\n" if $whatis_name eq "";
|
|
|
|
|
|
|
|
|
|
if ($outfile) { # Write all Output to $outfile
|
|
|
|
|
$whatisdb = $outfile;
|
|
|
|
|
} else { # Use man/whatis
|
|
|
|
|
$whatisdb = $dir . "/$whatis_name.tmp";
|
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$tmp = $whatisdb; # for signals
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
|
1996-05-22 00:57:42 +00:00
|
|
|
|
# Array of all entries
|
1995-03-31 04:00:53 +00:00
|
|
|
|
@a = ();
|
|
|
|
|
|
1996-05-22 00:57:42 +00:00
|
|
|
|
|
|
|
|
|
# Append mode
|
|
|
|
|
if ($append) {
|
|
|
|
|
local($file) = $whatisdb;
|
|
|
|
|
$file =~ s/\.tmp$// if !$outfile;
|
|
|
|
|
|
|
|
|
|
if (open(A, "$file")) {
|
|
|
|
|
warn "Open $file for append mode\n" if $verbose;
|
|
|
|
|
while(<A>) {
|
|
|
|
|
push(@a, $_);
|
|
|
|
|
}
|
|
|
|
|
close A;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
warn "$whatisdb: $!\n" if lstat($file) && $verbose; #
|
|
|
|
|
}
|
|
|
|
|
undef $file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "Open $whatisdb\n" if $verbose;
|
1996-05-22 00:57:42 +00:00
|
|
|
|
if (!open(A, "> $whatisdb")) {
|
|
|
|
|
die "$whatisdb: $!\n" if $outfile;
|
|
|
|
|
|
|
|
|
|
warn "$whatisdb: $!\n"; $err++; return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1995-01-11 09:21:29 +00:00
|
|
|
|
select A;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub close_output {
|
|
|
|
|
local($success) = @_;
|
|
|
|
|
local($w) = $whatisdb;
|
|
|
|
|
local($counter) = 0;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
local($i, $last,@b);
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
$w =~ s/\.tmp$//;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
if ($success) { # success
|
|
|
|
|
|
|
|
|
|
# uniq
|
|
|
|
|
warn "\n" if $verbose && $pointflag;
|
|
|
|
|
warn "sort -u > $whatisdb\n" if $verbose;
|
|
|
|
|
foreach $i (sort @a) {
|
|
|
|
|
if ($i ne $last) {
|
|
|
|
|
push(@b, $i);
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$last =$i;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
1996-05-22 00:57:42 +00:00
|
|
|
|
|
|
|
|
|
$counter = $#b + 1;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
print @b; close A; select STDOUT;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
if (!$outfile) {
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "Rename $whatisdb to $w\n" if $verbose;
|
1996-05-22 00:57:42 +00:00
|
|
|
|
rename($whatisdb, $w) || warn "rename $whatisdb $w\n";
|
1995-01-11 09:21:29 +00:00
|
|
|
|
$counter_all += $counter;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "$counter entries in $w\n" if $verbose;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
$counter_all = $counter;
|
|
|
|
|
}
|
|
|
|
|
} else { # building whatisdb failed
|
|
|
|
|
unlink($whatisdb);
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "building whatisdb: $whatisdb failed\n" if $verbose;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
sub parse_subdir {
|
|
|
|
|
local($dir) = @_;
|
|
|
|
|
local($file, $dev,$ino);
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "\n" if $pointflag;
|
|
|
|
|
warn "traverse $dir\n" if $verbose;
|
|
|
|
|
$pointflag = 0;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
if (!opendir(M, $dir)) {
|
|
|
|
|
warn "$dir: $!\n"; $err++; return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$| = 1 if $verbose;
|
|
|
|
|
foreach $file (readdir(M)) {
|
|
|
|
|
next if $file =~ /^(\.|\.\.)$/;
|
|
|
|
|
|
|
|
|
|
($dev, $ino) = ((stat("$dir/$file"))[01]);
|
|
|
|
|
if (-f _) {
|
|
|
|
|
if ($man_red{"$dev.$ino"}) {
|
|
|
|
|
# Link
|
|
|
|
|
print STDERR "+" if $verbose;
|
|
|
|
|
$pointflag++ if $verbose;
|
|
|
|
|
} else {
|
|
|
|
|
&manual("$dir/$file");
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$man_red{"$dev.$ino"} = 1;
|
|
|
|
|
} elsif (! -d _) {
|
|
|
|
|
warn "Cannot find file: $dir/$file\n"; $err++;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
}
|
|
|
|
|
closedir M;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# read man directory
|
|
|
|
|
sub parse_dir {
|
|
|
|
|
local($dir) = @_;
|
|
|
|
|
local($subdir, $file);
|
|
|
|
|
|
|
|
|
|
# clean up, in case mandir and subdirs are called simultaneously
|
|
|
|
|
# e. g.: ~/man/man1 ~/man/man2 ~/man
|
|
|
|
|
#~/man/ man1 and ~/man/man2 are a subset of ~/man
|
|
|
|
|
foreach $file (keys %man_red) {
|
|
|
|
|
delete $man_red{$file};
|
|
|
|
|
}
|
|
|
|
|
|
1997-07-04 22:32:59 +00:00
|
|
|
|
if ($dir =~ /man/) {
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "\n" if $verbose && $pointflag;
|
|
|
|
|
warn "open manpath directory ``$dir''\n" if $verbose;
|
|
|
|
|
$pointflag = 0;
|
|
|
|
|
if (!opendir(DIR, $dir)) {
|
|
|
|
|
warn "opendir ``$dir'':$!\n"; $err = 1; return 0;
|
|
|
|
|
}
|
|
|
|
|
foreach $subdir (sort(readdir(DIR))) {
|
|
|
|
|
if ($subdir =~ /^man\w+$/) {
|
|
|
|
|
$subdir = "$dir/$subdir";
|
|
|
|
|
&parse_subdir($subdir);
|
|
|
|
|
}
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
closedir DIR
|
|
|
|
|
|
|
|
|
|
} elsif ($dir =~ /man\w+$/) {
|
|
|
|
|
&parse_subdir($dir);
|
|
|
|
|
} else {
|
|
|
|
|
warn "Assume ``$dir'' is not a man directory.\n";
|
|
|
|
|
$err = 1; return 0;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
1995-02-26 19:35:06 +00:00
|
|
|
|
sub dir_redundant {
|
|
|
|
|
local($dir) = @_;
|
|
|
|
|
|
|
|
|
|
local ($dev,$ino) = (stat($dir))[0..1];
|
|
|
|
|
|
|
|
|
|
if ($dir_redundant{"$dev.$ino"}) {
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "$dir is equal to: $dir_redundant{\"$dev.$ino\"}\n" if $verbose;
|
1995-02-26 19:35:06 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
$dir_redundant{"$dev.$ino"} = $dir;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ``/usr/man/man1/foo.l'' -> ``l''
|
|
|
|
|
sub ext {
|
|
|
|
|
local($filename) = @_;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
local($extension) = $filename;
|
|
|
|
|
|
|
|
|
|
$extension =~ s/$ext$//g; # strip .gz
|
|
|
|
|
$extension =~ s/.*\///g; # basename
|
|
|
|
|
|
1997-07-04 22:32:59 +00:00
|
|
|
|
if ($extension !~ m%[^/]+\.[^.]+$%) { # no dot
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$extension = $filename;
|
|
|
|
|
#$extension =~ s|/[^/]+$||;
|
1997-07-04 22:32:59 +00:00
|
|
|
|
$extension =~ s%.*man([^/]+)/[^/]+%$1%; # last character
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "\n" if $verbose && $pointflag;
|
|
|
|
|
warn "$filename has no extension, try section ``$extension''\n"
|
|
|
|
|
if $verbose;
|
|
|
|
|
$pointflag = 0;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
} else {
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$extension =~ s/.*\.//g; # foo.bla.1 -> 1
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
return "$extension";
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ``/usr/man/man1/foo.1'' -> ``foo''
|
|
|
|
|
sub name {
|
|
|
|
|
local($name) = @_;
|
|
|
|
|
|
1995-09-10 13:05:52 +00:00
|
|
|
|
$name =~ s=.*/==;
|
|
|
|
|
$name =~ s=$ext$==o;
|
|
|
|
|
$name =~ s=\.[^\.]+$==;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
return "$name";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# output
|
|
|
|
|
sub out {
|
|
|
|
|
local($list) = @_;
|
|
|
|
|
local($delim) = " - ";
|
|
|
|
|
$_ = $list;
|
|
|
|
|
|
|
|
|
|
# delete italic etc.
|
|
|
|
|
s/^\.[^ -]+[ -]+//;
|
|
|
|
|
s/\\\((em|mi)//;
|
|
|
|
|
s/\\f[IRBP]//g;
|
|
|
|
|
s/\\\*p//g;
|
|
|
|
|
s/\(OBSOLETED\)[ ]?//;
|
|
|
|
|
s/\\&//g;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
s/^\@INDOT\@//;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
s/[\"\\]//g; #"
|
|
|
|
|
s/[. \t-]+$//;
|
|
|
|
|
|
|
|
|
|
s/ / - / unless / - /;
|
|
|
|
|
($man,$desc) = split(/ - /);
|
1995-03-31 04:00:53 +00:00
|
|
|
|
|
1995-01-11 09:21:29 +00:00
|
|
|
|
$man = $name unless $man;
|
|
|
|
|
$man =~ s/[,. ]+$//;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$man =~ s/,/($extension),/g;
|
|
|
|
|
$man .= "($extension)";
|
1995-09-10 13:05:52 +00:00
|
|
|
|
|
|
|
|
|
&manpagename;
|
|
|
|
|
|
1995-01-11 09:21:29 +00:00
|
|
|
|
$desc =~ s/^[ \t]+//;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
|
|
|
|
|
for($i = length($man); $i < $indent && $desc; $i++) {
|
1995-01-11 09:21:29 +00:00
|
|
|
|
$man .= ' ';
|
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
if ($desc) {
|
|
|
|
|
push(@a, "$man$delim$desc\n");
|
|
|
|
|
} else {
|
|
|
|
|
push(@a, "$man\n");
|
|
|
|
|
}
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-10 13:05:52 +00:00
|
|
|
|
# The filename of manual page is not a keyword.
|
1996-05-14 23:07:05 +00:00
|
|
|
|
# This is bad, because you don't find the manpage
|
1995-09-10 13:05:52 +00:00
|
|
|
|
# whith: $ man <section> <keyword>
|
|
|
|
|
#
|
|
|
|
|
# Add filename if a) filename is not a keyword and b) no keyword(s)
|
|
|
|
|
# exist as file in same mansection
|
|
|
|
|
#
|
|
|
|
|
sub manpagename {
|
|
|
|
|
foreach (split(/,\s+/, $man)) {
|
|
|
|
|
s/\(.+//;
|
|
|
|
|
# filename is keyword
|
|
|
|
|
return if $name eq $_;
|
|
|
|
|
}
|
|
|
|
|
|
1996-05-14 23:07:05 +00:00
|
|
|
|
local($f) = $file; $f =~ s%/*[^/]+$%%; # dirname
|
|
|
|
|
local($e) = $file; $e =~ s/$ext$//; $e =~ s%.*(\.[^.]+)$%$1%; # .1
|
1996-05-12 21:02:04 +00:00
|
|
|
|
|
1995-09-10 13:05:52 +00:00
|
|
|
|
foreach (split(/,\s+/, $man)) {
|
|
|
|
|
s/\(.+//;
|
1996-05-12 21:02:04 +00:00
|
|
|
|
|
1995-09-10 13:05:52 +00:00
|
|
|
|
# a keyword exist as file
|
1996-05-14 23:07:05 +00:00
|
|
|
|
return if -e "$f/$_$e" || -e "$f/$_$e$ext";
|
1995-09-10 13:05:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-05-14 23:07:05 +00:00
|
|
|
|
$man = "$name($extension), $man";
|
1995-09-10 13:05:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
# looking for NAME
|
1995-01-11 09:21:29 +00:00
|
|
|
|
sub manual {
|
|
|
|
|
local($file) = @_;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
local($list, $desc, $extension);
|
1995-01-11 09:21:29 +00:00
|
|
|
|
local($ofile) = $file;
|
|
|
|
|
|
|
|
|
|
# Compressed man pages
|
1995-03-31 04:00:53 +00:00
|
|
|
|
if ($ofile =~ /$ext$/) {
|
1995-01-11 09:21:29 +00:00
|
|
|
|
$ofile = "gzcat $file |";
|
1995-03-31 04:00:53 +00:00
|
|
|
|
print STDERR "*" if $verbose;
|
|
|
|
|
} else {
|
|
|
|
|
print STDERR "." if $verbose;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$pointflag++ if $verbose;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
if (!open(F, "$ofile")) {
|
|
|
|
|
warn "Cannot open file: $ofile\n"; $err++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
# extension/section
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$extension = &ext($file);
|
1995-01-11 09:21:29 +00:00
|
|
|
|
$name = &name($file);
|
|
|
|
|
|
|
|
|
|
local($source) = 0;
|
1995-03-31 04:00:53 +00:00
|
|
|
|
local($list);
|
1995-01-11 09:21:29 +00:00
|
|
|
|
while(<F>) {
|
|
|
|
|
# ``man'' style pages
|
|
|
|
|
# &&: it takes you only half the user time, regexp is slow!!!
|
1997-03-14 21:58:43 +00:00
|
|
|
|
if (/^\.SH/ && /^\.SH[ \t]+["]?(NAME|Name|NAMN|BEZEICHNUNG|̾<><CCBE>)["]?/) {
|
1995-01-11 09:21:29 +00:00
|
|
|
|
#while(<F>) { last unless /^\./ } # Skip
|
|
|
|
|
#chop; $list = $_;
|
|
|
|
|
while(<F>) {
|
|
|
|
|
last if /^\.SH[ \t]/;
|
|
|
|
|
chop;
|
1997-03-01 15:20:50 +00:00
|
|
|
|
s/^\.IX\s.*//; # delete perlpod garbage
|
1995-01-11 09:21:29 +00:00
|
|
|
|
s/^\.[A-Z]+[ ]+[0-9]+$//; # delete commands
|
|
|
|
|
s/^\.[A-Za-z]+[ \t]*//; # delete commands
|
|
|
|
|
s/^\.\\".*$//; #" delete comments
|
|
|
|
|
s/^[ \t]+//;
|
|
|
|
|
if ($_) {
|
|
|
|
|
$list .= $_;
|
|
|
|
|
$list .= ' ';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
&out($list); close F; return 1;
|
1997-03-14 21:58:43 +00:00
|
|
|
|
} elsif (/^\.Sh/ && /^\.Sh[ \t]+["]?(NAME|Name|BEZEICHNUNG|̾<><CCBE>)["]?/) {
|
1995-01-11 09:21:29 +00:00
|
|
|
|
# ``doc'' style pages
|
|
|
|
|
local($flag) = 0;
|
|
|
|
|
while(<F>) {
|
|
|
|
|
last if /^\.Sh/;
|
|
|
|
|
chop;
|
|
|
|
|
s/^\.\\".*$//; #" delete comments
|
|
|
|
|
if (/^\.Nm/) {
|
|
|
|
|
s/^\.Nm[ \t]*//;
|
|
|
|
|
s/ ,/,/g;
|
|
|
|
|
s/[ \t]+$//;
|
|
|
|
|
$list .= $_;
|
|
|
|
|
$list .= ' ';
|
|
|
|
|
} else {
|
|
|
|
|
$list .= '- ' if (!$flag && !/-/);
|
|
|
|
|
$flag++;
|
|
|
|
|
s/^\.[A-Z][a-z][ \t]*//;
|
|
|
|
|
s/[ \t]+$//;
|
|
|
|
|
$list .= $_;
|
|
|
|
|
$list .= ' ';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
&out($list); close F; return 1;
|
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
} elsif(/^\.so/ && /^\.so[ \t]+man/) {
|
1995-01-11 09:21:29 +00:00
|
|
|
|
close F; return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
if (!$source && $verbose) {
|
|
|
|
|
warn "\n" if $pointflag;
|
|
|
|
|
warn "Maybe $file is not a manpage\n" ;
|
|
|
|
|
$pointflag = 0;
|
|
|
|
|
}
|
1995-01-11 09:21:29 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
# make relative path to absolute path
|
|
|
|
|
sub absolute_path {
|
|
|
|
|
local(@dirlist) = @_;
|
|
|
|
|
local($pwd, $dir, @a);
|
|
|
|
|
|
|
|
|
|
$pwd = $ENV{'PWD'};
|
|
|
|
|
foreach $dir (@dirlist) {
|
|
|
|
|
if ($dir !~ "^/") {
|
|
|
|
|
chop($pwd = `pwd`) if (!$pwd || $pwd !~ /^\//);
|
|
|
|
|
push(@a, "$pwd/$dir");
|
|
|
|
|
} else {
|
|
|
|
|
push(@a, $dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return @a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# strip unused '/'
|
|
|
|
|
# e.g.: //usr///home// -> /usr/home
|
|
|
|
|
sub stripdir {
|
|
|
|
|
local($dir) = @_;
|
|
|
|
|
|
|
|
|
|
$dir =~ s|/+|/|g; # delete double '/'
|
|
|
|
|
$dir =~ s|/$||; # delete '/' at end
|
|
|
|
|
$dir =~ s|/(\.\/)+|/|g; # delete ././././
|
|
|
|
|
|
|
|
|
|
$dir =~ s|/+|/|g; # delete double '/'
|
|
|
|
|
$dir =~ s|/$||; # delete '/' at end
|
|
|
|
|
$dir =~ s|/\.$||; # delete /. at end
|
|
|
|
|
return $dir if $dir ne "";
|
|
|
|
|
return '/';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub variables {
|
|
|
|
|
$verbose = 0; # Verbose
|
|
|
|
|
$indent = 24; # indent for description
|
|
|
|
|
$outfile = 0; # Don't write to ./whatis
|
|
|
|
|
$whatis_name = "whatis"; # Default name for DB
|
1996-05-22 00:57:42 +00:00
|
|
|
|
$append = 0; # Don't delete old entries
|
1995-03-31 04:00:53 +00:00
|
|
|
|
|
|
|
|
|
# if no argument for directories given
|
|
|
|
|
@defaultmanpath = ( '/usr/share/man' );
|
|
|
|
|
|
1995-09-10 13:05:52 +00:00
|
|
|
|
$ext = '.gz'; # extension
|
1995-03-31 04:00:53 +00:00
|
|
|
|
umask(022);
|
|
|
|
|
|
|
|
|
|
$err = 0; # exit code
|
|
|
|
|
$whatisdb = '';
|
|
|
|
|
$counter_all = 0;
|
|
|
|
|
$dir_redundant = ''; # redundant directories
|
|
|
|
|
$man_red = ''; # redundant man pages
|
|
|
|
|
@a = (); # Array for output
|
|
|
|
|
|
|
|
|
|
# Signals
|
|
|
|
|
$SIG{'INT'} = 'Exit';
|
|
|
|
|
$SIG{'HUP'} = 'Exit';
|
|
|
|
|
$SIG{'TRAP'} = 'Exit';
|
|
|
|
|
$SIG{'QUIT'} = 'Exit';
|
|
|
|
|
$SIG{'TERM'} = 'Exit';
|
|
|
|
|
$tmp = ''; # tmp file
|
|
|
|
|
|
|
|
|
|
$ENV{'PATH'} = "/bin:/usr/bin:$ENV{'PATH'}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub Exit {
|
|
|
|
|
unlink($tmp) if $tmp ne ""; # unlink if a filename
|
|
|
|
|
die "$0: die on signal SIG@_\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub parse {
|
|
|
|
|
local(@argv) = @_;
|
|
|
|
|
local($i);
|
|
|
|
|
|
|
|
|
|
while ($_ = $argv[0], /^-/) {
|
|
|
|
|
shift @argv;
|
|
|
|
|
last if /^--$/;
|
|
|
|
|
if (/^--?(v|verbose)$/) { $verbose = 1 }
|
|
|
|
|
elsif (/^--?(h|help|\?)$/) { &usage }
|
|
|
|
|
elsif (/^--?(o|outfile)$/) { $outfile = $argv[0]; shift @argv }
|
|
|
|
|
elsif (/^--?(f|format|i|indent)$/) { $i = $argv[0]; shift @argv }
|
|
|
|
|
elsif (/^--?(n|name)$/) { $whatis_name = $argv[0];shift @argv }
|
1996-05-22 00:57:42 +00:00
|
|
|
|
elsif (/^--?(a|append)$/) { $append = 1 }
|
1995-03-31 04:00:53 +00:00
|
|
|
|
else { &usage }
|
|
|
|
|
}
|
|
|
|
|
|
1995-04-01 11:43:09 +00:00
|
|
|
|
if ($i ne "") {
|
|
|
|
|
if ($i =~ /^[0-9]+$/) {
|
|
|
|
|
$indent = $i;
|
|
|
|
|
} else {
|
|
|
|
|
warn "Ignoring wrong indent value: ``$i''\n";
|
|
|
|
|
}
|
1995-03-31 04:00:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &absolute_path(@argv) if $#argv >= 0;
|
|
|
|
|
return @defaultmanpath if $#defaultmanpath >= 0;
|
|
|
|
|
|
|
|
|
|
warn "Missing directories\n"; &usage;
|
|
|
|
|
}
|
|
|
|
|
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
## Main
|
|
|
|
|
##
|
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
&variables;
|
1995-01-11 09:21:29 +00:00
|
|
|
|
# allow colons in dir: ``makewhatis dir1:dir2:dir3''
|
1995-03-31 04:00:53 +00:00
|
|
|
|
@argv = &parse(split(/[: ]/, join($", @ARGV))); # "
|
|
|
|
|
|
1995-01-11 09:21:29 +00:00
|
|
|
|
|
|
|
|
|
if ($outfile) {
|
1995-03-31 04:00:53 +00:00
|
|
|
|
if(&open_output($outfile)){
|
|
|
|
|
foreach $dir (@argv) {
|
|
|
|
|
$dir = &stripdir($dir);
|
|
|
|
|
&dir_redundant($dir) && &parse_dir($dir);
|
|
|
|
|
}
|
1995-02-26 19:35:06 +00:00
|
|
|
|
}
|
1995-01-11 09:21:29 +00:00
|
|
|
|
&close_output(1);
|
|
|
|
|
} else {
|
|
|
|
|
foreach $dir (@argv) {
|
1995-03-31 04:00:53 +00:00
|
|
|
|
$dir = &stripdir($dir);
|
|
|
|
|
&dir_redundant($dir) &&
|
|
|
|
|
&close_output(&open_output($dir) && &parse_dir($dir));
|
1995-01-11 09:21:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1995-03-31 04:00:53 +00:00
|
|
|
|
warn "Total entries: $counter_all\n" if $verbose && ($#argv > 0 || $outfile);
|
1995-01-11 09:21:29 +00:00
|
|
|
|
exit $err;
|