home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / koi8rxterm < prev    next >
Encoding:
Text File  |  2006-12-20  |  2.2 KB  |  86 lines

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