:
# SCCSID(@(#)mkimg	1.91 LCC) Modified 15:54:17 1/18/93

#****************************************************************************
# Script to make the Merge DOS image files.
#****************************************************************************
#
#	Copyright (c) 1985-92 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.
#
#****************************************************************************
# New mkimg options for DOS 5.0 support.
# New feature: "use-dosdev".  This feature makes sure that
# DOS drivers are not loaded in the UMB area where a memory mapped io
# device might latter need to be attached.  Mkimg does this by looking at
# the /etc/dosdev file for direct attach memory mapped io definitions, and
# preventing drivers from being loaded at the defined memory locations when
# making the DOS images.
#
# There are three new options disable "use-dosdev":
#
# no_dosdev	(NO_DOSDEV variable)
#		Turn off the "use-dosdev" feature.
#		This option is not to be documented for end users.
# devicelow	(DEV_LOW variable)
#		Edit config.sys to change any "devicehigh" lines to "device"
#		lines.  This results in no drivers not being loaded in
#		the UMB area as part of the DOS image.
#		This option also disables "use-dosdev", as if the "no_dosdev"
#		option was used.
# +aXXX		(DEV_ATTACH_LIST variable)
#		Attaches XXX device while making images.
#		If the XXX device has memory-mapped io, then
#		drivers will not be loaded at those locations.
#		This option also disables "use-dosdev", as if the "no_dosdev"
#		option was used.
#****************************************************************************
unset ONUNIX

DBIN=/usr/dbin
LIBM=/usr/lib/merge

IMAGE_ROOT=/usr/merge/image
DEFAULT_IMAGEDIR=$IMAGE_ROOT/std

# The script "set_nls.sh" uses LIBM to set MFILE.
. $LIBM/set_nls.sh

# DM is the domain for messages for this script.
DM="LCC.MERGE.UNIX.MKIMG"
NULL=/dev/null
> $NULL
export NULL
STD_VGAROM=$LIBM/std_vga.rom
STD_EGAROM=$LIBM/std_ega.rom
VIDEO_ROM=
THISPROG=$0
VGAFLAG=
EGAFLAG=
CGAFLAG=
MDAFLAG=
VISUALMKIMG=
VISUAL2=
CONSOLE=
UNKNOWN=
NATIVE=
NONATIVE=
VGAOK=
EGAOK=
FAKEEGA=
NEW_ROM=
DEV_LOW=
NO_DOSDEV=
DEV_ATTACH_LIST=
PROBLEMS=0
PATH=/bin:/usr/bin:/usr/local/bin:/usr/dbin ; export PATH
# Important: This script has code that makes these assumptions:
#  - VFLOP is in /usr/tmp
#  - RS_FILE is in /tmp
VFLOP_DIR=/usr/tmp
VFLOP=$VFLOP_DIR/vflp$$
VSNAP=$VFLOP_DIR/vsnp$$
RS_DIR=/tmp
RS_FILE=$RS_DIR/rs$$
TMPFILE=/usr/tmp/mkimg$$
TMPCONFIG=/usr/tmp/config$$
TMPAUTOE=/usr/tmp/autoe$$
ERR_FILE=/usr/tmp/err$$

if [ -c /dev/con ]
then
	CONSOLE=/dev/con	### CT console device
else
	CONSOLE=/dev/console
fi


# Function "Writeable"
# Return 0 if able to write to the file (arg $1)
# Does not change the time stamp an existing file.
# Does not leave a zero length file if the file did not exist.
Writeable()
{
	RETVAL=1
	if [ -f $1 ]
	then
		[ -w $1 ] && RETVAL=0
	else
		eval "> $1" 2>> $NULL
		[ -w $1 ] && RETVAL=0
		rm -f $1
	fi
	return $RETVAL
}

EXIT_NOW()
{
	rm -f /usr/merge/doing_mkimg
	exit $1
}

# Function "Exit_Clean"
# Cleans up and then exits with the code in arg $1
Exit_Clean()
{
	rm -f $TMPFILE
	rm -f $VFLOP
	rm -f $VSNAP
	rm -f $RS_FILE
	rm -f $ERR_FILE
	rm -f $TMPCONFIG
	rm -f $TMPAUTOE
	rm -f /tmp/dos.img
	rm -f /tmp/umb_????.img
	rm -f /tmp/hma.img
	rm -f /tmp/pcidrive
	EXIT_NOW $1
}

# Space consumed by image files:
#   low image + umb image = 144 blocks
#   high image = 128 blocks.
#   vga rom = 64 blocks
# So for mono or cga, 272 blocks.
# So for ega or vga, 336 blocks.

# Function Check_Room
# Checks for needed space.
# Zero return means ok,  non-zero means not enough room.
Check_Room()
{
	# Make sure there is enough space.
	# First parameter is the directory.
	# Second parameter is the number of blocks needed in the directory.
	#
	WHERE=$1
	NEED=$2
	export HOWMUCH
	Blocks=`$LIBM/dfmerge -b $WHERE`
	[ $Blocks -lt $NEED ] && return 1
	return 0
}

Copy_To_Vsnap()
{
	# First parameter: file to copy.
	# Second parameter: name to copy it to on the virtual floppy.
	echo "copyto $2 $1" | /usr/lib/merge/dosdisk -s $VSNAP
	return 0
}

Make_config_mki()
{
	if [ -f $IMGDIR/config.mki ]
	then
		# Already made.
		return
	fi
	# Need the correct config.mki file to make images.
	if [ "z$DOSVER" = "zMS-DOS 5.0" ]
	then
		cp /usr/lib/merge/config5.mki $IMGDIR/config.mki
	elif [ "z$DOSVER" = "zDR-DOS 6.0" ]
	then
		cp /usr/lib/merge/config_dr6.mki $IMGDIR/config.mki
	else
		# Default (MS-DOS 3.3)
		cp /usr/lib/merge/config3.mki $IMGDIR/config.mki
	fi
}

