#!/bin/ksh
echo `basename $0` : no action
echo 0 > status.${JON}
exit 0
echo "IDCAMS : start LISTCAT"
if [ $IDEBUG = "yes" ] 
then
	echo "$0  starts with :"
	for i in $1
	do
		param=`echo $i | cut -f1 -d')' | cut -f2 -d'('`
		key=`echo $i | cut -f1 -d'('`
		echo "                     key=$key     param=$param"
	done
fi

entry=null
outfi=null
catalg=null
catalg1=null

split=1
onlycat=0
count=0
aa=0
multi=null

cat=null
name=null
liscat=null
type=null
path=null
pathname=null
namefile=null
gdgnum=null
cluste=null
novsam=null
scambio=null
ddspath=null

flty=null
dacre=null
daexp=null
resiz=0
nucol=null

vsdata=0

for i in $1
do
		param=`echo $i | cut -f1 -d')' | cut -f2 -d'('`
		key=`echo $i | cut -f1 -d'('`


		case $key in
	ENTRIES|entries|ENT|ent|LEVEL|level|LVL|lvl) 	   
							split=2
							entry=$key
							multi=$param;;
	OUTFILE|outfile|OFILE|ofile) 			  
							split=1
							outfi=$param;;
	CATALOG|catalog|CAT|cat) 			   
							split=1
							catalg=$param;;
	CLUSTER|cluster|CL|cl|DATA|data|INDEX|IX|index|ix)
							split=1
							cluste=$key;;
	NONVSAM|nonvsam|NVSAM|nvsam)
							split=1
							novsam=$key;;

	ALIAS|alias|ALTERNATEINDEX|AIX|alternateindex|aix|\
	generationdatagroup|GDG|gdg|GENERATIONDATAGROUP|\
	PAGESPACE|pagespace|PGSPC|pgspc|PATH|\
	path|SPACE|space|SPC|spc|USERCATALOG|usercatalog|UCAT|ucat)
			echo "IDCAMS: LISTCAT $key command not supported"
			exit 1;;

	CREATION|creation|CREAT|creat|ALL|all|\
	NAME|name|HISTORY|history|HIST|hist|VOLUME|volume|VOL|vol|\
	ALLOCATION|allocation|ALLOC|alloc|NOTUSABLE|notusable|NUS|nus)
			split=1
			if [ $IDEBUG = "yes" ] 
			then
				echo "IDCAMS: LISTCAT $key command ignored"
			fi;;
		*)
			if [ $split -eq 2 ]
			then
				multi="$multi $param"
			else
				echo "$key: key unknown"
			fi
			;;
		esac

done


if [ $IDEBUG != "yes" ] 
then

if [ $catalg = null ] 
then
	echo $JOB_CAT >/tmp/JOB.$$
	grep ":" /tmp/JOB.$$ 2>$DEVNULL
	if [ $? -ne 0 ]
	then
		catalg1=$JOB_CAT
	else
		catalg1=`echo $JOB_CAT |cut -f1 -d':'`
	fi
	rm /tmp/JOB.$$
	catalg=$JOB_CAT
else
	catalg1=$catalg
fi

if [ $outfi = null ]
then
	outfi=`eval echo $DD_SYSPRINT`
else
	pre=$`echo DSN_$outfi`
	scambio=`eval echo $pre`
	liscat=`grep $scambio $FILEMAP|cut -f2 -d';'`
	outfi=`ftval $scambio $liscat 4`
	temp=$?
	if [ $temp -ne 0 ]
	then
		exit 1
	fi
fi

if [ $entry != null ]
then
	for i in $multi
	do
		echo $i >> /tmp/list.$$
	done
else
if [ $cluste != null ]
then
		grep -v ";FS;" $FILEMAP|grep $catalg1|cut -f1 -d';' > /tmp/list.$$	
		temp=$?
		if [ $temp -ne 0 ]
		then
			rm /tmp/list.$$  2>$DEVNULL
			exit 1
		fi
else
if [ $novsam != null ]
then
		grep ";FS;" $FILEMAP|grep $catalg1|cut -f1 -d';' > /tmp/list.$$	
		temp=$?
		cat /tmp/list.$$
		if [ $temp -ne 0 ]
		then
			rm /tmp/list.$$  2>$DEVNULL
			exit 1
		fi
else
		onlycat=1
		grep $catalg1 $FILEMAP|cut -f1 -d';' > /tmp/list.$$	
		temp=$?
		if [ $temp -ne 0 ]
		then
			rm /tmp/list.$$  2>$DEVNULL
			exit 1
		fi
fi
fi
fi


echo "================================================================================" > $outfi
echo "                                            TIME: `date`" >> $outfi
echo " " >> $outfi
echo "                     -=- IDCAMS:    LISTCAT UTILITY -=-" >> $outfi
echo " " >> $outfi
echo "================================================================================" >> $outfi
echo " " >> $outfi
	if [ $onlycat -eq 1 ]
	then
		echo "\t\t LISTING FROM CATALOG: $catalg" >> $outfi
	fi
echo " " >> $outfi
echo " " >> $outfi


