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