:
# SCCSID(@(#)mkvfloppy	1.17 LCC) Modified 22:56:50 2/21/93
#
#  Create and format a virtual floppy disk.
#
#****************************************************************************/
#
#	Copyright (c) 1987-1993 Locus Computing Corporation.
#	All rights reserved.
#	This is an unpublished work containing CONFIDENTIAL INFORMATION
#	that is the property of Locus Computing Corporation.
#	Any unauthorized use, duplication or disclosure is prohibited.
#
#****************************************************************************/
unset ONUNIX
PATH=/bin:/usr/bin:/usr/dbin
LIBM=${LIBM:-/usr/lib/merge}

FILE=$1
TMPFILE=/tmp/$$

if [ "x$2" = "xvisual" ]
then
	VISUAL=1
	shift
fi
OPT1="$2"
ERROR=noerror
if [ "x$OPT1" = "x-s" ]
then
	BOOTABLE=1
fi

if [ -z "$FILE" ]
then
	ERROR=error
else
	# Make sure file is writeable.
	> $FILE 
	if [ ! -w $FILE ]
	then
		ERROR=error
	fi
fi
	

if [ "$ERROR" = "error" ]
then
	# The script "set_nls.sh" sets MFILE
	. $LIBM/set_nls.sh
	# DM is the domain for messages for this script.
	DM="LCC.MERGE.UNIX.MKVFLP"
	lmfmsg $MFILE $DM.USAGE $0 >/dev/null 2>&1
	if [ $? -eq 0 ]
	then
		lmfmsg $MFILE $DM.USAGE $0
	else
		echo "USAGE: $0 filename format-option"
	fi
	exit 1
fi

# Note: As of 10-June-91 a bug in PCI code causes a single carriage
# return will not be passed to DOS when redirected to stdin.
# It needs another character in the line.
# So, as a workaround, put a space before the carriage returns in
# the lines that are only carriage returns.
/bin/cat > $TMPFILE <<-EOF
 
 
 
 
n
 
EOF
if [ -f /usr/dbin/version.dos ]
then
	. /usr/dbin/version.dos
fi

# Give this script a time limit.
(sleep 30; kill $$ 2>> /dev/null) &

DRV=a:
if [ "x$DOSVER" = "xDR-DOS 6.0" ]
then
	# This is a workaround for a problem with virtual
	# floppies with DR-DOS.  Formatting seems to work
	# with drive B, but not A.
	DRV=b:
fi
if [ "x$DOSVER" != "xMS-DOS 3.3" ]
then
	# With newer DOS, must use the "u" flag to give it an
	# initial format, otherwise can have problems due to
	# the "unformat" feature when trying to format.
	if [ -n "$BOOTABLE" ]
	then
	    # When using the 's' option to make it bootable,
	    # pre-format the disk.
	    if [ -n "$VISUAL" ]
	    then
		dos +a${DRV}=${FILE} -e -p -b /usr/dbin/format ${DRV} -u
	    else
		dos +a${DRV}=${FILE} -e -p +b /usr/dbin/format ${DRV} -u  \
			< $TMPFILE > /dev/null
	    fi
	fi
	if [ -n "$VISUAL" ]
	then
		dos +a${DRV}=${FILE} -e -p -b /usr/dbin/format ${DRV} -u $OPT1 
	else
		dos +a${DRV}=${FILE} -e -p +b /usr/dbin/format ${DRV} -u $OPT1 \
			< $TMPFILE > /dev/null
	fi
else
	if [ -n "$VISUAL" ]
	then
		dos +a${DRV}=${FILE} -e -p -b /usr/dbin/format ${DRV} $OPT1
	else
		dos +a${DRV}=${FILE} -e -p +b /usr/dbin/format ${DRV} $OPT1 \
			< $TMPFILE > /dev/null
	fi
fi
rm -f $TMPFILE