while read i
do
	name=`ftval $i $catalg 1`
	temp=$?
	if [ $temp -ne 0 ]
	then
		rm /tmp/list.$$  2>$DEVNULL
		exit 1
	fi
	cat=`ftval $i $catalg 2`
	temp=$?
	if [ $temp -ne 0 ]
	then
		rm /tmp/list.$$  2>$DEVNULL
		exit 1
	fi
	type=`ftval $i $catalg 3`
	temp=$?
	if [ $temp -ne 0 ]
	then
		rm /tmp/list.$$  2>$DEVNULL
		exit 1
	fi
	if [ $type = "VS" ]
	then
		type=VSAM
	fi
	pathname=`ftval $i $catalg 4`
	temp=$?
	if [ $temp -ne 0 ]
	then
		rm /tmp/list.$$  2>$DEVNULL
		exit 1
	fi
	if [ $type != "VSAM" ]
	then
		path=`dirname $pathname`
		namefile=`basename $pathname`
	fi
	gdgnum=`ftval $i $catalg 6`
	temp=$?
	if [ $temp -ne 0 ]
	then
		rm /tmp/list.$$  2>$DEVNULL
		exit 1
	fi
	if [ $type = "DB" ]
	then
		ddspath=`ftval $i $catalg 5`
		temp=$?
		if [ $temp -ne 0 ]
		then
			rm /tmp/list.$$  2>$DEVNULL
			exit 1
		fi
		rdmlff -f $pathname -of listcat.$$ 1>$DEVNULL
 		temp=$?
 		if [ $temp -ne 0 ]
 		then
 			rm /tmp/list.$$  2>$DEVNULL
 			rm listcat.$$  2>$DEVNULL
 			exit 1
 		fi
		grep : listcat.$$|cut -f2 -d':'|cut -f2 -d' ' >/tmp/listcat.$$
		temp=$?
		if [ $temp -ne 0 ]
		then
			rm /tmp/list.$$  2>$DEVNULL
			rm listcat.$$  2>$DEVNULL
			rm /tmp/listcat.$$  2>$DEVNULL
			exit 1
		fi
		rm listcat.$$  2>$DEVNULL
		while read j
		do
			count=`expr $count + 1`
			case $count in
				2)	flty=$j;;
				5)	dacre=$j;;
				6)	daexp=$j;;
				12)	resiz=$j;;
				13)	nucol=$j;;
				*)	;;
			esac	
		done < /tmp/listcat.$$

		rm /tmp/listcat.$$  2>$DEVNULL
	fi


if [ $type = "VSAM" ]
then
	echo "\t\t    -+- DSN: $name -+-" >> $outfi
	echo " " >> $outfi
	if [ $onlycat -eq 1 ]
	then
		if test $gdgnum
		then
			echo "TYPE=$type\tGDG=$gdgnum" >> $outfi
		else
			echo "TYPE=$type" >> $outfi
		fi
	else
		if test $gdgnum
		then
			echo "CATALG=$cat\t\tTYPE=$type\tGDG=$gdgnum" >> $outfi
		else
			echo "CATALG=$cat\t\tTYPE=$type" >> $outfi
		fi
	fi
	if [ $KIXDATA ]
	then
		echo "DIR=$KIXDATA" >> $outfi
	else
		vsdata=1
		echo "DIR=KIXDATA no present" >> $outfi
	fi
else
	if [ $type = "DB" ]
	then
		echo "\t\t    -+- DSN: $name -+-" >> $outfi
		echo " " >> $outfi
		if [ $onlycat -eq 1 ]
		then
			if test $gdgnum
			then
				echo "TYPE=$type\t\tGDG=$gdgnum" >> $outfi
			else
				echo "TYPE=$type" >> $outfi
			fi
		else
			if test $gdgnum
			then
			echo "CATALG=$cat\t\tTYPE=$type\t\tGDG=$gdgnum" >>$outfi
			else
			echo "CATALG=$cat\t\tTYPE=$type" >>$outfi
			fi
		fi
		echo "DIR=$path" >> $outfi
		echo "DDSPATH=$ddspath" >> $outfi
		echo "FILE TYPE=$flty file" >> $outfi
		echo "DATE OF CREATION=$dacre\t\tDATE OF EXPIRY=$daexp" >>$outfi
		echo "RECORD SIZE=$resiz bytes" >> $outfi
		echo "NUMBER OF COLUMNS=$nucol" >> $outfi
	else
		echo "\t\t    -+- DSN: $name -+-" >> $outfi
		echo " " >> $outfi
		if [ $onlycat -eq 1 ]
		then
			if test $gdgnum
			then
				echo "TYPE=$type\t\tGDG=$gdgnum" >> $outfi
			else
				echo "TYPE=$type" >> $outfi
			fi
		else
			if test $gdgnum
			then
			echo "CATALG=$cat\t\tTYPE=$type\t\tGDG=$gdgnum" >>$outfi
			else
			echo "CATALG=$cat\t\tTYPE=$type" >>$outfi
			fi
		fi
		echo "DIR=$path" >> $outfi
	fi
fi

echo " " >> $outfi

if [ $vsdata -eq 0 ]
then
echo "  permis.   l. owner    group      size    last mod.       name " >> $outfi
echo "----------  -- ------   ------   ------- ------------ -------------- " >> $outfi

if [ $type = "VSAM" ]
then
	cd $KIXDATA
	ls -la $pathname.dta >> $outfi 2>$DEVNULL
	temp=$?
	if [ $temp -ne 0 ]
	then
		aa=$temp
        	echo "\tThe DSN:$name isn't present under $KIXDATA directory" >>$outfi
	fi
else
	pwdir=`pwd`
	cd $path
	ls -la $namefile >> $pwdir/$outfi 2>$DEVNULL
	temp=$?
	if [ $temp -ne 0 ]
	then
		aa=$temp
        	echo "\tThe DSN:$name isn't present under $path directory" >>$pwdir/$outfi
	fi
fi
fi
	cd $pwdir
	if [ $vsdata -eq 1 ]
	then
		vsdata=0
	fi

echo " " >> $outfi
echo " " >> $outfi
echo " " >> $outfi


done < /tmp/list.$$


echo "================================================================================" >> $outfi

rm /tmp/list.$$  2>$DEVNULL

fi
# fi of if debug

exit $aa
