#! /bin/sh
# Author: Nigel Goddard 
#
# MAKE SURE YOU SET THE VARIABLES bitmap AND bmtoa FOR YOUR SITE !!
#
# format is: makeicon <icon-name> [+intervals (8)] [-intervals (8)]"
# icon files will be named icon-name_0, icon-name_1, ..., icon-name_x,
# icon-name_x+1, ..., icon-name_y, where x is the number of negative
# intervals (default is 8) and (y-x) is the number of positive intervals
# (default is 8).  Of course the range in the show command must suit
# these interval choices, otherwise some negative icons will be displayed
# for positive values, or vice versa.  This script generates the appropriate
# filenames and then calls bitmap which puts up a window to generate an icon.
# When you have generated it, click on write-output and quit, and the shell
# script will convert the icon specification to ascii and call bitmap again
# so you can design the next icon in the range.  The script starts with the
# icon representing the largest positive value, works down to the lowest
# positive icon, then goes from most negative to least negative icons, and
# finally generates the zero icon.  If the number of positive and negative
# intervals are equal, then the negative icons will be initialized to the
# corresponding positive icon before bitmap is called - you may just want
# to invert the positive icon to generate the negative one.
#


bitmap=/usr/local/X/clients/bitmap/bitmap
bmtoa=/usr/local/X/clients/bitmap/bmtoa
if test $1
then
	name=$1
	if test $2
	then
		pcount=$2
	else
		pcount=8
	fi
	if test $3
	then
		ncount=$3
	else
		ncount=8
	fi
	total=`echo "$pcount + $ncount" | bc`
	echo "Making icon family $name, with $total members"
	echo "Positive icons first, largest to smallest"
	tc=$pcount
	while test $tc -gt 0
	do
		cur=`echo "$pcount + $tc" | bc`
		fname="$name"_"$cur".bm
		aname="$name"_"$cur"
		if test $tc -lt $pcount
		then
			cp $pfname $fname
		fi			
		echo "Making $aname ($fname)..."
		$bitmap $fname
		$bmtoa $fname > $aname
		tc=`echo "$tc - 1" | bc`
		pfname=$fname
	done
	if test $pcount -ne $ncount
	then
		echo "Now the negative icons, largest first"
		cur=0
		while test $cur -le $ncount
		do
			fname="$name"_"$cur".bm
			aname="$name"_"$cur"
			if test $cur -lt $ncount
			then
				cp $pfname $fname
			fi			
			echo "Making $aname ..."
			$bitmap $fname
			$bmtoa $fname > $aname
			cur=`echo "$tc - 1" | bc`
			pfname=$fname
		done
	else
		echo "Now the negative icons, largest first, based on positive"
		cur=1
		while test $cur -le $ncount
		do
			pname="$name"_`echo "$total - $cur + 1" | bc`.bm
			fname="$name"_"$cur".bm
			cp $pname $fname
			aname="$name"_"$cur"
			echo "Making $aname ..."
			$bitmap $fname
			$bmtoa $fname > $aname
			cur=`echo "$cur + 1" | bc`
			pfname=$fname
		done
	fi
	echo "Now the icon for zero"
	fname="$name"_0.bm
	aname="$name"_0
	echo "Making $aname ..."
	$bitmap $fname
	$bmtoa $fname > $aname
else
	echo "Usage: makeicon <icon-name> [+intervals (8)] [-intervals (8)]"
	echo "Look at the shell script for more information."
fi
