#!/bin/sh
programName=`basename $0`

onpath() {
	curpath=$PATH

	IFS=:
    for i in $curpath
	do

		if [ -x $i/xpaint -a ! -d $i/xpaint ] ; then
	    	found="TRUE"
	    	break
		fi
   	done
}


main() {


	trap exit       1 2 3 4 5 6 7 8  15 16

	if [ ! -f ${ALIAS_BITMAP_LOCATION}/${3}/${2} ]
	then
		cp  ${ALIAS_LOCATION}/bitmaps/${3}/${1} ${ALIAS_BITMAP_LOCATION}/${3}/${2}
		chmod u+w ${ALIAS_BITMAP_LOCATION}/${3}/${2}
	fi

	type=`file ${ALIAS_BITMAP_LOCATION}/${3}/${2}`

	if expr "$type" : '.*\(alias.*pix.*file\).*' >/dev/null ; then
		pix=true
	else
		pix=false
	fi

	if [ $pix = true ] ; then

		${ALIAS_LOCATION}/Gifts/bin/pixtoppm ${ALIAS_BITMAP_LOCATION}/${3}/${2} > ${ALIAS_BITMAP_LOCATION}/${3}/${2}.ppm

	fi

	found="FALSE"
	onpath

	if [ $found = "TRUE" ]
	then
		if [ $pix = true ] ; then
			xpaint ${ALIAS_BITMAP_LOCATION}/${3}/${2}.ppm
		else
			xpaint ${ALIAS_BITMAP_LOCATION}/${3}/${2}
		fi
	else
		if [ $pix = true ] ; then
			${ALIAS_LOCATION}/Gifts/bin/xpaint ${ALIAS_BITMAP_LOCATION}/${3}/${2}.ppm
		else
			${ALIAS_LOCATION}/Gifts/bin/xpaint ${ALIAS_BITMAP_LOCATION}/${3}/${2}
		fi
	fi

	if [ $pix = true ] ; then
		${ALIAS_LOCATION}/Gifts/bin/ppmtopix ${ALIAS_BITMAP_LOCATION}/${3}/${2}.ppm > ${ALIAS_BITMAP_LOCATION}/${3}/${2}
	fi

	/bin/rm -f ${ALIAS_BITMAP_LOCATION}/${3}/${2}.ppm
}

main "$@"

