688N/A###############################################################################
1064N/A# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
688N/A#
688N/A# Permission is hereby granted, free of charge, to any person obtaining a
919N/A# copy of this software and associated documentation files (the "Software"),
919N/A# to deal in the Software without restriction, including without limitation
919N/A# the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A# and/or sell copies of the Software, and to permit persons to whom the
919N/A# Software is furnished to do so, subject to the following conditions:
919N/A#
919N/A# The above copyright notice and this permission notice (including the next
919N/A# paragraph) shall be included in all copies or substantial portions of the
919N/A# Software.
919N/A#
919N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A# DEALINGS IN THE SOFTWARE.
688N/A#
688N/A
1370N/Adiff --git a/modules/im/ximcp/imImSw.c b/modules/im/ximcp/imImSw.c
1370N/Aindex 28b1725..327736e 100644
1370N/A--- a/modules/im/ximcp/imImSw.c
1370N/A+++ b/modules/im/ximcp/imImSw.c
1064N/A@@ -48,7 +48,9 @@ _XimCheckIfDefault(
688N/A }
688N/A
688N/A XimImsportSW _XimImSportRec[] = {
688N/A+#ifdef USE_R6_LOCALIM
688N/A { _XimCheckIfLocalProcessing, _XimLocalOpenIM, _XimLocalIMFree },
688N/A+#endif
688N/A { _XimCheckIfThaiProcessing, _XimThaiOpenIM, _XimThaiIMFree },
688N/A { _XimCheckIfDefault, _XimProtoOpenIM, _XimProtoIMFree },
688N/A { NULL, NULL, NULL },
1370N/Adiff --git a/modules/im/ximcp/imThaiFlt.c b/modules/im/ximcp/imThaiFlt.c
1370N/Aindex f134e84..898fc1f 100644
1370N/A--- a/modules/im/ximcp/imThaiFlt.c
1370N/A+++ b/modules/im/ximcp/imThaiFlt.c
1064N/A@@ -76,6 +76,12 @@ SOFTWARE.
688N/A #include "XimThai.h"
688N/A #include "XlcPubI.h"
688N/A
688N/A+#ifdef sun
1370N/A+# include "XlcGeneric.h"
1370N/A+# if !defined(X_LOCALE)
1370N/A+# define STDCVT
1370N/A+# endif
688N/A+#endif
688N/A
688N/A #define SPACE 32
688N/A
1370N/A@@ -516,6 +522,47 @@ static Bool ThaiComposeConvert(
688N/A (wchar_t)(c) : \
688N/A ((0x0A1<=(c)) ? ((wchar_t)(c)-0xA0+0x0E00) : 0))
688N/A
688N/A+#ifdef sun
1370N/A+static int
1370N/A+wc2tis(XLCd lcd, unsigned char* ch, wchar_t wc)
688N/A+{
688N/A+#ifdef STDCVT
688N/A+ if (XLC_GENERIC(lcd, use_stdc_env) == True)
688N/A+ return wctomb((char*)ch, wc);
688N/A+ else
688N/A+#endif
688N/A+ {
688N/A+ wchar_t wc_mask = (1<<XLC_GENERIC(lcd, wc_shift_bits))-1;
688N/A+ ( 0<=wc && wc<=0x7F ) ? (*ch=(unsigned char)wc) : (*ch= (unsigned char)(wc&wc_mask|0x80));//GR 0x80
688N/A+ }
688N/A+ return 1;
688N/A+}
688N/A+
688N/A+
1370N/A+static int
1370N/A+tis2wc(XLCd lcd, wchar_t *pwc, unsigned char* ch)
688N/A+{
688N/A+#ifdef STDCVT
688N/A+ if (XLC_GENERIC(lcd, use_stdc_env) == True)
688N/A+ return mbtowc(pwc, (char*)ch, 1);
688N/A+ else
688N/A+#endif
688N/A+ {
688N/A+ wchar_t wc_mask = (1<<XLC_GENERIC(lcd, wc_shift_bits))-1;
688N/A+ CodeSet GR_codeset = XLC_GENERIC(lcd, initial_state_GR);
688N/A+ if ( 0<=*ch && *ch<=0x7F ) {
688N/A+ *pwc=(wchar_t)*ch;
688N/A+ } else {
688N/A+ if (0xA1<=*ch) {
688N/A+ *pwc = (wchar_t)*ch&wc_mask|GR_codeset->wc_encoding;
688N/A+ return 1;
688N/A+ } else
688N/A+ return 0;
688N/A+ }
688N/A+ }
688N/A+}
688N/A+#endif
688N/A+
688N/A /*
688N/A * Macros to save and recall last input character in XIC
688N/A */
1370N/A@@ -1210,6 +1257,42 @@ static void InitIscMode(Xic ic)
688N/A return;
688N/A }
688N/A
688N/A+#ifdef sun
1370N/A+static Bool
1370N/A+is_utf8_locale(void)
688N/A+{
688N/A+ const char* locale;
688N/A+ locale = getenv("LC_ALL");
688N/A+ if (!locale || !*locale) {
688N/A+ locale = getenv("LC_CTYPE");
688N/A+ if (!locale || !*locale) {
688N/A+ locale = getenv("LANG");
688N/A+ }
688N/A+ }
688N/A+ if (locale && *locale) {
688N/A+ /* The most general syntax of a locale:
688N/A+ language[_territory][.codeset][@modifier]
688N/A+ To retrieve the codeset, search the first dot. Stop searching when
688N/A+ a '@' is encountered. */
688N/A+ const char* cp = locale;
688N/A+ for (; *cp != '\0' && *cp != '@'; cp++) {
688N/A+ if (*cp == '.') {
688N/A+ const char* encoding = ++cp;
688N/A+ for (; *cp != '\0' && *cp != '@'; cp++);
688N/A+ /* Check it for "UTF-8", which is the only official IANA name of
688N/A+ UTF-8. Also check for the lowercase-no-dashes version, which is
688N/A+ what some SystemV systems use. */
688N/A+ if ((cp-encoding == 5 && !strncmp(encoding, "UTF-8", 5))
688N/A+ || (cp-encoding == 4 && !strncmp(encoding, "utf8", 4)))
688N/A+ return True; /* it's UTF-8 */
688N/A+ break; /* not UTF-8 */
688N/A+ }
688N/A+ }
688N/A+ }
688N/A+ return False;
688N/A+}
688N/A+#endif
688N/A+
688N/A /*
688N/A * Helper functions for _XimThaiFilter()
688N/A */
1370N/A@@ -1217,8 +1300,20 @@ static Bool
688N/A ThaiFltAcceptInput(Xic ic, unsigned char new_char, KeySym symbol)
688N/A {
688N/A DefTreeBase *b = &ic->private.local.base;
688N/A+#ifdef sun
688N/A+ if (is_utf8_locale()) {
688N/A+ b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
688N/A+ b->wc[b->tree[ic->private.local.composed].wc+1] = '\0';
688N/A+ } else {
688N/A+ wchar_t *wcTmp = NULL;
688N/A+ wcTmp = &(b->wc[b->tree[ic->private.local.composed].wc+0]);
688N/A+ tis2wc(ic->core.im->core.lcd, wcTmp, &new_char);
688N/A+ *(wcTmp+1) = '\0';
688N/A+ }
688N/A+#else
688N/A b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
688N/A b->wc[b->tree[ic->private.local.composed].wc+1] = '\0';
688N/A+#endif
688N/A
688N/A if ((new_char <= 0x1f) || (new_char == 0x7f))
688N/A b->tree[ic->private.local.composed].keysym = symbol;
1370N/A@@ -1233,9 +1328,23 @@ ThaiFltReorderInput(Xic ic, unsigned char previous_char, unsigned char new_char)
688N/A {
688N/A DefTreeBase *b = &ic->private.local.base;
688N/A if (!IC_DeletePreviousChar(ic)) return False;
688N/A+#ifdef sun
688N/A+ if (is_utf8_locale()) {
688N/A+ b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
688N/A+ b->wc[b->tree[ic->private.local.composed].wc+1] = tis2ucs(previous_char);
688N/A+ b->wc[b->tree[ic->private.local.composed].wc+2] = '\0';
688N/A+ } else {
688N/A+ wchar_t *wcTmp = NULL;
688N/A+ wcTmp = &(b->wc[b->tree[ic->private.local.composed].wc+0]);
688N/A+ tis2wc(ic->core.im->core.lcd, wcTmp, &new_char);
688N/A+ tis2wc(ic->core.im->core.lcd, (wcTmp+1), &previous_char);
688N/A+ *(wcTmp+2) = '\0';
688N/A+ }
688N/A+#else
688N/A b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
688N/A b->wc[b->tree[ic->private.local.composed].wc+1] = tis2ucs(previous_char);
688N/A b->wc[b->tree[ic->private.local.composed].wc+2] = '\0';
688N/A+#endif
1370N/A
688N/A b->tree[ic->private.local.composed].keysym = NoSymbol;
688N/A
1370N/A@@ -1247,8 +1356,20 @@ ThaiFltReplaceInput(Xic ic, unsigned char new_char, KeySym symbol)
688N/A {
688N/A DefTreeBase *b = &ic->private.local.base;
688N/A if (!IC_DeletePreviousChar(ic)) return False;
688N/A+#ifdef sun
688N/A+ if (is_utf8_locale()) {
688N/A+ b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
688N/A+ b->wc[b->tree[ic->private.local.composed].wc+1] = '\0';
688N/A+ } else {
688N/A+ wchar_t *wcTmp = NULL;
688N/A+ wcTmp = &(b->wc[b->tree[ic->private.local.composed].wc+0]);
688N/A+ tis2wc(ic->core.im->core.lcd, wcTmp, &new_char);
688N/A+ *(wcTmp+1) = '\0';
688N/A+ }
688N/A+#else
688N/A b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char);
688N/A b->wc[b->tree[ic->private.local.composed].wc+1] = '\0';
688N/A+#endif
1370N/A
688N/A if ((new_char <= 0x1f) || (new_char == 0x7f))
688N/A b->tree[ic->private.local.composed].keysym = symbol;
1370N/A@@ -1374,7 +1495,15 @@ _XimThaiFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
688N/A */
688N/A isc_mode = IC_IscMode(ic);
688N/A if (!(previous_char = IC_GetPreviousChar(ic))) previous_char = ' ';
688N/A+#ifdef sun
688N/A+ if (is_utf8_locale()) {
688N/A+ new_char = ucs2tis(wbuf[0]);
688N/A+ } else {
688N/A+ wc2tis(ic->core.im->core.lcd, &new_char, wbuf[0]);
688N/A+ }
688N/A+#else
688N/A new_char = ucs2tis(wbuf[0]);
688N/A+#endif
688N/A isReject = True;
688N/A if (THAI_isaccepted(new_char, previous_char, isc_mode)) {
688N/A ThaiFltAcceptInput(ic, new_char, symbol);