235N/A###############################################################################
235N/A# Copyright (c) 2009, 2011, Oracle
and/or its affiliates. All rights reserved.
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# 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# 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@@ -48,7 +48,9 @@ _XimCheckIfDefault(
235N/A XimImsportSW _XimImSportRec[] = {
235N/A { _XimCheckIfLocalProcessing, _XimLocalOpenIM, _XimLocalIMFree },
235N/A { _XimCheckIfThaiProcessing, _XimThaiOpenIM, _XimThaiIMFree },
822N/A { _XimCheckIfDefault, _XimProtoOpenIM, _XimProtoIMFree },
235N/A@@ -76,6 +76,12 @@ SOFTWARE.
493N/A+#if !defined(macII) && !defined(Lynx_22) && !defined(X_LOCALE)
235N/A@@ -516,6 +522,45 @@ Private Bool ThaiComposeConvert(
235N/A ((0x0A1<=(c)) ? ((wchar_t)(c)-0xA0+0x0E00) : 0))
235N/A+Private int wc2tis(XLCd lcd, unsigned char* ch, wchar_t wc)
822N/A+ if (XLC_GENERIC(lcd, use_stdc_env) == True)
822N/A+ return wctomb((char*)ch, wc);
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
247N/A+Private int tis2wc(XLCd lcd, wchar_t *pwc, unsigned char* ch)
247N/A+ if (XLC_GENERIC(lcd, use_stdc_env) == True)
235N/A+ return mbtowc(pwc, (char*)ch, 1);
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&wc_mask|GR_codeset->wc_encoding;
235N/A * Macros to save and recall last input character in XIC
235N/A@@ -1210,6 +1255,41 @@ Private void InitIscMode(Xic ic)
235N/A+Private Bool is_utf8_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+ 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++) {
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 */
606N/A * Helper functions for _XimThaiFilter()
822N/A@@ -1217,8 +1297,20 @@ Private Bool
822N/A ThaiFltAcceptInput(Xic ic, unsigned char new_char, KeySym symbol)
241N/A+ if (is_utf8_locale()) {
493N/A+ wchar_t *wcTmp = NULL;
454N/A if ((new_char <= 0x1f) || (new_char == 0x7f))
235N/A@@ -1233,10 +1325,23 @@ ThaiFltReorderInput(Xic ic, unsigned cha
493N/A if (!IC_DeletePreviousChar(ic)) return False;
606N/A+ if (is_utf8_locale()) {
235N/A+ wchar_t *wcTmp = NULL;
822N/A@@ -1247,9 +1352,20 @@ ThaiFltReplaceInput(Xic ic, unsigned cha
606N/A if (!IC_DeletePreviousChar(ic)) return False;
235N/A+ if (is_utf8_locale()) {
606N/A+ wchar_t *wcTmp = NULL;
822N/A if ((new_char <= 0x1f) || (new_char == 0x7f))
235N/A@@ -1367,7 +1483,15 @@ _XimThaiFilter(Display *d, Window w, XEv
235N/A isc_mode = IC_IscMode(ic);
235N/A if (!(previous_char = IC_GetPreviousChar(ic))) previous_char = ' ';
247N/A+ if (is_utf8_locale()) {
247N/A+ new_char = ucs2tis(wbuf[0]);
822N/A new_char = ucs2tis(wbuf[0]);
822N/A if (THAI_isaccepted(new_char, previous_char, isc_mode)) {
822N/A ThaiFltAcceptInput(ic, new_char, symbol);