#!/bin/bash
#    Copyright (C) 1996-2005  Ola Lundqvist
#    $Id: rensa 2582 2008-04-29 05:54:45Z ola $
#
#    For full COPYRIGHT notice see the COPYING document.
#
#    If you want more information about the program or updated versions,
#    visit the official homepage at:
#      http://www.opal.dhs.org/programs/rensa/
#    or contact the author at:
#      ola@inguza.com
#
#Name:		rensa
#Author:	Ola Lundqvist <ola@inguza.com>
#Dates:		1996-10-06	Enkel ifsats
#		1997-10-17	Forslinga
#		1998-03-26	Liten omskrivning
#		1998-04-07	Buggfix ang syntax
#		2000-07-25	Created a package and released to the public.
#				Improved it too.
#	        2005-07-04	Concact and copyright update.
#Funktion:	Tar bort alla backup och temporrfiler i en katalog
#		Removes all backup and temporary files in a directory.

if [ "$1" = "--help" ]; then
    echo "USAGE: rensa [--help] dir ..."
    exit
fi

CLEAN="./*~ ./.*~ ./core ./DEADJOE ./#*#"
DIRS="";
CURDIR=$PWD

if [ -z $1 ]; then
    DIRS="."
    #echo Cleaning this directory.
else
    DIRS=$*
fi
for I in $DIRS; do
    if [ -f $I ]; then
	echo "ERROR: $I is a file. Only directories can be specified."
    elif [ -d $I ]; then
	cd $I
	#echo Cleaning $I...
	for II in $CLEAN; do
	    [ ! -f $II ] && continue
	    /bin/rm -f $II &
	done
	cd $CURDIR
    fi
done
