#!/usr/bin/perl
#
# This runs thru the MANPATH environment variable and builds the whatis
# file for each (writable) directory.

$MP = $ENV{'MANPATH'} || '/usr/man';

@mp = split(':',$MP);

for $d (@mp) {
	print "MAN dir $d/whatis ...\n";
	if (!open(W,">$d/whatis")) {
		print STDERR "$0: Can't write $d/whatis [$!]\n";
		next;
	}
	if (!open(P,"whatis -M $d -w '*' | sort |")) {
		print STDERR "$0: Can't run whatis [$!]\n";
		next;
	}
	while (<P>) {
		print W;
	}
	print "Created $d/whatis\n";
}
