#! /bin/sh

# invoke xterm in UTF-8 mode

# configure font to be used with an X resource entry 
# (typically in $HOME/.Xdefaults),
# e.g. one of:
#! 10x20 is a nice big font for use with Unicode terminal
#UXTerm*font:	10x20
#! 9x18 is a little bit spindly but needed for double-width Han range
#UXTerm*font:	9x18

# retrieve X font resource for class UXTerm and use it if available;
# this should actually be achieved with -class UXTerm instead, 
# but due to an xterm bug, -e is ignored when -class is used, 
# so uterm wouldn't work with umined;
# fixed with xterm 162
xtermversion=`xterm -version | sed -e 's,.*(\([0-9]*\)).*,\1,' -e t -e d`
if [ 0$xtermversion -ge 162 ]
then	uresources="-class UXTerm"
else	# work-around for buggy xterm that ignores -e when -class is present
	# also for xterm that understands neither -version nor -class 
	# (e.g. SunOS /usr/openwin/bin/xterm)
	uresources=`
		xrdb -query |
		sed -e ': start' -e '/\\$/ b cont' -e b -e ': cont' -e N -e 'b start' |
		sed -e "s,^UXTerm\(.*\),-xrm 'XTerm\1'," -e t -e d
	`
fi


# modify locale environment to inform about UTF-8 mode:
case "$LC_ALL" in
?*)	LC_ALL=`echo $LC_ALL | sed -e "s,\..*,,"`.UTF-8;;
*)	LC_CTYPE=`echo $LC_CTYPE | sed -e "s,\..*,,"`.UTF-8
	export LC_CTYPE;;
esac

# set application-specific environment variables:
LESSCHARSET=utf-8	# used by older less version to select UTF-8 display
export LESSCHARSET

eval exec xterm -u8 $uresources "$@"
