Home | History | Annotate | Line # | Download | only in dist
koi8rxterm revision 1.1.1.3
      1      1.1  mrg #!/bin/sh
      2  1.1.1.3  mrg # $XTermId: koi8rxterm,v 1.6 2021/01/27 01:35:34 tom Exp $
      3  1.1.1.2  mrg # -----------------------------------------------------------------------------
      4  1.1.1.2  mrg # this file is part of xterm
      5  1.1.1.2  mrg #
      6  1.1.1.3  mrg # Copyright 2007,2021 by Thomas E. Dickey
      7  1.1.1.2  mrg # 
      8  1.1.1.2  mrg #                         All Rights Reserved
      9  1.1.1.2  mrg # 
     10  1.1.1.2  mrg # Permission is hereby granted, free of charge, to any person obtaining a
     11  1.1.1.2  mrg # copy of this software and associated documentation files (the
     12  1.1.1.2  mrg # "Software"), to deal in the Software without restriction, including
     13  1.1.1.2  mrg # without limitation the rights to use, copy, modify, merge, publish,
     14  1.1.1.2  mrg # distribute, sublicense, and/or sell copies of the Software, and to
     15  1.1.1.2  mrg # permit persons to whom the Software is furnished to do so, subject to
     16  1.1.1.2  mrg # the following conditions:
     17  1.1.1.2  mrg # 
     18  1.1.1.2  mrg # The above copyright notice and this permission notice shall be included
     19  1.1.1.2  mrg # in all copies or substantial portions of the Software.
     20  1.1.1.2  mrg # 
     21  1.1.1.2  mrg # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     22  1.1.1.2  mrg # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     23  1.1.1.2  mrg # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     24  1.1.1.2  mrg # IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
     25  1.1.1.2  mrg # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     26  1.1.1.2  mrg # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     27  1.1.1.2  mrg # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     28  1.1.1.2  mrg # 
     29  1.1.1.2  mrg # Except as contained in this notice, the name(s) of the above copyright
     30  1.1.1.2  mrg # holders shall not be used in advertising or otherwise to promote the
     31  1.1.1.2  mrg # sale, use or other dealings in this Software without prior written
     32  1.1.1.2  mrg # authorization.
     33  1.1.1.2  mrg # -----------------------------------------------------------------------------
     34      1.1  mrg # This is a wrapper script to set up xterm with a KOI8-R locale; based on
     35  1.1.1.2  mrg # uxterm by Branden Robinson.
     36      1.1  mrg 
     37      1.1  mrg whoami=koi8rxterm
     38      1.1  mrg 
     39  1.1.1.3  mrg : "${XTERM_PROGRAM=xterm}"
     40      1.1  mrg 
     41      1.1  mrg # Check if there is a workable locale program.  If there is not, we will read
     42      1.1  mrg # something via the standard error.  Ignore whatever is written to the
     43      1.1  mrg # standard output.
     44      1.1  mrg locale=`sh -c "LC_ALL=C LC_CTYPE=C LANG=C locale >/dev/null" 2>&1`
     45      1.1  mrg found=no
     46      1.1  mrg 
     47      1.1  mrg # Check for -version and -help options, to provide a simple return without
     48      1.1  mrg # requiring the program to create a window:
     49      1.1  mrg if test $# = 1
     50      1.1  mrg then
     51      1.1  mrg 	case $1 in
     52      1.1  mrg 	-v|-ver*|-h|-he*)
     53      1.1  mrg 		$XTERM_PROGRAM "$@"
     54      1.1  mrg 		exit $?
     55      1.1  mrg 		;;
     56      1.1  mrg 	esac
     57      1.1  mrg fi
     58      1.1  mrg 
     59      1.1  mrg # Check environment variables that xterm does, in the same order:
     60      1.1  mrg for name in LC_ALL LC_CTYPE LANG
     61      1.1  mrg do
     62      1.1  mrg 	eval 'value=$'$name
     63      1.1  mrg 	if test -n "$value" ; then
     64      1.1  mrg 		case $value in
     65      1.1  mrg 		*.koi8r|*.KOI8R|*.koi8-r|*.KOI8-R)
     66      1.1  mrg 			found=yes
     67      1.1  mrg 			;;
     68      1.1  mrg 		*.koi8r@*|*.KOI8R@*|*.koi8-r@*|*.KOI8-R*)
     69      1.1  mrg 			found=yes
     70      1.1  mrg 			;;
     71      1.1  mrg 		*)
     72      1.1  mrg 			# The user may not have configured his or her
     73      1.1  mrg 			# locale; try to muddle through anyway.
     74      1.1  mrg 			value=ru_RU.KOI8-R
     75      1.1  mrg 			;;
     76      1.1  mrg 		esac
     77      1.1  mrg 		break
     78      1.1  mrg 	fi
     79      1.1  mrg done
     80      1.1  mrg 
     81      1.1  mrg # If we didn't find one that uses KOI8-R, modify the safest one.  Not everyone
     82      1.1  mrg # has a KOI8-R locale installed (and there appears to be no trivial/portable
     83      1.1  mrg # way to determine whether it is, from a shell script).  We could check if the
     84      1.1  mrg # user's shell does not reset unknown locale specifiers, but not all shells do.
     85      1.1  mrg if test $found != yes ; then
     86      1.1  mrg 	if test -n "$value" ; then
     87      1.1  mrg 		value=`echo ${value} |sed -e 's/[.@].*//'`.KOI8-R
     88      1.1  mrg 	else
     89      1.1  mrg 		name="LC_CTYPE"
     90      1.1  mrg 		value="ru_RU.KOI8-R"
     91      1.1  mrg 	fi
     92      1.1  mrg 	eval save=\$${name}
     93      1.1  mrg 	eval ${name}=${value}
     94      1.1  mrg 	eval export ${name}
     95      1.1  mrg 	if test -z "$locale" ; then
     96      1.1  mrg 		# The 'locale' program tries to do a sanity check.
     97      1.1  mrg 		check=`sh -c "locale >/dev/null" 2>&1`
     98      1.1  mrg 		if test -n "$check" ; then
     99  1.1.1.3  mrg 			eval ${name}="${save}"
    100      1.1  mrg 			eval export ${name}
    101      1.1  mrg 
    102      1.1  mrg 			echo "$whoami tried to use locale $value by setting \$$name" >&2
    103      1.1  mrg 			xmessage -file - <<EOF
    104      1.1  mrg $whoami tried unsuccessfully to use locale $value
    105      1.1  mrg by setting \$$name to "${value}".
    106      1.1  mrg EOF
    107      1.1  mrg 			exit 1
    108      1.1  mrg 		fi
    109      1.1  mrg 	fi
    110      1.1  mrg fi
    111      1.1  mrg 
    112      1.1  mrg # for testing:
    113      1.1  mrg #test -f ./xterm && XTERM_PROGRAM=./xterm
    114      1.1  mrg 
    115  1.1.1.3  mrg exec "$XTERM_PROGRAM" -class KOI8RXTerm -title "$whoami" -k8 "$@"
    116