summaryrefslogtreecommitdiff
path: root/xc/lib/X11/imConv.c
diff options
context:
space:
mode:
Diffstat (limited to 'xc/lib/X11/imConv.c')
-rw-r--r--xc/lib/X11/imConv.c279
1 files changed, 181 insertions, 98 deletions
diff --git a/xc/lib/X11/imConv.c b/xc/lib/X11/imConv.c
index d15fc20a3..e46735c5d 100644
--- a/xc/lib/X11/imConv.c
+++ b/xc/lib/X11/imConv.c
@@ -31,7 +31,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
fujiwara@a80.tech.yk.fujitsu.co.jp
******************************************************************/
-/* $XFree86: xc/lib/X11/imConv.c,v 1.22 2000/02/18 12:18:51 tsi Exp $ */
+/* $XFree86: xc/lib/X11/imConv.c,v 1.25 2000/06/23 19:50:59 dawes Exp $ */
#define NEED_EVENTS
#include <stdio.h>
@@ -66,18 +66,18 @@ unsigned int Const _Xlatin1[128] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-0x990ee, 0x88000, 0x89000, 0x89084, 0x0902e, 0x89000, 0x09080, 0x9908e,
-0x0908e, 0x89080, 0x88000, 0x89080, 0x89080, 0x990ee, 0x89000, 0x89008,
-0x9908e, 0x89080, 0x89084, 0x89084, 0x0908e, 0x89004, 0x89000, 0x99084,
-0x0900c, 0x89000, 0x88000, 0x89080, 0x09000, 0x09084, 0x09000, 0x88000,
-0x88004, 0x9800e, 0x9800e, 0x98008, 0x9800e, 0x98008, 0x98008, 0x88006,
-0x88004, 0x9800e, 0x88004, 0x9800e, 0x88004, 0x9800e, 0x9800e, 0x98004,
-0x90000, 0x88004, 0x88004, 0x98006, 0x9800e, 0x98008, 0x9800e, 0x8800e,
-0x98008, 0x88004, 0x9800e, 0x9800c, 0x9800e, 0x90002, 0x90000, 0x9800e,
-0x88004, 0x9800e, 0x9800e, 0x98008, 0x9800e, 0x98008, 0x98008, 0x88004,
-0x88004, 0x9800e, 0x88004, 0x9800e, 0x88004, 0x9800e, 0x9800e, 0x98004,
-0x90000, 0x88004, 0x88004, 0x98006, 0x9800e, 0x98008, 0x9800e, 0x8800e,
-0x98008, 0x88004, 0x9800e, 0x9800c, 0x9800e, 0x90002, 0x90000, 0x88000
+0xb90ee, 0x88000, 0xa9000, 0xa9084, 0x2902e, 0x89000, 0x29080, 0xb908e,
+0x0908e, 0xa9080, 0x88000, 0xa9080, 0xa9080, 0xb90ee, 0xa9000, 0x89008,
+0xb908e, 0xa9080, 0xa9084, 0xa9084, 0x0908e, 0xa9004, 0xa9000, 0xb9084,
+0x0900c, 0xa9000, 0x88000, 0xa9080, 0x29000, 0x29084, 0x29000, 0x88000,
+0x88004, 0x9800e, 0x9800e, 0x98008, 0xb800e, 0xb8008, 0x98008, 0x88006,
+0x88004, 0xb800e, 0x88004, 0x9800e, 0x88004, 0x9800e, 0x9800e, 0x98004,
+0x90000, 0x88004, 0x88004, 0xb8006, 0x9800e, 0xb8008, 0xb800e, 0xa800e,
+0x98008, 0x88004, 0x9800e, 0x9800c, 0xb800e, 0x90002, 0x90000, 0xb800e,
+0x88004, 0x9800e, 0x9800e, 0x98008, 0xb800e, 0xb8008, 0x98008, 0x88004,
+0x88004, 0xb800e, 0x88004, 0x9800e, 0x88004, 0x9800e, 0x9800e, 0x98004,
+0x90000, 0x88004, 0x88004, 0xb8006, 0x9800e, 0xb8008, 0xb800e, 0xa800e,
+0x98008, 0x88004, 0x9800e, 0x9800c, 0xb800e, 0x90002, 0x90000, 0x88000
};
/* bit (1<<i) means character is in codeset i */
@@ -91,12 +91,12 @@ unsigned int Const _Xlatin2[128] = {
0x1800c, 0x10008, 0x00008, 0x00000, 0x0800c, 0x00000, 0x00000, 0x00008,
0x0800c, 0x00008, 0x00004, 0x00000, 0x00000, 0x00000, 0x00008, 0x00004,
0x00000, 0x1800c, 0x1800c, 0x00000, 0x1800c, 0x00000, 0x00000, 0x08004,
-0x10008, 0x1800c, 0x10008, 0x1800c, 0x00000, 0x18008, 0x18008, 0x00000,
-0x00008, 0x00000, 0x00000, 0x18004, 0x1800c, 0x00000, 0x1800c, 0x0800c,
+0x30008, 0x1800c, 0x10008, 0x1800c, 0x00000, 0x18008, 0x18008, 0x00000,
+0x00008, 0x20000, 0x00000, 0x18004, 0x1800c, 0x00000, 0x1800c, 0x0800c,
0x00000, 0x00000, 0x0800c, 0x00000, 0x0800c, 0x10000, 0x00000, 0x1800c,
0x00000, 0x1800c, 0x1800c, 0x00000, 0x1800c, 0x00000, 0x00000, 0x08004,
-0x10008, 0x1800c, 0x10008, 0x1800c, 0x00000, 0x1800c, 0x1800c, 0x00000,
-0x00008, 0x00000, 0x00000, 0x18004, 0x1800c, 0x00000, 0x1800c, 0x0800c,
+0x30008, 0x1800c, 0x10008, 0x1800c, 0x00000, 0x1800c, 0x1800c, 0x00000,
+0x00008, 0x20000, 0x00000, 0x18004, 0x1800c, 0x00000, 0x1800c, 0x0800c,
0x00000, 0x00000, 0x0800c, 0x00000, 0x0800c, 0x10000, 0x00000, 0x0000c
};
@@ -409,7 +409,7 @@ static int keysym_to_ucs4(keysym)
struct CodesetRec {
unsigned long locale_code;
char* locale_name;
- char* escape_seq;
+ char* charset_name;
};
#define sLatin1 0L
@@ -438,38 +438,38 @@ struct CodesetRec {
#define sUTF8 0x02000000L
static struct CodesetRec CodesetTable[] = {
- {sLatin1, "ISO8859-1", "\033-A"},
- {sLatin2, "ISO8859-2", "\033-B"},
- {sLatin3, "ISO8859-3", "\033-C"},
- {sLatin4, "ISO8859-4", "\033-D"},
- {sCyrillic, "ISO8859-5", "\033-L"},
- {sArabic, "ISO8859-6", "\033-G"},
- {sGreek, "ISO8859-7", "\033-F"},
- {sHebrew, "ISO8859-8", "\033-H"},
- {sLatin5, "ISO8859-9", "\033-M"},
- {sLatin6, "ISO8859-10", "\033-V"},
- {sThai, "TACTIS", "\033-T"},
- {sKorean, "ko.euc", "\033$(C"},
- {sThai, "ISO8859-11", "\033-T"},
- {sThai, "TIS620.2533-1", "\033-T"},
+ {sLatin1, "ISO8859-1", NULL },
+ {sLatin2, "ISO8859-2", NULL },
+ {sLatin3, "ISO8859-3", NULL },
+ {sLatin4, "ISO8859-4", NULL },
+ {sCyrillic, "ISO8859-5", NULL },
+ {sArabic, "ISO8859-6", NULL },
+ {sGreek, "ISO8859-7", NULL },
+ {sHebrew, "ISO8859-8", NULL },
+ {sLatin5, "ISO8859-9", NULL },
+ {sLatin6, "ISO8859-10",NULL },
+ {sKorean, "ko.euc", "KSC5601.1987-0:GL"},
+ {sThai, "TACTIS", "TIS620.2533-1:GR" },
+ {sThai, "ISO8859-11", "TIS620.2533-1:GR" },
+ {sThai, "TIS620.2533-1", NULL },
+ {sLatin7, "ISO8859-13",NULL }, /* Baltic Rim */
#if 0
- {sLatin8, "ISO8859-12", "\033-?"},/* Celtic, superceded by -14 */
- {sLatin7, "ISO8859-13", "\033-?"},/* Baltic Rim */
- {sLatin8 "ISO8859-14", "\033-?"},/* Celtic */
+ {sLatin8, "ISO8859-12", ""},/* Celtic, superceded by -14 */
+ {sLatin8 "ISO8859-14", ""},/* Celtic */
#endif
- {sUTF8, "UTF-8", "\033%G"},
+ {sUTF8, "UTF-8", "ISO10646-1"},
/* Non-standard */
- {sKoi8_r, "KOI8-R", "\033%/1\200\210koi8-r\002"},
- {sKoi8_u, "KOI8-U", "\033%/1\200\211koi8-u\002"},
- {sLatin9, "ISO8859-15", "\033%/1\200\213iso8859-15\002"},/* a.k.a. Latin-0 */
- {sArmenian, "ARMSCII-8", "\033%/1\200\210armscii-8\002"},
- {sGeorgian, "GEORGIAN-ACADEMY", "\033%/1\200\210georgian-academy\002"},
- {sGeorgian, "GEORGIAN-PS", "\033%/1\200\210georgian-ps\002"},
+ {sKoi8_r, "KOI8-R", NULL },
+ {sKoi8_u, "KOI8-U", NULL },
+ {sLatin9, "ISO8859-15", NULL },/* a.k.a. Latin-0 */
+ {sArmenian, "ARMSCII-8", NULL },
+ {sGeorgian, "GEORGIAN-ACADEMY", NULL },
+ {sGeorgian, "GEORGIAN-PS", NULL },
/* TODO find better values for the sLatin1 below */
- {sLatin1, "IBM-CP1133", "\033%/1\200\210ibm-cp1133\002"},
- {sLatin1, "MULELAO-1", "\033%/1\200\210mulelao-1\002"},
- {sLatin1, "VISCII1.1-1", "\033%/1\200\210viscii1.1-1\002"},
- {sLatin1, "TCVN-5712", "\033%/1\200\210tcvn-5712\002"},
+ {sLatin1, "IBM-CP1133", NULL },
+ {sLatin1, "MULELAO-1", NULL },
+ {sLatin1, "VISCII1.1-1", NULL },
+ {sLatin1, "TCVN-5712", NULL },
};
@@ -488,11 +488,11 @@ unsigned long Const *
#if NeedFunctionPrototypes
_XimGetLocaleCode (
_Xconst char* encoding_name,
- XPointer* cset_ret)
+ XlcCharSet* charset_ret)
#else
-_XimGetLocaleCode (name, cset_ret)
+_XimGetLocaleCode (encoding_name, charset_ret)
_Xconst char* encoding_name;
- XPointer* cset_ret;
+ XlcCharSet* charset_ret;
#endif
{
int i;
@@ -507,8 +507,21 @@ _XimGetLocaleCode (name, cset_ret)
}
}
- if (cset_ret)
- *cset_ret = (XPointer) cset;
+ if (charset_ret) {
+ *charset_ret = NULL;
+ if (cset->charset_name == NULL) {
+ char *name = Xmalloc(strlen(cset->locale_name) + 4);
+ if (name != NULL) {
+ strcpy(name, cset->locale_name);
+ strcat(name, ":GR");
+ *charset_ret = _XlcGetCharSet(name);
+ }
+ } else {
+ *charset_ret = _XlcGetCharSet(cset->charset_name);
+ }
+ if (*charset_ret == NULL)
+ *charset_ret = _XlcGetCharSet("ISO8859-1:GR");
+ }
return &(cset->locale_code);
}
@@ -549,7 +562,9 @@ _XimGetCharCode (locale_code, keysym, buf, nbytes)
if (locale_code == sUTF8) {
unsigned int ucs4 = keysym_to_ucs4 (keysym);
- int count;
+
+ if (!ucs4)
+ return 0;
if (ucs4 < 0x80)
count = 1;
else if (ucs4 < 0x800)
@@ -613,6 +628,8 @@ _XimGetCharCode (locale_code, keysym, buf, nbytes)
*buf = _Xkoi8_u[keysym & 0x7f];
else
*buf = _Xcyrillic[keysym & 0x7f];
+ if (!buf[0])
+ count = 0;
break;
case sGreek:
*buf = _Xgreek[keysym & 0x7f];
@@ -640,6 +657,16 @@ _XimGetCharCode (locale_code, keysym, buf, nbytes)
*buf = (unsigned char)0xfd;
else if ((locale_code == sX0201) && (keysym == XK_yen))
*buf = (unsigned char)0x5c;
+ else if (locale_code == sLatin7) {
+ switch (keysym) {
+ case XK_acute: *buf = (unsigned char)0xff; break;
+ case XK_AE: *buf = (unsigned char)0xaf; break;
+ case XK_ae: *buf = (unsigned char)0xbf; break;
+ case XK_Ooblique: *buf = (unsigned char)0xa8; break;
+ case XK_oslash: *buf = (unsigned char)0xb8; break;
+ default: count = 0;
+ }
+ }
else count = 0;
}
} else if (isLatin1) {
@@ -670,6 +697,28 @@ _XimGetCharCode (locale_code, keysym, buf, nbytes)
else if (keysym == XK_zcaron)
*buf = (unsigned char)0xb8;
else count = 0;
+ } else if (locale_code == sLatin7) {
+ switch (keysym) {
+ case XK_Aogonek: *buf = (unsigned char)0xc0; break;
+ case XK_aogonek: *buf = (unsigned char)0xe0; break;
+ case XK_Cacute: *buf = (unsigned char)0xc3; break;
+ case XK_cacute: *buf = (unsigned char)0xe3; break;
+ case XK_Eogonek: *buf = (unsigned char)0xc6; break;
+ case XK_eogonek: *buf = (unsigned char)0xe6; break;
+ case XK_Zacute: *buf = (unsigned char)0xca; break;
+ case XK_zacute: *buf = (unsigned char)0xea; break;
+ case XK_Scaron: *buf = (unsigned char)0xd0; break;
+ case XK_scaron: *buf = (unsigned char)0xf0; break;
+ case XK_Lstroke: *buf = (unsigned char)0xd9; break;
+ case XK_lstroke: *buf = (unsigned char)0xf9; break;
+ case XK_Sacute: *buf = (unsigned char)0xda; break;
+ case XK_sacute: *buf = (unsigned char)0xfa; break;
+ case XK_Zabovedot: *buf = (unsigned char)0xdd; break;
+ case XK_zabovedot: *buf = (unsigned char)0xfd; break;
+ case XK_Zcaron: *buf = (unsigned char)0xde; break;
+ case XK_zcaron: *buf = (unsigned char)0xfe; break;
+ default: count = 0;
+ }
} else count = 0;
} else if ((keysym >> 8) == sLatin3) {
if (locale_code == sLatin5) {
@@ -725,6 +774,37 @@ _XimGetCharCode (locale_code, keysym, buf, nbytes)
case XK_uogonek: *buf = (unsigned char)(keysym & 0xff); break;
default: count = 0;
}
+ } else if (locale_code == sLatin7) {
+ count = 1;
+ switch (keysym) {
+ case XK_Emacron: *buf = (unsigned char)0xc7; break;
+ case XK_emacron: *buf = (unsigned char)0xe7; break;
+ case XK_Gcedilla: *buf = (unsigned char)0xcc; break;
+ case XK_gcedilla: *buf = (unsigned char)0xec; break;
+ case XK_Rcedilla: *buf = (unsigned char)0xaa; break;
+ case XK_rcedilla: *buf = (unsigned char)0xba; break;
+ case XK_Imacron: *buf = (unsigned char)0xce; break;
+ case XK_imacron: *buf = (unsigned char)0xee; break;
+ case XK_Lcedilla: *buf = (unsigned char)0xcf; break;
+ case XK_lcedilla: *buf = (unsigned char)0xef; break;
+ case XK_Umacron: *buf = (unsigned char)0xdb; break;
+ case XK_umacron: *buf = (unsigned char)0xfb; break;
+ case XK_Amacron: *buf = (unsigned char)0xc2; break;
+ case XK_amacron: *buf = (unsigned char)0xe2; break;
+ case XK_Kcedilla: *buf = (unsigned char)0xcd; break;
+ case XK_kcedilla: *buf = (unsigned char)0xed; break;
+ case XK_Iogonek: *buf = (unsigned char)0xc1; break;
+ case XK_iogonek: *buf = (unsigned char)0xe1; break;
+ case XK_Eabovedot: *buf = (unsigned char)0xcb; break;
+ case XK_eabovedot: *buf = (unsigned char)0xeb; break;
+ case XK_Ncedilla: *buf = (unsigned char)0xd2; break;
+ case XK_ncedilla: *buf = (unsigned char)0xf2; break;
+ case XK_Omacron: *buf = (unsigned char)0xd4; break;
+ case XK_omacron: *buf = (unsigned char)0xf4; break;
+ case XK_Uogonek: *buf = (unsigned char)0xd8; break;
+ case XK_uogonek: *buf = (unsigned char)0xf8; break;
+ default: count = 0;
+ }
}
} else if (locale_code == sLatin9 && keysym == XK_EuroSign) {
count = 1;
@@ -772,13 +852,11 @@ _XimLookupMBText(ic, event, buffer, nbytes, keysym, status)
KeySym* keysym;
XComposeStatus* status;
{
- int count, local_count;
+ int count;
KeySym symbol;
- struct CodesetRec *cset;
Status dummy;
Xim im = (Xim)ic->core.im;
- XLCd lcd = im->core.lcd;
- unsigned char local_buf[BUF_SIZE];
+ XimCommonPrivateRec* private = &im->private.common;
unsigned char look[BUF_SIZE];
/* force a latin-1 lookup for compatibility */
@@ -786,25 +864,7 @@ _XimLookupMBText(ic, event, buffer, nbytes, keysym, status)
if (keysym != NULL) *keysym = symbol;
if ((nbytes == 0) || (symbol == NoSymbol)) return count;
- _XimGetLocaleCode(XLC_PUBLIC(lcd,encoding_name), (XPointer *) &cset);
-
- if ((count == 0 && cset != NULL) ||
- (count == 1 && (symbol > 0x7f && symbol < 0xff00) &&
- cset->locale_code != 0)) {
- if ((count = _XimGetCharCode(cset->locale_code, symbol,
- look, sizeof look))) {
- strcpy((char*) local_buf, cset->escape_seq);
- local_count = strlen(cset->escape_seq);
- strncpy((char *)(&local_buf[local_count]), (char *)look, count);
- local_count += local_count;
- local_buf[local_count] = '\0';
- if ((count = im->methods->ctstombs(ic->core.im,
- (char*) local_buf, local_count,
- (char *)buffer, nbytes, &dummy)) < 0) {
- count = 0;
- }
- }
- } else if (count > 1) { /* not ASCII Encoding */
+ if (count > 1) {
memcpy(look, (char *)buffer,count);
look[count] = '\0';
if ((count = im->methods->ctstombs(ic->core.im,
@@ -812,6 +872,28 @@ _XimLookupMBText(ic, event, buffer, nbytes, keysym, status)
buffer, nbytes, &dummy)) < 0) {
count = 0;
}
+ } else if ((count == 0) ||
+ (count == 1 && (symbol > 0x7f && symbol < 0xff00) &&
+ private->locale_code != 0)) {
+ if ((count = _XimGetCharCode(private->locale_code, symbol,
+ look, sizeof look))) {
+
+ XPointer args[1];
+ unsigned char *from = look;
+ unsigned char *to = (unsigned char*) buffer;
+ int from_len = count;
+ int to_len = nbytes;
+ args[0] = (XPointer) private->keyboard_charset;
+
+ if ((count = _XlcConvert(private->cstomb_conv,
+ (XPointer*) &from, &from_len,
+ (XPointer*) &to, &to_len,
+ args, 1 )) != 0) {
+ count = 0;
+ } else {
+ count = nbytes - to_len;
+ }
+ }
}
/*
* we should make sure that if the character is a Latin1 character
@@ -830,13 +912,11 @@ _XimLookupWCText(ic, event, buffer, nbytes, keysym, status)
KeySym* keysym;
XComposeStatus* status;
{
- int count, local_count;
+ int count;
KeySym symbol;
- struct CodesetRec *cset;
Status dummy;
Xim im = (Xim)ic->core.im;
- XLCd lcd = im->core.lcd;
- unsigned char local_buf[BUF_SIZE];
+ XimCommonPrivateRec* private = &im->private.common;
unsigned char look[BUF_SIZE];
/* force a latin-1 lookup for compatibility */
@@ -844,30 +924,33 @@ _XimLookupWCText(ic, event, buffer, nbytes, keysym, status)
if (keysym != NULL) *keysym = symbol;
if ((nbytes == 0) || (symbol == NoSymbol)) return count;
- _XimGetLocaleCode(XLC_PUBLIC(lcd,encoding_name), (XPointer *) &cset);
-
- if ((count == 0 && cset != NULL) ||
- (count == 1 && (symbol > 0x7f && symbol < 0xff00) &&
- cset->locale_code != 0)) {
- if ((count = _XimGetCharCode(cset->locale_code, symbol,
- look, sizeof look))) {
- strcpy((char*) local_buf, cset->escape_seq);
- local_count = strlen(cset->escape_seq);
- strncpy((char *)(&local_buf[local_count]), (char *)look, count);
- local_count += count;
- local_buf[local_count] = '\0';
- if ((count = im->methods->ctstowcs(ic->core.im,
- (char*) local_buf, local_count,
- buffer, nbytes, &dummy)) < 0) {
- count = 0;
- }
- }
- } else if (count > 1) {
+ if (count > 1) {
if ((count = im->methods->ctstowcs(ic->core.im,
(char*) look, count,
buffer, nbytes, &dummy)) < 0) {
count = 0;
}
+ } else if ((count == 0) ||
+ (count == 1 && (symbol > 0x7f && symbol < 0xff00) &&
+ private->locale_code != 0)) {
+ if ((count = _XimGetCharCode(private->locale_code, symbol,
+ look, sizeof look))) {
+ XPointer args[1];
+ unsigned char *from = look;
+ wchar_t *to = buffer;
+ int from_len = count;
+ int to_len = nbytes;
+ args[0] = (XPointer) private->keyboard_charset;
+
+ if ((count = _XlcConvert(private->cstowc_conv,
+ (XPointer*) &from, &from_len,
+ (XPointer*) &to, &to_len,
+ args, 1 )) != 0) {
+ count = 0;
+ } else {
+ count = nbytes - to_len;
+ }
+ }
} else
/*
* we should make sure that if the character is a Latin1 character