#!/usr/bin/perl

$oaf_dir="/opt/gnome/share/oaf";

print "Warning, this program may arbitrarily terminate all manner of vital apps\n use with extreme caution...\n";

chdir ($oaf_dir);
opendir (DIR, $oaf_dir) || die "can't opendir oaf_dir: $!";
@files = readdir (DIR);
closedir DIR;

$sysname=`uname -s`;
chomp ($sysname);

if ($sysname eq "SunOS") {
    $killall="pkill";
    $kill_params=' -9 ';
} else {
    $killall="killall";
    $kill_params=' -q -9 ';
}

# print "Killall :'", $killall, "' params '", $kill_params, "'\n";

while ($fname = shift (@files)) {
	open (FILE, $fname);
	while (<FILE>) {
		$line = $_;
		if ($line =~m/location[ \t]*\=/ && !($line =~m/type=\"shlib\"/)) {
			$line =~s/.*location[ \t]*\="//;
			$line =~s/".*//;
			chomp ($line);

			$line =~s/\.\///;
			if (not ($line =~m/^OAFIID:/)) {
				$cmd = $killall . $kill_params . $line;
#				print "'", $cmd, "'\n";
				system ($cmd);
# Get people who ran it by hande from a libtool script.
				$cmd = $killall . $kill_params . 'lt-' . $line;
#				print "'", $cmd, "'\n";
				system ($cmd);
			}
		}
	}
	close (FILE);
}
system ($killall . $kill_params . "oafd");
