:
# cobfile - give information on Micro Focus format files.
#
# @(#)cobfile	7.1

# Defaults
TMPDIR=${TMPDIR:-/tmp}
COBDIR=${COBDIR:-/opt/lib/cobol}

TMP=$TMPDIR/cobcf$$
TMP2=$TMPDIR/cobcF$$

# Check the usage
if test $# -lt 1
then
	echo "Usage: `basename $0` file [files]"
	exit 1
fi

# Search $COBDIR for the MF magic file.
OLDIFS=$IFS
IFS=:
for dir in $COBDIR
do
	if test -f $dir/etc/cobmagic
	then
		MAGIC=$dir/etc/cobmagic
		break
	fi
done
IFS=$OLDIFS

case ".$MAGIC" in
	.)	echo "$0: No magic file"
		exit 2
		;;
esac

# Create a magic file consisting of the MF and OS versions, if possible.
if test ! -f $TMP -a ! -f $TMP2
then
	for magic in /usr/share/misc/magic /etc/magic /usr/share/magic
	do
		if test -f $magic
		then
			DEFMAGIC=$magic
			break
		fi
	done

	cat $MAGIC $DEFMAGIC > $TMP
	MAGIC=$TMP
	file -m $MAGIC $* 2> $TMP2 || cat $TMP2
	rm -f $TMP $TMP2
else
	file -m $MAGIC $*
fi