Make_Config_File()
{
	# Put together a config.sys file to put on the snap disk.
	# Create the config.sys by concatinating "config.mki"
	# with a "config.sys".
	# First look for "config.mki" in the image subdirectory.
	# If it is not in the subdirectory then use the file from
	# the IMAGE_ROOT ("/usr/merge/image").  The "config.sys"
	# file always comes from the image subdirectory.
	# Note: The first parameter to this function is the image type.

	CONFIG_MKI=$DIRECTORY/$1/config.mki
	if [ ! -f $CONFIG_MKI -o ! -r $CONFIG_MKI -o ! -s $CONFIG_MKI ]
	then
		CONFIG_MKI=$IMAGE_ROOT/config.mki
		if [ ! -f $CONFIG_MKI -o ! -r $CONFIG_MKI -o ! -s $CONFIG_MKI ]
		then
			usrMsg ECHO CANNOT_COPY \
				"Cannot copy $CONFIG_MKI file.\n" $CONFIG_MKI
			return 1
		fi
	fi

	CONFIG_SYS=$DIRECTORY/$1/config.sys
	if [ ! -f $CONFIG_SYS -o ! -r $CONFIG_SYS -o ! -s $CONFIG_SYS ]
	then
		CONFIG_SYS=
	fi

	rm -f $TMPCONFIG
	# Do DOS to UNIX converstions to get rid of any trailing ^Z.
	# (Note: use our private copy of charconv, because an installation of
	# PCI might have overwritten an installed an incompatable version.)
	/usr/lib/merge/charconv -d -x -z $CONFIG_MKI > $TMPCONFIG 2>>$NULL
	if [ -n "$CONFIG_SYS" ]
	then	
		/usr/lib/merge/charconv -d -x -z $CONFIG_SYS > $TMPFILE 2>>$NULL
		cat $TMPFILE >> $TMPCONFIG
	fi

	# When DEV_LOW is set:	Edit config.sys to change any "devicehigh"
	#	lines to "device" lines.  This results in those drivers
	#	not being loaded in the UMB area.
	if [ -n "$DEV_LOW" ]
	then
		sed "s/devicehigh/device/g" $TMPCONFIG > $TMPFILE
		sed "s/DEVICEHIGH/DEVICE/g" $TMPFILE > $TMPCONFIG
	fi

	# Do a UNIX to DOS converstion.
	cp $TMPCONFIG $TMPFILE
	/usr/lib/merge/charconv -p -x $TMPFILE $TMPCONFIG >> $ERRLOG 2>&1
	rm -f $TMPFILE

	cat $TMPCONFIG >> $NULL

	Copy_To_Vsnap "$TMPCONFIG" config.sys
	RETVAL=$?
	rm -f $TMPCONFIG
	if [ $RETVAL -ne 0 ]
	then
		usrMsg ECHO CANNOT_COPY \
			"Cannot copy config.sys file.\n" config.sys
		return 1
	fi
	return 0
}

Make_AE_File()
{
	# Put together a autoexec.bat file to put on the snap disk.
	# Create the autoexec.bat by concatinating "autoexec.mki"
	# with an "autoexec.bat".
	# First look for "autoexec.mki" in the image subdirectory.
	# If it is not in the subdirectory then use the file from
	# the IMAGE_ROOT ("/usr/merge/image").  The "autoexec.bat"
	# file always comes from the image subdirectory.
	# Note: The first parameter to this function is the image type.

	AUTOE_MKI=$DIRECTORY/$1/autoexec.mki
	if [ ! -f $AUTOE_MKI -o ! -r $AUTOE_MKI -o ! -s $AUTOE_MKI ]
	then
		AUTOE_MKI=$IMAGE_ROOT/autoexec.mki
		if [ ! -f $AUTOE_MKI -o ! -r $AUTOE_MKI -o ! -s $AUTOE_MKI ]
		then
			AUTOE_MKI=
		fi
	fi

	AUTOE_BAT=$DIRECTORY/$1/autoexec.bat
	if [ ! -f $AUTOE_BAT -o ! -r $AUTOE_BAT -o ! -s $AUTOE_BAT ]
	then
		AUTOE_BAT=
	fi

	rm -f $TMPAUTOE
	# Do DOS to UNIX converstions to get rid of any trailing ^Z.
	if [ -n "$AUTOE_MKI" ]
	then	
		/usr/lib/merge/charconv -d -x -z $AUTOE_MKI > $TMPFILE 2>>$NULL
	fi
	if [ -n "$AUTOE_BAT" ]
	then	
		/usr/lib/merge/charconv -d -x -z $AUTOE_BAT >> $TMPFILE 2>>$NULL
	fi
	# When DR-DOS is being used, put in the merge command to set "drdos on".
	if [ "z$DOSVER" = "zDR-DOS 6.0" ]
	then
		echo "merge set drdos on" >> $TMPFILE
	fi
	if [ ! -s $TMPFILE ]
	then
		# Nothing to do.
		return 0
	fi

	# Do a UNIX to DOS converstion.
	/usr/lib/merge/charconv -p -x $TMPFILE $TMPAUTOE >> $ERRLOG 2>&1
	rm -f $TMPFILE

	Copy_To_Vsnap "$TMPAUTOE" autoexec.bat
	RETVAL=$?
	rm -f $TMPAUTOE
	if [ $RETVAL -ne 0 ]
	then
		usrMsg ECHO CANNOT_COPY \
			"Cannot copy autoexec.bat file.\n" autoexec.bat
		return 1
	fi
	return 0
}

Get_devattach()
{
	if [ -n "$NO_DOSDEV" ]
	then
		# When "no_dosdev" was specified (NO_DOSDEV=1),
		# then don't look for direct attach devices in /etc/dosdev.
		DEV_ATTACH_LIST=
		return
	fi
	if [ -n "$DEV_ATTACH_LIST" ]
	then
		# Already have devices to attach, as specified
		# by the user with "+aXXX", so don't look at
		# /etc/dosdev for direct attach devices.
		return
	fi
	if [ -n "$DEV_LOW" ]
	then
		# When "devicelow" was specified (DEV_LOW=1), then no
		# need to look at /etc/dosdev for direct attach memory
		# ranges to reserve from having devices put there.
		return
	fi
	# Since the attach list was not specified (with +aXXX), look
	# through /etc/dosdev for direct attach devices, and put the
	# them in the attach list.  With the "exclude_umb_only" flag,
	# dosexec will not actually attach them, but will only use
	# the memory map range info (if any) to tell the xms driver
	# to avoid those ranges.
	LIST=
	export LIST
	DEV_ATTACH_LIST=`grep d /etc/dosdev 2>> $NULL | while true ;\
		do read TOKEN TYPE OTHER ;\
			if [ -z "$TOKEN" ] ; then echo "$LIST" ; exit 0 ; fi ;\
			if [ "x$TYPE" != "xd" ] ; then continue ; fi ;\
			LIST="$LIST +a$TOKEN,exclude_umb_only" ;\
 		done`
}

