1d522f475Smrg#!/bin/sh 204b94745Smrg# $XTermId: koi8rxterm,v 1.7 2023/05/03 23:59:22 tom Exp $ 320d2c4d2Smrg# ----------------------------------------------------------------------------- 420d2c4d2Smrg# this file is part of xterm 520d2c4d2Smrg# 65307cd1aSmrg# Copyright 2007-2021,2023 by Thomas E. Dickey 720d2c4d2Smrg# 820d2c4d2Smrg# All Rights Reserved 920d2c4d2Smrg# 1020d2c4d2Smrg# Permission is hereby granted, free of charge, to any person obtaining a 1120d2c4d2Smrg# copy of this software and associated documentation files (the 1220d2c4d2Smrg# "Software"), to deal in the Software without restriction, including 1320d2c4d2Smrg# without limitation the rights to use, copy, modify, merge, publish, 1420d2c4d2Smrg# distribute, sublicense, and/or sell copies of the Software, and to 1520d2c4d2Smrg# permit persons to whom the Software is furnished to do so, subject to 1620d2c4d2Smrg# the following conditions: 1720d2c4d2Smrg# 1820d2c4d2Smrg# The above copyright notice and this permission notice shall be included 1920d2c4d2Smrg# in all copies or substantial portions of the Software. 2020d2c4d2Smrg# 2120d2c4d2Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 2220d2c4d2Smrg# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2320d2c4d2Smrg# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 2420d2c4d2Smrg# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 2520d2c4d2Smrg# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2620d2c4d2Smrg# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2720d2c4d2Smrg# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2820d2c4d2Smrg# 2920d2c4d2Smrg# Except as contained in this notice, the name(s) of the above copyright 3020d2c4d2Smrg# holders shall not be used in advertising or otherwise to promote the 3120d2c4d2Smrg# sale, use or other dealings in this Software without prior written 3220d2c4d2Smrg# authorization. 3320d2c4d2Smrg# ----------------------------------------------------------------------------- 34d522f475Smrg# This is a wrapper script to set up xterm with a KOI8-R locale; based on 3520d2c4d2Smrg# uxterm by Branden Robinson. 36d522f475Smrg 37d522f475Smrgwhoami=koi8rxterm 38d522f475Smrg 39f2e35a3aSmrg: "${XTERM_PROGRAM=xterm}" 40d522f475Smrg 41d522f475Smrg# Check if there is a workable locale program. If there is not, we will read 42d522f475Smrg# something via the standard error. Ignore whatever is written to the 43d522f475Smrg# standard output. 44d522f475Smrglocale=`sh -c "LC_ALL=C LC_CTYPE=C LANG=C locale >/dev/null" 2>&1` 45d522f475Smrgfound=no 46d522f475Smrg 47d522f475Smrg# Check for -version and -help options, to provide a simple return without 48d522f475Smrg# requiring the program to create a window: 49d522f475Smrgif test $# = 1 50d522f475Smrgthen 51d522f475Smrg case $1 in 52d522f475Smrg -v|-ver*|-h|-he*) 53d522f475Smrg $XTERM_PROGRAM "$@" 54d522f475Smrg exit $? 55d522f475Smrg ;; 56d522f475Smrg esac 57d522f475Smrgfi 58d522f475Smrg 59d522f475Smrg# Check environment variables that xterm does, in the same order: 60d522f475Smrgfor name in LC_ALL LC_CTYPE LANG 61d522f475Smrgdo 62d522f475Smrg eval 'value=$'$name 63d522f475Smrg if test -n "$value" ; then 64d522f475Smrg case $value in 65d522f475Smrg *.koi8r|*.KOI8R|*.koi8-r|*.KOI8-R) 66d522f475Smrg found=yes 67d522f475Smrg ;; 68d522f475Smrg *.koi8r@*|*.KOI8R@*|*.koi8-r@*|*.KOI8-R*) 69d522f475Smrg found=yes 70d522f475Smrg ;; 71d522f475Smrg *) 72d522f475Smrg # The user may not have configured his or her 73d522f475Smrg # locale; try to muddle through anyway. 74d522f475Smrg value=ru_RU.KOI8-R 75d522f475Smrg ;; 76d522f475Smrg esac 77d522f475Smrg break 78d522f475Smrg fi 79d522f475Smrgdone 80d522f475Smrg 81d522f475Smrg# If we didn't find one that uses KOI8-R, modify the safest one. Not everyone 82d522f475Smrg# has a KOI8-R locale installed (and there appears to be no trivial/portable 83d522f475Smrg# way to determine whether it is, from a shell script). We could check if the 84d522f475Smrg# user's shell does not reset unknown locale specifiers, but not all shells do. 85d522f475Smrgif test $found != yes ; then 86d522f475Smrg if test -n "$value" ; then 87d522f475Smrg value=`echo ${value} |sed -e 's/[.@].*//'`.KOI8-R 88d522f475Smrg else 89d522f475Smrg name="LC_CTYPE" 90d522f475Smrg value="ru_RU.KOI8-R" 91d522f475Smrg fi 92d522f475Smrg eval save=\$${name} 93d522f475Smrg eval ${name}=${value} 94d522f475Smrg eval export ${name} 95d522f475Smrg if test -z "$locale" ; then 96d522f475Smrg # The 'locale' program tries to do a sanity check. 97d522f475Smrg check=`sh -c "locale >/dev/null" 2>&1` 98d522f475Smrg if test -n "$check" ; then 99f2e35a3aSmrg eval ${name}="${save}" 100d522f475Smrg eval export ${name} 101d522f475Smrg 102d522f475Smrg echo "$whoami tried to use locale $value by setting \$$name" >&2 103d522f475Smrg xmessage -file - <<EOF 104d522f475Smrg$whoami tried unsuccessfully to use locale $value 105d522f475Smrgby setting \$$name to "${value}". 106d522f475SmrgEOF 107d522f475Smrg exit 1 108d522f475Smrg fi 109d522f475Smrg fi 110d522f475Smrgfi 111d522f475Smrg 112d522f475Smrg# for testing: 113d522f475Smrg#test -f ./xterm && XTERM_PROGRAM=./xterm 114d522f475Smrg 1155307cd1aSmrgexec "$XTERM_PROGRAM" -class KOI8RXTerm -k8 "$@" 116