: '
: *************************************************************************
:
:			   INFORMIX SOFTWARE, INC.
: 
:			      PROPRIETARY DATA
: 
:	THIS DOCUMENT CONTAINS TRADE SECRET DATA WHICH IS THE PROPERTY OF 
:	INFORMIX SOFTWARE, INC.  THIS DOCUMENT IS SUBMITTED TO RECIPIENT IN
:	CONFIDENCE.  INFORMATION CONTAINED HEREIN MAY NOT BE USED, COPIED OR 
:	DISCLOSED IN WHOLE OR IN PART EXCEPT AS PERMITTED BY WRITTEN AGREEMENT 
:	SIGNED BY AN OFFICER OF INFORMIX SOFTWARE, INC.
:
:	THIS MATERIAL IS ALSO COPYRIGHTED AS AN UNPUBLISHED WORK UNDER
:	SECTIONS 104 AND 408 OF TITLE 17 OF THE UNITED STATES CODE. 
:	UNAUTHORIZED USE, COPYING OR OTHER REPRODUCTION IS PROHIBITED BY LAW.
:
:
:   Title:	finderr
:   Description: finderr scans the ascii file $INFORMIXDIR/msg/errmsg.txt
:	and copies the text of one or more error messages to standard output.
:
: *************************************************************************
: '
# The following variable is for porting
# Please set '1' if sed program of the platform supports the Locale
# specific codeset and set '0' if the sed does't support the codeset.
LCSED=1

# The following variables define the upper limit of + and - message numbers,
# as documented in the errmsg.txt file.

PLUSLIMIT=71572
MINUSLIMIT=55933

INFDIR=${INFORMIXDIR-/usr/informix}
INTLMSGDIR="en_us/0333"
EF="errmsg.txt"

# make sure we have arguments, give usage if not
case $# in
    0)
	# Print usage message
	infxmsg 33510
	exit 1
esac

# Now find the english errmsg.txt -- pathname variable EEP

if test -s ${INFDIR}/msg/${INTLMSGDIR}/${EF}
then EEP=${INFDIR}/msg/${INTLMSGDIR}/${EF}
elif test -s ${INFDIR}/msg/english/${EF}
then EEP=${INFDIR}/msg/english/${EF}
else EEP=""
fi

# find localized errmsg.txt if both of LCSED is 1

if test "$LCSED" = "1"
then
    EP=`msgfile $EF`
else
    EP=$EEP
fi

# Error if no errmsg.txt is found

if test "$EP" = ""
then
    infxmsg -33512 $EF
    exit 2
fi

# Function to extract message info from errmsg.txt file

tmp=/tmp/fe$$
tmpa=/tmp/fe$$a

geterr()
{
  # Use sed to extract all lines for the specified message, if it exists.
  # Note that there can be more than one entry for each message.

  grep -n "^$1 *	" $2 | sed "s@:@	@" > $tmp
  if test -s $tmp
  then
      if test `cat $tmp | wc -l` -eq 1
      then
          sed -n "/^$1 *	/,/^[-]*[0-9][0-9]* *	/p" $2 | sed '$d'
      else
	  cat /dev/null > $tmpa
	  while read flno msgnum msgtxt
	  do
	      sed -n "$flno,/^[-]*[0-9][0-9]* *	/p" $2 | sed '$d' >> $tmpa
	  done < $tmp
          cat $tmpa
      fi
      rm -f $tmp $tmpa
      return 0
  else 
      return 1
  fi
}
ec=0
while true ; do

  case $1 in
     -v|-V)     sed -n "1,/^#/p" $EP | sed '$d'
		exit
		;;
    [0-9]*)     if test "`echo $1 | tr -d \"+\-0123456789\"`" != ""
                then # echo argument $1 is non-numeric
		     infxmsg -33514 $1
		     exit 3
                fi
		N1=-$1 
                if expr $N1 \< -$MINUSLIMIT > /dev/null
		then # echo "$N1 is outside the range of documented messages."
		     infxmsg -33513 $N1
		     exit 1
		fi
		;;
    -[0-9]*)     if test "`echo $1 | tr -d \"+\-0123456789\"`" != ""
                then # echo argument $1 is non-numeric
		     infxmsg -33514 $1
		     exit 3
                fi
		N1=$1
		if expr $N1 \< -$MINUSLIMIT > /dev/null
		then # echo "$N1 is outside the range of documented messages."
		     infxmsg -33513 $N1
		     exit 1
                fi
		;;
    +[0-9]*)     if test "`echo $1 | tr -d \"+\-0123456789\"`" != ""
                then # echo argument $1 is non-numeric
		     infxmsg -33514 $1
		     exit 3
                fi
		N1=`echo $1 | tr -d "+"`
		if expr $N1 \> $PLUSLIMIT > /dev/null
		then # echo "$N1 is outside the range of documented messages."
		     infxmsg -33513 $N1
		     exit 1
                fi
		;;
   "")          break;;
   *)           # echo "argument ($1) is not numeric."
		infxmsg -33514 $1
                exit 3;;
  esac

  geterr $N1 $EP
  if test $? -ne 0
  then
      # echo "Message $N1 not found"
      infxmsg -33515 $N1
      ec=1
  fi
  shift

done

rm -f $tmp $tmp.bak
exit $ec


