#!/usr/bin/perl
#
# Whatis [dir]...
#
# This runs the "catman -w" command to update the "whatis" files in a
# list of directories. If no directories are called, then the list in
# $MANPATH is used.  If that's missing, we just use  /usr/man,  which
# exists  on  most  Unix-like systems, but may not be writable unless
# you're a superuser.
#
# You need write permission in all the directories, of course.
#
# Author: John Chambers <jc@trillian.mit.edu>

$| = 1;
$dirs = 0;

if (!@ARGV) {
	@ARGV = split(/:/,($ENV{MANPATH} || '/usr/man'));
}
for $d (@ARGV) {
	$Dirs[$dirs++] = $d;
}

for $d (@Dirs) {
	if (!-d $d) {
		print STDERR "$d is not a directory.\n";
		system "ls -Ldl $d";
		next;
	}
	if (!-w $d) {
		print STDERR "$d is not writable.\n";
		system "ls -Ldl $d";
		next;
	}
	print "$d ...\n";
	system "catman -w -M $d";
	system "ls -l $d/whatis";
}

