#!/usr/bin/perl
# this removes directories IF they are empty OR they have only a CVS directory
# in them

D: for $d (@ARGV) {
	$d =~ /\n/s and die "a bad filename >$d< contains a newline!!\n";
	opendir DIR, $d;
	$has_cvs = 0;
	while (defined ($_ = readdir DIR)) {
		next if /^\.\.?\z/s;
		if (/CVS/ and -d "$d/CVS") { $has_cvs = 1; }
		else { # has something else; skip
			next D;
		}
	}
	if ($has_cvs) {
		for $f (<$d/CVS/*>) { unlink $f; }
		rmdir("$d/CVS");
	}
	rmdir($d);
}
