#
# Try to autodetect UTF-8 capable terminal line
#
where testutf8 > /dev/null
if ( $? == 0 ) then
    testutf8
    set ret="$?"
    if ( ${?LANG} ) then
	if      ( $ret == 2 ) then
	    switch ($LANG)
	    case POSIX:
	    case *.UTF-8:
		breaksw
	    default:
		setenv LANG `echo ${LANG}|sed 's/[\.@].*//'`.UTF-8
		breaksw
	    endsw
	else if ( $ret == 1 ) then
	    switch ($LANG)
	    case *.UTF-8:
		setenv LANG `echo ${LANG}|sed 's/[\.@].*//'`
		breaksw
	    default:
		breaksw
	    endsw
	endif
    endif
    foreach lc (LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE		\
		LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME	\
		LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT		\
		LC_IDENTIFICATION LC_ALL)
	eval set val=\${\?$lc}
	if ( $val == 0 ) continue
	eval set val=\$$lc
	if      ( $ret == 2 ) then
	    switch ($val)
	    case POSIX:
	    case *.UTF-8:
		breaksw
	    default:
		eval setenv \$lc `echo ${val}|sed 's/[\.@].*//'`.UTF-8
		breaksw
	    endsw
	else if ( $ret == 1 ) then
	    switch ($val)
	    case *.UTF-8:
		eval setenv \$lc `echo ${val}|sed 's/[\.@].*//'`
		breaksw
	    default:
		breaksw
	    endsw
	endif
    end
    unset ret lc val
    setenv LANG $LANG
endif
