#!/bin/csh -f

if ($#argv < 4) then
  set foo = "$0"
  echo "Usage: $foo:t parent-world child-world locale file1.oa ..."
  exit 1
endif

if (! $?OAKPATH) setenv OAKPATH /usr/misc/.oaklisp

set parent = $1
set child  = $2
set locale = $3
set oafiles = ($argv[4-])

set del = 0

if (-e $child) then
  mv -f $child $child~~
  set del = 1
endif

set switches = (-d -b -G)
if ($?OAKFLIW) then
  set switches = ($OAKFLIW $switches) 
endif
if ($?OAKLISP) then
  set switches = ($OAKLISP $switches) 
endif

echo "(block (dolist (f '(" $oafiles ")) (load f $locale)) (exit)) \
" $child | $OAKPATH/etc/emulator $switches $parent

set estatus = $status

if ($estatus != 0) then
  echo "Oaklisp terminated with status $estatus."
  rm -f $child
  if ($del == 1) mv -f $child~~ $child
  exit $estatus
endif

if ($del == 1) rm $child~~
echo dumped
