#!/bin/sh
#
# AbiSuite program wrapper script, dynamically generated
# from abi/src/pkg/common/unix/scripts/makewrapper.sh.

currentFonts=`xset q | grep Abi`
# Change this if you move the AbiSuite tree.
ABISUITE_HOME=/usr/X11R6/share/AbiSuite
export ABISUITE_HOME

# Change this if you move the AbiSuite binaries.
ABISUITE_LIBEXEC=/usr/X11R6/bin

# Change this if you move your fonts.
ABISUITE_FONT_HOME=$ABISUITE_HOME/fonts

# locale-specific dirs could be added to it.
ABISUITE_FONT_PATH=$ABISUITE_FONT_HOME

#now try to guess locale
locale=$LC_ALL	#it's incorrect to set this variable, but someone
		#might set it incorrectly.
if [ -z "$locale" ]
then
    locale=$LANG
elif [ -x $locale ]
then
	locale=$LC_CTYPE
fi

if [ ! -z "$locale" ]
then
	#now guess country/region/encoding
	country=`echo $locale | sed -e 's/\(.*\)_.*$/\1/'`
	region=`echo $locale | sed -e 's/^.*_\(.*\)\..*/\1/'`
    encoding=`echo $locale | sed -e 's/^.*\.\(.*\)$/\1/'`
	if [ ! -z $country -o ! -z $region -o ! -z $encoding ]
    then
	addfontdirlst="$ABISUITE_FONT_HOME/$country $ABISUITE_FONT_HOME/${country}-${region} $ABISUITE_FONT_HOME/$encoding $ABISUITE_FONT_HOME/${country}-${region}.${encoding}"
	for addfontdir in $addfontdirlst
	do
		if [ ! -z $addfontdir ]
		then
		if [ -d $addfontdir -a ! -f $addfontdir/.already-in-fp ]
		then
			#add directory with locale-specific fonts to font path
			ABISUITE_FONT_PATH=$ABISUITE_FONT_PATH,$addfontdir
		fi
		fi
	done
    fi
fi

# Set run-time font path
if [ -d $ABISUITE_FONT_HOME -a -z "$currentFonts" ]
then
    xset fp+ $ABISUITE_FONT_PATH 1>/dev/null 2>/dev/null
fi

# Figure out which binary to run
if [ -f $ABISUITE_LIBEXEC/AbiWord_d ]
then
    $ABISUITE_LIBEXEC/AbiWord_d "$@"
elif [ -f $ABISUITE_LIBEXEC/AbiWord_s ]
then
    $ABISUITE_LIBEXEC/AbiWord_s "$@"
else
    echo ""
    echo "Error: can't find AbiWord executables:"
    echo "    $ABISUITE_LIBEXEC/AbiWord_d"
    echo "    -or-"
    echo "    $ABISUITE_LIBEXEC/AbiWord_s"
    echo ""
    exit
fi

# Check to make sure we don't stomp on anything
if [ -z "$currentFonts" ]
then
    # Set post run-time font path
    if [ -d "$ABISUITE_FONT_HOME" ]
    then
	xset fp- $ABISUITE_FONT_PATH 1>/dev/null 2>/dev/null
	xset fp rehash 1>/dev/null 2>/dev/null
    fi
fi
