1 ###############################################################################
2 # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the "Software"),
6 # to deal in the Software without restriction, including without limitation
7 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 # and/or sell copies of the Software, and to permit persons to whom the
9 # Software is furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice (including the next
12 # paragraph) shall be included in all copies or substantial portions of the
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 # DEALINGS IN THE SOFTWARE.
24 diff --git a/modules/im/ximcp/imImSw.c b/modules/im/ximcp/imImSw.c
25 index 28b1725..327736e 100644
26 --- a/modules/im/ximcp/imImSw.c
27 +++ b/modules/im/ximcp/imImSw.c
28 @@ -48,7 +48,9 @@ _XimCheckIfDefault(
31 XimImsportSW _XimImSportRec[] = {
32 +#ifdef USE_R6_LOCALIM
33 { _XimCheckIfLocalProcessing, _XimLocalOpenIM, _XimLocalIMFree },
35 { _XimCheckIfThaiProcessing, _XimThaiOpenIM, _XimThaiIMFree },
36 { _XimCheckIfDefault, _XimProtoOpenIM, _XimProtoIMFree },
38 diff --git a/modules/im/ximcp/imThaiFlt.c b/modules/im/ximcp/imThaiFlt.c
39 index f134e84..898fc1f 100644
40 --- libX11-1.6.2/modules/im/ximcp/imThaiFlt.c.~1~ 2013-09-09 05:37:20.000000000 +0400
41 +++ libX11-1.6.2/modules/im/ximcp/imThaiFlt.c 2015-02-04 12:03:13.672449821 +0300
47 +# include "XlcGeneric.h"
48 +# if !defined(X_LOCALE)
57 ((0x0A1<=(c)) ? ((wchar_t)(c)-0xA0+0x0E00) : 0))
61 +wc2tis(XLCd lcd, unsigned char* ch, wchar_t wc)
64 + if (XLC_GENERIC(lcd, use_stdc_env) == True)
65 + return wctomb((char*)ch, wc);
69 + wchar_t wc_mask = (1<<XLC_GENERIC(lcd, wc_shift_bits))-1;
70 + ( 0<=wc && wc<=0x7F ) ? (*ch=(unsigned char)wc) : (*ch= (unsigned char)(wc&wc_mask|0x80));//GR 0x80
77 +tis2wc(XLCd lcd, wchar_t *pwc, unsigned char* ch)
80 + if (XLC_GENERIC(lcd, use_stdc_env) == True)
81 + return mbtowc(pwc, (char*)ch, 1);
85 + wchar_t wc_mask = (1<<XLC_GENERIC(lcd, wc_shift_bits))-1;
86 + CodeSet GR_codeset = XLC_GENERIC(lcd, initial_state_GR);
87 + if ( 0<=*ch && *ch<=0x7F ) {
92 + *pwc = (wchar_t)*ch&wc_mask|GR_codeset->wc_encoding;
102 * Macros to save and recall last input character in XIC
104 @@ -1210,6 +1258,42 @@
110 +is_utf8_locale(void)
112 + const char* locale;
113 + locale = getenv("LC_ALL");
114 + if (!locale || !*locale) {
115 + locale = getenv("LC_CTYPE");
116 + if (!locale || !*locale) {
117 + locale = getenv("LANG");
120 + if (locale && *locale) {
121 + /* The most general syntax of a locale:
122 + language[_territory][.codeset][@modifier]
123 + To retrieve the codeset, search the first dot. Stop searching when
124 + a '@' is encountered. */
125 + const char* cp = locale;
126 + for (; *cp != '\0' && *cp != '@'; cp++) {
128 + const char* encoding = ++cp;
129 + for (; *cp != '\0' && *cp != '@'; cp++);
130 + /* Check it for "UTF-8", which is the only official IANA name of
131 + UTF-8. Also check for the lowercase-no-dashes version, which is
132 + what some SystemV systems use. */
133 + if ((cp-encoding == 5 && !strncmp(encoding, "UTF-8", 5))
134 + || (cp-encoding == 4 && !strncmp(encoding, "utf8", 4)))
135 + return True; /* it's UTF-8 */
136 + break; /* not UTF-8 */
145 * Helper functions for _XimThaiFilter()
147 @@ -1217,8 +1301,20 @@
148 ThaiFltAcceptInput(Xic ic, unsigned char new_char, KeySym symbol)
150 DefTreeBase *b = &ic->private.local.base;
152 + if (is_utf8_locale()) {
153 + b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
154 + b->wc[b->tree[ic->private.local.composed].wc+1] = '\0';
156 + wchar_t *wcTmp = NULL;
157 + wcTmp = &(b->wc[b->tree[ic->private.local.composed].wc+0]);
158 + tis2wc(ic->core.im->core.lcd, wcTmp, &new_char);
162 b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
163 b->wc[b->tree[ic->private.local.composed].wc+1] = '\0';
166 if ((new_char <= 0x1f) || (new_char == 0x7f))
167 b->tree[ic->private.local.composed].keysym = symbol;
168 @@ -1233,9 +1329,23 @@
170 DefTreeBase *b = &ic->private.local.base;
171 if (!IC_DeletePreviousChar(ic)) return False;
173 + if (is_utf8_locale()) {
174 + b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
175 + b->wc[b->tree[ic->private.local.composed].wc+1] = tis2ucs(previous_char);
176 + b->wc[b->tree[ic->private.local.composed].wc+2] = '\0';
178 + wchar_t *wcTmp = NULL;
179 + wcTmp = &(b->wc[b->tree[ic->private.local.composed].wc+0]);
180 + tis2wc(ic->core.im->core.lcd, wcTmp, &new_char);
181 + tis2wc(ic->core.im->core.lcd, (wcTmp+1), &previous_char);
185 b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
186 b->wc[b->tree[ic->private.local.composed].wc+1] = tis2ucs(previous_char);
187 b->wc[b->tree[ic->private.local.composed].wc+2] = '\0';
190 b->tree[ic->private.local.composed].keysym = NoSymbol;
192 @@ -1247,8 +1357,20 @@
194 DefTreeBase *b = &ic->private.local.base;
195 if (!IC_DeletePreviousChar(ic)) return False;
197 + if (is_utf8_locale()) {
198 + b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
199 + b->wc[b->tree[ic->private.local.composed].wc+1] = '\0';
201 + wchar_t *wcTmp = NULL;
202 + wcTmp = &(b->wc[b->tree[ic->private.local.composed].wc+0]);
203 + tis2wc(ic->core.im->core.lcd, wcTmp, &new_char);
207 b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
208 b->wc[b->tree[ic->private.local.composed].wc+1] = '\0';
211 if ((new_char <= 0x1f) || (new_char == 0x7f))
212 b->tree[ic->private.local.composed].keysym = symbol;
213 @@ -1374,7 +1496,15 @@
215 isc_mode = IC_IscMode(ic);
216 if (!(previous_char = IC_GetPreviousChar(ic))) previous_char = ' ';
218 + if (is_utf8_locale()) {
219 + new_char = ucs2tis(wbuf[0]);
221 + wc2tis(ic->core.im->core.lcd, &new_char, wbuf[0]);
224 new_char = ucs2tis(wbuf[0]);
227 if (THAI_isaccepted(new_char, previous_char, isc_mode)) {
228 ThaiFltAcceptInput(ic, new_char, symbol);