#!/bin/sh
#=========================================================================
# name:         tapefile
# description:  return the current tape file number of the specified tape
# author:       G.R.Keech
# date:         1998-04-21
# $Id: tapefile,v 1.1 1999/03/04 02:56:02 rkeech Exp $
#=========================================================================

# ----------------------------------------------------------------------
version () {
  ver='$Revision: 1.1 $'
  echo $ver|sed 's/\$//g; s/Revision://g'|awk '{print $1}'
}
#---------------------------------------------------------------------------

if [ ${1}x = "-fx" -a ${2}x != x ]
then
  # A tape name has been specified on the command line
  TAPE=${2};  export TAPE
  shift 2
fi

if [ $# != 0 ]
then
  if [ $1 = "--version" ]
  then
    echo `basename $0` Version `version`.
    echo Written by G.Richard Keech, 1998.
  else
    echo Usage:  `basename $0` [-f tape]
  fi
  exit
fi

if [ ${TAPE}x = x ]
then
  # No tape has been specified; set the default.
  TAPE=/dev/rmt/0; export TAPE
fi

line=`/bin/mt -f $TAPE status 2>/dev/null | grep -i file 2>/dev/null`
if [ $? = 0 ]
then
  echo $line|sed 's/,//g; s/[N,n]umber//g; s/no//g; s/=//g'|awk '{print $2}'
else
  exit 1
fi
