#! /bin/sh
# file: o2_testsuite2.bat
# test suite2 for o2linker not very complete
echo "////////////////////////////////////////"
echo "////////////o2linker_testsuite2.bat////////////"
echo "////////////////////////////////////////"
qa="/usr/local/yacco2/qa/"
o2=/usr/local/yacco2/bin/o2linker
tmp=/tmp/o2
if [ ! -e "$tmp" ] 
then
  mkdir $tmp
fi
cd $tmp
prt_pdf=0
delete_files=1
#echo '\input eplain' > $tmp/eplain.txt
cont=n
ccresult=0

sw1=$1
sw2=$2
sw3=$3
sw4=$4

file_no=$((0))
file_pos=$((1))
cc_lex()
{
  echo "    =====Grammar=> $1 <===File==="
  sed -n -f '/usr/local/yacco2/qa/qa_echo.sedt' "$1" | sh
  file_name_only="`basename $2`"
  dir_only="`dirname $2`"
  #echo "%%%%%%%%%%%%%%%%target directory $dir_only"
  echo "	executing command line=>: $o2 $sw1 $sw2 $sw3 $sw4 $1"
  eval "$o2  $sw1 $sw2 $sw3 $sw4 $1"
  echo "------------------------------------------------"
  echo " "
  # once gened is enough for the various T gening
  sw1=
  sw2=
  sw3=
  sw4=
  if test $ccresult -eq 1; then
    echo -n "grammar in error: continue y or n: ";
    read cont;
    if test $cont -eq n; then
      echo "Error in grammar exiting";
      exit 1;
    fi
  fi 
  if test $prt_pdf -eq 1; then
   eval "mpost $file_name_only.mp"
   eval "cweave $file_name_only.w"
   ##eval "cat eplain.txt $file_name_only.tex > $file_name_only.tex1"
   eval "pdftex $file_name_only.tex"
   xref="$file_name_only""_idx"
   echo "%%%%%%%%%%%%%%%%% index file: $xref to cweave and pdftex"
   eval "cweave $xref.w"
   eval "pdftex $xref.tex"
   pdftops "$file_name_only.pdf"
   pdftops "$xref"".pdf"
  fi
if test $delete_files -eq 1; then
  for k in `ls * `;
  do
   #echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!Casing on $k"
   case $k in
    *.cpp|*.h) 
      eval "cp $k $dir_only/$k";
      #echo "-----Copying--------> $k to $dir_only/$k"
      eval "rm -f $k" 
;;
    *.fsc) 
      eval "cp $k $dir_only/$k";
      #echo "-------------> Deleting $k"
      eval "rm -f $k" ;;
    *.scn|*.idx|*.log|*.toc)
      #echo "-------------> Deleting $k"
      eval "rm -f $k" 
;;
    Err.w|T.w) # error and terminal documents to be cweave then pdftex printed by xpdf
      #echo "-------------> Deleting $k"
      #eval "rm -f $k" eof
;;
    *.w)
      #echo "-------------> Deleting $k"
      #eval "rm -f $k" 
;;
    *.tex)
      #echo "-------------> Deleting $k"
      eval "rm -f $k" 
;;
    *.mp)
      #echo "-------------> Deleting $k"
      eval "rm -f $k" 
;;
    *.tex1)
      #echo "-------------> Deleting $k"
      eval "rm -f $k" 
;;
    *.[1-9])
      #echo "-------------> Deleting Mpost diagrams $k"
      eval "rm -f $k" 
;;
     *.[1-9][0-9]*)
      #echo "-------------> Deleting Mpost diagrams $k"
      eval "rm -f $k"
 ;;
   esac
  done
fi
}

cc_lex "$qa"TS.fsc "$qa"TS
cc_lex "$qa"TS1.fsc "$qa"TS1

