:
# 
# $Header: oerr.sh 6.14 92/07/09 10:43:55 tpopovic Osd<unix> $ oerr.sh Copyr (c) 1988 Oracle
# 

# 
# Usage: oerr facility error
#
# This shell script is used to get the description and the cause and action
# of an error from a message text file when a list of error numbers are passed
# to it.  It supports different lauguage environments and errors from different
# facilities.
#

if [ "$ORACLE_TRACE" = "T" ]; then
	set -x
fi

if [ "$#" != "2" ]; then
	echo "Usage: $0 facility error"
	echo ""
	echo "Facility is identified by the letter prefix in the error number."
	echo "For example, if you get ORA-7300, \"ora\" is the facility and"
	echo "\"7300\" is the error.  So you should type \"oerr ora 7300\"."
	echo "If you get LCD-111, type \"oerr lcd 111\", and so on."
	echo ""
	exit 
fi

# 
# If ORACLE_HOME is not set, we will not be able to locate
# the message text file.
#
if [ ! "$ORACLE_HOME" ]; then
	echo "ORACLE_HOME not set!"
	echo "Please set ORACLE_HOME and try again."
	exit 1
fi

FAC=`echo $1 | tr [A-Z] [a-z]`
case $FAC in
	ora)
		PRODUCT=rdbms
		;;
	dba)
		PRODUCT=rdbms
		;;
	exp)
		PRODUCT=rdbms
		;;
	imp)
		PRODUCT=rdbms 
		;;
	lcd)
		PRODUCT=rdbms
		;;
	iac)
		PRODUCT=forms
		;;
	iad)
		PRODUCT=forms
		;;
	iap)
		PRODUCT=forms
		;;
	iag)
		PRODUCT=forms
		;;
	typ)
		PRODUCT=forms
		;;
	srw)
		PRODUCT=sqlreport
		;;
	cgen)
		PRODUCT=cgen
		FAC=cgu
		;;
	cgen20)
		PRODUCT=cgen20
		FAC=cgu
		;;
	tns)
	 	PRODUCT=network
		FAC=tns
		;;
	nl)
                PRODUCT=network
		FAC=nl
		;;
	snl)
		PRODUCT=network
		FAC=snl
		;;
	*)	
		echo $0: Unknown facility: $1
		exit 1
		;;
esac

#
#  Below we map the language to the proper lang key. e.g. for German
#  we map to 'd' so that the NLS msg files will end in d.msg
#
#    filename      Lang.
#   ---------      -------
#  
#     d.msg	   German
#    dk.msg        Danish
#     e.msg	   Spanish
#     f.msg	   French
#     i.msg	   Italian
#     n.msg	   Norwegian
#    nl.msg	   Dutch
#     s.msg	   Swedish
#    sf.msg	   Finnish
#    us.msg	   English
#  
#    el.msg	   Greek
#    pt.msg	   Portuguese
#    ptb.msg	   Brazilian Portuguese
#    tr.msg	   Turkish
#  
#    cs.msg	   Czech
#    hu.msg	   Hungarian
#    pl.msg	   Polish
#    ru.msg	   Russian
#    sk.msg	   Slovak
#  

LANGUAGE=`echo $LANGUAGE | tr [A-Z] [a-z]`
case $LANGUAGE in
	german*)		LANGUAGE=d ;;
	danish*)		LANGUAGE=dk ;;
	spanish*)		LANGUAGE=e ;;
	french*)		LANGUAGE=f ;;
	italian*)		LANGUAGE=i ;;
	norwegian*)		LANGUAGE=n ;;
	dutch*)			LANGUAGE=nl ;;
	swedish*)		LANGUAGE=s ;;
	finnish*)		LANGUAGE=sf ;;
	us*|english*)		LANGUAGE=us ;;

	greek*)			LANGUAGE=el ;;
	portuguese*)		LANGUAGE=pt ;;
	#
	#>>> the following line allows the user to type 3 different inputs
	#    to select Brazilian Portuguese since it is composed of 2 words. 
	brazilian*|brazilian-portuguese*|"brazilian portuguese"*) LANGUAGE=ptb ;;
	turkish*)		LANGUAGE=tr ;;

	czech*)			LANGUAGE=cs ;;
	hungarian*)		LANGUAGE=hu ;;
	polish*)		LANGUAGE=pl ;;
	russian*)		LANGUAGE=ru ;;
	slovak*)		LANGUAGE=sk ;;

	*)			LANGUAGE=us ;;
esac

ERRFILE=$ORACLE_HOME/$PRODUCT/mesg/${FAC}${LANGUAGE}.msg

if [ -r $ERRFILE ]
then
	shift
	for ERR in $*
	do
		awk "BEGIN	{ FOUND=0; }
		/^0*${ERR},/ 	{ FOUND=1; print ; next;}
		/^\/\//		{ if (FOUND)
				  {
					print 
					next
				  }
	   			  else
					next;
				}
				{ if (FOUND)
					exit;
				   else
					next;
				} " $ERRFILE

	done
else
	echo Cannot find $ERRFILE file.
fi
