#!/bin/csh
#
# Generic option parser for speech scripts
#
# options are supplied in keyword=value format
#
# version copies soundfiles in local /tmp to speed up access
# removes copies in /tmp after finishing


# Actually do the argument parsing here

set fast = 0
set geometry = 1200x400+0+0
set ft = 16kHzlin
set fussy = 1
set zoom = 0
set zoomval = 4
set trsubdir = trans/
set ussvers = 3.3

# Actually do the argument parsing here

while ( "$1" != "" )
	switch ("$1")
	case *=*:
		set key = `echo $1 | cut -d= -f1`
		set val = `echo $1 | cut -d= -f2`
		eval "set $key "= \'"$val"\'
		unset key val
		shift
		breaksw
        default:
		break
        endsw
end

# end option parser

set reffile = $1
if( $reffile:e == "16" ) then
  set filetype = raw_s16_
  set frequency = 16000
else if( $reffile:e == "al" ) then
  set filetype = al
  set frequency = 8000
endif

set sp1 = `echo $1:r | sed 's/^......//'`
set sp2 = `echo $2:r | sed 's/^......//'`

if( `echo $1:r | sed 's/...$//'` != `echo $2:r | sed 's/...$//'` ) then
  echo not the same dialog...
  if( $fussy ) then
    exit
  endif
endif

set dlg = `echo $1:r | sed 's/..$//'`

if( -e $1 ) then
  echo found $1. good.
else
  echo missing $1...
  exit
endif

if( -e $2 ) then
  echo found $2. good.
else
  echo missing $2...
  exit
endif

if( -w $trsubdir$dlg.mar ) then
  echo found $trsubdir$dlg.mar. good.
else
  echo missing/not writeable $trsubdir$dlg.mar. Contact vm-admin
  exit
endif

if( -w $trsubdir$dlg.trl ) then
  echo found $trsubdir$dlg.trl. good.
else
  echo missing/not writeable $trsubdir$dlg.trl. Contact vm-admin
  exit
endif

cp $1 /tmp
cp $2 /tmp

cat <<EOB>! /tmp/vmussconfig
VMTC
filename=$trsubdir$dlg.mar
label=labeler_ref
ref=1
rows=4
height=50
END
SIGNAL
filename=/tmp/$1
height=80
rows=2
filetype=$filetype
frequency=$frequency
framesize=128
buffsize=500000
label=$1
reflabel=labeler_ref
zoomon=$zoom
vzoom=$zoomval
END
SIGNAL
filename=/tmp/$2
filetype=$filetype
frequency=$frequency
height=80
framesize=128
buffsize=500000
reflabel=signal_1
label=$2
zoomon=$zoom
vzoom=$zoomval
END
EOB

chmod 666 /tmp/vmussconfig

if( `ps | grep -v grep | grep xemacs` != "" ) then
  echo xemacs already running
else
  if ( -e /usr/X11/bin/xemacs ) then
    echo starting xemacs $trsubdir$dlg.trl
    /usr/X11/bin/xemacs -geometry 80x30+0+500 $trsubdir$dlg.trl &
  else
    echo FEHLER: xemacs nicht gefunden !!
  endif
endif

/usr/local/uss-3.0/uss-$ussvers config=/tmp/vmussconfig fast=$fast vmturncut -geometry $geometry 
rm /tmp/vmussconfig
rm /tmp/$1
rm /tmp/$2
