:
# Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
# 
# Permission to use, copy, modify, and distribute this material 
# for any purpose and without fee is hereby granted, provided 
# that the above copyright notice and this permission notice 
# appear in all copies, and that the name of Bellcore not be 
# used in advertising or publicity pertaining to this 
# material without the specific, prior written permission 
# of an authorized representative of Bellcore.  BELLCORE 
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
# OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.

# Conversion from C shell to Bourne shell
# by Bob Glickstein, Z-Code Software Corp.
# Conversion Copyright (c) 1992 Z-Code Software Corp. (Z-Code)
# 
# Permission to use, copy, modify, and distribute this material for
# any purpose and without fee is hereby granted, provided that the
# above copyright notice and this permission notice appear in all
# copies, and that the name of Z-Code not be used in advertising or
# publicity pertaining to this material without the specific, prior
# written permission of an authorized representative of Z-Code.
# Z-CODE MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY OF
# THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", WITHOUT ANY
# EXPRESS OR IMPLIED WARRANTIES.

thishost=`hostname`

AUDIOBINDIR=/u/andrew/phone-sau/bin
AUDIOPHONEHOST=greenbush
AUDIOPHONEHOSTLONG=greenbush.bellcore.com
ORG=Bellcore

if test "$1" = "-p"
then
	AUDIOPHONE=$2
	shift
	shift
fi

if test "$1" = "-s"
then
	AUDIOSPEAKERFORCE=1
fi

playphone=0
if test ! -z "${AUDIOPHONE:-}" -o ! -z "${AUDIOPHONEFORCE:-}"
then
	playphone=1
fi

if test $playphone -eq 0
then
	if test ! -d "$AUDIOBINDIR"
	then
		AUDIOSPEAKERFORCE=1
	fi

	if test -z "${AUDIOSPEAKERFORCE:-}" -a -z "${AUDIOPHONEFORCE:-}"
	then
		if test ! -z "${MM_NOTTTY:-}"
		then
			if test $MM_NOTTTY -eq 1
			then
				MM_NOTTTY=0; export MM_NOTTTY
				xterm -e showaudio $*
				exit 0
			fi
		fi
		echo This program can display audio on the speakers of some workstations, 
		echo "or (at some sites) it can call you on the telephone.  Please choose one:"
		echo ""
		echo "1 -- Use the computer's speaker"
		echo "2 -- Call me on the telephone"
		echo ""
		echo-n "Which do you prefer (1 or 2)? [1] "
		read ans
		if test "$ans" -eq 2
		then
			echo "OK, we'll use the telephone..."
			AUDIOPHONEFORCE=1
			echo "In the future, you can avoid this question by setting the environment variable"
			echo "AUDIOPHONEFORCE to 1"
			playphone=1
		else
			echo "OK, Attempting to play the audio using your computer's speaker.."
			AUDIOSPEAKERFORCE=1
			echo "In the future, you can avoid this question by setting the environment variable"
			echo "AUDIOSPEAKERFORCE to 1"
		fi
	fi
fi

if test $playphone -eq 0
then
	audiohost=$thishost
	if test ! -z "${DISPLAY:-}"
	then
		audiohost=`echo $DISPLAY | sed -e 's/:.*//'`
		if test "$audiohost" = unix
		then
			audiohost=$thishost
		fi
		if test -z "$audiohost"
		then
			audiohost=$thishost
		fi
	fi
	if test ! -z "${AUDIOHOST:-}"
	then
		audiohost=$AUDIOHOST
	fi

	if test ! "$audiohost" = "$thishost"
	then
		echo Sending audio to $audiohost...
		thisprog=`(cd; which showaudio)`
		cat $* | rsh $audiohost $thisprog -s
		exit 0
	fi

	if test -d /usr/sony
	then
		dev=/dev/sb0
	else
		dev=/dev/audio
	fi

	if test -x /usr/sbin/sfplay
	then
		file $* | grep AIFF > /dev/null 2>&1
		if test $? -eq 0
		then
			echo Playing AIFF audio on $thishost using /usr/sbin/sfplay, one moment...
			/usr/sbin/sfplay $*
		else
			echo Playing NeXT/Sun-format audio on $thishost using /usr/sbin/sfplay...
			/usr/sbin/sfplay -i format next end $*
		fi
		exit 0
	fi

	if test -w $dev
	then
		echo Playing audio on $thishost using $dev, one moment please...
		cat $* > $dev
		exit 0
	fi
fi

if test -d "$AUDIOBINDIR"
then
	thisprog=`which showaudio`
	if test -z "${AUDIOPHONE:-}"
	then
		if test ! -z "${MM_NOTTTY:-}"
		then
			if test $MM_NOTTTY -eq 1
			then
				MM_NOTTTY=0; export MM_NOTTTY
				xterm -e $thisprog $*
				exit 0
			fi
		fi
		echo This message contains audio, which can be sent to your telephone.
		echo Please enter the telephone number at which you would like to hear this
		echo-n "audio message as you would dial it from inside ${ORG}: "
		read AUDIOPHONE
	fi

	if test "$thishost" == "$AUDIOPHONEHOST \
		-o "$thishost" == "$AUDIOPHONEHOSTLONG"
	then
		echo Calling Phone number $AUDIOPHONE
		echo "If the process seems stuck after you hang up,"
		echo "then please interrupt with ^C or whatever your interrupt key is"
		cat $AUDIOBINDIR/../GREET.au $* - | $AUDIOBINDIR/play -\# $AUDIOPHONE -
		echo All done
		exit 0
	else
		echo Trying to rsh to $AUDIOPHONEHOST to send audio via telephone
		cat $* | rsh $AUDIOPHONEHOST $thisprog -p $AUDIOPHONE
		exit 0
	fi
fi
echo ""
echo This message contains an audio mesage, which can not currently be
echo played on this type of workstation.   If you log into an appropriate 
echo "machine (currently a SPARCstation or Sony News workstation)"
echo and read this message there, you should be able to hear the audio
echo message.  
