#! /bin/csh -f

# gradingsetup <dir> <template> [<progfiles>] <gradedfile>:
#       copy the gradesheet <template> into each student's directory which
#		  are all located in the <dir>; name the gradesheet <gradedfile>
#             <dir> is the directory containing the students' directories
#								 with their assignment submissions
#             <template> is the file containing the grading template, 
#                        called gsTemp (must be located in <dir>)
#             <progfiles> is a list of submitted files (if any) in each
#                        student submission directory to be included in the
#                        grading file (** I have not ever used this.)
#             <grading file> is the name of the new file to contain 
#                        <template> + <progfiles> in each submission directory
#		   example: gradingsetup Students gsTemp gs

if ($#argv < 3) then
   echo ""
   echo "gradingsetup <assignment directory> <template> [<submitted files>] <grading file>"
   echo ""
   exit
endif

cd $1
if (-f $2) then
   set class = *
   foreach student ($class)
      if (-d $student) then
         cd $student
         echo -n "   setting up for $student..."
         echo "--- Graded work for $student ---" > $argv[$#argv]
         echo " " >> $argv[$#argv]
         cat ../$2 >> $argv[$#argv]
         if ($#argv > 3) then
            set last = $#argv
            @ last--
            foreach submittedfile ($argv[3-$last])
               echo " " >> $argv[$#argv]
               echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> $argv[$#argv]
               echo "  file $submittedfile :" >> $argv[$#argv]
               echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" >> $argv[$#argv]
               echo " " >> $argv[$#argv]
               echo " " >> $argv[$#argv]
               if (-f $submittedfile) then
                  cat $submittedfile >> $argv[$#argv]
               else
                  echo "*************** file not found" >> $argv[$#argv]
               endif
               echo " " >> $argv[$#argv]
               echo " " >> $argv[$#argv]
            end
         endif
         echo "done"
         cd ..
      endif
   end
else
   echo "  **** The template file $2 was not found. *****"
endif


