#!/bin/csh

#Given a house short name (first arg), create the full assignment message.
#Leave the message in the designated file (second arg)

# houses:	List of house short names and long names, one per line
#	sample: "500     500 Memorial Drive"
# goodemail:	Message sent out to assigned students
# bademail:	Message sent out to students with no assignment
# lockers:	List of froshinfo file names for additional information
#	sample: "500     500"
# froshinfopath:	Path to froshinfo locker


set houses = /afs/athena.mit.edu/astaff/project/hass-d/frhousing/datafiles/houses
set lockers = /afs/athena.mit.edu/astaff/project/hass-d/frhousing/datafiles/lockers.short
set mailfile = $2
set goodemail = /afs/athena.mit.edu/astaff/project/hass-d/frhousing/datafiles/mail1.txt
set bademail = /afs/athena.mit.edu/astaff/project/hass-d/frhousing/datafiles/mail2.txt
set fratemail = /afs/athena.mit.edu/astaff/project/hass-d/frhousing/datafiles/fratmail.txt
set froshinfopath = /afs/athena.mit.edu/activity/f/froshinfo

set shortname = $1
set assignment = `grep $shortname $houses | cut -c4-`

if ( $#assignment ) then
#	echo $1 is assigned to $assignment
	set errorflag = 0
else
#	echo $1 has no house
	if ( $shortname != "NUN") then
		set errorflag = 1
		cat $fratemail > $mailfile
	else
		set errorflag = 2
		cat $bademail > $mailfile
	endif
endif


if ( $errorflag == 0 ) then
	echo "Congratulations.  You have received a permanent assignment in" > $mailfile
	echo "the House lottery to" $assignment"." >> $mailfile
	echo "" >> $mailfile
	cat $goodemail >> $mailfile
	set lockerinfo = `grep $shortname $lockers | cut -f2`
	cat $froshinfopath/$lockerinfo >> $mailfile
endif
