#!/bin/csh
#----A shell script for starting Prolog and doing TPTP2X conversions.
#----The TPTP directory must be set in tptpread, before this is used.

#----Get directories information
echo -n "Absolute name of TPTP2X directory     : "
set TPTP2XDirectory=$<

#----Get Prolog name
echo -n "Name of your Prolog interpreter       : "
set PrologInterpreter=$<

#----Get the required information from the user
echo -n "Files to convert (e.g., Problems/*/*) : "
set FilesToConvert=$<
echo -n "Format to convert to (e.g., setheo)   : "
set FormatToConvertTo=$<
echo -n "Arrangements (e.g., [none,clr])       : "
set Arrangements=$<
echo -n "Absolute name of output directory     : "
set OutputDirectory=$<
echo -n "Shorten flag (either shorten or _)    : "
set ShortenFlag=$<

# echo "TPTP2X directory     = $TPTP2XDirectory"
# echo "Prolog interpreter   = $PrologInterpreter"
# echo "Files to convert     = $FilesToConvert"
# echo "Format to convert to = $FormatToConvertTo"
# echo "Arrangements         = $Arrangements"
# echo "Output directory     = $OutputDirectory"
# echo "Shorten flag         = $ShortenFlag"

#----Get the TPTP directory from tptpread
cd $TPTP2XDirectory
set PrologFact=`grep "^tptp_directory__(" tptpread`
set TPTPDirectory=`expr match $PrologFact "tptp_directory__('\(.*\)'). *"`
cd $TPTPDirectory

#----Make an input file for Prolog
echo "unix(cd('$TPTP2XDirectory'))." >PrologScript
echo "compile(tptp2X)." >>PrologScript

#----Look for the files from this directory
foreach FilePath ($FilesToConvert)
    echo "tptp2X('$FilePath',$FormatToConvertTo,$Arrangements,'$OutputDirectory',$ShortenFlag)." >>PrologScript
    end
echo "halt." >>PrologScript

#----Invoke the Prolog interpreter with this input
$PrologInterpreter <PrologScript

rm PrologScript
