# (This really has to be written in perl, but...)
#
# A small hack to show the power of shell scripts. -ot.95-11 Publ.Dom.

# Given the parameters $msgdir, $msgname, $msgvers, this loads the
# required message base file (for $LANG if available). Then the
# shell function MSG will be available:
# MSG $1 $2 - display message no. $1 from the message base.
# Any "%1" in the message will be replaced by $2.
# The format of the message base files is documented in "mbc".
# The name is ${msgname}.${LANG}.msg or ${msgname}.msg.

# The displaying function
MSG () {
       n=$1
       a=`echo $msglines | sed -n -e 's/^.*\.'$n'\.\([0-9,]*\).*$/\1/p'`
       sed -n "$a p" $msgfile | sed "s:%1:$2:g"
}

# Find the right message base file
msgfile=$msgdir/$msgname.$LANG.msg
[ -r $msgfile ] || {
       msgfile=$msgdir/$msgname.msg
       [ -r $msgfile ] || {
               echo "No message file for $msgname"
               exit 1
       }
}
# Check if the file has the right format
set `grep '^\.:' $msgfile | tr ':' ' '`
[ "$2" = "$msgname" -a "$3" = "$msgvers" -a "$4" = "C" ] || {
       echo "$msgfile: Format error"
       exit 1
}
# Load the index line
msglines=`grep '^\.[0-9]' $msgfile`

