#!/bin/csh -fv

set MYNAME = $0
#set PROGRAM = ( /etc/vf )
set PROGRAM = ( ./vf )
set DATE = ( `date` )
set ERRS = ( ./files.errs )
set LIST = ( ./files.perms )
#set ERRS = ( /etc/files.errs )
#set LIST = ( /etc/files.perms )
set HOST = ( `hostname` )
#set RCPTS = ( root@${HOST}, tom@uwvax )
set RCPTS = ( tom@uwvax )

if ! { ${PROGRAM} -c ${LIST} >& ${ERRS} } then
	set EXIT = $status # before it changes
	switch ( $EXIT )
		case 64:	
					set MESG = "command line usage error"; 
					breaksw;
		case 65:	
					set MESG = "data format error"; 
					breaksw;
		case 66:	
					set MESG = "cannot open input"; 
					breaksw;
		case 67:	
					set MESG = "addressee unknown"; 
					breaksw;
		case 68:	
					set MESG = "host name unknown"; 
					breaksw;
		case 69:	
					set MESG = "service unavailable"; 
					breaksw;
		case 70:	
					set MESG = "internal software error"; 
					breaksw;
		case 71:	
					set MESG = "system error"; 
					breaksw;
		case 72:	
					set MESG = "critical system file missing"; 
					breaksw;
		case 73:	
					set MESG = "can't create (user) output file"; 
					breaksw;
		case 74:	
					set MESG = "input/output error"; 
					breaksw;
		case 75:	
					set MESG = "temporary failure"; 
					breaksw;
		case 76:	
					set MESG = "remote error in protocol"; 
					breaksw;
		case 77:	
					set MESG = "permission denied "; 
					breaksw;
		case 129:	
					set MESG = "SIGNALED: Hangup",; 
					breaksw;
		case 130:	
					set MESG = "SIGNALED: Interrupt",	; 
					breaksw;
		case 131:	
					set MESG = "SIGNALED: Quit",; 
					breaksw;
		case 132:	
					set MESG = "SIGNALED: Illegal instruction",; 
					breaksw;
		case 133:	
					set MESG = "SIGNALED: Trace/BPT trap",; 
					breaksw;
		case 134:	
					set MESG = "SIGNALED: IOT trap",; 
					breaksw;
		case 135:	
					set MESG = "SIGNALED: EMT trap",; 
					breaksw;
		case 136:	
					set MESG = "SIGNALED: Floating exception",; 
					breaksw;
		case 137:	
					set MESG = "SIGNALED: Kill",; 
					breaksw;
		case 138:	
					set MESG = "SIGNALED: Bus error",; 
					breaksw;
		case 139:	
					set MESG = "SIGNALED: Segmentation fault",; 
					breaksw;
		case 140:	
					set MESG = "SIGNALED: Bad system call",; 
					breaksw;
		case 141:	
					set MESG = "SIGNALED: Broken pipe",; 
					breaksw;
		case 142:	
					set MESG = "SIGNALED: Alarm clock",; 
					breaksw;
		case 143:	
					set MESG = "SIGNALED: Terminated",; 
					breaksw;
		case 144:	
					set MESG = "SIGNALED: Urgent I/O condition",; 
					breaksw;
		case 145:	
					set MESG = "SIGNALED: Stopped (signal)",; 
					breaksw;
		case 146:	
					set MESG = "SIGNALED: Stopped",; 
					breaksw;
		case 147:	
					set MESG = "SIGNALED: Continued",; 
					breaksw;
		case 148:	
					set MESG = "SIGNALED: Child exited",; 
					breaksw;
		case 149:	
					set MESG = "SIGNALED: Stopped (tty input)",; 
					breaksw;
		case 150:	
					set MESG = "SIGNALED: Stopped (tty output)",; 
					breaksw;
		case 151:	
					set MESG = "SIGNALED: I/O possible",; 
					breaksw;
		case 152:	
					set MESG = "SIGNALED: Cputime limit exceeded",; 
					breaksw;
		case 153:	
					set MESG = "SIGNALED: Filesize limit exceeded",; 
					breaksw;
		case 154:	
					set MESG = "SIGNALED: Virtual timer expired",; 
					breaksw;
		case 155:	
					set MESG = "SIGNALED: Profiling timer expired",; 
					breaksw;
		case 156:	
					set MESG = "SIGNALED: Window size changed",; 
					breaksw;
		case 157:	
					set MESG = "SIGNALED: Unknown Signal 29",; 
					breaksw;
		case 158:	
					set MESG = "SIGNALED: User defined signal 1",; 
					breaksw;
		case 159:	
					set MESG = "SIGNALED: User defined signal 2",; 
					breaksw;
		case 160:	
					set MESG = "SIGNALED: Unknown Signal 32"; 
					breaksw;
		default:	
					set MESG = "Undefined EXIT Status";
	endsw;

	if ( ${EXIT} == 75 ) then
		set ACTION = "have been auto-corrected and need no attention."
	else
		set ACTION = "are SERIOUS and require immediate attention."
	endif

	(echo "The following error messages were generated when";\
	 echo "the program ${PROGRAM} exited abnormally with status ${EXIT}.";\
	 echo "It was run on ${HOST} on ${DATE}.";\
	 echo " ";\
	 echo 'This exit status indicates "' "${MESG}" '";';\
	 echo "Consult the manual for details.";\
	 echo " ";\
	 sed 's/^/	/'  ${ERRS}; \
	 echo " ";\
	 echo "These errors ${ACTION}";\
	 echo " ";\
	 echo "			--the ${MYNAME} script.";\
	 echo " "; ) \
		 | tee error.report
#		 | /usr/ucb/mail -s "${MYNAME} error report" ${RCPTS}
else
	echo ok.
endif