Format_Vflop()
{
	# Create virtual snap disk
	rm -f $VFLOP
	cp /usr/dbin/boot.dsk $VFLOP
}

Create_Vsnap()
{
	# What the parameters are:
	# 1: the filename of the virtual floppy.
	# 2: the directory where the base Merge files are.
	# 3: the directory where the DOS files are.
	# 4: the directory where the image specific file are.

	VSnap=$1
	MergeDir=$2
	DosDir=$3
	ImageDir=$4

	> $TMPFILE
	# Copy files from MergeDir
	for i in init.com snap.com bridge.sys hicon.sys part.sys ulink.sys \
		mrgxms.sys merge_ae.exe merge.set
	do
		echo "copyto $i $MergeDir/$i" >> $TMPFILE
	done
	# Copy files from DosDir
	if [ -f $DosDir/.subst.exe ]
	then
		# This command file is hidden from normal use, but
		# we need it on the snap disk.
		echo "copyto subst.exe $DosDir/.subst.exe" >> $TMPFILE
	fi
	for i in display.sys ega.cpi mode.com quit.com nlsfunc.exe \
		subst.exe keyb.com keyboard.sys merge.exe
	do
		if [ -f $DosDir/$i ]
		then
			echo "copyto $i $DosDir/$i" >> $TMPFILE
		fi
	done
	if [ -f /country.sys ]
	then
		echo "copyto country.sys /country.sys" >> $TMPFILE
	fi
	if [ "z$DOSVER" = "zDR-DOS 6.0" ]
	then
		# DR-DOS 6.0 only, copy hidos.sys to the snap disk.
		for i in hidos.sys
		do
			if [ -f $DosDir/$i ]
			then
				echo "copyto $i $DosDir/$i" >> $TMPFILE
			fi
		done
	fi
	for i in `ls $ImageDir`
	do
		# Don't put existing image files on the disk. (*.img)
		# Don't put saved image files on the disk.    (*.img.sv)
		# Don't put rom files on the disk.            (*.rom)
		# Don't put saved rom files on the disk.      (*.rom.sv)
		# Don't put config or autoexec files on the
		# list now. They are done later.  Note that we reject
		# any file name with "autoexec.bat" in it, not only those
		# that end with it.  This is because if for example,
		# "autoexec.bat.save" is copied to the snap disk, the
		# name is truncated to "autoexec.bat", thus conflicting
		# with the real autoexec.bat file.
		TEST=accept
		for j in  '\.img$' '\.img\.sv$' '\.rom$' '\.rom\.sv$' \
			'^autoexec.bat' '^autoexec.mki$' '^config.sys$' \
			'^config.mki$' '^core$'
		do
			echo $i | grep $j >> $NULL 2>&1
			if [ $? -eq 0 ]
			then
				# Don't copy it to the snap disk.
				TEST=reject
				continue
			fi
		done
		if [ "$TEST" = "accept" ]
		then
			echo "copyto $i $ImageDir/$i" >> $TMPFILE
		fi
	done
	# At this point $TMPFILE has all the "dosdisk" commands needed
	# to copy all the needed files to the vsnap disk,
	# (except for the config.sys file).

	# Copy the files to the vsnap disk.
	cat $TMPFILE | /usr/lib/merge/dosdisk -s $VSNAP

	rm -f $TMPFILE
	return 0
}

# Determine display type
DISPLAY=`$LIBM/display $CONSOLE 2>> $NULL`
TTYDSP=`$LIBM/display /dev/tty 2>> $NULL`

if [ "$DISPLAY" = "ega" -o "$TTYDSP" = "ega" ]
then
	[ "$TTYDSP" = "ega" ] && DISPLAY=ega
	if [ -r "$STD_EGAROM" ]
	then
		EGAOK=egaok			# Native or standard
		VIDEO_ROM=$STD_EGAROM
	else
		EGAOK=onlynative
		NATIVE=native			# Force native
	fi
else
	[ "$TTYDSP" = "vga" ] && DISPLAY=vga
	if [ -r "$STD_VGAROM" ]
	then
		VIDEO_ROM=$STD_VGAROM
		if [ "$DISPLAY" = "vga" -a  -r /dev/kmem ]
		then
			# Can use native vga rom ONLY when on a vga console AND
			# have root permissions.
			VGAOK=vgaok			# Native or standard
		else
			# When regular user OR the console is not a vga,
			# then can only use the standard ROM.
			NONATIVE=nonative
			VGAOK=nonative			#  standard ROM only
		fi
	elif [ "$DISPLAY" = "vga" -a  -r /dev/kmem ]
	then
		# Can use native vga rom ONLY when on a vga console AND
		# have root permissions.
		VGAOK=onlynative
		NATIVE=native			# Force native
	fi
fi
# NOTE: Should NOT have EGAOK and VGAOK both set at same time.

USE1=
USE2=
USE3=
usrMsg STRING NATIVE_TOKEN "native"
NATIVE_TOKEN="$USRMSG_STRING"

if [ -n "$EGAOK" -o -n "$VGAOK" ]
then
	# When can use either generic or native video rom, give useage
	# of option that makes native ROM to be used: "native"
	if [ "$EGAOK" = "egaok" -o "$VGAOK" = "vgaok" ]
	then
		USE1="[ [$NATIVE_TOKEN] "
		USE3="] "
	fi
	if [ -n "$VGAOK" ]
	then
		USE2="[vga] "
	else
		USE2="[ega] "
	fi
fi

# For backwards compatability, all the options can use a leading dash.
# Also "tty", "mono" and "hercules" can be used for "mda".

