:

. $EMPRESSPATH/config/options

getuname ()
{
	FILE=/tmp/guname$$
	RMFILE="rm $FILE"
	cp /dev/null $FILE

	set -- `ls -l $FILE`
	NAME="$3"

	$RMFILE

	echo "$NAME"
}

case $1 in
 -remote)
	shift
	SERVER_NODE=$1
	;;
 *)
	PATH="$PATH:/etc:/bin:/usr/bin:/usr/ucb"
	if (hostname) > /dev/null 2>&1
	then
		SERVER_NODE=`hostname`
	else
		SERVER_NODE=`uname -n`
	fi
	;;
esac

case $SERVER_NODE in
 "")
	echo "The host name of the Empress ODBC Server is not specified."
	exit 1
	;;
esac



MSDSNNAME=empress
TESTDB="testdb"
MSOPORTNO=6322
MSOSERVER=`$EMPRESSPATH/common/sys_bin/sysuname`

SYSTEM=`uname -a`

case "$SYSTEM" in
  *Win*)
	########################
	# Data Source variables:
	########################

	. $EMPRESSPATH/win32/_util/getodbc_info

	DriverName="$PRODUCT_NAME"
	DefaultPWD=""
	DefaultUID=""
	Description="Empress example odbccl test database"
	Driver="$SYSTEMROOT\system32\\$ODBC_DLLNAME"
	ODBCLevel="2"
        ODBCVersion="3.51"
	CodeSet="US-ASCII"
	TraceFile=""
	TraceLevel="0"

	here="`pwd`"

        # Win32 ODBC manager accesses datasource through
        # ODBC.INI file (stored into the Registry).

        #echo "Updating Registry for ODBC.INI ..."
        regSetKey="$EMPRESSPATH/odbccl/local/win32/regSetKey"

	# Create 1st data source in the Registry
        H="HKEY_CURRENT_USER\\Software\\ODBC\\ODBC.INI\\$MSDSNNAME"
        $regSetKey "$H" "Codeset"     "$CodeSet"      "$here"
        $regSetKey "$H" "Database"    "$TESTDB"      "$here"
        $regSetKey "$H" "DefaultPWD"  "$DefaultPWD"   "$here"
        $regSetKey "$H" "DefaultUID"  "$DefaultUID"   "$here"
        $regSetKey "$H" "Description" "$Description"  "$here"
        $regSetKey "$H" "Driver"      "$Driver"       "$here"
        $regSetKey "$H" "ODBCLevel"   "$ODBCLevel"    "$here"
        $regSetKey "$H" "ODBCVersion" "$ODBCVersion"  "$here"
        $regSetKey "$H" "Port"        "$MSOPORTNO"    "$here"
        $regSetKey "$H" "Server"      "$MSOSERVER"    "$here"
        $regSetKey "$H" "TraceFile"   "$TraceFile"    "$here"
        $regSetKey "$H" "TraceLevel"  "$TraceLevel"   "$here"

        H="HKEY_CURRENT_USER\\Software\\ODBC\\ODBC.INI\\ODBC Data Sources"
        $regSetKey "$H" "$MSDSNNAME" "$PRODUCT_NAME" "$here"


	#echo "\nReplacing $Server's original $ODBC_DLLNAME ..."
	SYSDIR="$SYSTEMROOT/system32"
	if test -f $EMPRESSPATH/odbccl/lib/$ODBC_DLLNAME
	then
		if test ! -f $SYSDIR/${ODBC_DLLNAME}.installed
		then
			test -f $SYSDIR/$ODBC_DLLNAME && \
			mv $SYSDIR/$ODBC_DLLNAME $SYSDIR/${ODBC_DLLNAME}.installed
		fi
		cp $EMPRESSPATH/odbccl/lib/$ODBC_DLLNAME $SYSDIR
		$EMPRESSPATH/odbccl/local/win32/regInsOdbc
        fi
        ;;
  *)
	cat > odbc.ini <<EOM
[$MSDSNNAME]
Server = $SERVER_NODE
Port = $MSOPORTNO
Database = $TESTDB
EOM
	;;
esac


ME=`$EMPRESSPATH/common/sys_bin/getuname`

$EMPRESSPATH/bin/empocc -DLOGINNAME=\"$ME\" -o example example.c
./example > testout 2>&1

if cmp -s stdout testout
then
	cat <<EOM

	The program 'example' provides the expected result.
	The example program works correctly.

EOM
elif test "$MSSYS_PLATFORM" = "SYS_OS_WIN32" && \
        diff stdout.win32 testout > $MSFILENULL
then
	cat <<EOM

	The program 'example' provides the expected result.
	The example program works correctly (under Win32).

EOM
else
	cat <<EOM

	The program 'example' does not provide the exact result.

EOM
fi
