#!/bin/bash

case $# in
1)

 case $1 in
 LittleEndian)

  # Clean
  if test -f tv.bv16
  then
  \rm tv.bv16
  fi
  if test -f tv.bv16.raw
  then
  \rm tv.bv16.raw
  fi
  if test -f tv.bv16.bfe10.raw
  then
  \rm tv.bv16.bfe10.raw
  fi

  # Process codec
  BroadVoice16 enc tv.raw tv.bv16
  BroadVoice16 dec tv.bv16 tv.bv16.raw
  BroadVoice16 dec tv.bfe10.bv16 tv.bv16.bfe10.raw

  checksum=0;
  if test -n "`cmp tv.bv16 tv.bv16.ref`"
  then
  checksum=`expr $checksum + 1`
  fi
  if test -n "`cmp tv.bv16.raw tv.bv16.ref.raw`"
  then
  checksum=`expr $checksum + 1`
  fi
  if test -n "`cmp tv.bv16.bfe10.raw tv.bv16.bfe10.ref.raw`"
  then
  checksum=`expr $checksum + 1`
  fi

  if test ! -e tv.bv16
  then
  checksum=-1;
  fi
  if test ! -e tv.bv16.raw
  then
  checksum=-1;
  fi
  if test ! -e tv.bv16.bfe10.raw
  then
  checksum=-1;
  fi

  case $checksum in 
  -1)
   echo "  *************************************************"
   echo "  * WARNING: Missing files - something went wrong *"
   echo "  * Correct Endian format entered?                *"
   echo "  *************************************************"
   echo ""
  ;;
  0)
   echo "  **************************************************************************"
   echo "  * CONGRATULATIONS: Your compilation passed the simple functionality test *"
   echo "  **************************************************************************"
   echo ""
  \rm tv.bv16 tv.bv16.raw tv.bv16.bfe10.raw
  ;;
  *)
   echo "  ************************************************************************"
   echo "  * WARNING: Your compilation DID NOT pass the simple functionality test *"
   echo "  * Correct Endian format entered?                                       *"
   echo "  ************************************************************************"
   echo ""
  ;;
  esac

 ;;
 BigEndian)

  # Clean
  if test -f tvbe.bv16
  then
  \rm tvbe.bv16
  fi
  if test -f tvbe.bv16.raw
  then
  \rm tvbe.bv16.raw
  fi
  if test -f tvbe.bv16.bfe10.raw
  then
  \rm tvbe.bv16.bfe10.raw
  fi

  # Byte-swab little endian audio and G.192 bitstream reference files
  dd conv=swab if=tv.raw                of=tvbe.raw
  dd conv=swab if=tv.bv16.ref           of=tvbe.bv16.ref
  dd conv=swab if=tv.bv16.ref.raw       of=tvbe.bv16.ref.raw
  dd conv=swab if=tv.bfe10.bv16         of=tvbe.bfe10.bv16
  dd conv=swab if=tv.bv16.bfe10.ref.raw of=tvbe.bv16.bfe10.ref.raw

  # Process codec
  BroadVoice16 enc tvbe.raw tvbe.bv16
  BroadVoice16 dec tvbe.bv16 tvbe.bv16.raw
  BroadVoice16 dec tvbe.bfe10.bv16 tvbe.bv16.bfe10.raw

  checksum=0;
  if test -n "`cmp tvbe.bv16 tvbe.bv16.ref`"
  then
  checksum=`expr $checksum + 1`
  fi
  if test -n "`cmp tvbe.bv16.raw tvbe.bv16.ref.raw`"
  then
  checksum=`expr $checksum + 1`
  fi
  if test -n "`cmp tvbe.bv16.bfe10.raw tvbe.bv16.bfe10.ref.raw`"
  then
  checksum=`expr $checksum + 1`
  fi

  if test ! -e tvbe.bv16
  then
  checksum=-1;
  fi
  if test ! -e tvbe.bv16.raw
  then
  checksum=-1;
  fi
  if test ! -e tvbe.bv16.bfe10.raw
  then
  checksum=-1;
  fi

  case $checksum in 
  -1)
   echo "  *************************************************"
   echo "  * WARNING: Missing files - something went wrong *"
   echo "  * Correct Endian format entered?                *"
   echo "  *************************************************"
   echo ""
  ;;
  0)
   echo "  **************************************************************************"
   echo "  * CONGRATULATIONS: Your compilation passed the simple functionality test *"
   echo "  **************************************************************************"
   echo ""
   \rm tvbe.bv16 tvbe.bv16.raw tvbe.bv16.bfe10.raw tvbe.raw tvbe.bv16.ref tvbe.bv16.ref.raw tvbe.bfe10.bv16 tvbe.bv16.bfe10.ref.raw
  ;;
  *)
   echo "  ************************************************************************"
   echo "  * WARNING: Your compilation DID NOT pass the simple functionality test *"
   echo "  * Correct Endian format entered?                                       *"
   echo "  ************************************************************************"
   echo ""
  ;;
  esac

 ;;
 CleanAll)
  if test -f tv.bv16
  then
  \rm tv.bv16
  fi
  if test -f tv.bv16.raw
  then
  \rm tv.bv16.raw
  fi
  if test -f tv.bv16.bfe10.raw
  then
  \rm tv.bv16.bfe10.raw
  fi
  if test -f tvbe.bv16
  then
  \rm tvbe.bv16
  fi
  if test -f tvbe.bv16.raw
  then
  \rm tvbe.bv16.raw
  fi
  if test -f tvbe.bv16.bfe10.raw
  then
  \rm tvbe.bv16.bfe10.raw
  fi
  if test -f tvbe.raw
  then
  \rm tvbe.raw
  fi
  if test -f tvbe.bv16.ref
  then
  \rm tvbe.bv16.ref
  fi
  if test -f tvbe.bv16.ref.raw
  then
  \rm tvbe.bv16.ref.raw
  fi
  if test -f tvbe.bfe10.bv16
  then
  \rm tvbe.bfe10.bv16
  fi
  if test -f tvbe.bv16.bfe10.ref.raw
  then
  \rm tvbe.bv16.bfe10.ref.raw
  fi
  if test -f BroadVoice16
  then
  \rm BroadVoice16
  fi
  if test -f BroadVoice16.exe
  then
  \rm BroadVoice16.exe
  fi
 
 ;;
 *)
  echo "Invalid Endian format: $1"
 ;;
 esac

;;
*)
 echo "Usage: $0 LittleEndian/BigEndian/CleanAll"
;;
esac
