#!/bin/ksh

# Get the name of the test directory...
testdir=$1;

# Ensure that the directory exists...
if [ ! -d "$testdir" ]
then

   # It doesn't so barf...
   echo "Directory: $testdir does not exist"
   echo "Usage: $0 [directory]"
   exit 1

fi

# Now cd to the directory.
cd $testdir

# Tell the User what the directory is...
echo "Current directory is: $testdir"
echo "Proceed with cleanup [y/n]?"

read response

# Check the response
case "$response" in
       N|n|No|NO|no) echo "Exiting, no action taken"
	             exit 1;;
esac

# Remove all the OPTIONS* PREFACE* STRUCTURE* TITLE* VERSION* files
rm -f OPTIONS* PREFACE* STRUCTURE* TITLE* VERSION*

# Create the file list name.
fileslist=/tmp/$0.$$.fileslist

# Now find all the files that end with ~
find . -name "*~" > $fileslist

# Now for each file found remove it...
for file in `cat $fileslist`
do

    # Tell the User.
    echo "Removing file: $file"

    rm -f $file

done

# Remove the temporary file.  Just in case.
rm $fileslist

# Handle the DOC files...
find . -name "DOC*" > $fileslist

for file in `cat $fileslist`
do

    # Tell the User.
    echo "Removing file: $file"

    rm -f $file

done

# Remove the temporary file.  Just in case.
rm $fileslist

# Handle the CVS dirs...
find . -name "CVS*" > $fileslist

for file in `cat $fileslist`
do

    # Tell the User.
    echo "Removing: $file"

    rm -rf $file

done

# Remove the temporary file.  Just in case.
rm $fileslist

# Handle the #* files.
find . -name "#*#" > $fileslist

for file in `cat $fileslist`
do

    # Tell the User.
    echo "Removing file: $file"

    rm -rf $file

done

# Remove the temporary file.  Just in case.
rm $fileslist

# Handle the .#* files.
find . -name ".#*" > $fileslist

for file in `cat $fileslist`
do

    # Tell the User.
    echo "Removing file: $file"

    rm -rf $file

done

# Remove the temporary file.  Just in case.
rm $fileslist
