#! /bin/sh
# file: o2_testsuite.bat
# test suite for o2
echo "////////////////////////////////////////"
echo "////////////o2_testsuite.bat////////////"
echo "////////////testing syntax part of o2///"
echo "////////////////////////////////////////"
qa="/usr/local/yacco2/qa/"
o2=/usr/local/yacco2/bin/o2
tmp=/tmp/o2
sw1=
sw2=
sw3=
sw4=
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
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 $1"
  eval "$o2 $sw1 $1"
  echo "------------------------------------------------"
  echo " "
  # once gened is enough for the various T gening
  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 $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"fsm_class_phrase4.dat  "$qa"fsm_class_phrase4
cc_lex  "$qa"fsm_class_phrase5.dat  "$qa"fsm_class_phrase5
echo "//////////////////////////////test out cli options/////////////"
echo "bad rc cli switch deprecated"
sw1=-rc
cc_lex  "$qa"lr1_sp2.lex  "$qa"lr1_sp2
echo "bad lrk cli switch deprecated"
sw1=-lrk
cc_lex  "$qa"lr1_sp2.lex  "$qa"lr1_sp2
echo "bad prefix cli switch"
sw1=-e
cc_lex  "$qa"lr1_sp2.lex   "$qa"lr1_sp2
echo "bad prefix cli switch"
sw1=-er
cc_lex  "$qa"lr1_sp2.lex   "$qa"lr1_sp2
echo "bad too long overrun cli switch"
sw1=-errr
cc_lex  "$qa"lr1_sp2.lex   "$qa"lr1_sp2
echo "bad cli switch"
sw1=-n
cc_lex  "$qa"lr1_sp2.lex   "$qa"lr1_sp2
echo "bad cli switch"
sw1=-tT
cc_lex  "$qa"lr1_sp2.lex  "$qa"lr1_sp2
echo "bad cli switch"
sw1=-lr
cc_lex  "$qa"lr1_sp2.lex  "$qa"lr1_sp2
echo "bad cli switch --- act as a file name"
sw1=/x
cc_lex  "$qa"lr1_sp2.dat  "$qa"lr1_sp2
echo "bad cli switch deprecated"
sw1=-pp
cc_lex  "$qa"lr1_sp2.lex   "$qa"lr1_sp2
cc_lex  "$qa"lr1_sp21.lex  "$qa"lr1_sp2
echo "all switches good"
sw1="-err -t -p" 
echo "//////////////////////////////finished test out cli options/////////////"
sw1=" " 
cc_lex  "$qa"file_include1.dat  "$qa"file_include1
cc_lex  "$qa"file_include2.dat  "$qa"file_include2
cc_lex  "$qa"fsm_class_phrase.dat  "$qa"fsm_class_phrase
cc_lex  "$qa"fsm_class_phrase1.dat  "$qa"fsm_class_phrase1
cc_lex  "$qa"fsm_class_phrase2.dat  "$qa"fsm_class_phrase2
cc_lex  "$qa"fsm_class_phrase3.dat  "$qa"fsm_class_phrase3
cc_lex  "$qa"fsm_class_phrase4.dat  "$qa"fsm_class_phrase4 
cc_lex  "$qa"fsm_class_phrase5.dat  "$qa"fsm_class_phrase5 
cc_lex  "$qa"fsm_class_phrase6.dat  "$qa"fsm_class_phrase6 
cc_lex  "$qa"fsm_class_phrase7.dat  "$qa"fsm_class_phrase7 
cc_lex  "$qa"fsm_class_phrase8.dat  "$qa"fsm_class_phrase8
cc_lex  "$qa"fsm_class_phrase9.dat  "$qa"fsm_class_phrase9 
cc_lex  "$qa"fsm_class_phrase10.dat  "$qa"fsm_class_phrase10 
cc_lex  "$qa"fsm_class_phrase11.dat  "$qa"fsm_class_phrase11 
cc_lex  "$qa"fsm_class_phrase12.dat  "$qa"fsm_class_phrase12 
cc_lex  "$qa"fsm_class_phrase13.dat  "$qa"fsm_class_phrase13 
cc_lex  "$qa"fsm_class_phrase14.dat  "$qa"fsm_class_phrase14 
cc_lex  "$qa"fsm_class_phrase15.dat  "$qa"fsm_class_phrase15 

cc_lex  "$qa"rule1.dat  "$qa"rule1
cc_lex  "$qa"rule2.dat  "$qa"rule2
cc_lex  "$qa"rule3.dat  "$qa"rule3
cc_lex  "$qa"rule4.dat  "$qa"rule4
cc_lex  "$qa"rule5.dat  "$qa"rule5
cc_lex  "$qa"rule6.dat  "$qa"rule6
cc_lex  "$qa"rule7.dat  "$qa"rule7
cc_lex  "$qa"rule8.dat  "$qa"rule8 
cc_lex  "$qa"rule9.dat  "$qa"rule9 

cc_lex  "$qa"rule_test2.dat  "$qa"rule_test2 
cc_lex  "$qa"t_enum.dat  "$qa"t_enum 
cc_lex  "$qa"t_enum1.dat  "$qa"t_enum1 
cc_lex  "$qa"t_enum10.dat  "$qa"t_enum10 
cc_lex  "$qa"t_enum11.dat  "$qa"t_enum11 
cc_lex  "$qa"t_enum2.dat  "$qa"t_enum2 
cc_lex  "$qa"t_enum3.dat  "$qa"t_enum3 
cc_lex  "$qa"t_enum4.dat  "$qa"t_enum4 
cc_lex  "$qa"t_enum5.dat  "$qa"t_enum5
cc_lex  "$qa"t_enum6.dat  "$qa"t_enum6
cc_lex  "$qa"t_enum7.dat  "$qa"t_enum7
cc_lex  "$qa"t_enum8.dat  "$qa"t_enum8 
cc_lex  "$qa"t_enum9.dat  "$qa"t_enum9 
cc_lex  "$qa"term_test1.dat  "$qa"term_test1 
cc_lex  "$qa"term_test2.dat  "$qa"term_test2 
cc_lex  "$qa"term_test3.dat  "$qa"term_test3
cc_lex  "$qa"term_test4.dat  "$qa"term_test4 
cc_lex  "$qa"term_test5.dat  "$qa"term_test5 
cc_lex  "$qa"term_test6.dat  "$qa"term_test6 
cc_lex  "$qa"term_test7.dat  "$qa"term_test7
cc_lex  "$qa"term_test8.dat  "$qa"term_test8 
cc_lex  "$qa"term_test9.dat  "$qa"term_test9 

cc_lex  "$qa"parallel_parser1.dat  "$qa"parallel_parser1 
cc_lex  "$qa"parallel_parser2.dat  "$qa"parallel_parser2 

cc_lex  "$qa"fsm_op.dat  "$qa"fsm_op 
cc_lex  "$qa"fsm_op1.dat  "$qa"fsm_op1 
cc_lex  "$qa"fsm_op10.dat  "$qa"fsm_op10 
cc_lex  "$qa"fsm_op2.dat  "$qa"fsm_op2
cc_lex  "$qa"fsm_op3.dat  "$qa"fsm_op3
cc_lex  "$qa"fsm_op4.dat  "$qa"fsm_op4 
cc_lex  "$qa"fsm_op5.dat  "$qa"fsm_op5 
cc_lex  "$qa"fsm_op6.dat  "$qa"fsm_op6 
cc_lex  "$qa"fsm_op7.dat  "$qa"fsm_op7 
cc_lex  "$qa"fsm_op8.dat  fsm_op8 
cc_lex  "$qa"fsm_op9.dat  "$qa"fsm_op9 

cc_lex  "$qa"err_sym.dat  "$qa"err_sym 
cc_lex  "$qa"err_sym1.dat  "$qa"err_sym1 
cc_lex  "$qa"err_sym10.dat  "$qa"err_sym10 
cc_lex  "$qa"err_sym11.dat  "$qa"err_sym11 
cc_lex  "$qa"err_sym2.dat  "$qa"err_sym2 
cc_lex  "$qa"err_sym3.dat  "$qa"err_sym3 
cc_lex  "$qa"err_sym4.dat  "$qa"err_sym4 
cc_lex  "$qa"err_sym5.dat  "$qa"err_sym5 
cc_lex  "$qa"err_sym6.dat  "$qa"err_sym6 
cc_lex  "$qa"err_sym7.dat  "$qa"err_sym7 
cc_lex  "$qa"err_sym8.dat  "$qa"err_sym8 
cc_lex  "$qa"err_sym9.dat  "$qa"err_sym9 

cc_lex  "$qa"1.dat  "$qa"1 
cc_lex  "$qa"a.dat  "$qa"a 
cc_lex  "$qa"eol.dat  "$qa"eol 

cc_lex  "$qa"cmd_line.dat  "$qa"cmd_line 
cc_lex  "$qa"cmd_line1.dat  "$qa"cmd_line1 
cc_lex  "$qa"cmd_line2.dat  "$qa"cmd_line2 
cc_lex  "$qa"cmd_line3.dat  "$qa"cmd_line3 
cc_lex  "$qa"cmd_line4.dat  "$qa"cmd_line4 


