#!/bin/sh
# called by build_module
# ****  Calling Thorsten & Dieter's modem noise support fix, wherein input variable: noise
#   calls for alternative use of version 5.95 ltmdmobj.o
# For a very few modems, modem dialup noises were lost in the 5.95 -> 5.99 transition
# If the user called build_module_noisefix he intends to use the patch!
#
NONOISEFILE=badlist
echo 11c1:0441 > badlist 
# echo Next_Entry >> badlist 

NOISEFIX=`echo $CHOICE |grep build_module_noise`
if [ -z "$NOISEFIX" ]; then
        NOISEFIX=false
else
        NOISEFIX=true
fi
#
# if the user goes usual way and we find the device in $NONOISEFILE, we
# should give him a hint on how to proceed.
#
PROBLEMATIC=`grep "$MODEM_ID" $NONOISEFILE | cut -d: -f1` 
if [ ! -z "$PROBLEMATIC" ]; then
        if [ "$NOISEFIX" = "false" ]; then
                NOISEFIX=maybe
        fi
fi

if [ "$NOISEFIX" = "maybe" ] ; then
        cp badlist ../
        echo "======================================================================"
        echo ""
        echo "Watchout:"
        echo ""
        echo "Your modem device has been found in $NONOISEFILE."
        echo "It will *probably* not generate dialtones using the standard configuration"
        echo "If you want dialtones, you should say \"y\" here. If you do not know" 
        echo "or you are insecure, simply say \"n\" and test the results."
        echo "If your modem does not generate dialing noise, come back and recompile."
        echo ""
        echo "Do you want to use the noise-fix?"
        ANSWER=
        read ANSWER
        while [ "$ANSWER" != "y" -a "$ANSWER" != "Y" -a "$ANSWER" != "n" -a "$ANSWER" != "N" ]; do
                echo "You must say y or no here!"
                read ANSWER;
        done
        if [ "$ANSWER" = "n" -o "$ANSWER" = "N" ] ; then
                NOISEFIX=false
        fi
fi

# Checking if alternative 5.95 /home/marv/ltmodem-6.00b6/noise/ltmdmobj.o

if [ "$NOISEFIX" = "true" -o "$NOISEFIX" = "maybe" ] ; then
  ln -s ../build_module ../build_module_noise
  if [ "$NOISEFIX" = "true" ] ; then
        echo "======================================================================"
  fi
    echo "Looking for needed resources to compile alternative 5.95 DSP binary."
    echo "Checking for alternative 5.95 ltmdmobj.o supporting modem dial up noises."
  if [ -f ../noise.tar.gz ] && ! [ -f ../noise/ltmdmobj.o ] ; then
      (cd ..; tar zxvf noise.tar.gz > /dev/null 2>/dev/null)
  fi
  if ! [ -f ../noise/ltmdmobj.o ] ; then
    echo "The expected replacement noise/ltmdmobj.o file has not been found."
    echo "      Download noise.tar.gz from http://www.heby.de/ltmodem"
    echo Then within this ltmodem-"$VER" folder,
    echo "      tar zxvf noise.tar.gz"   
    echo "      The again run:  $0"
    echo "              or"
    echo "      "$0"_noise"      
    echo "======================================================================"
    echo $MSG
    echo
    exit 2
  else
    echo "      The alternative version 5.95 ltmdmobj.o has been found."
    echo "      Copying ../noise/ltmdmobj.o into the source/ folder."
    cp ../noise/ltmdmobj.o .
    echo NOISEFIX=$NOISEFIX >> $RECORD
  fi
  echo
  read -p "     Enter, to process further configuration options."
  echo
fi
# echo "======================================================================"
