#! /bin/csh

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

set tests = "5M4P3S2 associative massociative number parens pms_ops prescedence prescedence2 rightassociative simple stt_ops test1_normal test1_parens tsmm_ops adjops badop badparens nonassoc nooperator notoken"

set rpath = `pwd`
set testpath = "../../../../solns/tests"

touch p2grades

set i = 1

foreach x ($logins)

  set gradefile = "$rpath/$x.hw2.gr"
  touch $gradefile

  cd du/$x/P2

  echo "Grading $x"
  echo `pwd`

  make

  cd src

  set grade = 0

  foreach t ($tests)

    java -classpath . edu.du.cs.comp3351.p2.Parser < $testpath/$t.in >& ../$t.out

    set test_passed = `diff $rpath/solns/tests/$t.want ../$t.out | wc -l`

    if ($test_passed == 0) then

      @ grade = $grade + 5

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

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

  end

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