1 1.1 mrg #!/bin/sh 2 1.1 mrg # $XTermId: koi8rxterm,v 1.3 2007/12/30 16:33:06 tom Exp $ 3 1.1 mrg # This is a wrapper script to set up xterm with a KOI8-R locale; based on 4 1.1 mrg # uxterm. 5 1.1 mrg 6 1.1 mrg whoami=koi8rxterm 7 1.1 mrg 8 1.1 mrg : ${XTERM_PROGRAM=xterm} 9 1.1 mrg 10 1.1 mrg # Check if there is a workable locale program. If there is not, we will read 11 1.1 mrg # something via the standard error. Ignore whatever is written to the 12 1.1 mrg # standard output. 13 1.1 mrg locale=`sh -c "LC_ALL=C LC_CTYPE=C LANG=C locale >/dev/null" 2>&1` 14 1.1 mrg found=no 15 1.1 mrg 16 1.1 mrg # Check for -version and -help options, to provide a simple return without 17 1.1 mrg # requiring the program to create a window: 18 1.1 mrg if test $# = 1 19 1.1 mrg then 20 1.1 mrg case $1 in 21 1.1 mrg -v|-ver*|-h|-he*) 22 1.1 mrg $XTERM_PROGRAM "$@" 23 1.1 mrg exit $? 24 1.1 mrg ;; 25 1.1 mrg esac 26 1.1 mrg fi 27 1.1 mrg 28 1.1 mrg # Check environment variables that xterm does, in the same order: 29 1.1 mrg for name in LC_ALL LC_CTYPE LANG 30 1.1 mrg do 31 1.1 mrg eval 'value=$'$name 32 1.1 mrg if test -n "$value" ; then 33 1.1 mrg case $value in 34 1.1 mrg *.koi8r|*.KOI8R|*.koi8-r|*.KOI8-R) 35 1.1 mrg found=yes 36 1.1 mrg ;; 37 1.1 mrg *.koi8r@*|*.KOI8R@*|*.koi8-r@*|*.KOI8-R*) 38 1.1 mrg found=yes 39 1.1 mrg ;; 40 1.1 mrg *) 41 1.1 mrg # The user may not have configured his or her 42 1.1 mrg # locale; try to muddle through anyway. 43 1.1 mrg value=ru_RU.KOI8-R 44 1.1 mrg ;; 45 1.1 mrg esac 46 1.1 mrg break 47 1.1 mrg fi 48 1.1 mrg done 49 1.1 mrg 50 1.1 mrg # If we didn't find one that uses KOI8-R, modify the safest one. Not everyone 51 1.1 mrg # has a KOI8-R locale installed (and there appears to be no trivial/portable 52 1.1 mrg # way to determine whether it is, from a shell script). We could check if the 53 1.1 mrg # user's shell does not reset unknown locale specifiers, but not all shells do. 54 1.1 mrg if test $found != yes ; then 55 1.1 mrg if test -n "$value" ; then 56 1.1 mrg value=`echo ${value} |sed -e 's/[.@].*//'`.KOI8-R 57 1.1 mrg else 58 1.1 mrg name="LC_CTYPE" 59 1.1 mrg value="ru_RU.KOI8-R" 60 1.1 mrg fi 61 1.1 mrg eval save=\$${name} 62 1.1 mrg eval ${name}=${value} 63 1.1 mrg eval export ${name} 64 1.1 mrg if test -z "$locale" ; then 65 1.1 mrg # The 'locale' program tries to do a sanity check. 66 1.1 mrg check=`sh -c "locale >/dev/null" 2>&1` 67 1.1 mrg if test -n "$check" ; then 68 1.1 mrg eval ${name}=${save} 69 1.1 mrg eval export ${name} 70 1.1 mrg 71 1.1 mrg echo "$whoami tried to use locale $value by setting \$$name" >&2 72 1.1 mrg xmessage -file - <<EOF 73 1.1 mrg $whoami tried unsuccessfully to use locale $value 74 1.1 mrg by setting \$$name to "${value}". 75 1.1 mrg EOF 76 1.1 mrg exit 1 77 1.1 mrg fi 78 1.1 mrg fi 79 1.1 mrg fi 80 1.1 mrg 81 1.1 mrg # for testing: 82 1.1 mrg #test -f ./xterm && XTERM_PROGRAM=./xterm 83 1.1 mrg 84 1.1 mrg exec $XTERM_PROGRAM -class KOI8RXTerm -title $whoami -k8 "$@" 85