#!/bin/bash
#
# This shell-script allows you to enter several filenames to be fed to
# the 'auplay' program for playing on the PC's internal speaker.
#
# You can leave the ".au" off the end, and it will stick it on for you.
#
# (I've built in the ability to play "*.short" files, which are expected
#  to be "*.au"-files which have been shorten'd.  See README for details.)
#
#	Rick Miller <rick@ee.uwm.edu>

NAMES=' '

# Location of "auplay":
AUPLAY=/usr/local/bin/auplay

# "SHORTEN" is the fully-qualified filename of "shorten", if used.
SHORTEN=/usr/local/bin/shorten

for n in $* ; do
  if [ -e $n ]; then
    NAMES="$NAMES $n"
  else
    if [ -e ${n}.au ]; then
      NAMES="$NAMES ${n}.au"
    else
      if [ -e ${n}.short ]; then
	NAMES="$NAMES ${n}.short"
      else
	echo "Cannot find $n" >&2
      fi
    fi
  fi
done

if [ ${#NAMES} = 0 ]; then
  echo 'No files to play.' >&2
  exit 1
else
  for n in $NAMES ; do
    if [ $n = ${n:%.short} ]; then
      cat $n | $AUPLAY
    else
      $SHORTEN -x $n | $AUPLAY
    fi
  done
fi

exit 0
