:	'(c) Copyright	Empress Software Inc.	1983, 2000.'

USAGE="*** Usage ***  $0  : This script is for Empress internal use only"

case "$CNVDB" in
 "")
	echo "$USAGE"
	exit 1
	;;
esac

case "$EMP4GL" in
 no) exit 0 ;;
esac

. $EMPRESSPATH/config/options
 
case "$TESTMODE" in
 yes)
	MSINST_OLDVERS=$TESTOLDVER
	MSINST_OLDVERSPATH=$TESTOLDPATH
	;;
esac

UE_E0_CVV2_INFO1=10150
UE_E0_CVV2_INFO6=10176
UI_E0_COMP4GLAPPL=10063
UI_E0_EMPTYCL=10155
UI_E0_INFOMSG3=10068
UI_E0_INFOMSG=10005
UI_E0_LINK4GLAPPL=10064
UI_E0_NO4GLTABORAPPL=10058

case "$MSINST_OLDVERS" in
 "")    $NLSECHO "
	Sorry, during installation you did not mention that your current version
	of Empress is an upgrade from an older version. You should:
	   change directory to %s, and
	   run the script \'%s\'
	to configure the conversion utilities.
	Aborting.
	" $UE_E0_CVV2_INFO6 $EMPRESSPATH/rdbms empugprd
	exit 1
	;;
esac

case "$MSINST_OLDVERSPATH" in
 "")
	  $NLSECHO "Older version of Empress installation is not valid" $UE_E0_CVV2_INFO1
	  exit 1
	  ;;
esac

: "Test to see if the database contains Empress 4GL system tables"

$EMPRESSPATH/bin/empcmd "$CNVDB" "display sys_4gl_link;" > $TMP 2>&1

if grep "User Error" $TMP > /dev/null 2>&1
then
       	$NLSECHO  "The database does not contain any Empress 4GL \
			tables/applications" $UI_E0_NO4GLTABORAPPL
	rm $TMP
	exit 0
else
	rm $TMP
	case $DATE_FORMAT in
		"") $EMPRESSPATH/bin/empbatch "$CNVDB" <<@
update sys_4gl_field set data_type = "external" where data_type = "char";
@
;;
		*) $EMPRESSPATH/bin/empbatch "$CNVDB" <<@
update sys_4gl_field set data_type = "external" where data_type = "char";
update sys_4gl_field set data_type = "ms date($DATE_FORMAT)" where data_type = "date";
@
;;
	esac

	case "$COMPILE_LINK" in
	  yes)
		$NLSECHO  "
+=============================================================+
|                                                             |
|   If any error occurs while compiling or  linking, you do   |
|   not have to reconvert your database.  Simply proceed to   |
|   correct the error and recompile or relink.                |
|                                                             |
+=============================================================+
" $UI_E0_INFOMSG3
		;;
 	 *)
		exit 0
		;;
	esac	

	$NLSECHO "Cleaning up sys_4gl_compile and sys_4gl_link" $UI_E0_EMPTYCL

	$EMPRESSPATH/bin/empbatch "$CNVDB" <<'@'
empty sys_4gl_compile;
empty sys_4gl_link;
@

	$NLSECHO  "Compiling Empress 4GL applications" $UI_E0_COMP4GLAPPL
	$EMPRESSPATH/bin/emp4gl -c "$CNVDB"

		$NLSECHO  "
+=================================================+
|                                                 |
|   During the conversion, please ignore errors   |
|   concerning the attribute 'return_type'        |
|                                                 |
+=================================================+
" $UI_E0_INFOMSG

	$NLSECHO  "Linking Empress 4GL applications" $UI_E0_LINK4GLAPPL
	$EMPRESSPATH/bin/emp4gl -l "$CNVDB" 
fi
