#!/bin/bash

COURSE=$1
[[ $1 == "" ]] && COURSE=$(basename $PWD)

# throw the intermediate results on /dev/shm tmpfs filesystem
FILELF=/dev/shm/"$COURSE"_FILEL_INPUTS

# new method, ripping off the spellcheck algo!
rm -f $FILELF
for names in $(common/listfiles.sh) ; do 
    grep -rI \\filelink{ $names  \
	| sed -e s/filelink/FuckYouAssHole/g \
	| sed s+.*\FuckYouAssHole{++g \
	| sed 's/}.*//' >> $FILELF
done
# check links only once

sort -u $FILELF > EATSHIT
mv -f EATSHIT $FILELF
# first sed step makes no sense but it fails without it
# there is something speical about the name filelink,
#  anything else works such as kernlink, url etc.


cat $FILELF | while read FILE ; do
    FNAME=$FILE
    if [[ -e $FNAME ]] ; then
	echo "EXISTS:    "$FNAME 
    else
	echo "DOES NOT EXIST: "$FNAME
    fi
done

exit
grep -rI \\filelink{ ../MODULES/"$COURSE"_* \
    | sed -e s/filelink/FuckYouAssHole/g \
    | sed s+.*\FuckYouAssHole{++g \
    | sed 's/}.*//' > $FILELF
