#!/bin/sh
#
# Sum up points in @grade file.
# Looks for lines matching 
#   "== Score: MM out of NN" 
# or 
#   "Score: MM out of NN"
#
if [ -z "$1" ]
then
    echo usage `basename $0` file
    exit 1
fi
if [ ! -f "$1" ]
then
    echo "$1" not found
    exit 2
fi
outfile=tmp-$$
if [ -r $outfile ]
then
    rm $outfile
fi
grep "^== Score:" "$1" >> $outfile
grep "^Score:" "$1" >> $outfile
points=`sed -e 's/^.*Score://' -e 's/out of.*//' $outfile | tr '\n' '+'`
sum=`echo "$points" | sed -e 's/+ *$//' | bc`
rm -v $outfile
echo "Total score:  $sum" >> "$1"

