#! /usr/bin/perl
#
# Produces script to remove the labelfiles from the directories and CVS
#
# Use:
# <command to list> | RemoveLabelfile.pl
#
# Or
# RemoveLabelfile.pl filelist.txt
#
# Reads basenames from a file or standard input.
#
################################################################################
#
# Copyright R.J.J.H. van Son © 2001
#
# Author David Weenink, Rob van Son
# Institute of Phonetic Sciences & ACLC
# University of Amsterdam
# Herengracht 338
# NL-1016CG Amsterdam, The Netherlands
# Email: Rob.van.Son@hum.uva.nl
#        rob.van.son@workmail.com
# WWW  : http://www.fon.hum.uva.nl/rob/
# mail:  Institute of Phonetic Sciences
#        University of Amsterdam
#        Herengracht 338
#        NL-1016CG Amsterdam
#        The Netherlands
#        tel +31 205252183
#        fax +31 205252197
#
# License for use and disclaimers
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
#
#######################################################
#
my $HomeDir = "..";
require "$HomeDir/Links.pl";
require '../Links.pl' || die "require: $!\n";
while(<>)
{
	my @Line = split;
	while($File = shift(@Line))
	{
		next unless $File =~ /^([A-Z]+\d+[A-Z]+)/i;
		my $Speaker = $1;
		my $Extension = 'phoneme';
		if($File =~ /\.([a-z\d]+)$/i)
		{
			$Extension = $1;
			$File = $`;
		};
		my $Path = "$SentenceLabels/$Speaker/$Extension/$File.$Extension";
		
		# File does not exist
		unless(-e "$Path")
		{
			print "File not found: $Path\n";
			next;
		};
		
		# Move file and remove from CVS
		print << "REMOVEFILESCRIPT";
mkdir -p ~/RemovedFiles
mv '$Path' ~/RemovedFiles
cd $SentenceLabels/$Speaker/$Extension
cvs remove $File.$Extension
REMOVEFILESCRIPT
	};
};
