#! /bin/sh

# apsfilter 4.9
# by Andreas Klemm
# Mon Feb  6 19:54:12 MET 1995

# filtersetup	- look for installed filters supported by apsfilter
#		- and write supported filter into the filters_found
#		  database: APS_BASEDIR/global/filters_found

# This script runs normally during first-installation
# If you add more filters to your system (pbmplus utilities, etc...)
# then you must again run this utility to ensure that apsfilter
# knows about the new filters by updating the filters_found file

# printer filter programs supported by apsfilter 3.0
# if you want to add an additional filter, then you have to add the
# name here, too !!!

SUPPORTED_FILTERS="\
	gs \
	dvips \
	a2ps \
	ras2ps \
	giftoppm \
	pnmtops \
	ppmtopgm \
	fig2dev \
	rasttopnm \
	tifftopnm \
	gzip \
	compress \
	pack \
	djpeg \
	melt \
	"

# are we called by SETUP or are we standalone ?
# if standalone, then grab APS_BASEDIR from /etc/printcap file
if [ ! $APS_BASEDIR ]; then
	APS_BASEDIR=`grep APS_BASEDIR /etc/printcap | cut -d ':' -f 2`
	export APS_BASEDIR
fi

. $APS_BASEDIR/global/GLOBAL.sh


echo "cleaning global config file..."
if [ -f $FILTERS_FOUND ]; then
	: > $FILTERS_FOUND
fi

# extract searchpatch for find from PATH
SEARCHPATH=`echo $PATH | sed -e "s/:/\ /g"`

echo "looking for available filter programs on this system..."
for filter in $SUPPORTED_FILTERS
do
	FILTER=`echo $filter | tr 'a-z' 'A-Z'`
	for path in $SEARCHPATH
	do
		if [ -f $path/$filter ]
		then
			set HAVE_$FILTER="True" \
				&& echo "found filter $filter" \
				&& echo "HAVE_$FILTER=True" >> $FILTERS_FOUND
		fi
	done
done

if [ -f $FILTERS_FOUND ]; then
    sort < $FILTERS_FOUND | uniq > /tmp/apsfilterrc.$$
    mv /tmp/apsfilterrc.$$ $FILTERS_FOUND
else
    # a system without special filter
    echo "# no supported filters found during filtersetup ?!" >> $FILTERS_FOUND
    echo "# if you suppose to add filters like dvips, gs,..." >> $FILTERS_FOUND
    echo "# later, then run $APS_BASEDIR/setup/filtersetup  " >> $FILTERS_FOUND
    echo "# again !					    " >> $FILTERS_FOUND
    # mail the poor result !!!
    cat $FILTERS_FOUND | $MAIL root > /dev/null 2>&1
fi
