#!/usr/bin/csh -f

# the question directory is $1
# the persons in question are $2 and $3

echo "Creating link for $2 and $3..."

set questionhtml = "questions/$1.html"

set found = 0;

if (-f "$1/$2.txt") then
  if ($3 != "x") then
    if (-f "$1/$3.txt") then
      echo "<li><a href=\042#$2\042>" `cat candidates/$2.txt` "</a> and <a href=\042#$3\042>" `cat candidates/$3.txt` "</a>" >> $questionhtml
    else
      echo "<li><a href=\042#$2\042>" `cat candidates/$2.txt` "</a> and" `cat candidates/$3.txt` >> $questionhtml
    endif
  else
    echo "<li><a href=\042#$2\042>" `cat candidates/$2.txt` "</a>" >> $questionhtml
  endif
  set found = 1
else if (-f "$1/$3.txt") then
  echo "<li>" `cat candidates/$2.txt` "and <a href=\042#$3\042>" `cat candidates/$3.txt` "</a>" >> $questionhtml
  set found = 1
else if (-f "$1/$2_$3.txt") then
  echo "<li><a href=\042#$2_$3\042>" `cat candidates/$2.txt` " and " `cat candidates/$3.txt` "</a>" >> $questionhtml
  set found = 1
else if (-f "$1/$3_$2.txt") then
  echo "<li><a href=\042#$2_$3\042>" `cat candidates/$2.txt` " and " `cat candidates/$3.txt` "</a>" >> $questionhtml
  set found = 1
else
  echo "ERROR: No file for $2 or $3!"
endif

if ($found == 1) then
  if ($3 != "x") then
    echo "&nbsp;&nbsp;&nbsp;(<a href=\042../candidates/$2_$3.html\042>other question responses</a>)" >> $questionhtml
  else
    echo "&nbsp;&nbsp;&nbsp;(<a href=\042../candidates/$2.html\042>other question responses</a>)" >> $questionhtml
  endif
endif
