#!/bin/sh
# texclean -- clean up after tex
#
# SYNOPSIS:  Remove *.log, *.blg, *.dvi-err, *.ilg output files.
#	Giving prefixes causes only files with names starting in that list
#	to be removed.
#	If the -d option is given, removes the *.dvi-alw and *.dvi files also.
#	If the -f option is given, removes the *.aux, *.bbl *.glo *.idx *.ind
#       *.lof *.lot and *.toc files also (but not *.dvi and *.dvi-alw files)
#
# AUTHOR:	Gary T. Leavens

[ -n "$ECHO" ] && set -x

texclean()
{
USAGE="Usage: $0 [-f] [-d] [prefix ...]"

DEFAULTrms='log blg dvi-err ilg'
DVIrms='dvi dvi-alw'
ALLrms='aux dvi bbl glo idx lof lot toc ind'

SUFFIXES="$DEFAULTrms"

# check usage and set SUFFIXES to -f flag
while test `expr X"$1" : X'-.*'` -gt 1
do
	case "$1" in
	-f)
		SUFFIXES="$SUFFIXES $ALLrms"
		shift
		;;
	-d)
		SUFFIXES="$SUFFIXES $DVIrms"
		shift
		;;
	-fd|-df)
		SUFFIXES="$SUFFIXES $ALLrms $DVIrms"
		shift
		;;
	-?)
		echo "$USAGE" >&2
		exit 2
		;;
	-)
		shift
		break
		;;
	esac
done

# for the PC need to also use upper case version of suffixes
SUFFIXES="$SUFFIXES `echo $SUFFIXES | tr [a-z] [A-Z]`"

# all files if no prefix specified
if test $# -eq 0
then
	set '*'
fi


# remove the files
for p
do
	for s in $SUFFIXES
	do
		rm -f ${p}.${s}
	done
done
}


texclean $*

exit 0
