# Common shell routine used by im-config
# /usr/share/im-config/xinputrc.common
# (C) Osamu Aoki <osamu@debian.org>, GPL-2+
# vim: set sts=4 expandtab:
#
#############################################################
# Common variables used by im-config and its hook script
#############################################################
IM_CONFIG_VERSION=0.44-1ubuntu1.3
IM_CONFIG_DATA=/usr/share/im-config/data
IM_CONFIG_XINPUTRC_USR=$HOME/.xinputrc
IM_CONFIG_XINPUTRC_SYS=/etc/X11/xinit/xinputrc
IM_CONFIG_DEFAULT=/etc/default/im-config
IM_CONFIG_VERBOSE=false
. gettext.sh
TEXTDOMAIN="im-config"
export TEXTDOMAIN
TEXTDOMAINDIR="/usr/share/locale/"
export TEXTDOMAINDIR
if [ -r $IM_CONFIG_DEFAULT ]; then
. $IM_CONFIG_DEFAULT
fi
IM_CONFIG_LC_CTYPE=$(locale | sed -nr 's/LC_CTYPE=\"?([a-zA-Z_]*).*/\1/p')
IM_CONFIG_PREFERRED=$(echo "$IM_CONFIG_PREFERRED_RULE"| sed -rn "s/(^|.*:)${IM_CONFIG_LC_CTYPE},([^:]*)($|:.*$)/\2/p")
#############################################################
# Common functions used by im-config hook script (any mode)
#############################################################
# run selected input method script
# run_im <config>
run_im () {
IM_CONFIG_CODE="run_im"
if [ -r $IM_CONFIG_DATA/[012345678]?_$1.rc ]; then
. $IM_CONFIG_DATA/[012345678]?_$1.rc
IM_CONFIG_NAME=$1
if $IM_CONFIG_VERBOSE ; then
eval_gettext "I: Script for \$IM_CONFIG_NAME started at \$IM_CONFIG_CODE." >&2
echo >&2
fi
else
IM_CONFIG_NAME=$1
eval_gettext "E: Script for \$IM_CONFIG_NAME not found at \$IM_CONFIG_CODE." >&2
echo >&2
fi
}
#############################################################
# Package status function used by im-config and auto mode
#############################################################
# package_status <packagename>
# return TRUE if in properly installed
package_status () {
PACKAGE_NAME="$1"
if [ "$( LC_ALL=C dpkg-query -l "$PACKAGE_NAME" 2>/dev/null | \
sed -n '6s/\([^ ]*\) .*$/\1/p' )" = "ii" ]; then
# return TRUE
return 0
else
return 1
fi
}
#############################################################
# Common functions used by auto mode
#############################################################
# name_im <full_path>
name_im () {
local x
x=${1#$IM_CONFIG_DATA/??_}
x=${x%.rc}
x=${x%.conf}
echo -n $x
}
# avail_auto <config>
# configuration availability for auto mode
# define package_auto for 10-79*.conf
avail_auto () {
if [ -r $IM_CONFIG_DATA/??_$1.conf ]; then
. $IM_CONFIG_DATA/??_$1.conf
package_auto
else
IM_CONFIG_CODE="avail_auto"
IM_CONFIG_NAME=$1
eval_gettext "E: Configuration for \$IM_CONFIG_NAME not found at \$IM_CONFIG_CODE." >&2
echo >&2
# return FALSE
return 1
fi
}
# autobase_im
# echo automatic IM configuration name (without considering locale)
autobase_im () {
# auto mode uses first available script in 10-79
# 79 is for "none", i.e., no IM used
for IM_CONFIG_SCRIPT_PATH in $IM_CONFIG_DATA/[1234567]*.rc ; do
IM_CONFIG_SCRIPT=$(name_im $IM_CONFIG_SCRIPT_PATH)
if avail_auto $IM_CONFIG_SCRIPT ; then
echo -n "$IM_CONFIG_SCRIPT"
break
fi
done
}
# automatic_im
# echo automatic IM configuration name
automatic_im () {
if [ "$IM_CONFIG_PREFERRED" != "" ] && avail_auto $IM_CONFIG_PREFERRED ; then
echo -n "$IM_CONFIG_PREFERRED"
else
autobase_im
fi
}
# imconfig_find_files_with_prefixpath_glob
# check if files exist with given array of strings (shell glob acceptable)
# accept a prefix where "find" is executed on, with a list of strings of
# glob-enabled absolute file path.
# return a string of matched files, using absolute path, separated with
# newline. The string is not ended with newline.
#
# Example:
# imconfig_find_files_with_prefixpath_glob /usr/lib \
# '/usr/lib/*/gtk-2.0/*/im_fcitx.so' \
# '/usr/lib/gtk-2.0/*/im_fcitx.so'
### DISABLED for #925160 bug
# This check was meant for setting IM_* to xim or not.
# Setting IM_* to xim comes with many issues such as lost key stroke.
# Not worth doing it anymore. Let's always set IM_* to non-xim.
imconfig_find_files_with_prefixpath_glob () {
printf '%s' "FOUND"
}