while [ -n "$1" ]
do

	case $1 in

	d)	### custom directory for installing DOS image files
		shift
		DIRECTORY=$1
		;;
	-d)	### custom directory for installing DOS image files
		shift
		DIRECTORY=$1
		;;
	vga)	VGAFLAG=1
		;;
	-vga)	VGAFLAG=1
		;;
	ega)	EGAFLAG=1
		;;
	-ega)	EGAFLAG=1
		;;
	cga)	CGAFLAG=1
		;;
	-cga)	CGAFLAG=1
		;;
	mda)	MDAFLAG=1
		;;
	-mda)	MDAFLAG=1
		;;
	mono)	MDAFLAG=1
		;;
	-mono)	MDAFLAG=1
		;;
	hercules)
		MDAFLAG=1
		;;
	-hercules)
		MDAFLAG=1
		;;
	tty)	MDAFLAG=1
		;;
	-tty)	MDAFLAG=1
		;;
	$NATIVE_TOKEN) NATIVE=native
		;;
	-$NATIVE_TOKEN) NATIVE=native
		;;
	visual)		VISUALMKIMG=1
		;;
	visual2)	VISUAL2=1
		;;
	devicelow)	DEV_LOW=1
		;;
	no_dosdev)	NO_DOSDEV=1
		;;
	*)

		# The only other options allowed are the "+a" options,
		# for attaching devices while making images.
		AOPT="`echo $1 | cut -c1-2`"
		if [ "x$AOPT" = "x+a" ]
		then
			TOKEN="`echo $1 | cut -c3-40`"
			echo "+a$TOKEN" >> $NULL
			DEV_ATTACH_LIST="$DEV_ATTACH_LIST $1"
		else
			AAA="$THISPROG ${USE1}${USE2}${USE3}"
			usrMsg ECHO USAGE_LINE \
	"USAGE: $AAA[cga] [mda] [ d directory ] [devicelow] [+aXXX]\n" "$AAA"
			Exit_Clean 1
		fi
		;;
	esac
	shift
done

# Default directory is DEFAULT_IMAGEDIR
[ -z "$DIRECTORY" ] && DIRECTORY=$DEFAULT_IMAGEDIR
if [ ! -d $DIRECTORY ]
then
	mkdir -p $DIRECTORY >> $NULL 2>&1 
	chmod 755 $IMAGE_ROOT $DIRECTORY
	chgrp bin $IMAGE_ROOT $DIRECTORY
	chown bin $IMAGE_ROOT $DIRECTORY
fi
if [ ! -d $DIRECTORY ]
then
	usrMsg ECHO NO_DIRECTORY \
		"The directory $DIRECTORY does not exist.\n" $DIRECTORY
	usrMsg ECHO CANNOT_CONTINUE "Cannot continue.\n"
	usrMsg ECHO NO_IMG_MADE "No image files were made.\n"
	Exit_Clean 1
fi

if [ -n "$NATIVE" -a -n "$NONATIVE" ]
then
	usrMsg ERROR OPT_NA "$NATIVE_TOKEN option not allowed.\n" $NATIVE_TOKEN
	usrMsg ECHO NO_IMG_MADE "No image files were made.\n"
	Exit_Clean 1
fi

if [ -z "$VGAFLAG" -a -z "$EGAFLAG" -a -z "$CGAFLAG" -a -z "$MDAFLAG" ]
then
	# Since image type was not specified, make the default image files:
	[ -n "$VGAOK" -a "$VGAOK" != "onlynative" ] && VGAFLAG=1
	[ -n "$EGAOK" -a "$EGAOK" != "onlynative" ] && EGAFLAG=1
	CGAFLAG=1
	MDAFLAG=1
fi

Writeable /tmp/dos.img
if [ $? -ne 0 ]
then
	usrMsg ERROR NO_PERMIS_TMP \
		"Error: No permission to create temporary file /tmp/dos.img\n" \
		/tmp/dos.img
	usrMsg ECHO NO_IMG_MADE "No image files were made.\n"
	Exit_Clean 1
fi
> /tmp/dos.img
chmod 644 /tmp/dos.img

Writeable $VFLOP
if [ $? -ne 0 ]
then
	usrMsg ERROR NO_PERMIS_TMP \
		"Error: No permission to create temporary file $VFLOP\n" \
		$VFLOP
	usrMsg ECHO NO_IMG_MADE "No image files were made.\n"
	Exit_Clean 1
fi
	
for i in /tmp/umb_????.img /tmp/hma.img
do
	[ ! -f $i ] && continue
	rm -f $i
	[ ! -f $i ] && continue
	usrMsg ERROR NO_PERMIS_TMP \
		"Error: No permission to create temporary file $i\n" \
		$i
	usrMsg ECHO NO_IMG_MADE "No image files were made.\n"
	Exit_Clean 1
done

