#! /usr/bin/sh
#
# Message utility to view messages from Palladium
#
##########################################################################
# COPYRIGHT:
#    5765-273 (C) COPYRIGHT IBM CORPORATION 1995.
#    All Rights Reserved.
#    Licenced Materials - Property of IBM
#
#    US Government Users Restricted Rights - Use, duplication, or
#    disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
##########################################################################
ME=$(basename $0)

if [[ "$PDBASE" = "" && -r /etc/rc.config.d/pd ]]
then
   . /etc/rc.config.d/pd
   export PATH=$PATH:/opt/pd/bin:/opt/pd/lbin
   export PDBASE=/var/opt/pd

   # Default the HPDPS locale to C.

   temp_lang=""

   if [[ -n "$LC_MESSAGES" ]]
   then
      temp_lang="$LC_MESSAGES"

   elif [[ -n "$LC_ALL" ]]
   then
      temp_lang="$LC_ALL"

   elif [[ -n "$LANG" ]]
   then
      temp_lang="$LANG"
   fi

   if [[ -z "$temp_lang" ]]
   then
      temp_lang="C"
      export LANG="C"
   fi

   if [[ "$temp_lang" = "C" ]]
   then
      export NLSPATH=/opt/pd/lib/nls/msg/C/%N
   else
      export NLSPATH=/opt/pd/lib/nls/msg/%L/%N:/opt/pd/lib/nls/msg/C/%N
   fi
fi

readonly PD_MSG_DESC_CATALOG="fpahelp.cat"
readonly PD_MSG_TEXT_CATALOG="fpa.cat"

readonly INSERT="________"


usage()
{
        IFS=
        msg=`dspmsg $PD_MSG_TEXT_CATALOG 10 438`
        echo
        echo $msg
        echo
        exit 1;
}

NO_TEXT=0
NO_DESC=0
while getopts dt i
do
        case $i in
                d)      NO_TEXT=1
                        ;;
                t)      NO_DESC=1
                        ;;
                \?)     usage
                        ;;
        esac
done

shift `expr $OPTIND - 1`

if [ $# -ne 1 ] ; then
        usage
fi

IFS=-

# Check for syntactically valid message number
if [[ $1 != 5010$IFS[[:digit:]]?([[:digit:]])?([[:digit:]])?([[:digit:]]) ]] 
then
   if [[ $1 != ?(0)42[0-9]$IFS[[:digit:]]?([[:digit:]])?([[:digit:]]) ]] ; then
           usage
   fi
fi

# Set the description and text catalog names
if [[ $1 != ?(0)42[0-9]$IFS[[:digit:]]?([[:digit:]])?([[:digit:]]) ]] ; then
   DESC_CATALOG=$PD_MSG_DESC_CATALOG
   TEXT_CATALOG=$PD_MSG_TEXT_CATALOG
fi
if [[ $NO_TEXT = 1 ]] ; then
   TEXT_CATALOG=
fi
if [[ $NO_DESC = 1 ]] ; then
   DESC_CATALOG=
fi

set -A msg_num $1

IFS=

(( msg_set = 10 + (${msg_num[1]} / 1000) ))
(( msg_num[1] = ${msg_num[1]} - (${msg_num[1]} / 1000 * 1000) ))

ERROR_MSG="$ME:  Unable to access message catalog $TEXT_CATALOG"

        for i in $TEXT_CATALOG $DESC_CATALOG
        do
                if [[ "$i" = "$PD_MSG_TEXT_CATALOG" ]] ; then

                   msg=`dspmsg $i ${msg_set}  ${msg_num[1]} 2> /dev/null`

		   if [ $? = 0 ]
		   then
                       echo
                       echo $msg
                       echo
                   else
                       echo
                       echo "$ME: Unable to access message catalog $i, set ${msg_set}, message number ${msg_num[1]} "
                       echo
		       exit 1
                   fi
                else
                   msg=`dspmsg $i ${msg_set}  ${msg_num[1]} 2> /dev/null `
		   if [ $? = 0 ]
		   then
                       echo
		       echo $msg
                       echo
		   else
                       echo
                       echo "$ME: Unable to access message catalog $i, set ${msg_set}, message number ${msg_num[1]} "
                       echo
		       exit 1
		   fi
                fi

        done

exit 0
#
#    Version      Date     Time    Owner   Comment
# ------------- -------- -------- -------- ----------------------------
# V             10/10/94 11:04:17 root     Original version
# V             10/10/94 11:05:09 hlava    Original version
# V1.2          10/28/94 10:24:43 dennison Modify copyright info
# V1.3          02/13/95 08:34:55 hlava    Use pdmsghlp to handle Pd-unique inserts
