#! /bin/sh

if [ -z "$w_wims_session" ] || [ ! -d "$w_wims_home/sessions/$w_wims_session" ]; then exit; fi
if [ -z "$w_toefsource" ] || [ ! -f "$w_toefsource" ]; then exit; fi
if [ -z "$w_toefoutput" ]; then exit; fi

basedir=`pwd`
cd $w_wims_home/sessions/$w_wims_session
file=toef.src

echo "cat <<$w_toef_keyword" >$file

sed 's/\\\\\\toef_var/\$w_toef_var/g' $basedir/$w_toefsource >>$file
echo "
$w_toef_keyword
" >>$file

cat <<@ >$w_toefoutput
% TOEF 1.0 type1
% This file is automatically generated. Do not edit by hand!
% Generated by WIMS-Createxo toef-generator.

% {
toef_varcnt=$w_toef_varcnt
$w_exodata
@
cat <<@ >>$w_toefoutput
!exit
% }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% END  OF  TOEF HEADER %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% The following is OEF %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

@

. ./$file >>$w_toefoutput
rm ./$file

rm -rf $w_wims_home/sessions/$w_wims_session/getfile 

mkdir $w_wims_home/sessions/$w_wims_session/getfile
cp $w_toefoutput $w_wims_home/sessions/$w_wims_session/getfile/$w_fichname
