#get parameters for log tty, if not already done.

if [ "$logpars_done" != y ]; then

export logpars_done=y

echo
if ! preset makeindexfile; then
 printf "Make a $ttytitle index file "
 getpar makeindexfile n yn
fi
allpars makeindexfile

#special case if pars option given.
if [ "$only_params" = y ]; then

 if [ $makeindexfile = y ]; then 
  echo

  if ! preset autoindexname; then
   printf "Automatically generate and use index file name "
   getpar autoindexname n yn
  fi
  allpars autoindexname

  if [ $autoindexname = n ]; then
   echo
   getfilename indexfilename "$ttytitle index file name" new
  fi
  
  echo
   
  if ! preset gzipindexfile; then
   printf "Gzip the $ttytitle index file that will be made? "
   getpar gzipindexfile y yn
  fi
  allpars gzipindexfile

 fi

else

if [ $makeindexfile = y ]; then
 
 #think up nice default name.
 if [ $indexdir = "." ]; then 
   indexdir=$userwd
 fi
 
 export dea_indexfilename=$indexdir/$ttytitle.idx.1
 
 #special case for set method on tbackup
 if [ "$ttytitle" = "backup" ]; then
  if [ "$choosemethod" = "set" ]; then
   export dea_indexfilename=$indexdir/$setname.idx.1
  fi
 fi
 #special case for set method on tlist
 if [ "$ttytitle" = "list" ]; then
  if [ "$dea_choosemethod" = "set" ]; then
    export dea_indexfilename=$indexdir/$dea_setname.idx.1
  fi
 fi


#increase index file number, if necessary.

 tmp=`echo $dea_indexfilename | gawk -F. '{ print $NF; }'`
 if i2split $tmp &>/dev/null; then
  tmp2=`echo $dea_indexfilename | gawk -F. '{ OFS="."; $NF=""; print }'`
  ls $tmp2* 2>/dev/null | \
  gawk -v n=$tmp -W lint -F. '
$NF ~ /[0-9]+/ { if($NF>=n) n=$NF+1; }
($NF ~ /(gz)|z|Z/ ) && ( $(NF-1) ~ /[0-9]+/ ) { if($(NF-1)>=n) n=$(NF-1)+1; }
END { print n; }' >nr
  export dea_indexfilename=$tmp2`cat nr`
  rm nr
 fi

 autoindexname=n
 if [ "$dea_autoindexname" = y ]; then autoindexname=y; fi
 if [ "$pre_autoindexname" = y ]; then autoindexname=y; fi
 if [ "$checkpre_autoindexname" = y ]; then autoindexname=y; fi

 if [ $autoindexname = y ]; then
   export indexfilename=$dea_indexfilename
   echo "The $ttytitle index file name is $indexfilename."
   echo >$indexfilename
   if [ ! -f $indexfilename ]; then
     echo "Oops, trouble creating $indexfilename."
     getfilename indexfilename "$ttytitle index file name" new nodea
   fi
 else

   echo
   getfilename indexfilename "$ttytitle index file name" new nodea

 fi

 dea_rpars indexfilename
 allpars indexfilename
 
fi

echo 

#batch mode?
if [ $batchmode = y ]; then

 echo "  [Batch mode.  See the index file, if made, for progress info.]"
 ln -s /dev/null /tmp/tbup/logttydev

else
#running on a vitual console or under X?
if [ $virtcons = y ]; then 

 ln -s /dev/tty$progressconsole /tmp/tbup/logttydev
 stty sane </dev/tty$progressconsole
 echo "  [The $ttytitle progress will be displayed on virtual console $progressconsole.]"

else

 echo "  [Creating $ttytitle progress window.]"
 if [ "`type -all xterm 2>/dev/null`" != "" ]; then
  cd /tmp
  xterm -sb -sl 500 -geometry $progressgeometry -title "$ttytitle progress" \
      -e $binbup\logxterm &
  cd /tmp/tbup
  
#wait for creation of logttydev, handle premature xterm exit
  while [ ! -e /tmp/tbup/logttydev ]; do 
   if [ ! -e /proc/$! ]; then
     echo "WARNING: Can't create progress window.  Backup progress to /dev/null."
     ln -s /dev/null /tmp/tbup/logttydev
     break
   fi
   sleep 1
  done
 else
  echo "WARNING: Can't find xterm program.  Backup progress to /dev/null."
  ln -s /dev/null /tmp/tbup/logttydev
 fi
fi
 #virtcons
fi
 #batchmode

fi
 #(only_params)

fi
 #(!logpars_done)
