#!/bin/csh -f
#***********************************************************************\
#									*
# Copyright (C) 1993, ElectroGIG Nederland BV, The Netherlands		*
# 									*
# ElectroGIG Nederland							*
# Amstel 222								*
# 1017   AJ Amsterdam							*
# tel:   020-6233495							*
# fax:   020-6226801							*
# email: cm@gig.nl							*
#									*
#***********************************************************************/

# check if user is root
set user=`whoami`


if ( $user == root ) then
  echo do not run this script as root
  exit 1
endif

onintr cleanup

switch(`uname -m`)
   case IP[0-9]:
   case IP[0-9][0-9]:
   case IP[0-9][0-9][0-9]:
      set m = iris
      breaksw
   case MIPS:
   case RISC:
      set m = dec
      breaksw
   case sun:
   case sun4:
   case sun4[a-z0-9]:
      set m = sun
      breaksw
   case 9000/[0-9][0-9][0-9]:
      set m = hp
      breaksw
   case i[0-9]86:
      set m = i86
      breaksw
    default:
      echo unknown machine
      exit 1
endsw

if ( ! $?DISPLAY ) then
    setenv DISPLAY `hostname`':0.0'
endif


if ( $?LG && $?GM && $?GB ) then
   set bin=$LG/$GM/$GB
else if ($?GIG_D_BIN) then
   set bin=$GIG_D_BIN
else
   set bin=.
endif

if ($?GIG_D_TOOLUTILS) then
  set utils=$GIG_D_TOOLUTILS
else
  set utils=.
endif

set testfiles = ""
set demofiles = ""
/bin/rm -f $GIG_D_BIN/Demo_gt
/bin/rm -f $GIG_D_BIN/Nurbs_gt
/bin/rm -f $GIG_D_BIN/ProjectManager_gt
/bin/rm -f $GIG_D_BIN/Converter_gt
/bin/rm -f $GIG_D_BIN/Flipbook_gt
/bin/rm -f $GIG_D_BIN/Online_gt
/bin/rm -f $GIG_D_BIN/'Flow Motion_gt'
/bin/rm -f $GIG_D_BIN/RenderClient_gt
/bin/rm -f $GIG_D_PROJECTS/*_prj/intenv/tmpscrnlay.txt >& /dev/null
set converters = ""


set gig = $bin/gig

if ($m == sun) then
  if( -e ${gig}X ) then
    xdpyinfo -display :0.0 | fgrep -s X3D-PEX
    if ( $status ) then
      set gig = ${gig}X
    else
      set db_sup = `pexdpyinfo -impDepConstants | grep DoubleBufferSupported | awk '{print $2}'`
      if ( $db_sup == 0 ) then
        set gig = ${gig}X
      endif
    endif
  endif
  uname -a | fgrep -s sun4u
  if( ! $status && -e ${gig}ULTRA ) then
    set gig = ${gig}ULTRA
  endif
endif

set binargs=

while ($#argv > 0)
  set tmp=$1
  shift argv
  if ("--" == "$tmp") then
    break
  else if ("-t" == "$tmp") then
    set testfiles = "$testfiles $1"
    shift
  else if ("-i" == "$tmp" ) then
    # intdebug option for GIG/3D-GO
    set binargs = ($binargs -d)
  else if ("-a" == "$tmp" ) then
    set binargs = ($binargs $1)
    shift
  else if ("-d" == "$tmp" ) then
    set demofiles = "gigdemoopen gigdemo "
    touch $GIG_D_BIN/Demo_gt
  else
    set gig = $bin/gig$tmp
  endif
end
if ($#argv > 0) then
  set binargs = ($binargs $argv)
endif

foreach f (`/bin/ls $GIG_D_INTERCOL/*_conv.int $GIG_D_INTERCOL/*_out.int`)
  set sf = $f:t
  set sf = $sf:r
  if( -e $GIG_D_TOOLUTILS/$sf) then
    set converters = "$converters $sf"
  endif
end


if ( -e $GIG_D_TOOLUTILS/startProjectManager && -e $GIG_D_TOOLUTILS/tkui) then
  touch $GIG_D_BIN/ProjectManager_gt
endif

if ( -e $GIG_D_TOOLUTILS/startConverter && -e $GIG_D_TOOLUTILS/tkui) then
  touch $GIG_D_BIN/Converter_gt
endif

if ( -e $GIG_D_TOOLUTILS/startRenderClient && -e $GIG_D_TOOLUTILS/tkuidp) then
  touch $GIG_D_BIN/RenderClient_gt
endif

if ( -e $GIG_D_TOOLUTILS/startFlipbook && -e $GIG_D_TOOLUTILS/tkui) then
  touch $GIG_D_BIN/Flipbook_gt
endif

if ( -e $GIG_D_TOOLUTILS/startOnline && -e $GIG_D_TOOLUTILS/online) then
  $GIG_D_TOOLUTILS/online -l
  if (! $status ) then
    touch $GIG_D_BIN/Online_gt
  endif
endif

#initialise nurbs-module
if ( -e $GIG_D_INTERCOL/nurbs.int && -e $GIG_D_BIN/Nurbs_modeler) then
  $GIG_D_BIN/Nurbs_modeler check_license
  if ( ! $status ) then
    touch $GIG_D_BIN/Nurbs_gt
  endif
endif

#initialise flowmotion-module
if ( -e $GIG_D_INTERCOL/fminit.int ) then
  touch $GIG_D_BIN/'Flow Motion_gt'
endif

#initialise mapfactory
if ( -e $GIG_D_INTERCOL/mapfinit.int ) then
  set testfiles = "$testfiles mapfinit"
endif

if ( !(-f $gig)) then 
   echo file $gig does not exist 
   exit
endif

if ( !(-x $gig) ) then 
   echo file $gig is not executable 
   exit
endif


# create temp directory for evaluation and remove when done


$gig	$binargs gigfiles \
	$demofiles $converters gigx $testfiles gigmain

cleanup:


