#! /bin/csh

set logins = `awk '{ print $1 }' classlist`
set emails = `awk '{ print $2 }' classlist`

set rpath = `pwd`
set testpath = "$rpath/solns/p6/test"

cd $testpath

set tests = `ls tc??.txt tc?.txt`

cd $rpath

touch p6_grades

set i = 1

foreach x ($logins)

  set gradefile = "$rpath/du/$x/P6/$x.p6.gr"
  rm $gradefile
  touch $gradefile

  cd du/$x/P6

  echo "Grading $x"
  echo `pwd`

  make

  cd src

  set grade = 0

  foreach t ($tests)

    java -classpath . edu.du.cs.comp3351.p6.Interpreter < $testpath/$t >& $t.out

    awk -F: '{ print $1 }' $t.out > temp1
    awk -F: '{ print $1 }' $testpath/$t.out > temp2

    set test_passed = `diff temp1 temp2 | wc -l`

    if ($test_passed == 0) then

      @ grade = $grade + 1

      echo "Test $t passed\!" >> $gradefile

    else
      echo "Test $t failed\!" >> $gradefile
    endif

  end

  rm temp1 temp2

  cd ../../../..
  echo "$x $emails[$i] $grade" >> p6_grades
  @ i = $i + 1
end
