function processDir
{
for a in `ls $1/*.jpg`
do
fname=`echo $a | sed -e s:$2/:: | sed -e s:/:_: | sed -e s/\\\./_/`
printTemplate $fname $a >> $3
done;
for a in `ls $1/*.png`
do
fname=`echo $a | sed -e s:$2/:: | sed -e s:/:_: | sed -e s/\\\./_/`
printTemplate $fname $a >> $3
done;
}

function printTemplate
{
echo $2 | grep "SMOOTH" >/dev/null
if [ $? == 0 ]
then
mode="SMOOTH"
else
mode="NONE"
fi

echo "new t2dImageMapDatablock($1) { 
      imageName = \"./$2\";
      imageMode = \"FULL\";
      frameCount = \"-1\";
      filterMode = \"$mode\";
      filterPad = \"1\";
      preferPerf = \"1\";
      cellRowOrder = \"1\";
      cellOffsetX = \"0\";
      cellOffsetY = \"0\";
      cellStrideX = \"0\";
      cellStrideY = \"0\";
      cellCountX = \"-1\";
      cellCountY = \"-1\";
      cellWidth = \"0\";
      cellHeight = \"0\";
      preload = \"0\";
      allowUnload = \"0\";
      force16Bit = \"0\";
   };"
}

if [ -z $3 ]
then
echo "Usage: $0 <template file> <output file> <image dir>"
exit 1
fi

cat $1 > $2

for a in `find_unix $3 -type d`
do
processDir $a $3 $2
done

echo "};">>$2
