#!/bin/sh
#* ----------------------------------------------------------------------
#*               Proprietary and Confidential Information
#*
#* This material contains, and is part of a computer software program
#* which is, proprietary and confidential information owned by COMPUTER
#* ASSOCIATES INTERNATIONAL, INC.  The program, including this material,
#* may not be duplicated, disclosed or reproduced in whole or in part for
#* any purpose without the express written authorization of COMPUTER
#* ASSOCIATES. All authorized reproductions must be marked with this
#* legend.
#*
#*                          Copyright (c) 1992-2005
#*             Computer Associates International, Incorporated
#*                          All rights reserved
#*
#* ----------------------------------------------------------------------
#*  SCCS Module Control Stamp
#* ----------------------------------------------------------------------
#
#* "@(#)lcl_echo_func	1.31  08/26/05 08:10:28"
#* "Copyright (C) 1992-2005 Computer Associates International, Inc.  All rights reserved."
#
#

#
#
#+----------------------------------------------------------------------------+
#|                                                                            |
#| Function:    lcl_echo()                                                    |
#|                                                                            |
#| Description: Displays a portion of the generated language text file.       |
#|                                                                            |
#| Input:       $1 = The "key".                                               | 
#|                                                                            |
#|                   The key is used by appending a _B for the beginning      |
#|                   marker, and a _E for the ending marker.  For example:    |
#|                                                                            |
#|                   key=TEST_KEY                                             |
#|                   beginning marker=TEST_KEY_B                              | 
#|                   ending marker   =TEST_KEY_E                              |
#|                                                                            |
#|              $2 = The file where the text is located. (NOT FULL PATH)      |
#|              $3 = (Optional) The component which is calling lcl_echo.                 |
#|                   (example secu, sche, opr, cal, ...)                      |
#|              $4 = (Optional) the name of the file to send the output to.   |
#|                                                                            |
#| Output:      The text in between the beginning and ending keys             |
#|              is sent to stdout (terminal).                                 |
#+----------------------------------------------------------------------------+
lcl_echo()
{

   if [ "$#" -lt 2 ];then
	  return
   fi

   if [ -z "$CASHCOMP" ];then
		$ECHO "CASHCOMP is not set. Exiting.."
		exit 100
   fi

   test -r "$CASHCOMP/csutils/scripts/calocale" && . "$CASHCOMP/csutils/scripts/calocale"

   [ -z "$CA_CAILANGUAGE" ] && CA_CAILANGUAGE=enu

   if [ -f "$CASHCOMP/csutils/scripts/$2_$CA_CAILANGUAGE.lcl" ];then

     lcl_file="$CASHCOMP/csutils/scripts/$2_$CA_CAILANGUAGE.lcl"
     if [ ! -f "$lcl_file" ];then
        if [ -f "$CASHCOMP/csutils/scripts/$2_enu.lcl" ];then
           lcl_file="$CASHCOMP/csutils/scripts/$2_enu.lcl"
        else
           $ECHO "Unable to locate lcl translation file: $2_$CA_CAILANGUAGE.lcl"
                   return
        fi
     fi

   elif [ -f "$CASHCOMP/ccs/common/scripts/$2_$CA_CAILANGUAGE.lcl" ]; then

     lcl_file="$CASHCOMP/ccs/common/scripts/$2_$CA_CAILANGUAGE.lcl"
     if [ ! -f $lcl_file -a -f "$2_$CA_CAILANGUAGE.lcl" ];then
        lcl_file="$2_$CA_CAILANGUAGE.lcl"
     elif [ ! -f $lcl_file ];then
        if [ -f "$CASHCOMP/ccs/common/scripts/$2_enu.lcl" ];then
           lcl_file="$CASHCOMP/ccs/common/scripts/$2_enu.lcl"
        else
           $ECHO "Unable to locate lcl translation file: $2_$CA_CAILANGUAGE.lcl"
		   return
        fi
     fi

   elif [ -f "$CANSM/scripts/$2_$CA_CAILANGUAGE.lcl" ];then

     lcl_file="$CANSM/scripts/$2_$CA_CAILANGUAGE.lcl"
     if [ ! -f "$lcl_file" ];then
        if [ -f "$CANSM/scripts/$2_enu.lcl" ];then
           lcl_file="$CANSM/scripts/$2_enu.lcl"
        else
           $ECHO "Unable to locate lcl translation file: $2_$CA_CAILANGUAGE.lcl"
                   return
        fi
     fi

   elif [ -f "$CASHCOMP/ccs/$3/scripts/$2_$CA_CAILANGUAGE.lcl" -o -f "$CASHCOMP/ccs/$3/scripts/$2_enu.lcl" ];then
	
	 lcl_file="$CASHCOMP/ccs/$3/scripts/$2_$CA_CAILANGUAGE.lcl"	
     if [ ! -f "$lcl_file" ];then
        if [ -f "$CASHCOMP/ccs/$3/scripts/$2_enu.lcl" ];then
           lcl_file="$CASHCOMP/ccs/$3/scripts/$2_enu.lcl"
        else
           $ECHO "Unable to locate lcl translation file: $2_$CA_CAILANGUAGE.lcl"
                   return
        fi
     fi
   elif [ -f "$2_$CA_CAILANGUAGE.lcl" -o -f "$2_enu.lcl" ];then
	if [ -f "$2_$CA_CAILANGUAGE.lcl" ];then
		lcl_file="$2_$CA_CAILANGUAGE.lcl"
	elif [ -f "$2_enu.lcl" ];then
		lcl_file="$2_enu.lcl"
	fi
   elif [ -n "${PIF_PREINSTALL_DIR}" ];then
	
		test -r ${PIF_PREINSTALL_DIR}/ca-cs-utils-cmp.d/\$CASHCOMP/calocale && . ${PIF_PREINSTALL_DIR}/ca-cs-utils-cmp.d/\$CASHCOMP/calocale
		[ -z "$CA_CAILANGUAGE" ] && CA_CAILANGUAGE=enu

		lcl_file="$PIF_PREINSTALL_DIR/scripts/$2_$CA_CAILANGUAGE.lcl"
		 if [ ! -f "$lcl_file" ];then
			if [ -f "$PIF_PREINSTALL_DIR/scripts/$2_enu.lcl" ];then
			   lcl_file="$PIF_PREINSTALL_DIR/scripts/$2_enu.lcl"
			else
			   $ECHO "Unable to locate lcl translation file: $2_$CA_CAILANGUAGE.lcl"
					   return
			fi
		 fi
   else
	 if [ "$3" != "" ];then
		 lcl_file="$CASHCOMP/ccs/$3/scripts/$2_$CA_CAILANGUAGE.lcl"
		 if [ ! -f $lcl_file -a -f "$2_$CA_CAILANGUAGE.lcl" ];then
			lcl_file="$2_$CA_CAILANGUAGE.lcl"
		 elif [ ! -f $lcl_file ];then
			if [ -f "$CASHCOMP/ccs/$3/scripts/$2_enu.lcl" ];then
			   lcl_file="$CASHCOMP/ccs/$3/scripts/$2_enu.lcl"
			else
				if [ -f "$CASHCOMP/ccs/common/scripts/$2_enu.lcl" ];then
					lcl_file="$CASHCOMP/ccs/common/scripts/$2_enu.lcl" 
				else	
					$ECHO "Unable to locate lcl translation file: $2_$CA_CAILANGUAGE.lcl"
					return
				fi
			fi
		 fi
	 else
		$ECHO "Unable to locate lcl translation file $2_$CA_CAILANGUAGE.lcl"
		return
	 fi
   fi
      
   if [ -x /usr/bin/nawk ]
   then AWK=nawk
   else AWK=awk
   fi
   (
   test -n "$4" && exec >$4
   exec $AWK '
	$1 ~ key "_B$" { begun = 1; next }
	$1 ~ key "_E$" { ended = 1; exit }
	begun == 1 { print }
	END {
		if (!begun) print "Invalid key:", key "_B File:", FILENAME
		if (!ended) print "Invalid key:", key "_E File:", FILENAME
	}
   ' key=$1 $lcl_file
   )
}

# Setup ECHO and options
if [ -x "$CASHCOMP/csutils/bin/casystyp" ];then
	os="`$CASHCOMP/csutils/bin/casystyp`"
else
	os="`uname`"
fi

if [ "$os" = "Linux" ];then
   ECHO="echo -e"
else
   ECHO="echo"
fi

# setup UNCOMPRESS
UNCOMPRESS=`type uncompress 2> /dev/null | awk '{ print $3 }'`
if [ `uname` = "Linux" -a "$UNCOMPRESS" = "" -o "$UNCOMPRESS" = "found." ];then
   UNCOMPRESS=`type gunzip 2>/dev/null | awk ' { print $3 }'`
   if [ `uname` = "Linux" -a "$UNCOMPRESS" = "" -o "$UNCOMPRESS" = "found." ];then
      lcl_echo \.uncompress_not_found_exiting setup release
      exit 4
   fi
fi

# If ca_read script is available then read from here otherwise
# use system generated functions
if [ -f $CASHCOMP/csutils/bin/ca_read ];then
 . $CASHCOMP/csutils/bin/ca_read
elif [ -f ./ca_read ];then
 . ./ca_read
fi

