#!/bin/sh
#
# 	@(#)giganibatch	31.1 96/04/03
#
# script for generating a batch job to render animation files
#
# - calls gig_sa with the necessary intercol file names to generate
#   a batch job and enters the intercol command to start up the batch
#   job via a pipe
# - the first three arguments are taken to be arguments to intercol
#   command 'addanibatch';
# - all following arguments are taken to be intercol file names and are
#   passed on to gig_sa;

TMPDIR=/usr/tmp/gigab$$
mkdir -p $TMPDIR
export TMPDIR
GIGSA="gig_sa"
GIGARG=""
intfiles="intjob giglist videoback giganimap giganibatch0"

if [ -x $GIG_D_BIN/$GIGSA.mips2 ]
then
  if hinv -t cpu | fgrep -s R4 
  then
    GIGSA=$GIGSA.mips2
  fi
fi

if [ -x $GIG_D_BIN/gig_saULTRA ]
then
  if uname -a | fgrep -s sun4u 
  then
    GIGSA=gig_saULTRA
  fi
fi

/bin/rm -f $TMPDIR/$$.int > /dev/null

set -- `getopt vr:i:o:idp: $*`
if [ $? != 0 -o $# -eq 1 ]
then
  echo usage: giganibatch [option] animationname startframenr endframenr 
  echo options:
  echo "      -i intercolfile"
  echo "      -r rendercommand"
  echo "      -o outputcommand"
  echo "      -v render verbose"
  echo "      -p projectname"
  echo eg.
  echo "      giganibatch -r size:100x100:25x25+50x50 -r alias:2,-2 -v -i extra test 1 5"
  echo "      giganibatch -r framestep:10 test 1 40 (renders 1, 11, 21, 31)"
  echo "      giganibatch -o path:/usr/tmp -o basename:hallo -o extension:tga test 1 5"
  echo ""
  echo " alias:2,-2   renders video setting from render menu:"
  echo "               |---|---|---|---|"
  echo "               |   |   |   | h | 0    h = high"
  echo "           |---|---|---|---|---|"
  echo "           |   |   |   |   |   | 1    v = video"
  echo "       |---|---|---|---|---|---|"
  echo "       |   |   |   |   | v |   | 2    d = default"
  echo "   |---|---|---|---|---|---|---|"
  echo "   | l |   |   | d |   |   |   | 3    l = low"
  echo "   |---|---|---|---|---|---|---|"
  echo "     3   2   1   0  -1  -2  -3"
  echo ""
  exit
fi
for i in $*
do
  case $i in
  -d)       GIGARG="$GIGARG -d"; shift;;
  -v | -V)  GIGARG="$GIGARG -r verbose"; shift;;
  -r)       GIGARG="$GIGARG -r $2"; shift 2;;
  -o)       GIGARG="$GIGARG -o $2"; shift 2;;
  -p)       GIGARG="$GIGARG -p $2"; shift 2;;
  -i)       intfiles="$intfiles $2"; shift 2;;
  --)       shift; break;;
  esac
done

if [ $# -lt 3 ]
then
  echo usage: giganibatch [option] animationname startframenr endframenr 
  echo
  exit
fi

aniname=$1
anifrm0=$2
anifrmN=$3

shift
shift
shift

while [ $# != 0 ] 
do
  if test -r $1.int
  then
    intfiles=${intfiles}" "$1
    shift
  fi
done

( echo addanibatch\( \"$aniname\", $anifrm0, $anifrmN\)\;
  echo batchjob\(\)\;
  echo forcedexit\(\)\;) | $GIGSA $GIGARG  $intfiles

/bin/rm -r $TMPDIR
