#! /bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 1999,2019 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#
#* CPRY
#
# sccsid = "@(#)84   1.7   src/rsct/pgs/cmds/nlssrc.sh, gsctrl, rsct_rady, rady2035a 11/12/15 16:45:03"
#*======================================================================
#* Module Name:  nlssrc
#*======================================================================


basecmd="nlssrc"
basepath=/opt/rsct/bin
lssrc_cmd=/usr/bin/lssrc

SPMSG=${basepath}/hadspmsg
MSGMAPPATH=/opt/rsct/msgmaps
export MSGMAPPATH

# process the command lines
if [[ -z $1 ]]; then
   # no arguments
   $SPMSG hagsctrl ha_gs.cat IMsg_nlssrc_Usage $basecmd $basecmd $basecmd $basecmd $basecmd
   exit
fi

args=""
c_opt=""
L_opt=""

#
#NOTE: -L option is not currently unsupported
#
while getopts ":h:g:s:p:alc" opt; do
    case $opt in
	h | s | p )
	    args="$args -${opt} $OPTARG"
	    ;;
        g )
            opt=s
	    args="$args -${opt} $OPTARG"
	    ;;
	a | l )
	    args="$args -${opt}"
	    ;;
	c )
	    c_opt=1
	    ;;
	L )
	    L_opt=1
	    ;;
        * )
	    # ${basecmd}: Not a recognized flag: -${OPTARG}
            $SPMSG hagsctrl ha_gs.cat EMsg_Incorrect_Flag ${basecmd} ${OPTARG}
            $SPMSG hagsctrl ha_gs.cat IMsg_nlssrc_Usage $basecmd $basecmd $basecmd $basecmd $basecmd
	    exit 1
	    ;;
    esac
done

shift $(($OPTIND - 1))

if [[ ! -z $c_opt ]]; then
	# canonical form
	LC_ALL=C exec ${basepath}/${basecmd}_c $args
else
   if [[ ! -z $L_opt ]]; then
	# Using the current locale
   	if [[ -f /usr/bin/locale ]]; then
		LOCALE=`/usr/bin/locale`
	else
		LOCALE=`/bin/locale`
	fi

	# /usr/bin/locale may produce LC_MESSAGES=en_US or LC_MESSAGES="en_US".
	# We use two sed "s" commands, the first one gets rid of LC_MESSAGES=,
	# the second one removes the two surrounding '"' if they are there.
	LOCALE=`echo "$LOCALE" |grep LC_MESSAGES|sed "s/LC_MESSAGES=//;s/\"//g"`
	args="$args -a $LOCALE"
	exec ${basepath}/${basecmd}_nls $args
   else
	# normal lssrc
	exec ${lssrc_cmd} $args
   fi
fi