#! /bin/sh
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#

#* $Date:   27 Feb 2002 11:00:14  $
#* $Modtime:   27 Feb 2002 11:05:24  $

# ***********************************************
# $Workfile:   kixcnvtcat80.sh  $ $Revision:   1.0  $
# ***********************************************

#*
#* $Log:   /net/dilithium/unikix/builds/dd134127/SunMTP8.0.0c/unikixsrc/vsam/utilities/PVCS/kixcnvtcat80.shv  $
#
#   Rev 1.0   27 Feb 2002 11:00:14   dd134127
#Initial revision.
#  

if test -z "$KIXSYS"
then
   echo "Please set KIXSYS environment variable for the catalog you are converting"
   exit 1
   fi

if [ $# -eq 0 ] 
then
   echo "No batch read-locking option was specified for converting $KIXSYS/CATALOG;"
   echo "Do you want to continue with the batch read-locking option set to 'Y'?"
   read answer
   case $answer in
   y*|Y*) RD4UPDT=Y
        CATALOG="CATALOG";;
   *)  echo "Syntax: kixcnvtcat -r {Y|N} [-c catalog]"
       echo "                   -r set read-for-update flag"
       echo "                   -c catalog name; CATALOG assumed if not specified"
       echo " Please retry with the required option"
       exit 1;;
   esac
elif [ $# -ne 2 -a $# -ne 4 ] 
then
   echo "Syntax: kixcnvtcat -r {Y|N} [-c catalog]"
   echo "                   -r set read-for-update flag"
   echo "                   -c catalog name; CATALOG assumed if not specified"
   echo " Please retry with the required option"
   exit 1
   fi

if [ $# -eq 2 ] 
then 
case "$1" in
-r) RD4UPDT=$2
    CATALOG="CATALOG";;
*) echo "Syntax: kixcnvtcat -r {Y|N} [-c catalog]"
   echo "                   -r set read-for-update flag"
   echo "                   -c catalog name; CATALOG assumed if not specified"
   echo " Please retry with the required option"
   exit 1;;
esac
fi

if [ $# -eq 4 ] 
then 
case "$3" in
-r) 
    RD4UPDT=$4;;
-c)
    CATALOG=$4;;
*) echo "Syntax: kixcnvtcat -r {Y|N} [-c catalog]"
   echo "                   -r set read-for-update flag"
   echo "                   -c catalog name; CATALOG assumed if not specified"
   echo " Please retry with the required option"
   exit 1;;
esac
case "$1" in
-r) 
    RD4UPDT=$2;;
-c) 
    CATALOG=$2;;
*) echo "Syntax: kixcnvtcat -r {Y|N} [-c catalog]"
   echo "                   -r set read-for-update flag"
   echo "                   -c catalog name; CATALOG assumed if not specified"
   echo " Please retry with the required option"
   exit 1;;
esac
if [ -z "$RD4UPDT" -o -z "$CATALOG" ]
then
   echo "Syntax: kixcnvtcat -r {Y|N} [-c catalog]"
   echo "                   -r set read-for-update flag"
   echo "                   -c catalog name; CATALOG assumed if not specified"
   echo " Please retry with the required option"
   exit 1
   fi
fi

if test -z "$TMPDIR"
then
   echo "Please set TMPDIR environment variable to a directory for handling temporary files"
   exit 1
   fi

cd $KIXSYS

if test ! -s $KIXSYS/$CATALOG.dta
then
    echo "File $CATALOG.dta does not exist in the KIXSYS directory"
    exit 1
fi

kixexpcat -c $CATALOG -l $TMPDIR/$CATALOG.lst -x $RD4UPDT
case $? in
0) break;;
*)
   errornum=$?
   echo "kixexpcat -c $CATALOG -l $TMPDIR/$CATALOG.lst -x $RD4UPDT"
   echo "VSAM catalog not converted; kixexpcat utility error: " $errornum
   exit 1;;
esac
kiximpcat -c $CATALOG -l $TMPDIR/$CATALOG.lst
case $? in
0) break;;
*)
   errornum=$?
   echo "kiximpcat -c $CATALOG -l $TMPDIR/$CATALOG.lst"
   echo "VSAM catalog not converted; kiximpcat utility error: " $errornum
   exit 1;;
esac
rm $TMPDIR/$CATALOG.lst
echo "Sun MTP VSAM catalog" $CATALOG "converted, under directory" `pwd`
