#!/bin/csh -f
# echo 'Arguments are: ' $*
#************************************************************************
#
#			Projet     Formel
#
#			    ML in ML
#
#*************************************************************************
#
#            			Inria
#			Domaine de Voluceau
#			78150  Rocquencourt
#				France
#
#*************************************************************************
#
# camlyacc      camlyacc Script Cshell
#		Calls yacc, then a filter, then the CAML compiler
# Try to guess format of yacc output (different for 4.xBSD and SV)
#
if (! $?CAMLSYS) setenv CAMLSYS BSD
set CAML = '/usr/local/caml/V2-6.1'
setenv PATH :$CAML/camlyacc:/bin:/usr/local/bin:/usr/bin:/usr/ucb
set CLEAN = '/bin/rm -f camlyacc.lock'

onintr ERROR
if ($argv[1] == '-v' ) then
	set flag = ' -v'
	shift
else
	set flag = ''
        set CLEAN = "$CLEAN y.tab.c"
endif
set EDIT = "$CAML/camlyacc/$CAMLSYS/camlyacc.sh"
if ($?GEMACSCOMPILER) then
   	set EDIT = "gemacs -batch -l $CAML/camlyacc/$CAMLSYS/camlyacc.el"
endif
#if ($argv[1] == '-ge' ) then
#	set EDIT = "gemacs -batch -l $CAML/camlyacc/$CAMLSYS/camlyacc.el"
#	shift
#endif
set FILE = $argv[1]
if (-e camlyacc.lock) then
	echo 'Another camlyacc in progress'
	exit 1
else
	touch camlyacc.lock
endif
set SYNTAX = `sed -n -e '/^let current_syntax = /s/^let current_syntax = \"\(.*\)\";;$/\1/p' $FILE.ly | sed -n -e 1p`
if ("$flag" == ' -v') then
    echo ''; echo SYNTAX is \"$SYNTAX\" FILE is \"$FILE\"
endif
yacc $flag $FILE.ly || goto ERROR
test -s y.tab.c || goto ERROR
echo ''
echo -n 'Editing y.tab.c ...'
($EDIT $SYNTAX >! $FILE\_mly.ml) || goto ERROR
echo ''
eval $CLEAN 
exit 0

ERROR:
eval $CLEAN ; exit 1
