#!/bin/sh
# @(#) $Header: option5,v 1.24 93/02/22 15:07:24 ss2 Exp $
#

set -a

FILE_HPGL2=$HPNP/testfiles/hpgl2
FILE_PS=$HPNP/testfiles/ps
FILE_TEXT=$HPNP/testfiles/text
HPNPF=$HPNP/hpnpf

if [ ! -f $HPNPF ]
then
  echo ""
  echo "The spooler software must not have been installed since"
  echo "$HPNPF does not exist.  This test can not be run"
  echo "without the spooler software."
  echo ""
  $ECHO "Press the return key to return to the main menu ... $NL"
  read RESP
  exit 1
fi


getname option5 $1
if [ "$?" != "0" ]
then
  exit 1
fi

PERIPH=`cat $TMP/NAME`
XTNAME=`cat $TMP/NAME`
rm $TMP/NAME

	#
	# Get port  number
	# eg is it a serial or parallel printer
	#

if [ ${ADMINDIR}x = "x" ]
then
  # ADMINDIR should be set already, - if not then set it to default value
  ADMINDIR=/opt/hpxt/enware2/lbin
fi

$ADMINDIR/whichport
if [ $? != 0 ]
then
  exit 100
fi

PERIPHPORT=`cat $TMP/PERIPHPORT`
rm  $TMP/PERIPHPORT

DASHN=""


#
# Check if the right extension are loaded for Altima
#
$REMSH $PERIPH get installed | egrep -i 'kernel.*version' > /dev/null
if [ $? -eq 0 ]
then
  # It's an Altima
  case $PERIPHPORT in
    9101)      EXTENSION=parallelExt; DRIVER="Parallel Port harware driver" ;;
    9100|9102) EXTENSION=serialExt  ; DRIVER="Serial Port harware driver"   ;;
  esac
  echo
  echo examining extensions and drivers loaded in $PERIPH
  $REMSH $PERIPH get installed | egrep -i $EXTENSION > /dev/null
  if [ $? -ne 0 ]
  then
    echo ""
    echo "The \"$DRIVER\" does not seem to be loaded."
    echo "Please activate this driver and the \"Remote Ports Extension\""
    echo "in the netstation configuration screen."
    echo "<Depress F12 for 2 sec><Click Terminal><Click Extensions>"
    $ECHO "Press the return key to continue ... $NL"
    read RESP
    echo ""
    exit 1
  fi
  EXTENSION=remportExt; DRIVER="Remote Ports Extension" 
  $REMSH $PERIPH get installed | egrep -i $EXTENSION > /dev/null
  if [ $? -ne 0 ]
  then
    echo ""
    echo "The \"$DRIVER\" does not seem to be loaded."
    echo "Please activate this driver in the netstation configuration screen."
    echo "<Depress F12 for 2 sec><Click Terminal><Click Extensions>"
    $ECHO "Press the return key to continue ... $NL"
    read RESP
    echo ""
    exit 1
  fi
  echo  ".. all necessary extensions and drivers seem to be loaded "
  sleep 2
  echo
fi



while [ 0 ]
do
    echo ""
    echo "The following types of test files can be sent to the printer:"
    echo ""
    echo "                    1) text file"
    echo "                    2) PostScript file"
    echo "                    3) HP-GL/2 file"
    echo ""
    echo "The printer must be configured for the language"
    echo "that is appropriate for your selection or have the"
    echo "auto-switching capability enabled."
    echo "   "
    $ECHO "Which type of file should be sent? (1/2/3 default=1) $NL"
    read RESP
    if [ "$RESP" = "" ]
    then
      RESP=1
    fi
    case "$RESP" in
      1) FILE=$FILE_TEXT 
	 DASHN="-n"
	 break ;;
      2) FILE=$FILE_PS 
	 break ;;
      3) FILE=$FILE_HPGL2 
	 break ;;
      q) exit 1 ;;
      \?) echo ""
	 echo "The test file sent depends upon the capabilities of the printer."
	 echo "Sending the wrong type of file to a printer may result in no"
	 echo "output or unexpected output.  Choose the right file type for your"
	 echo "printer."
	 echo ""
	 $QUITHELP
	 ;;
      *) echo ""
	 echo "Invalid response"
	 ;;
    esac
done

if [ ! -f "$FILE" ]
then
  echo ""
  echo "Unable to run test because $FILE does not exist."
  $ECHO "Press the return key to continue ... $NL"
  read RESP
  exit 1
fi

trap "" 1 2 3 15

echo ""
echo "Sending a test file to $PERIPH ..."
echo ""
echo $HPNPF $DASHN -v -R -x $PERIPH -p $PERIPHPORT $FILE
$HPNPF $DASHN -v -R -x $PERIPH -p $PERIPHPORT $FILE

if [ $? = 0 ]
then
  echo ""
  echo "The file was successfully sent to $PERIPH."
else
  echo ""
  echo "An error occurred sending the file to $PERIPH.  If the"
  echo "printer has already passed the test in options 1"
  echo "please verify that the printer is online."
fi

echo "==============================================================="
echo ""
echo "The netstation printer test is complete."
$ECHO "Press the return key to continue ... $NL"
read RESP
