# CPSC 1011 Lab 1 Grading Script
# Written by Lauren Dukes (lcairco@clemson.edu)

#set up the output csv file to hold the grades
echo "student_id, grade" >> gradelab1.csv

#find all the files in the directory, recursively, that are named lab1.c
for file in $(find . -type f -name "lab1.c" )
#for each of those files
do
        #extract out the student's name from the path
        path=${file%/*}
        studentname=${path##*/}

        #print out user name
        echo "Grading for "+$studentname

        #compile the file
        gcc $file -lm -std=c99
        #run it
        ./a.out

        #ask the grading criteria
        echo "Did the output print Hello world five times? 1 for yes, 0 for no"
        read grade
        #show the .c file so you can look over it
        cat $file

        #write out the grading results for the file as a CSV

        #write out the student's name
        echo -n $studentname >> gradelab1.csv
        echo -n "," >> gradelab1.csv
        #write out the grade and go to next line
        echo $grade >> gradelab1.csv

        #let you know you're moving on to the next file
        echo "Done grading for "+$studentname+"."
        #wait for keyboard input
        read dummy
done

