#! /bin/csh

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

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

cd $testpath

set tests = `ls tc??.txt`

cd $rpath

touch p5_grades

set i = 1

foreach x ($logins)

  set gradefile = "$rpath/du/$x/P5/$x.p5.gr"
  rm $gradefile
  touch $gradefile

  cd du/$x/P5

  echo "Grading $x"
  echo `pwd`

  make

  cd src

  set grade = 0

  foreach t ($tests)

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

    awk '{ print $1 }' $t.out > temp1
    awk '{ 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" >> p5_grades
  @ i = $i + 1
end
