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