#!/bin/tcsh -f

# Check (.html) files on the current directory to see if all the files
# they load (actually anything without quotes that is contained in
# quotes following an equal sign and "SRC", "HREF", or "virtual" in
# upper or lower case with optional white space around the equal sign)
# (with relative addressing) are present.
# Does not check files in command link that are links.

set debug = 0

set origdir = `pwd`

set tempfile = /tmp/gifsp.$$.$user

foreach htmlfile ($*)
  set htmlfile = ./$htmlfile
  if (! -l $htmlfile && -f $htmlfile) then
    set dir = $htmlfile:h
    set htmltail = $htmlfile:t
    if ($debug) then
      echo dir: $dir
      echo htmltail: $htmltail
    endif
    cd $dir
    if ($debug) ls -l $htmltail
    grepl '[a-zA-Z]*[ 	]*=[ 	]*"[^"]*"' $htmltail \
    | egrep '(SRC|src|HREF|href|VIRTUAL|virtual)' \
    | egrep -v '"(mailto|ftp):' \
    | sed 's+.*"\(.*\)"+\1+' \
    | sed  's+#.*++' \
    > $tempfile
    if ($debug) cat $tempfile
    foreach file (`cat $tempfile`)
    if (! -e $file) echo $file not present\; referenced by $htmlfile
    end
    cd $origdir
  endif
end

\rm -f $tempfile