if [ -n "$MDAFLAG" ]
then
	if [ ! -d $DIRECTORY/mono ]
	then
		mkdir $DIRECTORY/mono >> $NULL 2>&1 
	fi
	if [ ! -d $DIRECTORY/mono ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make MDA image.\n" MDA
		usrMsg ECHO NO_PERMIS_WRITE \
			"Do not have permission to write $DIRECTORY\n" \
			$DIRECTORY
	fi
	Writeable $DIRECTORY/mono/mono.img
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make MDA image.\n" MDA
		usrMsg ECHO NO_PERMIS_WRITE \
		    "Do not have permission to write $DIRECTORY/mono.img\n" \
		    $DIRECTORY/mono.img
		MDAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$CGAFLAG" ]
then
	Writeable $DIRECTORY/cga.img
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make CGA image.\n" CGA
		usrMsg ECHO NO_PERMIS_WRITE \
		    "Do not have permission to write $DIRECTORY/cga.img\n" \
		    $DIRECTORY/cga.img
		CGAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$EGAFLAG" ]
then
	if [ -z "$EGAOK" ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make EGA image.\n" EGA
		usrMsg ECHO WRONG_DISP \
			"Cannot make EGA image on $DISPLAY type display.\n" \
			EGA $DISPLAY
		EGAFLAG=""
		PROBLEMS=1
	fi
	if [ ! -r /dev/kmem ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make EGA image.\n" EGA
		usrMsg ECHO MUST_SU \
			"Must be root or su to make EGA image.\n" EGA
		EGAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$EGAFLAG" ]
then
	Writeable $DIRECTORY/ega.img
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make EGA image.\n" EGA
		usrMsg ECHO NO_PERMIS_WRITE \
		    "Do not have permission to write $DIRECTORY/ega.img\n" \
		    $DIRECTORY/ega.img
		EGAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$EGAFLAG" ]
then
	Writeable $DIRECTORY/ega.rom
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make EGA image.\n" EGA
		usrMsg ECHO NO_PERMIS_WRITE \
		    "Do not have permission to write $DIRECTORY/ega.img\n" \
		    $DIRECTORY/ega.img
		EGAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$VGAFLAG" ]
then
	if [ -z "$VGAOK" ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make VGA image.\n" VGA
		usrMsg ECHO WRONG_DISP \
			"Cannot make VGA image on $DISPLAY type display.\n" \
			VGA $DISPLAY
		VGAFLAG=""
		PROBLEMS=1
	elif [ -n "$NATIVE" -a ! -r /dev/kmem ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make VGA image.\n" VGA
		usrMsg ECHO MUST_SU \
			"Must be root or su to make VGA image.\n" VGA
		VGAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$VGAFLAG" ]
then
	Writeable $DIRECTORY/vga.img
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE "Cannot make VGA image.\n" VGA
		usrMsg ECHO NO_PERMIS_WRITE \
		    "Do not have permission to write $DIRECTORY/vga.img\n" \
		    $DIRECTORY/vga.img
		VGAFLAG=""
		PROBLEMS=1
	fi
fi

if [ -z "$VGAFLAG" -a -z "$MDAFLAG" -a -z "$CGAFLAG" -a -z "$EGAFLAG" ]
then
	usrMsg ECHO NO_IMG_MADE "No image files were made.\n"
	Exit_Clean 1
fi
Check_Room $VFLOP_DIR 650
if [ $? -ne 0 ]
then
	usrMsg ERROR NO_ROOM_TMP \
		"Not enough room to create temporary file $VFLOP\n" $VFLOP
	usrMsg ECHO NO_IMG_MADE "No image files were made.\n"
	Exit_Clean 1
fi
##############################################################################
# Here is where we actually start the image making work.
########################################################

usrMsg ECHO CONFIG_MSG "Configuring DOS image files.\n"

# Give this script ten minutes to complete.
(sleep 600; kill $$ 2>> $NULL) &

if [ ! -r /usr/dbin/boot.dsk ]
then
	if [ ! -f /usr/dbin/boot.dsk ]
	then
		usrMsg ERROR MISSING \
			"Missing file /usr/dbin/boot.dsk\n" /usr/dbin/boot.dsk
		if [ ! -f /usr/dbin/command.com ]
		then
			usrMsg ERROR DOS_NI "DOS is not installed\n"
		fi
	else
		usrMsg ERROR CANNOT_READ \
			"Cannot read file /usr/dbin/boot.dsk\n" \
			/usr/dbin/boot.dsk
	fi
	usrMsg ECHO CANNOT_CONTINUE "Cannot continue.\n"
	usrMsg ECHO NO_IMG_MADE "No image files were made.\n"
	Exit_Clean 1
fi
if [ -f /usr/dbin/version.dos ]
then
	. /usr/dbin/version.dos
fi
IMGDIR=/usr/merge/image
if [ ! -d $IMGDIR ]
then
	mkdir -p $IMGDIR
	chmod 755 $IMGDIR
	chgrp bin $IMGDIR
	chown bin $IMGDIR
fi
Make_config_mki

# Create the $VFLOP virtual floppy.
Format_Vflop

# Set up DEV_ATTACH_LIST
Get_devattach
echo "DEV_ATTACH_LIST=$DEV_ATTACH_LIST" >> $NULL

# Function "Put_Back" cleans up after a failed "Do_Img" or "Do_Xga".
# Remove the temporary files and restore the original img files.
Put_Back()
{
	rm -f $VSNAP
	rm -f /tmp/dos.img
	rm -f /tmp/${IMG_TYPE}.img
	rm -f /tmp/umb_????.img
	rm -f /tmp/hma.img
	for p_b in ${IMD}/*.img.sv
	do
		[ ! -f $p_b ]  && continue
		rm -f  ${IMD}/`basename $p_b .sv`
		mv $p_b ${IMD}/`basename $p_b .sv`
	done
	if [ -n "$NEW_ROM" -a -n "$SAVE_ROM" -a -f "$SAVE_ROM" ]
	then
		rm -f $ROMFILE
		mv $SAVE_ROM $ROMFILE >> $NULL 2>&1
	fi
}

################# "Do_Img" - Function that makes mda/cga image files. #########
################# (image files that don't use video roms) #####################
Do_Img ()
{
	IMG_TAG=$1
	IMG_TYPE=$2
	IMD=${DIRECTORY}/${IMG_TYPE}
	NEW_ROM=
	if [ ! -d ${IMD} ]
	then
		mkdir ${IMD} >> $NULL 2>&1
	fi
	if [ ! -d ${IMD} ]
	then
		usrMsg ECHO CANNOT_MKDIR \
			"Cannot make directory: ${IMD}" \
			"${IMD}"
		return 1	# problems
	fi
	# Remove any existing temporary files.
	for i in /tmp/dos.img /tmp/${IMG_TYPE}.img /tmp/umb_????.img \
		/tmp/hma.img $VSNAP
	do
		rm -f $i
		if [ -f $i ]
		then
			usrMsg WARN REMOVE_FAIL "Could not remove file $i\n" $i
			return 1	# problems
		fi
	done

	cp $VFLOP $VSNAP
	cmp -s $VFLOP $VSNAP >> $NULL 2>&1
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_WRITE \
			"Could not write $VSNAP\n" $VSNAP
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image.\n" $IMG_TAG
		return 1
	fi
	# Parameters to "Create_Vsnap":
	# 1: the filename of the virtual floppy.
	# 2: the directory where the base Merge files are.
	# 3: the directory where the DOS files are.
	# 4: the directory where the image specific files are.
	Create_Vsnap $VSNAP $LIBM /usr/dbin ${IMD}
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image.\n" $IMG_TAG
		rm -f $VSNAP
		return 1
	fi
	Make_Config_File $IMG_TYPE
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image.\n" $IMG_TAG
		rm -f $VSNAP
		return 1	# problems
	fi
	Make_AE_File $IMG_TYPE
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image.\n" $IMG_TAG
		rm -f $VSNAP
		return 1	# problems
	fi

	usrMsg ECHO MAKING "Making $IMG_TAG Image.\n" $IMG_TAG

	> /tmp/dos.img
	chmod 644 /tmp/dos.img

	Check_Room /tmp 400
	if [ $? -ne 0 ]
	then
		usrMsg WARN NOT_MADE "$IMG_TAG image was not made.\n" \
			$IMG_TAG
		usrMsg ECHO CREATE_NOROOM \
			"Not enough room to create file /tmp/dos.img\n" \
			/tmp/dos.img
		return 1	# problems
	fi
	if [ -n "$SAVE_VSNAP" ]
	then
		cp $VSNAP /tmp/vsnap.$IMG_TYPE
	fi
	> /tmp/save_msg.dos 2> /dev/null
	rm -f /tmp/save_msg.dos
	if [ ! -s /tmp/save_msg.dos ]
	then
		MSG_SAVE=/tmp/save_msg.dos
	else
		MSG_SAVE=
	fi
	if [ -z "$VISUALMKIMG" ]
	then
		dos +a$IMG_TYPE +aa:=$VSNAP $DEV_ATTACH_LIST \
			+b +c -e -l -p ver >> $NULL
	else
		# Allow the screen to be seen during boot and snap.
		dos +a$IMG_TYPE +aa:=$VSNAP $DEV_ATTACH_LIST \
			-b +c -e -l -p ver
	fi
	EXITVAL=$?
	echo "EXITVAL=$EXITVAL" >> $NULL
	if [ $EXITVAL -ne 0 ]
	then
		usrMsg WARN NOT_MADE "$IMG_TAG image was not made.\n" \
			$IMG_TAG
		echo "($EXITVAL)" | tee -a $NULL
		if [ -n "$MSG_SAVE" -a -s $MSG_SAVE ]
		then
			cat $MSG_SAVE | tee -a $NULL
		fi
		Put_Back
		return 1	# problems
	fi
	
	SIZE=`wc -c < /tmp/dos.img`
	if [ $SIZE -lt 10000 ]
	then
		echo "SIZE=$SIZE" >> $NULL
		usrMsg WARN NOT_MADE "$IMG_TAG image was not made.\n" \
			$IMG_TAG
		if [ $SIZE -ne 0 ]
		then
			usrMsg ECHO NO_ROOM "(No more room?)\n"
		fi
		if [ -n "$MSG_SAVE" -a -s $MSG_SAVE ]
		then
			cat $MSG_SAVE | tee -a $NULL
		fi
		Put_Back
		return 1	# problems
	fi
	# Rename the current image files to ".sv" names, so that can
	# restore them if needed.
	for i in $IMD/${IMG_TYPE}.img
	do
		rm -f $i.sv
		if [ -f $i.sv ]
		then
			usrMsg WARN REMOVE_FAIL \
				"Could not remove file $i.sv\n" $i.sv
			Put_Back
			return 1	# problems
		fi
		[ -f $i ] && mv $i $i.sv
	done

	rm -f /tmp/${IMG_TYPE}.img
	if [ -f /tmp/${IMG_TYPE}.img ]
	then
		usrMsg WARN REMOVE_FAIL \
			"Could not remove file /tmp/${IMG_TYPE}.img\n" \
			/tmp/${IMG_TYPE}.img
		Put_Back
		return 1	# problems
	fi
	mv /tmp/dos.img /tmp/${IMG_TYPE}.img
	
	if [ -f $IMD/umb_????.img ]
	then
		rm -f $IMD/umb_????.img >> $NULL
	fi

	if [ -f $IMD/hma.img ]
	then
		rm -f $IMD/hma.img >> $NULL
	fi

	for i in /tmp/${IMG_TYPE}.img /tmp/umb_????.img /tmp/hma.img
	do
		[ ! -f $i ] && continue
		mv $i $IMD
		BN=`basename $i`
		if [ ! -f $IMD/$BN ]
		then
			usrMsg WARN CANNOT_WRITE \
				"Could not write $IMD/$BN\n" \
				$IMD/$BN
			usrMsg ECHO NO_ROOM "(No more room?)\n"
			Put_Back
			return 1	# problems

		fi
	done
	rm -f /tmp/dos.img
	rm -f /tmp/umb_????.img
	rm -f /tmp/hma.img
	rm -f $IMD/*.img.sv
	rm -f $VSNAP
	dosopt Patch_image_file $IMG_TYPE $IMD/${IMG_TYPE}.img >> $NULL 2>&1
	return 0	# Success
}


################# "Do_Xga" - Function that makes ega/vga image files ##########
Do_Xga()
{
	IMG_TAG=$1
	IMG_TYPE=$2
	IMD=${DIRECTORY}/${IMG_TYPE}
	NEW_ROM=
	if [ ! -d ${IMD} ]
	then
		mkdir ${IMD} >> $NULL 2>&1
	fi
	if [ ! -d ${IMD} ]
	then
		usrMsg ECHO CANNOT_MKDIR \
			"Cannot make directory: ${IMD}" \
			"${IMD}"
		return 1	# problems
	fi
	# Remove any existing temporary files.
	for i in /tmp/dos.img /tmp/${IMG_TYPE}.img /tmp/umb_????.img \
		/tmp/hma.img $VSNAP
	do
		rm -f $i
		if [ -f $i ]
		then
			usrMsg WARN REMOVE_FAIL "Could not remove file $i\n" $i
			return 1	# problems
		fi
	done

	ROMFILE="${IMD}/${IMG_TYPE}.rom"
	SAVE_ROM=$ROMFILE.sv

	cp $VFLOP $VSNAP
	cmp -s $VFLOP $VSNAP >> $NULL 2>&1
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_WRITE \
			"Could not write $VSNAP\n" $VSNAP
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image.\n" $IMG_TAG
		return 1
	fi
	# Parameters to "Create_Vsnap":
	# 1: the filename of the virtual floppy.
	# 2: the directory where the base Merge files are.
	# 3: the directory where the DOS files are.
	# 4: the directory where the image specific files are.
	Create_Vsnap $VSNAP $LIBM /usr/dbin ${IMD}
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image.\n" $IMG_TAG
		rm -f $VSNAP
		return 1
	fi
	Make_Config_File $IMG_TYPE
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image.\n" $IMG_TAG
		rm -f $VSNAP
		return 1	# problems
	fi
	Make_AE_File $IMG_TYPE
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image.\n" $IMG_TAG
		rm -f $VSNAP
		return 1	# problems
	fi

	> /tmp/dos.img
	chmod 644 /tmp/dos.img

	# Set up ega.rom/vga.rom
	if [ -n "$NATIVE" ]
	then
		# Use ROM on the EGA/VGA card.
		Check_Room $RS_DIR 274
		if [ $? -ne 0 ]
		then
			usrMsg WARN CANNOT_MAKE \
				"Cannot make $IMG_TAG image.\n" $IMG_TAG
			usrMsg ECHO CREATE_NOROOM \
				"Not enough room to create file $RS_FILE\n" \
				$RS_FILE
			return 1	# problems
		fi
		grep CTMERGE /usr/merge/Version >>$NULL 2>&1
		if [ $? = 0 ]
		then	# do CT/UNISYS way
			$LIBM/romsnap d60c0000 $RS_FILE -k
		else
			$LIBM/romsnap c0000 $RS_FILE
		fi
		SIZE=`wc -c < $RS_FILE`
		if [ $SIZE -lt 10000 ]
		then
			usrMsg WARN CANNOT_MAKE \
				"Cannot make $IMG_TAG image." $IMG_TAG
			usrMsg WARN CANNOT_WRITE \
				"Could not write $RS_FILE\n" $RS_FILE
			rm -f $RS_FILE
			return 1	# problems
		fi
		cmp -s $ROMFILE $RS_FILE
		if [ $? -ne 0 ]
		then
			# The ROM is different.  Need to use the fresh snap.
			usrMsg ECHO USING_ONCARD \
				"Using $IMG_TAG ROM on the display card.\n" \
				$IMG_TAG
			NEW_ROM=$RS_FILE
		fi
	else
		# Not native, so use the generic ROM
		cmp -s $ROMFILE $VIDEO_ROM
		if [ $? -ne 0 ]
		then
			# Need to copy in the generic ROM.
			NEW_ROM=$VIDEO_ROM
		fi
	fi
	if [ -n "$NEW_ROM" ]
	then
		Writeable $ROMFILE
		if [ $? -ne 0 ]
		then
			usrMsg WARN CANNOT_MAKE \
				"Cannot make $IMG_TAG image." $IMG_TAG
			usrMsg ECHO NO_PERMIS_WRITE \
				"Do not have permission to write $ROMFILE\n" \
				$ROMFILE
			return 1	# problems
		fi
		rm -f $SAVE_ROM
		mv $ROMFILE $SAVE_ROM >> $NULL 2>&1
		cp $NEW_ROM $ROMFILE >> $NULL 2>&1
		if [ $? -ne 0 ]
		then
			usrMsg WARN CANNOT_MAKE \
				"Cannot make $IMG_TAG image." $IMG_TAG
			usrMsg WARN CANNOT_WRITE \
				"Could not write $ROMFILE\n" $ROMFILE
			usrMsg ECHO NO_ROOM "(No more room?)\n"
			rm -f $ROMFILE
			mv $SAVE_ROM $ROMFILE >> $NULL 2>&1
			return 1	# problems
		fi
	fi
	rm -f $RS_FILE

	if [ "$IMG_TYPE" = "ega" -a ! -s ${IMD}/ega.img ]
	then
		# For +aega option, there must be an "ega" image file.
		FAKEEGA=isfake
		cp $DIRECTORY/mono/mono.img ${IMD}/ega.img
	elif [ -n "$NEW_ROM" ]
	then
		# When changing roms, then move the old image aside.
		# Do this because if the image make crashes, we don't want
		# the old image there, because the rom will be mismatched.
		mv ${IMD}/${IMG_TYPE}.img ${IMD}/${IMG_TYPE}.img.sv >>$NULL 2>&1
	fi
	sync
	Check_Room /tmp 400
	if [ $? -ne 0 ]
	then
		usrMsg WARN CANNOT_MAKE \
			"Cannot make $IMG_TAG image." $IMG_TAG
		usrMsg ECHO CREATE_NOROOM \
			"Not enough room to create file /tmp/dos.img\n" \
			/tmp/dos.img
		return 1	# problems
	fi
	if [ -n "$SAVE_VSNAP" ]
	then
		cp $VSNAP /tmp/vsnap.$IMG_TYPE
	fi
	usrMsg ECHO MAKING "Making $IMG_TAG Image.\n" $IMG_TAG
	> /tmp/save_msg.dos 2> /dev/null
	rm -f /tmp/save_msg.dos
	if [ ! -s /tmp/save_msg.dos ]
	then
		MSG_SAVE=/tmp/save_msg.dos
	else
		MSG_SAVE=
	fi
	if [ -n "$NATIVE" ]
	then
		if [ -z "$VISUALMKIMG" ]
		then
			dos +a${IMG_TYPE} $DEV_ATTACH_LIST \
			  +a.40-44,3b0-3df,7c6,b66,fc6..a0000-bffff.,i,no_umb \
			  +aa:=$VSNAP +b +c -e -l$DIRECTORY -p \
			  ver < $CONSOLE >$CONSOLE 2>$CONSOLE
		else
			# Allow the screen to be seen during boot and snap.
			dos +a${IMG_TYPE} $DEV_ATTACH_LIST \
			  +a.40-44,3b0-3df,7c6,b66,fc6..a0000-bffff.,i,no_umb \
			  +aa:=$VSNAP -b +c -e -l$DIRECTORY -p \
			  ver < $CONSOLE >$CONSOLE 2>$CONSOLE
		fi
	else
		if [ -z "$VISUALMKIMG" ]
		then
			dos +a${IMG_TYPE} $DEV_ATTACH_LIST \
				+aa:=$VSNAP +b +c -e -l$DIRECTORY -p \
				ver >$ERR_FILE 2>&1
		else
			# Allow the screen to be seen during boot and snap.
			dos +a${IMG_TYPE} $DEV_ATTACH_LIST \
				+aa:=$VSNAP -b +c -e -l$DIRECTORY -p \
				ver
		fi
	fi
	EXITVAL=$?
	if [ $EXITVAL -ne 0 ]
	then
		usrMsg WARN NOT_MADE "$IMG_TAG image was not made.\n" \
			$IMG_TAG
		usrMsg ECHO INCOMPATABLE \
			"(Incompatable $IMG_TAG card?)\n" $IMG_TAG
		echo "($EXITVAL)" | tee -a $NULL
		if [ -n "$MSG_SAVE" -a -s $MSG_SAVE ]
		then
			cat $MSG_SAVE | tee -a $NULL
		fi
		cat $ERR_FILE 2>> $NULL
		Put_Back
		return 1	# problems
	fi
	if [ -n "$NATIVE" ]
	then
		usrMsg ECHO IMG_MADE "$IMG_TAG image made.\n" $IMG_TAG
	fi

	# Move old image back.
	[ -f ${IMD}/${IMG_TYPE}.img.sv ] && \
		mv ${IMD}/${IMG_TYPE}.img.sv ${IMD}/${IMG_TYPE}.img >>$NULL 2>&1

	rm -f $ERR_FILE
	if [ "$FAKEEGA" = "isfake" ]
	then
		rm -f ${IMD}/ega.img
	fi
	SIZE=`wc -c < /tmp/dos.img`
	if [ $SIZE -lt 10000 ]
	then
		# Image is much too small.
		usrMsg WARN NOT_MADE "$IMG_TAG image was not made.\n" \
			$IMG_TAG
		if [ $SIZE -ne 0 ]
		then
			usrMsg ECHO NO_ROOM "(No more room?)\n"
		fi
		Put_Back
		return 1	# problems
	fi

	# Rename the current image files to ".sv" names, so that can
	# restore them if needed.
	for i in $IMD/${IMG_TYPE}.img
	do
		rm -f $i.sv
		if [ -f $i.sv ]
		then
			usrMsg WARN REMOVE_FAIL \
				"Could not remove file $i.sv\n" $i.sv
			Put_Back
			return 1	# problems
		fi
		[ -f $i ] && mv $i $i.sv
	done

	rm -f /tmp/${IMG_TYPE}.img
	if [ -f /tmp/${IMG_TYPE}.img ]
	then
		usrMsg WARN REMOVE_FAIL \
			"Could not remove file /tmp/${IMG_TYPE}.img\n" \
			/tmp/${IMG_TYPE}.img
		Put_Back
		return 1	# problems
	fi
	mv /tmp/dos.img /tmp/${IMG_TYPE}.img
	
	if [ -f $IMD/umb_????.img ]
	then
		rm -f $IMD/umb_????.img >> $NULL
	fi

	if [ -f $IMD/hma.img ]
	then
		rm -f $IMD/hma.img >> $NULL
	fi

	for i in /tmp/${IMG_TYPE}.img /tmp/umb_????.img /tmp/hma.img
	do
		[ ! -f $i ] && continue
		mv $i $IMD
		BN=`basename $i`
		if [ ! -f $IMD/$BN ]
		then
			usrMsg WARN CANNOT_WRITE \
				"Could not write $IMD/$BN\n" \
				$IMD/$BN
			usrMsg ECHO NO_ROOM "(No more room?)\n"
			Put_Back
			return 1	# problems

		fi
	done

	rm -f $SAVE_ROM
	rm -f /tmp/dos.img
	rm -f /tmp/umb_????.img
	rm -f /tmp/hma.img
	rm -f $IMD/*.img.sv
	rm -f $VSNAP
	dosopt Patch_image_file $IMG_TYPE $IMD/${IMG_TYPE}.img >> $NULL 2>&1
	return 0	# Success
}

# (NOTE: Do NOT nls-ize the copyright lines.  They must be exactly like this.)
# Print ROM copyrights taken from rom/atbase.asm
echo "BIOS V2.09 Copyright 1984, 1985 Award Software Inc."
# Print EMS copyright taken from ems40/locus/oeminit.asm
echo "Quadtel Expanded Memory Manager Copyright(c) 1989, 1990 Quadtel Corp."
if [ -n "$VGAFLAG" -a  -z "$NATIVE" ]
then
	# Print VGA ROM copyrights taken from vga/chip451/oem/oem.asm
	echo "Quadtel 82C451 VGA BIOS Copyright(c) 1987, 1988 Quadtel Corp."
fi
# (NOTE: Do NOT nls-ize this string.  It must be exactly like this.)
echo "All Rights Reserved"

if [ -n "$MDAFLAG" ]
then
	Do_Img MDA mono
	if [ $? -ne 0 ]
	then
		MDAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$CGAFLAG" ]
then
	Do_Img CGA cga
	if [ $? -ne 0 ]
	then
		CGAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$EGAFLAG" ]
then
	Do_Xga EGA ega
	if [ $? -ne 0 ]
	then
		EGAFLAG=""
		PROBLEMS=1
	fi
fi
if [ -n "$VGAFLAG" ]
then
	Do_Xga VGA vga
	if [ $? -ne 0 ]
	then
		VGAFLAG=""
		PROBLEMS=1
	fi
fi

if [ $PROBLEMS -ne 0 ]
then
	if [ -z "$VGAFLAG" -a -z "$EGAFLAG" -a -z "$CGAFLAG" -a -z "$MDAFLAG" ]
	then
		usrMsg WARN NO_IMG_MADE "No image files were made.\n"
	else
		usrMsg WARN SOME_NOT_MADE "Some image files were not made.\n"
	fi
	Exit_Clean 1
fi
Exit_Clean 0
