#!/usr/local/bin/perl
#
#  Darren Hardy, hardy@cs.colorado.edu, December 1993
#
#  Verify that all external programs are present in the user's search path.
#  For each external program specified, it prints the full pathname if it
#  finds the program, or prints an error message.  Returns the number of
#  programs not found as an exit code.  The data file needs to use the
#  following format for each line of the file:
#
#     summarizer-name <TAB> list-of-commands
#
#  For example,
#
#     C.sum	awk ctags head rm
#
$nmissing = 0;
while (<>) {
	next if (/^#/o);
	chop;
	($summarizer, @command_list) = split;
	while ($cmd = shift(@command_list)) {
		$commands{$cmd} .= "$summarizer ";
	}
}
foreach $cmd (keys %commands) {
	if ($x = do cmd_exists($cmd)) {
		print "Found $x\n";
	} else {
		print "*CANNOT* FIND $cmd :: $commands{$cmd} need $cmd\n";
		$nmissing++;
	}
}
if ($nmissing == 0) {
	print "All external programs needed by Essence are installed correctly.\n";
} else {
print "ERROR: All external programs needed by Essence are NOT installed correctly.\n";
}
exit $nmissing;

sub cmd_exists {
	local($cmd) = @_;
	@paths = split(/:/, $ENV{'PATH'});
	while ($path = shift(@paths)) {
		return "$path/$cmd" if (-x "$path/$cmd");
	}
	return 0;
}
