#!/usr/bin/perl -w
#
#NAME
#  delSCD - Look for simply-named SCD medley files that have multiple versions.
#
#SYNOPSIS
#  delSCD [file]..
#
#DESCRIPTION
#  By default, we just list the SCD medley files.   With  the  +d  option  we also
#  pseudo-delete them by moving them into the old/ subdirectory.
#
#OPTIONS
#
#EXAMPLES
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

$| = 1;
($P = $0) =~ s".*/"";	# Our name, minus directories
$V = $ENV{"V_$P"} || 1;	# Verbose/trace/debug level
$exitstat = 0;			# Set to nonzero for failure

mkdir("old",0775) unless -d 'old';

@files = glob('[A-Z]*[A-Za-z].abc');
file:
for $fil (@files) {
	$fil =~ s/[\r\s]+$//;
	print "--- $fil\n" if $V>2;
	($base,$suff) = ($fil =~ /^(.*)\.(\w+)$/);
	@derivs = glob($base . '?*.*');
	if (@derivs) {
		for $drv (@derivs) {
			$drv =~ s/[\r\s]+$//;
			if ($drv =~ /^$base.+\.$suff$/) {
				print "    $drv\n" if $V>2;
				if (rename($fil,"old/$fil")) {
					print ">>> $fil -> old/$fil\n" if $V>1;
				} else {
					print "### Can't rename(\"$fil\"\"old/$fil\") [$?]\n" if $V>0;
				}
				next file;
			}
		}
	}
}

exit $exitstat;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
