libgit2: update to 1.9.0
[oi-userland.git] / components / inputmethod / imf-selector / src / data / 0210.im
blobc28504a4bf341e071cea8ce131b7b185613ae2d0
1 #!/bin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
8 # with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # CDDL HEADER END
23 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
26 LING=${LC_CTYPE:-"$LC_ALL"}
27 LING=${LING:-"$LANG"}
28 LING=${LING:-"C"}
30 XIM_SCRIPT_DIR=/etc/X11/xinit/imf.d
31 XIM_USR_CONF=$HOME/.imf
32 IM_SCRIPT=''
33 IMFSELECTOR='/usr/bin/imf-selector'
35 tolines(){
36 for imfile in $@
38 im_name=`sh $imfile -name`
39 /bin/echo "$im_name|$imfile"
40 done
43 list_ims(){
45 # list available IM on system
46 if [ ! -d $XIM_SCRIPT_DIR ]; then
47 return
49 s="$1"
50 if [ X"$s" != X ]; then
51 im_file=`LC_ALL=C /bin/ls $XIM_SCRIPT_DIR \
52 | /bin/grep "[0-9][0-9]*\.$s\$"`
53 if [ X$im_file != X ]; then
54 im_name=`sh $XIM_SCRIPT_DIR/$im_file -name`
55 /bin/echo "$im_name|$XIM_SCRIPT_DIR/$im_file"
57 return
60 LC_ALL=C /bin/ls -F $XIM_SCRIPT_DIR/[0-9][0-9]* \
61 | /bin/egrep -v '@$|/$' | /bin/cut -d'*' -f 1
65 get_prior_im(){
66 # Check specified default engine in for language
67 # if this selection is done once and ignored, skip.
68 if [ -f $XIM_USR_CONF ]; then
69 return
72 list_ims | while read imfile
73 do
74 prior_im=`sh $imfile -prior $LING`
75 if [ X"$prior_im" != X ]; then
76 echo "$prior_im"
77 return
79 done
82 get_default_im(){
84 # As default, enable for only specified Asian locales
85 case $LING in
86 ja* | zh* | ko* | th* | *_IN* )
87 tolines `list_ims | /usr/bin/head -1`; break;;
88 *) echo "None"
89 esac
92 get_current_im(){
94 # check IM scripts orderly.
95 if [ -f $XIM_USR_CONF ]; then
97 # 1. configuration in $HOME by tool
98 im_name=`/bin/sh $XIM_USR_CONF -name`
99 if [ X"$im_name" = X ]; then
100 im_data="None"
102 . "$XIM_USR_CONF"
103 if [ X"$IGNORE" = 'X1' ]; then
104 im_data=""
106 else
107 im_data="$im_name|$XIM_USR_CONF"
110 elif [ X$GTK_IM_MODULE != X ]; then
112 # 2-1. user's GTK_IM_MODULE variable
113 suffix=$GTK_IM_MODULE
114 im_data=`list_ims $suffix`
116 elif [ X$XMODIFIERS != X ]; then
118 # 2-2. user's XMODIFIERS variable
119 suffix=`/bin/echo $XMODIFIERS | cut -d '=' -f 2`
120 im_data=`list_ims $suffix`
123 if [ X"$im_data" != X ]; then
124 /bin/echo "$im_data"
125 return
128 # 3. system default if nothing specified
129 get_default_im
132 set_im(){
134 # copy given script file to user config file.
135 im_script="$1"
137 if ! touch $XIM_USR_CONF > /dev/null 2>&1; then
138 echo "Can not access config file: $XIM_USR_CONF" 1>&2
139 return 1
142 msg1="# This file is created by Input Method selector tool.\n"
143 msg2="# Please don't edit this file manually."
144 if [ X"$im_script" = X ]; then
145 /bin/echo "${msg1}${msg2}" > $XIM_USR_CONF
146 elif [ X"$im_script" = XIGNORE ]; then
147 /bin/echo "${msg1}${msg2}" > $XIM_USR_CONF
148 /bin/echo "IGNORE=1" >> $XIM_USR_CONF
149 else
150 /bin/cp $im_script $XIM_USR_CONF
152 return $?
155 start_im(){
157 # start IM
158 if [ X$IM_SCRIPT != X -a -f $IM_SCRIPT ]; then
159 . $IM_SCRIPT
161 if [ -x $XIM_PRG -a X$XIM_ASDAEMON != X ]; then
162 $XIM_PRG $XIM_OPT &
163 DTSTARTIMS=False; export DTSTARTIMS
164 elif [ -x $XIM_PRG ]; then
165 $XIM_PRG $XIM_OPT
166 DTSTARTIMS=False; export DTSTARTIMS
171 # Main
172 case $1 in
173 '-list') tolines `list_ims`; exit $?;;
174 '-default') get_default_im; exit $?;;
175 '-get') get_current_im; exit $?;;
176 '-set') set_im $2; exit $?;;
177 esac
179 PRIOR_IM=`get_prior_im`
180 if [ X"$PRIOR_IM" != X ]; then
181 (sleep 10 && $IMFSELECTOR -p "$PRIOR_IM") &
183 IM_SCRIPT=`get_current_im | cut -d '|' -f 2`
184 start_im