aboutsummaryrefslogtreecommitdiff
path: root/libX11/modules
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-09-12 11:27:51 +0200
committermarha <marha@users.sourceforge.net>2011-09-12 11:27:51 +0200
commitdafebc5bb70303f0b5baf0b087cf4d9a64b5c7f0 (patch)
treebdf833cc6a4fc9035411779e10dd9e8478201885 /libX11/modules
parent0b40f5f4b54453a77f4b09c431f8efc6875da61f (diff)
downloadvcxsrv-dafebc5bb70303f0b5baf0b087cf4d9a64b5c7f0.tar.gz
vcxsrv-dafebc5bb70303f0b5baf0b087cf4d9a64b5c7f0.tar.bz2
vcxsrv-dafebc5bb70303f0b5baf0b087cf4d9a64b5c7f0.zip
Synchronised line endinge with release branch
Diffstat (limited to 'libX11/modules')
-rw-r--r--libX11/modules/im/ximcp/imCallbk.c1508
-rw-r--r--libX11/modules/im/ximcp/imDefIc.c3162
-rw-r--r--libX11/modules/im/ximcp/imDefIm.c4088
-rw-r--r--libX11/modules/im/ximcp/imDefLkup.c2340
-rw-r--r--libX11/modules/im/ximcp/imInt.c528
-rw-r--r--libX11/modules/im/ximcp/imLcFlt.c250
-rw-r--r--libX11/modules/im/ximcp/imLcIc.c398
-rw-r--r--libX11/modules/im/ximcp/imLcIm.c1464
-rw-r--r--libX11/modules/im/ximcp/imLcLkup.c834
-rw-r--r--libX11/modules/im/ximcp/imRm.c6394
-rw-r--r--libX11/modules/im/ximcp/imRmAttr.c3030
-rw-r--r--libX11/modules/im/ximcp/imThaiIc.c454
-rw-r--r--libX11/modules/im/ximcp/imTrX.c1036
-rw-r--r--libX11/modules/im/ximcp/imTrans.c630
-rw-r--r--libX11/modules/lc/gen/lcGenConv.c6296
-rw-r--r--libX11/modules/lc/xlocale/lcJis.c1888
-rw-r--r--libX11/modules/om/generic/omGeneric.c4340
17 files changed, 19320 insertions, 19320 deletions
diff --git a/libX11/modules/im/ximcp/imCallbk.c b/libX11/modules/im/ximcp/imCallbk.c
index 761021354..6275bbf00 100644
--- a/libX11/modules/im/ximcp/imCallbk.c
+++ b/libX11/modules/im/ximcp/imCallbk.c
@@ -1,754 +1,754 @@
-/***********************************************************************
-Copyright 1993 by Digital Equipment Corporation, Maynard, Massachusetts,
-Copyright 1994 by FUJITSU LIMITED
-Copyright 1994 by Sony Corporation
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the names of Digital, FUJITSU
-LIMITED and Sony Corporation not be used in advertising or publicity
-pertaining to distribution of the software without specific, written
-prior permission.
-
-DIGITAL, FUJITSU LIMITED AND SONY CORPORATION DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL, FUJITSU LIMITED
-AND SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Hiroyuki Miyamoto Digital Equipment Corporation
- miyamoto@jrd.dec.com
- Modifier: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
- Makoto Wakamatsu Sony Corporation
- makoto@sm.sony.co.jp
-
-***********************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "XlcPubI.h"
-#ifdef X_LOCALE
-#define mblen(a,b) _Xmblen(a,b)
-extern int _Xmblen ();
-#endif
-
-#define sz_CARD8 1
-#define sz_INT8 1
-#define sz_CARD16 2
-#define sz_INT16 2
-#define sz_BITMASK16 sz_CARD16
-#define sz_CARD32 4
-#define sz_INT32 4
-#define sz_BITMASK32 sz_CARD32
-#define sz_XIMID sizeof(XIMID)
-#define sz_XICID sizeof(XICID)
-#define sz_XIMATTRID sizeof(XIMATTRID)
-#define sz_XICATTRID sizeof(XICATTRID)
-#define sz_ximPacketHeader (XIM_HEADER_SIZE + sz_XIMID + sz_XICID)
-#define sz_ximGeometry 0
-#define sz_ximStrConversion (sz_CARD32 + sz_CARD32 + sz_CARD32 + sz_CARD32)
-#define sz_ximPreeditStart 0
-#define sz_ximPreeditStartReply sz_INT32
-#define sz_ximPreeditCaret (sz_INT32 + sz_CARD32 + sz_CARD32)
-#define sz_ximPreeditCaretReply sz_CARD32
-#define sz_ximPreeditDone 0
-#define sz_ximStatusStart 0
-#define sz_ximStatusDone 0
-
-typedef enum {
- XimCbSuccess,
- XimCbNoCallback,
- XimCbError,
- XimCbQueued,
- XimCbBadContextID,
- XimCbBadOpcode
-} XimCbStatus;
-
-typedef XimCbStatus (*XimCb)(
- Xim, Xic, char*, int
- );
-
-#define PACKET_TO_MAJOROPCODE(p) (*(CARD8*)((CARD8*)(p)))
-#define PACKET_TO_MINOROPCODE(p) (*(CARD8*)((CARD8*)(p) + sz_CARD8))
-#define PACKET_TO_LENGTH(p) (*(CARD16*)((CARD8*)(p) + sz_CARD8 + sz_CARD8))
-#define PACKET_TO_IMID(p) (*(XIMID*)((CARD8*)(p) + XIM_HEADER_SIZE))
-#define PACKET_TO_ICID(p) (*(XICID*)((CARD8*)(p) + XIM_HEADER_SIZE + sz_XIMID))
-
-#define _XimWriteData(im,len,data) \
- (im->private.proto.write((im),(len),(XPointer)(data)))
-#define _XimReadData(im,buf,buf_len,len) \
- (im->private.proto.read((im),(XPointer)(buf),(buf_len),&(len)))
-#define _XimFlushData(im) im->private.proto.flush((im))
-
-Private XimCbStatus _XimGeometryCallback(Xim, Xic, char*, int);
-Private XimCbStatus _XimStrConversionCallback(Xim, Xic, char*, int);
-Private XimCbStatus _XimPreeditStartCallback(Xim, Xic, char*, int);
-Private XimCbStatus _XimPreeditDoneCallback(Xim, Xic, char*, int);
-Private void _free_memory_for_text(XIMText*);
-Private XimCbStatus _XimPreeditDrawCallback(Xim, Xic, char*, int);
-Private XimCbStatus _XimPreeditCaretCallback(Xim, Xic, char*, int);
-Private XimCbStatus _XimStatusStartCallback(Xim, Xic, char*, int);
-Private XimCbStatus _XimStatusDoneCallback(Xim, Xic, char*, int);
-Private XimCbStatus _XimStatusDrawCallback(Xim, Xic, char*, int);
-Private XimCbStatus _XimPreeditStateNotifyCallback(Xim, Xic, char *, int);
-
-#if defined(__STDC__) && ((defined(sun) && defined(SVR4)) || defined(WIN32))
-#define RConst /**/
-#else
-#define RConst const
-#endif
-
-/* NOTE:
- * the table below depends on the protocol number
- * defined in the IM Protocol document.
- */
-static RConst XimCb callback_table[] = {
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #000-009 */
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #010-019 */
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #020-029 */
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #030-039 */
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #040-049 */
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #050-059 */
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #060-069 */
- _XimGeometryCallback, /* #070 */
- _XimStrConversionCallback, /* #071 */
- NULL, /* #072 */
- _XimPreeditStartCallback, /* #073 */
- NULL, /* #074 */
- _XimPreeditDrawCallback, /* #075 */
- _XimPreeditCaretCallback, /* #076 */
- NULL, /* #077 */
- _XimPreeditDoneCallback, /* #078 */
- _XimStatusStartCallback, /* #079 */
- _XimStatusDrawCallback, /* #080 */
- _XimStatusDoneCallback, /* #081 */
- _XimPreeditStateNotifyCallback /* #082 */
- };
-
-
-Private Bool
-_XimIsReadyForProcess(Xic ic)
-{
- return(!ic->private.proto.waitCallback); /* check HM */
-}
-
-Private void
-_XimProcessPendingCallbacks(Xic ic)
-{
- XimPendingCallback pcbq;
-
- while (((pcbq = ic->private.proto.pend_cb_que) != (XimPendingCallback)NULL)
- && _XimIsReadyForProcess(ic)) {
- (void) (*callback_table[pcbq->major_opcode])(pcbq->im,
- pcbq->ic,
- pcbq->proto,
- pcbq->proto_len);
- ic->private.proto.pend_cb_que = pcbq->next;
- Xfree(pcbq->proto); /* free memory of XimPendingCallback */
- Xfree(pcbq);
- }
-}
-
-Private void
-_XimPutCbIntoQueue(Xic ic, XimPendingCallback call_data)
-{
- XimPendingCallback pcbq = ic->private.proto.pend_cb_que;
-
- /* Queuing is FIFO
- */
- while (pcbq != (XimPendingCallback)NULL) {
- if (pcbq->next == (XimPendingCallback)NULL) {
- break;
- }
- pcbq = pcbq->next;
- }
- if (pcbq == (XimPendingCallback)NULL) {
- ic->private.proto.pend_cb_que = call_data;
- }
- else {
- pcbq->next = call_data;
- }
-}
-
-Public Bool
-_XimCbDispatch(Xim xim,
- INT16 len,
- XPointer data,
- XPointer call_data)
-{
- /* `data' points to the beginning of the packet defined in IM Protocol doc.
- */
- int major_opcode = PACKET_TO_MAJOROPCODE(data);
- XIMID imid = PACKET_TO_IMID(data);
- XICID icid = PACKET_TO_ICID(data);
- Xim im = (Xim)call_data; /* check HM */
- Xic ic = _XimICOfXICID(im, icid);
- char* proto;
- int proto_len;
-
- /* check validity of im/ic
- */
- if ((imid != im->private.proto.imid) || !ic) {
- return False; /* status = XimCbBadContextID; */
- }
-
- /* process pending callbacks
- */
- _XimProcessPendingCallbacks(ic);
-
- /* check if the protocol should be processed here
- */
- if (major_opcode > 82) {
- return False; /* status = XimCbBadOpcode; */
- }
- if (!callback_table[major_opcode]) {
- return False; /* status = XimCbBadOpcode; */
- }
-
- /* move the pointer ahead by the IM Protocol packet header size
- */
- proto = (char*)data + sz_ximPacketHeader;
- proto_len = (int)len - sz_ximPacketHeader;
-
- /* check if it can be processed right away
- * and if no, queue the protocol, otherwise invoke a callback
- */
- if (!_XimIsReadyForProcess(ic)) {
-
- /* queue the protocol
- */
- XimPendingCallback pcb;
- char *proto_buf = (proto_len > 0) ? (char*)Xmalloc(proto_len) : NULL;
-
- pcb = (XimPendingCallback)Xmalloc(sizeof(XimPendingCallbackRec));
- if (pcb && (proto_len <= 0 || proto_buf)) {
- if (proto_len > 0)
- memcpy(proto_buf, proto, proto_len);
-
- pcb->major_opcode = major_opcode;
- pcb->im = im;
- pcb->ic = ic;
- pcb->proto = proto_buf;
- pcb->proto_len = proto_len;
- pcb->next = (XimPendingCallback)NULL; /* queue is FIFO */
- _XimPutCbIntoQueue(ic, pcb);
- /* status = XimCbQueued; */
- } else {
- /* status = XimCbError; */
- Xfree(pcb);
- Xfree(proto_buf);
- }
- }
- else {
- /* invoke each callback according to the major opcode.
- * `proto' points to the next address of IM-ID and IC-ID.
- * `proto_len' specifies the packet length.
- */
- (void) (*callback_table[major_opcode])(im, ic, proto, proto_len);
- }
- return True;
-}
-
-Private XimCbStatus
-_XimGeometryCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.geometry_callback;
-
- /* invoke the callack
- */
- if (cb && cb->callback) {
- (*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
- }
- else {
-
- /* no callback registered
- */
- return XimCbNoCallback;
- }
-
- return XimCbSuccess;
-}
-
-Private XimCbStatus
-_XimStrConversionCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.string_conversion_callback; /* check HM */
- XIMStringConversionCallbackStruct cbrec;
-
- /* invoke the callback
- */
- if (cb && cb->callback) {
- int p = XIM_HEADER_SIZE;
- cbrec.position = (XIMStringConversionPosition)
- *(CARD32*)&proto[p]; p += sz_CARD32;
- cbrec.direction = (XIMCaretDirection)
- *(CARD32*)&proto[p]; p += sz_CARD32;
- cbrec.operation = (XIMStringConversionOperation)
- *(CARD32*)&proto[p]; p += sz_CARD32;
- cbrec.factor = (unsigned short)
- *(CARD32*)&proto[p];
-
- (*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbrec);
- }
- else {
-
- /* no callback registered
- */
- _XimError(im, ic,
- (CARD16)XIM_BadSomething,
- (INT16)len,
- (CARD16)XIM_STR_CONVERSION,
- (char*)proto); /* send XIM_ERROR */
- return XimCbNoCallback;
- }
-
- /* send a reply
- */
- {
- CARD8 *buf;
- INT16 buf_len;
- int p, length_in_bytes, i;
-
- /* Assumption:
- * `cbrec.text->length' means the string length in characters
- */
- {
- length_in_bytes = (cbrec.text->encoding_is_wchar)?
- sizeof(wchar_t) * cbrec.text->length: /* wchar */
- strlen(cbrec.text->string.mbs); /* mb */
- buf_len = XIM_HEADER_SIZE +
- sz_CARD16 +
- 2 + length_in_bytes +
- XIM_PAD(2 + length_in_bytes) +
- 2 + 2 + sz_CARD32 * cbrec.text->length;
- buf = (CARD8*)Xmalloc(buf_len);
- }
- _XimSetHeader((XPointer)buf, XIM_STR_CONVERSION_REPLY, 0, &buf_len);
- buf_len -= XIM_HEADER_SIZE; /* added by _XimSetHeader (HACK) */
- p = XIM_HEADER_SIZE;
- *(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
- *(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
- *(CARD16*)&buf[p] = (CARD16)cbrec.text->length; p += sz_CARD16;
- memcpy(&buf[p],&cbrec.text->string.mbs,length_in_bytes);
- p += length_in_bytes;
- *(CARD16*)&buf[p] = (CARD16)(sz_CARD32*cbrec.text->length);
- p += XIM_PAD(2);
- for (i = 0; i < (int)cbrec.text->length; i++) {
- *(CARD32*)&buf[p] = (CARD32)cbrec.text->feedback[i];
- p += sz_CARD32;
- }
-
- if (!(_XimWriteData(im, buf_len, buf))) {
- return XimCbError;
- }
- _XimFlushData(im);
-
- Xfree(buf);
- }
-
- return XimCbSuccess;
-}
-
-Private XimCbStatus
-_XimPreeditStartCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.preedit_attr.start_callback;
- int ret;
-
- /* invoke the callback
- */
- if (cb && cb->callback){
- ret = (*(cb->callback))((XIC)ic, cb->client_data, (XPointer)NULL);
- }
- else {
-
- /* no callback registered
- */
- _XimError(im, ic,
- (CARD16)XIM_BadSomething,
- (INT16)len,
- (CARD16)XIM_PREEDIT_START,
- (char*)proto); /* send XIM_ERROR */
- return XimCbNoCallback;
- }
-
- /* send a reply
- */
- {
- CARD32 buf32[(sz_ximPacketHeader + sz_ximPreeditStartReply) / 4];
- CARD8 *buf = (CARD8 *)buf32;
- INT16 buf_len = sz_XIMID + sz_XICID + sz_ximPreeditStartReply;
- int p;
-
- _XimSetHeader((XPointer)buf, XIM_PREEDIT_START_REPLY, 0, &buf_len);
- p = XIM_HEADER_SIZE;
- *(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
- *(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
- *(INT32*)&buf[p] = (INT32)ret;
-
- if (!(_XimWriteData(im, buf_len, buf))) {
- return XimCbError;
- }
- _XimFlushData(im);
- }
-
- return XimCbSuccess;
-}
-
-Private XimCbStatus
-_XimPreeditDoneCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.preedit_attr.done_callback;
-
- /* invoke the callback
- */
- if (cb && cb->callback) {
- (*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
- }
- else {
-
- /* no callback registered
- */
- return XimCbNoCallback;
- }
-
- return XimCbSuccess;
-}
-
-Private void
-_read_text_from_packet(Xim im,
- char* buf,
- XIMText** text_ptr)
-{
- int status;
- XIMText* text;
- int tmp_len;
- char* tmp_buf;
- Status s = 0;
-
- status = (int)*(BITMASK32*)buf; buf += sz_BITMASK32;
-
- /* string part
- */
- if (status & 0x00000001) /* "no string" bit on */ {
- buf += sz_CARD16; /* skip "length of preedit string" */
- buf += 2; /* pad */
- *text_ptr = (XIMText*)NULL;
- return;
- }
-
- *text_ptr = text = (XIMText*)Xmalloc(sizeof(XIMText));
- if (text == (XIMText*)NULL) return;
-
- tmp_len = (int)*(CARD16*)buf;
- buf += sz_CARD16;
- if ((tmp_buf = (char*)Xmalloc(tmp_len + 1))) {
- memcpy(tmp_buf, buf, tmp_len);
- tmp_buf[tmp_len] = '\0';
-
- text->encoding_is_wchar = False;
- text->length = im->methods->ctstombs((XIM)im,
- tmp_buf, tmp_len,
- NULL, 0, &s); /* CT? HM */
- if (s != XLookupNone) {
-#ifndef NO_DEC_I18N_FIX
- /* Allow for NULL-terminated */
- if ((text->string.multi_byte =
- (char*)Xmalloc(text->length *
- XLC_PUBLIC(im->core.lcd,mb_cur_max) + 1))) {
-#else
- if (text->string.multi_byte = (char*)Xmalloc(text->length+1)) {
-#endif
- int tmp;
-#ifndef NO_DEC_I18N_FIX
- char *char_tmp;
- int char_len;
-#endif
- tmp = im->methods->ctstombs((XIM)im,
- tmp_buf, tmp_len,
-#ifndef NO_DEC_I18N_FIX
- text->string.multi_byte,
- text->length * XLC_PUBLIC(im->core.lcd,mb_cur_max) + 1,
-#else
- text->string.multi_byte, text->length,
-#endif
- &s);
- text->string.multi_byte[tmp] = '\0';
-#ifndef NO_DEC_I18N_FIX
- text->length = 0;
- char_tmp = text->string.multi_byte;
- while (*char_tmp != '\0') {
- char_len = mblen(char_tmp, strlen(char_tmp));
- char_tmp = char_tmp + char_len;
- (text->length)++;
- }
-#endif
- }
- }
- else {
- text->length = 0;
- text->string.multi_byte = NULL;
- }
-
- Xfree(tmp_buf);
- }
- buf += tmp_len;
-
- buf += XIM_PAD(sz_CARD16 + tmp_len); /* pad */
-
- /* feedback part
- */
- if (status & 0x00000002) /* "no feedback" bit on */ {
- text->feedback = (XIMFeedback*)NULL;
- }
- else {
- int i, j;
-
- i = (int)*(CARD16*)buf; buf += sz_CARD16;
- buf += sz_CARD16; /* skip `unused' */
- text->feedback = (XIMFeedback*)Xmalloc(i*(sizeof(XIMFeedback)/sizeof(CARD32)));
- j = 0;
- while (i > 0) {
- text->feedback[j] = (XIMFeedback)*(CARD32*)buf;
- buf += sz_CARD32;
- i -= sz_CARD32;
- j++;
- }
- /*
- * text->length tells how long both the status string and
- * the feedback array are. If there's "no string" the
- * text->length was set to zero previously. See above.
- * But if there is feedback (i.e. not "no feedback") then
- * we need to convey the length of the feedback array.
- * It might have been better if the protocol sent two
- * different values, one for the length of the status
- * string and one for the length of the feedback array.
- */
- if (status & 0x00000001) /* "no string" bit on */ {
- text->length = j;
- }
- }
-}
-
-Private void
-_free_memory_for_text(XIMText* text)
-{
- if (text) {
- if (text->string.multi_byte)
- Xfree(text->string.multi_byte);
- if (text->feedback)
- Xfree(text->feedback);
- Xfree(text);
- }
-}
-
-Private XimCbStatus
-_XimPreeditDrawCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.preedit_attr.draw_callback;
- XIMPreeditDrawCallbackStruct cbs;
-
- /* invoke the callback
- */
- if (cb && cb->callback) {
- cbs.caret = (int)*(INT32*)proto; proto += sz_INT32;
- cbs.chg_first = (int)*(INT32*)proto; proto += sz_INT32;
- cbs.chg_length = (int)*(INT32*)proto; proto += sz_INT32;
- _read_text_from_packet(im, proto, &cbs.text);
-
- (*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
-
- _free_memory_for_text((XIMText*)cbs.text);
- }
- else {
-
- /* no callback registered
- */
- return XimCbNoCallback;
- }
-
- return XimCbSuccess;
-}
-
-Private XimCbStatus
-_XimPreeditCaretCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.preedit_attr.caret_callback;
- XIMPreeditCaretCallbackStruct cbs;
-
- /* invoke the callback
- */
- if (cb && cb->callback) {
- cbs.position = (int)*(INT32*)proto; proto += sz_INT32;
- cbs.direction = (XIMCaretDirection)*(CARD32*)proto; proto += sz_CARD32;
- cbs.style = (XIMCaretStyle)*(CARD32*)proto; proto += sz_CARD32;
-
- (*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
- }
- else {
-
- /* no callback registered
- */
- _XimError(im, ic,
- (CARD16)XIM_BadSomething,
- (INT16)len,
- (CARD16)XIM_PREEDIT_CARET,
- (char*)proto); /* send XIM_ERROR */
- return XimCbNoCallback;
- }
-
- /* Send a reply
- */
- {
- CARD8 buf[sz_ximPacketHeader + sz_ximPreeditCaretReply];
- INT16 len = sz_XIMID + sz_XICID + sz_ximPreeditCaretReply;
- int p;
-
- _XimSetHeader((XPointer)buf, XIM_PREEDIT_CARET_REPLY, 0, &len);
- p = XIM_HEADER_SIZE;
- *(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
- *(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
- *(CARD32*)&buf[p] = (CARD32)cbs.position;
-
- if (!(_XimWriteData(im, len, buf))) {
- return XimCbError;
- }
- _XimFlushData(im);
- }
-
- return XimCbSuccess;
-}
-
-Private XimCbStatus
-_XimStatusStartCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.status_attr.start_callback;
-
- /* invoke the callback
- */
- if (cb && cb->callback) {
- (*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
- }
- else {
-
- /* no callback registered
- */
- return XimCbNoCallback;
- }
-
- return XimCbSuccess;
-}
-
-Private XimCbStatus
-_XimStatusDoneCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.status_attr.done_callback;
-
- /* invoke the callback
- */
- if (cb && cb->callback) {
- (*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
- }
- else {
-
- /* no callback registered
- */
- return XimCbNoCallback;
- }
-
- return XimCbSuccess;
-}
-
-Private XimCbStatus
-_XimStatusDrawCallback(Xim im,
- Xic ic,
- char* proto,
- int len)
-{
- XICCallback* cb = &ic->core.status_attr.draw_callback;
- XIMStatusDrawCallbackStruct cbs;
-
- /* invoke the callback
- */
- if (cb && cb->callback) {
- cbs.type = (XIMStatusDataType)*(CARD32*)proto; proto += sz_CARD32;
- if (cbs.type == XIMTextType) {
- _read_text_from_packet(im, proto, &cbs.data.text);
- }
- else if (cbs.type == XIMBitmapType) {
- cbs.data.bitmap = (Pixmap)*(CARD32*)proto;
- }
-
- (*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
-
- if (cbs.type == XIMTextType)
- _free_memory_for_text((XIMText *)cbs.data.text);
- }
- else {
-
- /* no callback registered
- */
- return XimCbNoCallback;
- }
-
- return XimCbSuccess;
-}
-
-Private XimCbStatus
-_XimPreeditStateNotifyCallback( Xim im, Xic ic, char* proto, int len )
-{
- XICCallback *cb = &ic->core.preedit_attr.state_notify_callback;
-
- /* invoke the callack
- */
- if( cb && cb->callback ) {
- XIMPreeditStateNotifyCallbackStruct cbrec;
-
- cbrec.state = *(BITMASK32 *)proto;
- (*cb->callback)( (XIC)ic, cb->client_data, (XPointer)&cbrec );
- }
- else {
- /* no callback registered
- */
- return XimCbNoCallback;
- }
-
- return XimCbSuccess;
-}
-
+/***********************************************************************
+Copyright 1993 by Digital Equipment Corporation, Maynard, Massachusetts,
+Copyright 1994 by FUJITSU LIMITED
+Copyright 1994 by Sony Corporation
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Digital, FUJITSU
+LIMITED and Sony Corporation not be used in advertising or publicity
+pertaining to distribution of the software without specific, written
+prior permission.
+
+DIGITAL, FUJITSU LIMITED AND SONY CORPORATION DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL, FUJITSU LIMITED
+AND SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Hiroyuki Miyamoto Digital Equipment Corporation
+ miyamoto@jrd.dec.com
+ Modifier: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+ Makoto Wakamatsu Sony Corporation
+ makoto@sm.sony.co.jp
+
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "XlcPubI.h"
+#ifdef X_LOCALE
+#define mblen(a,b) _Xmblen(a,b)
+extern int _Xmblen ();
+#endif
+
+#define sz_CARD8 1
+#define sz_INT8 1
+#define sz_CARD16 2
+#define sz_INT16 2
+#define sz_BITMASK16 sz_CARD16
+#define sz_CARD32 4
+#define sz_INT32 4
+#define sz_BITMASK32 sz_CARD32
+#define sz_XIMID sizeof(XIMID)
+#define sz_XICID sizeof(XICID)
+#define sz_XIMATTRID sizeof(XIMATTRID)
+#define sz_XICATTRID sizeof(XICATTRID)
+#define sz_ximPacketHeader (XIM_HEADER_SIZE + sz_XIMID + sz_XICID)
+#define sz_ximGeometry 0
+#define sz_ximStrConversion (sz_CARD32 + sz_CARD32 + sz_CARD32 + sz_CARD32)
+#define sz_ximPreeditStart 0
+#define sz_ximPreeditStartReply sz_INT32
+#define sz_ximPreeditCaret (sz_INT32 + sz_CARD32 + sz_CARD32)
+#define sz_ximPreeditCaretReply sz_CARD32
+#define sz_ximPreeditDone 0
+#define sz_ximStatusStart 0
+#define sz_ximStatusDone 0
+
+typedef enum {
+ XimCbSuccess,
+ XimCbNoCallback,
+ XimCbError,
+ XimCbQueued,
+ XimCbBadContextID,
+ XimCbBadOpcode
+} XimCbStatus;
+
+typedef XimCbStatus (*XimCb)(
+ Xim, Xic, char*, int
+ );
+
+#define PACKET_TO_MAJOROPCODE(p) (*(CARD8*)((CARD8*)(p)))
+#define PACKET_TO_MINOROPCODE(p) (*(CARD8*)((CARD8*)(p) + sz_CARD8))
+#define PACKET_TO_LENGTH(p) (*(CARD16*)((CARD8*)(p) + sz_CARD8 + sz_CARD8))
+#define PACKET_TO_IMID(p) (*(XIMID*)((CARD8*)(p) + XIM_HEADER_SIZE))
+#define PACKET_TO_ICID(p) (*(XICID*)((CARD8*)(p) + XIM_HEADER_SIZE + sz_XIMID))
+
+#define _XimWriteData(im,len,data) \
+ (im->private.proto.write((im),(len),(XPointer)(data)))
+#define _XimReadData(im,buf,buf_len,len) \
+ (im->private.proto.read((im),(XPointer)(buf),(buf_len),&(len)))
+#define _XimFlushData(im) im->private.proto.flush((im))
+
+Private XimCbStatus _XimGeometryCallback(Xim, Xic, char*, int);
+Private XimCbStatus _XimStrConversionCallback(Xim, Xic, char*, int);
+Private XimCbStatus _XimPreeditStartCallback(Xim, Xic, char*, int);
+Private XimCbStatus _XimPreeditDoneCallback(Xim, Xic, char*, int);
+Private void _free_memory_for_text(XIMText*);
+Private XimCbStatus _XimPreeditDrawCallback(Xim, Xic, char*, int);
+Private XimCbStatus _XimPreeditCaretCallback(Xim, Xic, char*, int);
+Private XimCbStatus _XimStatusStartCallback(Xim, Xic, char*, int);
+Private XimCbStatus _XimStatusDoneCallback(Xim, Xic, char*, int);
+Private XimCbStatus _XimStatusDrawCallback(Xim, Xic, char*, int);
+Private XimCbStatus _XimPreeditStateNotifyCallback(Xim, Xic, char *, int);
+
+#if defined(__STDC__) && ((defined(sun) && defined(SVR4)) || defined(WIN32))
+#define RConst /**/
+#else
+#define RConst const
+#endif
+
+/* NOTE:
+ * the table below depends on the protocol number
+ * defined in the IM Protocol document.
+ */
+static RConst XimCb callback_table[] = {
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #000-009 */
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #010-019 */
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #020-029 */
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #030-039 */
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #040-049 */
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #050-059 */
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #060-069 */
+ _XimGeometryCallback, /* #070 */
+ _XimStrConversionCallback, /* #071 */
+ NULL, /* #072 */
+ _XimPreeditStartCallback, /* #073 */
+ NULL, /* #074 */
+ _XimPreeditDrawCallback, /* #075 */
+ _XimPreeditCaretCallback, /* #076 */
+ NULL, /* #077 */
+ _XimPreeditDoneCallback, /* #078 */
+ _XimStatusStartCallback, /* #079 */
+ _XimStatusDrawCallback, /* #080 */
+ _XimStatusDoneCallback, /* #081 */
+ _XimPreeditStateNotifyCallback /* #082 */
+ };
+
+
+Private Bool
+_XimIsReadyForProcess(Xic ic)
+{
+ return(!ic->private.proto.waitCallback); /* check HM */
+}
+
+Private void
+_XimProcessPendingCallbacks(Xic ic)
+{
+ XimPendingCallback pcbq;
+
+ while (((pcbq = ic->private.proto.pend_cb_que) != (XimPendingCallback)NULL)
+ && _XimIsReadyForProcess(ic)) {
+ (void) (*callback_table[pcbq->major_opcode])(pcbq->im,
+ pcbq->ic,
+ pcbq->proto,
+ pcbq->proto_len);
+ ic->private.proto.pend_cb_que = pcbq->next;
+ Xfree(pcbq->proto); /* free memory of XimPendingCallback */
+ Xfree(pcbq);
+ }
+}
+
+Private void
+_XimPutCbIntoQueue(Xic ic, XimPendingCallback call_data)
+{
+ XimPendingCallback pcbq = ic->private.proto.pend_cb_que;
+
+ /* Queuing is FIFO
+ */
+ while (pcbq != (XimPendingCallback)NULL) {
+ if (pcbq->next == (XimPendingCallback)NULL) {
+ break;
+ }
+ pcbq = pcbq->next;
+ }
+ if (pcbq == (XimPendingCallback)NULL) {
+ ic->private.proto.pend_cb_que = call_data;
+ }
+ else {
+ pcbq->next = call_data;
+ }
+}
+
+Public Bool
+_XimCbDispatch(Xim xim,
+ INT16 len,
+ XPointer data,
+ XPointer call_data)
+{
+ /* `data' points to the beginning of the packet defined in IM Protocol doc.
+ */
+ int major_opcode = PACKET_TO_MAJOROPCODE(data);
+ XIMID imid = PACKET_TO_IMID(data);
+ XICID icid = PACKET_TO_ICID(data);
+ Xim im = (Xim)call_data; /* check HM */
+ Xic ic = _XimICOfXICID(im, icid);
+ char* proto;
+ int proto_len;
+
+ /* check validity of im/ic
+ */
+ if ((imid != im->private.proto.imid) || !ic) {
+ return False; /* status = XimCbBadContextID; */
+ }
+
+ /* process pending callbacks
+ */
+ _XimProcessPendingCallbacks(ic);
+
+ /* check if the protocol should be processed here
+ */
+ if (major_opcode > 82) {
+ return False; /* status = XimCbBadOpcode; */
+ }
+ if (!callback_table[major_opcode]) {
+ return False; /* status = XimCbBadOpcode; */
+ }
+
+ /* move the pointer ahead by the IM Protocol packet header size
+ */
+ proto = (char*)data + sz_ximPacketHeader;
+ proto_len = (int)len - sz_ximPacketHeader;
+
+ /* check if it can be processed right away
+ * and if no, queue the protocol, otherwise invoke a callback
+ */
+ if (!_XimIsReadyForProcess(ic)) {
+
+ /* queue the protocol
+ */
+ XimPendingCallback pcb;
+ char *proto_buf = (proto_len > 0) ? (char*)Xmalloc(proto_len) : NULL;
+
+ pcb = (XimPendingCallback)Xmalloc(sizeof(XimPendingCallbackRec));
+ if (pcb && (proto_len <= 0 || proto_buf)) {
+ if (proto_len > 0)
+ memcpy(proto_buf, proto, proto_len);
+
+ pcb->major_opcode = major_opcode;
+ pcb->im = im;
+ pcb->ic = ic;
+ pcb->proto = proto_buf;
+ pcb->proto_len = proto_len;
+ pcb->next = (XimPendingCallback)NULL; /* queue is FIFO */
+ _XimPutCbIntoQueue(ic, pcb);
+ /* status = XimCbQueued; */
+ } else {
+ /* status = XimCbError; */
+ Xfree(pcb);
+ Xfree(proto_buf);
+ }
+ }
+ else {
+ /* invoke each callback according to the major opcode.
+ * `proto' points to the next address of IM-ID and IC-ID.
+ * `proto_len' specifies the packet length.
+ */
+ (void) (*callback_table[major_opcode])(im, ic, proto, proto_len);
+ }
+ return True;
+}
+
+Private XimCbStatus
+_XimGeometryCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.geometry_callback;
+
+ /* invoke the callack
+ */
+ if (cb && cb->callback) {
+ (*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
+ }
+ else {
+
+ /* no callback registered
+ */
+ return XimCbNoCallback;
+ }
+
+ return XimCbSuccess;
+}
+
+Private XimCbStatus
+_XimStrConversionCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.string_conversion_callback; /* check HM */
+ XIMStringConversionCallbackStruct cbrec;
+
+ /* invoke the callback
+ */
+ if (cb && cb->callback) {
+ int p = XIM_HEADER_SIZE;
+ cbrec.position = (XIMStringConversionPosition)
+ *(CARD32*)&proto[p]; p += sz_CARD32;
+ cbrec.direction = (XIMCaretDirection)
+ *(CARD32*)&proto[p]; p += sz_CARD32;
+ cbrec.operation = (XIMStringConversionOperation)
+ *(CARD32*)&proto[p]; p += sz_CARD32;
+ cbrec.factor = (unsigned short)
+ *(CARD32*)&proto[p];
+
+ (*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbrec);
+ }
+ else {
+
+ /* no callback registered
+ */
+ _XimError(im, ic,
+ (CARD16)XIM_BadSomething,
+ (INT16)len,
+ (CARD16)XIM_STR_CONVERSION,
+ (char*)proto); /* send XIM_ERROR */
+ return XimCbNoCallback;
+ }
+
+ /* send a reply
+ */
+ {
+ CARD8 *buf;
+ INT16 buf_len;
+ int p, length_in_bytes, i;
+
+ /* Assumption:
+ * `cbrec.text->length' means the string length in characters
+ */
+ {
+ length_in_bytes = (cbrec.text->encoding_is_wchar)?
+ sizeof(wchar_t) * cbrec.text->length: /* wchar */
+ strlen(cbrec.text->string.mbs); /* mb */
+ buf_len = XIM_HEADER_SIZE +
+ sz_CARD16 +
+ 2 + length_in_bytes +
+ XIM_PAD(2 + length_in_bytes) +
+ 2 + 2 + sz_CARD32 * cbrec.text->length;
+ buf = (CARD8*)Xmalloc(buf_len);
+ }
+ _XimSetHeader((XPointer)buf, XIM_STR_CONVERSION_REPLY, 0, &buf_len);
+ buf_len -= XIM_HEADER_SIZE; /* added by _XimSetHeader (HACK) */
+ p = XIM_HEADER_SIZE;
+ *(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
+ *(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
+ *(CARD16*)&buf[p] = (CARD16)cbrec.text->length; p += sz_CARD16;
+ memcpy(&buf[p],&cbrec.text->string.mbs,length_in_bytes);
+ p += length_in_bytes;
+ *(CARD16*)&buf[p] = (CARD16)(sz_CARD32*cbrec.text->length);
+ p += XIM_PAD(2);
+ for (i = 0; i < (int)cbrec.text->length; i++) {
+ *(CARD32*)&buf[p] = (CARD32)cbrec.text->feedback[i];
+ p += sz_CARD32;
+ }
+
+ if (!(_XimWriteData(im, buf_len, buf))) {
+ return XimCbError;
+ }
+ _XimFlushData(im);
+
+ Xfree(buf);
+ }
+
+ return XimCbSuccess;
+}
+
+Private XimCbStatus
+_XimPreeditStartCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.preedit_attr.start_callback;
+ int ret;
+
+ /* invoke the callback
+ */
+ if (cb && cb->callback){
+ ret = (*(cb->callback))((XIC)ic, cb->client_data, (XPointer)NULL);
+ }
+ else {
+
+ /* no callback registered
+ */
+ _XimError(im, ic,
+ (CARD16)XIM_BadSomething,
+ (INT16)len,
+ (CARD16)XIM_PREEDIT_START,
+ (char*)proto); /* send XIM_ERROR */
+ return XimCbNoCallback;
+ }
+
+ /* send a reply
+ */
+ {
+ CARD32 buf32[(sz_ximPacketHeader + sz_ximPreeditStartReply) / 4];
+ CARD8 *buf = (CARD8 *)buf32;
+ INT16 buf_len = sz_XIMID + sz_XICID + sz_ximPreeditStartReply;
+ int p;
+
+ _XimSetHeader((XPointer)buf, XIM_PREEDIT_START_REPLY, 0, &buf_len);
+ p = XIM_HEADER_SIZE;
+ *(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
+ *(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
+ *(INT32*)&buf[p] = (INT32)ret;
+
+ if (!(_XimWriteData(im, buf_len, buf))) {
+ return XimCbError;
+ }
+ _XimFlushData(im);
+ }
+
+ return XimCbSuccess;
+}
+
+Private XimCbStatus
+_XimPreeditDoneCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.preedit_attr.done_callback;
+
+ /* invoke the callback
+ */
+ if (cb && cb->callback) {
+ (*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
+ }
+ else {
+
+ /* no callback registered
+ */
+ return XimCbNoCallback;
+ }
+
+ return XimCbSuccess;
+}
+
+Private void
+_read_text_from_packet(Xim im,
+ char* buf,
+ XIMText** text_ptr)
+{
+ int status;
+ XIMText* text;
+ int tmp_len;
+ char* tmp_buf;
+ Status s = 0;
+
+ status = (int)*(BITMASK32*)buf; buf += sz_BITMASK32;
+
+ /* string part
+ */
+ if (status & 0x00000001) /* "no string" bit on */ {
+ buf += sz_CARD16; /* skip "length of preedit string" */
+ buf += 2; /* pad */
+ *text_ptr = (XIMText*)NULL;
+ return;
+ }
+
+ *text_ptr = text = (XIMText*)Xmalloc(sizeof(XIMText));
+ if (text == (XIMText*)NULL) return;
+
+ tmp_len = (int)*(CARD16*)buf;
+ buf += sz_CARD16;
+ if ((tmp_buf = (char*)Xmalloc(tmp_len + 1))) {
+ memcpy(tmp_buf, buf, tmp_len);
+ tmp_buf[tmp_len] = '\0';
+
+ text->encoding_is_wchar = False;
+ text->length = im->methods->ctstombs((XIM)im,
+ tmp_buf, tmp_len,
+ NULL, 0, &s); /* CT? HM */
+ if (s != XLookupNone) {
+#ifndef NO_DEC_I18N_FIX
+ /* Allow for NULL-terminated */
+ if ((text->string.multi_byte =
+ (char*)Xmalloc(text->length *
+ XLC_PUBLIC(im->core.lcd,mb_cur_max) + 1))) {
+#else
+ if (text->string.multi_byte = (char*)Xmalloc(text->length+1)) {
+#endif
+ int tmp;
+#ifndef NO_DEC_I18N_FIX
+ char *char_tmp;
+ int char_len;
+#endif
+ tmp = im->methods->ctstombs((XIM)im,
+ tmp_buf, tmp_len,
+#ifndef NO_DEC_I18N_FIX
+ text->string.multi_byte,
+ text->length * XLC_PUBLIC(im->core.lcd,mb_cur_max) + 1,
+#else
+ text->string.multi_byte, text->length,
+#endif
+ &s);
+ text->string.multi_byte[tmp] = '\0';
+#ifndef NO_DEC_I18N_FIX
+ text->length = 0;
+ char_tmp = text->string.multi_byte;
+ while (*char_tmp != '\0') {
+ char_len = mblen(char_tmp, strlen(char_tmp));
+ char_tmp = char_tmp + char_len;
+ (text->length)++;
+ }
+#endif
+ }
+ }
+ else {
+ text->length = 0;
+ text->string.multi_byte = NULL;
+ }
+
+ Xfree(tmp_buf);
+ }
+ buf += tmp_len;
+
+ buf += XIM_PAD(sz_CARD16 + tmp_len); /* pad */
+
+ /* feedback part
+ */
+ if (status & 0x00000002) /* "no feedback" bit on */ {
+ text->feedback = (XIMFeedback*)NULL;
+ }
+ else {
+ int i, j;
+
+ i = (int)*(CARD16*)buf; buf += sz_CARD16;
+ buf += sz_CARD16; /* skip `unused' */
+ text->feedback = (XIMFeedback*)Xmalloc(i*(sizeof(XIMFeedback)/sizeof(CARD32)));
+ j = 0;
+ while (i > 0) {
+ text->feedback[j] = (XIMFeedback)*(CARD32*)buf;
+ buf += sz_CARD32;
+ i -= sz_CARD32;
+ j++;
+ }
+ /*
+ * text->length tells how long both the status string and
+ * the feedback array are. If there's "no string" the
+ * text->length was set to zero previously. See above.
+ * But if there is feedback (i.e. not "no feedback") then
+ * we need to convey the length of the feedback array.
+ * It might have been better if the protocol sent two
+ * different values, one for the length of the status
+ * string and one for the length of the feedback array.
+ */
+ if (status & 0x00000001) /* "no string" bit on */ {
+ text->length = j;
+ }
+ }
+}
+
+Private void
+_free_memory_for_text(XIMText* text)
+{
+ if (text) {
+ if (text->string.multi_byte)
+ Xfree(text->string.multi_byte);
+ if (text->feedback)
+ Xfree(text->feedback);
+ Xfree(text);
+ }
+}
+
+Private XimCbStatus
+_XimPreeditDrawCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.preedit_attr.draw_callback;
+ XIMPreeditDrawCallbackStruct cbs;
+
+ /* invoke the callback
+ */
+ if (cb && cb->callback) {
+ cbs.caret = (int)*(INT32*)proto; proto += sz_INT32;
+ cbs.chg_first = (int)*(INT32*)proto; proto += sz_INT32;
+ cbs.chg_length = (int)*(INT32*)proto; proto += sz_INT32;
+ _read_text_from_packet(im, proto, &cbs.text);
+
+ (*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
+
+ _free_memory_for_text((XIMText*)cbs.text);
+ }
+ else {
+
+ /* no callback registered
+ */
+ return XimCbNoCallback;
+ }
+
+ return XimCbSuccess;
+}
+
+Private XimCbStatus
+_XimPreeditCaretCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.preedit_attr.caret_callback;
+ XIMPreeditCaretCallbackStruct cbs;
+
+ /* invoke the callback
+ */
+ if (cb && cb->callback) {
+ cbs.position = (int)*(INT32*)proto; proto += sz_INT32;
+ cbs.direction = (XIMCaretDirection)*(CARD32*)proto; proto += sz_CARD32;
+ cbs.style = (XIMCaretStyle)*(CARD32*)proto; proto += sz_CARD32;
+
+ (*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
+ }
+ else {
+
+ /* no callback registered
+ */
+ _XimError(im, ic,
+ (CARD16)XIM_BadSomething,
+ (INT16)len,
+ (CARD16)XIM_PREEDIT_CARET,
+ (char*)proto); /* send XIM_ERROR */
+ return XimCbNoCallback;
+ }
+
+ /* Send a reply
+ */
+ {
+ CARD8 buf[sz_ximPacketHeader + sz_ximPreeditCaretReply];
+ INT16 len = sz_XIMID + sz_XICID + sz_ximPreeditCaretReply;
+ int p;
+
+ _XimSetHeader((XPointer)buf, XIM_PREEDIT_CARET_REPLY, 0, &len);
+ p = XIM_HEADER_SIZE;
+ *(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
+ *(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
+ *(CARD32*)&buf[p] = (CARD32)cbs.position;
+
+ if (!(_XimWriteData(im, len, buf))) {
+ return XimCbError;
+ }
+ _XimFlushData(im);
+ }
+
+ return XimCbSuccess;
+}
+
+Private XimCbStatus
+_XimStatusStartCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.status_attr.start_callback;
+
+ /* invoke the callback
+ */
+ if (cb && cb->callback) {
+ (*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
+ }
+ else {
+
+ /* no callback registered
+ */
+ return XimCbNoCallback;
+ }
+
+ return XimCbSuccess;
+}
+
+Private XimCbStatus
+_XimStatusDoneCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.status_attr.done_callback;
+
+ /* invoke the callback
+ */
+ if (cb && cb->callback) {
+ (*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
+ }
+ else {
+
+ /* no callback registered
+ */
+ return XimCbNoCallback;
+ }
+
+ return XimCbSuccess;
+}
+
+Private XimCbStatus
+_XimStatusDrawCallback(Xim im,
+ Xic ic,
+ char* proto,
+ int len)
+{
+ XICCallback* cb = &ic->core.status_attr.draw_callback;
+ XIMStatusDrawCallbackStruct cbs;
+
+ /* invoke the callback
+ */
+ if (cb && cb->callback) {
+ cbs.type = (XIMStatusDataType)*(CARD32*)proto; proto += sz_CARD32;
+ if (cbs.type == XIMTextType) {
+ _read_text_from_packet(im, proto, &cbs.data.text);
+ }
+ else if (cbs.type == XIMBitmapType) {
+ cbs.data.bitmap = (Pixmap)*(CARD32*)proto;
+ }
+
+ (*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
+
+ if (cbs.type == XIMTextType)
+ _free_memory_for_text((XIMText *)cbs.data.text);
+ }
+ else {
+
+ /* no callback registered
+ */
+ return XimCbNoCallback;
+ }
+
+ return XimCbSuccess;
+}
+
+Private XimCbStatus
+_XimPreeditStateNotifyCallback( Xim im, Xic ic, char* proto, int len )
+{
+ XICCallback *cb = &ic->core.preedit_attr.state_notify_callback;
+
+ /* invoke the callack
+ */
+ if( cb && cb->callback ) {
+ XIMPreeditStateNotifyCallbackStruct cbrec;
+
+ cbrec.state = *(BITMASK32 *)proto;
+ (*cb->callback)( (XIC)ic, cb->client_data, (XPointer)&cbrec );
+ }
+ else {
+ /* no callback registered
+ */
+ return XimCbNoCallback;
+ }
+
+ return XimCbSuccess;
+}
+
diff --git a/libX11/modules/im/ximcp/imDefIc.c b/libX11/modules/im/ximcp/imDefIc.c
index cd3ed5854..a962c1b0f 100644
--- a/libX11/modules/im/ximcp/imDefIc.c
+++ b/libX11/modules/im/ximcp/imDefIc.c
@@ -1,1581 +1,1581 @@
-/*
- * Copyright 1991, 1992 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
- Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-Private Bool
-_XimCreateICCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
-
- if ((major_opcode == XIM_CREATE_IC_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid))
- return True;
- return False;
-}
-
-#ifdef XIM_CONNECTABLE
-Public Bool
-_XimReCreateIC(ic)
- Xic ic;
-{
- Xim im = (Xim)ic->core.im;
- Xic save_ic;
- XIMResourceList res;
- unsigned int num;
- XIMStyle input_style = ic->core.input_style;
- XimDefICValues ic_values;
- INT16 len;
- CARD16 *buf_s;
- char *tmp;
- CARD32 tmp_buf32[BUFSIZE/4];
- char *tmp_buf = (char *)tmp_buf32;
- char *buf;
- int buf_size;
- char *data;
- int data_len;
- int ret_len;
- int total;
- int idx;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int ret_code;
-
- if (!(save_ic = (Xic)Xmalloc(sizeof(XicRec))))
- return False;
- memcpy((char *)save_ic, (char *)ic, sizeof(XicRec));
-
- ic->core.filter_events = im->private.proto.forward_event_mask;
- ic->private.proto.forward_event_mask =
- im->private.proto.forward_event_mask;
- ic->private.proto.synchronous_event_mask =
- im->private.proto.synchronous_event_mask;
-
- num = im->core.ic_num_resources;
- buf_size = sizeof(XIMResource) * num;
- if (!(res = (XIMResourceList)Xmalloc(buf_size)))
- goto ErrorOnReCreateIC;
- (void)memcpy((char *)res, (char *)im->core.ic_resources, buf_size);
- ic->private.proto.ic_resources = res;
- ic->private.proto.ic_num_resources = num;
-
- num = im->private.proto.ic_num_inner_resources;
- buf_size = sizeof(XIMResource) * num;
- if (!(res = (XIMResourceList)Xmalloc(buf_size)))
- goto ErrorOnReCreateIC;
- (void)memcpy((char *)res,
- (char *)im->private.proto.ic_inner_resources, buf_size);
- ic->private.proto.ic_inner_resources = res;
- ic->private.proto.ic_num_inner_resources = num;
-
- _XimSetICMode(ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources, input_style);
-
- _XimSetICMode(ic->private.proto.ic_inner_resources,
- ic->private.proto.ic_num_inner_resources, input_style);
-
- _XimGetCurrentICValues(ic, &ic_values);
- buf = tmp_buf;
- buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
- data_len = BUFSIZE - buf_size;
- total = 0;
- idx = 0;
- for (;;) {
- data = &buf[buf_size];
- if (!_XimEncodeSavedICATTRIBUTE(ic, ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources, &idx, data, data_len,
- &ret_len, (XPointer)&ic_values, XIM_CREATEIC)) {
- if (buf != tmp_buf)
- Xfree(buf);
- goto ErrorOnReCreateIC;
- }
-
- total += ret_len;
- if (idx == -1) {
- break;
- }
-
- buf_size += ret_len;
- if (buf == tmp_buf) {
- if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
- goto ErrorOnReCreateIC;
- }
- memcpy(tmp, buf, buf_size);
- buf = tmp;
- } else {
- if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
- Xfree(buf);
- goto ErrorOnReCreateIC;
- }
- buf = tmp;
- }
- }
-
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- buf_s[0] = im->private.proto.imid;
- buf_s[1] = (INT16)total;
-
- len = (INT16)(sizeof(CARD16) + sizeof(INT16) + total);
- _XimSetHeader((XPointer)buf, XIM_CREATE_IC, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- if (buf != tmp_buf)
- Xfree(buf);
- goto ErrorOnReCreateIC;
- }
- _XimFlush(im);
- if (buf != tmp_buf)
- Xfree(buf);
- ic->private.proto.waitCallback = True;
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimCreateICCheck, 0);
- if (ret_code == XIM_TRUE) {
- preply = reply;
- } else if (ret_code == XIM_OVERFLOW) {
- if (len <= 0) {
- preply = reply;
- } else {
- buf_size = (int)len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimCreateICCheck, 0);
- if (ret_code != XIM_TRUE) {
- Xfree(preply);
- ic->private.proto.waitCallback = False;
- goto ErrorOnReCreateIC;
- }
- }
- } else {
- ic->private.proto.waitCallback = False;
- goto ErrorOnReCreateIC;
- }
- ic->private.proto.waitCallback = False;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if (reply != preply)
- Xfree(preply);
- goto ErrorOnReCreateIC;
- }
-
- ic->private.proto.icid = buf_s[1]; /* icid */
- if (reply != preply)
- Xfree(preply);
-
- _XimRegisterFilter(ic);
- MARK_IC_CONNECTED(ic);
- if (save_ic->private.proto.ic_resources)
- Xfree(save_ic->private.proto.ic_resources);
- if (save_ic->private.proto.ic_inner_resources)
- Xfree(save_ic->private.proto.ic_inner_resources);
- Xfree(save_ic);
- return True;
-
-ErrorOnReCreateIC:
- memcpy((char *)ic, (char *)save_ic, sizeof(XicRec));
- Xfree(save_ic);
- return False;
-}
-
-Private char *
-_XimDelayModeGetICValues(ic, arg)
- Xic ic;
- XIMArg *arg;
-{
- XimDefICValues ic_values;
-
- _XimGetCurrentICValues(ic, &ic_values);
- return _XimGetICValueData(ic, (XPointer)&ic_values,
- ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources,
- arg, XIM_GETICVALUES);
-}
-#endif /* XIM_CONNECTABLE */
-
-Private Bool
-_XimGetICValuesCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- Xic ic = (Xic)arg;
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
-
- if ((major_opcode == XIM_GET_IC_VALUES_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid)
- && (icid == ic->private.proto.icid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid)
- && (buf_s[2] & XIM_ICID_VALID)
- && (icid == ic->private.proto.icid))
- return True;
- return False;
-}
-
-Private char *
-_XimProtoGetICValues(
- XIC xic,
- XIMArg *arg)
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- register XIMArg *p;
- register XIMArg *pp;
- register int n;
- CARD8 *buf;
- CARD16 *buf_s;
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply = NULL;
- int buf_size;
- int ret_code;
- char *makeid_name;
- char *decode_name;
- CARD16 *data = NULL;
- INT16 data_len = 0;
-
-#ifndef XIM_CONNECTABLE
- if (!IS_IC_CONNECTED(ic))
- return arg->name;
-#else
- if (!IS_IC_CONNECTED(ic)) {
- if (IS_CONNECTABLE(im)) {
- if (_XimConnectServer(im)) {
- if (!_XimReCreateIC(ic)) {
- _XimDelayModeSetAttr(im);
- return _XimDelayModeGetICValues(ic, arg);
- }
- } else {
- return _XimDelayModeGetICValues(ic, arg);
- }
- } else {
- return arg->name;
- }
- }
-#endif /* XIM_CONNECTABLE */
-
- for (n = 0, p = arg; p && p->name; p++) {
- n++;
- if ((strcmp(p->name, XNPreeditAttributes) == 0)
- || (strcmp(p->name, XNStatusAttributes) == 0)) {
- n++;
- for (pp = (XIMArg *)p->value; pp && pp->name; pp++)
- n++;
- }
- }
-
- if (!n)
- return (char *)NULL;
-
- buf_size = sizeof(CARD16) * n;
- buf_size += XIM_HEADER_SIZE
- + sizeof(CARD16)
- + sizeof(CARD16)
- + sizeof(INT16)
- + XIM_PAD(2 + buf_size);
-
- if (!(buf = (CARD8 *)Xmalloc(buf_size)))
- return arg->name;
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
-
- makeid_name = _XimMakeICAttrIDList(ic, ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources, arg,
- &buf_s[3], &len, XIM_GETICVALUES);
-
- if (len > 0) {
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
- buf_s[2] = len; /* length of ic-attr-id */
- len += sizeof(INT16); /* sizeof length of attr */
- XIM_SET_PAD(&buf_s[2], len); /* pad */
- len += sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16); /* sizeof icid */
-
- _XimSetHeader((XPointer)buf, XIM_GET_IC_VALUES, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- Xfree(buf);
- return arg->name;
- }
- _XimFlush(im);
- Xfree(buf);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimGetICValuesCheck, (XPointer)ic);
- if (ret_code == XIM_TRUE) {
- preply = reply;
- } else if (ret_code == XIM_OVERFLOW) {
- if (len <= 0) {
- preply = reply;
- } else {
- buf_size = (int)len;
- preply = (XPointer)Xmalloc(len);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimGetICValuesCheck, (XPointer)ic);
- if (ret_code != XIM_TRUE) {
- if (preply != reply)
- Xfree(preply);
- return arg->name;
- }
- }
- } else {
- return arg->name;
- }
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if (reply != preply)
- Xfree(preply);
- return arg->name;
- }
- data = &buf_s[4];
- data_len = buf_s[2];
- }
- else if (len < 0) {
- return arg->name;
- }
-
- decode_name = _XimDecodeICATTRIBUTE(ic, ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources, data, data_len,
- arg, XIM_GETICVALUES);
- if (reply != preply)
- Xfree(preply);
-
- if (decode_name)
- return decode_name;
- else
- return makeid_name;
-}
-
-#ifdef XIM_CONNECTABLE
-Private Bool
-_XimCheckNestQuarkList(quark_list, num_quark, quark, separator)
- XrmQuark *quark_list;
- int num_quark;
- XrmQuark quark;
- XrmQuark separator;
-{
- register int i;
-
- for (i = 0; i < num_quark; i++) {
- if (quark_list[i] == separator) {
- break;
- }
- if (quark_list[i] == quark) {
- return True;
- }
- }
- return False;
-}
-
-Private Bool
-_XimCheckNestedQuarkList(quark_list, idx, num_quark, arg, separator)
- XrmQuark **quark_list;
- int idx;
- int *num_quark;
- XIMArg *arg;
- XrmQuark separator;
-{
- XrmQuark *q_list = *quark_list;
- int n_quark = *num_quark;
- register XIMArg *p;
- XrmQuark quark;
- XrmQuark *tmp;
- register int i;
-
- for (p = arg; p && p->name; p++) {
- quark = XrmStringToQuark(p->name);
- if (_XimCheckNestQuarkList(&q_list[idx], n_quark - idx,
- quark, separator)) {
- continue;
- }
- if (!(tmp = (XrmQuark *)Xmalloc((sizeof(XrmQuark) * (n_quark + 1))))) {
- *quark_list = q_list;
- *num_quark = n_quark;
- return False;
- }
- n_quark++;
- for (i = 0; i < idx; i++) {
- tmp[i] = q_list[i];
- }
- tmp[i] = quark;
- for (i = idx + 1; i < n_quark; i++) {
- tmp[i] = q_list[i - 1];
- }
- q_list = tmp;
- }
- *quark_list = q_list;
- *num_quark = n_quark;
- return True;
-}
-
-Private Bool
-_XimCheckICQuarkList(quark_list, num_quark, quark, idx)
- XrmQuark *quark_list;
- int num_quark;
- XrmQuark quark;
- int *idx;
-{
- register int i;
-
- for (i = 0; i < num_quark; i++) {
- if (quark_list[i] == quark) {
- *idx = i;
- return True;
- }
- }
- return False;
-}
-
-Private Bool
-_XimSaveICValues(ic, arg)
- Xic ic;
- XIMArg *arg;
-{
- register XIMArg *p;
- register int n;
- XrmQuark *quark_list;
- XrmQuark *tmp;
- XrmQuark quark;
- int num_quark;
- XrmQuark pre_quark;
- XrmQuark sts_quark;
- XrmQuark separator;
- int idx;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
- separator = XrmStringToQuark(XNSeparatorofNestedList);
-
- if (quark_list = ic->private.proto.saved_icvalues) {
- num_quark = ic->private.proto.num_saved_icvalues;
- for (p = arg; p && p->name; p++) {
- quark = XrmStringToQuark(p->name);
- if ((quark == pre_quark) || (quark == sts_quark)) {
- if (!_XimCheckICQuarkList(quark_list, num_quark, quark, &idx)) {
- register XIMArg *pp;
- int nn;
- XrmQuark *q_list;
-
- for (pp = (XIMArg *)p->value, nn = 0;
- pp && pp->name; pp++, nn++);
- if (!(tmp = (XrmQuark *)Xrealloc(quark_list,
- (sizeof(XrmQuark) * (num_quark + nn + 2))))) {
- ic->private.proto.saved_icvalues = quark_list;
- ic->private.proto.num_saved_icvalues = num_quark;
- return False;
- }
- quark_list = tmp;
- q_list = &quark_list[num_quark];
- num_quark += nn + 2;
- *q_list++ = quark;
- for (pp = (XIMArg *)p->value;
- pp && pp->name; pp++, quark_list++) {
- *q_list = XrmStringToQuark(pp->name);
- }
- *q_list = separator;
- } else {
- if (!_XimCheckNestedQuarkList(&quark_list, idx + 1,
- &num_quark, (XIMArg *)p->value, separator)) {
- ic->private.proto.saved_icvalues = quark_list;
- ic->private.proto.num_saved_icvalues = num_quark;
- return False;
- }
- }
- } else {
- if (_XimCheckICQuarkList(quark_list, num_quark, quark, &idx)) {
- continue;
- }
- if (!(tmp = (XrmQuark *)Xrealloc(quark_list,
- (sizeof(XrmQuark) * (num_quark + 1))))) {
- ic->private.proto.saved_icvalues = quark_list;
- ic->private.proto.num_saved_icvalues = num_quark;
- return False;
- }
- quark_list = tmp;
- quark_list[num_quark] = quark;
- num_quark++;
- }
- }
- ic->private.proto.saved_icvalues = quark_list;
- ic->private.proto.num_saved_icvalues = num_quark;
- return True;
- }
-
- for (p = arg, n = 0; p && p->name; p++, n++) {
- if ((!strcmp(p->name, XNPreeditAttributes))
- || (!strcmp(p->name, XNStatusAttributes))) {
- register XIMArg *pp;
- int nn;
-
- for (pp = (XIMArg *)p->value, nn = 0; pp && pp->name; pp++, nn++);
- n += nn + 1;
- }
- }
-
- if (!(quark_list = (XrmQuark *)Xmalloc(sizeof(XrmQuark) * n))) {
- return False;
- }
-
- ic->private.proto.saved_icvalues = quark_list;
- ic->private.proto.num_saved_icvalues = n;
- for (p = arg; p && p->name; p++, quark_list++) {
- *quark_list = XrmStringToQuark(p->name);
- if ((*quark_list == pre_quark) || (*quark_list == sts_quark)) {
- register XIMArg *pp;
-
- quark_list++;
- for (pp = (XIMArg *)p->value; pp && pp->name; pp++, quark_list++) {
- *quark_list = XrmStringToQuark(pp->name);
- }
- *quark_list = separator;
- }
- }
- return True;
-}
-
-Private char *
-_XimDelayModeSetICValues(ic, arg)
- Xic ic;
- XIMArg *arg;
-{
- XimDefICValues ic_values;
- char *name;
-
- _XimGetCurrentICValues(ic, &ic_values);
- name = _XimSetICValueData(ic, (XPointer)&ic_values,
- ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources,
- arg, XIM_SETICVALUES, False);
- _XimSetCurrentICValues(ic, &ic_values);
- return name;
-}
-#endif /* XIM_CONNECTABLE */
-
-Private Bool
-_XimSetICValuesCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- Xic ic = (Xic)arg;
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
-
- if ((major_opcode == XIM_SET_IC_VALUES_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid)
- && (icid == ic->private.proto.icid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid)
- && (buf_s[2] & XIM_ICID_VALID)
- && (icid == ic->private.proto.icid))
- return True;
- return False;
-}
-
-Private char *
-_XimProtoSetICValues(
- XIC xic,
- XIMArg *arg)
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- XimDefICValues ic_values;
- INT16 len;
- CARD16 *buf_s;
- char *tmp;
- CARD32 tmp_buf32[BUFSIZE/4];
- char *tmp_buf = (char *)tmp_buf32;
- char *buf;
- int buf_size;
- char *data;
- int data_len;
- int ret_len;
- int total;
- XIMArg *arg_ret;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply = NULL;
- int ret_code;
- BITMASK32 flag = 0L;
- char *name;
- char *tmp_name = (arg) ? arg->name : NULL;
-
-#ifndef XIM_CONNECTABLE
- if (!IS_IC_CONNECTED(ic))
- return tmp_name;
-#else
- if (!_XimSaveICValues(ic, arg))
- return NULL;
-
- if (!IS_IC_CONNECTED(ic)) {
- if (IS_CONNECTABLE(im)) {
- if (_XimConnectServer(im)) {
- if (!_XimReCreateIC(ic)) {
- _XimDelayModeSetAttr(im);
- return _XimDelayModeSetICValues(ic, arg);
- }
- } else {
- return _XimDelayModeSetICValues(ic, arg);
- }
- } else {
- return tmp_name;
- }
- }
-#endif /* XIM_CONNECTABLE */
-
- _XimGetCurrentICValues(ic, &ic_values);
- buf = tmp_buf;
- buf_size = XIM_HEADER_SIZE
- + sizeof(CARD16) + sizeof(CARD16) + sizeof(INT16) + sizeof(CARD16);
- data_len = BUFSIZE - buf_size;
- total = 0;
- arg_ret = arg;
- for (;;) {
- data = &buf[buf_size];
- if ((name = _XimEncodeICATTRIBUTE(ic, ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources, arg, &arg_ret,
- data, data_len, &ret_len, (XPointer)&ic_values,
- &flag, XIM_SETICVALUES))) {
- break;
- }
-
- total += ret_len;
- if (!(arg = arg_ret)) {
- break;
- }
-
- buf_size += ret_len;
- if (buf == tmp_buf) {
- if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
- return tmp_name;
- }
- memcpy(tmp, buf, buf_size);
- buf = tmp;
- } else {
- if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
- Xfree(buf);
- return tmp_name;
- }
- buf = tmp;
- }
- }
- _XimSetCurrentICValues(ic, &ic_values);
-
- if (!total) {
- return tmp_name;
- }
-
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
-
-#ifdef EXT_MOVE
- if (_XimExtenMove(im, ic, flag, &buf_s[4], (INT16)total))
- return name;
-#endif
-
- buf_s[0] = im->private.proto.imid;
- buf_s[1] = ic->private.proto.icid;
- buf_s[2] = (INT16)total;
- buf_s[3] = 0;
- len = (INT16)(sizeof(CARD16) + sizeof(CARD16)
- + sizeof(INT16) + sizeof(CARD16) + total);
-
- _XimSetHeader((XPointer)buf, XIM_SET_IC_VALUES, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- if (buf != tmp_buf)
- Xfree(buf);
- return tmp_name;
- }
- _XimFlush(im);
- if (buf != tmp_buf)
- Xfree(buf);
- ic->private.proto.waitCallback = True;
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimSetICValuesCheck, (XPointer)ic);
- if (ret_code == XIM_TRUE) {
- preply = reply;
- } else if (ret_code == XIM_OVERFLOW) {
- buf_size = (int)len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimSetICValuesCheck, (XPointer)ic);
- if (ret_code != XIM_TRUE) {
- Xfree(preply);
- ic->private.proto.waitCallback = False;
- return tmp_name;
- }
- } else {
- ic->private.proto.waitCallback = False;
- return tmp_name;
- }
- ic->private.proto.waitCallback = False;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if (reply != preply)
- Xfree(preply);
- return tmp_name;
- }
- if (reply != preply)
- Xfree(preply);
-
- return name;
-}
-
-Private Bool
-_XimDestroyICCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- Xic ic = (Xic)arg;
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
- Bool ret = False;
-
- if ((major_opcode == XIM_DESTROY_IC_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid)
- && (icid == ic->private.proto.icid))
- ret = True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid)
- && (buf_s[2] & XIM_ICID_VALID)
- && (icid == ic->private.proto.icid))
- ret = False;
- return ret;
-}
-
-Private void
-_XimProtoICFree(
- Xic ic)
-{
-#ifdef XIM_CONNECTABLE
- Xim im = (Xim)ic->core.im;
-#endif
-
- if (ic->private.proto.preedit_font) {
- Xfree(ic->private.proto.preedit_font);
- ic->private.proto.preedit_font = NULL;
- }
- if (ic->private.proto.status_font) {
- Xfree(ic->private.proto.status_font);
- ic->private.proto.status_font = NULL;
- }
- if (ic->private.proto.commit_info) {
- _XimFreeCommitInfo(ic);
- ic->private.proto.commit_info = NULL;
- }
- if (ic->private.proto.ic_inner_resources) {
- Xfree(ic->private.proto.ic_inner_resources);
- ic->private.proto.ic_inner_resources = NULL;
- }
-
-#ifdef XIM_CONNECTABLE
- if (IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
- return;
- }
-#endif /* XIM_CONNECTABLE */
-
- if (ic->private.proto.saved_icvalues) {
- Xfree(ic->private.proto.saved_icvalues);
- ic->private.proto.saved_icvalues = NULL;
- }
- if (ic->private.proto.ic_resources) {
- Xfree(ic->private.proto.ic_resources);
- ic->private.proto.ic_resources = NULL;
- }
- if (ic->core.hotkey) {
- Xfree(ic->core.hotkey);
- ic->core.hotkey = NULL;
- }
-
- return;
-}
-
-Private void
-_XimProtoDestroyIC(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
-
- if (IS_SERVER_CONNECTED(im)) {
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
-
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16); /* sizeof icid */
-
- _XimSetHeader((XPointer)buf, XIM_DESTROY_IC, 0, &len);
- (void)_XimWrite(im, len, (XPointer)buf);
- _XimFlush(im);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimDestroyICCheck, (XPointer)ic);
- if (ret_code == XIM_OVERFLOW) {
- buf_size = len;
- preply = (XPointer)Xmalloc(buf_size);
- (void)_XimRead(im, &len, preply, buf_size,
- _XimDestroyICCheck, (XPointer)ic);
- Xfree(preply);
- }
- }
- UNMARK_IC_CONNECTED(ic);
- _XimUnregisterFilter(ic);
- _XimProtoICFree(ic);
- return;
-}
-
-Private void
-_XimProtoSetFocus(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len;
-
-#ifndef XIM_CONNECTABLE
- if (!IS_IC_CONNECTED(ic))
- return;
-#else
- if (!IS_IC_CONNECTED(ic)) {
- if (IS_CONNECTABLE(im)) {
- if (_XimConnectServer(im)) {
- if (!_XimReCreateIC(ic)) {
- _XimDelayModeSetAttr(im);
- return;
- }
- } else {
- return;
- }
- } else {
- return;
- }
- }
-#endif /* XIM_CONNECTABLE */
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
-
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16); /* sizeof icid */
-
- _XimSetHeader((XPointer)buf, XIM_SET_IC_FOCUS, 0, &len);
- (void)_XimWrite(im, len, (XPointer)buf);
- _XimFlush(im);
-
- MARK_FOCUSED(ic);
-
- _XimRegisterFilter(ic);
- return;
-}
-
-Private void
-_XimProtoUnsetFocus(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len;
-
-#ifndef XIM_CONNECTABLE
- if (!IS_IC_CONNECTED(ic))
- return;
-#else
- if (!IS_IC_CONNECTED(ic)) {
- if (IS_CONNECTABLE(im)) {
- if (_XimConnectServer(im)) {
- if (!_XimReCreateIC(ic)) {
- _XimDelayModeSetAttr(im);
- return;
- }
- } else {
- return;
- }
- } else {
- return;
- }
- }
-#endif /* XIM_CONNECTABLE */
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
-
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16); /* sizeof icid */
-
- _XimSetHeader((XPointer)buf, XIM_UNSET_IC_FOCUS, 0, &len);
- (void)_XimWrite(im, len, (XPointer)buf);
- _XimFlush(im);
-
- UNMARK_FOCUSED(ic);
-
- _XimUnregisterFilter(ic);
- return;
-}
-
-Private Bool
-_XimResetICCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- Xic ic = (Xic)arg;
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
-
- if ((major_opcode == XIM_RESET_IC_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid)
- && (icid == ic->private.proto.icid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid)
- && (buf_s[2] & XIM_ICID_VALID)
- && (icid == ic->private.proto.icid))
- return True;
- return False;
-}
-
-Private char *
-_XimProtoReset(
- XIC xic,
- char * (*retfunc) (Xim im, Xic ic, XPointer buf) )
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
- char *commit;
-
- if (!IS_IC_CONNECTED(ic))
- return (char *)NULL;
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
-
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16); /* sizeof icid */
-
- _XimSetHeader((XPointer)buf, XIM_RESET_IC, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return NULL;
- _XimFlush(im);
- ic->private.proto.waitCallback = True;
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimResetICCheck, (XPointer)ic);
- if (ret_code == XIM_TRUE) {
- preply = reply;
- } else if (ret_code == XIM_OVERFLOW) {
- if (len < 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimResetICCheck, (XPointer)ic);
- if (ret_code != XIM_TRUE) {
- Xfree(preply);
- ic->private.proto.waitCallback = False;
- return NULL;
- }
- }
- } else {
- ic->private.proto.waitCallback = False;
- return NULL;
- }
- ic->private.proto.waitCallback = False;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if (reply != preply)
- free(preply);
- return NULL;
- }
-
- commit = retfunc(im, ic, (XPointer)&buf_s[2]);
-
- if (reply != preply)
- Xfree(preply);
- return commit;
-}
-
-Private char *
-_XimCommitedMbString(
- Xim im,
- Xic ic,
- XPointer buf)
-{
- CARD16 *buf_s = (CARD16 *)buf;
- XimCommitInfo info;
- int len;
- int new_len;
- char *commit;
- char *new_commit = NULL;
- char *str;
- Status status;
-
- len = 0;
- for (info = ic->private.proto.commit_info; info; info = info->next)
- len += info->string_len;
- len += buf_s[0];
- if ( len == 0 )
- return( NULL );
-
- if (!(commit = (char *)Xmalloc(len + 1)))
- goto Error_On_Reset;
-
- str = commit;
- for (info = ic->private.proto.commit_info; info; info = info->next) {
- (void)memcpy(str, info->string, info->string_len);
- str += info->string_len;
- }
- (void)memcpy(str, (char *)&buf_s[1], buf_s[0]);
- commit[len] = '\0';
-
- new_len = im->methods->ctstombs((XIM)im, commit, len, NULL, 0, &status);
- if (status != XLookupNone) {
- if (!(new_commit = Xmalloc(new_len + 1))) {
- Xfree(commit);
- goto Error_On_Reset;
- }
- (void)im->methods->ctstombs((XIM)im, commit, len,
- new_commit, new_len, NULL);
- new_commit[new_len] = '\0';
- }
- Xfree(commit);
-
-Error_On_Reset:
- _XimFreeCommitInfo( ic );
- return new_commit;
-}
-
-Private char *
-_XimProtoMbReset(
- XIC xic)
-{
- return _XimProtoReset(xic, _XimCommitedMbString);
-}
-
-Private wchar_t *
-_XimCommitedWcString(
- Xim im,
- Xic ic,
- XPointer buf)
-{
- CARD16 *buf_s = (CARD16 *)buf;
- XimCommitInfo info;
- int len;
- int new_len;
- char *commit;
- wchar_t *new_commit = (wchar_t *)NULL;
- char *str;
- Status status;
-
- len = 0;
- for (info = ic->private.proto.commit_info; info; info = info->next)
- len += info->string_len;
- len += buf_s[0];
- if ( len == 0 )
- return( (wchar_t *)NULL );
-
- if (!(commit = (char *)Xmalloc(len + 1)))
- goto Error_On_Reset;
-
- str = commit;
- for (info = ic->private.proto.commit_info; info; info = info->next) {
- (void)memcpy(str, info->string, info->string_len);
- str += info->string_len;
- }
- (void)memcpy(str, (char *)&buf_s[1], buf_s[0]);
- commit[len] = '\0';
-
- new_len = im->methods->ctstowcs((XIM)im, commit, len, NULL, 0, &status);
- if (status != XLookupNone) {
- if (!(new_commit =
- (wchar_t *)Xmalloc(sizeof(wchar_t) * (new_len + 1)))) {
- Xfree(commit);
- goto Error_On_Reset;
- }
- (void)im->methods->ctstowcs((XIM)im, commit, len,
- new_commit, new_len, NULL);
- new_commit[new_len] = (wchar_t)'\0';
- }
- Xfree(commit);
-
-Error_On_Reset:
- _XimFreeCommitInfo( ic );
- return new_commit;
-}
-
-Private wchar_t *
-_XimProtoWcReset(
- XIC xic)
-{
- return (wchar_t *) _XimProtoReset(xic,
- (char * (*) (Xim, Xic, XPointer)) _XimCommitedWcString);
-}
-
-Private char *
-_XimCommitedUtf8String(
- Xim im,
- Xic ic,
- XPointer buf)
-{
- CARD16 *buf_s = (CARD16 *)buf;
- XimCommitInfo info;
- int len;
- int new_len;
- char *commit;
- char *new_commit = NULL;
- char *str;
- Status status;
-
- len = 0;
- for (info = ic->private.proto.commit_info; info; info = info->next)
- len += info->string_len;
- len += buf_s[0];
- if ( len == 0 )
- return( NULL );
-
- if (!(commit = (char *)Xmalloc(len + 1)))
- goto Error_On_Reset;
-
- str = commit;
- for (info = ic->private.proto.commit_info; info; info = info->next) {
- (void)memcpy(str, info->string, info->string_len);
- str += info->string_len;
- }
- (void)memcpy(str, (char *)&buf_s[1], buf_s[0]);
- commit[len] = '\0';
-
- new_len = im->methods->ctstoutf8((XIM)im, commit, len, NULL, 0, &status);
- if (status != XLookupNone) {
- if (!(new_commit = Xmalloc(new_len + 1))) {
- Xfree(commit);
- goto Error_On_Reset;
- }
- (void)im->methods->ctstoutf8((XIM)im, commit, len,
- new_commit, new_len, NULL);
- new_commit[new_len] = '\0';
- }
- Xfree(commit);
-
-Error_On_Reset:
- _XimFreeCommitInfo( ic );
- return new_commit;
-}
-
-Private char *
-_XimProtoUtf8Reset(
- XIC xic)
-{
- return _XimProtoReset(xic, _XimCommitedUtf8String);
-}
-
-Private XICMethodsRec ic_methods = {
- _XimProtoDestroyIC, /* destroy */
- _XimProtoSetFocus, /* set_focus */
- _XimProtoUnsetFocus, /* unset_focus */
- _XimProtoSetICValues, /* set_values */
- _XimProtoGetICValues, /* get_values */
- _XimProtoMbReset, /* mb_reset */
- _XimProtoWcReset, /* wc_reset */
- _XimProtoUtf8Reset, /* utf8_reset */
- _XimProtoMbLookupString, /* mb_lookup_string */
- _XimProtoWcLookupString, /* wc_lookup_string */
- _XimProtoUtf8LookupString /* utf8_lookup_string */
-};
-
-Private Bool
-_XimGetInputStyle(
- XIMArg *arg,
- XIMStyle *input_style)
-{
- register XIMArg *p;
-
- for (p = arg; p && p->name; p++) {
- if (!(strcmp(p->name, XNInputStyle))) {
- *input_style = (XIMStyle)p->value;
- return True;
- }
- }
- return False;
-}
-
-#ifdef XIM_CONNECTABLE
-Private Bool
-_XimDelayModeCreateIC(
- Xic ic,
- XIMArg *values,
- XIMResourceList res,
- unsigned int num)
-{
- Xim im = (Xim)ic->core.im;
- XimDefICValues ic_values;
- int len;
- XIMStyle input_style;
-
- bzero((char *)&ic_values, sizeof(XimDefICValues));
- _XimGetCurrentICValues(ic, &ic_values);
- if (!(_XimGetInputStyle(values, &input_style)))
- return False;
-
- _XimSetICMode(res, num, input_style);
-
- if (_XimSetICValueData(ic, (XPointer)&ic_values, res, num,
- values, XIM_CREATEIC, False)) {
- return False;
- }
- _XimSetCurrentICValues(ic, &ic_values);
- if (!_XimSetICDefaults(ic, (XPointer)&ic_values,
- XIM_SETICDEFAULTS, res, num)) {
- return False;
- }
- ic_values.filter_events = KeyPressMask;
- _XimSetCurrentICValues(ic, &ic_values);
- _XimRegisterFilter(ic);
-
- return True;
-}
-
-Public Bool
-_XimReconnectModeCreateIC(ic)
- Xic ic;
-{
- Xim im = (Xim)ic->core.im;
- int len;
- XIMStyle input_style = ic->core.input_style;
- XIMResourceList res;
- unsigned int num;
-
- num = im->core.ic_num_resources;
- len = sizeof(XIMResource) * num;
- if (!(res = (XIMResourceList)Xmalloc(len)))
- return False;
- (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
- ic->private.proto.ic_resources = res;
- ic->private.proto.ic_num_resources = num;
-
- _XimSetICMode(res, num, input_style);
-
- ic->core.filter_events = KeyPressMask;
-
- return True;
-}
-#endif /* XIM_CONNECTABLE */
-
-Public XIC
-_XimProtoCreateIC(
- XIM xim,
- XIMArg *arg)
-{
- Xim im = (Xim)xim;
- Xic ic;
- XimDefICValues ic_values;
- XIMResourceList res;
- unsigned int num;
- XIMStyle input_style;
- INT16 len;
- CARD16 *buf_s;
- char *tmp;
- CARD32 tmp_buf32[BUFSIZE/4];
- char *tmp_buf = (char *)tmp_buf32;
- char *buf;
- int buf_size;
- char *data;
- int data_len;
- int ret_len;
- int total;
- XIMArg *arg_ret;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int ret_code;
-
-#ifdef XIM_CONNECTABLE
- if (!IS_SERVER_CONNECTED(im) && !IS_CONNECTABLE(im))
- return (XIC)NULL;
-#else
- if (!IS_SERVER_CONNECTED(im))
- return (XIC)NULL;
-#endif /* XIM_CONNECTABLE */
-
- if (!(_XimGetInputStyle(arg, &input_style)))
- return (XIC)NULL;
-
- if ((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL)
- return (XIC)NULL;
-
- ic->methods = &ic_methods;
- ic->core.im = (XIM)im;
- ic->core.input_style = input_style;
-
- num = im->core.ic_num_resources;
- len = sizeof(XIMResource) * num;
- if (!(res = (XIMResourceList)Xmalloc(len)))
- goto ErrorOnCreatingIC;
- (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
- ic->private.proto.ic_resources = res;
- ic->private.proto.ic_num_resources = num;
-
-#ifdef XIM_CONNECTABLE
- if (!_XimSaveICValues(ic, arg))
- return False;
-
- if (!IS_SERVER_CONNECTED(im)) {
- if (!_XimConnectServer(im)) {
- if (_XimDelayModeCreateIC(ic, arg, res, num)) {
- return (XIC)ic;
- }
- goto ErrorOnCreatingIC;
- }
- }
-#endif /* XIM_CONNECTABLE */
-
- ic->core.filter_events = im->private.proto.forward_event_mask;
- ic->private.proto.forward_event_mask =
- im->private.proto.forward_event_mask;
- ic->private.proto.synchronous_event_mask =
- im->private.proto.synchronous_event_mask;
-
- num = im->private.proto.ic_num_inner_resources;
- len = sizeof(XIMResource) * num;
- if (!(res = (XIMResourceList)Xmalloc(len)))
- goto ErrorOnCreatingIC;
- (void)memcpy((char *)res,
- (char *)im->private.proto.ic_inner_resources, len);
- ic->private.proto.ic_inner_resources = res;
- ic->private.proto.ic_num_inner_resources = num;
-
- _XimSetICMode(ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources, input_style);
-
- _XimSetICMode(ic->private.proto.ic_inner_resources,
- ic->private.proto.ic_num_inner_resources, input_style);
-
- _XimGetCurrentICValues(ic, &ic_values);
- buf = tmp_buf;
- buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
- data_len = BUFSIZE - buf_size;
- total = 0;
- arg_ret = arg;
- for (;;) {
- data = &buf[buf_size];
- if (_XimEncodeICATTRIBUTE(ic, ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources, arg, &arg_ret, data,
- data_len, &ret_len, (XPointer)&ic_values, 0, XIM_CREATEIC)) {
- goto ErrorOnCreatingIC;
- }
-
- total += ret_len;
- if (!(arg = arg_ret)) {
- break;
- }
-
- buf_size += ret_len;
- if (buf == tmp_buf) {
- if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
- goto ErrorOnCreatingIC;
- }
- memcpy(tmp, buf, buf_size);
- buf = tmp;
- } else {
- if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
- Xfree(buf);
- goto ErrorOnCreatingIC;
- }
- buf = tmp;
- }
- }
- _XimSetCurrentICValues(ic, &ic_values);
-
- if (!(_XimCheckCreateICValues(ic->private.proto.ic_resources,
- ic->private.proto.ic_num_resources)))
- goto ErrorOnCreatingIC;
-
- _XimRegisterFilter(ic);
-
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- buf_s[0] = im->private.proto.imid;
- buf_s[1] = (INT16)total;
-
- len = (INT16)(sizeof(CARD16) + sizeof(INT16) + total);
- _XimSetHeader((XPointer)buf, XIM_CREATE_IC, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- if (buf != tmp_buf)
- Xfree(buf);
- goto ErrorOnCreatingIC;
- }
- _XimFlush(im);
- if (buf != tmp_buf)
- Xfree(buf);
- ic->private.proto.waitCallback = True;
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimCreateICCheck, 0);
- if (ret_code == XIM_TRUE) {
- preply = reply;
- } else if (ret_code == XIM_OVERFLOW) {
- if (len <= 0) {
- preply = reply;
- } else {
- buf_size = (int)len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimCreateICCheck, 0);
- if (ret_code != XIM_TRUE) {
- Xfree(preply);
- ic->private.proto.waitCallback = False;
- goto ErrorOnCreatingIC;
- }
- }
- } else {
- ic->private.proto.waitCallback = False;
- goto ErrorOnCreatingIC;
- }
- ic->private.proto.waitCallback = False;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if (reply != preply)
- Xfree(preply);
- goto ErrorOnCreatingIC;
- }
-
- ic->private.proto.icid = buf_s[1]; /* icid */
- if (reply != preply)
- Xfree(preply);
- MARK_IC_CONNECTED(ic);
- return (XIC)ic;
-
-ErrorOnCreatingIC:
- _XimUnregisterFilter(ic);
- if (ic->private.proto.ic_resources)
- Xfree(ic->private.proto.ic_resources);
- if (ic->private.proto.ic_inner_resources)
- Xfree(ic->private.proto.ic_inner_resources);
- Xfree(ic);
- return (XIC)NULL;
-}
+/*
+ * Copyright 1991, 1992 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
+ Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Private Bool
+_XimCreateICCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+
+ if ((major_opcode == XIM_CREATE_IC_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid))
+ return True;
+ return False;
+}
+
+#ifdef XIM_CONNECTABLE
+Public Bool
+_XimReCreateIC(ic)
+ Xic ic;
+{
+ Xim im = (Xim)ic->core.im;
+ Xic save_ic;
+ XIMResourceList res;
+ unsigned int num;
+ XIMStyle input_style = ic->core.input_style;
+ XimDefICValues ic_values;
+ INT16 len;
+ CARD16 *buf_s;
+ char *tmp;
+ CARD32 tmp_buf32[BUFSIZE/4];
+ char *tmp_buf = (char *)tmp_buf32;
+ char *buf;
+ int buf_size;
+ char *data;
+ int data_len;
+ int ret_len;
+ int total;
+ int idx;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int ret_code;
+
+ if (!(save_ic = (Xic)Xmalloc(sizeof(XicRec))))
+ return False;
+ memcpy((char *)save_ic, (char *)ic, sizeof(XicRec));
+
+ ic->core.filter_events = im->private.proto.forward_event_mask;
+ ic->private.proto.forward_event_mask =
+ im->private.proto.forward_event_mask;
+ ic->private.proto.synchronous_event_mask =
+ im->private.proto.synchronous_event_mask;
+
+ num = im->core.ic_num_resources;
+ buf_size = sizeof(XIMResource) * num;
+ if (!(res = (XIMResourceList)Xmalloc(buf_size)))
+ goto ErrorOnReCreateIC;
+ (void)memcpy((char *)res, (char *)im->core.ic_resources, buf_size);
+ ic->private.proto.ic_resources = res;
+ ic->private.proto.ic_num_resources = num;
+
+ num = im->private.proto.ic_num_inner_resources;
+ buf_size = sizeof(XIMResource) * num;
+ if (!(res = (XIMResourceList)Xmalloc(buf_size)))
+ goto ErrorOnReCreateIC;
+ (void)memcpy((char *)res,
+ (char *)im->private.proto.ic_inner_resources, buf_size);
+ ic->private.proto.ic_inner_resources = res;
+ ic->private.proto.ic_num_inner_resources = num;
+
+ _XimSetICMode(ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources, input_style);
+
+ _XimSetICMode(ic->private.proto.ic_inner_resources,
+ ic->private.proto.ic_num_inner_resources, input_style);
+
+ _XimGetCurrentICValues(ic, &ic_values);
+ buf = tmp_buf;
+ buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
+ data_len = BUFSIZE - buf_size;
+ total = 0;
+ idx = 0;
+ for (;;) {
+ data = &buf[buf_size];
+ if (!_XimEncodeSavedICATTRIBUTE(ic, ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources, &idx, data, data_len,
+ &ret_len, (XPointer)&ic_values, XIM_CREATEIC)) {
+ if (buf != tmp_buf)
+ Xfree(buf);
+ goto ErrorOnReCreateIC;
+ }
+
+ total += ret_len;
+ if (idx == -1) {
+ break;
+ }
+
+ buf_size += ret_len;
+ if (buf == tmp_buf) {
+ if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
+ goto ErrorOnReCreateIC;
+ }
+ memcpy(tmp, buf, buf_size);
+ buf = tmp;
+ } else {
+ if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
+ Xfree(buf);
+ goto ErrorOnReCreateIC;
+ }
+ buf = tmp;
+ }
+ }
+
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ buf_s[0] = im->private.proto.imid;
+ buf_s[1] = (INT16)total;
+
+ len = (INT16)(sizeof(CARD16) + sizeof(INT16) + total);
+ _XimSetHeader((XPointer)buf, XIM_CREATE_IC, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ if (buf != tmp_buf)
+ Xfree(buf);
+ goto ErrorOnReCreateIC;
+ }
+ _XimFlush(im);
+ if (buf != tmp_buf)
+ Xfree(buf);
+ ic->private.proto.waitCallback = True;
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimCreateICCheck, 0);
+ if (ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if (ret_code == XIM_OVERFLOW) {
+ if (len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = (int)len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimCreateICCheck, 0);
+ if (ret_code != XIM_TRUE) {
+ Xfree(preply);
+ ic->private.proto.waitCallback = False;
+ goto ErrorOnReCreateIC;
+ }
+ }
+ } else {
+ ic->private.proto.waitCallback = False;
+ goto ErrorOnReCreateIC;
+ }
+ ic->private.proto.waitCallback = False;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if (reply != preply)
+ Xfree(preply);
+ goto ErrorOnReCreateIC;
+ }
+
+ ic->private.proto.icid = buf_s[1]; /* icid */
+ if (reply != preply)
+ Xfree(preply);
+
+ _XimRegisterFilter(ic);
+ MARK_IC_CONNECTED(ic);
+ if (save_ic->private.proto.ic_resources)
+ Xfree(save_ic->private.proto.ic_resources);
+ if (save_ic->private.proto.ic_inner_resources)
+ Xfree(save_ic->private.proto.ic_inner_resources);
+ Xfree(save_ic);
+ return True;
+
+ErrorOnReCreateIC:
+ memcpy((char *)ic, (char *)save_ic, sizeof(XicRec));
+ Xfree(save_ic);
+ return False;
+}
+
+Private char *
+_XimDelayModeGetICValues(ic, arg)
+ Xic ic;
+ XIMArg *arg;
+{
+ XimDefICValues ic_values;
+
+ _XimGetCurrentICValues(ic, &ic_values);
+ return _XimGetICValueData(ic, (XPointer)&ic_values,
+ ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources,
+ arg, XIM_GETICVALUES);
+}
+#endif /* XIM_CONNECTABLE */
+
+Private Bool
+_XimGetICValuesCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ Xic ic = (Xic)arg;
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+
+ if ((major_opcode == XIM_GET_IC_VALUES_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid)
+ && (icid == ic->private.proto.icid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid)
+ && (buf_s[2] & XIM_ICID_VALID)
+ && (icid == ic->private.proto.icid))
+ return True;
+ return False;
+}
+
+Private char *
+_XimProtoGetICValues(
+ XIC xic,
+ XIMArg *arg)
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ register XIMArg *p;
+ register XIMArg *pp;
+ register int n;
+ CARD8 *buf;
+ CARD16 *buf_s;
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply = NULL;
+ int buf_size;
+ int ret_code;
+ char *makeid_name;
+ char *decode_name;
+ CARD16 *data = NULL;
+ INT16 data_len = 0;
+
+#ifndef XIM_CONNECTABLE
+ if (!IS_IC_CONNECTED(ic))
+ return arg->name;
+#else
+ if (!IS_IC_CONNECTED(ic)) {
+ if (IS_CONNECTABLE(im)) {
+ if (_XimConnectServer(im)) {
+ if (!_XimReCreateIC(ic)) {
+ _XimDelayModeSetAttr(im);
+ return _XimDelayModeGetICValues(ic, arg);
+ }
+ } else {
+ return _XimDelayModeGetICValues(ic, arg);
+ }
+ } else {
+ return arg->name;
+ }
+ }
+#endif /* XIM_CONNECTABLE */
+
+ for (n = 0, p = arg; p && p->name; p++) {
+ n++;
+ if ((strcmp(p->name, XNPreeditAttributes) == 0)
+ || (strcmp(p->name, XNStatusAttributes) == 0)) {
+ n++;
+ for (pp = (XIMArg *)p->value; pp && pp->name; pp++)
+ n++;
+ }
+ }
+
+ if (!n)
+ return (char *)NULL;
+
+ buf_size = sizeof(CARD16) * n;
+ buf_size += XIM_HEADER_SIZE
+ + sizeof(CARD16)
+ + sizeof(CARD16)
+ + sizeof(INT16)
+ + XIM_PAD(2 + buf_size);
+
+ if (!(buf = (CARD8 *)Xmalloc(buf_size)))
+ return arg->name;
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+
+ makeid_name = _XimMakeICAttrIDList(ic, ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources, arg,
+ &buf_s[3], &len, XIM_GETICVALUES);
+
+ if (len > 0) {
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+ buf_s[2] = len; /* length of ic-attr-id */
+ len += sizeof(INT16); /* sizeof length of attr */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16); /* sizeof icid */
+
+ _XimSetHeader((XPointer)buf, XIM_GET_IC_VALUES, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ Xfree(buf);
+ return arg->name;
+ }
+ _XimFlush(im);
+ Xfree(buf);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimGetICValuesCheck, (XPointer)ic);
+ if (ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if (ret_code == XIM_OVERFLOW) {
+ if (len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = (int)len;
+ preply = (XPointer)Xmalloc(len);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimGetICValuesCheck, (XPointer)ic);
+ if (ret_code != XIM_TRUE) {
+ if (preply != reply)
+ Xfree(preply);
+ return arg->name;
+ }
+ }
+ } else {
+ return arg->name;
+ }
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if (reply != preply)
+ Xfree(preply);
+ return arg->name;
+ }
+ data = &buf_s[4];
+ data_len = buf_s[2];
+ }
+ else if (len < 0) {
+ return arg->name;
+ }
+
+ decode_name = _XimDecodeICATTRIBUTE(ic, ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources, data, data_len,
+ arg, XIM_GETICVALUES);
+ if (reply != preply)
+ Xfree(preply);
+
+ if (decode_name)
+ return decode_name;
+ else
+ return makeid_name;
+}
+
+#ifdef XIM_CONNECTABLE
+Private Bool
+_XimCheckNestQuarkList(quark_list, num_quark, quark, separator)
+ XrmQuark *quark_list;
+ int num_quark;
+ XrmQuark quark;
+ XrmQuark separator;
+{
+ register int i;
+
+ for (i = 0; i < num_quark; i++) {
+ if (quark_list[i] == separator) {
+ break;
+ }
+ if (quark_list[i] == quark) {
+ return True;
+ }
+ }
+ return False;
+}
+
+Private Bool
+_XimCheckNestedQuarkList(quark_list, idx, num_quark, arg, separator)
+ XrmQuark **quark_list;
+ int idx;
+ int *num_quark;
+ XIMArg *arg;
+ XrmQuark separator;
+{
+ XrmQuark *q_list = *quark_list;
+ int n_quark = *num_quark;
+ register XIMArg *p;
+ XrmQuark quark;
+ XrmQuark *tmp;
+ register int i;
+
+ for (p = arg; p && p->name; p++) {
+ quark = XrmStringToQuark(p->name);
+ if (_XimCheckNestQuarkList(&q_list[idx], n_quark - idx,
+ quark, separator)) {
+ continue;
+ }
+ if (!(tmp = (XrmQuark *)Xmalloc((sizeof(XrmQuark) * (n_quark + 1))))) {
+ *quark_list = q_list;
+ *num_quark = n_quark;
+ return False;
+ }
+ n_quark++;
+ for (i = 0; i < idx; i++) {
+ tmp[i] = q_list[i];
+ }
+ tmp[i] = quark;
+ for (i = idx + 1; i < n_quark; i++) {
+ tmp[i] = q_list[i - 1];
+ }
+ q_list = tmp;
+ }
+ *quark_list = q_list;
+ *num_quark = n_quark;
+ return True;
+}
+
+Private Bool
+_XimCheckICQuarkList(quark_list, num_quark, quark, idx)
+ XrmQuark *quark_list;
+ int num_quark;
+ XrmQuark quark;
+ int *idx;
+{
+ register int i;
+
+ for (i = 0; i < num_quark; i++) {
+ if (quark_list[i] == quark) {
+ *idx = i;
+ return True;
+ }
+ }
+ return False;
+}
+
+Private Bool
+_XimSaveICValues(ic, arg)
+ Xic ic;
+ XIMArg *arg;
+{
+ register XIMArg *p;
+ register int n;
+ XrmQuark *quark_list;
+ XrmQuark *tmp;
+ XrmQuark quark;
+ int num_quark;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+ XrmQuark separator;
+ int idx;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+ separator = XrmStringToQuark(XNSeparatorofNestedList);
+
+ if (quark_list = ic->private.proto.saved_icvalues) {
+ num_quark = ic->private.proto.num_saved_icvalues;
+ for (p = arg; p && p->name; p++) {
+ quark = XrmStringToQuark(p->name);
+ if ((quark == pre_quark) || (quark == sts_quark)) {
+ if (!_XimCheckICQuarkList(quark_list, num_quark, quark, &idx)) {
+ register XIMArg *pp;
+ int nn;
+ XrmQuark *q_list;
+
+ for (pp = (XIMArg *)p->value, nn = 0;
+ pp && pp->name; pp++, nn++);
+ if (!(tmp = (XrmQuark *)Xrealloc(quark_list,
+ (sizeof(XrmQuark) * (num_quark + nn + 2))))) {
+ ic->private.proto.saved_icvalues = quark_list;
+ ic->private.proto.num_saved_icvalues = num_quark;
+ return False;
+ }
+ quark_list = tmp;
+ q_list = &quark_list[num_quark];
+ num_quark += nn + 2;
+ *q_list++ = quark;
+ for (pp = (XIMArg *)p->value;
+ pp && pp->name; pp++, quark_list++) {
+ *q_list = XrmStringToQuark(pp->name);
+ }
+ *q_list = separator;
+ } else {
+ if (!_XimCheckNestedQuarkList(&quark_list, idx + 1,
+ &num_quark, (XIMArg *)p->value, separator)) {
+ ic->private.proto.saved_icvalues = quark_list;
+ ic->private.proto.num_saved_icvalues = num_quark;
+ return False;
+ }
+ }
+ } else {
+ if (_XimCheckICQuarkList(quark_list, num_quark, quark, &idx)) {
+ continue;
+ }
+ if (!(tmp = (XrmQuark *)Xrealloc(quark_list,
+ (sizeof(XrmQuark) * (num_quark + 1))))) {
+ ic->private.proto.saved_icvalues = quark_list;
+ ic->private.proto.num_saved_icvalues = num_quark;
+ return False;
+ }
+ quark_list = tmp;
+ quark_list[num_quark] = quark;
+ num_quark++;
+ }
+ }
+ ic->private.proto.saved_icvalues = quark_list;
+ ic->private.proto.num_saved_icvalues = num_quark;
+ return True;
+ }
+
+ for (p = arg, n = 0; p && p->name; p++, n++) {
+ if ((!strcmp(p->name, XNPreeditAttributes))
+ || (!strcmp(p->name, XNStatusAttributes))) {
+ register XIMArg *pp;
+ int nn;
+
+ for (pp = (XIMArg *)p->value, nn = 0; pp && pp->name; pp++, nn++);
+ n += nn + 1;
+ }
+ }
+
+ if (!(quark_list = (XrmQuark *)Xmalloc(sizeof(XrmQuark) * n))) {
+ return False;
+ }
+
+ ic->private.proto.saved_icvalues = quark_list;
+ ic->private.proto.num_saved_icvalues = n;
+ for (p = arg; p && p->name; p++, quark_list++) {
+ *quark_list = XrmStringToQuark(p->name);
+ if ((*quark_list == pre_quark) || (*quark_list == sts_quark)) {
+ register XIMArg *pp;
+
+ quark_list++;
+ for (pp = (XIMArg *)p->value; pp && pp->name; pp++, quark_list++) {
+ *quark_list = XrmStringToQuark(pp->name);
+ }
+ *quark_list = separator;
+ }
+ }
+ return True;
+}
+
+Private char *
+_XimDelayModeSetICValues(ic, arg)
+ Xic ic;
+ XIMArg *arg;
+{
+ XimDefICValues ic_values;
+ char *name;
+
+ _XimGetCurrentICValues(ic, &ic_values);
+ name = _XimSetICValueData(ic, (XPointer)&ic_values,
+ ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources,
+ arg, XIM_SETICVALUES, False);
+ _XimSetCurrentICValues(ic, &ic_values);
+ return name;
+}
+#endif /* XIM_CONNECTABLE */
+
+Private Bool
+_XimSetICValuesCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ Xic ic = (Xic)arg;
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+
+ if ((major_opcode == XIM_SET_IC_VALUES_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid)
+ && (icid == ic->private.proto.icid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid)
+ && (buf_s[2] & XIM_ICID_VALID)
+ && (icid == ic->private.proto.icid))
+ return True;
+ return False;
+}
+
+Private char *
+_XimProtoSetICValues(
+ XIC xic,
+ XIMArg *arg)
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ XimDefICValues ic_values;
+ INT16 len;
+ CARD16 *buf_s;
+ char *tmp;
+ CARD32 tmp_buf32[BUFSIZE/4];
+ char *tmp_buf = (char *)tmp_buf32;
+ char *buf;
+ int buf_size;
+ char *data;
+ int data_len;
+ int ret_len;
+ int total;
+ XIMArg *arg_ret;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply = NULL;
+ int ret_code;
+ BITMASK32 flag = 0L;
+ char *name;
+ char *tmp_name = (arg) ? arg->name : NULL;
+
+#ifndef XIM_CONNECTABLE
+ if (!IS_IC_CONNECTED(ic))
+ return tmp_name;
+#else
+ if (!_XimSaveICValues(ic, arg))
+ return NULL;
+
+ if (!IS_IC_CONNECTED(ic)) {
+ if (IS_CONNECTABLE(im)) {
+ if (_XimConnectServer(im)) {
+ if (!_XimReCreateIC(ic)) {
+ _XimDelayModeSetAttr(im);
+ return _XimDelayModeSetICValues(ic, arg);
+ }
+ } else {
+ return _XimDelayModeSetICValues(ic, arg);
+ }
+ } else {
+ return tmp_name;
+ }
+ }
+#endif /* XIM_CONNECTABLE */
+
+ _XimGetCurrentICValues(ic, &ic_values);
+ buf = tmp_buf;
+ buf_size = XIM_HEADER_SIZE
+ + sizeof(CARD16) + sizeof(CARD16) + sizeof(INT16) + sizeof(CARD16);
+ data_len = BUFSIZE - buf_size;
+ total = 0;
+ arg_ret = arg;
+ for (;;) {
+ data = &buf[buf_size];
+ if ((name = _XimEncodeICATTRIBUTE(ic, ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources, arg, &arg_ret,
+ data, data_len, &ret_len, (XPointer)&ic_values,
+ &flag, XIM_SETICVALUES))) {
+ break;
+ }
+
+ total += ret_len;
+ if (!(arg = arg_ret)) {
+ break;
+ }
+
+ buf_size += ret_len;
+ if (buf == tmp_buf) {
+ if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
+ return tmp_name;
+ }
+ memcpy(tmp, buf, buf_size);
+ buf = tmp;
+ } else {
+ if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
+ Xfree(buf);
+ return tmp_name;
+ }
+ buf = tmp;
+ }
+ }
+ _XimSetCurrentICValues(ic, &ic_values);
+
+ if (!total) {
+ return tmp_name;
+ }
+
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+
+#ifdef EXT_MOVE
+ if (_XimExtenMove(im, ic, flag, &buf_s[4], (INT16)total))
+ return name;
+#endif
+
+ buf_s[0] = im->private.proto.imid;
+ buf_s[1] = ic->private.proto.icid;
+ buf_s[2] = (INT16)total;
+ buf_s[3] = 0;
+ len = (INT16)(sizeof(CARD16) + sizeof(CARD16)
+ + sizeof(INT16) + sizeof(CARD16) + total);
+
+ _XimSetHeader((XPointer)buf, XIM_SET_IC_VALUES, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ if (buf != tmp_buf)
+ Xfree(buf);
+ return tmp_name;
+ }
+ _XimFlush(im);
+ if (buf != tmp_buf)
+ Xfree(buf);
+ ic->private.proto.waitCallback = True;
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimSetICValuesCheck, (XPointer)ic);
+ if (ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if (ret_code == XIM_OVERFLOW) {
+ buf_size = (int)len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimSetICValuesCheck, (XPointer)ic);
+ if (ret_code != XIM_TRUE) {
+ Xfree(preply);
+ ic->private.proto.waitCallback = False;
+ return tmp_name;
+ }
+ } else {
+ ic->private.proto.waitCallback = False;
+ return tmp_name;
+ }
+ ic->private.proto.waitCallback = False;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if (reply != preply)
+ Xfree(preply);
+ return tmp_name;
+ }
+ if (reply != preply)
+ Xfree(preply);
+
+ return name;
+}
+
+Private Bool
+_XimDestroyICCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ Xic ic = (Xic)arg;
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+ Bool ret = False;
+
+ if ((major_opcode == XIM_DESTROY_IC_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid)
+ && (icid == ic->private.proto.icid))
+ ret = True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid)
+ && (buf_s[2] & XIM_ICID_VALID)
+ && (icid == ic->private.proto.icid))
+ ret = False;
+ return ret;
+}
+
+Private void
+_XimProtoICFree(
+ Xic ic)
+{
+#ifdef XIM_CONNECTABLE
+ Xim im = (Xim)ic->core.im;
+#endif
+
+ if (ic->private.proto.preedit_font) {
+ Xfree(ic->private.proto.preedit_font);
+ ic->private.proto.preedit_font = NULL;
+ }
+ if (ic->private.proto.status_font) {
+ Xfree(ic->private.proto.status_font);
+ ic->private.proto.status_font = NULL;
+ }
+ if (ic->private.proto.commit_info) {
+ _XimFreeCommitInfo(ic);
+ ic->private.proto.commit_info = NULL;
+ }
+ if (ic->private.proto.ic_inner_resources) {
+ Xfree(ic->private.proto.ic_inner_resources);
+ ic->private.proto.ic_inner_resources = NULL;
+ }
+
+#ifdef XIM_CONNECTABLE
+ if (IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
+ return;
+ }
+#endif /* XIM_CONNECTABLE */
+
+ if (ic->private.proto.saved_icvalues) {
+ Xfree(ic->private.proto.saved_icvalues);
+ ic->private.proto.saved_icvalues = NULL;
+ }
+ if (ic->private.proto.ic_resources) {
+ Xfree(ic->private.proto.ic_resources);
+ ic->private.proto.ic_resources = NULL;
+ }
+ if (ic->core.hotkey) {
+ Xfree(ic->core.hotkey);
+ ic->core.hotkey = NULL;
+ }
+
+ return;
+}
+
+Private void
+_XimProtoDestroyIC(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+
+ if (IS_SERVER_CONNECTED(im)) {
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16); /* sizeof icid */
+
+ _XimSetHeader((XPointer)buf, XIM_DESTROY_IC, 0, &len);
+ (void)_XimWrite(im, len, (XPointer)buf);
+ _XimFlush(im);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimDestroyICCheck, (XPointer)ic);
+ if (ret_code == XIM_OVERFLOW) {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ (void)_XimRead(im, &len, preply, buf_size,
+ _XimDestroyICCheck, (XPointer)ic);
+ Xfree(preply);
+ }
+ }
+ UNMARK_IC_CONNECTED(ic);
+ _XimUnregisterFilter(ic);
+ _XimProtoICFree(ic);
+ return;
+}
+
+Private void
+_XimProtoSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len;
+
+#ifndef XIM_CONNECTABLE
+ if (!IS_IC_CONNECTED(ic))
+ return;
+#else
+ if (!IS_IC_CONNECTED(ic)) {
+ if (IS_CONNECTABLE(im)) {
+ if (_XimConnectServer(im)) {
+ if (!_XimReCreateIC(ic)) {
+ _XimDelayModeSetAttr(im);
+ return;
+ }
+ } else {
+ return;
+ }
+ } else {
+ return;
+ }
+ }
+#endif /* XIM_CONNECTABLE */
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16); /* sizeof icid */
+
+ _XimSetHeader((XPointer)buf, XIM_SET_IC_FOCUS, 0, &len);
+ (void)_XimWrite(im, len, (XPointer)buf);
+ _XimFlush(im);
+
+ MARK_FOCUSED(ic);
+
+ _XimRegisterFilter(ic);
+ return;
+}
+
+Private void
+_XimProtoUnsetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len;
+
+#ifndef XIM_CONNECTABLE
+ if (!IS_IC_CONNECTED(ic))
+ return;
+#else
+ if (!IS_IC_CONNECTED(ic)) {
+ if (IS_CONNECTABLE(im)) {
+ if (_XimConnectServer(im)) {
+ if (!_XimReCreateIC(ic)) {
+ _XimDelayModeSetAttr(im);
+ return;
+ }
+ } else {
+ return;
+ }
+ } else {
+ return;
+ }
+ }
+#endif /* XIM_CONNECTABLE */
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16); /* sizeof icid */
+
+ _XimSetHeader((XPointer)buf, XIM_UNSET_IC_FOCUS, 0, &len);
+ (void)_XimWrite(im, len, (XPointer)buf);
+ _XimFlush(im);
+
+ UNMARK_FOCUSED(ic);
+
+ _XimUnregisterFilter(ic);
+ return;
+}
+
+Private Bool
+_XimResetICCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ Xic ic = (Xic)arg;
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+
+ if ((major_opcode == XIM_RESET_IC_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid)
+ && (icid == ic->private.proto.icid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid)
+ && (buf_s[2] & XIM_ICID_VALID)
+ && (icid == ic->private.proto.icid))
+ return True;
+ return False;
+}
+
+Private char *
+_XimProtoReset(
+ XIC xic,
+ char * (*retfunc) (Xim im, Xic ic, XPointer buf) )
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+ char *commit;
+
+ if (!IS_IC_CONNECTED(ic))
+ return (char *)NULL;
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16); /* sizeof icid */
+
+ _XimSetHeader((XPointer)buf, XIM_RESET_IC, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return NULL;
+ _XimFlush(im);
+ ic->private.proto.waitCallback = True;
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimResetICCheck, (XPointer)ic);
+ if (ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if (ret_code == XIM_OVERFLOW) {
+ if (len < 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimResetICCheck, (XPointer)ic);
+ if (ret_code != XIM_TRUE) {
+ Xfree(preply);
+ ic->private.proto.waitCallback = False;
+ return NULL;
+ }
+ }
+ } else {
+ ic->private.proto.waitCallback = False;
+ return NULL;
+ }
+ ic->private.proto.waitCallback = False;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if (reply != preply)
+ free(preply);
+ return NULL;
+ }
+
+ commit = retfunc(im, ic, (XPointer)&buf_s[2]);
+
+ if (reply != preply)
+ Xfree(preply);
+ return commit;
+}
+
+Private char *
+_XimCommitedMbString(
+ Xim im,
+ Xic ic,
+ XPointer buf)
+{
+ CARD16 *buf_s = (CARD16 *)buf;
+ XimCommitInfo info;
+ int len;
+ int new_len;
+ char *commit;
+ char *new_commit = NULL;
+ char *str;
+ Status status;
+
+ len = 0;
+ for (info = ic->private.proto.commit_info; info; info = info->next)
+ len += info->string_len;
+ len += buf_s[0];
+ if ( len == 0 )
+ return( NULL );
+
+ if (!(commit = (char *)Xmalloc(len + 1)))
+ goto Error_On_Reset;
+
+ str = commit;
+ for (info = ic->private.proto.commit_info; info; info = info->next) {
+ (void)memcpy(str, info->string, info->string_len);
+ str += info->string_len;
+ }
+ (void)memcpy(str, (char *)&buf_s[1], buf_s[0]);
+ commit[len] = '\0';
+
+ new_len = im->methods->ctstombs((XIM)im, commit, len, NULL, 0, &status);
+ if (status != XLookupNone) {
+ if (!(new_commit = Xmalloc(new_len + 1))) {
+ Xfree(commit);
+ goto Error_On_Reset;
+ }
+ (void)im->methods->ctstombs((XIM)im, commit, len,
+ new_commit, new_len, NULL);
+ new_commit[new_len] = '\0';
+ }
+ Xfree(commit);
+
+Error_On_Reset:
+ _XimFreeCommitInfo( ic );
+ return new_commit;
+}
+
+Private char *
+_XimProtoMbReset(
+ XIC xic)
+{
+ return _XimProtoReset(xic, _XimCommitedMbString);
+}
+
+Private wchar_t *
+_XimCommitedWcString(
+ Xim im,
+ Xic ic,
+ XPointer buf)
+{
+ CARD16 *buf_s = (CARD16 *)buf;
+ XimCommitInfo info;
+ int len;
+ int new_len;
+ char *commit;
+ wchar_t *new_commit = (wchar_t *)NULL;
+ char *str;
+ Status status;
+
+ len = 0;
+ for (info = ic->private.proto.commit_info; info; info = info->next)
+ len += info->string_len;
+ len += buf_s[0];
+ if ( len == 0 )
+ return( (wchar_t *)NULL );
+
+ if (!(commit = (char *)Xmalloc(len + 1)))
+ goto Error_On_Reset;
+
+ str = commit;
+ for (info = ic->private.proto.commit_info; info; info = info->next) {
+ (void)memcpy(str, info->string, info->string_len);
+ str += info->string_len;
+ }
+ (void)memcpy(str, (char *)&buf_s[1], buf_s[0]);
+ commit[len] = '\0';
+
+ new_len = im->methods->ctstowcs((XIM)im, commit, len, NULL, 0, &status);
+ if (status != XLookupNone) {
+ if (!(new_commit =
+ (wchar_t *)Xmalloc(sizeof(wchar_t) * (new_len + 1)))) {
+ Xfree(commit);
+ goto Error_On_Reset;
+ }
+ (void)im->methods->ctstowcs((XIM)im, commit, len,
+ new_commit, new_len, NULL);
+ new_commit[new_len] = (wchar_t)'\0';
+ }
+ Xfree(commit);
+
+Error_On_Reset:
+ _XimFreeCommitInfo( ic );
+ return new_commit;
+}
+
+Private wchar_t *
+_XimProtoWcReset(
+ XIC xic)
+{
+ return (wchar_t *) _XimProtoReset(xic,
+ (char * (*) (Xim, Xic, XPointer)) _XimCommitedWcString);
+}
+
+Private char *
+_XimCommitedUtf8String(
+ Xim im,
+ Xic ic,
+ XPointer buf)
+{
+ CARD16 *buf_s = (CARD16 *)buf;
+ XimCommitInfo info;
+ int len;
+ int new_len;
+ char *commit;
+ char *new_commit = NULL;
+ char *str;
+ Status status;
+
+ len = 0;
+ for (info = ic->private.proto.commit_info; info; info = info->next)
+ len += info->string_len;
+ len += buf_s[0];
+ if ( len == 0 )
+ return( NULL );
+
+ if (!(commit = (char *)Xmalloc(len + 1)))
+ goto Error_On_Reset;
+
+ str = commit;
+ for (info = ic->private.proto.commit_info; info; info = info->next) {
+ (void)memcpy(str, info->string, info->string_len);
+ str += info->string_len;
+ }
+ (void)memcpy(str, (char *)&buf_s[1], buf_s[0]);
+ commit[len] = '\0';
+
+ new_len = im->methods->ctstoutf8((XIM)im, commit, len, NULL, 0, &status);
+ if (status != XLookupNone) {
+ if (!(new_commit = Xmalloc(new_len + 1))) {
+ Xfree(commit);
+ goto Error_On_Reset;
+ }
+ (void)im->methods->ctstoutf8((XIM)im, commit, len,
+ new_commit, new_len, NULL);
+ new_commit[new_len] = '\0';
+ }
+ Xfree(commit);
+
+Error_On_Reset:
+ _XimFreeCommitInfo( ic );
+ return new_commit;
+}
+
+Private char *
+_XimProtoUtf8Reset(
+ XIC xic)
+{
+ return _XimProtoReset(xic, _XimCommitedUtf8String);
+}
+
+Private XICMethodsRec ic_methods = {
+ _XimProtoDestroyIC, /* destroy */
+ _XimProtoSetFocus, /* set_focus */
+ _XimProtoUnsetFocus, /* unset_focus */
+ _XimProtoSetICValues, /* set_values */
+ _XimProtoGetICValues, /* get_values */
+ _XimProtoMbReset, /* mb_reset */
+ _XimProtoWcReset, /* wc_reset */
+ _XimProtoUtf8Reset, /* utf8_reset */
+ _XimProtoMbLookupString, /* mb_lookup_string */
+ _XimProtoWcLookupString, /* wc_lookup_string */
+ _XimProtoUtf8LookupString /* utf8_lookup_string */
+};
+
+Private Bool
+_XimGetInputStyle(
+ XIMArg *arg,
+ XIMStyle *input_style)
+{
+ register XIMArg *p;
+
+ for (p = arg; p && p->name; p++) {
+ if (!(strcmp(p->name, XNInputStyle))) {
+ *input_style = (XIMStyle)p->value;
+ return True;
+ }
+ }
+ return False;
+}
+
+#ifdef XIM_CONNECTABLE
+Private Bool
+_XimDelayModeCreateIC(
+ Xic ic,
+ XIMArg *values,
+ XIMResourceList res,
+ unsigned int num)
+{
+ Xim im = (Xim)ic->core.im;
+ XimDefICValues ic_values;
+ int len;
+ XIMStyle input_style;
+
+ bzero((char *)&ic_values, sizeof(XimDefICValues));
+ _XimGetCurrentICValues(ic, &ic_values);
+ if (!(_XimGetInputStyle(values, &input_style)))
+ return False;
+
+ _XimSetICMode(res, num, input_style);
+
+ if (_XimSetICValueData(ic, (XPointer)&ic_values, res, num,
+ values, XIM_CREATEIC, False)) {
+ return False;
+ }
+ _XimSetCurrentICValues(ic, &ic_values);
+ if (!_XimSetICDefaults(ic, (XPointer)&ic_values,
+ XIM_SETICDEFAULTS, res, num)) {
+ return False;
+ }
+ ic_values.filter_events = KeyPressMask;
+ _XimSetCurrentICValues(ic, &ic_values);
+ _XimRegisterFilter(ic);
+
+ return True;
+}
+
+Public Bool
+_XimReconnectModeCreateIC(ic)
+ Xic ic;
+{
+ Xim im = (Xim)ic->core.im;
+ int len;
+ XIMStyle input_style = ic->core.input_style;
+ XIMResourceList res;
+ unsigned int num;
+
+ num = im->core.ic_num_resources;
+ len = sizeof(XIMResource) * num;
+ if (!(res = (XIMResourceList)Xmalloc(len)))
+ return False;
+ (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
+ ic->private.proto.ic_resources = res;
+ ic->private.proto.ic_num_resources = num;
+
+ _XimSetICMode(res, num, input_style);
+
+ ic->core.filter_events = KeyPressMask;
+
+ return True;
+}
+#endif /* XIM_CONNECTABLE */
+
+Public XIC
+_XimProtoCreateIC(
+ XIM xim,
+ XIMArg *arg)
+{
+ Xim im = (Xim)xim;
+ Xic ic;
+ XimDefICValues ic_values;
+ XIMResourceList res;
+ unsigned int num;
+ XIMStyle input_style;
+ INT16 len;
+ CARD16 *buf_s;
+ char *tmp;
+ CARD32 tmp_buf32[BUFSIZE/4];
+ char *tmp_buf = (char *)tmp_buf32;
+ char *buf;
+ int buf_size;
+ char *data;
+ int data_len;
+ int ret_len;
+ int total;
+ XIMArg *arg_ret;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int ret_code;
+
+#ifdef XIM_CONNECTABLE
+ if (!IS_SERVER_CONNECTED(im) && !IS_CONNECTABLE(im))
+ return (XIC)NULL;
+#else
+ if (!IS_SERVER_CONNECTED(im))
+ return (XIC)NULL;
+#endif /* XIM_CONNECTABLE */
+
+ if (!(_XimGetInputStyle(arg, &input_style)))
+ return (XIC)NULL;
+
+ if ((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL)
+ return (XIC)NULL;
+
+ ic->methods = &ic_methods;
+ ic->core.im = (XIM)im;
+ ic->core.input_style = input_style;
+
+ num = im->core.ic_num_resources;
+ len = sizeof(XIMResource) * num;
+ if (!(res = (XIMResourceList)Xmalloc(len)))
+ goto ErrorOnCreatingIC;
+ (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
+ ic->private.proto.ic_resources = res;
+ ic->private.proto.ic_num_resources = num;
+
+#ifdef XIM_CONNECTABLE
+ if (!_XimSaveICValues(ic, arg))
+ return False;
+
+ if (!IS_SERVER_CONNECTED(im)) {
+ if (!_XimConnectServer(im)) {
+ if (_XimDelayModeCreateIC(ic, arg, res, num)) {
+ return (XIC)ic;
+ }
+ goto ErrorOnCreatingIC;
+ }
+ }
+#endif /* XIM_CONNECTABLE */
+
+ ic->core.filter_events = im->private.proto.forward_event_mask;
+ ic->private.proto.forward_event_mask =
+ im->private.proto.forward_event_mask;
+ ic->private.proto.synchronous_event_mask =
+ im->private.proto.synchronous_event_mask;
+
+ num = im->private.proto.ic_num_inner_resources;
+ len = sizeof(XIMResource) * num;
+ if (!(res = (XIMResourceList)Xmalloc(len)))
+ goto ErrorOnCreatingIC;
+ (void)memcpy((char *)res,
+ (char *)im->private.proto.ic_inner_resources, len);
+ ic->private.proto.ic_inner_resources = res;
+ ic->private.proto.ic_num_inner_resources = num;
+
+ _XimSetICMode(ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources, input_style);
+
+ _XimSetICMode(ic->private.proto.ic_inner_resources,
+ ic->private.proto.ic_num_inner_resources, input_style);
+
+ _XimGetCurrentICValues(ic, &ic_values);
+ buf = tmp_buf;
+ buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
+ data_len = BUFSIZE - buf_size;
+ total = 0;
+ arg_ret = arg;
+ for (;;) {
+ data = &buf[buf_size];
+ if (_XimEncodeICATTRIBUTE(ic, ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources, arg, &arg_ret, data,
+ data_len, &ret_len, (XPointer)&ic_values, 0, XIM_CREATEIC)) {
+ goto ErrorOnCreatingIC;
+ }
+
+ total += ret_len;
+ if (!(arg = arg_ret)) {
+ break;
+ }
+
+ buf_size += ret_len;
+ if (buf == tmp_buf) {
+ if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
+ goto ErrorOnCreatingIC;
+ }
+ memcpy(tmp, buf, buf_size);
+ buf = tmp;
+ } else {
+ if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
+ Xfree(buf);
+ goto ErrorOnCreatingIC;
+ }
+ buf = tmp;
+ }
+ }
+ _XimSetCurrentICValues(ic, &ic_values);
+
+ if (!(_XimCheckCreateICValues(ic->private.proto.ic_resources,
+ ic->private.proto.ic_num_resources)))
+ goto ErrorOnCreatingIC;
+
+ _XimRegisterFilter(ic);
+
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ buf_s[0] = im->private.proto.imid;
+ buf_s[1] = (INT16)total;
+
+ len = (INT16)(sizeof(CARD16) + sizeof(INT16) + total);
+ _XimSetHeader((XPointer)buf, XIM_CREATE_IC, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ if (buf != tmp_buf)
+ Xfree(buf);
+ goto ErrorOnCreatingIC;
+ }
+ _XimFlush(im);
+ if (buf != tmp_buf)
+ Xfree(buf);
+ ic->private.proto.waitCallback = True;
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimCreateICCheck, 0);
+ if (ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if (ret_code == XIM_OVERFLOW) {
+ if (len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = (int)len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimCreateICCheck, 0);
+ if (ret_code != XIM_TRUE) {
+ Xfree(preply);
+ ic->private.proto.waitCallback = False;
+ goto ErrorOnCreatingIC;
+ }
+ }
+ } else {
+ ic->private.proto.waitCallback = False;
+ goto ErrorOnCreatingIC;
+ }
+ ic->private.proto.waitCallback = False;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if (reply != preply)
+ Xfree(preply);
+ goto ErrorOnCreatingIC;
+ }
+
+ ic->private.proto.icid = buf_s[1]; /* icid */
+ if (reply != preply)
+ Xfree(preply);
+ MARK_IC_CONNECTED(ic);
+ return (XIC)ic;
+
+ErrorOnCreatingIC:
+ _XimUnregisterFilter(ic);
+ if (ic->private.proto.ic_resources)
+ Xfree(ic->private.proto.ic_resources);
+ if (ic->private.proto.ic_inner_resources)
+ Xfree(ic->private.proto.ic_inner_resources);
+ Xfree(ic);
+ return (XIC)NULL;
+}
diff --git a/libX11/modules/im/ximcp/imDefIm.c b/libX11/modules/im/ximcp/imDefIm.c
index 2ea4427c3..18a3cc85f 100644
--- a/libX11/modules/im/ximcp/imDefIm.c
+++ b/libX11/modules/im/ximcp/imDefIm.c
@@ -1,2044 +1,2044 @@
-/*
- * Copyright 1990, 1991, 1992 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/******************************************************************
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
- Copyright 1993, 1994 by Sony Corporation
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the names of Digital, FUJITSU
-LIMITED and Sony Corporation not be used in advertising or publicity
-pertaining to distribution of the software without specific, written
-prior permission.
-
-DIGITAL, FUJITSU LIMITED AND SONY CORPORATION DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL, FUJITSU LIMITED
-AND SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
- Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
- Makoto Wakamatsu Sony Corporation
- makoto@sm.sony.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xatom.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcPublic.h"
-#include "XlcPubI.h"
-#include "XimTrInt.h"
-#include "Ximint.h"
-
-
-Public int
-_XimCheckDataSize(
- XPointer buf,
- int len)
-{
- CARD16 *buf_s = (CARD16 *)buf;
-
- if(len < XIM_HEADER_SIZE)
- return -1;
- return buf_s[1];
-}
-
-Public void
-_XimSetHeader(
- XPointer buf,
- CARD8 major_opcode,
- CARD8 minor_opcode,
- INT16 *len
-)
-{
- CARD8 *buf_b = (CARD8 *)buf;
- CARD16 *buf_s = (CARD16 *)buf;
-
- buf_b[0] = major_opcode;
- buf_b[1] = minor_opcode;
- buf_s[1] = ((*len) / 4);
- *len += XIM_HEADER_SIZE;
- return;
-}
-
-Public char
-_XimGetMyEndian(void)
-{
- CARD16 test_card = 1;
-
- if(*((char *)&test_card))
- return LITTLEENDIAN;
- else
- return BIGENDIAN;
-}
-
-Private Bool
-_XimCheckServerName(
- Xim im,
- char *str)
-{
- char *server_name = im->core.im_name;
- int len;
- int str_len;
- int category_len = strlen(XIM_SERVER_CATEGORY);
- char *pp;
- register char *p;
-
- if(server_name && *server_name)
- len = strlen(server_name);
- else
- return True;
-
- if((int)strlen(str) < category_len)
- return False;
-
- if(strncmp(str, XIM_SERVER_CATEGORY, category_len))
- return False;
-
- pp = &str[category_len];
-
- for(;;) {
- for(p = pp; (*p != ',') && (*p); p++);
- str_len = (int)(p - pp);
-
- if((len == str_len) && (!strncmp(pp, server_name, len)))
- break;
- if(!(*p))
- return False;
- pp = p + 1;
- }
- return True;
-}
-
-Private char *
-_XimCheckLocaleName(
- Xim im,
- char *address,
- int address_len,
- char *locale_name[],
- int len)
-{
- int category_len;
- char *pp;
- register char *p;
- register int n;
- Bool finish = False;
-
- category_len = strlen(XIM_LOCAL_CATEGORY);
- if(address_len < category_len)
- return (char*)NULL;
-
- if(strncmp(address, XIM_LOCAL_CATEGORY, category_len))
- return (char*)NULL;
-
- pp = &address[category_len];
-
- for(;;) {
- for( p = pp; *p && *p != ','; p++);
- if (!*p)
- finish = True;
- address_len = (int)(p - pp);
- *p = '\0';
-
- for( n = 0; n < len; n++ )
- if( locale_name[n] && !_XlcCompareISOLatin1( pp, locale_name[n] ) )
- return locale_name[n];
- if (finish)
- break;
- pp = p + 1;
- }
- return (char *)NULL;
-}
-
-Private Bool
-_XimCheckTransport(
- char *address,
- int address_len,
- const char *transport,
- int len,
- char **trans_addr)
-{
- int category_len = strlen(XIM_TRANSPORT_CATEGORY);
- char *pp;
- register char *p;
-
- if(address_len < category_len)
- return False;
-
- if(strncmp(address, XIM_TRANSPORT_CATEGORY, category_len))
- return False;
-
- pp = &address[category_len];
-
- for(;;) {
- *trans_addr = pp;
-
- for(p = pp; (*p != '/') && (*p != ',') && (*p); p++);
- if(*p == ',') {
- pp = p + 1;
- continue;
- }
- if(!(*p))
- return False;
-
- address_len = (int)(p - pp);
-
- if((len == address_len) && (!strncmp(pp, transport, len)))
- break;
- pp = p + 1;
- }
- pp = p + 1;
- for(p = pp; (*p != ',') && (*p); p++);
- if (*p)
- *p = '\0';
- return True;
-}
-
-Private Bool
-_CheckSNEvent(
- Display *display,
- XEvent *xevent,
- XPointer arg)
-{
- XSelectionEvent *event = (XSelectionEvent *)xevent;
- Window window = *(Window*)arg;
-
- if((event->type == SelectionNotify) && (window == event->requestor))
- return True;
- return False;
-}
-
-Private Bool
-_XimGetSelectionNotify(
- Display *display,
- Window window,
- Atom target,
- char **ret_address)
-{
- XEvent event;
- XSelectionEvent *ev = (XSelectionEvent *)&event;
- Atom actual_type;
- int actual_format;
- unsigned long nitems, bytes_after;
-
- for(;;) {
- XIfEvent(display, &event, _CheckSNEvent, (XPointer)&window);
- if((ev->type == SelectionNotify) && (window == ev->requestor))
- break;
- }
-
- if(ev->property == (Atom)None)
- return False;
- if( XGetWindowProperty( display, window, target, 0L, 1000000L,
- True, target, &actual_type, &actual_format,
- &nitems, &bytes_after,
- (unsigned char **)&*ret_address ) != Success )
- return False;
- return True;
-}
-
-Private Bool
-_XimPreConnectionIM(
- Xim im,
- Atom selection)
-{
- Display *display = im->core.display;
- Atom locales, transport;
- char *address;
- XLCd lcd;
- char *language;
- char *territory;
- char *codeset;
- char *trans_addr;
- char *locale_name[4], *locale;
- int llen, tlen, clen;
- register int i;
- Window window;
- char *str;
-
- if(!(lcd = im->core.lcd))
- return False;
-
- for( i = 0; i < 4; i++ )
- locale_name[i] = NULL;
- /* requestor window */
- if(!(window = XCreateSimpleWindow(display, DefaultRootWindow(display),
- 0, 0, 1, 1, 1, 0, 0)))
- return False;
-
- /* server name check */
- if( !(str = XGetAtomName( display, selection )) )
- return False;
- if(!_XimCheckServerName(im, str)) {
- XFree( (XPointer)str );
- goto Error;
- }
- XFree( (XPointer)str );
-
- /* locale name check */
- _XGetLCValues(lcd, XlcNLanguage, &language, XlcNTerritory, &territory,
- XlcNCodeset, &codeset, NULL);
- llen = strlen( language );
- tlen = territory ? strlen( territory ): 0;
- clen = codeset ? strlen( codeset ): 0;
-
- if( tlen != 0 && clen != 0 ) {
- if( (locale_name[0] = Xmalloc(llen+tlen+clen+3)) != NULL )
- sprintf( locale_name[0], "%s_%s.%s", language, territory, codeset );
- }
- if( clen != 0 ) {
- if( (locale_name[1] = Xmalloc(llen+clen+2)) != NULL )
- sprintf( locale_name[1], "%s.%s", language, codeset );
- else
- goto Error;
- }
- if( tlen != 0 ) {
- if( (locale_name[2] = Xmalloc(llen+tlen+2)) != NULL )
- sprintf( locale_name[2], "%s_%s", language, territory );
- else
- goto Error;
- }
- if( (locale_name[3] = Xmalloc(llen+1)) != NULL )
- strcpy( locale_name[3], language );
- else
- goto Error;
- if((locales = XInternAtom(display, XIM_LOCALES, True)) == (Atom)None)
- goto Error;
-
- XConvertSelection(display, selection, locales, locales, window,
- CurrentTime);
- if(!(_XimGetSelectionNotify(display, window, locales, &address)))
- goto Error;
-
- if((locale = _XimCheckLocaleName(im, address, strlen(address), locale_name,
- 4)) == NULL) {
- XFree((XPointer)address);
- goto Error;
- }
- im->private.proto.locale_name = locale;
- for( i = 0; i < 4; i++ ) {
- if( locale_name[i] != NULL && locale_name[i] != locale ) {
- XFree( locale_name[i] );
- locale_name[i] = NULL;
- }
- }
- XFree((XPointer)address);
-
- /* transport check */
- if((transport = XInternAtom(display, XIM_TRANSPORT, True)) == (Atom)None)
- goto Error;
-
- XConvertSelection(display, selection, transport, transport, window,
- CurrentTime);
- if(!_XimGetSelectionNotify(display, window, transport, &address))
- goto Error;
-
- for(i = 0; _XimTransportRec[i].transportname ; i++) {
- if( _XimCheckTransport(address, strlen(address),
- _XimTransportRec[i].transportname,
- strlen(_XimTransportRec[i].transportname),
- &trans_addr)) {
- if( _XimTransportRec[i].config(im, trans_addr) ) {
- XFree((XPointer)address);
- XDestroyWindow(display, window);
- return True;
- }
- }
- }
-
- XFree((XPointer)address);
-Error:
- for( i = 0; i < 4; i++ )
- if( locale_name[i] != NULL )
- XFree( locale_name[i] );
- XDestroyWindow(display, window);
- return False;
-}
-
-Private Bool
-_XimPreConnect(
- Xim im)
-{
- Display *display = im->core.display;
- Atom imserver;
- Atom actual_type;
- int actual_format;
- unsigned long nitems;
- unsigned long bytes_after;
- unsigned char *prop_return;
- Atom *atoms;
- Window im_window = 0;
- register int i;
-
- if((imserver = XInternAtom(display, XIM_SERVERS, True)) == (Atom)None)
- return False;
-
- if(XGetWindowProperty(display, RootWindow(display, 0),
- imserver, 0L, 1000000L, False, XA_ATOM, &actual_type,
- &actual_format, &nitems, &bytes_after,
- &prop_return) != Success)
- return False;
-
- if( (actual_type != XA_ATOM) || (actual_format != 32) ) {
- if( nitems )
- XFree((XPointer)prop_return);
- return False;
- }
-
- atoms = (Atom *)prop_return;
- for(i = 0; i < nitems; i++) {
- if((im_window = XGetSelectionOwner(display, atoms[i])) == (Window)None)
- continue;
-
- if(_XimPreConnectionIM(im, atoms[i]))
- break;
- }
-
- XFree((XPointer)prop_return);
- if(i >= nitems)
- return False;
-
- im->private.proto.im_window = im_window;
- return True;
-}
-
-Private Bool
-_XimGetAuthProtocolNames(
- Xim im,
- CARD16 *buf,
- CARD8 *num,
- INT16 *len)
-{
- if (!IS_USE_AUTHORIZATION_FUNC(im)) {
- *num = 0;
- *len = 0;
- return True;
- }
- /*
- * Not yet
- */
- return True;
-}
-
-Private Bool
-_XimSetAuthReplyData(
- Xim im,
- XPointer buf,
- INT16 *len)
-{
- /*
- * Not yet
- */
- *len = 0;
- return True;
-}
-
-Private Bool
-_XimSetAuthNextData(
- Xim im,
- XPointer buf,
- INT16 *len)
-{
- /*
- * Not yet
- */
- *len = 0;
- return True;
-}
-
-Private Bool
-_XimSetAuthRequiredData(
- Xim im,
- XPointer buf,
- INT16 *len)
-{
- /*
- * Not yet
- */
- *len = 0;
- return True;
-}
-
-Private Bool
-_XimCheckAuthSetupData(
- Xim im,
- XPointer buf)
-{
- /*
- * Not yet
- */
- return True;
-}
-
-Private Bool
-_XimCheckAuthNextData(
- Xim im,
- XPointer buf)
-{
- /*
- * Not yet
- */
- return True;
-}
-
-#define NO_MORE_AUTH 2
-#define GOOD_AUTH 1
-#define BAD_AUTH 0
-
-Private int
-_XimClientAuthCheck(
- Xim im,
- XPointer buf)
-{
- /*
- * Not yet
- */
- return NO_MORE_AUTH;
-}
-
-Private void
-_XimAuthNG(
- Xim im)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- INT16 len = 0;
-
- _XimSetHeader((XPointer)buf, XIM_AUTH_NG, 0, &len);
- (void)_XimWrite(im, len, (XPointer)buf);
- _XimFlush(im);
- return;
-}
-
-Private Bool
-_XimAllRecv(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- return True;
-}
-
-#define CLIENT_WAIT1 1
-#define CLIENT_WAIT2 2
-
-Private Bool
-_XimConnection(
- Xim im)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD8 *buf_b = &buf[XIM_HEADER_SIZE];
- CARD16 *buf_s = (CARD16 *)((XPointer)buf_b);
- INT16 len;
- CARD8 num;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
- CARD8 major_opcode;
- int wait_mode;
- int ret;
-
- if(!(_XimConnect(im))) /* Transport Connect */
- return False;
-
- if(!_XimDispatchInit(im))
- return False;
-
- _XimRegProtoIntrCallback(im, XIM_ERROR, 0, _XimErrorCallback, (XPointer)im);
-
- if(!_XimGetAuthProtocolNames(im, &buf_s[4], &num, &len))
- return False;
-
- im->private.proto.protocol_major_version = PROTOCOLMAJORVERSION;
- im->private.proto.protocol_minor_version = PROTOCOLMINORVERSION;
-
- buf_b[0] = _XimGetMyEndian();
- buf_b[1] = 0;
- buf_s[1] = PROTOCOLMAJORVERSION;
- buf_s[2] = PROTOCOLMINORVERSION;
- buf_s[3] = num;
- len += sizeof(CARD8)
- + sizeof(CARD8)
- + sizeof(CARD16)
- + sizeof(CARD16)
- + sizeof(CARD16);
-
- major_opcode = XIM_CONNECT;
- wait_mode = (IS_USE_AUTHORIZATION_FUNC(im)) ? CLIENT_WAIT1 : CLIENT_WAIT2;
-
- for(;;) {
- _XimSetHeader((XPointer)buf, major_opcode, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, reply, buf_size, _XimAllRecv, 0);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size, _XimAllRecv, 0);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return False;
- }
- }
- } else
- return False;
-
- major_opcode = *((CARD8 *)preply);
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
-
- if (wait_mode == CLIENT_WAIT1) {
- if (major_opcode == XIM_AUTH_REQUIRED) {
- ret = _XimClientAuthCheck(im, (XPointer)buf_s);
- if(reply != preply)
- Xfree(preply);
- if (ret == NO_MORE_AUTH) {
- if (!(_XimSetAuthReplyData(im,
- (XPointer)&buf[XIM_HEADER_SIZE], &len))) {
- _XimAuthNG(im);
- return False;
- }
- major_opcode = XIM_AUTH_REPLY;
- wait_mode = CLIENT_WAIT2;
- } else if (ret == GOOD_AUTH) {
- if (!(_XimSetAuthNextData(im,
- (XPointer)&buf[XIM_HEADER_SIZE], &len))) {
- _XimAuthNG(im);
- return False;
- }
- major_opcode = XIM_AUTH_NEXT;
- } else { /* BAD_AUTH */
- _XimAuthNG(im);
- return False;
- }
- } else {
- if(reply != preply)
- Xfree(preply);
- _XimAuthNG(im);
- return False;
- }
- } else { /* CLIENT_WAIT2 */
- if (major_opcode == XIM_CONNECT_REPLY) {
- break;
- } else if (major_opcode == XIM_AUTH_SETUP) {
- if (!(_XimCheckAuthSetupData(im, (XPointer)buf_s))) {
- _XimAuthNG(im);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
- if (!(_XimSetAuthRequiredData(im,
- (XPointer)&buf[XIM_HEADER_SIZE], &len))) {
- _XimAuthNG(im);
- return False;
- }
- major_opcode = XIM_AUTH_REQUIRED;
- } else if (major_opcode == XIM_AUTH_NEXT) {
- if (!(_XimCheckAuthNextData(im, (XPointer)buf_s))) {
- _XimAuthNG(im);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
- if (!(_XimSetAuthRequiredData(im,
- (XPointer)&buf[XIM_HEADER_SIZE], &len))) {
- _XimAuthNG(im);
- return False;
- }
- major_opcode = XIM_AUTH_REQUIRED;
- } else if (major_opcode == XIM_AUTH_NG) {
- if(reply != preply)
- Xfree(preply);
- return False;
- } else {
- _XimAuthNG(im);
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- }
- }
-
- if (!( buf_s[0] == im->private.proto.protocol_major_version
- && buf_s[1] == im->private.proto.protocol_minor_version)) {
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
- MARK_SERVER_CONNECTED(im);
-
- _XimRegProtoIntrCallback(im, XIM_REGISTER_TRIGGERKEYS, 0,
- _XimRegisterTriggerKeysCallback, (XPointer)im);
- return True;
-}
-
-Private Bool
-_XimDisconnectCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
-
- if ((major_opcode == XIM_DISCONNECT_REPLY)
- && (minor_opcode == 0))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0))
- return True;
- return False;
-}
-
-Private Bool
-_XimDisconnect(
- Xim im)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- INT16 len = 0;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
-
- if (IS_SERVER_CONNECTED(im)) {
- _XimSetHeader((XPointer)buf, XIM_DISCONNECT, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimDisconnectCheck, 0);
- if(ret_code == XIM_OVERFLOW) {
- if(len > 0) {
- buf_size = len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimDisconnectCheck, 0);
- Xfree(preply);
- if(ret_code != XIM_TRUE)
- return False;
- }
- } else if(ret_code == XIM_FALSE)
- return False;
-
- }
- if (!(_XimShutdown(im))) /* Transport shutdown */
- return False;
- return True;
-}
-
-Private Bool
-_XimOpenCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
-
- if ((major_opcode == XIM_OPEN_REPLY)
- && (minor_opcode == 0))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0))
- return True;
- return False;
-}
-
-Private Bool
-_XimOpen(
- Xim im)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD8 *buf_b = &buf[XIM_HEADER_SIZE];
- CARD16 *buf_s;
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
- char *locale_name;
-
- locale_name = im->private.proto.locale_name;
- len = strlen(locale_name);
- buf_b[0] = (BYTE)len; /* length of locale name */
- (void)strcpy((char *)&buf_b[1], locale_name); /* locale name */
- len += sizeof(BYTE); /* sizeof length */
- XIM_SET_PAD(buf_b, len); /* pad */
-
- _XimSetHeader((XPointer)buf, XIM_OPEN, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, reply, buf_size,
- _XimOpenCheck, 0);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimOpenCheck, 0);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return False;
- }
- }
- } else
- return False;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if(reply != preply)
- Xfree(preply);
- return False;
- }
-
- im->private.proto.imid = buf_s[0]; /* imid */
-
- if (!(_XimGetAttributeID(im, &buf_s[1]))) {
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
-
- if (!(_XimSetInnerIMResourceList(&(im->private.proto.im_inner_resources),
- &(im->private.proto.im_num_inner_resources))))
- return False;
-
- if (!(_XimSetInnerICResourceList(&(im->private.proto.ic_inner_resources),
- &(im->private.proto.ic_num_inner_resources))))
- return False;
-
- _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
- _XimSetIMMode(im->private.proto.im_inner_resources,
- im->private.proto.im_num_inner_resources);
-
- /* Transport Callbak */
- _XimRegProtoIntrCallback(im, XIM_SET_EVENT_MASK, 0,
- _XimSetEventMaskCallback, (XPointer)im);
- _XimRegProtoIntrCallback(im, XIM_FORWARD_EVENT, 0,
- _XimForwardEventCallback, (XPointer)im);
- _XimRegProtoIntrCallback(im, XIM_COMMIT, 0,
- _XimCommitCallback, (XPointer)im);
- _XimRegProtoIntrCallback(im, XIM_SYNC, 0,
- _XimSyncCallback, (XPointer)im);
-
- if(!_XimExtension(im))
- return False;
-
- /* register a hook for callback protocols */
- _XimRegisterDispatcher(im, _XimCbDispatch, (XPointer)im);
-
- return True;
-}
-
-Private Bool
-_XimCloseCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
-
- if ((major_opcode == XIM_CLOSE_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid))
- return True;
- return False;
-}
-
-Private Bool
-_XimClose(
- Xim im)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
-
- if (!IS_SERVER_CONNECTED(im))
- return True;
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = 0; /* unused */
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16); /* sizeof unused */
-
- _XimSetHeader((XPointer)buf, XIM_CLOSE, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimCloseCheck, 0);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size, _XimCloseCheck, 0);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return False;
- }
- }
- } else
- return False;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if(reply != preply)
- Xfree(preply);
- return False;
- }
-
- if(reply != preply)
- Xfree(preply);
- return True;
-}
-
-Public void
-_XimProtoIMFree(
- Xim im)
-{
- /* XIMPrivateRec */
- if (im->private.proto.im_onkeylist) {
- Xfree(im->private.proto.im_onkeylist);
- im->private.proto.im_onkeylist = NULL;
- }
- if (im->private.proto.im_offkeylist) {
- Xfree(im->private.proto.im_offkeylist);
- im->private.proto.im_offkeylist = NULL;
- }
- if (im->private.proto.intrproto) {
- _XimFreeProtoIntrCallback(im);
- im->private.proto.intrproto = NULL;
- }
- if (im->private.proto.im_inner_resources) {
- Xfree(im->private.proto.im_inner_resources);
- im->private.proto.im_inner_resources = NULL;
- }
- if (im->private.proto.ic_inner_resources) {
- Xfree(im->private.proto.ic_inner_resources);
- im->private.proto.ic_inner_resources = NULL;
- }
- if (im->private.proto.hold_data) {
- Xfree(im->private.proto.hold_data);
- im->private.proto.hold_data = NULL;
- }
- if (im->private.proto.locale_name) {
- Xfree(im->private.proto.locale_name);
- im->private.proto.locale_name = NULL;
- }
- if (im->private.proto.ctom_conv) {
- _XlcCloseConverter(im->private.proto.ctom_conv);
- im->private.proto.ctom_conv = NULL;
- }
- if (im->private.proto.ctow_conv) {
- _XlcCloseConverter(im->private.proto.ctow_conv);
- im->private.proto.ctow_conv = NULL;
- }
- if (im->private.proto.ctoutf8_conv) {
- _XlcCloseConverter(im->private.proto.ctoutf8_conv);
- im->private.proto.ctoutf8_conv = NULL;
- }
- if (im->private.proto.cstomb_conv) {
- _XlcCloseConverter(im->private.proto.cstomb_conv);
- im->private.proto.cstomb_conv = NULL;
- }
- if (im->private.proto.cstowc_conv) {
- _XlcCloseConverter(im->private.proto.cstowc_conv);
- im->private.proto.cstowc_conv = NULL;
- }
- if (im->private.proto.cstoutf8_conv) {
- _XlcCloseConverter(im->private.proto.cstoutf8_conv);
- im->private.proto.cstoutf8_conv = NULL;
- }
- if (im->private.proto.ucstoc_conv) {
- _XlcCloseConverter(im->private.proto.ucstoc_conv);
- im->private.proto.ucstoc_conv = NULL;
- }
- if (im->private.proto.ucstoutf8_conv) {
- _XlcCloseConverter(im->private.proto.ucstoutf8_conv);
- im->private.proto.ucstoutf8_conv = NULL;
- }
-
-#ifdef XIM_CONNECTABLE
- if (!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
- return;
- }
-#endif /* XIM_CONNECTABLE */
-
- if (im->private.proto.saved_imvalues) {
- Xfree(im->private.proto.saved_imvalues);
- im->private.proto.saved_imvalues = NULL;
- }
- if (im->private.proto.default_styles) {
- Xfree(im->private.proto.default_styles);
- im->private.proto.default_styles = NULL;
- }
-
- /* core */
- if (im->core.res_name) {
- Xfree(im->core.res_name);
- im->core.res_name = NULL;
- }
- if (im->core.res_class) {
- Xfree(im->core.res_class);
- im->core.res_class = NULL;
- }
- if (im->core.im_values_list) {
- Xfree(im->core.im_values_list);
- im->core.im_values_list = NULL;
- }
- if (im->core.ic_values_list) {
- Xfree(im->core.ic_values_list);
- im->core.ic_values_list = NULL;
- }
- if (im->core.im_name) {
- Xfree(im->core.im_name);
- im->core.im_name = NULL;
- }
- if (im->core.styles) {
- Xfree(im->core.styles);
- im->core.styles = NULL;
- }
- if (im->core.im_resources) {
- Xfree(im->core.im_resources);
- im->core.im_resources = NULL;
- }
- if (im->core.ic_resources) {
- Xfree(im->core.ic_resources);
- im->core.ic_resources = NULL;
- }
-
- return;
-}
-
-Private Status
-_XimProtoCloseIM(
- XIM xim)
-{
- Xim im = (Xim)xim;
- XIC ic;
- XIC next;
- Status status;
-
- ic = im->core.ic_chain;
- while (ic) {
- (*ic->methods->destroy) (ic);
- next = ic->core.next;
-#ifdef XIM_CONNECTABLE
- if (!(!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im))) {
- Xfree ((char *) ic);
- }
-#else
- Xfree ((char *) ic);
-#endif /* XIM_CONNECTABLE */
- ic = next;
- }
-#ifdef XIM_CONNECTABLE
- if (!(!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)))
- im->core.ic_chain = NULL;
-#else
- im->core.ic_chain = NULL;
-#endif
-
- _XimUnregisterServerFilter(im);
- _XimResetIMInstantiateCallback(im);
- status = (Status)_XimClose(im);
- status = (Status)_XimDisconnect(im) && status;
- _XimProtoIMFree(im);
-#ifdef XIM_CONNECTABLE
- if (!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
- _XimReconnectModeSetAttr(im);
- for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
- _XimReconnectModeCreateIC(ic);
- }
- return 0;
- }
-#endif /* XIM_CONNECTABLE */
- _XimDestroyIMStructureList(im);
- return status;
-}
-
-#ifdef XIM_CONNECTABLE
-Private Bool
-_XimCheckIMQuarkList(
- XrmQuark *quark_list,
- int num_quark,
- XrmQuark quark)
-{
- register int i;
-
- for (i = 0; i < num_quark; i++) {
- if (quark_list[i] == quark) {
- return True;
- }
- }
- return False;
-}
-
-Private Bool
-_XimSaveIMValues(
- Xim im,
- XIMArg *arg)
-{
- register XIMArg *p;
- register int n;
- XrmQuark *quark_list;
- XrmQuark *tmp;
- XrmQuark quark;
- int num_quark;
-
- if (quark_list = im->private.proto.saved_imvalues) {
- num_quark = im->private.proto.num_saved_imvalues;
- for (p = arg; p && p->name; p++) {
- quark = XrmStringToQuark(p->name);
- if (_XimCheckIMQuarkList(quark_list, num_quark, quark)) {
- continue;
- }
- if (!(tmp = (XrmQuark *)Xrealloc(quark_list,
- (sizeof(XrmQuark) * (num_quark + 1))))) {
- im->private.proto.saved_imvalues = quark_list;
- im->private.proto.num_saved_imvalues = num_quark;
- return False;
- }
- num_quark++;
- quark_list = tmp;
- quark_list[num_quark] = quark;
- }
- im->private.proto.saved_imvalues = quark_list;
- im->private.proto.num_saved_imvalues = num_quark;
- return True;
- }
-
- for (p = arg, n = 0; p && p->name; p++, n++);
-
- if (!(quark_list = (XrmQuark *)Xmalloc(sizeof(XrmQuark) * n))) {
- return False;
- }
-
- im->private.proto.saved_imvalues = quark_list;
- im->private.proto.num_saved_imvalues = n;
- for (p = arg; p && p->name; p++, quark_list++) {
- *quark_list = XrmStringToQuark(p->name);
- }
-
- return True;
-}
-
-Private char *
-_XimDelayModeSetIMValues(
- Xim im,
- XIMArg *arg)
-{
- XimDefIMValues im_values;
- char *name;
- XIMArg *values;
-
- _XimGetCurrentIMValues(im, &im_values);
- name = _XimSetIMValueData(im, (XPointer)&im_values, values,
- im->core.im_resources, im->core.im_num_resources);
- _XimSetCurrentIMValues(im, &im_values);
-
- return name;
-}
-#endif /* XIM_CONNECTABLE */
-
-Private Bool
-_XimSetIMValuesCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
-
- if ((major_opcode == XIM_SET_IM_VALUES_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid))
- return True;
- return False;
-}
-
-Private char *
-_XimProtoSetIMValues(
- XIM xim,
- XIMArg *arg)
-{
- Xim im = (Xim)xim;
- XimDefIMValues im_values;
- INT16 len;
- CARD16 *buf_s;
- char *tmp;
- CARD32 tmp_buf32[BUFSIZE/4];
- char *tmp_buf = (char *)tmp_buf32;
- char *buf;
- int buf_size;
- char *data;
- int data_len;
- int ret_len;
- int total;
- XIMArg *arg_ret;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int ret_code;
- char *name;
-
-#ifndef XIM_CONNECTABLE
- if (!IS_SERVER_CONNECTED(im))
- return arg->name;
-#else
- if (!_XimSaveIMValues(im, arg))
- return arg->name;
-
- if (!IS_SERVER_CONNECTED(im)) {
- if (IS_CONNECTABLE(im)) {
- if (!_XimConnectServer(im)) {
- return _XimDelayModeSetIMValues(im, arg);
- }
- } else {
- return arg->name;
- }
- }
-#endif /* XIM_CONNECTABLE */
-
- _XimGetCurrentIMValues(im, &im_values);
- buf = tmp_buf;
- buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
- data_len = BUFSIZE - buf_size;
- total = 0;
- arg_ret = arg;
- for (;;) {
- data = &buf[buf_size];
- if ((name = _XimEncodeIMATTRIBUTE(im, im->core.im_resources,
- im->core.im_num_resources, arg, &arg_ret, data, data_len,
- &ret_len, (XPointer)&im_values, XIM_SETIMVALUES))) {
- if (buf != tmp_buf)
- Xfree(buf);
- break;
- }
-
- total += ret_len;
- if (!(arg = arg_ret)) {
- break;
- }
-
- buf_size += ret_len;
- if (buf == tmp_buf) {
- if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
- return arg->name;
- }
- memcpy(tmp, buf, buf_size);
- buf = tmp;
- } else {
- if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
- Xfree(buf);
- return arg->name;
- }
- buf = tmp;
- }
- }
- _XimSetCurrentIMValues(im, &im_values);
-
- if (!total)
- return (char *)NULL;
-
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- buf_s[0] = im->private.proto.imid;
- buf_s[1] = (INT16)total;
-
- len = (INT16)(sizeof(CARD16) + sizeof(INT16) + total);
- _XimSetHeader((XPointer)buf, XIM_SET_IM_VALUES, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- if (buf != tmp_buf)
- Xfree(buf);
- return arg->name;
- }
- _XimFlush(im);
- if (buf != tmp_buf)
- Xfree(buf);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimSetIMValuesCheck, 0);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = (int)len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, reply, buf_size,
- _XimSetIMValuesCheck, 0);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return arg->name;
- }
- }
- } else
- return arg->name;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if(reply != preply)
- Xfree(preply);
- return arg->name;
- }
- if(reply != preply)
- Xfree(preply);
-
- return name;
-}
-
-#ifdef XIM_CONNECTABLE
-Private char *
-_XimDelayModeGetIMValues(
- Xim im,
- XIMArg *arg)
-{
- XimDefIMValues im_values;
-
- _XimGetCurrentIMValues(im, &im_values);
- return(_XimGetIMValueData(im, (XPointer)&im_values, arg,
- im->core.im_resources, im->core.im_num_resources));
-}
-#endif /* XIM_CONNECTABLE */
-
-Private Bool
-_XimGetIMValuesCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
-
- if ((major_opcode == XIM_GET_IM_VALUES_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid))
- return True;
- return False;
-}
-
-Private char *
-_XimProtoGetIMValues(
- XIM xim,
- XIMArg *arg)
-{
- Xim im = (Xim)xim;
- register XIMArg *p;
- register int n;
- CARD8 *buf;
- CARD16 *buf_s;
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply = NULL;
- int buf_size;
- int ret_code;
- char *makeid_name;
- char *decode_name;
- CARD16 *data = NULL;
- INT16 data_len = 0;
-
-#ifndef XIM_CONNECTABLE
- if (!IS_SERVER_CONNECTED(im))
- return arg->name;
-#else
- if (!IS_SERVER_CONNECTED(im)) {
- if (IS_CONNECTABLE(im)) {
- if (!_XimConnectServer(im)) {
- return _XimDelayModeGetIMValues(im, arg);
- }
- } else {
- return arg->name;
- }
- }
-#endif /* XIM_CONNECTABLE */
-
- for (n = 0, p = arg; p->name; p++)
- n++;
-
- if (!n)
- return (char *)NULL;
-
- buf_size = sizeof(CARD16) * n;
- buf_size += XIM_HEADER_SIZE
- + sizeof(CARD16)
- + sizeof(INT16)
- + XIM_PAD(buf_size);
-
- if (!(buf = (CARD8 *)Xmalloc(buf_size)))
- return arg->name;
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
-
- makeid_name = _XimMakeIMAttrIDList(im, im->core.im_resources,
- im->core.im_num_resources, arg,
- &buf_s[2], &len, XIM_GETIMVALUES);
-
- if (len) {
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = len; /* length of im-attr-id */
- XIM_SET_PAD(&buf_s[2], len); /* pad */
- len += sizeof(CARD16) /* sizeof imid */
- + sizeof(INT16); /* sizeof length of attr */
-
- _XimSetHeader((XPointer)buf, XIM_GET_IM_VALUES, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- Xfree(buf);
- return arg->name;
- }
- _XimFlush(im);
- Xfree(buf);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimGetIMValuesCheck, 0);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimGetIMValuesCheck, 0);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return arg->name;
- }
- }
- } else
- return arg->name;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if(reply != preply)
- Xfree(preply);
- return arg->name;
- }
- data = &buf_s[2];
- data_len = buf_s[1];
- }
- decode_name = _XimDecodeIMATTRIBUTE(im, im->core.im_resources,
- im->core.im_num_resources, data, data_len,
- arg, XIM_GETIMVALUES);
- if (reply != preply)
- Xfree(preply);
-
- if (decode_name)
- return decode_name;
- else
- return makeid_name;
-}
-
-Private XIMMethodsRec im_methods = {
- _XimProtoCloseIM, /* close */
- _XimProtoSetIMValues, /* set_values */
- _XimProtoGetIMValues, /* get_values */
- _XimProtoCreateIC, /* create_ic */
- _Ximctstombs, /* ctstombs */
- _Ximctstowcs, /* ctstowcs */
- _Ximctstoutf8 /* ctstoutf8 */
-};
-
-Private Bool
-_XimSetEncodingByName(
- Xim im,
- char **buf,
- int *len)
-{
- char *encoding = (char *)NULL;
- int encoding_len;
- int compound_len;
- BYTE *ret;
-
- _XGetLCValues(im->core.lcd, XlcNCodeset, &encoding, NULL);
- if (!encoding) {
- *buf = (char *)NULL;
- *len = 0;
- return True;
- }
- encoding_len = strlen(encoding);
- compound_len = strlen("COMPOUND_TEXT");
- *len = encoding_len + sizeof(BYTE) + compound_len + sizeof(BYTE);
- if (!(ret = (BYTE *)Xmalloc(*len))) {
- return False;
- }
- *buf = (char *)ret;
-
- ret[0] = (BYTE)encoding_len;
- (void)strncpy((char *)&ret[1], encoding, encoding_len);
- ret += (encoding_len + sizeof(BYTE));
- ret[0] = (BYTE)compound_len;
- (void)strncpy((char *)&ret[1], "COMPOUND_TEXT", compound_len);
- return True;
-}
-
-Private Bool
-_XimSetEncodingByDetail(
- Xim im,
- char **buf,
- int *len)
-{
- *len = 0;
- *buf = NULL;
- return True;
-}
-
-Private Bool
-_XimGetEncoding(
- Xim im,
- CARD16 *buf,
- char *name,
- int name_len,
- char *detail,
- int detail_len)
-{
- XLCd lcd = im->core.lcd;
- CARD16 category = buf[0];
- CARD16 idx = buf[1];
- int len;
- XlcConv ctom_conv = NULL;
- XlcConv ctow_conv = NULL;
- XlcConv ctoutf8_conv = NULL;
- XlcConv conv;
- XimProtoPrivateRec *private = &im->private.proto;
-
- if (idx == (CARD16)XIM_Default_Encoding_IDX) { /* XXX */
- if (!(ctom_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNMultiByte)))
- return False;
- if (!(ctow_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNWideChar)))
- return False;
- if (!(ctoutf8_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNUtf8String)))
- return False;
- }
-
- if (category == XIM_Encoding_NameCategory) {
- while (name_len > 0) {
- len = (int)name[0];
- if (!strncmp(&name[1], "COMPOUND_TEXT", len)) {
- if (!(ctom_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNMultiByte)))
- return False;
- if (!(ctow_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNWideChar)))
- return False;
- if (!(ctoutf8_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNUtf8String)))
- return False;
- break;
- } else {
- /*
- * Not yet
- */
- }
- len += sizeof(BYTE);
- name_len -= len;
- name += len;
- }
- } else if (category == XIM_Encoding_DetailCategory) {
- /*
- * Not yet
- */
- } else {
- return False;
- }
-
- private->ctom_conv = ctom_conv;
- private->ctow_conv = ctow_conv;
- private->ctoutf8_conv = ctoutf8_conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte)))
- return False;
- private->cstomb_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar)))
- return False;
- private->cstowc_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String)))
- return False;
- private->cstoutf8_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar)))
- return False;
- private->ucstoc_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String)))
- return False;
- private->ucstoutf8_conv = conv;
-
- return True;
-}
-
-Private Bool
-_XimEncodingNegoCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
-
- if ((major_opcode == XIM_ENCODING_NEGOTIATION_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid))
- return True;
- return False;
-}
-
-Private Bool
-_XimEncodingNegotiation(
- Xim im)
-{
- char *name_ptr = 0;
- int name_len = 0;
- char *detail_ptr = 0;
- int detail_len = 0;
- CARD8 *buf;
- CARD16 *buf_s;
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
-
- if (!(_XimSetEncodingByName(im, &name_ptr, &name_len)))
- return False;
-
- if (!(_XimSetEncodingByDetail(im, &detail_ptr, &detail_len)))
- goto free_name_ptr;
-
- len = sizeof(CARD16)
- + sizeof(INT16)
- + name_len
- + XIM_PAD(name_len)
- + sizeof(INT16)
- + sizeof(CARD16)
- + detail_len;
-
- if (!(buf = (CARD8 *)Xmalloc(XIM_HEADER_SIZE + len)))
- goto free_detail_ptr;
-
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
-
- buf_s[0] = im->private.proto.imid;
- buf_s[1] = (INT16)name_len;
- if (name_ptr)
- (void)memcpy((char *)&buf_s[2], name_ptr, name_len);
- XIM_SET_PAD(&buf_s[2], name_len);
- buf_s = (CARD16 *)((char *)&buf_s[2] + name_len);
- buf_s[0] = detail_len;
- buf_s[1] = 0;
- if (detail_ptr)
- (void)memcpy((char *)&buf_s[2], detail_ptr, detail_len);
-
- _XimSetHeader((XPointer)buf, XIM_ENCODING_NEGOTIATION, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- Xfree(buf);
- goto free_detail_ptr;
- }
- _XimFlush(im);
- Xfree(buf);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimEncodingNegoCheck, 0);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimEncodingNegoCheck, 0);
- if(ret_code != XIM_TRUE)
- goto free_preply;
- }
- } else
- goto free_detail_ptr;
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- goto free_preply;
- }
-
- if (!(_XimGetEncoding(im, &buf_s[1], name_ptr, name_len,
- detail_ptr, detail_len)))
- goto free_preply;
-
- if (name_ptr)
- Xfree(name_ptr);
- if (detail_ptr)
- Xfree(detail_ptr);
-
- if(reply != preply)
- Xfree(preply);
-
- return True;
-
-free_preply:
- if (reply != preply)
- Xfree(preply);
-
-free_detail_ptr:
- Xfree(detail_ptr);
-
-free_name_ptr:
- Xfree(name_ptr);
-
- return False;
-}
-
-#ifdef XIM_CONNECTABLE
-Private Bool
-_XimSendSavedIMValues(
- Xim im)
-{
- XimDefIMValues im_values;
- INT16 len;
- CARD16 *buf_s;
- char *tmp;
- CARD32 tmp_buf32[BUFSIZE/4];
- char *tmp_buf = (char *)tmp_buf32;
- char *buf;
- int buf_size;
- char *data;
- int data_len;
- int ret_len;
- int total;
- int idx;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int ret_code;
-
- _XimGetCurrentIMValues(im, &im_values);
- buf = tmp_buf;
- buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
- data_len = BUFSIZE - buf_size;
- total = 0;
- idx = 0;
- for (;;) {
- data = &buf[buf_size];
- if (!_XimEncodeSavedIMATTRIBUTE(im, im->core.im_resources,
- im->core.im_num_resources, &idx, data, data_len,
- &ret_len, (XPointer)&im_values, XIM_SETIMVALUES)) {
- if (buf != tmp_buf)
- Xfree(buf);
- return False;
- }
-
- total += ret_len;
- if (idx == -1) {
- break;
- }
-
- buf_size += ret_len;
- if (buf == tmp_buf) {
- if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
- return False;
- }
- memcpy(tmp, buf, buf_size);
- buf = tmp;
- } else {
- if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
- Xfree(buf);
- return False;
- }
- buf = tmp;
- }
- }
-
- if (!total)
- return True;
-
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- buf_s[0] = im->private.proto.imid;
- buf_s[1] = (INT16)total;
-
- len = (INT16)(sizeof(CARD16) + sizeof(INT16) + total);
- _XimSetHeader((XPointer)buf, XIM_SET_IM_VALUES, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- if (buf != tmp_buf)
- Xfree(buf);
- return False;
- }
- _XimFlush(im);
- if (buf != tmp_buf)
- Xfree(buf);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimSetIMValuesCheck, 0);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = (int)len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, reply, buf_size,
- _XimSetIMValuesCheck, 0);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return False;
- }
- }
- } else
- return False;
-
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
-
- return True;
-}
-
-Private void
-_XimDelayModeIMFree(
- Xim im)
-{
- if (im->core.im_resources) {
- Xfree(im->core.im_resources);
- im->core.im_resources = NULL;
- }
- if (im->core.ic_resources) {
- Xfree(im->core.ic_resources);
- im->core.ic_resources = NULL;
- }
- if (im->core.im_values_list) {
- Xfree(im->core.im_values_list);
- im->core.im_values_list = NULL;
- }
- if (im->core.ic_values_list) {
- Xfree(im->core.ic_values_list);
- im->core.ic_values_list = NULL;
- }
- return;
-}
-
-Public Bool
-_XimConnectServer(
- Xim im)
-{
- Xim save_im;
-
- if (!(save_im = (Xim)Xmalloc(sizeof(XimRec))))
- return False;
- memcpy((char *)save_im, (char *)im, sizeof(XimRec));
-
- if (_XimPreConnect(im) && _XimConnection(im)
- && _XimOpen(im) && _XimEncodingNegotiation(im)) {
- if (_XimSendSavedIMValues(im)) {
- _XimDelayModeIMFree(save_im);
- _XimRegisterServerFilter(im);
- Xfree(save_im);
- return True;
- }
- }
- memcpy((char *)im, (char *)save_im, sizeof(XimRec));
- Xfree(save_im);
- return False;
-}
-
-Public Bool
-_XimDelayModeSetAttr(
- Xim im)
-{
- XimDefIMValues im_values;
-
- if(!_XimSetIMResourceList(&im->core.im_resources,
- &im->core.im_num_resources)) {
- return False;
- }
- if(!_XimSetICResourceList(&im->core.ic_resources,
- &im->core.ic_num_resources)) {
- return False;
- }
-
- _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
-
- _XimGetCurrentIMValues(im, &im_values);
- if(!_XimSetLocalIMDefaults(im, (XPointer)&im_values,
- im->core.im_resources, im->core.im_num_resources)) {
- return False;
- }
- _XimSetCurrentIMValues(im, &im_values);
- if (im->private.proto.default_styles) {
- if (im->core.styles)
- Xfree(im->core.styles);
- im->core.styles = im->private.proto.default_styles;
- }
-
- return True;
-}
-
-Private Bool
-_XimReconnectModeSetAttr(
- Xim im)
-{
- XimDefIMValues im_values;
-
- if(!_XimSetIMResourceList(&im->core.im_resources,
- &im->core.im_num_resources)) {
- return False;
- }
- if(!_XimSetICResourceList(&im->core.ic_resources,
- &im->core.ic_num_resources)) {
- return False;
- }
-
- _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
-
- if (im->private.proto.default_styles) {
- if (im->core.styles)
- Xfree(im->core.styles);
- im->core.styles = im->private.proto.default_styles;
- }
-
- return True;
-}
-#endif /* XIM_CONNECTABLE */
-
-Public Bool
-_XimProtoOpenIM(
- Xim im)
-{
- _XimInitialResourceInfo();
-
- im->methods = &im_methods;
-
-#ifdef XIM_CONNECTABLE
- _XimSetProtoResource(im);
-#endif /* XIM_CONNECTABLE */
-
- if (_XimPreConnect(im)) {
- if (_XimConnection(im) && _XimOpen(im) && _XimEncodingNegotiation(im)) {
- _XimRegisterServerFilter(im);
- return True;
- }
- _XimShutdown(im);
-#ifdef XIM_CONNECTABLE
- } else if (IS_DELAYBINDABLE(im)) {
- if (_XimDelayModeSetAttr(im))
- return True;
-#endif /* XIM_CONNECTABLE */
- }
- _XimProtoIMFree(im);
- return False;
-}
+/*
+ * Copyright 1990, 1991, 1992 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/******************************************************************
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+ Copyright 1993, 1994 by Sony Corporation
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Digital, FUJITSU
+LIMITED and Sony Corporation not be used in advertising or publicity
+pertaining to distribution of the software without specific, written
+prior permission.
+
+DIGITAL, FUJITSU LIMITED AND SONY CORPORATION DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL, FUJITSU LIMITED
+AND SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
+ Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+ Makoto Wakamatsu Sony Corporation
+ makoto@sm.sony.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xatom.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcPublic.h"
+#include "XlcPubI.h"
+#include "XimTrInt.h"
+#include "Ximint.h"
+
+
+Public int
+_XimCheckDataSize(
+ XPointer buf,
+ int len)
+{
+ CARD16 *buf_s = (CARD16 *)buf;
+
+ if(len < XIM_HEADER_SIZE)
+ return -1;
+ return buf_s[1];
+}
+
+Public void
+_XimSetHeader(
+ XPointer buf,
+ CARD8 major_opcode,
+ CARD8 minor_opcode,
+ INT16 *len
+)
+{
+ CARD8 *buf_b = (CARD8 *)buf;
+ CARD16 *buf_s = (CARD16 *)buf;
+
+ buf_b[0] = major_opcode;
+ buf_b[1] = minor_opcode;
+ buf_s[1] = ((*len) / 4);
+ *len += XIM_HEADER_SIZE;
+ return;
+}
+
+Public char
+_XimGetMyEndian(void)
+{
+ CARD16 test_card = 1;
+
+ if(*((char *)&test_card))
+ return LITTLEENDIAN;
+ else
+ return BIGENDIAN;
+}
+
+Private Bool
+_XimCheckServerName(
+ Xim im,
+ char *str)
+{
+ char *server_name = im->core.im_name;
+ int len;
+ int str_len;
+ int category_len = strlen(XIM_SERVER_CATEGORY);
+ char *pp;
+ register char *p;
+
+ if(server_name && *server_name)
+ len = strlen(server_name);
+ else
+ return True;
+
+ if((int)strlen(str) < category_len)
+ return False;
+
+ if(strncmp(str, XIM_SERVER_CATEGORY, category_len))
+ return False;
+
+ pp = &str[category_len];
+
+ for(;;) {
+ for(p = pp; (*p != ',') && (*p); p++);
+ str_len = (int)(p - pp);
+
+ if((len == str_len) && (!strncmp(pp, server_name, len)))
+ break;
+ if(!(*p))
+ return False;
+ pp = p + 1;
+ }
+ return True;
+}
+
+Private char *
+_XimCheckLocaleName(
+ Xim im,
+ char *address,
+ int address_len,
+ char *locale_name[],
+ int len)
+{
+ int category_len;
+ char *pp;
+ register char *p;
+ register int n;
+ Bool finish = False;
+
+ category_len = strlen(XIM_LOCAL_CATEGORY);
+ if(address_len < category_len)
+ return (char*)NULL;
+
+ if(strncmp(address, XIM_LOCAL_CATEGORY, category_len))
+ return (char*)NULL;
+
+ pp = &address[category_len];
+
+ for(;;) {
+ for( p = pp; *p && *p != ','; p++);
+ if (!*p)
+ finish = True;
+ address_len = (int)(p - pp);
+ *p = '\0';
+
+ for( n = 0; n < len; n++ )
+ if( locale_name[n] && !_XlcCompareISOLatin1( pp, locale_name[n] ) )
+ return locale_name[n];
+ if (finish)
+ break;
+ pp = p + 1;
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimCheckTransport(
+ char *address,
+ int address_len,
+ const char *transport,
+ int len,
+ char **trans_addr)
+{
+ int category_len = strlen(XIM_TRANSPORT_CATEGORY);
+ char *pp;
+ register char *p;
+
+ if(address_len < category_len)
+ return False;
+
+ if(strncmp(address, XIM_TRANSPORT_CATEGORY, category_len))
+ return False;
+
+ pp = &address[category_len];
+
+ for(;;) {
+ *trans_addr = pp;
+
+ for(p = pp; (*p != '/') && (*p != ',') && (*p); p++);
+ if(*p == ',') {
+ pp = p + 1;
+ continue;
+ }
+ if(!(*p))
+ return False;
+
+ address_len = (int)(p - pp);
+
+ if((len == address_len) && (!strncmp(pp, transport, len)))
+ break;
+ pp = p + 1;
+ }
+ pp = p + 1;
+ for(p = pp; (*p != ',') && (*p); p++);
+ if (*p)
+ *p = '\0';
+ return True;
+}
+
+Private Bool
+_CheckSNEvent(
+ Display *display,
+ XEvent *xevent,
+ XPointer arg)
+{
+ XSelectionEvent *event = (XSelectionEvent *)xevent;
+ Window window = *(Window*)arg;
+
+ if((event->type == SelectionNotify) && (window == event->requestor))
+ return True;
+ return False;
+}
+
+Private Bool
+_XimGetSelectionNotify(
+ Display *display,
+ Window window,
+ Atom target,
+ char **ret_address)
+{
+ XEvent event;
+ XSelectionEvent *ev = (XSelectionEvent *)&event;
+ Atom actual_type;
+ int actual_format;
+ unsigned long nitems, bytes_after;
+
+ for(;;) {
+ XIfEvent(display, &event, _CheckSNEvent, (XPointer)&window);
+ if((ev->type == SelectionNotify) && (window == ev->requestor))
+ break;
+ }
+
+ if(ev->property == (Atom)None)
+ return False;
+ if( XGetWindowProperty( display, window, target, 0L, 1000000L,
+ True, target, &actual_type, &actual_format,
+ &nitems, &bytes_after,
+ (unsigned char **)&*ret_address ) != Success )
+ return False;
+ return True;
+}
+
+Private Bool
+_XimPreConnectionIM(
+ Xim im,
+ Atom selection)
+{
+ Display *display = im->core.display;
+ Atom locales, transport;
+ char *address;
+ XLCd lcd;
+ char *language;
+ char *territory;
+ char *codeset;
+ char *trans_addr;
+ char *locale_name[4], *locale;
+ int llen, tlen, clen;
+ register int i;
+ Window window;
+ char *str;
+
+ if(!(lcd = im->core.lcd))
+ return False;
+
+ for( i = 0; i < 4; i++ )
+ locale_name[i] = NULL;
+ /* requestor window */
+ if(!(window = XCreateSimpleWindow(display, DefaultRootWindow(display),
+ 0, 0, 1, 1, 1, 0, 0)))
+ return False;
+
+ /* server name check */
+ if( !(str = XGetAtomName( display, selection )) )
+ return False;
+ if(!_XimCheckServerName(im, str)) {
+ XFree( (XPointer)str );
+ goto Error;
+ }
+ XFree( (XPointer)str );
+
+ /* locale name check */
+ _XGetLCValues(lcd, XlcNLanguage, &language, XlcNTerritory, &territory,
+ XlcNCodeset, &codeset, NULL);
+ llen = strlen( language );
+ tlen = territory ? strlen( territory ): 0;
+ clen = codeset ? strlen( codeset ): 0;
+
+ if( tlen != 0 && clen != 0 ) {
+ if( (locale_name[0] = Xmalloc(llen+tlen+clen+3)) != NULL )
+ sprintf( locale_name[0], "%s_%s.%s", language, territory, codeset );
+ }
+ if( clen != 0 ) {
+ if( (locale_name[1] = Xmalloc(llen+clen+2)) != NULL )
+ sprintf( locale_name[1], "%s.%s", language, codeset );
+ else
+ goto Error;
+ }
+ if( tlen != 0 ) {
+ if( (locale_name[2] = Xmalloc(llen+tlen+2)) != NULL )
+ sprintf( locale_name[2], "%s_%s", language, territory );
+ else
+ goto Error;
+ }
+ if( (locale_name[3] = Xmalloc(llen+1)) != NULL )
+ strcpy( locale_name[3], language );
+ else
+ goto Error;
+ if((locales = XInternAtom(display, XIM_LOCALES, True)) == (Atom)None)
+ goto Error;
+
+ XConvertSelection(display, selection, locales, locales, window,
+ CurrentTime);
+ if(!(_XimGetSelectionNotify(display, window, locales, &address)))
+ goto Error;
+
+ if((locale = _XimCheckLocaleName(im, address, strlen(address), locale_name,
+ 4)) == NULL) {
+ XFree((XPointer)address);
+ goto Error;
+ }
+ im->private.proto.locale_name = locale;
+ for( i = 0; i < 4; i++ ) {
+ if( locale_name[i] != NULL && locale_name[i] != locale ) {
+ XFree( locale_name[i] );
+ locale_name[i] = NULL;
+ }
+ }
+ XFree((XPointer)address);
+
+ /* transport check */
+ if((transport = XInternAtom(display, XIM_TRANSPORT, True)) == (Atom)None)
+ goto Error;
+
+ XConvertSelection(display, selection, transport, transport, window,
+ CurrentTime);
+ if(!_XimGetSelectionNotify(display, window, transport, &address))
+ goto Error;
+
+ for(i = 0; _XimTransportRec[i].transportname ; i++) {
+ if( _XimCheckTransport(address, strlen(address),
+ _XimTransportRec[i].transportname,
+ strlen(_XimTransportRec[i].transportname),
+ &trans_addr)) {
+ if( _XimTransportRec[i].config(im, trans_addr) ) {
+ XFree((XPointer)address);
+ XDestroyWindow(display, window);
+ return True;
+ }
+ }
+ }
+
+ XFree((XPointer)address);
+Error:
+ for( i = 0; i < 4; i++ )
+ if( locale_name[i] != NULL )
+ XFree( locale_name[i] );
+ XDestroyWindow(display, window);
+ return False;
+}
+
+Private Bool
+_XimPreConnect(
+ Xim im)
+{
+ Display *display = im->core.display;
+ Atom imserver;
+ Atom actual_type;
+ int actual_format;
+ unsigned long nitems;
+ unsigned long bytes_after;
+ unsigned char *prop_return;
+ Atom *atoms;
+ Window im_window = 0;
+ register int i;
+
+ if((imserver = XInternAtom(display, XIM_SERVERS, True)) == (Atom)None)
+ return False;
+
+ if(XGetWindowProperty(display, RootWindow(display, 0),
+ imserver, 0L, 1000000L, False, XA_ATOM, &actual_type,
+ &actual_format, &nitems, &bytes_after,
+ &prop_return) != Success)
+ return False;
+
+ if( (actual_type != XA_ATOM) || (actual_format != 32) ) {
+ if( nitems )
+ XFree((XPointer)prop_return);
+ return False;
+ }
+
+ atoms = (Atom *)prop_return;
+ for(i = 0; i < nitems; i++) {
+ if((im_window = XGetSelectionOwner(display, atoms[i])) == (Window)None)
+ continue;
+
+ if(_XimPreConnectionIM(im, atoms[i]))
+ break;
+ }
+
+ XFree((XPointer)prop_return);
+ if(i >= nitems)
+ return False;
+
+ im->private.proto.im_window = im_window;
+ return True;
+}
+
+Private Bool
+_XimGetAuthProtocolNames(
+ Xim im,
+ CARD16 *buf,
+ CARD8 *num,
+ INT16 *len)
+{
+ if (!IS_USE_AUTHORIZATION_FUNC(im)) {
+ *num = 0;
+ *len = 0;
+ return True;
+ }
+ /*
+ * Not yet
+ */
+ return True;
+}
+
+Private Bool
+_XimSetAuthReplyData(
+ Xim im,
+ XPointer buf,
+ INT16 *len)
+{
+ /*
+ * Not yet
+ */
+ *len = 0;
+ return True;
+}
+
+Private Bool
+_XimSetAuthNextData(
+ Xim im,
+ XPointer buf,
+ INT16 *len)
+{
+ /*
+ * Not yet
+ */
+ *len = 0;
+ return True;
+}
+
+Private Bool
+_XimSetAuthRequiredData(
+ Xim im,
+ XPointer buf,
+ INT16 *len)
+{
+ /*
+ * Not yet
+ */
+ *len = 0;
+ return True;
+}
+
+Private Bool
+_XimCheckAuthSetupData(
+ Xim im,
+ XPointer buf)
+{
+ /*
+ * Not yet
+ */
+ return True;
+}
+
+Private Bool
+_XimCheckAuthNextData(
+ Xim im,
+ XPointer buf)
+{
+ /*
+ * Not yet
+ */
+ return True;
+}
+
+#define NO_MORE_AUTH 2
+#define GOOD_AUTH 1
+#define BAD_AUTH 0
+
+Private int
+_XimClientAuthCheck(
+ Xim im,
+ XPointer buf)
+{
+ /*
+ * Not yet
+ */
+ return NO_MORE_AUTH;
+}
+
+Private void
+_XimAuthNG(
+ Xim im)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ INT16 len = 0;
+
+ _XimSetHeader((XPointer)buf, XIM_AUTH_NG, 0, &len);
+ (void)_XimWrite(im, len, (XPointer)buf);
+ _XimFlush(im);
+ return;
+}
+
+Private Bool
+_XimAllRecv(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ return True;
+}
+
+#define CLIENT_WAIT1 1
+#define CLIENT_WAIT2 2
+
+Private Bool
+_XimConnection(
+ Xim im)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD8 *buf_b = &buf[XIM_HEADER_SIZE];
+ CARD16 *buf_s = (CARD16 *)((XPointer)buf_b);
+ INT16 len;
+ CARD8 num;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+ CARD8 major_opcode;
+ int wait_mode;
+ int ret;
+
+ if(!(_XimConnect(im))) /* Transport Connect */
+ return False;
+
+ if(!_XimDispatchInit(im))
+ return False;
+
+ _XimRegProtoIntrCallback(im, XIM_ERROR, 0, _XimErrorCallback, (XPointer)im);
+
+ if(!_XimGetAuthProtocolNames(im, &buf_s[4], &num, &len))
+ return False;
+
+ im->private.proto.protocol_major_version = PROTOCOLMAJORVERSION;
+ im->private.proto.protocol_minor_version = PROTOCOLMINORVERSION;
+
+ buf_b[0] = _XimGetMyEndian();
+ buf_b[1] = 0;
+ buf_s[1] = PROTOCOLMAJORVERSION;
+ buf_s[2] = PROTOCOLMINORVERSION;
+ buf_s[3] = num;
+ len += sizeof(CARD8)
+ + sizeof(CARD8)
+ + sizeof(CARD16)
+ + sizeof(CARD16)
+ + sizeof(CARD16);
+
+ major_opcode = XIM_CONNECT;
+ wait_mode = (IS_USE_AUTHORIZATION_FUNC(im)) ? CLIENT_WAIT1 : CLIENT_WAIT2;
+
+ for(;;) {
+ _XimSetHeader((XPointer)buf, major_opcode, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, reply, buf_size, _XimAllRecv, 0);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size, _XimAllRecv, 0);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return False;
+ }
+ }
+ } else
+ return False;
+
+ major_opcode = *((CARD8 *)preply);
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+
+ if (wait_mode == CLIENT_WAIT1) {
+ if (major_opcode == XIM_AUTH_REQUIRED) {
+ ret = _XimClientAuthCheck(im, (XPointer)buf_s);
+ if(reply != preply)
+ Xfree(preply);
+ if (ret == NO_MORE_AUTH) {
+ if (!(_XimSetAuthReplyData(im,
+ (XPointer)&buf[XIM_HEADER_SIZE], &len))) {
+ _XimAuthNG(im);
+ return False;
+ }
+ major_opcode = XIM_AUTH_REPLY;
+ wait_mode = CLIENT_WAIT2;
+ } else if (ret == GOOD_AUTH) {
+ if (!(_XimSetAuthNextData(im,
+ (XPointer)&buf[XIM_HEADER_SIZE], &len))) {
+ _XimAuthNG(im);
+ return False;
+ }
+ major_opcode = XIM_AUTH_NEXT;
+ } else { /* BAD_AUTH */
+ _XimAuthNG(im);
+ return False;
+ }
+ } else {
+ if(reply != preply)
+ Xfree(preply);
+ _XimAuthNG(im);
+ return False;
+ }
+ } else { /* CLIENT_WAIT2 */
+ if (major_opcode == XIM_CONNECT_REPLY) {
+ break;
+ } else if (major_opcode == XIM_AUTH_SETUP) {
+ if (!(_XimCheckAuthSetupData(im, (XPointer)buf_s))) {
+ _XimAuthNG(im);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+ if (!(_XimSetAuthRequiredData(im,
+ (XPointer)&buf[XIM_HEADER_SIZE], &len))) {
+ _XimAuthNG(im);
+ return False;
+ }
+ major_opcode = XIM_AUTH_REQUIRED;
+ } else if (major_opcode == XIM_AUTH_NEXT) {
+ if (!(_XimCheckAuthNextData(im, (XPointer)buf_s))) {
+ _XimAuthNG(im);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+ if (!(_XimSetAuthRequiredData(im,
+ (XPointer)&buf[XIM_HEADER_SIZE], &len))) {
+ _XimAuthNG(im);
+ return False;
+ }
+ major_opcode = XIM_AUTH_REQUIRED;
+ } else if (major_opcode == XIM_AUTH_NG) {
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ } else {
+ _XimAuthNG(im);
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ }
+ }
+
+ if (!( buf_s[0] == im->private.proto.protocol_major_version
+ && buf_s[1] == im->private.proto.protocol_minor_version)) {
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+ MARK_SERVER_CONNECTED(im);
+
+ _XimRegProtoIntrCallback(im, XIM_REGISTER_TRIGGERKEYS, 0,
+ _XimRegisterTriggerKeysCallback, (XPointer)im);
+ return True;
+}
+
+Private Bool
+_XimDisconnectCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+
+ if ((major_opcode == XIM_DISCONNECT_REPLY)
+ && (minor_opcode == 0))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0))
+ return True;
+ return False;
+}
+
+Private Bool
+_XimDisconnect(
+ Xim im)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ INT16 len = 0;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+
+ if (IS_SERVER_CONNECTED(im)) {
+ _XimSetHeader((XPointer)buf, XIM_DISCONNECT, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimDisconnectCheck, 0);
+ if(ret_code == XIM_OVERFLOW) {
+ if(len > 0) {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimDisconnectCheck, 0);
+ Xfree(preply);
+ if(ret_code != XIM_TRUE)
+ return False;
+ }
+ } else if(ret_code == XIM_FALSE)
+ return False;
+
+ }
+ if (!(_XimShutdown(im))) /* Transport shutdown */
+ return False;
+ return True;
+}
+
+Private Bool
+_XimOpenCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+
+ if ((major_opcode == XIM_OPEN_REPLY)
+ && (minor_opcode == 0))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0))
+ return True;
+ return False;
+}
+
+Private Bool
+_XimOpen(
+ Xim im)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD8 *buf_b = &buf[XIM_HEADER_SIZE];
+ CARD16 *buf_s;
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+ char *locale_name;
+
+ locale_name = im->private.proto.locale_name;
+ len = strlen(locale_name);
+ buf_b[0] = (BYTE)len; /* length of locale name */
+ (void)strcpy((char *)&buf_b[1], locale_name); /* locale name */
+ len += sizeof(BYTE); /* sizeof length */
+ XIM_SET_PAD(buf_b, len); /* pad */
+
+ _XimSetHeader((XPointer)buf, XIM_OPEN, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, reply, buf_size,
+ _XimOpenCheck, 0);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimOpenCheck, 0);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return False;
+ }
+ }
+ } else
+ return False;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+
+ im->private.proto.imid = buf_s[0]; /* imid */
+
+ if (!(_XimGetAttributeID(im, &buf_s[1]))) {
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+
+ if (!(_XimSetInnerIMResourceList(&(im->private.proto.im_inner_resources),
+ &(im->private.proto.im_num_inner_resources))))
+ return False;
+
+ if (!(_XimSetInnerICResourceList(&(im->private.proto.ic_inner_resources),
+ &(im->private.proto.ic_num_inner_resources))))
+ return False;
+
+ _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
+ _XimSetIMMode(im->private.proto.im_inner_resources,
+ im->private.proto.im_num_inner_resources);
+
+ /* Transport Callbak */
+ _XimRegProtoIntrCallback(im, XIM_SET_EVENT_MASK, 0,
+ _XimSetEventMaskCallback, (XPointer)im);
+ _XimRegProtoIntrCallback(im, XIM_FORWARD_EVENT, 0,
+ _XimForwardEventCallback, (XPointer)im);
+ _XimRegProtoIntrCallback(im, XIM_COMMIT, 0,
+ _XimCommitCallback, (XPointer)im);
+ _XimRegProtoIntrCallback(im, XIM_SYNC, 0,
+ _XimSyncCallback, (XPointer)im);
+
+ if(!_XimExtension(im))
+ return False;
+
+ /* register a hook for callback protocols */
+ _XimRegisterDispatcher(im, _XimCbDispatch, (XPointer)im);
+
+ return True;
+}
+
+Private Bool
+_XimCloseCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+
+ if ((major_opcode == XIM_CLOSE_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid))
+ return True;
+ return False;
+}
+
+Private Bool
+_XimClose(
+ Xim im)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+
+ if (!IS_SERVER_CONNECTED(im))
+ return True;
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = 0; /* unused */
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16); /* sizeof unused */
+
+ _XimSetHeader((XPointer)buf, XIM_CLOSE, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimCloseCheck, 0);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size, _XimCloseCheck, 0);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return False;
+ }
+ }
+ } else
+ return False;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+
+ if(reply != preply)
+ Xfree(preply);
+ return True;
+}
+
+Public void
+_XimProtoIMFree(
+ Xim im)
+{
+ /* XIMPrivateRec */
+ if (im->private.proto.im_onkeylist) {
+ Xfree(im->private.proto.im_onkeylist);
+ im->private.proto.im_onkeylist = NULL;
+ }
+ if (im->private.proto.im_offkeylist) {
+ Xfree(im->private.proto.im_offkeylist);
+ im->private.proto.im_offkeylist = NULL;
+ }
+ if (im->private.proto.intrproto) {
+ _XimFreeProtoIntrCallback(im);
+ im->private.proto.intrproto = NULL;
+ }
+ if (im->private.proto.im_inner_resources) {
+ Xfree(im->private.proto.im_inner_resources);
+ im->private.proto.im_inner_resources = NULL;
+ }
+ if (im->private.proto.ic_inner_resources) {
+ Xfree(im->private.proto.ic_inner_resources);
+ im->private.proto.ic_inner_resources = NULL;
+ }
+ if (im->private.proto.hold_data) {
+ Xfree(im->private.proto.hold_data);
+ im->private.proto.hold_data = NULL;
+ }
+ if (im->private.proto.locale_name) {
+ Xfree(im->private.proto.locale_name);
+ im->private.proto.locale_name = NULL;
+ }
+ if (im->private.proto.ctom_conv) {
+ _XlcCloseConverter(im->private.proto.ctom_conv);
+ im->private.proto.ctom_conv = NULL;
+ }
+ if (im->private.proto.ctow_conv) {
+ _XlcCloseConverter(im->private.proto.ctow_conv);
+ im->private.proto.ctow_conv = NULL;
+ }
+ if (im->private.proto.ctoutf8_conv) {
+ _XlcCloseConverter(im->private.proto.ctoutf8_conv);
+ im->private.proto.ctoutf8_conv = NULL;
+ }
+ if (im->private.proto.cstomb_conv) {
+ _XlcCloseConverter(im->private.proto.cstomb_conv);
+ im->private.proto.cstomb_conv = NULL;
+ }
+ if (im->private.proto.cstowc_conv) {
+ _XlcCloseConverter(im->private.proto.cstowc_conv);
+ im->private.proto.cstowc_conv = NULL;
+ }
+ if (im->private.proto.cstoutf8_conv) {
+ _XlcCloseConverter(im->private.proto.cstoutf8_conv);
+ im->private.proto.cstoutf8_conv = NULL;
+ }
+ if (im->private.proto.ucstoc_conv) {
+ _XlcCloseConverter(im->private.proto.ucstoc_conv);
+ im->private.proto.ucstoc_conv = NULL;
+ }
+ if (im->private.proto.ucstoutf8_conv) {
+ _XlcCloseConverter(im->private.proto.ucstoutf8_conv);
+ im->private.proto.ucstoutf8_conv = NULL;
+ }
+
+#ifdef XIM_CONNECTABLE
+ if (!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
+ return;
+ }
+#endif /* XIM_CONNECTABLE */
+
+ if (im->private.proto.saved_imvalues) {
+ Xfree(im->private.proto.saved_imvalues);
+ im->private.proto.saved_imvalues = NULL;
+ }
+ if (im->private.proto.default_styles) {
+ Xfree(im->private.proto.default_styles);
+ im->private.proto.default_styles = NULL;
+ }
+
+ /* core */
+ if (im->core.res_name) {
+ Xfree(im->core.res_name);
+ im->core.res_name = NULL;
+ }
+ if (im->core.res_class) {
+ Xfree(im->core.res_class);
+ im->core.res_class = NULL;
+ }
+ if (im->core.im_values_list) {
+ Xfree(im->core.im_values_list);
+ im->core.im_values_list = NULL;
+ }
+ if (im->core.ic_values_list) {
+ Xfree(im->core.ic_values_list);
+ im->core.ic_values_list = NULL;
+ }
+ if (im->core.im_name) {
+ Xfree(im->core.im_name);
+ im->core.im_name = NULL;
+ }
+ if (im->core.styles) {
+ Xfree(im->core.styles);
+ im->core.styles = NULL;
+ }
+ if (im->core.im_resources) {
+ Xfree(im->core.im_resources);
+ im->core.im_resources = NULL;
+ }
+ if (im->core.ic_resources) {
+ Xfree(im->core.ic_resources);
+ im->core.ic_resources = NULL;
+ }
+
+ return;
+}
+
+Private Status
+_XimProtoCloseIM(
+ XIM xim)
+{
+ Xim im = (Xim)xim;
+ XIC ic;
+ XIC next;
+ Status status;
+
+ ic = im->core.ic_chain;
+ while (ic) {
+ (*ic->methods->destroy) (ic);
+ next = ic->core.next;
+#ifdef XIM_CONNECTABLE
+ if (!(!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im))) {
+ Xfree ((char *) ic);
+ }
+#else
+ Xfree ((char *) ic);
+#endif /* XIM_CONNECTABLE */
+ ic = next;
+ }
+#ifdef XIM_CONNECTABLE
+ if (!(!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)))
+ im->core.ic_chain = NULL;
+#else
+ im->core.ic_chain = NULL;
+#endif
+
+ _XimUnregisterServerFilter(im);
+ _XimResetIMInstantiateCallback(im);
+ status = (Status)_XimClose(im);
+ status = (Status)_XimDisconnect(im) && status;
+ _XimProtoIMFree(im);
+#ifdef XIM_CONNECTABLE
+ if (!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
+ _XimReconnectModeSetAttr(im);
+ for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
+ _XimReconnectModeCreateIC(ic);
+ }
+ return 0;
+ }
+#endif /* XIM_CONNECTABLE */
+ _XimDestroyIMStructureList(im);
+ return status;
+}
+
+#ifdef XIM_CONNECTABLE
+Private Bool
+_XimCheckIMQuarkList(
+ XrmQuark *quark_list,
+ int num_quark,
+ XrmQuark quark)
+{
+ register int i;
+
+ for (i = 0; i < num_quark; i++) {
+ if (quark_list[i] == quark) {
+ return True;
+ }
+ }
+ return False;
+}
+
+Private Bool
+_XimSaveIMValues(
+ Xim im,
+ XIMArg *arg)
+{
+ register XIMArg *p;
+ register int n;
+ XrmQuark *quark_list;
+ XrmQuark *tmp;
+ XrmQuark quark;
+ int num_quark;
+
+ if (quark_list = im->private.proto.saved_imvalues) {
+ num_quark = im->private.proto.num_saved_imvalues;
+ for (p = arg; p && p->name; p++) {
+ quark = XrmStringToQuark(p->name);
+ if (_XimCheckIMQuarkList(quark_list, num_quark, quark)) {
+ continue;
+ }
+ if (!(tmp = (XrmQuark *)Xrealloc(quark_list,
+ (sizeof(XrmQuark) * (num_quark + 1))))) {
+ im->private.proto.saved_imvalues = quark_list;
+ im->private.proto.num_saved_imvalues = num_quark;
+ return False;
+ }
+ num_quark++;
+ quark_list = tmp;
+ quark_list[num_quark] = quark;
+ }
+ im->private.proto.saved_imvalues = quark_list;
+ im->private.proto.num_saved_imvalues = num_quark;
+ return True;
+ }
+
+ for (p = arg, n = 0; p && p->name; p++, n++);
+
+ if (!(quark_list = (XrmQuark *)Xmalloc(sizeof(XrmQuark) * n))) {
+ return False;
+ }
+
+ im->private.proto.saved_imvalues = quark_list;
+ im->private.proto.num_saved_imvalues = n;
+ for (p = arg; p && p->name; p++, quark_list++) {
+ *quark_list = XrmStringToQuark(p->name);
+ }
+
+ return True;
+}
+
+Private char *
+_XimDelayModeSetIMValues(
+ Xim im,
+ XIMArg *arg)
+{
+ XimDefIMValues im_values;
+ char *name;
+ XIMArg *values;
+
+ _XimGetCurrentIMValues(im, &im_values);
+ name = _XimSetIMValueData(im, (XPointer)&im_values, values,
+ im->core.im_resources, im->core.im_num_resources);
+ _XimSetCurrentIMValues(im, &im_values);
+
+ return name;
+}
+#endif /* XIM_CONNECTABLE */
+
+Private Bool
+_XimSetIMValuesCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+
+ if ((major_opcode == XIM_SET_IM_VALUES_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid))
+ return True;
+ return False;
+}
+
+Private char *
+_XimProtoSetIMValues(
+ XIM xim,
+ XIMArg *arg)
+{
+ Xim im = (Xim)xim;
+ XimDefIMValues im_values;
+ INT16 len;
+ CARD16 *buf_s;
+ char *tmp;
+ CARD32 tmp_buf32[BUFSIZE/4];
+ char *tmp_buf = (char *)tmp_buf32;
+ char *buf;
+ int buf_size;
+ char *data;
+ int data_len;
+ int ret_len;
+ int total;
+ XIMArg *arg_ret;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int ret_code;
+ char *name;
+
+#ifndef XIM_CONNECTABLE
+ if (!IS_SERVER_CONNECTED(im))
+ return arg->name;
+#else
+ if (!_XimSaveIMValues(im, arg))
+ return arg->name;
+
+ if (!IS_SERVER_CONNECTED(im)) {
+ if (IS_CONNECTABLE(im)) {
+ if (!_XimConnectServer(im)) {
+ return _XimDelayModeSetIMValues(im, arg);
+ }
+ } else {
+ return arg->name;
+ }
+ }
+#endif /* XIM_CONNECTABLE */
+
+ _XimGetCurrentIMValues(im, &im_values);
+ buf = tmp_buf;
+ buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
+ data_len = BUFSIZE - buf_size;
+ total = 0;
+ arg_ret = arg;
+ for (;;) {
+ data = &buf[buf_size];
+ if ((name = _XimEncodeIMATTRIBUTE(im, im->core.im_resources,
+ im->core.im_num_resources, arg, &arg_ret, data, data_len,
+ &ret_len, (XPointer)&im_values, XIM_SETIMVALUES))) {
+ if (buf != tmp_buf)
+ Xfree(buf);
+ break;
+ }
+
+ total += ret_len;
+ if (!(arg = arg_ret)) {
+ break;
+ }
+
+ buf_size += ret_len;
+ if (buf == tmp_buf) {
+ if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
+ return arg->name;
+ }
+ memcpy(tmp, buf, buf_size);
+ buf = tmp;
+ } else {
+ if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
+ Xfree(buf);
+ return arg->name;
+ }
+ buf = tmp;
+ }
+ }
+ _XimSetCurrentIMValues(im, &im_values);
+
+ if (!total)
+ return (char *)NULL;
+
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ buf_s[0] = im->private.proto.imid;
+ buf_s[1] = (INT16)total;
+
+ len = (INT16)(sizeof(CARD16) + sizeof(INT16) + total);
+ _XimSetHeader((XPointer)buf, XIM_SET_IM_VALUES, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ if (buf != tmp_buf)
+ Xfree(buf);
+ return arg->name;
+ }
+ _XimFlush(im);
+ if (buf != tmp_buf)
+ Xfree(buf);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimSetIMValuesCheck, 0);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = (int)len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, reply, buf_size,
+ _XimSetIMValuesCheck, 0);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return arg->name;
+ }
+ }
+ } else
+ return arg->name;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if(reply != preply)
+ Xfree(preply);
+ return arg->name;
+ }
+ if(reply != preply)
+ Xfree(preply);
+
+ return name;
+}
+
+#ifdef XIM_CONNECTABLE
+Private char *
+_XimDelayModeGetIMValues(
+ Xim im,
+ XIMArg *arg)
+{
+ XimDefIMValues im_values;
+
+ _XimGetCurrentIMValues(im, &im_values);
+ return(_XimGetIMValueData(im, (XPointer)&im_values, arg,
+ im->core.im_resources, im->core.im_num_resources));
+}
+#endif /* XIM_CONNECTABLE */
+
+Private Bool
+_XimGetIMValuesCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+
+ if ((major_opcode == XIM_GET_IM_VALUES_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid))
+ return True;
+ return False;
+}
+
+Private char *
+_XimProtoGetIMValues(
+ XIM xim,
+ XIMArg *arg)
+{
+ Xim im = (Xim)xim;
+ register XIMArg *p;
+ register int n;
+ CARD8 *buf;
+ CARD16 *buf_s;
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply = NULL;
+ int buf_size;
+ int ret_code;
+ char *makeid_name;
+ char *decode_name;
+ CARD16 *data = NULL;
+ INT16 data_len = 0;
+
+#ifndef XIM_CONNECTABLE
+ if (!IS_SERVER_CONNECTED(im))
+ return arg->name;
+#else
+ if (!IS_SERVER_CONNECTED(im)) {
+ if (IS_CONNECTABLE(im)) {
+ if (!_XimConnectServer(im)) {
+ return _XimDelayModeGetIMValues(im, arg);
+ }
+ } else {
+ return arg->name;
+ }
+ }
+#endif /* XIM_CONNECTABLE */
+
+ for (n = 0, p = arg; p->name; p++)
+ n++;
+
+ if (!n)
+ return (char *)NULL;
+
+ buf_size = sizeof(CARD16) * n;
+ buf_size += XIM_HEADER_SIZE
+ + sizeof(CARD16)
+ + sizeof(INT16)
+ + XIM_PAD(buf_size);
+
+ if (!(buf = (CARD8 *)Xmalloc(buf_size)))
+ return arg->name;
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+
+ makeid_name = _XimMakeIMAttrIDList(im, im->core.im_resources,
+ im->core.im_num_resources, arg,
+ &buf_s[2], &len, XIM_GETIMVALUES);
+
+ if (len) {
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = len; /* length of im-attr-id */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += sizeof(CARD16) /* sizeof imid */
+ + sizeof(INT16); /* sizeof length of attr */
+
+ _XimSetHeader((XPointer)buf, XIM_GET_IM_VALUES, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ Xfree(buf);
+ return arg->name;
+ }
+ _XimFlush(im);
+ Xfree(buf);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimGetIMValuesCheck, 0);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimGetIMValuesCheck, 0);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return arg->name;
+ }
+ }
+ } else
+ return arg->name;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if(reply != preply)
+ Xfree(preply);
+ return arg->name;
+ }
+ data = &buf_s[2];
+ data_len = buf_s[1];
+ }
+ decode_name = _XimDecodeIMATTRIBUTE(im, im->core.im_resources,
+ im->core.im_num_resources, data, data_len,
+ arg, XIM_GETIMVALUES);
+ if (reply != preply)
+ Xfree(preply);
+
+ if (decode_name)
+ return decode_name;
+ else
+ return makeid_name;
+}
+
+Private XIMMethodsRec im_methods = {
+ _XimProtoCloseIM, /* close */
+ _XimProtoSetIMValues, /* set_values */
+ _XimProtoGetIMValues, /* get_values */
+ _XimProtoCreateIC, /* create_ic */
+ _Ximctstombs, /* ctstombs */
+ _Ximctstowcs, /* ctstowcs */
+ _Ximctstoutf8 /* ctstoutf8 */
+};
+
+Private Bool
+_XimSetEncodingByName(
+ Xim im,
+ char **buf,
+ int *len)
+{
+ char *encoding = (char *)NULL;
+ int encoding_len;
+ int compound_len;
+ BYTE *ret;
+
+ _XGetLCValues(im->core.lcd, XlcNCodeset, &encoding, NULL);
+ if (!encoding) {
+ *buf = (char *)NULL;
+ *len = 0;
+ return True;
+ }
+ encoding_len = strlen(encoding);
+ compound_len = strlen("COMPOUND_TEXT");
+ *len = encoding_len + sizeof(BYTE) + compound_len + sizeof(BYTE);
+ if (!(ret = (BYTE *)Xmalloc(*len))) {
+ return False;
+ }
+ *buf = (char *)ret;
+
+ ret[0] = (BYTE)encoding_len;
+ (void)strncpy((char *)&ret[1], encoding, encoding_len);
+ ret += (encoding_len + sizeof(BYTE));
+ ret[0] = (BYTE)compound_len;
+ (void)strncpy((char *)&ret[1], "COMPOUND_TEXT", compound_len);
+ return True;
+}
+
+Private Bool
+_XimSetEncodingByDetail(
+ Xim im,
+ char **buf,
+ int *len)
+{
+ *len = 0;
+ *buf = NULL;
+ return True;
+}
+
+Private Bool
+_XimGetEncoding(
+ Xim im,
+ CARD16 *buf,
+ char *name,
+ int name_len,
+ char *detail,
+ int detail_len)
+{
+ XLCd lcd = im->core.lcd;
+ CARD16 category = buf[0];
+ CARD16 idx = buf[1];
+ int len;
+ XlcConv ctom_conv = NULL;
+ XlcConv ctow_conv = NULL;
+ XlcConv ctoutf8_conv = NULL;
+ XlcConv conv;
+ XimProtoPrivateRec *private = &im->private.proto;
+
+ if (idx == (CARD16)XIM_Default_Encoding_IDX) { /* XXX */
+ if (!(ctom_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNMultiByte)))
+ return False;
+ if (!(ctow_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNWideChar)))
+ return False;
+ if (!(ctoutf8_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNUtf8String)))
+ return False;
+ }
+
+ if (category == XIM_Encoding_NameCategory) {
+ while (name_len > 0) {
+ len = (int)name[0];
+ if (!strncmp(&name[1], "COMPOUND_TEXT", len)) {
+ if (!(ctom_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNMultiByte)))
+ return False;
+ if (!(ctow_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNWideChar)))
+ return False;
+ if (!(ctoutf8_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNUtf8String)))
+ return False;
+ break;
+ } else {
+ /*
+ * Not yet
+ */
+ }
+ len += sizeof(BYTE);
+ name_len -= len;
+ name += len;
+ }
+ } else if (category == XIM_Encoding_DetailCategory) {
+ /*
+ * Not yet
+ */
+ } else {
+ return False;
+ }
+
+ private->ctom_conv = ctom_conv;
+ private->ctow_conv = ctow_conv;
+ private->ctoutf8_conv = ctoutf8_conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte)))
+ return False;
+ private->cstomb_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar)))
+ return False;
+ private->cstowc_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String)))
+ return False;
+ private->cstoutf8_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar)))
+ return False;
+ private->ucstoc_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String)))
+ return False;
+ private->ucstoutf8_conv = conv;
+
+ return True;
+}
+
+Private Bool
+_XimEncodingNegoCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+
+ if ((major_opcode == XIM_ENCODING_NEGOTIATION_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid))
+ return True;
+ return False;
+}
+
+Private Bool
+_XimEncodingNegotiation(
+ Xim im)
+{
+ char *name_ptr = 0;
+ int name_len = 0;
+ char *detail_ptr = 0;
+ int detail_len = 0;
+ CARD8 *buf;
+ CARD16 *buf_s;
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+
+ if (!(_XimSetEncodingByName(im, &name_ptr, &name_len)))
+ return False;
+
+ if (!(_XimSetEncodingByDetail(im, &detail_ptr, &detail_len)))
+ goto free_name_ptr;
+
+ len = sizeof(CARD16)
+ + sizeof(INT16)
+ + name_len
+ + XIM_PAD(name_len)
+ + sizeof(INT16)
+ + sizeof(CARD16)
+ + detail_len;
+
+ if (!(buf = (CARD8 *)Xmalloc(XIM_HEADER_SIZE + len)))
+ goto free_detail_ptr;
+
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+
+ buf_s[0] = im->private.proto.imid;
+ buf_s[1] = (INT16)name_len;
+ if (name_ptr)
+ (void)memcpy((char *)&buf_s[2], name_ptr, name_len);
+ XIM_SET_PAD(&buf_s[2], name_len);
+ buf_s = (CARD16 *)((char *)&buf_s[2] + name_len);
+ buf_s[0] = detail_len;
+ buf_s[1] = 0;
+ if (detail_ptr)
+ (void)memcpy((char *)&buf_s[2], detail_ptr, detail_len);
+
+ _XimSetHeader((XPointer)buf, XIM_ENCODING_NEGOTIATION, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ Xfree(buf);
+ goto free_detail_ptr;
+ }
+ _XimFlush(im);
+ Xfree(buf);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimEncodingNegoCheck, 0);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimEncodingNegoCheck, 0);
+ if(ret_code != XIM_TRUE)
+ goto free_preply;
+ }
+ } else
+ goto free_detail_ptr;
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ goto free_preply;
+ }
+
+ if (!(_XimGetEncoding(im, &buf_s[1], name_ptr, name_len,
+ detail_ptr, detail_len)))
+ goto free_preply;
+
+ if (name_ptr)
+ Xfree(name_ptr);
+ if (detail_ptr)
+ Xfree(detail_ptr);
+
+ if(reply != preply)
+ Xfree(preply);
+
+ return True;
+
+free_preply:
+ if (reply != preply)
+ Xfree(preply);
+
+free_detail_ptr:
+ Xfree(detail_ptr);
+
+free_name_ptr:
+ Xfree(name_ptr);
+
+ return False;
+}
+
+#ifdef XIM_CONNECTABLE
+Private Bool
+_XimSendSavedIMValues(
+ Xim im)
+{
+ XimDefIMValues im_values;
+ INT16 len;
+ CARD16 *buf_s;
+ char *tmp;
+ CARD32 tmp_buf32[BUFSIZE/4];
+ char *tmp_buf = (char *)tmp_buf32;
+ char *buf;
+ int buf_size;
+ char *data;
+ int data_len;
+ int ret_len;
+ int total;
+ int idx;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int ret_code;
+
+ _XimGetCurrentIMValues(im, &im_values);
+ buf = tmp_buf;
+ buf_size = XIM_HEADER_SIZE + sizeof(CARD16) + sizeof(INT16);
+ data_len = BUFSIZE - buf_size;
+ total = 0;
+ idx = 0;
+ for (;;) {
+ data = &buf[buf_size];
+ if (!_XimEncodeSavedIMATTRIBUTE(im, im->core.im_resources,
+ im->core.im_num_resources, &idx, data, data_len,
+ &ret_len, (XPointer)&im_values, XIM_SETIMVALUES)) {
+ if (buf != tmp_buf)
+ Xfree(buf);
+ return False;
+ }
+
+ total += ret_len;
+ if (idx == -1) {
+ break;
+ }
+
+ buf_size += ret_len;
+ if (buf == tmp_buf) {
+ if (!(tmp = (char *)Xmalloc(buf_size + data_len))) {
+ return False;
+ }
+ memcpy(tmp, buf, buf_size);
+ buf = tmp;
+ } else {
+ if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) {
+ Xfree(buf);
+ return False;
+ }
+ buf = tmp;
+ }
+ }
+
+ if (!total)
+ return True;
+
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ buf_s[0] = im->private.proto.imid;
+ buf_s[1] = (INT16)total;
+
+ len = (INT16)(sizeof(CARD16) + sizeof(INT16) + total);
+ _XimSetHeader((XPointer)buf, XIM_SET_IM_VALUES, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ if (buf != tmp_buf)
+ Xfree(buf);
+ return False;
+ }
+ _XimFlush(im);
+ if (buf != tmp_buf)
+ Xfree(buf);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimSetIMValuesCheck, 0);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = (int)len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, reply, buf_size,
+ _XimSetIMValuesCheck, 0);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return False;
+ }
+ }
+ } else
+ return False;
+
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+
+ return True;
+}
+
+Private void
+_XimDelayModeIMFree(
+ Xim im)
+{
+ if (im->core.im_resources) {
+ Xfree(im->core.im_resources);
+ im->core.im_resources = NULL;
+ }
+ if (im->core.ic_resources) {
+ Xfree(im->core.ic_resources);
+ im->core.ic_resources = NULL;
+ }
+ if (im->core.im_values_list) {
+ Xfree(im->core.im_values_list);
+ im->core.im_values_list = NULL;
+ }
+ if (im->core.ic_values_list) {
+ Xfree(im->core.ic_values_list);
+ im->core.ic_values_list = NULL;
+ }
+ return;
+}
+
+Public Bool
+_XimConnectServer(
+ Xim im)
+{
+ Xim save_im;
+
+ if (!(save_im = (Xim)Xmalloc(sizeof(XimRec))))
+ return False;
+ memcpy((char *)save_im, (char *)im, sizeof(XimRec));
+
+ if (_XimPreConnect(im) && _XimConnection(im)
+ && _XimOpen(im) && _XimEncodingNegotiation(im)) {
+ if (_XimSendSavedIMValues(im)) {
+ _XimDelayModeIMFree(save_im);
+ _XimRegisterServerFilter(im);
+ Xfree(save_im);
+ return True;
+ }
+ }
+ memcpy((char *)im, (char *)save_im, sizeof(XimRec));
+ Xfree(save_im);
+ return False;
+}
+
+Public Bool
+_XimDelayModeSetAttr(
+ Xim im)
+{
+ XimDefIMValues im_values;
+
+ if(!_XimSetIMResourceList(&im->core.im_resources,
+ &im->core.im_num_resources)) {
+ return False;
+ }
+ if(!_XimSetICResourceList(&im->core.ic_resources,
+ &im->core.ic_num_resources)) {
+ return False;
+ }
+
+ _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
+
+ _XimGetCurrentIMValues(im, &im_values);
+ if(!_XimSetLocalIMDefaults(im, (XPointer)&im_values,
+ im->core.im_resources, im->core.im_num_resources)) {
+ return False;
+ }
+ _XimSetCurrentIMValues(im, &im_values);
+ if (im->private.proto.default_styles) {
+ if (im->core.styles)
+ Xfree(im->core.styles);
+ im->core.styles = im->private.proto.default_styles;
+ }
+
+ return True;
+}
+
+Private Bool
+_XimReconnectModeSetAttr(
+ Xim im)
+{
+ XimDefIMValues im_values;
+
+ if(!_XimSetIMResourceList(&im->core.im_resources,
+ &im->core.im_num_resources)) {
+ return False;
+ }
+ if(!_XimSetICResourceList(&im->core.ic_resources,
+ &im->core.ic_num_resources)) {
+ return False;
+ }
+
+ _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
+
+ if (im->private.proto.default_styles) {
+ if (im->core.styles)
+ Xfree(im->core.styles);
+ im->core.styles = im->private.proto.default_styles;
+ }
+
+ return True;
+}
+#endif /* XIM_CONNECTABLE */
+
+Public Bool
+_XimProtoOpenIM(
+ Xim im)
+{
+ _XimInitialResourceInfo();
+
+ im->methods = &im_methods;
+
+#ifdef XIM_CONNECTABLE
+ _XimSetProtoResource(im);
+#endif /* XIM_CONNECTABLE */
+
+ if (_XimPreConnect(im)) {
+ if (_XimConnection(im) && _XimOpen(im) && _XimEncodingNegotiation(im)) {
+ _XimRegisterServerFilter(im);
+ return True;
+ }
+ _XimShutdown(im);
+#ifdef XIM_CONNECTABLE
+ } else if (IS_DELAYBINDABLE(im)) {
+ if (_XimDelayModeSetAttr(im))
+ return True;
+#endif /* XIM_CONNECTABLE */
+ }
+ _XimProtoIMFree(im);
+ return False;
+}
diff --git a/libX11/modules/im/ximcp/imDefLkup.c b/libX11/modules/im/ximcp/imDefLkup.c
index e53845d4c..996d36aef 100644
--- a/libX11/modules/im/ximcp/imDefLkup.c
+++ b/libX11/modules/im/ximcp/imDefLkup.c
@@ -1,1170 +1,1170 @@
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xatom.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-Public Xic
-_XimICOfXICID(
- Xim im,
- XICID icid)
-{
- Xic pic;
-
- for (pic = (Xic)im->core.ic_chain; pic; pic = (Xic)pic->core.next) {
- if (pic->private.proto.icid == icid)
- return pic;
- }
- return (Xic)0;
-}
-
-Private void
-_XimProcIMSetEventMask(
- Xim im,
- XPointer buf)
-{
- EVENTMASK *buf_l = (EVENTMASK *)buf;
-
- im->private.proto.forward_event_mask = buf_l[0];
- im->private.proto.synchronous_event_mask = buf_l[1];
- return;
-}
-
-Private void
-_XimProcICSetEventMask(
- Xic ic,
- XPointer buf)
-{
- EVENTMASK *buf_l = (EVENTMASK *)buf;
-
- ic->private.proto.forward_event_mask = buf_l[0];
- ic->private.proto.synchronous_event_mask = buf_l[1];
- _XimReregisterFilter(ic);
- return;
-}
-
-Public Bool
-_XimSetEventMaskCallback(
- Xim xim,
- INT16 len,
- XPointer data,
- XPointer call_data)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
- Xim im = (Xim)call_data;
- Xic ic;
-
- if (imid == im->private.proto.imid) {
- if (icid) {
- ic = _XimICOfXICID(im, icid);
- _XimProcICSetEventMask(ic, (XPointer)&buf_s[2]);
- } else {
- _XimProcIMSetEventMask(im, (XPointer)&buf_s[2]);
- }
- return True;
- }
- return False;
-}
-
-Private Bool
-_XimSyncCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- Xic ic = (Xic)arg;
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
-
- if ((major_opcode == XIM_SYNC_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid)
- && (icid == ic->private.proto.icid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid)
- && (buf_s[2] & XIM_ICID_VALID)
- && (icid == ic->private.proto.icid))
- return True;
- return False;
-}
-
-Public Bool
-_XimSync(
- Xim im,
- Xic ic)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
-
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16); /* sizeof icid */
-
- _XimSetHeader((XPointer)buf, XIM_SYNC, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimSyncCheck, (XPointer)ic);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(len);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimSyncCheck, (XPointer)ic);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return False;
- }
- }
- } else {
- return False;
- }
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
- return True;
-}
-
-Public Bool
-_XimProcSyncReply(
- Xim im,
- Xic ic)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len;
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
-
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16); /* sizeof icid */
-
- _XimSetHeader((XPointer)buf, XIM_SYNC_REPLY, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- return True;
-}
-
-Public Bool
-_XimRespSyncReply(
- Xic ic,
- BITMASK16 mode)
-{
- if (mode & XimSYNCHRONUS) /* SYNC Request */ {
- if (IS_FOCUSED(ic))
- MARK_NEED_SYNC_REPLY(ic);
- else
- _XimProcSyncReply((Xim)ic->core.im, ic);
- }
-
- return True;
-}
-
-Public Bool
-_XimSyncCallback(
- Xim xim,
- INT16 len,
- XPointer data,
- XPointer call_data)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
- Xim im = (Xim)call_data;
- Xic ic;
-
- if ((imid == im->private.proto.imid)
- && (ic = _XimICOfXICID(im, icid))) {
- (void)_XimProcSyncReply(im, ic);
- return True;
- }
- return False;
-}
-
-Private INT16
-_XimSetEventToWire(
- XEvent *ev,
- xEvent *event)
-{
- if (!(_XimProtoEventToWire(ev, event, False)))
- return 0;
- event->u.u.sequenceNumber =
- ((XAnyEvent *)ev)->serial & (unsigned long)0xffff;
- return sz_xEvent;
-}
-
-Private Bool
-_XimForwardEventCore(
- Xic ic,
- XEvent *ev,
- Bool sync)
-{
- Xim im = (Xim)ic->core.im;
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
- INT16 len;
-
- if (!(len = _XimSetEventToWire(ev, (xEvent *)&buf_s[4])))
- return False; /* X event */
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
- buf_s[2] = sync ? XimSYNCHRONUS : 0; /* flag */
- buf_s[3] =
- (CARD16)((((XAnyEvent *)ev)->serial & ~((unsigned long)0xffff)) >> 16);
- /* serial number */
-
- len += sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16) /* sizeof icid */
- + sizeof(BITMASK16) /* sizeof flag */
- + sizeof(CARD16); /* sizeof serila number */
-
- _XimSetHeader((XPointer)buf, XIM_FORWARD_EVENT, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
-
- if (sync) {
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimSyncCheck, (XPointer)ic);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(len);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimSyncCheck, (XPointer)ic);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return False;
- }
- }
- } else {
- return False;
- }
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
- }
- return True;
-}
-
-Public Bool
-_XimForwardEvent(
- Xic ic,
- XEvent *ev,
- Bool sync)
-{
-#ifdef EXT_FORWARD
- if (((ev->type == KeyPress) || (ev->type == KeyRelease)))
- if (_XimExtForwardKeyEvent(ic, (XKeyEvent *)ev, sync))
- return True;
-#endif
- return _XimForwardEventCore(ic, ev, sync);
-}
-
-Private void
-_XimProcEvent(
- Display *d,
- Xic ic,
- XEvent *ev,
- CARD16 *buf)
-{
- INT16 serial = buf[0];
- xEvent *xev = (xEvent *)&buf[1];
-
- _XimProtoWireToEvent(ev, xev, False);
- ev->xany.serial |= serial << 16;
- ev->xany.send_event = False;
- ev->xany.display = d;
- MARK_FABLICATED(ic);
- return;
-}
-
-Private Bool
-_XimForwardEventRecv(
- Xim im,
- Xic ic,
- XPointer buf)
-{
- CARD16 *buf_s = (CARD16 *)buf;
- Display *d = im->core.display;
- XEvent ev;
-
- _XimProcEvent(d, ic, &ev, &buf_s[1]);
-
- (void)_XimRespSyncReply(ic, buf_s[0]);
-
- XPutBackEvent(d, &ev);
-
- return True;
-}
-
-Public Bool
-_XimForwardEventCallback(
- Xim xim,
- INT16 len,
- XPointer data,
- XPointer call_data)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
- Xim im = (Xim)call_data;
- Xic ic;
-
- if ((imid == im->private.proto.imid)
- && (ic = _XimICOfXICID(im, icid))) {
- (void)_XimForwardEventRecv(im, ic, (XPointer)&buf_s[2]);
- return True;
- }
- return False;
-}
-
-Private Bool
-_XimRegisterTriggerkey(
- Xim im,
- XPointer buf)
-{
- CARD32 *buf_l = (CARD32 *)buf;
- CARD32 len;
- CARD32 *key;
-
- if (IS_DYNAMIC_EVENT_FLOW(im)) /* already Dynamic event flow mode */
- return True;
-
- /*
- * register onkeylist
- */
-
- len = buf_l[0]; /* length of on-keys */
- len += sizeof(INT32); /* sizeof length of on-keys */
-
- if (!(key = (CARD32 *)Xmalloc(len))) {
- _XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
- return False;
- }
- memcpy((char *)key, (char *)buf_l, len);
- im->private.proto.im_onkeylist = key;
-
- MARK_DYNAMIC_EVENT_FLOW(im);
-
- /*
- * register offkeylist
- */
-
- buf_l = (CARD32 *)((char *)buf + len);
- len = buf_l[0]; /* length of off-keys */
- len += sizeof(INT32); /* sizeof length of off-keys */
-
- if (!(key = (CARD32 *)Xmalloc(len))) {
- _XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
- return False;
- }
-
- memcpy((char *)key, (char *)buf_l, len);
- im->private.proto.im_offkeylist = key;
-
- return True;
-}
-
-Public Bool
-_XimRegisterTriggerKeysCallback(
- Xim xim,
- INT16 len,
- XPointer data,
- XPointer call_data)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- Xim im = (Xim)call_data;
-
- (void )_XimRegisterTriggerkey(im, (XPointer)&buf_s[2]);
- return True;
-}
-
-Public EVENTMASK
-_XimGetWindowEventmask(
- Xic ic)
-{
- Xim im = (Xim )ic->core.im;
- XWindowAttributes atr;
-
- if (!XGetWindowAttributes(im->core.display, ic->core.focus_window, &atr))
- return 0;
- return (EVENTMASK)atr.your_event_mask;
-}
-
-
-Private Bool
-_XimTriggerNotifyCheck(
- Xim im,
- INT16 len,
- XPointer data,
- XPointer arg)
-{
- Xic ic = (Xic)arg;
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- CARD8 major_opcode = *((CARD8 *)data);
- CARD8 minor_opcode = *((CARD8 *)data + 1);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
-
- if ((major_opcode == XIM_TRIGGER_NOTIFY_REPLY)
- && (minor_opcode == 0)
- && (imid == im->private.proto.imid)
- && (icid == ic->private.proto.icid))
- return True;
- if ((major_opcode == XIM_ERROR)
- && (minor_opcode == 0)
- && (buf_s[2] & XIM_IMID_VALID)
- && (imid == im->private.proto.imid)
- && (buf_s[2] & XIM_ICID_VALID)
- && (icid == ic->private.proto.icid))
- return True;
- return False;
-}
-
-Public Bool
-_XimTriggerNotify(
- Xim im,
- Xic ic,
- int mode,
- CARD32 idx)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- CARD32 *buf_l = (CARD32 *)&buf[XIM_HEADER_SIZE];
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
- INT16 len;
- EVENTMASK mask = _XimGetWindowEventmask(ic);
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
- buf_l[1] = mode; /* flag */
- buf_l[2] = idx; /* index of keys list */
- buf_l[3] = mask; /* select-event-mask */
-
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16) /* sizeof icid */
- + sizeof(CARD32) /* sizeof flag */
- + sizeof(CARD32) /* sizeof index of key list */
- + sizeof(EVENTMASK); /* sizeof select-event-mask */
-
- _XimSetHeader((XPointer)buf, XIM_TRIGGER_NOTIFY, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimTriggerNotifyCheck, (XPointer)ic);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_size = len;
- preply = (XPointer)Xmalloc(len);
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimTriggerNotifyCheck, (XPointer)ic);
- if(ret_code != XIM_TRUE) {
- Xfree(preply);
- return False;
- }
- }
- } else {
- return False;
- }
- buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
- if (*((CARD8 *)preply) == XIM_ERROR) {
- _XimProcError(im, 0, (XPointer)&buf_s[3]);
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
- return True;
-}
-
-Private Bool
-_XimRegCommitInfo(
- Xic ic,
- char *string,
- int string_len,
- KeySym *keysym,
- int keysym_len)
-{
- XimCommitInfo info;
-
- if (!(info = (XimCommitInfo)Xmalloc(sizeof(XimCommitInfoRec))))
- return False;
- info->string = string;
- info->string_len = string_len;
- info->keysym = keysym;
- info->keysym_len = keysym_len;
- info->next = ic->private.proto.commit_info;
- ic->private.proto.commit_info = info;
- return True;
-}
-
-Private void
-_XimUnregCommitInfo(
- Xic ic)
-{
- XimCommitInfo info;
-
- if (!(info = ic->private.proto.commit_info))
- return;
-
- if (info->string)
- Xfree(info->string);
- if (info->keysym)
- Xfree(info->keysym);
- ic->private.proto.commit_info = info->next;
- Xfree(info);
- return;
-}
-
-Public void
-_XimFreeCommitInfo(
- Xic ic)
-{
- while (ic->private.proto.commit_info)
- _XimUnregCommitInfo(ic);
- return;
-}
-
-Private Bool
-_XimProcKeySym(
- Xic ic,
- CARD32 sym,
- KeySym **xim_keysym,
- int *xim_keysym_len)
-{
- Xim im = (Xim)ic->core.im;
-
- if (!(*xim_keysym = (KeySym *)Xmalloc(sizeof(KeySym)))) {
- _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
- return False;
- }
-
- **xim_keysym = (KeySym)sym;
- *xim_keysym_len = 1;
-
- return True;
-}
-
-Private Bool
-_XimProcCommit(
- Xic ic,
- BYTE *buf,
- int len,
- char **xim_string,
- int *xim_string_len)
-{
- Xim im = (Xim)ic->core.im;
- char *string;
-
- if (!(string = (char *)Xmalloc(len + 1))) {
- _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
- return False;
- }
-
- (void)memcpy(string, (char *)buf, len);
- string[len] = '\0';
-
- *xim_string = string;
- *xim_string_len = len;
- return True;
-}
-
-Private Bool
-_XimCommitRecv(
- Xim im,
- Xic ic,
- XPointer buf)
-{
- CARD16 *buf_s = (CARD16 *)buf;
- BITMASK16 flag = buf_s[0];
- XKeyEvent ev;
- char *string = NULL;
- int string_len = 0;
- KeySym *keysym = NULL;
- int keysym_len = 0;
-
- if ((flag & XimLookupBoth) == XimLookupChars) {
- if (!(_XimProcCommit(ic, (BYTE *)&buf_s[2],
- (int)buf_s[1], &string, &string_len)))
- return False;
-
- } else if ((flag & XimLookupBoth) == XimLookupKeySym) {
- if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len)))
- return False;
-
- } else if ((flag & XimLookupBoth) == XimLookupBoth) {
- if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len)))
- return False;
-
- if (!(_XimProcCommit(ic, (BYTE *)&buf_s[5],
- (int)buf_s[4], &string, &string_len))) {
- Xfree(keysym);
- return False;
- }
- }
-
- if (!(_XimRegCommitInfo(ic, string, string_len, keysym, keysym_len))) {
- if (string)
- Xfree(string);
- if (keysym)
- Xfree(keysym);
- _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
- return False;
- }
-
- (void)_XimRespSyncReply(ic, flag);
-
- MARK_FABLICATED(ic);
-
- ev.type = KeyPress;
- ev.send_event = False;
- ev.display = im->core.display;
- ev.window = ic->core.focus_window;
- ev.keycode = 0;
- ev.state = 0;
-
- XPutBackEvent(im->core.display, (XEvent *)&ev);
-
- return True;
-}
-
-Public Bool
-_XimCommitCallback(
- Xim xim,
- INT16 len,
- XPointer data,
- XPointer call_data)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- XIMID imid = buf_s[0];
- XICID icid = buf_s[1];
- Xim im = (Xim)call_data;
- Xic ic;
-
- if ((imid == im->private.proto.imid)
- && (ic = _XimICOfXICID(im, icid))) {
- (void)_XimCommitRecv(im, ic, (XPointer)&buf_s[2]);
- return True;
- }
- return False;
-}
-
-Public void
-_XimProcError(
- Xim im,
- Xic ic,
- XPointer data)
-{
- return;
-}
-
-Public Bool
-_XimErrorCallback(
- Xim xim,
- INT16 len,
- XPointer data,
- XPointer call_data)
-{
- CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
- BITMASK16 flag = buf_s[2];
- XIMID imid;
- XICID icid;
- Xim im = (Xim)call_data;
- Xic ic = NULL;
-
- if (flag & XIM_IMID_VALID) {
- imid = buf_s[0];
- if (imid != im->private.proto.imid)
- return False;
- }
- if (flag & XIM_ICID_VALID) {
- icid = buf_s[1];
- if (!(ic = _XimICOfXICID(im, icid)))
- return False;
- }
- _XimProcError(im, ic, (XPointer)&buf_s[3]);
-
- return True;
-}
-
-Public Bool
-_XimError(
- Xim im,
- Xic ic,
- CARD16 error_code,
- INT16 detail_length,
- CARD16 type,
- char *detail)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len = 0;
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[2] = XIM_IMID_VALID; /* flag */
- if (ic) {
- buf_s[1] = ic->private.proto.icid; /* icid */
- buf_s[2] |= XIM_ICID_VALID; /* flag */
- }
- buf_s[3] = error_code; /* Error Code */
- buf_s[4] = detail_length; /* length of error detail */
- buf_s[5] = type; /* type of error detail */
-
- if (detail_length && detail) {
- len = detail_length;
- memcpy((char *)&buf_s[6], detail, len);
- XIM_SET_PAD(&buf_s[6], len);
- }
-
- len += sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16) /* sizeof icid */
- + sizeof(BITMASK16) /* sizeof flag */
- + sizeof(CARD16) /* sizeof error_code */
- + sizeof(INT16) /* sizeof length of detail */
- + sizeof(CARD16); /* sizeof type */
-
- _XimSetHeader((XPointer)buf, XIM_ERROR, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- return True;
-}
-
-Private int
-_Ximctsconvert(
- XlcConv conv,
- char *from,
- int from_len,
- char *to,
- int to_len,
- Status *state)
-{
- int from_left;
- int to_left;
- int from_savelen;
- int to_savelen;
- int from_cnvlen;
- int to_cnvlen;
- char *from_buf;
- char *to_buf;
- char scratchbuf[BUFSIZ];
- Status tmp_state;
-
- if (!state)
- state = &tmp_state;
-
- if (!conv || !from || !from_len) {
- *state = XLookupNone;
- return 0;
- }
-
- /* Reset the converter. The CompoundText at 'from' starts in
- initial state. */
- _XlcResetConverter(conv);
-
- from_left = from_len;
- to_left = BUFSIZ;
- from_cnvlen = 0;
- to_cnvlen = 0;
- for (;;) {
- from_buf = &from[from_cnvlen];
- from_savelen = from_left;
- to_buf = &scratchbuf[to_cnvlen];
- to_savelen = to_left;
- if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
- (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
- *state = XLookupNone;
- return 0;
- }
- from_cnvlen += (from_savelen - from_left);
- to_cnvlen += (to_savelen - to_left);
- if (from_left == 0) {
- if (!to_cnvlen) {
- *state = XLookupNone;
- return 0;
- }
- break;
- }
- }
-
- if (!to || !to_len || (to_len < to_cnvlen)) {
- *state = XBufferOverflow;
- } else {
- memcpy(to, scratchbuf, to_cnvlen);
- *state = XLookupChars;
- }
- return to_cnvlen;
-}
-
-Public int
-_Ximctstombs(XIM xim, char *from, int from_len,
- char *to, int to_len, Status *state)
-{
- return _Ximctsconvert(((Xim)xim)->private.proto.ctom_conv,
- from, from_len, to, to_len, state);
-}
-
-Public int
-_Ximctstowcs(
- XIM xim,
- char *from,
- int from_len,
- wchar_t *to,
- int to_len,
- Status *state)
-{
- Xim im = (Xim)xim;
- XlcConv conv = im->private.proto.ctow_conv;
- int from_left;
- int to_left;
- int from_savelen;
- int to_savelen;
- int from_cnvlen;
- int to_cnvlen;
- char *from_buf;
- wchar_t *to_buf;
- wchar_t scratchbuf[BUFSIZ];
- Status tmp_state;
-
- if (!state)
- state = &tmp_state;
-
- if (!conv || !from || !from_len) {
- *state = XLookupNone;
- return 0;
- }
-
- /* Reset the converter. The CompoundText at 'from' starts in
- initial state. */
- _XlcResetConverter(conv);
-
- from_left = from_len;
- to_left = BUFSIZ;
- from_cnvlen = 0;
- to_cnvlen = 0;
- for (;;) {
- from_buf = &from[from_cnvlen];
- from_savelen = from_left;
- to_buf = &scratchbuf[to_cnvlen];
- to_savelen = to_left;
- if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
- (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
- *state = XLookupNone;
- return 0;
- }
- from_cnvlen += (from_savelen - from_left);
- to_cnvlen += (to_savelen - to_left);
- if (from_left == 0) {
- if (!to_cnvlen){
- *state = XLookupNone;
- return 0;
- }
- break;
- }
- }
-
- if (!to || !to_len || (to_len < to_cnvlen)) {
- *state = XBufferOverflow;
- } else {
- memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t));
- *state = XLookupChars;
- }
- return to_cnvlen;
-}
-
-Public int
-_Ximctstoutf8(
- XIM xim,
- char *from,
- int from_len,
- char *to,
- int to_len,
- Status *state)
-{
- return _Ximctsconvert(((Xim)xim)->private.proto.ctoutf8_conv,
- from, from_len, to, to_len, state);
-}
-
-Public int
-_XimProtoMbLookupString(
- XIC xic,
- XKeyEvent *ev,
- char *buffer,
- int bytes,
- KeySym *keysym,
- Status *state)
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- int ret;
- Status tmp_state;
- XimCommitInfo info;
-
- if (!IS_SERVER_CONNECTED(im))
- return 0;
-
- if (!state)
- state = &tmp_state;
-
- if ((ev->type == KeyPress) && (ev->keycode == 0)) { /* Filter function */
- if (!(info = ic->private.proto.commit_info)) {
- *state = XLookupNone;
- return 0;
- }
-
- ret = im->methods->ctstombs((XIM)im, info->string,
- info->string_len, buffer, bytes, state);
- if (*state == XBufferOverflow)
- return ret;
- if (keysym && (info->keysym && *(info->keysym))) {
- *keysym = *(info->keysym);
- if (*state == XLookupChars)
- *state = XLookupBoth;
- else
- *state = XLookupKeySym;
- }
- _XimUnregCommitInfo(ic);
-
- } else if (ev->type == KeyPress) {
- ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
- if (ret > 0) {
- if (ret > bytes)
- *state = XBufferOverflow;
- else if (keysym && *keysym != NoSymbol)
- *state = XLookupBoth;
- else
- *state = XLookupChars;
- } else {
- if (keysym && *keysym != NoSymbol)
- *state = XLookupKeySym;
- else
- *state = XLookupNone;
- }
- } else {
- *state = XLookupNone;
- ret = 0;
- }
-
- return ret;
-}
-
-Public int
-_XimProtoWcLookupString(
- XIC xic,
- XKeyEvent *ev,
- wchar_t *buffer,
- int bytes,
- KeySym *keysym,
- Status *state)
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- int ret;
- Status tmp_state;
- XimCommitInfo info;
-
- if (!IS_SERVER_CONNECTED(im))
- return 0;
-
- if (!state)
- state = &tmp_state;
-
- if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
- if (!(info = ic->private.proto.commit_info)) {
- *state = XLookupNone;
- return 0;
- }
-
- ret = im->methods->ctstowcs((XIM)im, info->string,
- info->string_len, buffer, bytes, state);
- if (*state == XBufferOverflow)
- return ret;
- if (keysym && (info->keysym && *(info->keysym))) {
- *keysym = *(info->keysym);
- if (*state == XLookupChars)
- *state = XLookupBoth;
- else
- *state = XLookupKeySym;
- }
- _XimUnregCommitInfo(ic);
-
- } else if (ev->type == KeyPress) {
- ret = _XimLookupWCText(ic, ev, buffer, bytes, keysym, NULL);
- if (ret > 0) {
- if (ret > bytes)
- *state = XBufferOverflow;
- else if (keysym && *keysym != NoSymbol)
- *state = XLookupBoth;
- else
- *state = XLookupChars;
- } else {
- if (keysym && *keysym != NoSymbol)
- *state = XLookupKeySym;
- else
- *state = XLookupNone;
- }
- } else {
- *state = XLookupNone;
- ret = 0;
- }
-
- return ret;
-}
-
-Public int
-_XimProtoUtf8LookupString(
- XIC xic,
- XKeyEvent *ev,
- char *buffer,
- int bytes,
- KeySym *keysym,
- Status *state)
-{
- Xic ic = (Xic)xic;
- Xim im = (Xim)ic->core.im;
- int ret;
- Status tmp_state;
- XimCommitInfo info;
-
- if (!IS_SERVER_CONNECTED(im))
- return 0;
-
- if (!state)
- state = &tmp_state;
-
- if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
- if (!(info = ic->private.proto.commit_info)) {
- *state = XLookupNone;
- return 0;
- }
-
- ret = im->methods->ctstoutf8((XIM)im, info->string,
- info->string_len, buffer, bytes, state);
- if (*state == XBufferOverflow)
- return ret;
- if (keysym && (info->keysym && *(info->keysym))) {
- *keysym = *(info->keysym);
- if (*state == XLookupChars)
- *state = XLookupBoth;
- else
- *state = XLookupKeySym;
- }
- _XimUnregCommitInfo(ic);
-
- } else if (ev->type == KeyPress) {
- ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);
- if (ret > 0) {
- if (ret > bytes)
- *state = XBufferOverflow;
- else if (keysym && *keysym != NoSymbol)
- *state = XLookupBoth;
- else
- *state = XLookupChars;
- } else {
- if (keysym && *keysym != NoSymbol)
- *state = XLookupKeySym;
- else
- *state = XLookupNone;
- }
- } else {
- *state = XLookupNone;
- ret = 0;
- }
-
- return ret;
-}
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xatom.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Public Xic
+_XimICOfXICID(
+ Xim im,
+ XICID icid)
+{
+ Xic pic;
+
+ for (pic = (Xic)im->core.ic_chain; pic; pic = (Xic)pic->core.next) {
+ if (pic->private.proto.icid == icid)
+ return pic;
+ }
+ return (Xic)0;
+}
+
+Private void
+_XimProcIMSetEventMask(
+ Xim im,
+ XPointer buf)
+{
+ EVENTMASK *buf_l = (EVENTMASK *)buf;
+
+ im->private.proto.forward_event_mask = buf_l[0];
+ im->private.proto.synchronous_event_mask = buf_l[1];
+ return;
+}
+
+Private void
+_XimProcICSetEventMask(
+ Xic ic,
+ XPointer buf)
+{
+ EVENTMASK *buf_l = (EVENTMASK *)buf;
+
+ ic->private.proto.forward_event_mask = buf_l[0];
+ ic->private.proto.synchronous_event_mask = buf_l[1];
+ _XimReregisterFilter(ic);
+ return;
+}
+
+Public Bool
+_XimSetEventMaskCallback(
+ Xim xim,
+ INT16 len,
+ XPointer data,
+ XPointer call_data)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+ Xim im = (Xim)call_data;
+ Xic ic;
+
+ if (imid == im->private.proto.imid) {
+ if (icid) {
+ ic = _XimICOfXICID(im, icid);
+ _XimProcICSetEventMask(ic, (XPointer)&buf_s[2]);
+ } else {
+ _XimProcIMSetEventMask(im, (XPointer)&buf_s[2]);
+ }
+ return True;
+ }
+ return False;
+}
+
+Private Bool
+_XimSyncCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ Xic ic = (Xic)arg;
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+
+ if ((major_opcode == XIM_SYNC_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid)
+ && (icid == ic->private.proto.icid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid)
+ && (buf_s[2] & XIM_ICID_VALID)
+ && (icid == ic->private.proto.icid))
+ return True;
+ return False;
+}
+
+Public Bool
+_XimSync(
+ Xim im,
+ Xic ic)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16); /* sizeof icid */
+
+ _XimSetHeader((XPointer)buf, XIM_SYNC, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimSyncCheck, (XPointer)ic);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(len);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimSyncCheck, (XPointer)ic);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return False;
+ }
+ }
+ } else {
+ return False;
+ }
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+ return True;
+}
+
+Public Bool
+_XimProcSyncReply(
+ Xim im,
+ Xic ic)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len;
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16); /* sizeof icid */
+
+ _XimSetHeader((XPointer)buf, XIM_SYNC_REPLY, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ return True;
+}
+
+Public Bool
+_XimRespSyncReply(
+ Xic ic,
+ BITMASK16 mode)
+{
+ if (mode & XimSYNCHRONUS) /* SYNC Request */ {
+ if (IS_FOCUSED(ic))
+ MARK_NEED_SYNC_REPLY(ic);
+ else
+ _XimProcSyncReply((Xim)ic->core.im, ic);
+ }
+
+ return True;
+}
+
+Public Bool
+_XimSyncCallback(
+ Xim xim,
+ INT16 len,
+ XPointer data,
+ XPointer call_data)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+ Xim im = (Xim)call_data;
+ Xic ic;
+
+ if ((imid == im->private.proto.imid)
+ && (ic = _XimICOfXICID(im, icid))) {
+ (void)_XimProcSyncReply(im, ic);
+ return True;
+ }
+ return False;
+}
+
+Private INT16
+_XimSetEventToWire(
+ XEvent *ev,
+ xEvent *event)
+{
+ if (!(_XimProtoEventToWire(ev, event, False)))
+ return 0;
+ event->u.u.sequenceNumber =
+ ((XAnyEvent *)ev)->serial & (unsigned long)0xffff;
+ return sz_xEvent;
+}
+
+Private Bool
+_XimForwardEventCore(
+ Xic ic,
+ XEvent *ev,
+ Bool sync)
+{
+ Xim im = (Xim)ic->core.im;
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+ INT16 len;
+
+ if (!(len = _XimSetEventToWire(ev, (xEvent *)&buf_s[4])))
+ return False; /* X event */
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+ buf_s[2] = sync ? XimSYNCHRONUS : 0; /* flag */
+ buf_s[3] =
+ (CARD16)((((XAnyEvent *)ev)->serial & ~((unsigned long)0xffff)) >> 16);
+ /* serial number */
+
+ len += sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16) /* sizeof icid */
+ + sizeof(BITMASK16) /* sizeof flag */
+ + sizeof(CARD16); /* sizeof serila number */
+
+ _XimSetHeader((XPointer)buf, XIM_FORWARD_EVENT, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+
+ if (sync) {
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimSyncCheck, (XPointer)ic);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(len);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimSyncCheck, (XPointer)ic);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return False;
+ }
+ }
+ } else {
+ return False;
+ }
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+ }
+ return True;
+}
+
+Public Bool
+_XimForwardEvent(
+ Xic ic,
+ XEvent *ev,
+ Bool sync)
+{
+#ifdef EXT_FORWARD
+ if (((ev->type == KeyPress) || (ev->type == KeyRelease)))
+ if (_XimExtForwardKeyEvent(ic, (XKeyEvent *)ev, sync))
+ return True;
+#endif
+ return _XimForwardEventCore(ic, ev, sync);
+}
+
+Private void
+_XimProcEvent(
+ Display *d,
+ Xic ic,
+ XEvent *ev,
+ CARD16 *buf)
+{
+ INT16 serial = buf[0];
+ xEvent *xev = (xEvent *)&buf[1];
+
+ _XimProtoWireToEvent(ev, xev, False);
+ ev->xany.serial |= serial << 16;
+ ev->xany.send_event = False;
+ ev->xany.display = d;
+ MARK_FABLICATED(ic);
+ return;
+}
+
+Private Bool
+_XimForwardEventRecv(
+ Xim im,
+ Xic ic,
+ XPointer buf)
+{
+ CARD16 *buf_s = (CARD16 *)buf;
+ Display *d = im->core.display;
+ XEvent ev;
+
+ _XimProcEvent(d, ic, &ev, &buf_s[1]);
+
+ (void)_XimRespSyncReply(ic, buf_s[0]);
+
+ XPutBackEvent(d, &ev);
+
+ return True;
+}
+
+Public Bool
+_XimForwardEventCallback(
+ Xim xim,
+ INT16 len,
+ XPointer data,
+ XPointer call_data)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+ Xim im = (Xim)call_data;
+ Xic ic;
+
+ if ((imid == im->private.proto.imid)
+ && (ic = _XimICOfXICID(im, icid))) {
+ (void)_XimForwardEventRecv(im, ic, (XPointer)&buf_s[2]);
+ return True;
+ }
+ return False;
+}
+
+Private Bool
+_XimRegisterTriggerkey(
+ Xim im,
+ XPointer buf)
+{
+ CARD32 *buf_l = (CARD32 *)buf;
+ CARD32 len;
+ CARD32 *key;
+
+ if (IS_DYNAMIC_EVENT_FLOW(im)) /* already Dynamic event flow mode */
+ return True;
+
+ /*
+ * register onkeylist
+ */
+
+ len = buf_l[0]; /* length of on-keys */
+ len += sizeof(INT32); /* sizeof length of on-keys */
+
+ if (!(key = (CARD32 *)Xmalloc(len))) {
+ _XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
+ return False;
+ }
+ memcpy((char *)key, (char *)buf_l, len);
+ im->private.proto.im_onkeylist = key;
+
+ MARK_DYNAMIC_EVENT_FLOW(im);
+
+ /*
+ * register offkeylist
+ */
+
+ buf_l = (CARD32 *)((char *)buf + len);
+ len = buf_l[0]; /* length of off-keys */
+ len += sizeof(INT32); /* sizeof length of off-keys */
+
+ if (!(key = (CARD32 *)Xmalloc(len))) {
+ _XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
+ return False;
+ }
+
+ memcpy((char *)key, (char *)buf_l, len);
+ im->private.proto.im_offkeylist = key;
+
+ return True;
+}
+
+Public Bool
+_XimRegisterTriggerKeysCallback(
+ Xim xim,
+ INT16 len,
+ XPointer data,
+ XPointer call_data)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ Xim im = (Xim)call_data;
+
+ (void )_XimRegisterTriggerkey(im, (XPointer)&buf_s[2]);
+ return True;
+}
+
+Public EVENTMASK
+_XimGetWindowEventmask(
+ Xic ic)
+{
+ Xim im = (Xim )ic->core.im;
+ XWindowAttributes atr;
+
+ if (!XGetWindowAttributes(im->core.display, ic->core.focus_window, &atr))
+ return 0;
+ return (EVENTMASK)atr.your_event_mask;
+}
+
+
+Private Bool
+_XimTriggerNotifyCheck(
+ Xim im,
+ INT16 len,
+ XPointer data,
+ XPointer arg)
+{
+ Xic ic = (Xic)arg;
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ CARD8 major_opcode = *((CARD8 *)data);
+ CARD8 minor_opcode = *((CARD8 *)data + 1);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+
+ if ((major_opcode == XIM_TRIGGER_NOTIFY_REPLY)
+ && (minor_opcode == 0)
+ && (imid == im->private.proto.imid)
+ && (icid == ic->private.proto.icid))
+ return True;
+ if ((major_opcode == XIM_ERROR)
+ && (minor_opcode == 0)
+ && (buf_s[2] & XIM_IMID_VALID)
+ && (imid == im->private.proto.imid)
+ && (buf_s[2] & XIM_ICID_VALID)
+ && (icid == ic->private.proto.icid))
+ return True;
+ return False;
+}
+
+Public Bool
+_XimTriggerNotify(
+ Xim im,
+ Xic ic,
+ int mode,
+ CARD32 idx)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ CARD32 *buf_l = (CARD32 *)&buf[XIM_HEADER_SIZE];
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+ INT16 len;
+ EVENTMASK mask = _XimGetWindowEventmask(ic);
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+ buf_l[1] = mode; /* flag */
+ buf_l[2] = idx; /* index of keys list */
+ buf_l[3] = mask; /* select-event-mask */
+
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16) /* sizeof icid */
+ + sizeof(CARD32) /* sizeof flag */
+ + sizeof(CARD32) /* sizeof index of key list */
+ + sizeof(EVENTMASK); /* sizeof select-event-mask */
+
+ _XimSetHeader((XPointer)buf, XIM_TRIGGER_NOTIFY, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimTriggerNotifyCheck, (XPointer)ic);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_size = len;
+ preply = (XPointer)Xmalloc(len);
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimTriggerNotifyCheck, (XPointer)ic);
+ if(ret_code != XIM_TRUE) {
+ Xfree(preply);
+ return False;
+ }
+ }
+ } else {
+ return False;
+ }
+ buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
+ if (*((CARD8 *)preply) == XIM_ERROR) {
+ _XimProcError(im, 0, (XPointer)&buf_s[3]);
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+ return True;
+}
+
+Private Bool
+_XimRegCommitInfo(
+ Xic ic,
+ char *string,
+ int string_len,
+ KeySym *keysym,
+ int keysym_len)
+{
+ XimCommitInfo info;
+
+ if (!(info = (XimCommitInfo)Xmalloc(sizeof(XimCommitInfoRec))))
+ return False;
+ info->string = string;
+ info->string_len = string_len;
+ info->keysym = keysym;
+ info->keysym_len = keysym_len;
+ info->next = ic->private.proto.commit_info;
+ ic->private.proto.commit_info = info;
+ return True;
+}
+
+Private void
+_XimUnregCommitInfo(
+ Xic ic)
+{
+ XimCommitInfo info;
+
+ if (!(info = ic->private.proto.commit_info))
+ return;
+
+ if (info->string)
+ Xfree(info->string);
+ if (info->keysym)
+ Xfree(info->keysym);
+ ic->private.proto.commit_info = info->next;
+ Xfree(info);
+ return;
+}
+
+Public void
+_XimFreeCommitInfo(
+ Xic ic)
+{
+ while (ic->private.proto.commit_info)
+ _XimUnregCommitInfo(ic);
+ return;
+}
+
+Private Bool
+_XimProcKeySym(
+ Xic ic,
+ CARD32 sym,
+ KeySym **xim_keysym,
+ int *xim_keysym_len)
+{
+ Xim im = (Xim)ic->core.im;
+
+ if (!(*xim_keysym = (KeySym *)Xmalloc(sizeof(KeySym)))) {
+ _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
+ return False;
+ }
+
+ **xim_keysym = (KeySym)sym;
+ *xim_keysym_len = 1;
+
+ return True;
+}
+
+Private Bool
+_XimProcCommit(
+ Xic ic,
+ BYTE *buf,
+ int len,
+ char **xim_string,
+ int *xim_string_len)
+{
+ Xim im = (Xim)ic->core.im;
+ char *string;
+
+ if (!(string = (char *)Xmalloc(len + 1))) {
+ _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
+ return False;
+ }
+
+ (void)memcpy(string, (char *)buf, len);
+ string[len] = '\0';
+
+ *xim_string = string;
+ *xim_string_len = len;
+ return True;
+}
+
+Private Bool
+_XimCommitRecv(
+ Xim im,
+ Xic ic,
+ XPointer buf)
+{
+ CARD16 *buf_s = (CARD16 *)buf;
+ BITMASK16 flag = buf_s[0];
+ XKeyEvent ev;
+ char *string = NULL;
+ int string_len = 0;
+ KeySym *keysym = NULL;
+ int keysym_len = 0;
+
+ if ((flag & XimLookupBoth) == XimLookupChars) {
+ if (!(_XimProcCommit(ic, (BYTE *)&buf_s[2],
+ (int)buf_s[1], &string, &string_len)))
+ return False;
+
+ } else if ((flag & XimLookupBoth) == XimLookupKeySym) {
+ if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len)))
+ return False;
+
+ } else if ((flag & XimLookupBoth) == XimLookupBoth) {
+ if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len)))
+ return False;
+
+ if (!(_XimProcCommit(ic, (BYTE *)&buf_s[5],
+ (int)buf_s[4], &string, &string_len))) {
+ Xfree(keysym);
+ return False;
+ }
+ }
+
+ if (!(_XimRegCommitInfo(ic, string, string_len, keysym, keysym_len))) {
+ if (string)
+ Xfree(string);
+ if (keysym)
+ Xfree(keysym);
+ _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
+ return False;
+ }
+
+ (void)_XimRespSyncReply(ic, flag);
+
+ MARK_FABLICATED(ic);
+
+ ev.type = KeyPress;
+ ev.send_event = False;
+ ev.display = im->core.display;
+ ev.window = ic->core.focus_window;
+ ev.keycode = 0;
+ ev.state = 0;
+
+ XPutBackEvent(im->core.display, (XEvent *)&ev);
+
+ return True;
+}
+
+Public Bool
+_XimCommitCallback(
+ Xim xim,
+ INT16 len,
+ XPointer data,
+ XPointer call_data)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ XIMID imid = buf_s[0];
+ XICID icid = buf_s[1];
+ Xim im = (Xim)call_data;
+ Xic ic;
+
+ if ((imid == im->private.proto.imid)
+ && (ic = _XimICOfXICID(im, icid))) {
+ (void)_XimCommitRecv(im, ic, (XPointer)&buf_s[2]);
+ return True;
+ }
+ return False;
+}
+
+Public void
+_XimProcError(
+ Xim im,
+ Xic ic,
+ XPointer data)
+{
+ return;
+}
+
+Public Bool
+_XimErrorCallback(
+ Xim xim,
+ INT16 len,
+ XPointer data,
+ XPointer call_data)
+{
+ CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
+ BITMASK16 flag = buf_s[2];
+ XIMID imid;
+ XICID icid;
+ Xim im = (Xim)call_data;
+ Xic ic = NULL;
+
+ if (flag & XIM_IMID_VALID) {
+ imid = buf_s[0];
+ if (imid != im->private.proto.imid)
+ return False;
+ }
+ if (flag & XIM_ICID_VALID) {
+ icid = buf_s[1];
+ if (!(ic = _XimICOfXICID(im, icid)))
+ return False;
+ }
+ _XimProcError(im, ic, (XPointer)&buf_s[3]);
+
+ return True;
+}
+
+Public Bool
+_XimError(
+ Xim im,
+ Xic ic,
+ CARD16 error_code,
+ INT16 detail_length,
+ CARD16 type,
+ char *detail)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len = 0;
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[2] = XIM_IMID_VALID; /* flag */
+ if (ic) {
+ buf_s[1] = ic->private.proto.icid; /* icid */
+ buf_s[2] |= XIM_ICID_VALID; /* flag */
+ }
+ buf_s[3] = error_code; /* Error Code */
+ buf_s[4] = detail_length; /* length of error detail */
+ buf_s[5] = type; /* type of error detail */
+
+ if (detail_length && detail) {
+ len = detail_length;
+ memcpy((char *)&buf_s[6], detail, len);
+ XIM_SET_PAD(&buf_s[6], len);
+ }
+
+ len += sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16) /* sizeof icid */
+ + sizeof(BITMASK16) /* sizeof flag */
+ + sizeof(CARD16) /* sizeof error_code */
+ + sizeof(INT16) /* sizeof length of detail */
+ + sizeof(CARD16); /* sizeof type */
+
+ _XimSetHeader((XPointer)buf, XIM_ERROR, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ return True;
+}
+
+Private int
+_Ximctsconvert(
+ XlcConv conv,
+ char *from,
+ int from_len,
+ char *to,
+ int to_len,
+ Status *state)
+{
+ int from_left;
+ int to_left;
+ int from_savelen;
+ int to_savelen;
+ int from_cnvlen;
+ int to_cnvlen;
+ char *from_buf;
+ char *to_buf;
+ char scratchbuf[BUFSIZ];
+ Status tmp_state;
+
+ if (!state)
+ state = &tmp_state;
+
+ if (!conv || !from || !from_len) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ /* Reset the converter. The CompoundText at 'from' starts in
+ initial state. */
+ _XlcResetConverter(conv);
+
+ from_left = from_len;
+ to_left = BUFSIZ;
+ from_cnvlen = 0;
+ to_cnvlen = 0;
+ for (;;) {
+ from_buf = &from[from_cnvlen];
+ from_savelen = from_left;
+ to_buf = &scratchbuf[to_cnvlen];
+ to_savelen = to_left;
+ if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
+ (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
+ *state = XLookupNone;
+ return 0;
+ }
+ from_cnvlen += (from_savelen - from_left);
+ to_cnvlen += (to_savelen - to_left);
+ if (from_left == 0) {
+ if (!to_cnvlen) {
+ *state = XLookupNone;
+ return 0;
+ }
+ break;
+ }
+ }
+
+ if (!to || !to_len || (to_len < to_cnvlen)) {
+ *state = XBufferOverflow;
+ } else {
+ memcpy(to, scratchbuf, to_cnvlen);
+ *state = XLookupChars;
+ }
+ return to_cnvlen;
+}
+
+Public int
+_Ximctstombs(XIM xim, char *from, int from_len,
+ char *to, int to_len, Status *state)
+{
+ return _Ximctsconvert(((Xim)xim)->private.proto.ctom_conv,
+ from, from_len, to, to_len, state);
+}
+
+Public int
+_Ximctstowcs(
+ XIM xim,
+ char *from,
+ int from_len,
+ wchar_t *to,
+ int to_len,
+ Status *state)
+{
+ Xim im = (Xim)xim;
+ XlcConv conv = im->private.proto.ctow_conv;
+ int from_left;
+ int to_left;
+ int from_savelen;
+ int to_savelen;
+ int from_cnvlen;
+ int to_cnvlen;
+ char *from_buf;
+ wchar_t *to_buf;
+ wchar_t scratchbuf[BUFSIZ];
+ Status tmp_state;
+
+ if (!state)
+ state = &tmp_state;
+
+ if (!conv || !from || !from_len) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ /* Reset the converter. The CompoundText at 'from' starts in
+ initial state. */
+ _XlcResetConverter(conv);
+
+ from_left = from_len;
+ to_left = BUFSIZ;
+ from_cnvlen = 0;
+ to_cnvlen = 0;
+ for (;;) {
+ from_buf = &from[from_cnvlen];
+ from_savelen = from_left;
+ to_buf = &scratchbuf[to_cnvlen];
+ to_savelen = to_left;
+ if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
+ (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
+ *state = XLookupNone;
+ return 0;
+ }
+ from_cnvlen += (from_savelen - from_left);
+ to_cnvlen += (to_savelen - to_left);
+ if (from_left == 0) {
+ if (!to_cnvlen){
+ *state = XLookupNone;
+ return 0;
+ }
+ break;
+ }
+ }
+
+ if (!to || !to_len || (to_len < to_cnvlen)) {
+ *state = XBufferOverflow;
+ } else {
+ memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t));
+ *state = XLookupChars;
+ }
+ return to_cnvlen;
+}
+
+Public int
+_Ximctstoutf8(
+ XIM xim,
+ char *from,
+ int from_len,
+ char *to,
+ int to_len,
+ Status *state)
+{
+ return _Ximctsconvert(((Xim)xim)->private.proto.ctoutf8_conv,
+ from, from_len, to, to_len, state);
+}
+
+Public int
+_XimProtoMbLookupString(
+ XIC xic,
+ XKeyEvent *ev,
+ char *buffer,
+ int bytes,
+ KeySym *keysym,
+ Status *state)
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ int ret;
+ Status tmp_state;
+ XimCommitInfo info;
+
+ if (!IS_SERVER_CONNECTED(im))
+ return 0;
+
+ if (!state)
+ state = &tmp_state;
+
+ if ((ev->type == KeyPress) && (ev->keycode == 0)) { /* Filter function */
+ if (!(info = ic->private.proto.commit_info)) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ ret = im->methods->ctstombs((XIM)im, info->string,
+ info->string_len, buffer, bytes, state);
+ if (*state == XBufferOverflow)
+ return ret;
+ if (keysym && (info->keysym && *(info->keysym))) {
+ *keysym = *(info->keysym);
+ if (*state == XLookupChars)
+ *state = XLookupBoth;
+ else
+ *state = XLookupKeySym;
+ }
+ _XimUnregCommitInfo(ic);
+
+ } else if (ev->type == KeyPress) {
+ ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
+ if (ret > 0) {
+ if (ret > bytes)
+ *state = XBufferOverflow;
+ else if (keysym && *keysym != NoSymbol)
+ *state = XLookupBoth;
+ else
+ *state = XLookupChars;
+ } else {
+ if (keysym && *keysym != NoSymbol)
+ *state = XLookupKeySym;
+ else
+ *state = XLookupNone;
+ }
+ } else {
+ *state = XLookupNone;
+ ret = 0;
+ }
+
+ return ret;
+}
+
+Public int
+_XimProtoWcLookupString(
+ XIC xic,
+ XKeyEvent *ev,
+ wchar_t *buffer,
+ int bytes,
+ KeySym *keysym,
+ Status *state)
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ int ret;
+ Status tmp_state;
+ XimCommitInfo info;
+
+ if (!IS_SERVER_CONNECTED(im))
+ return 0;
+
+ if (!state)
+ state = &tmp_state;
+
+ if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
+ if (!(info = ic->private.proto.commit_info)) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ ret = im->methods->ctstowcs((XIM)im, info->string,
+ info->string_len, buffer, bytes, state);
+ if (*state == XBufferOverflow)
+ return ret;
+ if (keysym && (info->keysym && *(info->keysym))) {
+ *keysym = *(info->keysym);
+ if (*state == XLookupChars)
+ *state = XLookupBoth;
+ else
+ *state = XLookupKeySym;
+ }
+ _XimUnregCommitInfo(ic);
+
+ } else if (ev->type == KeyPress) {
+ ret = _XimLookupWCText(ic, ev, buffer, bytes, keysym, NULL);
+ if (ret > 0) {
+ if (ret > bytes)
+ *state = XBufferOverflow;
+ else if (keysym && *keysym != NoSymbol)
+ *state = XLookupBoth;
+ else
+ *state = XLookupChars;
+ } else {
+ if (keysym && *keysym != NoSymbol)
+ *state = XLookupKeySym;
+ else
+ *state = XLookupNone;
+ }
+ } else {
+ *state = XLookupNone;
+ ret = 0;
+ }
+
+ return ret;
+}
+
+Public int
+_XimProtoUtf8LookupString(
+ XIC xic,
+ XKeyEvent *ev,
+ char *buffer,
+ int bytes,
+ KeySym *keysym,
+ Status *state)
+{
+ Xic ic = (Xic)xic;
+ Xim im = (Xim)ic->core.im;
+ int ret;
+ Status tmp_state;
+ XimCommitInfo info;
+
+ if (!IS_SERVER_CONNECTED(im))
+ return 0;
+
+ if (!state)
+ state = &tmp_state;
+
+ if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
+ if (!(info = ic->private.proto.commit_info)) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ ret = im->methods->ctstoutf8((XIM)im, info->string,
+ info->string_len, buffer, bytes, state);
+ if (*state == XBufferOverflow)
+ return ret;
+ if (keysym && (info->keysym && *(info->keysym))) {
+ *keysym = *(info->keysym);
+ if (*state == XLookupChars)
+ *state = XLookupBoth;
+ else
+ *state = XLookupKeySym;
+ }
+ _XimUnregCommitInfo(ic);
+
+ } else if (ev->type == KeyPress) {
+ ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);
+ if (ret > 0) {
+ if (ret > bytes)
+ *state = XBufferOverflow;
+ else if (keysym && *keysym != NoSymbol)
+ *state = XLookupBoth;
+ else
+ *state = XLookupChars;
+ } else {
+ if (keysym && *keysym != NoSymbol)
+ *state = XLookupKeySym;
+ else
+ *state = XLookupNone;
+ }
+ } else {
+ *state = XLookupNone;
+ ret = 0;
+ }
+
+ return ret;
+}
diff --git a/libX11/modules/im/ximcp/imInt.c b/libX11/modules/im/ximcp/imInt.c
index e9371827d..9e8c426c3 100644
--- a/libX11/modules/im/ximcp/imInt.c
+++ b/libX11/modules/im/ximcp/imInt.c
@@ -1,264 +1,264 @@
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <unistd.h>
-#include <X11/Xatom.h>
-#include <X11/Xlib.h>
-#include <X11/Xmd.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "XimImSw.h"
-
-Private Xim *_XimCurrentIMlist = (Xim *)NULL;
-Private int _XimCurrentIMcount = 0;
-
-Private Bool
-_XimSetIMStructureList(
- Xim im)
-{
- register int i;
- Xim *xim;
-
- if(!(_XimCurrentIMlist)) {
- if(!(_XimCurrentIMlist = (Xim *)Xmalloc(sizeof(Xim))))
- return False;
- _XimCurrentIMlist[0] = im;
- _XimCurrentIMcount = 1;
- }
- else {
- for(i = 0; i < _XimCurrentIMcount; i++) {
- if(!( _XimCurrentIMlist[i])) {
- _XimCurrentIMlist[i] = im;
- break;
- }
- }
- if(i >= _XimCurrentIMcount) {
- if(!(xim = (Xim *)Xrealloc(_XimCurrentIMlist,
- ((i + 1) * sizeof(Xim)))))
- return False;
- _XimCurrentIMlist = xim;
- _XimCurrentIMlist[_XimCurrentIMcount] = im;
- _XimCurrentIMcount++;
- }
- }
- return True;
-}
-
-Public void
-_XimDestroyIMStructureList(Xim im)
-{
- register int i;
-
- for(i = 0; i < _XimCurrentIMcount; i++) {
- if(_XimCurrentIMlist[i] == im) {
- _XimCurrentIMlist[i] = NULL;
- break;
- }
- }
- return;
-}
-
-Public void
-_XimServerDestroy(Xim im_2_destroy)
-{
- register int i;
- Xim im;
- XIC ic;
-
- for(i = 0; i < _XimCurrentIMcount; i++) {
- if(!(im = _XimCurrentIMlist[i]))
- continue;
- /*
- * Only continue if this im is the one to be destroyed.
- */
- if (im != im_2_destroy)
- continue;
-
- if (im->core.destroy_callback.callback)
- (*im->core.destroy_callback.callback)((XIM)im,
- im->core.destroy_callback.client_data, NULL);
- for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
- if (ic->core.destroy_callback.callback) {
- (*ic->core.destroy_callback.callback)(ic,
- ic->core.destroy_callback.client_data, NULL);
- }
- }
- _XimResetIMInstantiateCallback( im );
- (void)im->methods->close((XIM)im);
- Xfree(im);
- _XimCurrentIMlist[i] = NULL;
- return;
- }
-}
-
-#ifdef XIM_CONNECTABLE
-Public void
-_XimServerReconectableDestroy(void)
-{
- register int i;
- Xim im;
- XIC ic;
-
- for(i = 0; i < _XimCurrentIMcount; i++) {
- if(!(im = _XimCurrentIMlist[i]))
- continue;
-
- if (im->core.destroy_callback.callback)
- (*im->core.destroy_callback.callback)(im,
- im->core.destroy_callback.client_data, NULL);
- for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
- if (ic->core.destroy_callback.callback) {
- (*ic->core.destroy_callback.callback)(ic,
- ic->core.destroy_callback.client_data, NULL);
- }
- }
- _XimResetIMInstantiateCallback( im );
- (void)im->methods->close((XIM)im);
- }
- return;
-}
-#endif /* XIM_CONNECTABLE */
-
-Private const char *
-_XimStrstr(
- register const char *src,
- register const char *dest)
-{
- int len;
-
- len = strlen(dest);
- while((src = strchr(src, *dest))) {
- if(!strncmp(src, dest, len))
- return src;
- src++;
- }
- return NULL;
-}
-
-Private char *
-_XimMakeImName(
- XLCd lcd)
-{
- const char* begin = NULL;
- const char* end = NULL;
- char* ret = NULL;
- const char* ximmodifier = XIMMODIFIER;
-
- if(lcd->core->modifiers != NULL && *lcd->core->modifiers != '\0') {
- begin = _XimStrstr(lcd->core->modifiers, ximmodifier);
- if (begin != NULL) {
- end = begin += strlen(ximmodifier);
- while (*end && *end != '@')
- end++;
- }
- }
- ret = Xmalloc(end - begin + 1);
- if (ret != NULL) {
- if (begin != NULL && end != NULL) {
- (void)strncpy(ret, begin, end - begin);
- ret[end - begin] = '\0';
- } else {
- ret[0] = '\0';
- }
- }
-
- return ret;
-}
-
-Public XIM
-_XimOpenIM(
- XLCd lcd,
- Display *dpy,
- XrmDatabase rdb,
- char *res_name,
- char *res_class)
-{
- Xim im;
- register int i;
-
- if (!(im = Xcalloc(1, sizeof(XimRec))))
- return (XIM)NULL;
-
- im->core.lcd = lcd;
- im->core.ic_chain = (XIC)NULL;
- im->core.display = dpy;
- im->core.rdb = rdb;
- im->core.res_name = NULL;
- im->core.res_class = NULL;
- if((res_name != NULL) && (*res_name != '\0')){
- if(!(im->core.res_name = strdup(res_name)))
- goto Error1;
- }
- if((res_class != NULL) && (*res_class != '\0')){
- if(!(im->core.res_class = strdup(res_class)))
- goto Error2;
- }
- if(!(im->core.im_name = _XimMakeImName(lcd)))
- goto Error3;
-
- for(i= 0; ; i++) {
- if(_XimImSportRec[i].checkprocessing(im)) {
- if(!(_XimImSportRec[i].im_open(im)))
- goto Error4;
- if(!_XimSetIMStructureList(im))
- goto Error4;
- return (XIM)im;
- }
- }
-
-Error4 :
- _XimImSportRec[i].im_free(im);
- Xfree(im);
- return NULL;
-Error3 :
- if(im->core.im_name)
- Xfree(im->core.im_name);
-Error2:
- if(im->core.res_class)
- Xfree(im->core.res_class);
-Error1:
- if(im->core.res_name)
- Xfree(im->core.res_name);
- Xfree(im);
- return NULL;
-}
-
-Public Bool
-_XInitIM(XLCd lcd)
-{
- if(lcd == (XLCd)NULL)
- return False;
- lcd->methods->open_im = _XimOpenIM;
- lcd->methods->register_callback = _XimRegisterIMInstantiateCallback;
- lcd->methods->unregister_callback = _XimUnRegisterIMInstantiateCallback;
- return True;
-}
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <unistd.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <X11/Xmd.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "XimImSw.h"
+
+Private Xim *_XimCurrentIMlist = (Xim *)NULL;
+Private int _XimCurrentIMcount = 0;
+
+Private Bool
+_XimSetIMStructureList(
+ Xim im)
+{
+ register int i;
+ Xim *xim;
+
+ if(!(_XimCurrentIMlist)) {
+ if(!(_XimCurrentIMlist = (Xim *)Xmalloc(sizeof(Xim))))
+ return False;
+ _XimCurrentIMlist[0] = im;
+ _XimCurrentIMcount = 1;
+ }
+ else {
+ for(i = 0; i < _XimCurrentIMcount; i++) {
+ if(!( _XimCurrentIMlist[i])) {
+ _XimCurrentIMlist[i] = im;
+ break;
+ }
+ }
+ if(i >= _XimCurrentIMcount) {
+ if(!(xim = (Xim *)Xrealloc(_XimCurrentIMlist,
+ ((i + 1) * sizeof(Xim)))))
+ return False;
+ _XimCurrentIMlist = xim;
+ _XimCurrentIMlist[_XimCurrentIMcount] = im;
+ _XimCurrentIMcount++;
+ }
+ }
+ return True;
+}
+
+Public void
+_XimDestroyIMStructureList(Xim im)
+{
+ register int i;
+
+ for(i = 0; i < _XimCurrentIMcount; i++) {
+ if(_XimCurrentIMlist[i] == im) {
+ _XimCurrentIMlist[i] = NULL;
+ break;
+ }
+ }
+ return;
+}
+
+Public void
+_XimServerDestroy(Xim im_2_destroy)
+{
+ register int i;
+ Xim im;
+ XIC ic;
+
+ for(i = 0; i < _XimCurrentIMcount; i++) {
+ if(!(im = _XimCurrentIMlist[i]))
+ continue;
+ /*
+ * Only continue if this im is the one to be destroyed.
+ */
+ if (im != im_2_destroy)
+ continue;
+
+ if (im->core.destroy_callback.callback)
+ (*im->core.destroy_callback.callback)((XIM)im,
+ im->core.destroy_callback.client_data, NULL);
+ for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
+ if (ic->core.destroy_callback.callback) {
+ (*ic->core.destroy_callback.callback)(ic,
+ ic->core.destroy_callback.client_data, NULL);
+ }
+ }
+ _XimResetIMInstantiateCallback( im );
+ (void)im->methods->close((XIM)im);
+ Xfree(im);
+ _XimCurrentIMlist[i] = NULL;
+ return;
+ }
+}
+
+#ifdef XIM_CONNECTABLE
+Public void
+_XimServerReconectableDestroy(void)
+{
+ register int i;
+ Xim im;
+ XIC ic;
+
+ for(i = 0; i < _XimCurrentIMcount; i++) {
+ if(!(im = _XimCurrentIMlist[i]))
+ continue;
+
+ if (im->core.destroy_callback.callback)
+ (*im->core.destroy_callback.callback)(im,
+ im->core.destroy_callback.client_data, NULL);
+ for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
+ if (ic->core.destroy_callback.callback) {
+ (*ic->core.destroy_callback.callback)(ic,
+ ic->core.destroy_callback.client_data, NULL);
+ }
+ }
+ _XimResetIMInstantiateCallback( im );
+ (void)im->methods->close((XIM)im);
+ }
+ return;
+}
+#endif /* XIM_CONNECTABLE */
+
+Private const char *
+_XimStrstr(
+ register const char *src,
+ register const char *dest)
+{
+ int len;
+
+ len = strlen(dest);
+ while((src = strchr(src, *dest))) {
+ if(!strncmp(src, dest, len))
+ return src;
+ src++;
+ }
+ return NULL;
+}
+
+Private char *
+_XimMakeImName(
+ XLCd lcd)
+{
+ const char* begin = NULL;
+ const char* end = NULL;
+ char* ret = NULL;
+ const char* ximmodifier = XIMMODIFIER;
+
+ if(lcd->core->modifiers != NULL && *lcd->core->modifiers != '\0') {
+ begin = _XimStrstr(lcd->core->modifiers, ximmodifier);
+ if (begin != NULL) {
+ end = begin += strlen(ximmodifier);
+ while (*end && *end != '@')
+ end++;
+ }
+ }
+ ret = Xmalloc(end - begin + 1);
+ if (ret != NULL) {
+ if (begin != NULL && end != NULL) {
+ (void)strncpy(ret, begin, end - begin);
+ ret[end - begin] = '\0';
+ } else {
+ ret[0] = '\0';
+ }
+ }
+
+ return ret;
+}
+
+Public XIM
+_XimOpenIM(
+ XLCd lcd,
+ Display *dpy,
+ XrmDatabase rdb,
+ char *res_name,
+ char *res_class)
+{
+ Xim im;
+ register int i;
+
+ if (!(im = Xcalloc(1, sizeof(XimRec))))
+ return (XIM)NULL;
+
+ im->core.lcd = lcd;
+ im->core.ic_chain = (XIC)NULL;
+ im->core.display = dpy;
+ im->core.rdb = rdb;
+ im->core.res_name = NULL;
+ im->core.res_class = NULL;
+ if((res_name != NULL) && (*res_name != '\0')){
+ if(!(im->core.res_name = strdup(res_name)))
+ goto Error1;
+ }
+ if((res_class != NULL) && (*res_class != '\0')){
+ if(!(im->core.res_class = strdup(res_class)))
+ goto Error2;
+ }
+ if(!(im->core.im_name = _XimMakeImName(lcd)))
+ goto Error3;
+
+ for(i= 0; ; i++) {
+ if(_XimImSportRec[i].checkprocessing(im)) {
+ if(!(_XimImSportRec[i].im_open(im)))
+ goto Error4;
+ if(!_XimSetIMStructureList(im))
+ goto Error4;
+ return (XIM)im;
+ }
+ }
+
+Error4 :
+ _XimImSportRec[i].im_free(im);
+ Xfree(im);
+ return NULL;
+Error3 :
+ if(im->core.im_name)
+ Xfree(im->core.im_name);
+Error2:
+ if(im->core.res_class)
+ Xfree(im->core.res_class);
+Error1:
+ if(im->core.res_name)
+ Xfree(im->core.res_name);
+ Xfree(im);
+ return NULL;
+}
+
+Public Bool
+_XInitIM(XLCd lcd)
+{
+ if(lcd == (XLCd)NULL)
+ return False;
+ lcd->methods->open_im = _XimOpenIM;
+ lcd->methods->register_callback = _XimRegisterIMInstantiateCallback;
+ lcd->methods->unregister_callback = _XimUnRegisterIMInstantiateCallback;
+ return True;
+}
diff --git a/libX11/modules/im/ximcp/imLcFlt.c b/libX11/modules/im/ximcp/imLcFlt.c
index 7ab56f8a1..06aa9980a 100644
--- a/libX11/modules/im/ximcp/imLcFlt.c
+++ b/libX11/modules/im/ximcp/imLcFlt.c
@@ -1,125 +1,125 @@
-/******************************************************************
-
- Copyright 1992 by Fuji Xerox Co., Ltd.
- Copyright 1992, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Fuji Xerox,
-FUJITSU LIMITED not be used in advertising or publicity pertaining
-to distribution of the software without specific, written prior
-permission. Fuji Xerox, FUJITSU LIMITED make no representations
-about the suitability of this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
-FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
-OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author : Kazunori Nishihara Fuji Xerox
- Modifier : Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include <X11/keysym.h>
-#include "Xlcint.h"
-#include "Ximint.h"
-
-Bool
-_XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
-{
- Xic ic = (Xic)client_data;
- KeySym keysym;
- static char buf[256];
- DefTree *b = ic->private.local.base.tree;
- DTIndex t;
- Bool braille = False;
-
- if(ev->xkey.keycode == 0)
- return (False);
-
- XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL);
-
- if(IsModifierKey(keysym))
- return (False);
-
- if(keysym >= XK_braille_dot_1 && keysym <= XK_braille_dot_8) {
- if(ev->type == KeyPress) {
- ic->private.local.brl_pressed |=
- 1<<(keysym-XK_braille_dot_1);
- return(True);
- } else {
- if(!ic->private.local.brl_committing
- || ev->xkey.time - ic->private.local.brl_release_start > 300) {
- ic->private.local.brl_committing = ic->private.local.brl_pressed;
- ic->private.local.brl_release_start = ev->xkey.time;
- }
- ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1));
- if(!ic->private.local.brl_pressed && ic->private.local.brl_committing) {
- /* Commited a braille pattern, let it go through compose tree */
- keysym = XK_braille_blank | ic->private.local.brl_committing;
- ev->type = KeyPress;
- braille = True;
- } else {
- return(True);
- }
- }
- }
-
- if( (ev->type != KeyPress)
- || (((Xim)ic->core.im)->private.local.top == 0 ) )
- goto emit_braille;
-
- for(t = ic->private.local.context; t; t = b[t].next) {
- if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) &&
- (keysym == b[t].keysym))
- break;
- }
-
- if(t) { /* Matched */
- if(b[t].succession) { /* Intermediate */
- ic->private.local.context = b[t].succession;
- return(True);
- } else { /* Terminate (reached to leaf) */
- ic->private.local.composed = t;
- ic->private.local.brl_committed = 0;
- /* return back to client KeyPressEvent keycode == 0 */
- ev->xkey.keycode = 0;
- XPutBackEvent(d, ev);
- /* initialize internal state for next key sequence */
- ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
- return(True);
- }
- } else { /* Unmatched */
- if(ic->private.local.context == ((Xim)ic->core.im)->private.local.top) {
- goto emit_braille;
- }
- /* Error (Sequence Unmatch occured) */
- /* initialize internal state for next key sequence */
- ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
- return(True);
- }
-
-emit_braille:
- if(braille) {
- /* Braille pattern is not in compose tree, emit alone */
- ic->private.local.brl_committed = ic->private.local.brl_committing;
- ic->private.local.composed = 0;
- ev->xkey.keycode = 0;
- _XPutBackEvent(d, ev);
- return(True);
- }
- return(False);
-}
+/******************************************************************
+
+ Copyright 1992 by Fuji Xerox Co., Ltd.
+ Copyright 1992, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Fuji Xerox,
+FUJITSU LIMITED not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission. Fuji Xerox, FUJITSU LIMITED make no representations
+about the suitability of this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
+FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author : Kazunori Nishihara Fuji Xerox
+ Modifier : Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include <X11/keysym.h>
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Bool
+_XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
+{
+ Xic ic = (Xic)client_data;
+ KeySym keysym;
+ static char buf[256];
+ DefTree *b = ic->private.local.base.tree;
+ DTIndex t;
+ Bool braille = False;
+
+ if(ev->xkey.keycode == 0)
+ return (False);
+
+ XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL);
+
+ if(IsModifierKey(keysym))
+ return (False);
+
+ if(keysym >= XK_braille_dot_1 && keysym <= XK_braille_dot_8) {
+ if(ev->type == KeyPress) {
+ ic->private.local.brl_pressed |=
+ 1<<(keysym-XK_braille_dot_1);
+ return(True);
+ } else {
+ if(!ic->private.local.brl_committing
+ || ev->xkey.time - ic->private.local.brl_release_start > 300) {
+ ic->private.local.brl_committing = ic->private.local.brl_pressed;
+ ic->private.local.brl_release_start = ev->xkey.time;
+ }
+ ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1));
+ if(!ic->private.local.brl_pressed && ic->private.local.brl_committing) {
+ /* Commited a braille pattern, let it go through compose tree */
+ keysym = XK_braille_blank | ic->private.local.brl_committing;
+ ev->type = KeyPress;
+ braille = True;
+ } else {
+ return(True);
+ }
+ }
+ }
+
+ if( (ev->type != KeyPress)
+ || (((Xim)ic->core.im)->private.local.top == 0 ) )
+ goto emit_braille;
+
+ for(t = ic->private.local.context; t; t = b[t].next) {
+ if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) &&
+ (keysym == b[t].keysym))
+ break;
+ }
+
+ if(t) { /* Matched */
+ if(b[t].succession) { /* Intermediate */
+ ic->private.local.context = b[t].succession;
+ return(True);
+ } else { /* Terminate (reached to leaf) */
+ ic->private.local.composed = t;
+ ic->private.local.brl_committed = 0;
+ /* return back to client KeyPressEvent keycode == 0 */
+ ev->xkey.keycode = 0;
+ XPutBackEvent(d, ev);
+ /* initialize internal state for next key sequence */
+ ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
+ return(True);
+ }
+ } else { /* Unmatched */
+ if(ic->private.local.context == ((Xim)ic->core.im)->private.local.top) {
+ goto emit_braille;
+ }
+ /* Error (Sequence Unmatch occured) */
+ /* initialize internal state for next key sequence */
+ ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
+ return(True);
+ }
+
+emit_braille:
+ if(braille) {
+ /* Braille pattern is not in compose tree, emit alone */
+ ic->private.local.brl_committed = ic->private.local.brl_committing;
+ ic->private.local.composed = 0;
+ ev->xkey.keycode = 0;
+ _XPutBackEvent(d, ev);
+ return(True);
+ }
+ return(False);
+}
diff --git a/libX11/modules/im/ximcp/imLcIc.c b/libX11/modules/im/ximcp/imLcIc.c
index 5cdd7d59d..49338853c 100644
--- a/libX11/modules/im/ximcp/imLcIc.c
+++ b/libX11/modules/im/ximcp/imLcIc.c
@@ -1,199 +1,199 @@
-/******************************************************************
-
- Copyright 1992,1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <X11/Xlib.h>
-#include <X11/Xmd.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-Private void
-_XimLocalUnSetFocus(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
-
- if (ic->core.focus_window)
- _XUnregisterFilter(ic->core.im->core.display,
- ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
- return;
-}
-
-Private void
-_XimLocalDestroyIC(
- XIC xic)
-{
- Xic ic = (Xic)xic;
-
- if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
- ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
- }
- if (ic->core.focus_window)
- _XUnregisterFilter(ic->core.im->core.display,
- ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
- if(ic->private.local.ic_resources) {
- Xfree(ic->private.local.ic_resources);
- ic->private.local.ic_resources = NULL;
- }
- return;
-}
-
-Private void
-_XimLocalSetFocus(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
-
- if (current_ic == (XIC)ic)
- return;
-
- if (current_ic != (XIC)NULL) {
- _XimLocalUnSetFocus(current_ic);
- }
- ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
-
- if (ic->core.focus_window)
- _XRegisterFilterByType(ic->core.im->core.display,
- ic->core.focus_window, KeyPress, KeyRelease,
- _XimLocalFilter, (XPointer)ic);
- return;
-}
-
-Private void
-_XimLocalReset(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- ic->private.local.composed = 0;
- ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
- ic->private.local.brl_pressed = 0;
- ic->private.local.brl_committing = 0;
- ic->private.local.brl_committed = 0;
-}
-
-Private char *
-_XimLocalMbReset(
- XIC xic)
-{
- _XimLocalReset(xic);
- return (char *)NULL;
-}
-
-Private wchar_t *
-_XimLocalWcReset(
- XIC xic)
-{
- _XimLocalReset(xic);
- return (wchar_t *)NULL;
-}
-
-Private XICMethodsRec Local_ic_methods = {
- _XimLocalDestroyIC, /* destroy */
- _XimLocalSetFocus, /* set_focus */
- _XimLocalUnSetFocus, /* unset_focus */
- _XimLocalSetICValues, /* set_values */
- _XimLocalGetICValues, /* get_values */
- _XimLocalMbReset, /* mb_reset */
- _XimLocalWcReset, /* wc_reset */
- _XimLocalMbReset, /* utf8_reset */
- _XimLocalMbLookupString, /* mb_lookup_string */
- _XimLocalWcLookupString, /* wc_lookup_string */
- _XimLocalUtf8LookupString /* utf8_lookup_string */
-};
-
-Public XIC
-_XimLocalCreateIC(
- XIM im,
- XIMArg *values)
-{
- Xic ic;
- XimDefICValues ic_values;
- XIMResourceList res;
- unsigned int num;
- int len;
-
- if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
- return ((XIC)NULL);
- }
-
- ic->methods = &Local_ic_methods;
- ic->core.im = im;
- ic->private.local.base = ((Xim)im)->private.local.base;
- ic->private.local.context = ((Xim)im)->private.local.top;
- ic->private.local.composed = 0;
- ic->private.local.brl_pressed = 0;
- ic->private.local.brl_committing = 0;
- ic->private.local.brl_committed = 0;
-
- num = im->core.ic_num_resources;
- len = sizeof(XIMResource) * num;
- if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) {
- goto Set_Error;
- }
- (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
- ic->private.local.ic_resources = res;
- ic->private.local.ic_num_resources = num;
-
- bzero((char *)&ic_values, sizeof(XimDefICValues));
- if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
- im->core.styles, res, num) == False) {
- goto Set_Error;
- }
-
- _XimSetICMode(res, num, ic_values.input_style);
-
- if(_XimSetICValueData(ic, (XPointer)&ic_values,
- ic->private.local.ic_resources,
- ic->private.local.ic_num_resources,
- values, XIM_CREATEIC, True)) {
- goto Set_Error;
- }
- ic_values.filter_events = KeyPressMask | KeyReleaseMask;
- _XimSetCurrentICValues(ic, &ic_values);
- if(_XimSetICDefaults(ic, (XPointer)&ic_values,
- XIM_SETICDEFAULTS, res, num) == False) {
- goto Set_Error;
- }
- _XimSetCurrentICValues(ic, &ic_values);
-
- return((XIC)ic);
-
-Set_Error :
- if (ic->private.local.ic_resources) {
- Xfree(ic->private.local.ic_resources);
- ic->private.local.ic_resources = NULL;
- }
- Xfree(ic);
- return((XIC)NULL);
-}
+/******************************************************************
+
+ Copyright 1992,1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlib.h>
+#include <X11/Xmd.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Private void
+_XimLocalUnSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
+
+ if (ic->core.focus_window)
+ _XUnregisterFilter(ic->core.im->core.display,
+ ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
+ return;
+}
+
+Private void
+_XimLocalDestroyIC(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+
+ if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
+ }
+ if (ic->core.focus_window)
+ _XUnregisterFilter(ic->core.im->core.display,
+ ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
+ if(ic->private.local.ic_resources) {
+ Xfree(ic->private.local.ic_resources);
+ ic->private.local.ic_resources = NULL;
+ }
+ return;
+}
+
+Private void
+_XimLocalSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
+
+ if (current_ic == (XIC)ic)
+ return;
+
+ if (current_ic != (XIC)NULL) {
+ _XimLocalUnSetFocus(current_ic);
+ }
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
+
+ if (ic->core.focus_window)
+ _XRegisterFilterByType(ic->core.im->core.display,
+ ic->core.focus_window, KeyPress, KeyRelease,
+ _XimLocalFilter, (XPointer)ic);
+ return;
+}
+
+Private void
+_XimLocalReset(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ ic->private.local.composed = 0;
+ ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
+ ic->private.local.brl_pressed = 0;
+ ic->private.local.brl_committing = 0;
+ ic->private.local.brl_committed = 0;
+}
+
+Private char *
+_XimLocalMbReset(
+ XIC xic)
+{
+ _XimLocalReset(xic);
+ return (char *)NULL;
+}
+
+Private wchar_t *
+_XimLocalWcReset(
+ XIC xic)
+{
+ _XimLocalReset(xic);
+ return (wchar_t *)NULL;
+}
+
+Private XICMethodsRec Local_ic_methods = {
+ _XimLocalDestroyIC, /* destroy */
+ _XimLocalSetFocus, /* set_focus */
+ _XimLocalUnSetFocus, /* unset_focus */
+ _XimLocalSetICValues, /* set_values */
+ _XimLocalGetICValues, /* get_values */
+ _XimLocalMbReset, /* mb_reset */
+ _XimLocalWcReset, /* wc_reset */
+ _XimLocalMbReset, /* utf8_reset */
+ _XimLocalMbLookupString, /* mb_lookup_string */
+ _XimLocalWcLookupString, /* wc_lookup_string */
+ _XimLocalUtf8LookupString /* utf8_lookup_string */
+};
+
+Public XIC
+_XimLocalCreateIC(
+ XIM im,
+ XIMArg *values)
+{
+ Xic ic;
+ XimDefICValues ic_values;
+ XIMResourceList res;
+ unsigned int num;
+ int len;
+
+ if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
+ return ((XIC)NULL);
+ }
+
+ ic->methods = &Local_ic_methods;
+ ic->core.im = im;
+ ic->private.local.base = ((Xim)im)->private.local.base;
+ ic->private.local.context = ((Xim)im)->private.local.top;
+ ic->private.local.composed = 0;
+ ic->private.local.brl_pressed = 0;
+ ic->private.local.brl_committing = 0;
+ ic->private.local.brl_committed = 0;
+
+ num = im->core.ic_num_resources;
+ len = sizeof(XIMResource) * num;
+ if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) {
+ goto Set_Error;
+ }
+ (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
+ ic->private.local.ic_resources = res;
+ ic->private.local.ic_num_resources = num;
+
+ bzero((char *)&ic_values, sizeof(XimDefICValues));
+ if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
+ im->core.styles, res, num) == False) {
+ goto Set_Error;
+ }
+
+ _XimSetICMode(res, num, ic_values.input_style);
+
+ if(_XimSetICValueData(ic, (XPointer)&ic_values,
+ ic->private.local.ic_resources,
+ ic->private.local.ic_num_resources,
+ values, XIM_CREATEIC, True)) {
+ goto Set_Error;
+ }
+ ic_values.filter_events = KeyPressMask | KeyReleaseMask;
+ _XimSetCurrentICValues(ic, &ic_values);
+ if(_XimSetICDefaults(ic, (XPointer)&ic_values,
+ XIM_SETICDEFAULTS, res, num) == False) {
+ goto Set_Error;
+ }
+ _XimSetCurrentICValues(ic, &ic_values);
+
+ return((XIC)ic);
+
+Set_Error :
+ if (ic->private.local.ic_resources) {
+ Xfree(ic->private.local.ic_resources);
+ ic->private.local.ic_resources = NULL;
+ }
+ Xfree(ic);
+ return((XIC)NULL);
+}
diff --git a/libX11/modules/im/ximcp/imLcIm.c b/libX11/modules/im/ximcp/imLcIm.c
index 44516e9ee..904169830 100644
--- a/libX11/modules/im/ximcp/imLcIm.c
+++ b/libX11/modules/im/ximcp/imLcIm.c
@@ -1,732 +1,732 @@
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
- Copyright 1993 by Digital Equipment Corporation
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of FUJITSU LIMITED and
-Digital Equipment Corporation not be used in advertising or publicity
-pertaining to distribution of the software without specific, written
-prior permission. FUJITSU LIMITED and Digital Equipment Corporation
-makes no representations about the suitability of this software for
-any purpose. It is provided "as is" without express or implied
-warranty.
-
-FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
-ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
- Modifier: Franky Ling Digital Equipment Corporation
- frankyling@hgrd01.enet.dec.com
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-
-#include <X11/Xmd.h>
-#include <X11/Xatom.h>
-#include <X11/Xos.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcPublic.h"
-#include "XlcPubI.h"
-#include "Ximint.h"
-#include <ctype.h>
-#include <assert.h>
-
-#ifdef COMPOSECACHE
-# include <sys/types.h>
-# include <sys/stat.h>
-# include <sys/mman.h>
-# include <langinfo.h>
-#endif
-
-
-#ifdef COMPOSECACHE
-
-/* include trailing '/' for cache directory, file prefix otherwise */
-#define XIM_GLOBAL_CACHE_DIR "/var/cache/libx11/compose/"
-#define XIM_HOME_CACHE_DIR "/.compose-cache/"
-#define XIM_CACHE_MAGIC ('X' | 'i'<<8 | 'm'<<16 | 'C'<<24)
-#define XIM_CACHE_VERSION 4
-#define XIM_CACHE_TREE_ALIGNMENT 4
-
-#define XIM_HASH_PRIME_1 13
-#define XIM_HASH_PRIME_2 1234096939
-
-typedef INT32 DTStructIndex;
-struct _XimCacheStruct {
- INT32 id;
- INT32 version;
- DTStructIndex tree;
- DTStructIndex mb;
- DTStructIndex wc;
- DTStructIndex utf8;
- DTStructIndex size;
- DTIndex top;
- DTIndex treeused;
- DTCharIndex mbused;
- DTCharIndex wcused;
- DTCharIndex utf8used;
- char fname[1];
- /* char encoding[1] */
-};
-
-Private struct _XimCacheStruct* _XimCache_mmap = NULL;
-Private DefTreeBase _XimCachedDefaultTreeBase;
-Private int _XimCachedDefaultTreeRefcount = 0;
-
-#endif
-
-
-Public Bool
-_XimCheckIfLocalProcessing(Xim im)
-{
- FILE *fp;
- char *name;
-
- if(strcmp(im->core.im_name, "") == 0) {
- name = _XlcFileName(im->core.lcd, COMPOSE_FILE);
- if (name != (char *)NULL) {
- fp = _XFopenFile (name, "r");
- Xfree(name);
- if (fp != (FILE *)NULL) {
- fclose(fp);
- return(True);
- }
- }
- return(False);
- } else if(strcmp(im->core.im_name, "local") == 0 ||
- strcmp(im->core.im_name, "none" ) == 0 ) {
- return(True);
- }
- return(False);
-}
-
-Private void
-XimFreeDefaultTree(
- DefTreeBase *b)
-{
- if (!b) return;
- if (b->tree == NULL) return;
-#ifdef COMPOSECACHE
- if (b->tree == _XimCachedDefaultTreeBase.tree) {
- _XimCachedDefaultTreeRefcount--;
- /* No deleting, it's a cache after all. */
- return;
- }
-#endif
- Xfree (b->tree);
- if (b->mb) Xfree (b->mb);
- if (b->wc) Xfree (b->wc);
- if (b->utf8) Xfree (b->utf8);
- b->tree = NULL;
- b->mb = NULL;
- b->wc = NULL;
- b->utf8 = NULL;
- b->treeused = b->treesize = 0;
- b->mbused = b->mbsize = 0;
- b->wcused = b->wcsize = 0;
- b->utf8used = b->utf8size = 0;
-}
-
-Public void
-_XimLocalIMFree(
- Xim im)
-{
- XimFreeDefaultTree(&im->private.local.base);
- im->private.local.top = 0;
-
- if(im->core.im_resources) {
- Xfree(im->core.im_resources);
- im->core.im_resources = NULL;
- }
- if(im->core.ic_resources) {
- Xfree(im->core.ic_resources);
- im->core.ic_resources = NULL;
- }
- if(im->core.im_values_list) {
- Xfree(im->core.im_values_list);
- im->core.im_values_list = NULL;
- }
- if(im->core.ic_values_list) {
- Xfree(im->core.ic_values_list);
- im->core.ic_values_list = NULL;
- }
- if(im->core.styles) {
- Xfree(im->core.styles);
- im->core.styles = NULL;
- }
- if(im->core.res_name) {
- Xfree(im->core.res_name);
- im->core.res_name = NULL;
- }
- if(im->core.res_class) {
- Xfree(im->core.res_class);
- im->core.res_class = NULL;
- }
- if(im->core.im_name) {
- Xfree(im->core.im_name);
- im->core.im_name = NULL;
- }
- if (im->private.local.ctom_conv) {
- _XlcCloseConverter(im->private.local.ctom_conv);
- im->private.local.ctom_conv = NULL;
- }
- if (im->private.local.ctow_conv) {
- _XlcCloseConverter(im->private.local.ctow_conv);
- im->private.local.ctow_conv = NULL;
- }
- if (im->private.local.ctoutf8_conv) {
- _XlcCloseConverter(im->private.local.ctoutf8_conv);
- im->private.local.ctoutf8_conv = NULL;
- }
- if (im->private.local.cstomb_conv) {
- _XlcCloseConverter(im->private.local.cstomb_conv);
- im->private.local.cstomb_conv = NULL;
- }
- if (im->private.local.cstowc_conv) {
- _XlcCloseConverter(im->private.local.cstowc_conv);
- im->private.local.cstowc_conv = NULL;
- }
- if (im->private.local.cstoutf8_conv) {
- _XlcCloseConverter(im->private.local.cstoutf8_conv);
- im->private.local.cstoutf8_conv = NULL;
- }
- if (im->private.local.ucstoc_conv) {
- _XlcCloseConverter(im->private.local.ucstoc_conv);
- im->private.local.ucstoc_conv = NULL;
- }
- if (im->private.local.ucstoutf8_conv) {
- _XlcCloseConverter(im->private.local.ucstoutf8_conv);
- im->private.local.ucstoutf8_conv = NULL;
- }
- return;
-}
-
-Private Status
-_XimLocalCloseIM(
- XIM xim)
-{
- Xim im = (Xim)xim;
- XIC ic;
- XIC next;
-
- ic = im->core.ic_chain;
- im->core.ic_chain = NULL;
- while (ic) {
- (*ic->methods->destroy) (ic);
- next = ic->core.next;
- Xfree ((char *) ic);
- ic = next;
- }
- _XimLocalIMFree(im);
- _XimDestroyIMStructureList(im);
- return(True);
-}
-
-Public char *
-_XimLocalGetIMValues(
- XIM xim,
- XIMArg *values)
-{
- Xim im = (Xim)xim;
- XimDefIMValues im_values;
-
- _XimGetCurrentIMValues(im, &im_values);
- return(_XimGetIMValueData(im, (XPointer)&im_values, values,
- im->core.im_resources, im->core.im_num_resources));
-}
-
-Public char *
-_XimLocalSetIMValues(
- XIM xim,
- XIMArg *values)
-{
- Xim im = (Xim)xim;
- XimDefIMValues im_values;
- char *name = (char *)NULL;
-
- _XimGetCurrentIMValues(im, &im_values);
- name = _XimSetIMValueData(im, (XPointer)&im_values, values,
- im->core.im_resources, im->core.im_num_resources);
- _XimSetCurrentIMValues(im, &im_values);
- return(name);
-}
-
-
-#ifdef COMPOSECACHE
-
-Private Bool
-_XimReadCachedDefaultTree(
- int fd_cache,
- const char *name,
- const char *encoding,
- DTStructIndex size)
-{
- struct _XimCacheStruct* m;
- int namelen = strlen (name) + 1;
- int encodinglen = strlen (encoding) + 1;
-
- m = mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd_cache, 0);
- if (m == NULL || m == MAP_FAILED)
- return False;
- assert (m->id == XIM_CACHE_MAGIC);
- assert (m->version == XIM_CACHE_VERSION);
- if (size != m->size ||
- size < XOffsetOf (struct _XimCacheStruct, fname) + namelen + encodinglen) {
- fprintf (stderr, "Ignoring broken XimCache %s [%s]\n", name, encoding);
- munmap (m, size);
- return False;
- }
- if (strncmp (name, m->fname, namelen) != 0) {
- /* m->fname may *not* be terminated - but who cares here */
- fprintf (stderr, "Filename hash clash - expected %s, got %s\n",
- name, m->fname);
- munmap (m, size);
- return False;
- }
- if (strncmp (encoding, m->fname + namelen, encodinglen) != 0) {
- /* m->fname+namelen may *not* be terminated - but who cares here */
- fprintf (stderr, "Enoding hash clash - expected %s, got %s\n",
- encoding, m->fname + namelen);
- munmap (m, size);
- return False;
- }
- _XimCache_mmap = m;
- _XimCachedDefaultTreeBase.tree = (DefTree *) (((char *) m) + m->tree);
- _XimCachedDefaultTreeBase.mb = (((char *) m) + m->mb);
- _XimCachedDefaultTreeBase.wc = (wchar_t *) (((char *) m) + m->wc);
- _XimCachedDefaultTreeBase.utf8 = (((char *) m) + m->utf8);
- _XimCachedDefaultTreeBase.treeused = m->treeused;
- _XimCachedDefaultTreeBase.mbused = m->mbused;
- _XimCachedDefaultTreeBase.wcused = m->wcused;
- _XimCachedDefaultTreeBase.utf8used = m->utf8used;
- /* treesize etc. is ignored because only used during parsing */
- _XimCachedDefaultTreeRefcount = 0;
-/* fprintf (stderr, "read cached tree at %p: %s\n", (void *) m, name); */
- return True;
-}
-
-Private unsigned int strToHash (
- const char *name)
-{
- unsigned int hash = 0;
- while (*name)
- hash = hash * XIM_HASH_PRIME_1 + *(unsigned const char *)name++;
- return hash % XIM_HASH_PRIME_2;
-}
-
-
-/* Returns read-only fd of cache file, -1 if none.
- * Sets *res to cache filename if safe. Sets *size to file size of cache. */
-Private int _XimCachedFileName (
- const char *dir, const char *name,
- const char *intname, const char *encoding,
- uid_t uid, int isglobal, char **res, off_t *size)
-{
- struct stat st_name, st;
- int fd;
- unsigned int len, hash, hash2;
- struct _XimCacheStruct *m;
- /* There are some races here with 'dir', but we are either in our own home
- * or the global cache dir, and not inside some public writable dir */
-/* fprintf (stderr, "XimCachedFileName for dir %s name %s intname %s encoding %s uid %d\n", dir, name, intname, encoding, uid); */
- if (stat (name, &st_name) == -1 || ! S_ISREG (st_name.st_mode)
- || stat (dir, &st) == -1 || ! S_ISDIR (st.st_mode) || st.st_uid != uid
- || (st.st_mode & 0022) != 0000) {
- *res = NULL;
- return -1;
- }
- len = strlen (dir);
- hash = strToHash (intname);
- hash2 = strToHash (encoding);
- *res = Xmalloc (len + 1 + 27 + 1); /* Max VERSION 9999 */
-
- if (len == 0 || dir [len-1] != '/')
- sprintf (*res, "%s/%c%d_%03x_%08x_%08x", dir, _XimGetMyEndian(),
- XIM_CACHE_VERSION, (unsigned int)sizeof (DefTree), hash, hash2);
- else
- sprintf (*res, "%s%c%d_%03x_%08x_%08x", dir, _XimGetMyEndian(),
- XIM_CACHE_VERSION, (unsigned int)sizeof (DefTree), hash, hash2);
-
-/* fprintf (stderr, "-> %s\n", *res); */
- if ( (fd = _XOpenFile (*res, O_RDONLY)) == -1)
- return -1;
-
- if (fstat (fd, &st) == -1) {
- Xfree (*res);
- *res = NULL;
- close (fd);
- return -1;
- }
- *size = st.st_size;
-
- if (! S_ISREG (st.st_mode) || st.st_uid != uid
- || (st.st_mode & 0022) != 0000 || st.st_mtime <= st_name.st_mtime
- || (st.st_mtime < time (NULL) - 24*60*60 && ! isglobal)) {
-
- close (fd);
- if (unlink (*res) != 0) {
- Xfree (*res);
- *res = NULL; /* cache is not safe */
- }
- return -1;
- }
-
- m = mmap (NULL, sizeof (struct _XimCacheStruct), PROT_READ, MAP_PRIVATE,
- fd, 0);
- if (m == NULL || m == MAP_FAILED) {
- close (fd);
- Xfree (*res);
- *res = NULL;
- return -1;
- }
- if (*size < sizeof (struct _XimCacheStruct) || m->id != XIM_CACHE_MAGIC) {
- munmap (m, sizeof (struct _XimCacheStruct));
- close (fd);
- fprintf (stderr, "Ignoring broken XimCache %s\n", *res);
- Xfree (*res);
- *res = NULL;
- return -1;
- }
- if (m->version != XIM_CACHE_VERSION) {
- munmap (m, sizeof (struct _XimCacheStruct));
- close (fd);
- if (unlink (*res) != 0) {
- Xfree (*res);
- *res = NULL; /* cache is not safe */
- }
- return -1;
- }
- munmap (m, sizeof (struct _XimCacheStruct));
-
- return fd;
-}
-
-
-Private Bool _XimLoadCache (
- int fd,
- const char *name,
- const char *encoding,
- off_t size,
- Xim im)
-{
- if (_XimCache_mmap ||
- _XimReadCachedDefaultTree (fd, name, encoding, size)) {
- _XimCachedDefaultTreeRefcount++;
- memcpy (&im->private.local.base, &_XimCachedDefaultTreeBase,
- sizeof (_XimCachedDefaultTreeBase));
- im->private.local.top = _XimCache_mmap->top;
- return True;
- }
-
- return False;
-}
-
-
-Private void
-_XimWriteCachedDefaultTree(
- const char *name,
- const char *encoding,
- const char *cachename,
- Xim im)
-{
- int fd;
- FILE *fp;
- struct _XimCacheStruct *m;
- int msize = (XOffsetOf(struct _XimCacheStruct, fname)
- + strlen(name) + strlen(encoding) + 2
- + XIM_CACHE_TREE_ALIGNMENT-1) & -XIM_CACHE_TREE_ALIGNMENT;
- DefTreeBase *b = &im->private.local.base;
-
- if (! b->tree && ! (b->tree = Xmalloc (sizeof(DefTree))) )
- return;
- if (! b->mb && ! (b->mb = Xmalloc (1)) )
- return;
- if (! b->wc && ! (b->wc = Xmalloc (sizeof(wchar_t))) )
- return;
- if (! b->utf8 && ! (b->utf8 = Xmalloc (1)) )
- return;
-
- /* First entry is always unused */
- memset (b->tree, 0, sizeof(DefTree));
- b->mb[0] = 0;
- b->wc[0] = 0;
- b->utf8[0] = 0;
-
- m = Xmalloc (msize);
- memset (m, 0, msize);
- m->id = XIM_CACHE_MAGIC;
- m->version = XIM_CACHE_VERSION;
- m->top = im->private.local.top;
- m->treeused = b->treeused;
- m->mbused = b->mbused;
- m->wcused = b->wcused;
- m->utf8used = b->utf8used;
- /* Tree first, then wide chars, then the rest due to alignment */
- m->tree = msize;
- m->wc = msize + sizeof (DefTree) * m->treeused;
- m->mb = m->wc + sizeof (wchar_t) * m->wcused;
- m->utf8 = m->mb + m->mbused;
- m->size = m->utf8 + m->utf8used;
- strcpy (m->fname, name);
- strcpy (m->fname+strlen(name)+1, encoding);
-
- /* This STILL might be racy on NFS */
- if ( (fd = _XOpenFileMode (cachename, O_WRONLY | O_CREAT | O_EXCL,
- 0600)) < 0) {
- Xfree(m);
- return;
- }
- if (! (fp = fdopen (fd, "wb")) ) {
- close (fd);
- Xfree(m);
- return;
- }
- fwrite (m, msize, 1, fp);
- fwrite (im->private.local.base.tree, sizeof(DefTree), m->treeused, fp);
- fwrite (im->private.local.base.wc, sizeof(wchar_t), m->wcused, fp);
- fwrite (im->private.local.base.mb, 1, m->mbused, fp);
- fwrite (im->private.local.base.utf8, 1, m->utf8used, fp);
- if (fclose (fp) != 0)
- unlink (cachename);
- _XimCache_mmap = m;
- memcpy (&_XimCachedDefaultTreeBase, &im->private.local.base,
- sizeof (_XimCachedDefaultTreeBase));
-/* fprintf (stderr, "wrote tree %s size %ld to %s\n", name, m->size, cachename); */
-}
-
-#endif
-
-
-Private void
-_XimCreateDefaultTree(
- Xim im)
-{
- FILE *fp = NULL;
- char *name, *tmpname = NULL, *intname;
- char *cachename = NULL;
- /* Should use getpwent() instead of $HOME (cross-platform?) */
- char *home = getenv("HOME");
- char *cachedir = NULL;
- char *tmpcachedir = NULL;
- int hl = home ? strlen (home) : 0;
-#ifdef COMPOSECACHE
- const char *encoding = nl_langinfo (CODESET);
- uid_t euid = geteuid ();
- gid_t egid = getegid ();
- int cachefd = -1;
- off_t size;
-#endif
-
- name = getenv("XCOMPOSEFILE");
- if (name == (char *) NULL) {
- if (home != (char *) NULL) {
- tmpname = name = Xmalloc(hl + 10 + 1);
- if (name != (char *) NULL) {
- int fd;
- strcpy(name, home);
- strcpy(name + hl, "/.XCompose");
- if ( (fd = _XOpenFile (name, O_RDONLY)) < 0) {
- Xfree (name);
- name = tmpname = NULL;
- } else
- close (fd);
- }
- }
- }
-
- if (name == (char *) NULL) {
- tmpname = name = _XlcFileName(im->core.lcd, COMPOSE_FILE);
- }
- intname = name;
-
-#ifdef COMPOSECACHE
- if (getuid () == euid && getgid () == egid && euid != 0) {
- char *c;
- /* Usage: XCOMPOSECACHE=<cachedir>[=<filename>]
- * cachedir: directory of cache files
- * filename: internally used name for cache file */
- cachedir = getenv("XCOMPOSECACHE");
- if (cachedir && (c = strchr (cachedir, '='))) {
- tmpcachedir = strdup (cachedir);
- intname = tmpcachedir + (c-cachedir) + 1;
- tmpcachedir[c-cachedir] = '\0';
- cachedir = tmpcachedir;
- }
- }
-
- if (! cachedir) {
- cachefd = _XimCachedFileName (XIM_GLOBAL_CACHE_DIR, name, intname,
- encoding, 0, 1, &cachename, &size);
- if (cachefd != -1) {
- if (_XimLoadCache (cachefd, intname, encoding, size, im)) {
- if (tmpcachedir)
- Xfree (tmpcachedir);
- if (tmpname)
- Xfree (tmpname);
- if (cachename)
- Xfree (cachename);
- close (cachefd);
- return;
- }
- close (cachefd);
- }
- if (cachename)
- Xfree (cachename);
- cachename = NULL;
- }
-
- if (getuid () == euid && getgid () == egid && euid != 0 && home) {
-
- if (! cachedir) {
- tmpcachedir = cachedir = Xmalloc (hl+strlen(XIM_HOME_CACHE_DIR)+1);
- strcpy (cachedir, home);
- strcat (cachedir, XIM_HOME_CACHE_DIR);
- }
- cachefd = _XimCachedFileName (cachedir, name, intname, encoding,
- euid, 0, &cachename, &size);
- if (cachefd != -1) {
- if (_XimLoadCache (cachefd, intname, encoding, size, im)) {
- if (tmpcachedir)
- Xfree (tmpcachedir);
- if (tmpname)
- Xfree (tmpname);
- if (cachename)
- Xfree (cachename);
- close (cachefd);
- return;
- }
- close (cachefd);
- }
- }
-#endif
-
- if (! (fp = _XFopenFile (name, "r"))) {
- if (tmpcachedir)
- Xfree (tmpcachedir);
- if (tmpname)
- Xfree (tmpname);
- if (cachename)
- Xfree (cachename);
- return;
- }
- _XimParseStringFile(fp, im);
- fclose(fp);
-
-#ifdef COMPOSECACHE
- if (cachename) {
- assert (euid != 0);
- _XimWriteCachedDefaultTree (intname, encoding, cachename, im);
- }
-#endif
-
- if (tmpcachedir)
- Xfree (tmpcachedir);
- if (tmpname)
- Xfree (tmpname);
- if (cachename)
- Xfree (cachename);
-}
-
-Private XIMMethodsRec Xim_im_local_methods = {
- _XimLocalCloseIM, /* close */
- _XimLocalSetIMValues, /* set_values */
- _XimLocalGetIMValues, /* get_values */
- _XimLocalCreateIC, /* create_ic */
- _XimLcctstombs, /* ctstombs */
- _XimLcctstowcs, /* ctstowcs */
- _XimLcctstoutf8 /* ctstoutf8 */
-};
-
-Public Bool
-_XimLocalOpenIM(
- Xim im)
-{
- XLCd lcd = im->core.lcd;
- XlcConv conv;
- XimDefIMValues im_values;
- XimLocalPrivateRec* private = &im->private.local;
-
- _XimInitialResourceInfo();
- if(_XimSetIMResourceList(&im->core.im_resources,
- &im->core.im_num_resources) == False) {
- goto Open_Error;
- }
- if(_XimSetICResourceList(&im->core.ic_resources,
- &im->core.ic_num_resources) == False) {
- goto Open_Error;
- }
-
- _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
-
- _XimGetCurrentIMValues(im, &im_values);
- if(_XimSetLocalIMDefaults(im, (XPointer)&im_values,
- im->core.im_resources, im->core.im_num_resources) == False) {
- goto Open_Error;
- }
- _XimSetCurrentIMValues(im, &im_values);
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte)))
- goto Open_Error;
- private->ctom_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar)))
- goto Open_Error;
- private->ctow_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNUtf8String)))
- goto Open_Error;
- private->ctoutf8_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte)))
- goto Open_Error;
- private->cstomb_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar)))
- goto Open_Error;
- private->cstowc_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String)))
- goto Open_Error;
- private->cstoutf8_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar)))
- goto Open_Error;
- private->ucstoc_conv = conv;
-
- if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String)))
- goto Open_Error;
- private->ucstoutf8_conv = conv;
-
- private->base.treeused = 1;
- private->base.mbused = 1;
- private->base.wcused = 1;
- private->base.utf8used = 1;
-
- _XimCreateDefaultTree(im);
-
- im->methods = &Xim_im_local_methods;
- private->current_ic = (XIC)NULL;
-
- return(True);
-
-Open_Error :
- _XimLocalIMFree(im);
- return(False);
-}
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+ Copyright 1993 by Digital Equipment Corporation
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of FUJITSU LIMITED and
+Digital Equipment Corporation not be used in advertising or publicity
+pertaining to distribution of the software without specific, written
+prior permission. FUJITSU LIMITED and Digital Equipment Corporation
+makes no representations about the suitability of this software for
+any purpose. It is provided "as is" without express or implied
+warranty.
+
+FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
+ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+ Modifier: Franky Ling Digital Equipment Corporation
+ frankyling@hgrd01.enet.dec.com
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+
+#include <X11/Xmd.h>
+#include <X11/Xatom.h>
+#include <X11/Xos.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcPublic.h"
+#include "XlcPubI.h"
+#include "Ximint.h"
+#include <ctype.h>
+#include <assert.h>
+
+#ifdef COMPOSECACHE
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <sys/mman.h>
+# include <langinfo.h>
+#endif
+
+
+#ifdef COMPOSECACHE
+
+/* include trailing '/' for cache directory, file prefix otherwise */
+#define XIM_GLOBAL_CACHE_DIR "/var/cache/libx11/compose/"
+#define XIM_HOME_CACHE_DIR "/.compose-cache/"
+#define XIM_CACHE_MAGIC ('X' | 'i'<<8 | 'm'<<16 | 'C'<<24)
+#define XIM_CACHE_VERSION 4
+#define XIM_CACHE_TREE_ALIGNMENT 4
+
+#define XIM_HASH_PRIME_1 13
+#define XIM_HASH_PRIME_2 1234096939
+
+typedef INT32 DTStructIndex;
+struct _XimCacheStruct {
+ INT32 id;
+ INT32 version;
+ DTStructIndex tree;
+ DTStructIndex mb;
+ DTStructIndex wc;
+ DTStructIndex utf8;
+ DTStructIndex size;
+ DTIndex top;
+ DTIndex treeused;
+ DTCharIndex mbused;
+ DTCharIndex wcused;
+ DTCharIndex utf8used;
+ char fname[1];
+ /* char encoding[1] */
+};
+
+Private struct _XimCacheStruct* _XimCache_mmap = NULL;
+Private DefTreeBase _XimCachedDefaultTreeBase;
+Private int _XimCachedDefaultTreeRefcount = 0;
+
+#endif
+
+
+Public Bool
+_XimCheckIfLocalProcessing(Xim im)
+{
+ FILE *fp;
+ char *name;
+
+ if(strcmp(im->core.im_name, "") == 0) {
+ name = _XlcFileName(im->core.lcd, COMPOSE_FILE);
+ if (name != (char *)NULL) {
+ fp = _XFopenFile (name, "r");
+ Xfree(name);
+ if (fp != (FILE *)NULL) {
+ fclose(fp);
+ return(True);
+ }
+ }
+ return(False);
+ } else if(strcmp(im->core.im_name, "local") == 0 ||
+ strcmp(im->core.im_name, "none" ) == 0 ) {
+ return(True);
+ }
+ return(False);
+}
+
+Private void
+XimFreeDefaultTree(
+ DefTreeBase *b)
+{
+ if (!b) return;
+ if (b->tree == NULL) return;
+#ifdef COMPOSECACHE
+ if (b->tree == _XimCachedDefaultTreeBase.tree) {
+ _XimCachedDefaultTreeRefcount--;
+ /* No deleting, it's a cache after all. */
+ return;
+ }
+#endif
+ Xfree (b->tree);
+ if (b->mb) Xfree (b->mb);
+ if (b->wc) Xfree (b->wc);
+ if (b->utf8) Xfree (b->utf8);
+ b->tree = NULL;
+ b->mb = NULL;
+ b->wc = NULL;
+ b->utf8 = NULL;
+ b->treeused = b->treesize = 0;
+ b->mbused = b->mbsize = 0;
+ b->wcused = b->wcsize = 0;
+ b->utf8used = b->utf8size = 0;
+}
+
+Public void
+_XimLocalIMFree(
+ Xim im)
+{
+ XimFreeDefaultTree(&im->private.local.base);
+ im->private.local.top = 0;
+
+ if(im->core.im_resources) {
+ Xfree(im->core.im_resources);
+ im->core.im_resources = NULL;
+ }
+ if(im->core.ic_resources) {
+ Xfree(im->core.ic_resources);
+ im->core.ic_resources = NULL;
+ }
+ if(im->core.im_values_list) {
+ Xfree(im->core.im_values_list);
+ im->core.im_values_list = NULL;
+ }
+ if(im->core.ic_values_list) {
+ Xfree(im->core.ic_values_list);
+ im->core.ic_values_list = NULL;
+ }
+ if(im->core.styles) {
+ Xfree(im->core.styles);
+ im->core.styles = NULL;
+ }
+ if(im->core.res_name) {
+ Xfree(im->core.res_name);
+ im->core.res_name = NULL;
+ }
+ if(im->core.res_class) {
+ Xfree(im->core.res_class);
+ im->core.res_class = NULL;
+ }
+ if(im->core.im_name) {
+ Xfree(im->core.im_name);
+ im->core.im_name = NULL;
+ }
+ if (im->private.local.ctom_conv) {
+ _XlcCloseConverter(im->private.local.ctom_conv);
+ im->private.local.ctom_conv = NULL;
+ }
+ if (im->private.local.ctow_conv) {
+ _XlcCloseConverter(im->private.local.ctow_conv);
+ im->private.local.ctow_conv = NULL;
+ }
+ if (im->private.local.ctoutf8_conv) {
+ _XlcCloseConverter(im->private.local.ctoutf8_conv);
+ im->private.local.ctoutf8_conv = NULL;
+ }
+ if (im->private.local.cstomb_conv) {
+ _XlcCloseConverter(im->private.local.cstomb_conv);
+ im->private.local.cstomb_conv = NULL;
+ }
+ if (im->private.local.cstowc_conv) {
+ _XlcCloseConverter(im->private.local.cstowc_conv);
+ im->private.local.cstowc_conv = NULL;
+ }
+ if (im->private.local.cstoutf8_conv) {
+ _XlcCloseConverter(im->private.local.cstoutf8_conv);
+ im->private.local.cstoutf8_conv = NULL;
+ }
+ if (im->private.local.ucstoc_conv) {
+ _XlcCloseConverter(im->private.local.ucstoc_conv);
+ im->private.local.ucstoc_conv = NULL;
+ }
+ if (im->private.local.ucstoutf8_conv) {
+ _XlcCloseConverter(im->private.local.ucstoutf8_conv);
+ im->private.local.ucstoutf8_conv = NULL;
+ }
+ return;
+}
+
+Private Status
+_XimLocalCloseIM(
+ XIM xim)
+{
+ Xim im = (Xim)xim;
+ XIC ic;
+ XIC next;
+
+ ic = im->core.ic_chain;
+ im->core.ic_chain = NULL;
+ while (ic) {
+ (*ic->methods->destroy) (ic);
+ next = ic->core.next;
+ Xfree ((char *) ic);
+ ic = next;
+ }
+ _XimLocalIMFree(im);
+ _XimDestroyIMStructureList(im);
+ return(True);
+}
+
+Public char *
+_XimLocalGetIMValues(
+ XIM xim,
+ XIMArg *values)
+{
+ Xim im = (Xim)xim;
+ XimDefIMValues im_values;
+
+ _XimGetCurrentIMValues(im, &im_values);
+ return(_XimGetIMValueData(im, (XPointer)&im_values, values,
+ im->core.im_resources, im->core.im_num_resources));
+}
+
+Public char *
+_XimLocalSetIMValues(
+ XIM xim,
+ XIMArg *values)
+{
+ Xim im = (Xim)xim;
+ XimDefIMValues im_values;
+ char *name = (char *)NULL;
+
+ _XimGetCurrentIMValues(im, &im_values);
+ name = _XimSetIMValueData(im, (XPointer)&im_values, values,
+ im->core.im_resources, im->core.im_num_resources);
+ _XimSetCurrentIMValues(im, &im_values);
+ return(name);
+}
+
+
+#ifdef COMPOSECACHE
+
+Private Bool
+_XimReadCachedDefaultTree(
+ int fd_cache,
+ const char *name,
+ const char *encoding,
+ DTStructIndex size)
+{
+ struct _XimCacheStruct* m;
+ int namelen = strlen (name) + 1;
+ int encodinglen = strlen (encoding) + 1;
+
+ m = mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd_cache, 0);
+ if (m == NULL || m == MAP_FAILED)
+ return False;
+ assert (m->id == XIM_CACHE_MAGIC);
+ assert (m->version == XIM_CACHE_VERSION);
+ if (size != m->size ||
+ size < XOffsetOf (struct _XimCacheStruct, fname) + namelen + encodinglen) {
+ fprintf (stderr, "Ignoring broken XimCache %s [%s]\n", name, encoding);
+ munmap (m, size);
+ return False;
+ }
+ if (strncmp (name, m->fname, namelen) != 0) {
+ /* m->fname may *not* be terminated - but who cares here */
+ fprintf (stderr, "Filename hash clash - expected %s, got %s\n",
+ name, m->fname);
+ munmap (m, size);
+ return False;
+ }
+ if (strncmp (encoding, m->fname + namelen, encodinglen) != 0) {
+ /* m->fname+namelen may *not* be terminated - but who cares here */
+ fprintf (stderr, "Enoding hash clash - expected %s, got %s\n",
+ encoding, m->fname + namelen);
+ munmap (m, size);
+ return False;
+ }
+ _XimCache_mmap = m;
+ _XimCachedDefaultTreeBase.tree = (DefTree *) (((char *) m) + m->tree);
+ _XimCachedDefaultTreeBase.mb = (((char *) m) + m->mb);
+ _XimCachedDefaultTreeBase.wc = (wchar_t *) (((char *) m) + m->wc);
+ _XimCachedDefaultTreeBase.utf8 = (((char *) m) + m->utf8);
+ _XimCachedDefaultTreeBase.treeused = m->treeused;
+ _XimCachedDefaultTreeBase.mbused = m->mbused;
+ _XimCachedDefaultTreeBase.wcused = m->wcused;
+ _XimCachedDefaultTreeBase.utf8used = m->utf8used;
+ /* treesize etc. is ignored because only used during parsing */
+ _XimCachedDefaultTreeRefcount = 0;
+/* fprintf (stderr, "read cached tree at %p: %s\n", (void *) m, name); */
+ return True;
+}
+
+Private unsigned int strToHash (
+ const char *name)
+{
+ unsigned int hash = 0;
+ while (*name)
+ hash = hash * XIM_HASH_PRIME_1 + *(unsigned const char *)name++;
+ return hash % XIM_HASH_PRIME_2;
+}
+
+
+/* Returns read-only fd of cache file, -1 if none.
+ * Sets *res to cache filename if safe. Sets *size to file size of cache. */
+Private int _XimCachedFileName (
+ const char *dir, const char *name,
+ const char *intname, const char *encoding,
+ uid_t uid, int isglobal, char **res, off_t *size)
+{
+ struct stat st_name, st;
+ int fd;
+ unsigned int len, hash, hash2;
+ struct _XimCacheStruct *m;
+ /* There are some races here with 'dir', but we are either in our own home
+ * or the global cache dir, and not inside some public writable dir */
+/* fprintf (stderr, "XimCachedFileName for dir %s name %s intname %s encoding %s uid %d\n", dir, name, intname, encoding, uid); */
+ if (stat (name, &st_name) == -1 || ! S_ISREG (st_name.st_mode)
+ || stat (dir, &st) == -1 || ! S_ISDIR (st.st_mode) || st.st_uid != uid
+ || (st.st_mode & 0022) != 0000) {
+ *res = NULL;
+ return -1;
+ }
+ len = strlen (dir);
+ hash = strToHash (intname);
+ hash2 = strToHash (encoding);
+ *res = Xmalloc (len + 1 + 27 + 1); /* Max VERSION 9999 */
+
+ if (len == 0 || dir [len-1] != '/')
+ sprintf (*res, "%s/%c%d_%03x_%08x_%08x", dir, _XimGetMyEndian(),
+ XIM_CACHE_VERSION, (unsigned int)sizeof (DefTree), hash, hash2);
+ else
+ sprintf (*res, "%s%c%d_%03x_%08x_%08x", dir, _XimGetMyEndian(),
+ XIM_CACHE_VERSION, (unsigned int)sizeof (DefTree), hash, hash2);
+
+/* fprintf (stderr, "-> %s\n", *res); */
+ if ( (fd = _XOpenFile (*res, O_RDONLY)) == -1)
+ return -1;
+
+ if (fstat (fd, &st) == -1) {
+ Xfree (*res);
+ *res = NULL;
+ close (fd);
+ return -1;
+ }
+ *size = st.st_size;
+
+ if (! S_ISREG (st.st_mode) || st.st_uid != uid
+ || (st.st_mode & 0022) != 0000 || st.st_mtime <= st_name.st_mtime
+ || (st.st_mtime < time (NULL) - 24*60*60 && ! isglobal)) {
+
+ close (fd);
+ if (unlink (*res) != 0) {
+ Xfree (*res);
+ *res = NULL; /* cache is not safe */
+ }
+ return -1;
+ }
+
+ m = mmap (NULL, sizeof (struct _XimCacheStruct), PROT_READ, MAP_PRIVATE,
+ fd, 0);
+ if (m == NULL || m == MAP_FAILED) {
+ close (fd);
+ Xfree (*res);
+ *res = NULL;
+ return -1;
+ }
+ if (*size < sizeof (struct _XimCacheStruct) || m->id != XIM_CACHE_MAGIC) {
+ munmap (m, sizeof (struct _XimCacheStruct));
+ close (fd);
+ fprintf (stderr, "Ignoring broken XimCache %s\n", *res);
+ Xfree (*res);
+ *res = NULL;
+ return -1;
+ }
+ if (m->version != XIM_CACHE_VERSION) {
+ munmap (m, sizeof (struct _XimCacheStruct));
+ close (fd);
+ if (unlink (*res) != 0) {
+ Xfree (*res);
+ *res = NULL; /* cache is not safe */
+ }
+ return -1;
+ }
+ munmap (m, sizeof (struct _XimCacheStruct));
+
+ return fd;
+}
+
+
+Private Bool _XimLoadCache (
+ int fd,
+ const char *name,
+ const char *encoding,
+ off_t size,
+ Xim im)
+{
+ if (_XimCache_mmap ||
+ _XimReadCachedDefaultTree (fd, name, encoding, size)) {
+ _XimCachedDefaultTreeRefcount++;
+ memcpy (&im->private.local.base, &_XimCachedDefaultTreeBase,
+ sizeof (_XimCachedDefaultTreeBase));
+ im->private.local.top = _XimCache_mmap->top;
+ return True;
+ }
+
+ return False;
+}
+
+
+Private void
+_XimWriteCachedDefaultTree(
+ const char *name,
+ const char *encoding,
+ const char *cachename,
+ Xim im)
+{
+ int fd;
+ FILE *fp;
+ struct _XimCacheStruct *m;
+ int msize = (XOffsetOf(struct _XimCacheStruct, fname)
+ + strlen(name) + strlen(encoding) + 2
+ + XIM_CACHE_TREE_ALIGNMENT-1) & -XIM_CACHE_TREE_ALIGNMENT;
+ DefTreeBase *b = &im->private.local.base;
+
+ if (! b->tree && ! (b->tree = Xmalloc (sizeof(DefTree))) )
+ return;
+ if (! b->mb && ! (b->mb = Xmalloc (1)) )
+ return;
+ if (! b->wc && ! (b->wc = Xmalloc (sizeof(wchar_t))) )
+ return;
+ if (! b->utf8 && ! (b->utf8 = Xmalloc (1)) )
+ return;
+
+ /* First entry is always unused */
+ memset (b->tree, 0, sizeof(DefTree));
+ b->mb[0] = 0;
+ b->wc[0] = 0;
+ b->utf8[0] = 0;
+
+ m = Xmalloc (msize);
+ memset (m, 0, msize);
+ m->id = XIM_CACHE_MAGIC;
+ m->version = XIM_CACHE_VERSION;
+ m->top = im->private.local.top;
+ m->treeused = b->treeused;
+ m->mbused = b->mbused;
+ m->wcused = b->wcused;
+ m->utf8used = b->utf8used;
+ /* Tree first, then wide chars, then the rest due to alignment */
+ m->tree = msize;
+ m->wc = msize + sizeof (DefTree) * m->treeused;
+ m->mb = m->wc + sizeof (wchar_t) * m->wcused;
+ m->utf8 = m->mb + m->mbused;
+ m->size = m->utf8 + m->utf8used;
+ strcpy (m->fname, name);
+ strcpy (m->fname+strlen(name)+1, encoding);
+
+ /* This STILL might be racy on NFS */
+ if ( (fd = _XOpenFileMode (cachename, O_WRONLY | O_CREAT | O_EXCL,
+ 0600)) < 0) {
+ Xfree(m);
+ return;
+ }
+ if (! (fp = fdopen (fd, "wb")) ) {
+ close (fd);
+ Xfree(m);
+ return;
+ }
+ fwrite (m, msize, 1, fp);
+ fwrite (im->private.local.base.tree, sizeof(DefTree), m->treeused, fp);
+ fwrite (im->private.local.base.wc, sizeof(wchar_t), m->wcused, fp);
+ fwrite (im->private.local.base.mb, 1, m->mbused, fp);
+ fwrite (im->private.local.base.utf8, 1, m->utf8used, fp);
+ if (fclose (fp) != 0)
+ unlink (cachename);
+ _XimCache_mmap = m;
+ memcpy (&_XimCachedDefaultTreeBase, &im->private.local.base,
+ sizeof (_XimCachedDefaultTreeBase));
+/* fprintf (stderr, "wrote tree %s size %ld to %s\n", name, m->size, cachename); */
+}
+
+#endif
+
+
+Private void
+_XimCreateDefaultTree(
+ Xim im)
+{
+ FILE *fp = NULL;
+ char *name, *tmpname = NULL, *intname;
+ char *cachename = NULL;
+ /* Should use getpwent() instead of $HOME (cross-platform?) */
+ char *home = getenv("HOME");
+ char *cachedir = NULL;
+ char *tmpcachedir = NULL;
+ int hl = home ? strlen (home) : 0;
+#ifdef COMPOSECACHE
+ const char *encoding = nl_langinfo (CODESET);
+ uid_t euid = geteuid ();
+ gid_t egid = getegid ();
+ int cachefd = -1;
+ off_t size;
+#endif
+
+ name = getenv("XCOMPOSEFILE");
+ if (name == (char *) NULL) {
+ if (home != (char *) NULL) {
+ tmpname = name = Xmalloc(hl + 10 + 1);
+ if (name != (char *) NULL) {
+ int fd;
+ strcpy(name, home);
+ strcpy(name + hl, "/.XCompose");
+ if ( (fd = _XOpenFile (name, O_RDONLY)) < 0) {
+ Xfree (name);
+ name = tmpname = NULL;
+ } else
+ close (fd);
+ }
+ }
+ }
+
+ if (name == (char *) NULL) {
+ tmpname = name = _XlcFileName(im->core.lcd, COMPOSE_FILE);
+ }
+ intname = name;
+
+#ifdef COMPOSECACHE
+ if (getuid () == euid && getgid () == egid && euid != 0) {
+ char *c;
+ /* Usage: XCOMPOSECACHE=<cachedir>[=<filename>]
+ * cachedir: directory of cache files
+ * filename: internally used name for cache file */
+ cachedir = getenv("XCOMPOSECACHE");
+ if (cachedir && (c = strchr (cachedir, '='))) {
+ tmpcachedir = strdup (cachedir);
+ intname = tmpcachedir + (c-cachedir) + 1;
+ tmpcachedir[c-cachedir] = '\0';
+ cachedir = tmpcachedir;
+ }
+ }
+
+ if (! cachedir) {
+ cachefd = _XimCachedFileName (XIM_GLOBAL_CACHE_DIR, name, intname,
+ encoding, 0, 1, &cachename, &size);
+ if (cachefd != -1) {
+ if (_XimLoadCache (cachefd, intname, encoding, size, im)) {
+ if (tmpcachedir)
+ Xfree (tmpcachedir);
+ if (tmpname)
+ Xfree (tmpname);
+ if (cachename)
+ Xfree (cachename);
+ close (cachefd);
+ return;
+ }
+ close (cachefd);
+ }
+ if (cachename)
+ Xfree (cachename);
+ cachename = NULL;
+ }
+
+ if (getuid () == euid && getgid () == egid && euid != 0 && home) {
+
+ if (! cachedir) {
+ tmpcachedir = cachedir = Xmalloc (hl+strlen(XIM_HOME_CACHE_DIR)+1);
+ strcpy (cachedir, home);
+ strcat (cachedir, XIM_HOME_CACHE_DIR);
+ }
+ cachefd = _XimCachedFileName (cachedir, name, intname, encoding,
+ euid, 0, &cachename, &size);
+ if (cachefd != -1) {
+ if (_XimLoadCache (cachefd, intname, encoding, size, im)) {
+ if (tmpcachedir)
+ Xfree (tmpcachedir);
+ if (tmpname)
+ Xfree (tmpname);
+ if (cachename)
+ Xfree (cachename);
+ close (cachefd);
+ return;
+ }
+ close (cachefd);
+ }
+ }
+#endif
+
+ if (! (fp = _XFopenFile (name, "r"))) {
+ if (tmpcachedir)
+ Xfree (tmpcachedir);
+ if (tmpname)
+ Xfree (tmpname);
+ if (cachename)
+ Xfree (cachename);
+ return;
+ }
+ _XimParseStringFile(fp, im);
+ fclose(fp);
+
+#ifdef COMPOSECACHE
+ if (cachename) {
+ assert (euid != 0);
+ _XimWriteCachedDefaultTree (intname, encoding, cachename, im);
+ }
+#endif
+
+ if (tmpcachedir)
+ Xfree (tmpcachedir);
+ if (tmpname)
+ Xfree (tmpname);
+ if (cachename)
+ Xfree (cachename);
+}
+
+Private XIMMethodsRec Xim_im_local_methods = {
+ _XimLocalCloseIM, /* close */
+ _XimLocalSetIMValues, /* set_values */
+ _XimLocalGetIMValues, /* get_values */
+ _XimLocalCreateIC, /* create_ic */
+ _XimLcctstombs, /* ctstombs */
+ _XimLcctstowcs, /* ctstowcs */
+ _XimLcctstoutf8 /* ctstoutf8 */
+};
+
+Public Bool
+_XimLocalOpenIM(
+ Xim im)
+{
+ XLCd lcd = im->core.lcd;
+ XlcConv conv;
+ XimDefIMValues im_values;
+ XimLocalPrivateRec* private = &im->private.local;
+
+ _XimInitialResourceInfo();
+ if(_XimSetIMResourceList(&im->core.im_resources,
+ &im->core.im_num_resources) == False) {
+ goto Open_Error;
+ }
+ if(_XimSetICResourceList(&im->core.ic_resources,
+ &im->core.ic_num_resources) == False) {
+ goto Open_Error;
+ }
+
+ _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
+
+ _XimGetCurrentIMValues(im, &im_values);
+ if(_XimSetLocalIMDefaults(im, (XPointer)&im_values,
+ im->core.im_resources, im->core.im_num_resources) == False) {
+ goto Open_Error;
+ }
+ _XimSetCurrentIMValues(im, &im_values);
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte)))
+ goto Open_Error;
+ private->ctom_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar)))
+ goto Open_Error;
+ private->ctow_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNUtf8String)))
+ goto Open_Error;
+ private->ctoutf8_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte)))
+ goto Open_Error;
+ private->cstomb_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar)))
+ goto Open_Error;
+ private->cstowc_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String)))
+ goto Open_Error;
+ private->cstoutf8_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar)))
+ goto Open_Error;
+ private->ucstoc_conv = conv;
+
+ if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String)))
+ goto Open_Error;
+ private->ucstoutf8_conv = conv;
+
+ private->base.treeused = 1;
+ private->base.mbused = 1;
+ private->base.wcused = 1;
+ private->base.utf8used = 1;
+
+ _XimCreateDefaultTree(im);
+
+ im->methods = &Xim_im_local_methods;
+ private->current_ic = (XIC)NULL;
+
+ return(True);
+
+Open_Error :
+ _XimLocalIMFree(im);
+ return(False);
+}
diff --git a/libX11/modules/im/ximcp/imLcLkup.c b/libX11/modules/im/ximcp/imLcLkup.c
index c62a9106c..ad96ea25c 100644
--- a/libX11/modules/im/ximcp/imLcLkup.c
+++ b/libX11/modules/im/ximcp/imLcLkup.c
@@ -1,417 +1,417 @@
-/******************************************************************
-
- Copyright 1992 by Fuji Xerox Co., Ltd.
- Copyright 1992, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Fuji Xerox,
-FUJITSU LIMITED not be used in advertising or publicity pertaining
-to distribution of the software without specific, written prior
-permission. Fuji Xerox, FUJITSU LIMITED make no representations
-about the suitability of this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
-FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
-OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Kazunori Nishihara Fuji Xerox
- Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <X11/Xatom.h>
-#include <X11/Xos.h>
-#include <X11/Xlib.h>
-#include <X11/keysym.h>
-#include <X11/Xutil.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcPubI.h"
-#include "Ximint.h"
-
-Public int
-_XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
- KeySym *keysym, Status *status)
-{
- Xic ic = (Xic)xic;
- int ret;
- DefTree *b = ic->private.local.base.tree;
- char *mb = ic->private.local.base.mb;
-
- if(ev->type != KeyPress) {
- if(status) *status = XLookupNone;
- return(0);
- }
- if(ev->keycode == 0 &&
- ( (ic->private.local.composed != 0)
- ||(ic->private.local.brl_committed != 0))) {
- if (ic->private.local.brl_committed != 0) { /* Braille Event */
- unsigned char pattern = ic->private.local.brl_committed;
- char *mb=alloca(XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max));
- ret = _Xlcwctomb(ic->core.im->core.lcd, mb, BRL_UC_ROW | pattern);
- if(ret > bytes) {
- if(status) *status = XBufferOverflow;
- return(ret);
- }
- if(keysym) *keysym = XK_braille_blank | pattern;
- if(ret > 0) {
- if (keysym) {
- if(status) *status = XLookupBoth;
- } else {
- if(status) *status = XLookupChars;
- }
- memcpy(buffer, mb, ret);
- } else {
- if(keysym) {
- if(status) *status = XLookupKeySym;
- } else {
- if(status) *status = XLookupNone;
- }
- }
- } else { /* Composed Event */
- ret = strlen(&mb[b[ic->private.local.composed].mb]);
- if(ret > bytes) {
- if(status) *status = XBufferOverflow;
- return(ret);
- }
- memcpy(buffer, &mb[b[ic->private.local.composed].mb], ret);
- if(keysym) *keysym = b[ic->private.local.composed].ks;
- if (ret > 0) {
- if (keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupBoth;
- } else {
- if(status) *status = XLookupChars;
- }
- } else {
- if(keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupKeySym;
- } else {
- if(status) *status = XLookupNone;
- }
- }
- }
- return (ret);
- } else { /* Throughed Event */
- ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
- if(ret > 0) {
- if (ret > bytes) {
- if (status) *status = XBufferOverflow;
- } else if (keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupBoth;
- } else {
- if(status) *status = XLookupChars;
- }
- } else {
- if(keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupKeySym;
- } else {
- if(status) *status = XLookupNone;
- }
- }
- }
- return (ret);
-}
-
-Public int
-_XimLocalWcLookupString(XIC xic, XKeyEvent *ev, wchar_t *buffer, int wlen,
- KeySym *keysym, Status *status)
-{
- Xic ic = (Xic)xic;
- int ret;
- DefTree *b = ic->private.local.base.tree;
- wchar_t *wc = ic->private.local.base.wc;
-
- if(ev->type != KeyPress) {
- if(status) *status = XLookupNone;
- return(0);
- }
- if(ev->keycode == 0) {
- if (ic->private.local.brl_committed != 0) { /* Braille Event */
- unsigned char pattern = ic->private.local.brl_committed;
- ret = 1;
- if (ret > wlen) {
- if(status) *status = XBufferOverflow;
- return (ret);
- }
- *buffer = BRL_UC_ROW | pattern;
- if(keysym) {
- *keysym = XK_braille_blank | pattern;
- if(status) *status = XLookupBoth;
- } else
- if(status) *status = XLookupChars;
- } else { /* Composed Event */
- ret = _Xwcslen(&wc[b[ic->private.local.composed].wc]);
- if(ret > wlen) {
- if(status) *status = XBufferOverflow;
- return (ret);
- }
- memcpy((char *)buffer, (char *)&wc[b[ic->private.local.composed].wc],
- ret * sizeof(wchar_t));
- if(keysym) *keysym = b[ic->private.local.composed].ks;
- if (ret > 0) {
- if (keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupBoth;
- } else {
- if(status) *status = XLookupChars;
- }
- } else {
- if(keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupKeySym;
- } else {
- if(status) *status = XLookupNone;
- }
- }
- }
- return (ret);
- } else { /* Throughed Event */
- ret = _XimLookupWCText(ic, ev, buffer, wlen, keysym, NULL);
- if(ret > 0) {
- if (ret > wlen) {
- if (status) *status = XBufferOverflow;
- } else if (keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupBoth;
- } else {
- if(status) *status = XLookupChars;
- }
- } else {
- if(keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupKeySym;
- } else {
- if(status) *status = XLookupNone;
- }
- }
- }
- return (ret);
-}
-
-Public int
-_XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
- KeySym *keysym, Status *status)
-{
- Xic ic = (Xic)xic;
- int ret;
- DefTree *b = ic->private.local.base.tree;
- char *utf8 = ic->private.local.base.utf8;
-
- if(ev->type != KeyPress) {
- if(status) *status = XLookupNone;
- return(0);
- }
- if(ev->keycode == 0) {
- if (ic->private.local.brl_committed != 0) { /* Braille Event */
- unsigned char pattern = ic->private.local.brl_committed;
- ret = 3;
- if (ret > bytes) {
- if(status) *status = XBufferOverflow;
- return (ret);
- }
- buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f);
- buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6);
- buffer[2] = 0x80 | (pattern & 0x3f);
- if(keysym) {
- *keysym = XK_braille_blank | pattern;
- if(status) *status = XLookupBoth;
- } else
- if(status) *status = XLookupChars;
- } else { /* Composed Event */
- ret = strlen(&utf8[b[ic->private.local.composed].utf8]);
- if(ret > bytes) {
- if(status) *status = XBufferOverflow;
- return (ret);
- }
- memcpy(buffer, &utf8[b[ic->private.local.composed].utf8], ret);
- if(keysym) *keysym = b[ic->private.local.composed].ks;
- if (ret > 0) {
- if (keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupBoth;
- } else {
- if(status) *status = XLookupChars;
- }
- } else {
- if(keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupKeySym;
- } else {
- if(status) *status = XLookupNone;
- }
- }
- }
- return (ret);
- } else { /* Throughed Event */
- ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);
- if(ret > 0) {
- if (ret > bytes) {
- if (status) *status = XBufferOverflow;
- } else if (keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupBoth;
- } else {
- if(status) *status = XLookupChars;
- }
- } else {
- if(keysym && *keysym != NoSymbol) {
- if(status) *status = XLookupKeySym;
- } else {
- if(status) *status = XLookupNone;
- }
- }
- }
- return (ret);
-}
-
-Private int
-_XimLcctsconvert(
- XlcConv conv,
- char *from,
- int from_len,
- char *to,
- int to_len,
- Status *state)
-{
- int from_left;
- int to_left;
- int from_savelen;
- int to_savelen;
- int from_cnvlen;
- int to_cnvlen;
- char *from_buf;
- char *to_buf;
- char scratchbuf[BUFSIZ];
- Status tmp_state;
-
- if (!state)
- state = &tmp_state;
-
- if (!conv || !from || !from_len) {
- *state = XLookupNone;
- return 0;
- }
-
- /* Reset the converter. The CompoundText at 'from' starts in
- initial state. */
- _XlcResetConverter(conv);
-
- from_left = from_len;
- to_left = BUFSIZ;
- from_cnvlen = 0;
- to_cnvlen = 0;
- for (;;) {
- from_buf = &from[from_cnvlen];
- from_savelen = from_left;
- to_buf = &scratchbuf[to_cnvlen];
- to_savelen = to_left;
- if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
- (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
- *state = XLookupNone;
- return 0;
- }
- from_cnvlen += (from_savelen - from_left);
- to_cnvlen += (to_savelen - to_left);
- if (from_left == 0) {
- if (!to_cnvlen) {
- *state = XLookupNone;
- return 0;
- }
- break;
- }
- }
-
- if (!to || !to_len || (to_len < to_cnvlen)) {
- *state = XBufferOverflow;
- } else {
- memcpy(to, scratchbuf, to_cnvlen);
- *state = XLookupChars;
- }
- return to_cnvlen;
-}
-
-Public int
-_XimLcctstombs(XIM xim, char *from, int from_len,
- char *to, int to_len, Status *state)
-{
- return _XimLcctsconvert(((Xim)xim)->private.local.ctom_conv,
- from, from_len, to, to_len, state);
-}
-
-Public int
-_XimLcctstowcs(XIM xim, char *from, int from_len,
- wchar_t *to, int to_len, Status *state)
-{
- Xim im = (Xim)xim;
- XlcConv conv = im->private.local.ctow_conv;
- int from_left;
- int to_left;
- int from_savelen;
- int to_savelen;
- int from_cnvlen;
- int to_cnvlen;
- char *from_buf;
- wchar_t *to_buf;
- wchar_t scratchbuf[BUFSIZ];
- Status tmp_state;
-
- if (!state)
- state = &tmp_state;
-
- if (!conv || !from || !from_len) {
- *state = XLookupNone;
- return 0;
- }
-
- /* Reset the converter. The CompoundText at 'from' starts in
- initial state. */
- _XlcResetConverter(conv);
-
- from_left = from_len;
- to_left = BUFSIZ;
- from_cnvlen = 0;
- to_cnvlen = 0;
- for (;;) {
- from_buf = &from[from_cnvlen];
- from_savelen = from_left;
- to_buf = &scratchbuf[to_cnvlen];
- to_savelen = to_left;
- if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
- (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
- *state = XLookupNone;
- return 0;
- }
- from_cnvlen += (from_savelen - from_left);
- to_cnvlen += (to_savelen - to_left);
- if (from_left == 0) {
- if (!to_cnvlen){
- *state = XLookupNone;
- return 0;
- }
- break;
- }
- }
-
- if (!to || !to_len || (to_len < to_cnvlen)) {
- *state = XBufferOverflow;
- } else {
- memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t));
- *state = XLookupChars;
- }
- return to_cnvlen;
-}
-
-Public int
-_XimLcctstoutf8(XIM xim, char *from, int from_len,
- char *to, int to_len, Status *state)
-{
- return _XimLcctsconvert(((Xim)xim)->private.local.ctoutf8_conv,
- from, from_len, to, to_len, state);
-}
+/******************************************************************
+
+ Copyright 1992 by Fuji Xerox Co., Ltd.
+ Copyright 1992, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Fuji Xerox,
+FUJITSU LIMITED not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission. Fuji Xerox, FUJITSU LIMITED make no representations
+about the suitability of this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
+FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Kazunori Nishihara Fuji Xerox
+ Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xatom.h>
+#include <X11/Xos.h>
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#include <X11/Xutil.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcPubI.h"
+#include "Ximint.h"
+
+Public int
+_XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
+ KeySym *keysym, Status *status)
+{
+ Xic ic = (Xic)xic;
+ int ret;
+ DefTree *b = ic->private.local.base.tree;
+ char *mb = ic->private.local.base.mb;
+
+ if(ev->type != KeyPress) {
+ if(status) *status = XLookupNone;
+ return(0);
+ }
+ if(ev->keycode == 0 &&
+ ( (ic->private.local.composed != 0)
+ ||(ic->private.local.brl_committed != 0))) {
+ if (ic->private.local.brl_committed != 0) { /* Braille Event */
+ unsigned char pattern = ic->private.local.brl_committed;
+ char *mb=alloca(XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max));
+ ret = _Xlcwctomb(ic->core.im->core.lcd, mb, BRL_UC_ROW | pattern);
+ if(ret > bytes) {
+ if(status) *status = XBufferOverflow;
+ return(ret);
+ }
+ if(keysym) *keysym = XK_braille_blank | pattern;
+ if(ret > 0) {
+ if (keysym) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ memcpy(buffer, mb, ret);
+ } else {
+ if(keysym) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ } else { /* Composed Event */
+ ret = strlen(&mb[b[ic->private.local.composed].mb]);
+ if(ret > bytes) {
+ if(status) *status = XBufferOverflow;
+ return(ret);
+ }
+ memcpy(buffer, &mb[b[ic->private.local.composed].mb], ret);
+ if(keysym) *keysym = b[ic->private.local.composed].ks;
+ if (ret > 0) {
+ if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+ } else { /* Throughed Event */
+ ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
+ if(ret > 0) {
+ if (ret > bytes) {
+ if (status) *status = XBufferOverflow;
+ } else if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+}
+
+Public int
+_XimLocalWcLookupString(XIC xic, XKeyEvent *ev, wchar_t *buffer, int wlen,
+ KeySym *keysym, Status *status)
+{
+ Xic ic = (Xic)xic;
+ int ret;
+ DefTree *b = ic->private.local.base.tree;
+ wchar_t *wc = ic->private.local.base.wc;
+
+ if(ev->type != KeyPress) {
+ if(status) *status = XLookupNone;
+ return(0);
+ }
+ if(ev->keycode == 0) {
+ if (ic->private.local.brl_committed != 0) { /* Braille Event */
+ unsigned char pattern = ic->private.local.brl_committed;
+ ret = 1;
+ if (ret > wlen) {
+ if(status) *status = XBufferOverflow;
+ return (ret);
+ }
+ *buffer = BRL_UC_ROW | pattern;
+ if(keysym) {
+ *keysym = XK_braille_blank | pattern;
+ if(status) *status = XLookupBoth;
+ } else
+ if(status) *status = XLookupChars;
+ } else { /* Composed Event */
+ ret = _Xwcslen(&wc[b[ic->private.local.composed].wc]);
+ if(ret > wlen) {
+ if(status) *status = XBufferOverflow;
+ return (ret);
+ }
+ memcpy((char *)buffer, (char *)&wc[b[ic->private.local.composed].wc],
+ ret * sizeof(wchar_t));
+ if(keysym) *keysym = b[ic->private.local.composed].ks;
+ if (ret > 0) {
+ if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+ } else { /* Throughed Event */
+ ret = _XimLookupWCText(ic, ev, buffer, wlen, keysym, NULL);
+ if(ret > 0) {
+ if (ret > wlen) {
+ if (status) *status = XBufferOverflow;
+ } else if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+}
+
+Public int
+_XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
+ KeySym *keysym, Status *status)
+{
+ Xic ic = (Xic)xic;
+ int ret;
+ DefTree *b = ic->private.local.base.tree;
+ char *utf8 = ic->private.local.base.utf8;
+
+ if(ev->type != KeyPress) {
+ if(status) *status = XLookupNone;
+ return(0);
+ }
+ if(ev->keycode == 0) {
+ if (ic->private.local.brl_committed != 0) { /* Braille Event */
+ unsigned char pattern = ic->private.local.brl_committed;
+ ret = 3;
+ if (ret > bytes) {
+ if(status) *status = XBufferOverflow;
+ return (ret);
+ }
+ buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f);
+ buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6);
+ buffer[2] = 0x80 | (pattern & 0x3f);
+ if(keysym) {
+ *keysym = XK_braille_blank | pattern;
+ if(status) *status = XLookupBoth;
+ } else
+ if(status) *status = XLookupChars;
+ } else { /* Composed Event */
+ ret = strlen(&utf8[b[ic->private.local.composed].utf8]);
+ if(ret > bytes) {
+ if(status) *status = XBufferOverflow;
+ return (ret);
+ }
+ memcpy(buffer, &utf8[b[ic->private.local.composed].utf8], ret);
+ if(keysym) *keysym = b[ic->private.local.composed].ks;
+ if (ret > 0) {
+ if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+ } else { /* Throughed Event */
+ ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);
+ if(ret > 0) {
+ if (ret > bytes) {
+ if (status) *status = XBufferOverflow;
+ } else if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+}
+
+Private int
+_XimLcctsconvert(
+ XlcConv conv,
+ char *from,
+ int from_len,
+ char *to,
+ int to_len,
+ Status *state)
+{
+ int from_left;
+ int to_left;
+ int from_savelen;
+ int to_savelen;
+ int from_cnvlen;
+ int to_cnvlen;
+ char *from_buf;
+ char *to_buf;
+ char scratchbuf[BUFSIZ];
+ Status tmp_state;
+
+ if (!state)
+ state = &tmp_state;
+
+ if (!conv || !from || !from_len) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ /* Reset the converter. The CompoundText at 'from' starts in
+ initial state. */
+ _XlcResetConverter(conv);
+
+ from_left = from_len;
+ to_left = BUFSIZ;
+ from_cnvlen = 0;
+ to_cnvlen = 0;
+ for (;;) {
+ from_buf = &from[from_cnvlen];
+ from_savelen = from_left;
+ to_buf = &scratchbuf[to_cnvlen];
+ to_savelen = to_left;
+ if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
+ (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
+ *state = XLookupNone;
+ return 0;
+ }
+ from_cnvlen += (from_savelen - from_left);
+ to_cnvlen += (to_savelen - to_left);
+ if (from_left == 0) {
+ if (!to_cnvlen) {
+ *state = XLookupNone;
+ return 0;
+ }
+ break;
+ }
+ }
+
+ if (!to || !to_len || (to_len < to_cnvlen)) {
+ *state = XBufferOverflow;
+ } else {
+ memcpy(to, scratchbuf, to_cnvlen);
+ *state = XLookupChars;
+ }
+ return to_cnvlen;
+}
+
+Public int
+_XimLcctstombs(XIM xim, char *from, int from_len,
+ char *to, int to_len, Status *state)
+{
+ return _XimLcctsconvert(((Xim)xim)->private.local.ctom_conv,
+ from, from_len, to, to_len, state);
+}
+
+Public int
+_XimLcctstowcs(XIM xim, char *from, int from_len,
+ wchar_t *to, int to_len, Status *state)
+{
+ Xim im = (Xim)xim;
+ XlcConv conv = im->private.local.ctow_conv;
+ int from_left;
+ int to_left;
+ int from_savelen;
+ int to_savelen;
+ int from_cnvlen;
+ int to_cnvlen;
+ char *from_buf;
+ wchar_t *to_buf;
+ wchar_t scratchbuf[BUFSIZ];
+ Status tmp_state;
+
+ if (!state)
+ state = &tmp_state;
+
+ if (!conv || !from || !from_len) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ /* Reset the converter. The CompoundText at 'from' starts in
+ initial state. */
+ _XlcResetConverter(conv);
+
+ from_left = from_len;
+ to_left = BUFSIZ;
+ from_cnvlen = 0;
+ to_cnvlen = 0;
+ for (;;) {
+ from_buf = &from[from_cnvlen];
+ from_savelen = from_left;
+ to_buf = &scratchbuf[to_cnvlen];
+ to_savelen = to_left;
+ if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
+ (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
+ *state = XLookupNone;
+ return 0;
+ }
+ from_cnvlen += (from_savelen - from_left);
+ to_cnvlen += (to_savelen - to_left);
+ if (from_left == 0) {
+ if (!to_cnvlen){
+ *state = XLookupNone;
+ return 0;
+ }
+ break;
+ }
+ }
+
+ if (!to || !to_len || (to_len < to_cnvlen)) {
+ *state = XBufferOverflow;
+ } else {
+ memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t));
+ *state = XLookupChars;
+ }
+ return to_cnvlen;
+}
+
+Public int
+_XimLcctstoutf8(XIM xim, char *from, int from_len,
+ char *to, int to_len, Status *state)
+{
+ return _XimLcctsconvert(((Xim)xim)->private.local.ctoutf8_conv,
+ from, from_len, to, to_len, state);
+}
diff --git a/libX11/modules/im/ximcp/imRm.c b/libX11/modules/im/ximcp/imRm.c
index ae35272fa..936db876a 100644
--- a/libX11/modules/im/ximcp/imRm.c
+++ b/libX11/modules/im/ximcp/imRm.c
@@ -1,3197 +1,3197 @@
-/******************************************************************
-
- Copyright 1990, 1991, 1992,1993, 1994 by FUJITSU LIMITED
- Copyright 1994 by Sony Corporation
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-and Sony Corporation not be used in advertising or publicity
-pertaining to distribution of the software without specific,
-written prior permission. FUJITSU LIMITED and Sony Corporation make
-no representations about the suitability of this software for any
-purpose. It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED AND SONY CORPORATION DISCLAIM ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU LIMITED AND
-SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
-PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
- Modifier: Makoto Wakamatsu Sony Corporation
- makoto@sm.sony.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <unistd.h>
-#include <X11/Xlib.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "Xresource.h"
-
-#define GET_NAME(x) name_table + x.name_offset
-
-typedef struct _XimValueOffsetInfo {
- unsigned short name_offset;
- XrmQuark quark;
- unsigned int offset;
- Bool (*defaults)(
- struct _XimValueOffsetInfo *, XPointer, XPointer, unsigned long
- );
- Bool (*encode)(
- struct _XimValueOffsetInfo *, XPointer, XPointer
- );
- Bool (*decode)(
- struct _XimValueOffsetInfo *, XPointer, XPointer
- );
-} XimValueOffsetInfoRec, *XimValueOffsetInfo;
-
-#ifdef XIM_CONNECTABLE
-Private Bool
-_XimCheckBool(str)
- char *str;
-{
- if(!strcmp(str, "True") || !strcmp(str, "true") ||
- !strcmp(str, "Yes") || !strcmp(str, "yes") ||
- !strcmp(str, "ON") || !strcmp(str, "on"))
- return True;
- return False;
-}
-
-Public void
-_XimSetProtoResource(im)
- Xim im;
-{
- char res_name_buf[256];
- char* res_name;
- char res_class_buf[256];
- char* res_class;
- char* str_type;
- XrmValue value;
- XIMStyle preedit_style = 0;
- XIMStyle status_style = 0;
- XIMStyles* imstyles;
- char* dotximdot = ".xim.";
- char* ximdot = "xim.";
- char* dotXimdot = ".Xim.";
- char* Ximdot = "Xim.";
-
- if (!im->core.rdb)
- return;
-
- if (strlen (im->core.res_name) < 200) res_name = res_name_buf;
- else res_name = Xmalloc (strlen (im->core.res_name) + 50);
- if (strlen (im->core.res_class) < 200) res_class = res_class_buf;
- else res_class = Xmalloc (strlen (im->core.res_class) + 50);
- /* pretend malloc always works */
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "useAuth");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "UseAuth");
- bzero(&value, sizeof(XrmValue));
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(_XimCheckBool(value.addr)) {
- MARK_USE_AUTHORIZATION_FUNC(im);
- }
- }
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "delaybinding");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "Delaybinding");
- bzero(&value, sizeof(XrmValue));
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(_XimCheckBool(value.addr)) {
- MARK_DELAYBINDABLE(im);
- }
- }
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "reconnect");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "Reconnect");
- bzero(&value, sizeof(XrmValue));
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(_XimCheckBool(value.addr)) {
- MARK_RECONNECTABLE(im);
- }
- }
-
- if(!IS_CONNECTABLE(im)) {
- if (res_name != res_name_buf) Xfree (res_name);
- if (res_class != res_class_buf) Xfree (res_class);
- return;
- }
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "preeditDefaultStyle");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "PreeditDefaultStyle");
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(!strcmp(value.addr, "XIMPreeditArea"))
- preedit_style = XIMPreeditArea;
- else if(!strcmp(value.addr, "XIMPreeditCallbacks"))
- preedit_style = XIMPreeditCallbacks;
- else if(!strcmp(value.addr, "XIMPreeditPosition"))
- preedit_style = XIMPreeditPosition;
- else if(!strcmp(value.addr, "XIMPreeditNothing"))
- preedit_style = XIMPreeditNothing;
- else if(!strcmp(value.addr, "XIMPreeditNone"))
- preedit_style = XIMPreeditNone;
- }
- if(!preedit_style)
- preedit_style = XIMPreeditNothing;
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "statusDefaultStyle");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "StatusDefaultStyle");
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(!strcmp(value.addr, "XIMStatusArea"))
- status_style = XIMStatusArea;
- else if(!strcmp(value.addr, "XIMStatusCallbacks"))
- status_style = XIMStatusCallbacks;
- else if(!strcmp(value.addr, "XIMStatusNothing"))
- status_style = XIMStatusNothing;
- else if(!strcmp(value.addr, "XIMStatusNone"))
- status_style = XIMStatusNone;
- }
- if(!status_style)
- status_style = XIMStatusNothing;
-
- if(!(imstyles = (XIMStyles *)Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){
- if (res_name != res_name_buf) Xfree (res_name);
- if (res_class != res_class_buf) Xfree (res_class);
- return;
- }
- imstyles->count_styles = 1;
- imstyles->supported_styles =
- (XIMStyle *)((char *)imstyles + sizeof(XIMStyles));
- imstyles->supported_styles[0] = preedit_style | status_style;
- im->private.proto.default_styles = imstyles;
- if (res_name != res_name_buf) Xfree (res_name);
- if (res_class != res_class_buf) Xfree (res_class);
-}
-#endif /* XIM_CONNECTABLE */
-
-static const char name_table[] =
- /* 0 */ XNQueryInputStyle"\0"
- /* 16 */ XNClientWindow"\0"
- /* 29 */ XNInputStyle"\0"
- /* 40 */ XNFocusWindow"\0"
- /* 52 */ XNResourceName"\0"
- /* 65 */ XNResourceClass"\0"
- /* 79 */ XNGeometryCallback"\0"
- /* 96 */ XNDestroyCallback"\0"
- /* 112 */ XNFilterEvents"\0"
- /* 125 */ XNPreeditStartCallback"\0"
- /* 146 */ XNPreeditDoneCallback"\0"
- /* 166 */ XNPreeditDrawCallback"\0"
- /* 186 */ XNPreeditCaretCallback"\0"
- /* 207 */ XNPreeditStateNotifyCallback"\0"
- /* 234 */ XNPreeditAttributes"\0"
- /* 252 */ XNStatusStartCallback"\0"
- /* 272 */ XNStatusDoneCallback"\0"
- /* 291 */ XNStatusDrawCallback"\0"
- /* 310 */ XNStatusAttributes"\0"
- /* 327 */ XNArea"\0"
- /* 332 */ XNAreaNeeded"\0"
- /* 343 */ XNSpotLocation"\0"
- /* 356 */ XNColormap"\0"
- /* 365 */ XNStdColormap"\0"
- /* 377 */ XNForeground"\0"
- /* 388 */ XNBackground"\0"
- /* 399 */ XNBackgroundPixmap"\0"
- /* 416 */ XNFontSet"\0"
- /* 424 */ XNLineSpace"\0"
- /* 434 */ XNCursor"\0"
- /* 441 */ XNQueryIMValuesList"\0"
- /* 459 */ XNQueryICValuesList"\0"
- /* 477 */ XNVisiblePosition"\0"
- /* 493 */ XNStringConversionCallback"\0"
- /* 518 */ XNStringConversion"\0"
- /* 535 */ XNResetState"\0"
- /* 546 */ XNHotKey"\0"
- /* 553 */ XNHotKeyState"\0"
- /* 565 */ XNPreeditState
-;
-
-#define OFFSET_XNQUERYINPUTSTYLE 0
-#define OFFSET_XNCLIENTWINDOW 16
-#define OFFSET_XNINPUTSTYLE 29
-#define OFFSET_XNFOCUSWINDOW 40
-#define OFFSET_XNRESOURCENAME 52
-#define OFFSET_XNRESOURCECLASS 65
-#define OFFSET_XNGEOMETRYCALLBACK 79
-#define OFFSET_XNDESTROYCALLBACK 96
-#define OFFSET_XNFILTEREVENTS 112
-#define OFFSET_XNPREEDITSTARTCALLBACK 125
-#define OFFSET_XNPREEDITDONECALLBACK 146
-#define OFFSET_XNPREEDITDRAWCALLBACK 166
-#define OFFSET_XNPREEDITCARETCALLBACK 186
-#define OFFSET_XNPREEDITSTATENOTIFYCALLBACK 207
-#define OFFSET_XNPREEDITATTRIBUTES 234
-#define OFFSET_XNSTATUSSTARTCALLBACK 252
-#define OFFSET_XNSTATUSDONECALLBACK 272
-#define OFFSET_XNSTATUSDRAWCALLBACK 291
-#define OFFSET_XNSTATUSATTRIBUTES 310
-#define OFFSET_XNAREA 327
-#define OFFSET_XNAREANEEDED 332
-#define OFFSET_XNSPOTLOCATION 343
-#define OFFSET_XNCOLORMAP 356
-#define OFFSET_XNSTDCOLORMAP 365
-#define OFFSET_XNFOREGROUND 377
-#define OFFSET_XNBACKGROUND 388
-#define OFFSET_XNBACKGROUNDPIXMAP 399
-#define OFFSET_XNFONTSET 416
-#define OFFSET_XNLINESPACE 424
-#define OFFSET_XNCURSOR 434
-#define OFFSET_XNQUERYIMVALUESLIST 441
-#define OFFSET_XNQUERYICVALUESLIST 459
-#define OFFSET_XNVISIBLEPOSITION 477
-#define OFFSET_XNSTRINGCONVERSIONCALLBACK 493
-#define OFFSET_XNSTRINGCONVERSION 518
-#define OFFSET_XNRESETSTATE 535
-#define OFFSET_XNHOTKEY 546
-#define OFFSET_XNHOTKEYSTATE 553
-#define OFFSET_XNPREEDITSTATE 565
-
-/* offsets into name_table */
-static const unsigned short supported_local_im_values_list[] = {
- OFFSET_XNQUERYINPUTSTYLE,
- OFFSET_XNRESOURCENAME,
- OFFSET_XNRESOURCECLASS,
- OFFSET_XNDESTROYCALLBACK,
- OFFSET_XNQUERYIMVALUESLIST,
- OFFSET_XNQUERYICVALUESLIST,
- OFFSET_XNVISIBLEPOSITION
-};
-
-/* offsets into name_table */
-static const unsigned short supported_local_ic_values_list[] = {
- OFFSET_XNINPUTSTYLE,
- OFFSET_XNCLIENTWINDOW,
- OFFSET_XNFOCUSWINDOW,
- OFFSET_XNRESOURCENAME,
- OFFSET_XNRESOURCECLASS,
- OFFSET_XNGEOMETRYCALLBACK,
- OFFSET_XNFILTEREVENTS,
- OFFSET_XNDESTROYCALLBACK,
- OFFSET_XNSTRINGCONVERSIONCALLBACK,
- OFFSET_XNSTRINGCONVERSIONCALLBACK,
- OFFSET_XNRESETSTATE,
- OFFSET_XNHOTKEY,
- OFFSET_XNHOTKEYSTATE,
- OFFSET_XNPREEDITATTRIBUTES,
- OFFSET_XNSTATUSATTRIBUTES,
- OFFSET_XNAREA,
- OFFSET_XNAREANEEDED,
- OFFSET_XNSPOTLOCATION,
- OFFSET_XNCOLORMAP,
- OFFSET_XNSTDCOLORMAP,
- OFFSET_XNFOREGROUND,
- OFFSET_XNBACKGROUND,
- OFFSET_XNBACKGROUNDPIXMAP,
- OFFSET_XNFONTSET,
- OFFSET_XNLINESPACE,
- OFFSET_XNCURSOR,
- OFFSET_XNPREEDITSTARTCALLBACK,
- OFFSET_XNPREEDITDONECALLBACK,
- OFFSET_XNPREEDITDRAWCALLBACK,
- OFFSET_XNPREEDITCARETCALLBACK,
- OFFSET_XNSTATUSSTARTCALLBACK,
- OFFSET_XNSTATUSDONECALLBACK,
- OFFSET_XNSTATUSDRAWCALLBACK,
- OFFSET_XNPREEDITSTATE,
- OFFSET_XNPREEDITSTATENOTIFYCALLBACK
-};
-
-static XIMStyle const supported_local_styles[] = {
- XIMPreeditNone | XIMStatusNone,
- XIMPreeditNothing | XIMStatusNothing,
- 0 /* dummy */
-};
-
-Private Bool
-_XimDefaultStyles(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm, /* unused */
- unsigned long mode) /* unused */
-{
- XIMStyles *styles;
- XIMStyles **out;
- register int i;
- unsigned int n;
- int len;
- XPointer tmp;
-
- n = XIMNumber(supported_local_styles) - 1;
- len = sizeof(XIMStyles) + sizeof(XIMStyle) * n;
- if(!(tmp = Xcalloc(1, len))) {
- return False;
- }
-
- styles = (XIMStyles *)tmp;
- if (n > 0) {
- styles->count_styles = (unsigned short)n;
- styles->supported_styles =
- (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
- for(i = 0; i < n; i++) {
- styles->supported_styles[i] = supported_local_styles[i];
- }
- }
-
- out = (XIMStyles **)((char *)top + info->offset);
- *out = styles;
- return True;
-}
-
-Private Bool
-_XimDefaultIMValues(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm, /* unused */
- unsigned long mode) /* unused */
-{
- XIMValuesList *values_list;
- XIMValuesList **out;
- register int i;
- unsigned int n;
- int len;
- XPointer tmp;
-
- n = XIMNumber(supported_local_im_values_list);
- len = sizeof(XIMValuesList) + sizeof(char **) * n;
- if(!(tmp = Xcalloc(1, len))) {
- return False;
- }
-
- values_list = (XIMValuesList *)tmp;
- if (n > 0) {
- values_list->count_values = (unsigned short)n;
- values_list->supported_values
- = (char **)((char *)tmp + sizeof(XIMValuesList));
- for(i = 0; i < n; i++) {
- values_list->supported_values[i] =
- (char *)name_table + supported_local_im_values_list[i];
- }
- }
-
- out = (XIMValuesList **)((char *)top + info->offset);
- *out = values_list;
- return True;
-}
-
-Private Bool
-_XimDefaultICValues(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm, /* unused */
- unsigned long mode) /* unused */
-{
- XIMValuesList *values_list;
- XIMValuesList **out;
- register int i;
- unsigned int n;
- int len;
- XPointer tmp;
-
- n = XIMNumber(supported_local_ic_values_list);
- len = sizeof(XIMValuesList) + sizeof(char **) * n;
- if(!(tmp = Xcalloc(1, len))) {
- return False;
- }
-
- values_list = (XIMValuesList *)tmp;
- if (n > 0) {
- values_list->count_values = (unsigned short)n;
- values_list->supported_values
- = (char **)((char *)tmp + sizeof(XIMValuesList));
- for(i = 0; i < n; i++) {
- values_list->supported_values[i] =
- (char *)name_table + supported_local_ic_values_list[i];
- }
- }
-
- out = (XIMValuesList **)((char *)top + info->offset);
- *out = values_list;
- return True;
-}
-
-Private Bool
-_XimDefaultVisiblePos(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm, /* unused */
- unsigned long mode) /* unused */
-{
- Bool *out;
-
- out = (Bool *)((char *)top + info->offset);
- *out = False;
- return True;
-}
-
-Private Bool
-_XimDefaultFocusWindow(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Window *out;
-
- if(ic->core.client_window == (Window)NULL) {
- return True;
- }
-
- out = (Window *)((char *)top + info->offset);
- *out = ic->core.client_window;
- return True;
-}
-
-Private Bool
-_XimDefaultResName(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- char **out;
-
- if(im->core.res_name == (char *)NULL) {
- return True;
- }
-
- out = (char **)((char *)top + info->offset);
- *out = im->core.res_name;
- return True;
-}
-
-Private Bool
-_XimDefaultResClass(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- char **out;
-
- if(im->core.res_class == (char *)NULL) {
- return True;
- }
-
- out = (char **)((char *)top + info->offset);
- *out = im->core.res_class;
- return True;
-}
-
-Private Bool
-_XimDefaultDestroyCB(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- XIMCallback *out;
-
- out = (XIMCallback *)((char *)top + info->offset);
- *out = im->core.destroy_callback;
- return True;
-}
-
-Private Bool
-_XimDefaultResetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- XIMResetState *out;
-
- out = (XIMResetState *)((char *)top + info->offset);
- *out = XIMInitialState;
- return True;
-}
-
-Private Bool
-_XimDefaultHotKeyState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- XIMHotKeyState *out;
-
- out = (XIMHotKeyState *)((char *)top + info->offset);
- *out = XIMHotKeyStateOFF;
- return True;
-}
-
-Private Bool
-_XimDefaultArea(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- Window root_return;
- int x_return, y_return;
- unsigned int width_return, height_return;
- unsigned int border_width_return;
- unsigned int depth_return;
- XRectangle area;
- XRectangle *out;
-
- if(ic->core.focus_window == (Window)NULL) {
- return True;
- }
- if(XGetGeometry(im->core.display, (Drawable)ic->core.focus_window,
- &root_return, &x_return, &y_return, &width_return,
- &height_return, &border_width_return, &depth_return)
- == (Status)Success) {
- return True;
- }
- area.x = 0;
- area.y = 0;
- area.width = width_return;
- area.height = height_return;
-
- out = (XRectangle *)((char *)top + info->offset);
- *out = area;
- return True;
-}
-
-Private Bool
-_XimDefaultColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- XWindowAttributes win_attr;
- Colormap *out;
-
- if(ic->core.client_window == (Window)NULL) {
- return True;
- }
- if(XGetWindowAttributes(im->core.display, ic->core.client_window,
- &win_attr) == (Status)Success) {
- return True;
- }
-
- out = (Colormap *)((char *)top + info->offset);
- *out = win_attr.colormap;
- return True;
-}
-
-Private Bool
-_XimDefaultStdColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Atom *out;
-
- out = (Atom *)((char *)top + info->offset);
- *out = (Atom)0;
- return True;
-}
-
-Private Bool
-_XimDefaultFg(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- unsigned long fg;
- unsigned long *out;
-
- fg = WhitePixel(im->core.display, DefaultScreen(im->core.display));
- out = (unsigned long *)((char *)top + info->offset);
- *out = fg;
- return True;
-}
-
-Private Bool
-_XimDefaultBg(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- unsigned long bg;
- unsigned long *out;
-
- bg = BlackPixel(im->core.display, DefaultScreen(im->core.display));
- out = (unsigned long *)((char *)top + info->offset);
- *out = bg;
- return True;
-}
-
-Private Bool
-_XimDefaultBgPixmap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Pixmap *out;
-
- out = (Pixmap *)((char *)top + info->offset);
- *out = (Pixmap)0;
- return True;
-}
-
-Private Bool
-_XimDefaultFontSet(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- XFontSet *out;
-
- out = (XFontSet *)((char *)top + info->offset);
- *out = 0;
- return True;
-}
-
-Private Bool
-_XimDefaultLineSpace(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- XFontSet fontset;
- XFontSetExtents *fset_extents;
- int line_space = 0;
- int *out;
-
- if(mode & XIM_PREEDIT_ATTR) {
- fontset = ic->core.preedit_attr.fontset;
- } else if(mode & XIM_STATUS_ATTR) {
- fontset = ic->core.status_attr.fontset;
- } else {
- return True;
- }
- if (fontset) {
- fset_extents = XExtentsOfFontSet(fontset);
- line_space = fset_extents->max_logical_extent.height;
- }
- out = (int *)((char *)top + info->offset);
- *out = line_space;
- return True;
-}
-
-Private Bool
-_XimDefaultCursor(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Cursor *out;
-
- out = (Cursor *)((char *)top + info->offset);
- *out = (Cursor)0;
- return True;
-}
-
-Private Bool
-_XimDefaultPreeditState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- XIMPreeditState *out;
-
- out = (XIMPreeditState *)((char *)top + info->offset);
- *out = XIMPreeditDisable;
- return True;
-}
-
-Private Bool
-_XimDefaultNest(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- return True;
-}
-
-Private Bool
-_XimEncodeCallback(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMCallback *out;
-
- out = (XIMCallback *)((char *)top + info->offset);
- *out = *((XIMCallback *)val);
- return True;
-}
-
-Private Bool
-_XimEncodeString(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- char *string;
- char **out;
-
- if(val == (XPointer)NULL) {
- return False;
- }
- if (!(string = strdup((char *)val))) {
- return False;
- }
-
- out = (char **)((char *)top + info->offset);
- if(*out) {
- Xfree(*out);
- }
- *out = string;
- return True;
-}
-
-Private Bool
-_XimEncodeStyle(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMStyle *out;
-
- out = (XIMStyle *)((char *)top + info->offset);
- *out = (XIMStyle)val;
- return True;
-}
-
-Private Bool
-_XimEncodeWindow(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Window *out;
-
- out = (Window *)((char *)top + info->offset);
- *out = (Window)val;
- return True;
-}
-
-Private Bool
-_XimEncodeStringConv(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- /*
- * Not yet
- */
- return True;
-}
-
-Private Bool
-_XimEncodeResetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMResetState *out;
-
- out = (XIMResetState *)((char *)top + info->offset);
- *out = (XIMResetState)val;
- return True;
-}
-
-Private Bool
-_XimEncodeHotKey(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)val;
- XIMHotKeyTriggers **out;
- XIMHotKeyTriggers *key_list;
- XIMHotKeyTrigger *key;
- XPointer tmp;
- int num;
- int len;
- register int i;
-
- if(hotkey == (XIMHotKeyTriggers *)NULL) {
- return True;
- }
-
- if((num = hotkey->num_hot_key) == 0) {
- return True;
- }
-
- len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
- if(!(tmp = (XPointer)Xmalloc(len))) {
- return False;
- }
-
- key_list = (XIMHotKeyTriggers *)tmp;
- key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
-
- for(i = 0; i < num; i++) {
- key[i] = hotkey->key[i];
- }
-
- key_list->num_hot_key = num;
- key_list->key = key;
-
- out = (XIMHotKeyTriggers **)((char *)top + info->offset);
- *out = key_list;
- return True;
-}
-
-Private Bool
-_XimEncodeHotKetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMHotKeyState *out;
-
- out = (XIMHotKeyState *)((char *)top + info->offset);
- *out = (XIMHotKeyState)val;
- return True;
-}
-
-Private Bool
-_XimEncodeRectangle(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XRectangle *out;
-
- out = (XRectangle *)((char *)top + info->offset);
- *out = *((XRectangle *)val);
- return True;
-}
-
-Private Bool
-_XimEncodeSpot(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XPoint *out;
-
- out = (XPoint *)((char *)top + info->offset);
- *out = *((XPoint *)val);
- return True;
-}
-
-Private Bool
-_XimEncodeColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Colormap *out;
-
- out = (Colormap *)((char *)top + info->offset);
- *out = (Colormap)val;
- return True;
-}
-
-Private Bool
-_XimEncodeStdColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Atom *out;
-
- out = (Atom *)((char *)top + info->offset);
- *out = (Atom)val;
- return True;
-}
-
-Private Bool
-_XimEncodeLong(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- unsigned long *out;
-
- out = (unsigned long *)((char *)top + info->offset);
- *out = (unsigned long)val;
- return True;
-}
-
-Private Bool
-_XimEncodeBgPixmap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Pixmap *out;
-
- out = (Pixmap *)((char *)top + info->offset);
- *out = (Pixmap)val;
- return True;
-}
-
-Private Bool
-_XimEncodeFontSet(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XFontSet *out;
-
- out = (XFontSet *)((char *)top + info->offset);
- *out = (XFontSet)val;
- return True;
-}
-
-Private Bool
-_XimEncodeLineSpace(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- int *out;
-
- out = (int *)((char *)top + info->offset);
- *out = (long)val;
- return True;
-}
-
-Private Bool
-_XimEncodeCursor(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Cursor *out;
-
- out = (Cursor *)((char *)top + info->offset);
- *out = (Cursor)val;
- return True;
-}
-
-Private Bool
-_XimEncodePreeditState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMPreeditState *out;
-
- out = (XIMPreeditState *)((char *)top + info->offset);
- *out = (XIMPreeditState)val;
- return True;
-}
-
-Private Bool
-_XimEncodeNest(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- return True;
-}
-
-Private Bool
-_XimDecodeStyles(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMStyles *styles;
- XIMStyles *out;
- register int i;
- unsigned int num;
- int len;
- XPointer tmp;
-
- if(val == (XPointer)NULL) {
- return False;
- }
-
- styles = *((XIMStyles **)((char *)top + info->offset));
- num = styles->count_styles;
-
- len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
- if(!(tmp = Xcalloc(1, len))) {
- return False;
- }
-
- out = (XIMStyles *)tmp;
- if(num >0) {
- out->count_styles = (unsigned short)num;
- out->supported_styles = (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
-
- for(i = 0; i < num; i++) {
- out->supported_styles[i] = styles->supported_styles[i];
- }
- }
- *((XIMStyles **)val) = out;
- return True;
-}
-
-Private Bool
-_XimDecodeValues(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMValuesList *values_list;
- XIMValuesList *out;
- register int i;
- unsigned int num;
- int len;
- XPointer tmp;
-
- if(val == (XPointer)NULL) {
- return False;
- }
-
- values_list = *((XIMValuesList **)((char *)top + info->offset));
- num = values_list->count_values;
-
- len = sizeof(XIMValuesList) + sizeof(char **) * num;
- if(!(tmp = Xcalloc(1, len))) {
- return False;
- }
-
- out = (XIMValuesList *)tmp;
- if(num) {
- out->count_values = (unsigned short)num;
- out->supported_values = (char **)((char *)tmp + sizeof(XIMValuesList));
-
- for(i = 0; i < num; i++) {
- out->supported_values[i] = values_list->supported_values[i];
- }
- }
- *((XIMValuesList **)val) = out;
- return True;
-}
-
-Private Bool
-_XimDecodeCallback(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMCallback *in;
- XIMCallback *callback;
-
- in = (XIMCallback *)((char *)top + info->offset);
- if(!(callback = (XIMCallback *)Xmalloc(sizeof(XIMCallback)))) {
- return False;
- }
- callback->client_data = in->client_data;
- callback->callback = in->callback;
-
- *((XIMCallback **)val) = callback;
- return True;
-}
-
-Private Bool
-_XimDecodeString(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- char *in;
- char *string;
-
- in = *((char **)((char *)top + info->offset));
- if (in != NULL) {
- string = strdup(in);
- } else {
- string = Xcalloc(1, 1); /* strdup("") */
- }
- if (string == NULL) {
- return False;
- }
- *((char **)val) = string;
- return True;
-}
-
-Private Bool
-_XimDecodeBool(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Bool *in;
-
- in = (Bool *)((char *)top + info->offset);
- *((Bool *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeStyle(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMStyle *in;
-
- in = (XIMStyle *)((char *)top + info->offset);
- *((XIMStyle *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeWindow(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Window *in;
-
- in = (Window *)((char *)top + info->offset);
- *((Window *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeStringConv(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- /*
- * Not yet
- */
- return True;
-}
-
-Private Bool
-_XimDecodeResetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMResetState *in;
-
- in = (XIMResetState *)((char *)top + info->offset);
- *((XIMResetState *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeHotKey(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMHotKeyTriggers *in;
- XIMHotKeyTriggers *hotkey;
- XIMHotKeyTrigger *key;
- XPointer tmp;
- int num;
- int len;
- register int i;
-
- in = *((XIMHotKeyTriggers **)((char *)top + info->offset));
- num = in->num_hot_key;
- len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
- if(!(tmp = (XPointer)Xmalloc(len))) {
- return False;
- }
-
- hotkey = (XIMHotKeyTriggers *)tmp;
- key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
-
- for(i = 0; i < num; i++) {
- key[i] = in->key[i];
- }
- hotkey->num_hot_key = num;
- hotkey->key = key;
-
- *((XIMHotKeyTriggers **)val) = hotkey;
- return True;
-}
-
-Private Bool
-_XimDecodeHotKetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMHotKeyState *in;
-
- in = (XIMHotKeyState *)((char *)top + info->offset);
- *((XIMHotKeyState *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeRectangle(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XRectangle *in;
- XRectangle *rect;
-
- in = (XRectangle *)((char *)top + info->offset);
- if(!(rect = (XRectangle *)Xmalloc(sizeof(XRectangle)))) {
- return False;
- }
- *rect = *in;
- *((XRectangle **)val) = rect;
- return True;
-}
-
-Private Bool
-_XimDecodeSpot(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XPoint *in;
- XPoint *spot;
-
- in = (XPoint *)((char *)top + info->offset);
- if(!(spot = (XPoint *)Xmalloc(sizeof(XPoint)))) {
- return False;
- }
- *spot = *in;
- *((XPoint **)val) = spot;
- return True;
-}
-
-Private Bool
-_XimDecodeColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Colormap *in;
-
- in = (Colormap *)((char *)top + info->offset);
- *((Colormap *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeStdColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Atom *in;
-
- in = (Atom *)((char *)top + info->offset);
- *((Atom *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeLong(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- unsigned long *in;
-
- in = (unsigned long *)((char *)top + info->offset);
- *((unsigned long *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeBgPixmap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Pixmap *in;
-
- in = (Pixmap *)((char *)top + info->offset);
- *((Pixmap *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeFontSet(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XFontSet *in;
-
- in = (XFontSet *)((char *)top + info->offset);
- *((XFontSet *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeLineSpace(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- int *in;
-
- in = (int *)((char *)top + info->offset);
- *((int *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeCursor(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Cursor *in;
-
- in = (Cursor *)((char *)top + info->offset);
- *((Cursor *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodePreeditState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMPreeditState *in;
-
- in = (XIMPreeditState *)((char *)top + info->offset);
- *((XIMPreeditState *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeNest(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- return True;
-}
-
-static XIMResource im_resources[] = {
- {XNQueryInputStyle, 0, XimType_XIMStyles, 0, 0, 0},
- {XNDestroyCallback, 0, 0, 0, 0, 0},
- {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
- {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
- {XNQueryIMValuesList, 0, 0, 0, 0, 0},
- {XNQueryICValuesList, 0, 0, 0, 0, 0},
- {XNVisiblePosition, 0, 0, 0, 0, 0}
-};
-
-static XIMResource im_inner_resources[] = {
- {XNDestroyCallback, 0, 0, 0, 0, 0},
- {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
- {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
- {XNQueryIMValuesList, 0, 0, 0, 0, 0},
- {XNQueryICValuesList, 0, 0, 0, 0, 0},
- {XNVisiblePosition, 0, 0, 0, 0, 0}
-};
-
-static XIMResource ic_resources[] = {
- {XNInputStyle, 0, XimType_CARD32, 0, 0, 0},
- {XNClientWindow, 0, XimType_Window, 0, 0, 0},
- {XNFocusWindow, 0, XimType_Window, 0, 0, 0},
- {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
- {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
- {XNGeometryCallback, 0, 0, 0, 0, 0},
- {XNFilterEvents, 0, XimType_CARD32, 0, 0, 0},
- {XNDestroyCallback, 0, 0, 0, 0, 0},
- {XNStringConversionCallback, 0, 0, 0, 0, 0},
- {XNStringConversion, 0, XimType_XIMStringConversion,0, 0, 0},
- {XNResetState, 0, 0, 0, 0, 0},
- {XNHotKey, 0, XimType_XIMHotKeyTriggers,0, 0, 0},
- {XNHotKeyState, 0, XimType_XIMHotKeyState, 0, 0, 0},
- {XNPreeditAttributes, 0, XimType_NEST, 0, 0, 0},
- {XNStatusAttributes, 0, XimType_NEST, 0, 0, 0},
- {XNArea, 0, XimType_XRectangle, 0, 0, 0},
- {XNAreaNeeded, 0, XimType_XRectangle, 0, 0, 0},
- {XNSpotLocation, 0, XimType_XPoint, 0, 0, 0},
- {XNColormap, 0, XimType_CARD32, 0, 0, 0},
- {XNStdColormap, 0, XimType_CARD32, 0, 0, 0},
- {XNForeground, 0, XimType_CARD32, 0, 0, 0},
- {XNBackground, 0, XimType_CARD32, 0, 0, 0},
- {XNBackgroundPixmap, 0, XimType_CARD32, 0, 0, 0},
- {XNFontSet, 0, XimType_XFontSet, 0, 0, 0},
- {XNLineSpace, 0, XimType_CARD32, 0, 0, 0},
- {XNCursor, 0, XimType_CARD32, 0, 0, 0},
- {XNPreeditStartCallback, 0, 0, 0, 0, 0},
- {XNPreeditDoneCallback, 0, 0, 0, 0, 0},
- {XNPreeditDrawCallback, 0, 0, 0, 0, 0},
- {XNPreeditCaretCallback, 0, 0, 0, 0, 0},
- {XNStatusStartCallback, 0, 0, 0, 0, 0},
- {XNStatusDoneCallback, 0, 0, 0, 0, 0},
- {XNStatusDrawCallback, 0, 0, 0, 0, 0},
- {XNPreeditState, 0, 0, 0, 0, 0},
- {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0},
-};
-
-static XIMResource ic_inner_resources[] = {
- {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
- {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
- {XNGeometryCallback, 0, 0, 0, 0, 0},
- {XNDestroyCallback, 0, 0, 0, 0, 0},
- {XNStringConversionCallback, 0, 0, 0, 0, 0},
- {XNPreeditStartCallback, 0, 0, 0, 0, 0},
- {XNPreeditDoneCallback, 0, 0, 0, 0, 0},
- {XNPreeditDrawCallback, 0, 0, 0, 0, 0},
- {XNPreeditCaretCallback, 0, 0, 0, 0, 0},
- {XNStatusStartCallback, 0, 0, 0, 0, 0},
- {XNStatusDoneCallback, 0, 0, 0, 0, 0},
- {XNStatusDrawCallback, 0, 0, 0, 0, 0},
- {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0},
-};
-
-static XimValueOffsetInfoRec im_attr_info[] = {
- {OFFSET_XNQUERYINPUTSTYLE, 0,
- XOffsetOf(XimDefIMValues, styles),
- _XimDefaultStyles, NULL, _XimDecodeStyles},
-
- {OFFSET_XNDESTROYCALLBACK, 0,
- XOffsetOf(XimDefIMValues, destroy_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNRESOURCENAME, 0,
- XOffsetOf(XimDefIMValues, res_name),
- NULL, _XimEncodeString, _XimDecodeString},
-
- {OFFSET_XNRESOURCECLASS, 0,
- XOffsetOf(XimDefIMValues, res_class),
- NULL, _XimEncodeString, _XimDecodeString},
-
- {OFFSET_XNQUERYIMVALUESLIST, 0,
- XOffsetOf(XimDefIMValues, im_values_list),
- _XimDefaultIMValues, NULL, _XimDecodeValues},
-
- {OFFSET_XNQUERYICVALUESLIST, 0,
- XOffsetOf(XimDefIMValues, ic_values_list),
- _XimDefaultICValues, NULL, _XimDecodeValues},
-
- {OFFSET_XNVISIBLEPOSITION, 0,
- XOffsetOf(XimDefIMValues, visible_position),
- _XimDefaultVisiblePos, NULL, _XimDecodeBool}
-};
-
-static XimValueOffsetInfoRec ic_attr_info[] = {
- {OFFSET_XNINPUTSTYLE, 0,
- XOffsetOf(XimDefICValues, input_style),
- NULL, _XimEncodeStyle, _XimDecodeStyle},
-
- {OFFSET_XNCLIENTWINDOW, 0,
- XOffsetOf(XimDefICValues, client_window),
- NULL, _XimEncodeWindow, _XimDecodeWindow},
-
- {OFFSET_XNFOCUSWINDOW, 0,
- XOffsetOf(XimDefICValues, focus_window),
- _XimDefaultFocusWindow, _XimEncodeWindow, _XimDecodeWindow},
-
- {OFFSET_XNRESOURCENAME, 0,
- XOffsetOf(XimDefICValues, res_name),
- _XimDefaultResName, _XimEncodeString, _XimDecodeString},
-
- {OFFSET_XNRESOURCECLASS, 0,
- XOffsetOf(XimDefICValues, res_class),
- _XimDefaultResClass, _XimEncodeString, _XimDecodeString},
-
- {OFFSET_XNGEOMETRYCALLBACK, 0,
- XOffsetOf(XimDefICValues, geometry_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNFILTEREVENTS, 0,
- XOffsetOf(XimDefICValues, filter_events),
- NULL, NULL, _XimDecodeLong},
-
- {OFFSET_XNDESTROYCALLBACK, 0,
- XOffsetOf(XimDefICValues, destroy_callback),
- _XimDefaultDestroyCB, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNSTRINGCONVERSIONCALLBACK, 0,
- XOffsetOf(XimDefICValues, string_conversion_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNSTRINGCONVERSION, 0,
- XOffsetOf(XimDefICValues, string_conversion),
- NULL, _XimEncodeStringConv, _XimDecodeStringConv},
-
- {OFFSET_XNRESETSTATE, 0,
- XOffsetOf(XimDefICValues, reset_state),
- _XimDefaultResetState, _XimEncodeResetState, _XimDecodeResetState},
-
- {OFFSET_XNHOTKEY, 0,
- XOffsetOf(XimDefICValues, hotkey),
- NULL, _XimEncodeHotKey, _XimDecodeHotKey},
-
- {OFFSET_XNHOTKEYSTATE, 0,
- XOffsetOf(XimDefICValues, hotkey_state),
- _XimDefaultHotKeyState, _XimEncodeHotKetState, _XimDecodeHotKetState},
-
- {OFFSET_XNPREEDITATTRIBUTES, 0,
- XOffsetOf(XimDefICValues, preedit_attr),
- _XimDefaultNest, _XimEncodeNest, _XimDecodeNest},
-
- {OFFSET_XNSTATUSATTRIBUTES, 0,
- XOffsetOf(XimDefICValues, status_attr),
- _XimDefaultNest, _XimEncodeNest, _XimDecodeNest},
-};
-
-static XimValueOffsetInfoRec ic_pre_attr_info[] = {
- {OFFSET_XNAREA, 0,
- XOffsetOf(ICPreeditAttributes, area),
- _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle},
-
- {OFFSET_XNAREANEEDED, 0,
- XOffsetOf(ICPreeditAttributes, area_needed),
- NULL, _XimEncodeRectangle, _XimDecodeRectangle},
-
- {OFFSET_XNSPOTLOCATION, 0,
- XOffsetOf(ICPreeditAttributes, spot_location),
- NULL, _XimEncodeSpot, _XimDecodeSpot},
-
- {OFFSET_XNCOLORMAP, 0,
- XOffsetOf(ICPreeditAttributes, colormap),
- _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap},
-
- {OFFSET_XNSTDCOLORMAP, 0,
- XOffsetOf(ICPreeditAttributes, std_colormap),
- _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap},
-
- {OFFSET_XNFOREGROUND, 0,
- XOffsetOf(ICPreeditAttributes, foreground),
- _XimDefaultFg, _XimEncodeLong, _XimDecodeLong},
-
- {OFFSET_XNBACKGROUND, 0,
- XOffsetOf(ICPreeditAttributes, background),
- _XimDefaultBg, _XimEncodeLong, _XimDecodeLong},
-
- {OFFSET_XNBACKGROUNDPIXMAP, 0,
- XOffsetOf(ICPreeditAttributes, background_pixmap),
- _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap},
-
- {OFFSET_XNFONTSET, 0,
- XOffsetOf(ICPreeditAttributes, fontset),
- _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet},
-
- {OFFSET_XNLINESPACE, 0,
- XOffsetOf(ICPreeditAttributes, line_spacing),
- _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace},
-
- {OFFSET_XNCURSOR, 0,
- XOffsetOf(ICPreeditAttributes, cursor),
- _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor},
-
- {OFFSET_XNPREEDITSTARTCALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, start_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNPREEDITDONECALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, done_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNPREEDITDRAWCALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, draw_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNPREEDITCARETCALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, caret_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNPREEDITSTATE, 0,
- XOffsetOf(ICPreeditAttributes, preedit_state),
- _XimDefaultPreeditState, _XimEncodePreeditState,_XimDecodePreeditState},
-
- {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, state_notify_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-};
-
-static XimValueOffsetInfoRec ic_sts_attr_info[] = {
- {OFFSET_XNAREA, 0,
- XOffsetOf(ICStatusAttributes, area),
- _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle},
-
- {OFFSET_XNAREANEEDED, 0,
- XOffsetOf(ICStatusAttributes, area_needed),
- NULL, _XimEncodeRectangle, _XimDecodeRectangle},
-
- {OFFSET_XNCOLORMAP, 0,
- XOffsetOf(ICStatusAttributes, colormap),
- _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap},
-
- {OFFSET_XNSTDCOLORMAP, 0,
- XOffsetOf(ICStatusAttributes, std_colormap),
- _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap},
-
- {OFFSET_XNFOREGROUND, 0,
- XOffsetOf(ICStatusAttributes, foreground),
- _XimDefaultFg, _XimEncodeLong, _XimDecodeLong},
-
- {OFFSET_XNBACKGROUND, 0,
- XOffsetOf(ICStatusAttributes, background),
- _XimDefaultBg, _XimEncodeLong, _XimDecodeLong},
-
- {OFFSET_XNBACKGROUNDPIXMAP, 0,
- XOffsetOf(ICStatusAttributes, background_pixmap),
- _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap},
-
- {OFFSET_XNFONTSET, 0,
- XOffsetOf(ICStatusAttributes, fontset),
- _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet},
-
- {OFFSET_XNLINESPACE, 0,
- XOffsetOf(ICStatusAttributes, line_spacing),
- _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace},
-
- {OFFSET_XNCURSOR, 0,
- XOffsetOf(ICStatusAttributes, cursor),
- _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor},
-
- {OFFSET_XNSTATUSSTARTCALLBACK, 0,
- XOffsetOf(ICStatusAttributes, start_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNSTATUSDONECALLBACK, 0,
- XOffsetOf(ICStatusAttributes, done_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNSTATUSDRAWCALLBACK, 0,
- XOffsetOf(ICStatusAttributes, draw_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback}
-};
-
-typedef struct _XimIMMode {
- unsigned short name_offset;
- unsigned short mode;
-} XimIMMode;
-
-static const XimIMMode im_mode[] = {
- {OFFSET_XNQUERYINPUTSTYLE,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
- {OFFSET_XNDESTROYCALLBACK,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
- {OFFSET_XNRESOURCENAME,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
- {OFFSET_XNRESOURCECLASS,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
- {OFFSET_XNQUERYIMVALUESLIST,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
- {OFFSET_XNQUERYICVALUESLIST,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
- {OFFSET_XNVISIBLEPOSITION,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}
-};
-
-typedef struct _XimICMode {
- unsigned short name_offset;
- unsigned short preedit_callback_mode;
- unsigned short preedit_position_mode;
- unsigned short preedit_area_mode;
- unsigned short preedit_nothing_mode;
- unsigned short preedit_none_mode;
- unsigned short status_callback_mode;
- unsigned short status_area_mode;
- unsigned short status_nothing_mode;
- unsigned short status_none_mode;
-} XimICMode;
-
-static const XimICMode ic_mode[] = {
- {OFFSET_XNINPUTSTYLE,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET)},
- {OFFSET_XNCLIENTWINDOW,
- (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
- 0,
- (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNFOCUSWINDOW,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNRESOURCENAME,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNRESOURCECLASS,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNGEOMETRYCALLBACK,
- 0,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0},
- {OFFSET_XNFILTEREVENTS,
- XIM_MODE_PRE_GET,
- XIM_MODE_PRE_GET,
- XIM_MODE_PRE_GET,
- XIM_MODE_PRE_GET,
- 0,
- XIM_MODE_STS_GET,
- XIM_MODE_STS_GET,
- XIM_MODE_STS_GET,
- XIM_MODE_STS_GET},
- {OFFSET_XNDESTROYCALLBACK,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNSTRINGCONVERSIONCALLBACK,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNSTRINGCONVERSION,
- XIM_MODE_PRE_SET,
- XIM_MODE_PRE_SET,
- XIM_MODE_PRE_SET,
- XIM_MODE_PRE_SET,
- XIM_MODE_PRE_SET,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNRESETSTATE,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNHOTKEY,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNHOTKEYSTATE,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITATTRIBUTES,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNSTATUSATTRIBUTES,
- 0,
- 0,
- 0,
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNAREA,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0},
- {OFFSET_XNAREANEEDED,
- 0,
- 0,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- (XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0},
- {OFFSET_XNSPOTLOCATION,
- 0, /*(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),*/
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNCOLORMAP,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNSTDCOLORMAP,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNFOREGROUND,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNBACKGROUND,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNBACKGROUNDPIXMAP,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNFONTSET,
- 0,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNLINESPACE,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNCURSOR,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNPREEDITSTARTCALLBACK,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITDONECALLBACK,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITDRAWCALLBACK,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITCARETCALLBACK,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITSTATE,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITSTATENOTIFYCALLBACK,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNSTATUSSTARTCALLBACK,
- 0,
- 0,
- 0,
- 0,
- 0,
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0,
- 0},
- {OFFSET_XNSTATUSDONECALLBACK,
- 0,
- 0,
- 0,
- 0,
- 0,
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0,
- 0},
- {OFFSET_XNSTATUSDRAWCALLBACK,
- 0,
- 0,
- 0,
- 0,
- 0,
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0,
- 0}
-};
-
-/* the quarks are separated from im_mode/ic_mode so those arrays
- * can be const.
- */
-static XrmQuark im_mode_quark[sizeof(im_mode) / sizeof(im_mode[0])];
-static XrmQuark ic_mode_quark[sizeof(ic_mode) / sizeof(ic_mode[0])];
-
-Private Bool
-_XimSetResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num,
- XIMResourceList resource,
- unsigned int num_resource,
- unsigned short id)
-{
- register int i;
- int len;
- XIMResourceList res;
-
- len = sizeof(XIMResource) * num_resource;
- if(!(res = Xcalloc(1, len))) {
- return False;
- }
-
- for(i = 0; i < num_resource; i++, id++) {
- res[i] = resource[i];
- res[i].id = id;
- }
-
- _XIMCompileResourceList(res, num_resource);
- *res_list = res;
- *list_num = num_resource;
- return True;
-}
-
-Public Bool
-_XimSetIMResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num)
-{
- return _XimSetResourceList(res_list, list_num,
- im_resources, XIMNumber(im_resources), 100);
-}
-
-Public Bool
-_XimSetICResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num)
-{
- return _XimSetResourceList(res_list, list_num,
- ic_resources, XIMNumber(ic_resources), 200);
-}
-
-Public Bool
-_XimSetInnerIMResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num)
-{
- return _XimSetResourceList(res_list, list_num,
- im_inner_resources, XIMNumber(im_inner_resources), 100);
-}
-
-Public Bool
-_XimSetInnerICResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num)
-{
- return _XimSetResourceList(res_list, list_num,
- ic_inner_resources, XIMNumber(ic_inner_resources), 200);
-}
-
-Private XIMResourceList
-_XimGetResourceListRecByMode(
- XIMResourceList res_list,
- unsigned int list_num,
- unsigned short mode)
-{
- register int i;
-
- for(i = 0; i < list_num; i++) {
- if (res_list[i].mode & mode) {
- return (XIMResourceList)&res_list[i];
- }
- }
- return (XIMResourceList)NULL;
-}
-
-Public Bool
-_XimCheckCreateICValues(
- XIMResourceList res_list,
- unsigned int list_num)
-{
- if (!_XimGetResourceListRecByMode(res_list, list_num, XIM_MODE_IC_CREATE)) {
- return True;
- }
- return False;
-}
-
-Public XIMResourceList
-_XimGetResourceListRecByQuark(
- XIMResourceList res_list,
- unsigned int list_num,
- XrmQuark quark)
-{
- register int i;
-
- for(i = 0; i < list_num; i++) {
- if (res_list[i].xrm_name == quark) {
- return (XIMResourceList)&res_list[i];
- }
- }
- return (XIMResourceList)NULL;
-}
-
-Public XIMResourceList
-_XimGetResourceListRec(
- XIMResourceList res_list,
- unsigned int list_num,
- const char *name)
-{
- XrmQuark quark = XrmStringToQuark(name);
-
- return _XimGetResourceListRecByQuark(res_list, list_num, quark);
-}
-
-Public char *
-_XimSetIMValueData(
- Xim im,
- XPointer top,
- XIMArg *values,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
-
- for(p = values; p->name != NULL; p++) {
- if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
- return p->value;
- }
- check = _XimCheckIMMode(res, XIM_SETIMVALUES);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if (check == XIM_CHECK_ERROR) {
- return p->value;
- }
-
- if(!_XimEncodeLocalIMAttr(res, top, p->value)) {
- return p->value;
- }
- }
- return NULL;
-}
-
-Public char *
-_XimGetIMValueData(
- Xim im,
- XPointer top,
- XIMArg *values,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
-
- for(p = values; p->name != NULL; p++) {
- if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
- return p->value;
- }
- check = _XimCheckIMMode(res, XIM_GETIMVALUES);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if (check == XIM_CHECK_ERROR) {
- return p->value;
- }
-
- if(!_XimDecodeLocalIMAttr(res, top, p->value)) {
- return p->value;
- }
- }
- return NULL;
-}
-
-Public void
-_XimSetIMMode(
- XIMResourceList res_list,
- unsigned int list_num)
-{
- XIMResourceList res;
- unsigned int n = XIMNumber(im_mode);
- register int i;
-
- for(i = 0; i < n; i++) {
- if(!(res = _XimGetResourceListRecByQuark(res_list,
- list_num, im_mode_quark[i]))) {
- continue;
- }
- res->mode = im_mode[i].mode;
- }
- return;
-}
-
-Private int
-_XimCheckSetIMDefaultsMode(
- XIMResourceList res)
-{
- if(res->mode & XIM_MODE_IM_DEFAULT) {
- return XIM_CHECK_VALID;
- }
- return XIM_CHECK_INVALID;
-}
-
-Private int
-_XimCheckSetIMValuesMode(
- XIMResourceList res)
-{
- if(res->mode & XIM_MODE_IM_SET) {
- return XIM_CHECK_VALID;
- }
- return XIM_CHECK_INVALID;
-}
-
-Private int
- _XimCheckGetIMValuesMode(
- XIMResourceList res)
-{
- if(res->mode & XIM_MODE_IM_GET) {
- return XIM_CHECK_VALID;
- }
- return XIM_CHECK_INVALID;
-}
-
-Public int
- _XimCheckIMMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(res->mode == 0) {
- return XIM_CHECK_INVALID;
- }
- if(mode & XIM_SETIMDEFAULTS) {
- return _XimCheckSetIMDefaultsMode(res);
- } else if (mode & XIM_SETIMVALUES) {
- return _XimCheckSetIMValuesMode(res);
- } else if (mode & XIM_GETIMVALUES) {
- return _XimCheckGetIMValuesMode(res);
- } else {
- return XIM_CHECK_ERROR;
- }
-}
-
-Public void
-_XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style)
-{
- XIMResourceList res;
- unsigned int n = XIMNumber(ic_mode);
- register int i;
- unsigned int pre_offset;
- unsigned int sts_offset;
-
- if(style & XIMPreeditArea) {
- pre_offset = XOffsetOf(XimICMode, preedit_area_mode);
- } else if(style & XIMPreeditCallbacks) {
- pre_offset = XOffsetOf(XimICMode, preedit_callback_mode);
- } else if(style & XIMPreeditPosition) {
- pre_offset = XOffsetOf(XimICMode, preedit_position_mode);
- } else if(style & XIMPreeditNothing) {
- pre_offset = XOffsetOf(XimICMode, preedit_nothing_mode);
- } else {
- pre_offset = XOffsetOf(XimICMode, preedit_none_mode);
- }
-
- if(style & XIMStatusArea) {
- sts_offset = XOffsetOf(XimICMode, status_area_mode);
- } else if(style & XIMStatusCallbacks) {
- sts_offset = XOffsetOf(XimICMode, status_callback_mode);
- } else if(style & XIMStatusNothing) {
- sts_offset = XOffsetOf(XimICMode, status_nothing_mode);
- } else {
- sts_offset = XOffsetOf(XimICMode, status_none_mode);
- }
-
- for(i = 0; i < n; i++) {
- if(!(res = _XimGetResourceListRecByQuark(res_list,
- list_num, ic_mode_quark[i]))) {
- continue;
- }
- res->mode = ( (*(unsigned short *)((char *)&ic_mode[i] + pre_offset))
- | (*(unsigned short *)((char *)&ic_mode[i] + sts_offset)));
- }
- return;
-}
-
-Private int
-_XimCheckSetICDefaultsMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode & XIM_PREEDIT_ATTR) {
- if(!(res->mode & XIM_MODE_PRE_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_PRE_CREATE) {
- return XIM_CHECK_ERROR;
- } else if (!(res->mode & XIM_MODE_PRE_DEFAULT)) {
- return XIM_CHECK_INVALID;
- }
-
- } else if(mode & XIM_STATUS_ATTR) {
- if(!(res->mode & XIM_MODE_STS_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_STS_CREATE) {
- return XIM_CHECK_ERROR;
- }
- if(!(res->mode & XIM_MODE_STS_DEFAULT)) {
- return XIM_CHECK_INVALID;
- }
-
- } else {
- if(!res->mode) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_IC_CREATE) {
- return XIM_CHECK_ERROR;
- }
- if(!(res->mode & XIM_MODE_IC_DEFAULT)) {
- return XIM_CHECK_INVALID;
- }
- }
- return XIM_CHECK_VALID;
-}
-
-Private int
-_XimCheckCreateICMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode & XIM_PREEDIT_ATTR) {
- if(!(res->mode & XIM_MODE_PRE_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_PRE_CREATE) {
- res->mode &= ~XIM_MODE_PRE_CREATE;
- } else if(res->mode & XIM_MODE_PRE_ONCE) {
- res->mode &= ~XIM_MODE_PRE_ONCE;
- } else if(res->mode & XIM_MODE_PRE_DEFAULT) {
- res->mode &= ~XIM_MODE_PRE_DEFAULT;
- } else if (!(res->mode & XIM_MODE_PRE_SET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else if(mode & XIM_STATUS_ATTR) {
- if(!(res->mode & XIM_MODE_STS_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_STS_CREATE) {
- res->mode &= ~XIM_MODE_STS_CREATE;
- } else if(res->mode & XIM_MODE_STS_ONCE) {
- res->mode &= ~XIM_MODE_STS_ONCE;
- } else if(res->mode & XIM_MODE_STS_DEFAULT) {
- res->mode &= ~XIM_MODE_STS_DEFAULT;
- } else if (!(res->mode & XIM_MODE_STS_SET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else {
- if(!res->mode) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_IC_CREATE) {
- res->mode &= ~XIM_MODE_IC_CREATE;
- } else if(res->mode & XIM_MODE_IC_ONCE) {
- res->mode &= ~XIM_MODE_IC_ONCE;
- } else if(res->mode & XIM_MODE_IC_DEFAULT) {
- res->mode &= ~XIM_MODE_IC_DEFAULT;
- } else if (!(res->mode & XIM_MODE_IC_SET)) {
- return XIM_CHECK_ERROR;
- }
- }
- return XIM_CHECK_VALID;
-}
-
-Private int
-_XimCheckSetICValuesMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode & XIM_PREEDIT_ATTR) {
- if(!(res->mode & XIM_MODE_PRE_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_PRE_ONCE) {
- res->mode &= ~XIM_MODE_PRE_ONCE;
- } else if(!(res->mode & XIM_MODE_PRE_SET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else if(mode & XIM_STATUS_ATTR) {
- if(!(res->mode & XIM_MODE_STS_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_STS_ONCE) {
- res->mode &= ~XIM_MODE_STS_ONCE;
- } else if(!(res->mode & XIM_MODE_STS_SET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else {
- if(!res->mode) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_IC_ONCE) {
- res->mode &= ~XIM_MODE_IC_ONCE;
- } else if(!(res->mode & XIM_MODE_IC_SET)) {
- return XIM_CHECK_ERROR;
- }
- }
- return XIM_CHECK_VALID;
-}
-
-Private int
-_XimCheckGetICValuesMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode & XIM_PREEDIT_ATTR) {
- if(!(res->mode & XIM_MODE_PRE_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(!(res->mode & XIM_MODE_PRE_GET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else if(mode & XIM_STATUS_ATTR) {
- if(!(res->mode & XIM_MODE_STS_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(!(res->mode & XIM_MODE_STS_GET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else {
- if(!res->mode) {
- return XIM_CHECK_INVALID;
- }
-
- if(!(res->mode & XIM_MODE_IC_GET)) {
- return XIM_CHECK_ERROR;
- }
- }
- return XIM_CHECK_VALID;
-}
-
-Public int
- _XimCheckICMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode &XIM_SETICDEFAULTS) {
- return _XimCheckSetICDefaultsMode(res, mode);
- } else if (mode & XIM_CREATEIC) {
- return _XimCheckCreateICMode(res, mode);
- } else if (mode & XIM_SETICVALUES) {
- return _XimCheckSetICValuesMode(res, mode);
- } else if (mode & XIM_GETICVALUES) {
- return _XimCheckGetICValuesMode(res, mode);
- } else {
- return XIM_CHECK_ERROR;
- }
-}
-
-Public Bool
-_XimSetLocalIMDefaults(
- Xim im,
- XPointer top,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- XimValueOffsetInfo info;
- unsigned int num;
- register int i;
- XIMResourceList res;
- int check;
-
- info = im_attr_info;
- num = XIMNumber(im_attr_info);
-
- for(i = 0; i < num; i++) {
- if((res = _XimGetResourceListRecByQuark( res_list, list_num,
- info[i].quark)) == (XIMResourceList)NULL) {
- return False;
- }
-
- check = _XimCheckIMMode(res, XIM_SETIMDEFAULTS);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if (check == XIM_CHECK_ERROR) {
- return False;
- }
-
- if(!info[i].defaults) {
- continue;
- }
- if(!(info[i].defaults(&info[i], top, (XPointer)NULL, 0))) {
- return False;
- }
- }
- return True;
-}
-
-Public Bool
-_XimSetICDefaults(
- Xic ic,
- XPointer top,
- unsigned long mode,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- unsigned int num;
- XimValueOffsetInfo info;
- register int i;
- XIMResourceList res;
- int check;
- XrmQuark pre_quark;
- XrmQuark sts_quark;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- if(mode & XIM_PREEDIT_ATTR) {
- info = ic_pre_attr_info;
- num = XIMNumber(ic_pre_attr_info);
- } else if(mode & XIM_STATUS_ATTR) {
- info = ic_sts_attr_info;
- num = XIMNumber(ic_sts_attr_info);
- } else {
- info = ic_attr_info;
- num = XIMNumber(ic_attr_info);
- }
-
- for(i = 0; i < num; i++) {
- if(info[i].quark == pre_quark) {
- if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
- (mode | XIM_PREEDIT_ATTR), res_list, list_num)) {
- return False;
- }
- } else if (info[i].quark == sts_quark) {
- if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
- (mode | XIM_STATUS_ATTR), res_list, list_num)) {
- return False;
- }
- } else {
- if(!(res = _XimGetResourceListRecByQuark(res_list, list_num,
- info[i].quark))) {
- return False;
- }
-
- check = _XimCheckICMode(res, mode);
- if (check == XIM_CHECK_INVALID) {
- continue;
- } else if (check == XIM_CHECK_ERROR) {
- return False;
- }
-
- if (!info[i].defaults) {
- continue;
- }
- if (!(info[i].defaults(&info[i], top, (XPointer)ic, mode))) {
- return False;
- }
- }
- }
- return True;
-}
-
-Private Bool
-_XimEncodeAttr(
- XimValueOffsetInfo info,
- unsigned int num,
- XIMResourceList res,
- XPointer top,
- XPointer val)
-{
- register int i;
-
- for(i = 0; i < num; i++ ) {
- if(info[i].quark == res->xrm_name) {
- if(!info[i].encode) {
- return False;
- }
- return (*info[i].encode)(&info[i], top, val);
- }
- }
- return False;
-}
-
-Public Bool
-_XimEncodeLocalIMAttr(
- XIMResourceList res,
- XPointer top,
- XPointer val)
-{
- return _XimEncodeAttr(im_attr_info, XIMNumber(im_attr_info),
- res, top, val);
-}
-
-Public Bool
-_XimEncodeLocalICAttr(
- Xic ic,
- XIMResourceList res,
- XPointer top,
- XIMArg *arg,
- unsigned long mode)
-{
- unsigned int num;
- XimValueOffsetInfo info;
-
- if(mode & XIM_PREEDIT_ATTR) {
- info = ic_pre_attr_info;
- num = XIMNumber(ic_pre_attr_info);
- } else if(mode & XIM_STATUS_ATTR) {
- info = ic_sts_attr_info;
- num = XIMNumber(ic_sts_attr_info);
- } else {
- info = ic_attr_info;
- num = XIMNumber(ic_attr_info);
- }
-
- return _XimEncodeAttr(info, num, res, top, arg->value);
-}
-
-Private Bool
-_XimEncodeLocalTopValue(
- Xic ic,
- XIMResourceList res,
- XPointer val,
- Bool flag)
-{
- XIMArg *p = (XIMArg *)val;
-
- if (res->xrm_name == XrmStringToQuark(XNClientWindow)) {
- ic->core.client_window = (Window)p->value;
- if (ic->core.focus_window == (Window)0)
- ic->core.focus_window = ic->core.client_window;
- if (flag) {
- _XRegisterFilterByType(ic->core.im->core.display,
- ic->core.focus_window,
- KeyPress, KeyRelease, _XimLocalFilter, (XPointer)ic);
- }
- } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
- if (ic->core.client_window) {
- if (flag) {
- _XUnregisterFilter(ic->core.im->core.display,
- ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
- }
- ic->core.focus_window = (Window)p->value;
- if (flag) {
- _XRegisterFilterByType(ic->core.im->core.display,
- ic->core.focus_window, KeyPress, KeyRelease,
- _XimLocalFilter, (XPointer)ic);
- }
- } else
- ic->core.focus_window = (Window)p->value;
- }
- return True;
-}
-
-Private Bool
-_XimEncodeLocalPreeditValue(
- Xic ic,
- XIMResourceList res,
- XPointer val)
-{
- XIMArg *p = (XIMArg *)val;
-
- if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
- XStandardColormap *colormap_ret;
- int count;
-
- if (!(XGetRGBColormaps(ic->core.im->core.display,
- ic->core.focus_window, &colormap_ret,
- &count, (Atom)p->value)))
- return False;
-
- Xfree(colormap_ret);
- }
- return True;
-}
-
-Private Bool
-_XimEncodeLocalStatusValue(
- Xic ic,
- XIMResourceList res,
- XPointer val)
-{
- XIMArg *p = (XIMArg *)val;
-
- if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
- XStandardColormap *colormap_ret;
- int count;
-
- if (!(XGetRGBColormaps(ic->core.im->core.display,
- ic->core.focus_window, &colormap_ret,
- &count, (Atom)p->value)))
- return False;
-
- Xfree(colormap_ret);
- }
- return True;
-}
-
-Public char *
-_XimSetICValueData(
- Xic ic,
- XPointer top,
- XIMResourceList res_list,
- unsigned int list_num,
- XIMArg *values,
- unsigned long mode,
- Bool flag)
-{
- register XIMArg *p;
- XIMResourceList res;
- char *name;
- int check;
- XrmQuark pre_quark;
- XrmQuark sts_quark;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- for(p = values; p->name != NULL; p++) {
- if((res = _XimGetResourceListRec(res_list, list_num,
- p->name)) == (XIMResourceList)NULL) {
- return p->name;
- }
- if(res->xrm_name == pre_quark) {
- if(((name = _XimSetICValueData(ic,
- (XPointer)(&((XimDefICValues *)top)->preedit_attr),
- res_list, list_num, (XIMArg *)p->value,
- (mode | XIM_PREEDIT_ATTR), flag)))) {
- return name;
- }
- } else if(res->xrm_name == sts_quark) {
- if(((name = _XimSetICValueData(ic,
- (XPointer)(&((XimDefICValues *)top)->status_attr),
- res_list, list_num, (XIMArg *)p->value,
- (mode | XIM_STATUS_ATTR), flag)))) {
- return name;
- }
- } else {
- check = _XimCheckICMode(res, mode);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if(check == XIM_CHECK_ERROR) {
- return p->name;
- }
-
- if(mode & XIM_PREEDIT_ATTR) {
- if (!_XimEncodeLocalPreeditValue(ic, res, (XPointer)p))
- return False;
- } else if(mode & XIM_STATUS_ATTR) {
- if (!_XimEncodeLocalStatusValue(ic, res, (XPointer)p))
- return False;
- } else {
- if (!_XimEncodeLocalTopValue(ic, res, (XPointer)p, flag))
- return False;
- }
- if(_XimEncodeLocalICAttr(ic, res, top, p, mode) == False) {
- return p->name;
- }
- }
- }
- return NULL;
-}
-
-Private Bool
-_XimCheckInputStyle(
- XIMStyles *styles,
- XIMStyle style)
-{
- int num = styles->count_styles;
- register int i;
-
- for(i = 0; i < num; i++) {
- if(styles->supported_styles[i] == style) {
- return True;
- }
- }
- return False;
-}
-
-Public Bool
-_XimCheckLocalInputStyle(
- Xic ic,
- XPointer top,
- XIMArg *values,
- XIMStyles *styles,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- XrmQuark quark = XrmStringToQuark(XNInputStyle);
- register XIMArg *p;
- XIMResourceList res;
-
- for(p = values; p && p->name != NULL; p++) {
- if(quark == XrmStringToQuark(p->name)) {
- if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
- return False;
- }
- if(!_XimEncodeLocalICAttr(ic, res, top, p, 0)) {
- return False;
- }
- if (_XimCheckInputStyle(styles,
- ((XimDefICValues *)top)->input_style)) {
- return True;
- }
- return False;
- }
- }
- return False;
-}
-
-Private Bool
-_XimDecodeAttr(
- XimValueOffsetInfo info,
- unsigned int num,
- XIMResourceList res,
- XPointer top,
- XPointer val)
-{
- register int i;
-
- for(i = 0; i < num; i++ ) {
- if(info[i].quark == res->xrm_name) {
- if(!info[i].decode) {
- return False;
- }
- return (*info[i].decode)(&info[i], top, val);
- }
- }
- return False;
-}
-
-Public Bool
-_XimDecodeLocalIMAttr(
- XIMResourceList res,
- XPointer top,
- XPointer val)
-{
- return _XimDecodeAttr(im_attr_info, XIMNumber(im_attr_info),
- res, top, val);
-}
-
-Public Bool
-_XimDecodeLocalICAttr(
- XIMResourceList res,
- XPointer top,
- XPointer val,
- unsigned long mode)
-{
- unsigned int num;
- XimValueOffsetInfo info;
-
- if(mode & XIM_PREEDIT_ATTR) {
- info = ic_pre_attr_info;
- num = XIMNumber(ic_pre_attr_info);
- } else if(mode & XIM_STATUS_ATTR) {
- info = ic_sts_attr_info;
- num = XIMNumber(ic_sts_attr_info);
- } else {
- info = ic_attr_info;
- num = XIMNumber(ic_attr_info);
- }
-
- return _XimDecodeAttr(info, num, res, top, val);
-}
-
-Public char *
-_XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list,
- unsigned int list_num, XIMArg *values, unsigned long mode)
-{
- register XIMArg *p;
- XIMResourceList res;
- char *name;
- int check;
- XrmQuark pre_quark;
- XrmQuark sts_quark;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- for(p = values; p->name != NULL; p++) {
- if((res = _XimGetResourceListRec(res_list, list_num,
- p->name)) == (XIMResourceList)NULL) {
- return p->name;
- }
- if(res->xrm_name == pre_quark) {
- if((name = _XimGetICValueData(ic,
- (XPointer)(&((XimDefICValues *)top)->preedit_attr),
- res_list, list_num, (XIMArg *)p->value,
- (mode | XIM_PREEDIT_ATTR)))) {
- return name;
- }
- } else if(res->xrm_name == sts_quark) {
- if((name = _XimGetICValueData(ic,
- (XPointer)(&((XimDefICValues *)top)->status_attr),
- res_list, list_num, (XIMArg *)p->value,
- (mode | XIM_STATUS_ATTR)))) {
- return name;
- }
- } else {
- check = _XimCheckICMode(res, mode);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if(check == XIM_CHECK_ERROR) {
- return p->name;
- }
-
- if(_XimDecodeLocalICAttr(res, top, p->value, mode) == False) {
- return p->name;
- }
- }
- }
- return NULL;
-}
-
-Public void
-_XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values)
-{
- bzero((char *)im_values, sizeof(XimDefIMValues));
-
- im_values->styles = im->core.styles;
- im_values->im_values_list = im->core.im_values_list;
- im_values->ic_values_list = im->core.ic_values_list;
- im_values->destroy_callback = im->core.destroy_callback;
- im_values->res_name = im->core.res_name;
- im_values->res_class = im->core.res_class;
- im_values->visible_position = im->core.visible_position;
-}
-
-Public void
-_XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values)
-{
- im->core.styles = im_values->styles;
- im->core.im_values_list = im_values->im_values_list;
- im->core.ic_values_list = im_values->ic_values_list;
- im->core.destroy_callback = im_values->destroy_callback;
- im->core.res_name = im_values->res_name;
- im->core.res_class = im_values->res_class;
- im->core.visible_position = im_values->visible_position;
-}
-
-Public void
-_XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values)
-{
- bzero((char *)ic_values, sizeof(XimDefICValues));
-
- ic_values->input_style = ic->core.input_style;
- ic_values->client_window = ic->core.client_window;
- ic_values->focus_window = ic->core.focus_window;
- ic_values->filter_events = ic->core.filter_events;
- ic_values->geometry_callback = ic->core.geometry_callback;
- ic_values->res_name = ic->core.res_name;
- ic_values->res_class = ic->core.res_class;
- ic_values->destroy_callback = ic->core.destroy_callback;
- ic_values->string_conversion_callback
- = ic->core.string_conversion_callback;
- ic_values->string_conversion = ic->core.string_conversion;
- ic_values->reset_state = ic->core.reset_state;
- ic_values->hotkey = ic->core.hotkey;
- ic_values->hotkey_state = ic->core.hotkey_state;
- ic_values->preedit_attr = ic->core.preedit_attr;
- ic_values->status_attr = ic->core.status_attr;
-}
-
-Public void
-_XimSetCurrentICValues(
- Xic ic,
- XimDefICValues *ic_values)
-{
- ic->core.input_style = ic_values->input_style;
- ic->core.client_window = ic_values->client_window;
- if (ic_values->focus_window)
- ic->core.focus_window = ic_values->focus_window;
- ic->core.filter_events = ic_values->filter_events;
- ic->core.geometry_callback = ic_values->geometry_callback;
- ic->core.res_name = ic_values->res_name;
- ic->core.res_class = ic_values->res_class;
- ic->core.destroy_callback = ic_values->destroy_callback;
- ic->core.string_conversion_callback
- = ic_values->string_conversion_callback;
- ic->core.string_conversion = ic_values->string_conversion;
- ic->core.reset_state = ic_values->reset_state;
- ic->core.hotkey = ic_values->hotkey;
- ic->core.hotkey_state = ic_values->hotkey_state;
- ic->core.preedit_attr = ic_values->preedit_attr;
- ic->core.status_attr = ic_values->status_attr;
-}
-
-Private void
-_XimInitialIMOffsetInfo(void)
-{
- unsigned int n = XIMNumber(im_attr_info);
- register int i;
-
- for(i = 0; i < n; i++) {
- im_attr_info[i].quark = XrmStringToQuark(GET_NAME(im_attr_info[i]));
- }
-}
-
-Private void
-_XimInitialICOffsetInfo(void)
-{
- unsigned int n;
- register int i;
-
- n = XIMNumber(ic_attr_info);
- for(i = 0; i < n; i++) {
- ic_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_attr_info[i]));
- }
-
- n = XIMNumber(ic_pre_attr_info);
- for(i = 0; i < n; i++) {
- ic_pre_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_pre_attr_info[i]));
- }
-
- n = XIMNumber(ic_sts_attr_info);
- for(i = 0; i < n; i++) {
- ic_sts_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_sts_attr_info[i]));
- }
-}
-
-Private void
-_XimInitialIMMode(void)
-{
- unsigned int n = XIMNumber(im_mode);
- register int i;
-
- for(i = 0; i < n; i++) {
- im_mode_quark[i] = XrmStringToQuark(GET_NAME(im_mode[i]));
- }
-}
-
-Private void
-_XimInitialICMode(void)
-{
- unsigned int n = XIMNumber(ic_mode);
- register int i;
-
- for(i = 0; i < n; i++) {
- ic_mode_quark[i] = XrmStringToQuark(GET_NAME(ic_mode[i]));
- }
-}
-
-Public void
-_XimInitialResourceInfo(void)
-{
- static Bool init_flag = False;
-
- if(init_flag == True) {
- return;
- }
- _XimInitialIMOffsetInfo();
- _XimInitialICOffsetInfo();
- _XimInitialIMMode();
- _XimInitialICMode();
- init_flag = True;
-}
+/******************************************************************
+
+ Copyright 1990, 1991, 1992,1993, 1994 by FUJITSU LIMITED
+ Copyright 1994 by Sony Corporation
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+and Sony Corporation not be used in advertising or publicity
+pertaining to distribution of the software without specific,
+written prior permission. FUJITSU LIMITED and Sony Corporation make
+no representations about the suitability of this software for any
+purpose. It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED AND SONY CORPORATION DISCLAIM ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU LIMITED AND
+SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+ Modifier: Makoto Wakamatsu Sony Corporation
+ makoto@sm.sony.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <unistd.h>
+#include <X11/Xlib.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "Xresource.h"
+
+#define GET_NAME(x) name_table + x.name_offset
+
+typedef struct _XimValueOffsetInfo {
+ unsigned short name_offset;
+ XrmQuark quark;
+ unsigned int offset;
+ Bool (*defaults)(
+ struct _XimValueOffsetInfo *, XPointer, XPointer, unsigned long
+ );
+ Bool (*encode)(
+ struct _XimValueOffsetInfo *, XPointer, XPointer
+ );
+ Bool (*decode)(
+ struct _XimValueOffsetInfo *, XPointer, XPointer
+ );
+} XimValueOffsetInfoRec, *XimValueOffsetInfo;
+
+#ifdef XIM_CONNECTABLE
+Private Bool
+_XimCheckBool(str)
+ char *str;
+{
+ if(!strcmp(str, "True") || !strcmp(str, "true") ||
+ !strcmp(str, "Yes") || !strcmp(str, "yes") ||
+ !strcmp(str, "ON") || !strcmp(str, "on"))
+ return True;
+ return False;
+}
+
+Public void
+_XimSetProtoResource(im)
+ Xim im;
+{
+ char res_name_buf[256];
+ char* res_name;
+ char res_class_buf[256];
+ char* res_class;
+ char* str_type;
+ XrmValue value;
+ XIMStyle preedit_style = 0;
+ XIMStyle status_style = 0;
+ XIMStyles* imstyles;
+ char* dotximdot = ".xim.";
+ char* ximdot = "xim.";
+ char* dotXimdot = ".Xim.";
+ char* Ximdot = "Xim.";
+
+ if (!im->core.rdb)
+ return;
+
+ if (strlen (im->core.res_name) < 200) res_name = res_name_buf;
+ else res_name = Xmalloc (strlen (im->core.res_name) + 50);
+ if (strlen (im->core.res_class) < 200) res_class = res_class_buf;
+ else res_class = Xmalloc (strlen (im->core.res_class) + 50);
+ /* pretend malloc always works */
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "useAuth");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "UseAuth");
+ bzero(&value, sizeof(XrmValue));
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(_XimCheckBool(value.addr)) {
+ MARK_USE_AUTHORIZATION_FUNC(im);
+ }
+ }
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "delaybinding");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "Delaybinding");
+ bzero(&value, sizeof(XrmValue));
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(_XimCheckBool(value.addr)) {
+ MARK_DELAYBINDABLE(im);
+ }
+ }
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "reconnect");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "Reconnect");
+ bzero(&value, sizeof(XrmValue));
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(_XimCheckBool(value.addr)) {
+ MARK_RECONNECTABLE(im);
+ }
+ }
+
+ if(!IS_CONNECTABLE(im)) {
+ if (res_name != res_name_buf) Xfree (res_name);
+ if (res_class != res_class_buf) Xfree (res_class);
+ return;
+ }
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "preeditDefaultStyle");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "PreeditDefaultStyle");
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(!strcmp(value.addr, "XIMPreeditArea"))
+ preedit_style = XIMPreeditArea;
+ else if(!strcmp(value.addr, "XIMPreeditCallbacks"))
+ preedit_style = XIMPreeditCallbacks;
+ else if(!strcmp(value.addr, "XIMPreeditPosition"))
+ preedit_style = XIMPreeditPosition;
+ else if(!strcmp(value.addr, "XIMPreeditNothing"))
+ preedit_style = XIMPreeditNothing;
+ else if(!strcmp(value.addr, "XIMPreeditNone"))
+ preedit_style = XIMPreeditNone;
+ }
+ if(!preedit_style)
+ preedit_style = XIMPreeditNothing;
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "statusDefaultStyle");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "StatusDefaultStyle");
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(!strcmp(value.addr, "XIMStatusArea"))
+ status_style = XIMStatusArea;
+ else if(!strcmp(value.addr, "XIMStatusCallbacks"))
+ status_style = XIMStatusCallbacks;
+ else if(!strcmp(value.addr, "XIMStatusNothing"))
+ status_style = XIMStatusNothing;
+ else if(!strcmp(value.addr, "XIMStatusNone"))
+ status_style = XIMStatusNone;
+ }
+ if(!status_style)
+ status_style = XIMStatusNothing;
+
+ if(!(imstyles = (XIMStyles *)Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){
+ if (res_name != res_name_buf) Xfree (res_name);
+ if (res_class != res_class_buf) Xfree (res_class);
+ return;
+ }
+ imstyles->count_styles = 1;
+ imstyles->supported_styles =
+ (XIMStyle *)((char *)imstyles + sizeof(XIMStyles));
+ imstyles->supported_styles[0] = preedit_style | status_style;
+ im->private.proto.default_styles = imstyles;
+ if (res_name != res_name_buf) Xfree (res_name);
+ if (res_class != res_class_buf) Xfree (res_class);
+}
+#endif /* XIM_CONNECTABLE */
+
+static const char name_table[] =
+ /* 0 */ XNQueryInputStyle"\0"
+ /* 16 */ XNClientWindow"\0"
+ /* 29 */ XNInputStyle"\0"
+ /* 40 */ XNFocusWindow"\0"
+ /* 52 */ XNResourceName"\0"
+ /* 65 */ XNResourceClass"\0"
+ /* 79 */ XNGeometryCallback"\0"
+ /* 96 */ XNDestroyCallback"\0"
+ /* 112 */ XNFilterEvents"\0"
+ /* 125 */ XNPreeditStartCallback"\0"
+ /* 146 */ XNPreeditDoneCallback"\0"
+ /* 166 */ XNPreeditDrawCallback"\0"
+ /* 186 */ XNPreeditCaretCallback"\0"
+ /* 207 */ XNPreeditStateNotifyCallback"\0"
+ /* 234 */ XNPreeditAttributes"\0"
+ /* 252 */ XNStatusStartCallback"\0"
+ /* 272 */ XNStatusDoneCallback"\0"
+ /* 291 */ XNStatusDrawCallback"\0"
+ /* 310 */ XNStatusAttributes"\0"
+ /* 327 */ XNArea"\0"
+ /* 332 */ XNAreaNeeded"\0"
+ /* 343 */ XNSpotLocation"\0"
+ /* 356 */ XNColormap"\0"
+ /* 365 */ XNStdColormap"\0"
+ /* 377 */ XNForeground"\0"
+ /* 388 */ XNBackground"\0"
+ /* 399 */ XNBackgroundPixmap"\0"
+ /* 416 */ XNFontSet"\0"
+ /* 424 */ XNLineSpace"\0"
+ /* 434 */ XNCursor"\0"
+ /* 441 */ XNQueryIMValuesList"\0"
+ /* 459 */ XNQueryICValuesList"\0"
+ /* 477 */ XNVisiblePosition"\0"
+ /* 493 */ XNStringConversionCallback"\0"
+ /* 518 */ XNStringConversion"\0"
+ /* 535 */ XNResetState"\0"
+ /* 546 */ XNHotKey"\0"
+ /* 553 */ XNHotKeyState"\0"
+ /* 565 */ XNPreeditState
+;
+
+#define OFFSET_XNQUERYINPUTSTYLE 0
+#define OFFSET_XNCLIENTWINDOW 16
+#define OFFSET_XNINPUTSTYLE 29
+#define OFFSET_XNFOCUSWINDOW 40
+#define OFFSET_XNRESOURCENAME 52
+#define OFFSET_XNRESOURCECLASS 65
+#define OFFSET_XNGEOMETRYCALLBACK 79
+#define OFFSET_XNDESTROYCALLBACK 96
+#define OFFSET_XNFILTEREVENTS 112
+#define OFFSET_XNPREEDITSTARTCALLBACK 125
+#define OFFSET_XNPREEDITDONECALLBACK 146
+#define OFFSET_XNPREEDITDRAWCALLBACK 166
+#define OFFSET_XNPREEDITCARETCALLBACK 186
+#define OFFSET_XNPREEDITSTATENOTIFYCALLBACK 207
+#define OFFSET_XNPREEDITATTRIBUTES 234
+#define OFFSET_XNSTATUSSTARTCALLBACK 252
+#define OFFSET_XNSTATUSDONECALLBACK 272
+#define OFFSET_XNSTATUSDRAWCALLBACK 291
+#define OFFSET_XNSTATUSATTRIBUTES 310
+#define OFFSET_XNAREA 327
+#define OFFSET_XNAREANEEDED 332
+#define OFFSET_XNSPOTLOCATION 343
+#define OFFSET_XNCOLORMAP 356
+#define OFFSET_XNSTDCOLORMAP 365
+#define OFFSET_XNFOREGROUND 377
+#define OFFSET_XNBACKGROUND 388
+#define OFFSET_XNBACKGROUNDPIXMAP 399
+#define OFFSET_XNFONTSET 416
+#define OFFSET_XNLINESPACE 424
+#define OFFSET_XNCURSOR 434
+#define OFFSET_XNQUERYIMVALUESLIST 441
+#define OFFSET_XNQUERYICVALUESLIST 459
+#define OFFSET_XNVISIBLEPOSITION 477
+#define OFFSET_XNSTRINGCONVERSIONCALLBACK 493
+#define OFFSET_XNSTRINGCONVERSION 518
+#define OFFSET_XNRESETSTATE 535
+#define OFFSET_XNHOTKEY 546
+#define OFFSET_XNHOTKEYSTATE 553
+#define OFFSET_XNPREEDITSTATE 565
+
+/* offsets into name_table */
+static const unsigned short supported_local_im_values_list[] = {
+ OFFSET_XNQUERYINPUTSTYLE,
+ OFFSET_XNRESOURCENAME,
+ OFFSET_XNRESOURCECLASS,
+ OFFSET_XNDESTROYCALLBACK,
+ OFFSET_XNQUERYIMVALUESLIST,
+ OFFSET_XNQUERYICVALUESLIST,
+ OFFSET_XNVISIBLEPOSITION
+};
+
+/* offsets into name_table */
+static const unsigned short supported_local_ic_values_list[] = {
+ OFFSET_XNINPUTSTYLE,
+ OFFSET_XNCLIENTWINDOW,
+ OFFSET_XNFOCUSWINDOW,
+ OFFSET_XNRESOURCENAME,
+ OFFSET_XNRESOURCECLASS,
+ OFFSET_XNGEOMETRYCALLBACK,
+ OFFSET_XNFILTEREVENTS,
+ OFFSET_XNDESTROYCALLBACK,
+ OFFSET_XNSTRINGCONVERSIONCALLBACK,
+ OFFSET_XNSTRINGCONVERSIONCALLBACK,
+ OFFSET_XNRESETSTATE,
+ OFFSET_XNHOTKEY,
+ OFFSET_XNHOTKEYSTATE,
+ OFFSET_XNPREEDITATTRIBUTES,
+ OFFSET_XNSTATUSATTRIBUTES,
+ OFFSET_XNAREA,
+ OFFSET_XNAREANEEDED,
+ OFFSET_XNSPOTLOCATION,
+ OFFSET_XNCOLORMAP,
+ OFFSET_XNSTDCOLORMAP,
+ OFFSET_XNFOREGROUND,
+ OFFSET_XNBACKGROUND,
+ OFFSET_XNBACKGROUNDPIXMAP,
+ OFFSET_XNFONTSET,
+ OFFSET_XNLINESPACE,
+ OFFSET_XNCURSOR,
+ OFFSET_XNPREEDITSTARTCALLBACK,
+ OFFSET_XNPREEDITDONECALLBACK,
+ OFFSET_XNPREEDITDRAWCALLBACK,
+ OFFSET_XNPREEDITCARETCALLBACK,
+ OFFSET_XNSTATUSSTARTCALLBACK,
+ OFFSET_XNSTATUSDONECALLBACK,
+ OFFSET_XNSTATUSDRAWCALLBACK,
+ OFFSET_XNPREEDITSTATE,
+ OFFSET_XNPREEDITSTATENOTIFYCALLBACK
+};
+
+static XIMStyle const supported_local_styles[] = {
+ XIMPreeditNone | XIMStatusNone,
+ XIMPreeditNothing | XIMStatusNothing,
+ 0 /* dummy */
+};
+
+Private Bool
+_XimDefaultStyles(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm, /* unused */
+ unsigned long mode) /* unused */
+{
+ XIMStyles *styles;
+ XIMStyles **out;
+ register int i;
+ unsigned int n;
+ int len;
+ XPointer tmp;
+
+ n = XIMNumber(supported_local_styles) - 1;
+ len = sizeof(XIMStyles) + sizeof(XIMStyle) * n;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ styles = (XIMStyles *)tmp;
+ if (n > 0) {
+ styles->count_styles = (unsigned short)n;
+ styles->supported_styles =
+ (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
+ for(i = 0; i < n; i++) {
+ styles->supported_styles[i] = supported_local_styles[i];
+ }
+ }
+
+ out = (XIMStyles **)((char *)top + info->offset);
+ *out = styles;
+ return True;
+}
+
+Private Bool
+_XimDefaultIMValues(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm, /* unused */
+ unsigned long mode) /* unused */
+{
+ XIMValuesList *values_list;
+ XIMValuesList **out;
+ register int i;
+ unsigned int n;
+ int len;
+ XPointer tmp;
+
+ n = XIMNumber(supported_local_im_values_list);
+ len = sizeof(XIMValuesList) + sizeof(char **) * n;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ values_list = (XIMValuesList *)tmp;
+ if (n > 0) {
+ values_list->count_values = (unsigned short)n;
+ values_list->supported_values
+ = (char **)((char *)tmp + sizeof(XIMValuesList));
+ for(i = 0; i < n; i++) {
+ values_list->supported_values[i] =
+ (char *)name_table + supported_local_im_values_list[i];
+ }
+ }
+
+ out = (XIMValuesList **)((char *)top + info->offset);
+ *out = values_list;
+ return True;
+}
+
+Private Bool
+_XimDefaultICValues(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm, /* unused */
+ unsigned long mode) /* unused */
+{
+ XIMValuesList *values_list;
+ XIMValuesList **out;
+ register int i;
+ unsigned int n;
+ int len;
+ XPointer tmp;
+
+ n = XIMNumber(supported_local_ic_values_list);
+ len = sizeof(XIMValuesList) + sizeof(char **) * n;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ values_list = (XIMValuesList *)tmp;
+ if (n > 0) {
+ values_list->count_values = (unsigned short)n;
+ values_list->supported_values
+ = (char **)((char *)tmp + sizeof(XIMValuesList));
+ for(i = 0; i < n; i++) {
+ values_list->supported_values[i] =
+ (char *)name_table + supported_local_ic_values_list[i];
+ }
+ }
+
+ out = (XIMValuesList **)((char *)top + info->offset);
+ *out = values_list;
+ return True;
+}
+
+Private Bool
+_XimDefaultVisiblePos(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm, /* unused */
+ unsigned long mode) /* unused */
+{
+ Bool *out;
+
+ out = (Bool *)((char *)top + info->offset);
+ *out = False;
+ return True;
+}
+
+Private Bool
+_XimDefaultFocusWindow(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Window *out;
+
+ if(ic->core.client_window == (Window)NULL) {
+ return True;
+ }
+
+ out = (Window *)((char *)top + info->offset);
+ *out = ic->core.client_window;
+ return True;
+}
+
+Private Bool
+_XimDefaultResName(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ char **out;
+
+ if(im->core.res_name == (char *)NULL) {
+ return True;
+ }
+
+ out = (char **)((char *)top + info->offset);
+ *out = im->core.res_name;
+ return True;
+}
+
+Private Bool
+_XimDefaultResClass(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ char **out;
+
+ if(im->core.res_class == (char *)NULL) {
+ return True;
+ }
+
+ out = (char **)((char *)top + info->offset);
+ *out = im->core.res_class;
+ return True;
+}
+
+Private Bool
+_XimDefaultDestroyCB(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ XIMCallback *out;
+
+ out = (XIMCallback *)((char *)top + info->offset);
+ *out = im->core.destroy_callback;
+ return True;
+}
+
+Private Bool
+_XimDefaultResetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ XIMResetState *out;
+
+ out = (XIMResetState *)((char *)top + info->offset);
+ *out = XIMInitialState;
+ return True;
+}
+
+Private Bool
+_XimDefaultHotKeyState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ XIMHotKeyState *out;
+
+ out = (XIMHotKeyState *)((char *)top + info->offset);
+ *out = XIMHotKeyStateOFF;
+ return True;
+}
+
+Private Bool
+_XimDefaultArea(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ Window root_return;
+ int x_return, y_return;
+ unsigned int width_return, height_return;
+ unsigned int border_width_return;
+ unsigned int depth_return;
+ XRectangle area;
+ XRectangle *out;
+
+ if(ic->core.focus_window == (Window)NULL) {
+ return True;
+ }
+ if(XGetGeometry(im->core.display, (Drawable)ic->core.focus_window,
+ &root_return, &x_return, &y_return, &width_return,
+ &height_return, &border_width_return, &depth_return)
+ == (Status)Success) {
+ return True;
+ }
+ area.x = 0;
+ area.y = 0;
+ area.width = width_return;
+ area.height = height_return;
+
+ out = (XRectangle *)((char *)top + info->offset);
+ *out = area;
+ return True;
+}
+
+Private Bool
+_XimDefaultColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ XWindowAttributes win_attr;
+ Colormap *out;
+
+ if(ic->core.client_window == (Window)NULL) {
+ return True;
+ }
+ if(XGetWindowAttributes(im->core.display, ic->core.client_window,
+ &win_attr) == (Status)Success) {
+ return True;
+ }
+
+ out = (Colormap *)((char *)top + info->offset);
+ *out = win_attr.colormap;
+ return True;
+}
+
+Private Bool
+_XimDefaultStdColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Atom *out;
+
+ out = (Atom *)((char *)top + info->offset);
+ *out = (Atom)0;
+ return True;
+}
+
+Private Bool
+_XimDefaultFg(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ unsigned long fg;
+ unsigned long *out;
+
+ fg = WhitePixel(im->core.display, DefaultScreen(im->core.display));
+ out = (unsigned long *)((char *)top + info->offset);
+ *out = fg;
+ return True;
+}
+
+Private Bool
+_XimDefaultBg(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ unsigned long bg;
+ unsigned long *out;
+
+ bg = BlackPixel(im->core.display, DefaultScreen(im->core.display));
+ out = (unsigned long *)((char *)top + info->offset);
+ *out = bg;
+ return True;
+}
+
+Private Bool
+_XimDefaultBgPixmap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Pixmap *out;
+
+ out = (Pixmap *)((char *)top + info->offset);
+ *out = (Pixmap)0;
+ return True;
+}
+
+Private Bool
+_XimDefaultFontSet(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ XFontSet *out;
+
+ out = (XFontSet *)((char *)top + info->offset);
+ *out = 0;
+ return True;
+}
+
+Private Bool
+_XimDefaultLineSpace(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ XFontSet fontset;
+ XFontSetExtents *fset_extents;
+ int line_space = 0;
+ int *out;
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ fontset = ic->core.preedit_attr.fontset;
+ } else if(mode & XIM_STATUS_ATTR) {
+ fontset = ic->core.status_attr.fontset;
+ } else {
+ return True;
+ }
+ if (fontset) {
+ fset_extents = XExtentsOfFontSet(fontset);
+ line_space = fset_extents->max_logical_extent.height;
+ }
+ out = (int *)((char *)top + info->offset);
+ *out = line_space;
+ return True;
+}
+
+Private Bool
+_XimDefaultCursor(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Cursor *out;
+
+ out = (Cursor *)((char *)top + info->offset);
+ *out = (Cursor)0;
+ return True;
+}
+
+Private Bool
+_XimDefaultPreeditState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ XIMPreeditState *out;
+
+ out = (XIMPreeditState *)((char *)top + info->offset);
+ *out = XIMPreeditDisable;
+ return True;
+}
+
+Private Bool
+_XimDefaultNest(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ return True;
+}
+
+Private Bool
+_XimEncodeCallback(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMCallback *out;
+
+ out = (XIMCallback *)((char *)top + info->offset);
+ *out = *((XIMCallback *)val);
+ return True;
+}
+
+Private Bool
+_XimEncodeString(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ char *string;
+ char **out;
+
+ if(val == (XPointer)NULL) {
+ return False;
+ }
+ if (!(string = strdup((char *)val))) {
+ return False;
+ }
+
+ out = (char **)((char *)top + info->offset);
+ if(*out) {
+ Xfree(*out);
+ }
+ *out = string;
+ return True;
+}
+
+Private Bool
+_XimEncodeStyle(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMStyle *out;
+
+ out = (XIMStyle *)((char *)top + info->offset);
+ *out = (XIMStyle)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeWindow(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Window *out;
+
+ out = (Window *)((char *)top + info->offset);
+ *out = (Window)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeStringConv(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ /*
+ * Not yet
+ */
+ return True;
+}
+
+Private Bool
+_XimEncodeResetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMResetState *out;
+
+ out = (XIMResetState *)((char *)top + info->offset);
+ *out = (XIMResetState)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeHotKey(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)val;
+ XIMHotKeyTriggers **out;
+ XIMHotKeyTriggers *key_list;
+ XIMHotKeyTrigger *key;
+ XPointer tmp;
+ int num;
+ int len;
+ register int i;
+
+ if(hotkey == (XIMHotKeyTriggers *)NULL) {
+ return True;
+ }
+
+ if((num = hotkey->num_hot_key) == 0) {
+ return True;
+ }
+
+ len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
+ if(!(tmp = (XPointer)Xmalloc(len))) {
+ return False;
+ }
+
+ key_list = (XIMHotKeyTriggers *)tmp;
+ key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
+
+ for(i = 0; i < num; i++) {
+ key[i] = hotkey->key[i];
+ }
+
+ key_list->num_hot_key = num;
+ key_list->key = key;
+
+ out = (XIMHotKeyTriggers **)((char *)top + info->offset);
+ *out = key_list;
+ return True;
+}
+
+Private Bool
+_XimEncodeHotKetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMHotKeyState *out;
+
+ out = (XIMHotKeyState *)((char *)top + info->offset);
+ *out = (XIMHotKeyState)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeRectangle(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XRectangle *out;
+
+ out = (XRectangle *)((char *)top + info->offset);
+ *out = *((XRectangle *)val);
+ return True;
+}
+
+Private Bool
+_XimEncodeSpot(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XPoint *out;
+
+ out = (XPoint *)((char *)top + info->offset);
+ *out = *((XPoint *)val);
+ return True;
+}
+
+Private Bool
+_XimEncodeColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Colormap *out;
+
+ out = (Colormap *)((char *)top + info->offset);
+ *out = (Colormap)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeStdColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Atom *out;
+
+ out = (Atom *)((char *)top + info->offset);
+ *out = (Atom)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeLong(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ unsigned long *out;
+
+ out = (unsigned long *)((char *)top + info->offset);
+ *out = (unsigned long)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeBgPixmap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Pixmap *out;
+
+ out = (Pixmap *)((char *)top + info->offset);
+ *out = (Pixmap)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeFontSet(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XFontSet *out;
+
+ out = (XFontSet *)((char *)top + info->offset);
+ *out = (XFontSet)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeLineSpace(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ int *out;
+
+ out = (int *)((char *)top + info->offset);
+ *out = (long)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeCursor(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Cursor *out;
+
+ out = (Cursor *)((char *)top + info->offset);
+ *out = (Cursor)val;
+ return True;
+}
+
+Private Bool
+_XimEncodePreeditState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMPreeditState *out;
+
+ out = (XIMPreeditState *)((char *)top + info->offset);
+ *out = (XIMPreeditState)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeNest(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ return True;
+}
+
+Private Bool
+_XimDecodeStyles(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMStyles *styles;
+ XIMStyles *out;
+ register int i;
+ unsigned int num;
+ int len;
+ XPointer tmp;
+
+ if(val == (XPointer)NULL) {
+ return False;
+ }
+
+ styles = *((XIMStyles **)((char *)top + info->offset));
+ num = styles->count_styles;
+
+ len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ out = (XIMStyles *)tmp;
+ if(num >0) {
+ out->count_styles = (unsigned short)num;
+ out->supported_styles = (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
+
+ for(i = 0; i < num; i++) {
+ out->supported_styles[i] = styles->supported_styles[i];
+ }
+ }
+ *((XIMStyles **)val) = out;
+ return True;
+}
+
+Private Bool
+_XimDecodeValues(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMValuesList *values_list;
+ XIMValuesList *out;
+ register int i;
+ unsigned int num;
+ int len;
+ XPointer tmp;
+
+ if(val == (XPointer)NULL) {
+ return False;
+ }
+
+ values_list = *((XIMValuesList **)((char *)top + info->offset));
+ num = values_list->count_values;
+
+ len = sizeof(XIMValuesList) + sizeof(char **) * num;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ out = (XIMValuesList *)tmp;
+ if(num) {
+ out->count_values = (unsigned short)num;
+ out->supported_values = (char **)((char *)tmp + sizeof(XIMValuesList));
+
+ for(i = 0; i < num; i++) {
+ out->supported_values[i] = values_list->supported_values[i];
+ }
+ }
+ *((XIMValuesList **)val) = out;
+ return True;
+}
+
+Private Bool
+_XimDecodeCallback(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMCallback *in;
+ XIMCallback *callback;
+
+ in = (XIMCallback *)((char *)top + info->offset);
+ if(!(callback = (XIMCallback *)Xmalloc(sizeof(XIMCallback)))) {
+ return False;
+ }
+ callback->client_data = in->client_data;
+ callback->callback = in->callback;
+
+ *((XIMCallback **)val) = callback;
+ return True;
+}
+
+Private Bool
+_XimDecodeString(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ char *in;
+ char *string;
+
+ in = *((char **)((char *)top + info->offset));
+ if (in != NULL) {
+ string = strdup(in);
+ } else {
+ string = Xcalloc(1, 1); /* strdup("") */
+ }
+ if (string == NULL) {
+ return False;
+ }
+ *((char **)val) = string;
+ return True;
+}
+
+Private Bool
+_XimDecodeBool(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Bool *in;
+
+ in = (Bool *)((char *)top + info->offset);
+ *((Bool *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeStyle(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMStyle *in;
+
+ in = (XIMStyle *)((char *)top + info->offset);
+ *((XIMStyle *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeWindow(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Window *in;
+
+ in = (Window *)((char *)top + info->offset);
+ *((Window *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeStringConv(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ /*
+ * Not yet
+ */
+ return True;
+}
+
+Private Bool
+_XimDecodeResetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMResetState *in;
+
+ in = (XIMResetState *)((char *)top + info->offset);
+ *((XIMResetState *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeHotKey(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMHotKeyTriggers *in;
+ XIMHotKeyTriggers *hotkey;
+ XIMHotKeyTrigger *key;
+ XPointer tmp;
+ int num;
+ int len;
+ register int i;
+
+ in = *((XIMHotKeyTriggers **)((char *)top + info->offset));
+ num = in->num_hot_key;
+ len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
+ if(!(tmp = (XPointer)Xmalloc(len))) {
+ return False;
+ }
+
+ hotkey = (XIMHotKeyTriggers *)tmp;
+ key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
+
+ for(i = 0; i < num; i++) {
+ key[i] = in->key[i];
+ }
+ hotkey->num_hot_key = num;
+ hotkey->key = key;
+
+ *((XIMHotKeyTriggers **)val) = hotkey;
+ return True;
+}
+
+Private Bool
+_XimDecodeHotKetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMHotKeyState *in;
+
+ in = (XIMHotKeyState *)((char *)top + info->offset);
+ *((XIMHotKeyState *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeRectangle(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XRectangle *in;
+ XRectangle *rect;
+
+ in = (XRectangle *)((char *)top + info->offset);
+ if(!(rect = (XRectangle *)Xmalloc(sizeof(XRectangle)))) {
+ return False;
+ }
+ *rect = *in;
+ *((XRectangle **)val) = rect;
+ return True;
+}
+
+Private Bool
+_XimDecodeSpot(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XPoint *in;
+ XPoint *spot;
+
+ in = (XPoint *)((char *)top + info->offset);
+ if(!(spot = (XPoint *)Xmalloc(sizeof(XPoint)))) {
+ return False;
+ }
+ *spot = *in;
+ *((XPoint **)val) = spot;
+ return True;
+}
+
+Private Bool
+_XimDecodeColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Colormap *in;
+
+ in = (Colormap *)((char *)top + info->offset);
+ *((Colormap *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeStdColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Atom *in;
+
+ in = (Atom *)((char *)top + info->offset);
+ *((Atom *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeLong(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ unsigned long *in;
+
+ in = (unsigned long *)((char *)top + info->offset);
+ *((unsigned long *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeBgPixmap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Pixmap *in;
+
+ in = (Pixmap *)((char *)top + info->offset);
+ *((Pixmap *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeFontSet(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XFontSet *in;
+
+ in = (XFontSet *)((char *)top + info->offset);
+ *((XFontSet *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeLineSpace(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ int *in;
+
+ in = (int *)((char *)top + info->offset);
+ *((int *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeCursor(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Cursor *in;
+
+ in = (Cursor *)((char *)top + info->offset);
+ *((Cursor *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodePreeditState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMPreeditState *in;
+
+ in = (XIMPreeditState *)((char *)top + info->offset);
+ *((XIMPreeditState *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeNest(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ return True;
+}
+
+static XIMResource im_resources[] = {
+ {XNQueryInputStyle, 0, XimType_XIMStyles, 0, 0, 0},
+ {XNDestroyCallback, 0, 0, 0, 0, 0},
+ {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
+ {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
+ {XNQueryIMValuesList, 0, 0, 0, 0, 0},
+ {XNQueryICValuesList, 0, 0, 0, 0, 0},
+ {XNVisiblePosition, 0, 0, 0, 0, 0}
+};
+
+static XIMResource im_inner_resources[] = {
+ {XNDestroyCallback, 0, 0, 0, 0, 0},
+ {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
+ {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
+ {XNQueryIMValuesList, 0, 0, 0, 0, 0},
+ {XNQueryICValuesList, 0, 0, 0, 0, 0},
+ {XNVisiblePosition, 0, 0, 0, 0, 0}
+};
+
+static XIMResource ic_resources[] = {
+ {XNInputStyle, 0, XimType_CARD32, 0, 0, 0},
+ {XNClientWindow, 0, XimType_Window, 0, 0, 0},
+ {XNFocusWindow, 0, XimType_Window, 0, 0, 0},
+ {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
+ {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
+ {XNGeometryCallback, 0, 0, 0, 0, 0},
+ {XNFilterEvents, 0, XimType_CARD32, 0, 0, 0},
+ {XNDestroyCallback, 0, 0, 0, 0, 0},
+ {XNStringConversionCallback, 0, 0, 0, 0, 0},
+ {XNStringConversion, 0, XimType_XIMStringConversion,0, 0, 0},
+ {XNResetState, 0, 0, 0, 0, 0},
+ {XNHotKey, 0, XimType_XIMHotKeyTriggers,0, 0, 0},
+ {XNHotKeyState, 0, XimType_XIMHotKeyState, 0, 0, 0},
+ {XNPreeditAttributes, 0, XimType_NEST, 0, 0, 0},
+ {XNStatusAttributes, 0, XimType_NEST, 0, 0, 0},
+ {XNArea, 0, XimType_XRectangle, 0, 0, 0},
+ {XNAreaNeeded, 0, XimType_XRectangle, 0, 0, 0},
+ {XNSpotLocation, 0, XimType_XPoint, 0, 0, 0},
+ {XNColormap, 0, XimType_CARD32, 0, 0, 0},
+ {XNStdColormap, 0, XimType_CARD32, 0, 0, 0},
+ {XNForeground, 0, XimType_CARD32, 0, 0, 0},
+ {XNBackground, 0, XimType_CARD32, 0, 0, 0},
+ {XNBackgroundPixmap, 0, XimType_CARD32, 0, 0, 0},
+ {XNFontSet, 0, XimType_XFontSet, 0, 0, 0},
+ {XNLineSpace, 0, XimType_CARD32, 0, 0, 0},
+ {XNCursor, 0, XimType_CARD32, 0, 0, 0},
+ {XNPreeditStartCallback, 0, 0, 0, 0, 0},
+ {XNPreeditDoneCallback, 0, 0, 0, 0, 0},
+ {XNPreeditDrawCallback, 0, 0, 0, 0, 0},
+ {XNPreeditCaretCallback, 0, 0, 0, 0, 0},
+ {XNStatusStartCallback, 0, 0, 0, 0, 0},
+ {XNStatusDoneCallback, 0, 0, 0, 0, 0},
+ {XNStatusDrawCallback, 0, 0, 0, 0, 0},
+ {XNPreeditState, 0, 0, 0, 0, 0},
+ {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0},
+};
+
+static XIMResource ic_inner_resources[] = {
+ {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
+ {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
+ {XNGeometryCallback, 0, 0, 0, 0, 0},
+ {XNDestroyCallback, 0, 0, 0, 0, 0},
+ {XNStringConversionCallback, 0, 0, 0, 0, 0},
+ {XNPreeditStartCallback, 0, 0, 0, 0, 0},
+ {XNPreeditDoneCallback, 0, 0, 0, 0, 0},
+ {XNPreeditDrawCallback, 0, 0, 0, 0, 0},
+ {XNPreeditCaretCallback, 0, 0, 0, 0, 0},
+ {XNStatusStartCallback, 0, 0, 0, 0, 0},
+ {XNStatusDoneCallback, 0, 0, 0, 0, 0},
+ {XNStatusDrawCallback, 0, 0, 0, 0, 0},
+ {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0},
+};
+
+static XimValueOffsetInfoRec im_attr_info[] = {
+ {OFFSET_XNQUERYINPUTSTYLE, 0,
+ XOffsetOf(XimDefIMValues, styles),
+ _XimDefaultStyles, NULL, _XimDecodeStyles},
+
+ {OFFSET_XNDESTROYCALLBACK, 0,
+ XOffsetOf(XimDefIMValues, destroy_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNRESOURCENAME, 0,
+ XOffsetOf(XimDefIMValues, res_name),
+ NULL, _XimEncodeString, _XimDecodeString},
+
+ {OFFSET_XNRESOURCECLASS, 0,
+ XOffsetOf(XimDefIMValues, res_class),
+ NULL, _XimEncodeString, _XimDecodeString},
+
+ {OFFSET_XNQUERYIMVALUESLIST, 0,
+ XOffsetOf(XimDefIMValues, im_values_list),
+ _XimDefaultIMValues, NULL, _XimDecodeValues},
+
+ {OFFSET_XNQUERYICVALUESLIST, 0,
+ XOffsetOf(XimDefIMValues, ic_values_list),
+ _XimDefaultICValues, NULL, _XimDecodeValues},
+
+ {OFFSET_XNVISIBLEPOSITION, 0,
+ XOffsetOf(XimDefIMValues, visible_position),
+ _XimDefaultVisiblePos, NULL, _XimDecodeBool}
+};
+
+static XimValueOffsetInfoRec ic_attr_info[] = {
+ {OFFSET_XNINPUTSTYLE, 0,
+ XOffsetOf(XimDefICValues, input_style),
+ NULL, _XimEncodeStyle, _XimDecodeStyle},
+
+ {OFFSET_XNCLIENTWINDOW, 0,
+ XOffsetOf(XimDefICValues, client_window),
+ NULL, _XimEncodeWindow, _XimDecodeWindow},
+
+ {OFFSET_XNFOCUSWINDOW, 0,
+ XOffsetOf(XimDefICValues, focus_window),
+ _XimDefaultFocusWindow, _XimEncodeWindow, _XimDecodeWindow},
+
+ {OFFSET_XNRESOURCENAME, 0,
+ XOffsetOf(XimDefICValues, res_name),
+ _XimDefaultResName, _XimEncodeString, _XimDecodeString},
+
+ {OFFSET_XNRESOURCECLASS, 0,
+ XOffsetOf(XimDefICValues, res_class),
+ _XimDefaultResClass, _XimEncodeString, _XimDecodeString},
+
+ {OFFSET_XNGEOMETRYCALLBACK, 0,
+ XOffsetOf(XimDefICValues, geometry_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNFILTEREVENTS, 0,
+ XOffsetOf(XimDefICValues, filter_events),
+ NULL, NULL, _XimDecodeLong},
+
+ {OFFSET_XNDESTROYCALLBACK, 0,
+ XOffsetOf(XimDefICValues, destroy_callback),
+ _XimDefaultDestroyCB, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNSTRINGCONVERSIONCALLBACK, 0,
+ XOffsetOf(XimDefICValues, string_conversion_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNSTRINGCONVERSION, 0,
+ XOffsetOf(XimDefICValues, string_conversion),
+ NULL, _XimEncodeStringConv, _XimDecodeStringConv},
+
+ {OFFSET_XNRESETSTATE, 0,
+ XOffsetOf(XimDefICValues, reset_state),
+ _XimDefaultResetState, _XimEncodeResetState, _XimDecodeResetState},
+
+ {OFFSET_XNHOTKEY, 0,
+ XOffsetOf(XimDefICValues, hotkey),
+ NULL, _XimEncodeHotKey, _XimDecodeHotKey},
+
+ {OFFSET_XNHOTKEYSTATE, 0,
+ XOffsetOf(XimDefICValues, hotkey_state),
+ _XimDefaultHotKeyState, _XimEncodeHotKetState, _XimDecodeHotKetState},
+
+ {OFFSET_XNPREEDITATTRIBUTES, 0,
+ XOffsetOf(XimDefICValues, preedit_attr),
+ _XimDefaultNest, _XimEncodeNest, _XimDecodeNest},
+
+ {OFFSET_XNSTATUSATTRIBUTES, 0,
+ XOffsetOf(XimDefICValues, status_attr),
+ _XimDefaultNest, _XimEncodeNest, _XimDecodeNest},
+};
+
+static XimValueOffsetInfoRec ic_pre_attr_info[] = {
+ {OFFSET_XNAREA, 0,
+ XOffsetOf(ICPreeditAttributes, area),
+ _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle},
+
+ {OFFSET_XNAREANEEDED, 0,
+ XOffsetOf(ICPreeditAttributes, area_needed),
+ NULL, _XimEncodeRectangle, _XimDecodeRectangle},
+
+ {OFFSET_XNSPOTLOCATION, 0,
+ XOffsetOf(ICPreeditAttributes, spot_location),
+ NULL, _XimEncodeSpot, _XimDecodeSpot},
+
+ {OFFSET_XNCOLORMAP, 0,
+ XOffsetOf(ICPreeditAttributes, colormap),
+ _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap},
+
+ {OFFSET_XNSTDCOLORMAP, 0,
+ XOffsetOf(ICPreeditAttributes, std_colormap),
+ _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap},
+
+ {OFFSET_XNFOREGROUND, 0,
+ XOffsetOf(ICPreeditAttributes, foreground),
+ _XimDefaultFg, _XimEncodeLong, _XimDecodeLong},
+
+ {OFFSET_XNBACKGROUND, 0,
+ XOffsetOf(ICPreeditAttributes, background),
+ _XimDefaultBg, _XimEncodeLong, _XimDecodeLong},
+
+ {OFFSET_XNBACKGROUNDPIXMAP, 0,
+ XOffsetOf(ICPreeditAttributes, background_pixmap),
+ _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap},
+
+ {OFFSET_XNFONTSET, 0,
+ XOffsetOf(ICPreeditAttributes, fontset),
+ _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet},
+
+ {OFFSET_XNLINESPACE, 0,
+ XOffsetOf(ICPreeditAttributes, line_spacing),
+ _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace},
+
+ {OFFSET_XNCURSOR, 0,
+ XOffsetOf(ICPreeditAttributes, cursor),
+ _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor},
+
+ {OFFSET_XNPREEDITSTARTCALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, start_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNPREEDITDONECALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, done_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNPREEDITDRAWCALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, draw_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNPREEDITCARETCALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, caret_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNPREEDITSTATE, 0,
+ XOffsetOf(ICPreeditAttributes, preedit_state),
+ _XimDefaultPreeditState, _XimEncodePreeditState,_XimDecodePreeditState},
+
+ {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, state_notify_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+};
+
+static XimValueOffsetInfoRec ic_sts_attr_info[] = {
+ {OFFSET_XNAREA, 0,
+ XOffsetOf(ICStatusAttributes, area),
+ _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle},
+
+ {OFFSET_XNAREANEEDED, 0,
+ XOffsetOf(ICStatusAttributes, area_needed),
+ NULL, _XimEncodeRectangle, _XimDecodeRectangle},
+
+ {OFFSET_XNCOLORMAP, 0,
+ XOffsetOf(ICStatusAttributes, colormap),
+ _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap},
+
+ {OFFSET_XNSTDCOLORMAP, 0,
+ XOffsetOf(ICStatusAttributes, std_colormap),
+ _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap},
+
+ {OFFSET_XNFOREGROUND, 0,
+ XOffsetOf(ICStatusAttributes, foreground),
+ _XimDefaultFg, _XimEncodeLong, _XimDecodeLong},
+
+ {OFFSET_XNBACKGROUND, 0,
+ XOffsetOf(ICStatusAttributes, background),
+ _XimDefaultBg, _XimEncodeLong, _XimDecodeLong},
+
+ {OFFSET_XNBACKGROUNDPIXMAP, 0,
+ XOffsetOf(ICStatusAttributes, background_pixmap),
+ _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap},
+
+ {OFFSET_XNFONTSET, 0,
+ XOffsetOf(ICStatusAttributes, fontset),
+ _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet},
+
+ {OFFSET_XNLINESPACE, 0,
+ XOffsetOf(ICStatusAttributes, line_spacing),
+ _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace},
+
+ {OFFSET_XNCURSOR, 0,
+ XOffsetOf(ICStatusAttributes, cursor),
+ _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor},
+
+ {OFFSET_XNSTATUSSTARTCALLBACK, 0,
+ XOffsetOf(ICStatusAttributes, start_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNSTATUSDONECALLBACK, 0,
+ XOffsetOf(ICStatusAttributes, done_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNSTATUSDRAWCALLBACK, 0,
+ XOffsetOf(ICStatusAttributes, draw_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback}
+};
+
+typedef struct _XimIMMode {
+ unsigned short name_offset;
+ unsigned short mode;
+} XimIMMode;
+
+static const XimIMMode im_mode[] = {
+ {OFFSET_XNQUERYINPUTSTYLE,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
+ {OFFSET_XNDESTROYCALLBACK,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
+ {OFFSET_XNRESOURCENAME,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
+ {OFFSET_XNRESOURCECLASS,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
+ {OFFSET_XNQUERYIMVALUESLIST,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
+ {OFFSET_XNQUERYICVALUESLIST,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
+ {OFFSET_XNVISIBLEPOSITION,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}
+};
+
+typedef struct _XimICMode {
+ unsigned short name_offset;
+ unsigned short preedit_callback_mode;
+ unsigned short preedit_position_mode;
+ unsigned short preedit_area_mode;
+ unsigned short preedit_nothing_mode;
+ unsigned short preedit_none_mode;
+ unsigned short status_callback_mode;
+ unsigned short status_area_mode;
+ unsigned short status_nothing_mode;
+ unsigned short status_none_mode;
+} XimICMode;
+
+static const XimICMode ic_mode[] = {
+ {OFFSET_XNINPUTSTYLE,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET)},
+ {OFFSET_XNCLIENTWINDOW,
+ (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
+ 0,
+ (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNFOCUSWINDOW,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNRESOURCENAME,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNRESOURCECLASS,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNGEOMETRYCALLBACK,
+ 0,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0},
+ {OFFSET_XNFILTEREVENTS,
+ XIM_MODE_PRE_GET,
+ XIM_MODE_PRE_GET,
+ XIM_MODE_PRE_GET,
+ XIM_MODE_PRE_GET,
+ 0,
+ XIM_MODE_STS_GET,
+ XIM_MODE_STS_GET,
+ XIM_MODE_STS_GET,
+ XIM_MODE_STS_GET},
+ {OFFSET_XNDESTROYCALLBACK,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTRINGCONVERSIONCALLBACK,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTRINGCONVERSION,
+ XIM_MODE_PRE_SET,
+ XIM_MODE_PRE_SET,
+ XIM_MODE_PRE_SET,
+ XIM_MODE_PRE_SET,
+ XIM_MODE_PRE_SET,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNRESETSTATE,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNHOTKEY,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNHOTKEYSTATE,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITATTRIBUTES,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTATUSATTRIBUTES,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNAREA,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0},
+ {OFFSET_XNAREANEEDED,
+ 0,
+ 0,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0},
+ {OFFSET_XNSPOTLOCATION,
+ 0, /*(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),*/
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNCOLORMAP,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNSTDCOLORMAP,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNFOREGROUND,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNBACKGROUND,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNBACKGROUNDPIXMAP,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNFONTSET,
+ 0,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNLINESPACE,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNCURSOR,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNPREEDITSTARTCALLBACK,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITDONECALLBACK,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITDRAWCALLBACK,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITCARETCALLBACK,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITSTATE,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITSTATENOTIFYCALLBACK,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTATUSSTARTCALLBACK,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTATUSDONECALLBACK,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTATUSDRAWCALLBACK,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0,
+ 0}
+};
+
+/* the quarks are separated from im_mode/ic_mode so those arrays
+ * can be const.
+ */
+static XrmQuark im_mode_quark[sizeof(im_mode) / sizeof(im_mode[0])];
+static XrmQuark ic_mode_quark[sizeof(ic_mode) / sizeof(ic_mode[0])];
+
+Private Bool
+_XimSetResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num,
+ XIMResourceList resource,
+ unsigned int num_resource,
+ unsigned short id)
+{
+ register int i;
+ int len;
+ XIMResourceList res;
+
+ len = sizeof(XIMResource) * num_resource;
+ if(!(res = Xcalloc(1, len))) {
+ return False;
+ }
+
+ for(i = 0; i < num_resource; i++, id++) {
+ res[i] = resource[i];
+ res[i].id = id;
+ }
+
+ _XIMCompileResourceList(res, num_resource);
+ *res_list = res;
+ *list_num = num_resource;
+ return True;
+}
+
+Public Bool
+_XimSetIMResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num)
+{
+ return _XimSetResourceList(res_list, list_num,
+ im_resources, XIMNumber(im_resources), 100);
+}
+
+Public Bool
+_XimSetICResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num)
+{
+ return _XimSetResourceList(res_list, list_num,
+ ic_resources, XIMNumber(ic_resources), 200);
+}
+
+Public Bool
+_XimSetInnerIMResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num)
+{
+ return _XimSetResourceList(res_list, list_num,
+ im_inner_resources, XIMNumber(im_inner_resources), 100);
+}
+
+Public Bool
+_XimSetInnerICResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num)
+{
+ return _XimSetResourceList(res_list, list_num,
+ ic_inner_resources, XIMNumber(ic_inner_resources), 200);
+}
+
+Private XIMResourceList
+_XimGetResourceListRecByMode(
+ XIMResourceList res_list,
+ unsigned int list_num,
+ unsigned short mode)
+{
+ register int i;
+
+ for(i = 0; i < list_num; i++) {
+ if (res_list[i].mode & mode) {
+ return (XIMResourceList)&res_list[i];
+ }
+ }
+ return (XIMResourceList)NULL;
+}
+
+Public Bool
+_XimCheckCreateICValues(
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ if (!_XimGetResourceListRecByMode(res_list, list_num, XIM_MODE_IC_CREATE)) {
+ return True;
+ }
+ return False;
+}
+
+Public XIMResourceList
+_XimGetResourceListRecByQuark(
+ XIMResourceList res_list,
+ unsigned int list_num,
+ XrmQuark quark)
+{
+ register int i;
+
+ for(i = 0; i < list_num; i++) {
+ if (res_list[i].xrm_name == quark) {
+ return (XIMResourceList)&res_list[i];
+ }
+ }
+ return (XIMResourceList)NULL;
+}
+
+Public XIMResourceList
+_XimGetResourceListRec(
+ XIMResourceList res_list,
+ unsigned int list_num,
+ const char *name)
+{
+ XrmQuark quark = XrmStringToQuark(name);
+
+ return _XimGetResourceListRecByQuark(res_list, list_num, quark);
+}
+
+Public char *
+_XimSetIMValueData(
+ Xim im,
+ XPointer top,
+ XIMArg *values,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+
+ for(p = values; p->name != NULL; p++) {
+ if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
+ return p->value;
+ }
+ check = _XimCheckIMMode(res, XIM_SETIMVALUES);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if (check == XIM_CHECK_ERROR) {
+ return p->value;
+ }
+
+ if(!_XimEncodeLocalIMAttr(res, top, p->value)) {
+ return p->value;
+ }
+ }
+ return NULL;
+}
+
+Public char *
+_XimGetIMValueData(
+ Xim im,
+ XPointer top,
+ XIMArg *values,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+
+ for(p = values; p->name != NULL; p++) {
+ if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
+ return p->value;
+ }
+ check = _XimCheckIMMode(res, XIM_GETIMVALUES);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if (check == XIM_CHECK_ERROR) {
+ return p->value;
+ }
+
+ if(!_XimDecodeLocalIMAttr(res, top, p->value)) {
+ return p->value;
+ }
+ }
+ return NULL;
+}
+
+Public void
+_XimSetIMMode(
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ XIMResourceList res;
+ unsigned int n = XIMNumber(im_mode);
+ register int i;
+
+ for(i = 0; i < n; i++) {
+ if(!(res = _XimGetResourceListRecByQuark(res_list,
+ list_num, im_mode_quark[i]))) {
+ continue;
+ }
+ res->mode = im_mode[i].mode;
+ }
+ return;
+}
+
+Private int
+_XimCheckSetIMDefaultsMode(
+ XIMResourceList res)
+{
+ if(res->mode & XIM_MODE_IM_DEFAULT) {
+ return XIM_CHECK_VALID;
+ }
+ return XIM_CHECK_INVALID;
+}
+
+Private int
+_XimCheckSetIMValuesMode(
+ XIMResourceList res)
+{
+ if(res->mode & XIM_MODE_IM_SET) {
+ return XIM_CHECK_VALID;
+ }
+ return XIM_CHECK_INVALID;
+}
+
+Private int
+ _XimCheckGetIMValuesMode(
+ XIMResourceList res)
+{
+ if(res->mode & XIM_MODE_IM_GET) {
+ return XIM_CHECK_VALID;
+ }
+ return XIM_CHECK_INVALID;
+}
+
+Public int
+ _XimCheckIMMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(res->mode == 0) {
+ return XIM_CHECK_INVALID;
+ }
+ if(mode & XIM_SETIMDEFAULTS) {
+ return _XimCheckSetIMDefaultsMode(res);
+ } else if (mode & XIM_SETIMVALUES) {
+ return _XimCheckSetIMValuesMode(res);
+ } else if (mode & XIM_GETIMVALUES) {
+ return _XimCheckGetIMValuesMode(res);
+ } else {
+ return XIM_CHECK_ERROR;
+ }
+}
+
+Public void
+_XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style)
+{
+ XIMResourceList res;
+ unsigned int n = XIMNumber(ic_mode);
+ register int i;
+ unsigned int pre_offset;
+ unsigned int sts_offset;
+
+ if(style & XIMPreeditArea) {
+ pre_offset = XOffsetOf(XimICMode, preedit_area_mode);
+ } else if(style & XIMPreeditCallbacks) {
+ pre_offset = XOffsetOf(XimICMode, preedit_callback_mode);
+ } else if(style & XIMPreeditPosition) {
+ pre_offset = XOffsetOf(XimICMode, preedit_position_mode);
+ } else if(style & XIMPreeditNothing) {
+ pre_offset = XOffsetOf(XimICMode, preedit_nothing_mode);
+ } else {
+ pre_offset = XOffsetOf(XimICMode, preedit_none_mode);
+ }
+
+ if(style & XIMStatusArea) {
+ sts_offset = XOffsetOf(XimICMode, status_area_mode);
+ } else if(style & XIMStatusCallbacks) {
+ sts_offset = XOffsetOf(XimICMode, status_callback_mode);
+ } else if(style & XIMStatusNothing) {
+ sts_offset = XOffsetOf(XimICMode, status_nothing_mode);
+ } else {
+ sts_offset = XOffsetOf(XimICMode, status_none_mode);
+ }
+
+ for(i = 0; i < n; i++) {
+ if(!(res = _XimGetResourceListRecByQuark(res_list,
+ list_num, ic_mode_quark[i]))) {
+ continue;
+ }
+ res->mode = ( (*(unsigned short *)((char *)&ic_mode[i] + pre_offset))
+ | (*(unsigned short *)((char *)&ic_mode[i] + sts_offset)));
+ }
+ return;
+}
+
+Private int
+_XimCheckSetICDefaultsMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode & XIM_PREEDIT_ATTR) {
+ if(!(res->mode & XIM_MODE_PRE_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_PRE_CREATE) {
+ return XIM_CHECK_ERROR;
+ } else if (!(res->mode & XIM_MODE_PRE_DEFAULT)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ } else if(mode & XIM_STATUS_ATTR) {
+ if(!(res->mode & XIM_MODE_STS_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_STS_CREATE) {
+ return XIM_CHECK_ERROR;
+ }
+ if(!(res->mode & XIM_MODE_STS_DEFAULT)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ } else {
+ if(!res->mode) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_IC_CREATE) {
+ return XIM_CHECK_ERROR;
+ }
+ if(!(res->mode & XIM_MODE_IC_DEFAULT)) {
+ return XIM_CHECK_INVALID;
+ }
+ }
+ return XIM_CHECK_VALID;
+}
+
+Private int
+_XimCheckCreateICMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode & XIM_PREEDIT_ATTR) {
+ if(!(res->mode & XIM_MODE_PRE_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_PRE_CREATE) {
+ res->mode &= ~XIM_MODE_PRE_CREATE;
+ } else if(res->mode & XIM_MODE_PRE_ONCE) {
+ res->mode &= ~XIM_MODE_PRE_ONCE;
+ } else if(res->mode & XIM_MODE_PRE_DEFAULT) {
+ res->mode &= ~XIM_MODE_PRE_DEFAULT;
+ } else if (!(res->mode & XIM_MODE_PRE_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else if(mode & XIM_STATUS_ATTR) {
+ if(!(res->mode & XIM_MODE_STS_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_STS_CREATE) {
+ res->mode &= ~XIM_MODE_STS_CREATE;
+ } else if(res->mode & XIM_MODE_STS_ONCE) {
+ res->mode &= ~XIM_MODE_STS_ONCE;
+ } else if(res->mode & XIM_MODE_STS_DEFAULT) {
+ res->mode &= ~XIM_MODE_STS_DEFAULT;
+ } else if (!(res->mode & XIM_MODE_STS_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else {
+ if(!res->mode) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_IC_CREATE) {
+ res->mode &= ~XIM_MODE_IC_CREATE;
+ } else if(res->mode & XIM_MODE_IC_ONCE) {
+ res->mode &= ~XIM_MODE_IC_ONCE;
+ } else if(res->mode & XIM_MODE_IC_DEFAULT) {
+ res->mode &= ~XIM_MODE_IC_DEFAULT;
+ } else if (!(res->mode & XIM_MODE_IC_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+ }
+ return XIM_CHECK_VALID;
+}
+
+Private int
+_XimCheckSetICValuesMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode & XIM_PREEDIT_ATTR) {
+ if(!(res->mode & XIM_MODE_PRE_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_PRE_ONCE) {
+ res->mode &= ~XIM_MODE_PRE_ONCE;
+ } else if(!(res->mode & XIM_MODE_PRE_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else if(mode & XIM_STATUS_ATTR) {
+ if(!(res->mode & XIM_MODE_STS_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_STS_ONCE) {
+ res->mode &= ~XIM_MODE_STS_ONCE;
+ } else if(!(res->mode & XIM_MODE_STS_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else {
+ if(!res->mode) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_IC_ONCE) {
+ res->mode &= ~XIM_MODE_IC_ONCE;
+ } else if(!(res->mode & XIM_MODE_IC_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+ }
+ return XIM_CHECK_VALID;
+}
+
+Private int
+_XimCheckGetICValuesMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode & XIM_PREEDIT_ATTR) {
+ if(!(res->mode & XIM_MODE_PRE_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(!(res->mode & XIM_MODE_PRE_GET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else if(mode & XIM_STATUS_ATTR) {
+ if(!(res->mode & XIM_MODE_STS_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(!(res->mode & XIM_MODE_STS_GET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else {
+ if(!res->mode) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(!(res->mode & XIM_MODE_IC_GET)) {
+ return XIM_CHECK_ERROR;
+ }
+ }
+ return XIM_CHECK_VALID;
+}
+
+Public int
+ _XimCheckICMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode &XIM_SETICDEFAULTS) {
+ return _XimCheckSetICDefaultsMode(res, mode);
+ } else if (mode & XIM_CREATEIC) {
+ return _XimCheckCreateICMode(res, mode);
+ } else if (mode & XIM_SETICVALUES) {
+ return _XimCheckSetICValuesMode(res, mode);
+ } else if (mode & XIM_GETICVALUES) {
+ return _XimCheckGetICValuesMode(res, mode);
+ } else {
+ return XIM_CHECK_ERROR;
+ }
+}
+
+Public Bool
+_XimSetLocalIMDefaults(
+ Xim im,
+ XPointer top,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ XimValueOffsetInfo info;
+ unsigned int num;
+ register int i;
+ XIMResourceList res;
+ int check;
+
+ info = im_attr_info;
+ num = XIMNumber(im_attr_info);
+
+ for(i = 0; i < num; i++) {
+ if((res = _XimGetResourceListRecByQuark( res_list, list_num,
+ info[i].quark)) == (XIMResourceList)NULL) {
+ return False;
+ }
+
+ check = _XimCheckIMMode(res, XIM_SETIMDEFAULTS);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if (check == XIM_CHECK_ERROR) {
+ return False;
+ }
+
+ if(!info[i].defaults) {
+ continue;
+ }
+ if(!(info[i].defaults(&info[i], top, (XPointer)NULL, 0))) {
+ return False;
+ }
+ }
+ return True;
+}
+
+Public Bool
+_XimSetICDefaults(
+ Xic ic,
+ XPointer top,
+ unsigned long mode,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ unsigned int num;
+ XimValueOffsetInfo info;
+ register int i;
+ XIMResourceList res;
+ int check;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ info = ic_pre_attr_info;
+ num = XIMNumber(ic_pre_attr_info);
+ } else if(mode & XIM_STATUS_ATTR) {
+ info = ic_sts_attr_info;
+ num = XIMNumber(ic_sts_attr_info);
+ } else {
+ info = ic_attr_info;
+ num = XIMNumber(ic_attr_info);
+ }
+
+ for(i = 0; i < num; i++) {
+ if(info[i].quark == pre_quark) {
+ if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
+ (mode | XIM_PREEDIT_ATTR), res_list, list_num)) {
+ return False;
+ }
+ } else if (info[i].quark == sts_quark) {
+ if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
+ (mode | XIM_STATUS_ATTR), res_list, list_num)) {
+ return False;
+ }
+ } else {
+ if(!(res = _XimGetResourceListRecByQuark(res_list, list_num,
+ info[i].quark))) {
+ return False;
+ }
+
+ check = _XimCheckICMode(res, mode);
+ if (check == XIM_CHECK_INVALID) {
+ continue;
+ } else if (check == XIM_CHECK_ERROR) {
+ return False;
+ }
+
+ if (!info[i].defaults) {
+ continue;
+ }
+ if (!(info[i].defaults(&info[i], top, (XPointer)ic, mode))) {
+ return False;
+ }
+ }
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeAttr(
+ XimValueOffsetInfo info,
+ unsigned int num,
+ XIMResourceList res,
+ XPointer top,
+ XPointer val)
+{
+ register int i;
+
+ for(i = 0; i < num; i++ ) {
+ if(info[i].quark == res->xrm_name) {
+ if(!info[i].encode) {
+ return False;
+ }
+ return (*info[i].encode)(&info[i], top, val);
+ }
+ }
+ return False;
+}
+
+Public Bool
+_XimEncodeLocalIMAttr(
+ XIMResourceList res,
+ XPointer top,
+ XPointer val)
+{
+ return _XimEncodeAttr(im_attr_info, XIMNumber(im_attr_info),
+ res, top, val);
+}
+
+Public Bool
+_XimEncodeLocalICAttr(
+ Xic ic,
+ XIMResourceList res,
+ XPointer top,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ unsigned int num;
+ XimValueOffsetInfo info;
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ info = ic_pre_attr_info;
+ num = XIMNumber(ic_pre_attr_info);
+ } else if(mode & XIM_STATUS_ATTR) {
+ info = ic_sts_attr_info;
+ num = XIMNumber(ic_sts_attr_info);
+ } else {
+ info = ic_attr_info;
+ num = XIMNumber(ic_attr_info);
+ }
+
+ return _XimEncodeAttr(info, num, res, top, arg->value);
+}
+
+Private Bool
+_XimEncodeLocalTopValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer val,
+ Bool flag)
+{
+ XIMArg *p = (XIMArg *)val;
+
+ if (res->xrm_name == XrmStringToQuark(XNClientWindow)) {
+ ic->core.client_window = (Window)p->value;
+ if (ic->core.focus_window == (Window)0)
+ ic->core.focus_window = ic->core.client_window;
+ if (flag) {
+ _XRegisterFilterByType(ic->core.im->core.display,
+ ic->core.focus_window,
+ KeyPress, KeyRelease, _XimLocalFilter, (XPointer)ic);
+ }
+ } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
+ if (ic->core.client_window) {
+ if (flag) {
+ _XUnregisterFilter(ic->core.im->core.display,
+ ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
+ }
+ ic->core.focus_window = (Window)p->value;
+ if (flag) {
+ _XRegisterFilterByType(ic->core.im->core.display,
+ ic->core.focus_window, KeyPress, KeyRelease,
+ _XimLocalFilter, (XPointer)ic);
+ }
+ } else
+ ic->core.focus_window = (Window)p->value;
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeLocalPreeditValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer val)
+{
+ XIMArg *p = (XIMArg *)val;
+
+ if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
+ XStandardColormap *colormap_ret;
+ int count;
+
+ if (!(XGetRGBColormaps(ic->core.im->core.display,
+ ic->core.focus_window, &colormap_ret,
+ &count, (Atom)p->value)))
+ return False;
+
+ Xfree(colormap_ret);
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeLocalStatusValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer val)
+{
+ XIMArg *p = (XIMArg *)val;
+
+ if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
+ XStandardColormap *colormap_ret;
+ int count;
+
+ if (!(XGetRGBColormaps(ic->core.im->core.display,
+ ic->core.focus_window, &colormap_ret,
+ &count, (Atom)p->value)))
+ return False;
+
+ Xfree(colormap_ret);
+ }
+ return True;
+}
+
+Public char *
+_XimSetICValueData(
+ Xic ic,
+ XPointer top,
+ XIMResourceList res_list,
+ unsigned int list_num,
+ XIMArg *values,
+ unsigned long mode,
+ Bool flag)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ char *name;
+ int check;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ for(p = values; p->name != NULL; p++) {
+ if((res = _XimGetResourceListRec(res_list, list_num,
+ p->name)) == (XIMResourceList)NULL) {
+ return p->name;
+ }
+ if(res->xrm_name == pre_quark) {
+ if(((name = _XimSetICValueData(ic,
+ (XPointer)(&((XimDefICValues *)top)->preedit_attr),
+ res_list, list_num, (XIMArg *)p->value,
+ (mode | XIM_PREEDIT_ATTR), flag)))) {
+ return name;
+ }
+ } else if(res->xrm_name == sts_quark) {
+ if(((name = _XimSetICValueData(ic,
+ (XPointer)(&((XimDefICValues *)top)->status_attr),
+ res_list, list_num, (XIMArg *)p->value,
+ (mode | XIM_STATUS_ATTR), flag)))) {
+ return name;
+ }
+ } else {
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if(check == XIM_CHECK_ERROR) {
+ return p->name;
+ }
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ if (!_XimEncodeLocalPreeditValue(ic, res, (XPointer)p))
+ return False;
+ } else if(mode & XIM_STATUS_ATTR) {
+ if (!_XimEncodeLocalStatusValue(ic, res, (XPointer)p))
+ return False;
+ } else {
+ if (!_XimEncodeLocalTopValue(ic, res, (XPointer)p, flag))
+ return False;
+ }
+ if(_XimEncodeLocalICAttr(ic, res, top, p, mode) == False) {
+ return p->name;
+ }
+ }
+ }
+ return NULL;
+}
+
+Private Bool
+_XimCheckInputStyle(
+ XIMStyles *styles,
+ XIMStyle style)
+{
+ int num = styles->count_styles;
+ register int i;
+
+ for(i = 0; i < num; i++) {
+ if(styles->supported_styles[i] == style) {
+ return True;
+ }
+ }
+ return False;
+}
+
+Public Bool
+_XimCheckLocalInputStyle(
+ Xic ic,
+ XPointer top,
+ XIMArg *values,
+ XIMStyles *styles,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ XrmQuark quark = XrmStringToQuark(XNInputStyle);
+ register XIMArg *p;
+ XIMResourceList res;
+
+ for(p = values; p && p->name != NULL; p++) {
+ if(quark == XrmStringToQuark(p->name)) {
+ if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
+ return False;
+ }
+ if(!_XimEncodeLocalICAttr(ic, res, top, p, 0)) {
+ return False;
+ }
+ if (_XimCheckInputStyle(styles,
+ ((XimDefICValues *)top)->input_style)) {
+ return True;
+ }
+ return False;
+ }
+ }
+ return False;
+}
+
+Private Bool
+_XimDecodeAttr(
+ XimValueOffsetInfo info,
+ unsigned int num,
+ XIMResourceList res,
+ XPointer top,
+ XPointer val)
+{
+ register int i;
+
+ for(i = 0; i < num; i++ ) {
+ if(info[i].quark == res->xrm_name) {
+ if(!info[i].decode) {
+ return False;
+ }
+ return (*info[i].decode)(&info[i], top, val);
+ }
+ }
+ return False;
+}
+
+Public Bool
+_XimDecodeLocalIMAttr(
+ XIMResourceList res,
+ XPointer top,
+ XPointer val)
+{
+ return _XimDecodeAttr(im_attr_info, XIMNumber(im_attr_info),
+ res, top, val);
+}
+
+Public Bool
+_XimDecodeLocalICAttr(
+ XIMResourceList res,
+ XPointer top,
+ XPointer val,
+ unsigned long mode)
+{
+ unsigned int num;
+ XimValueOffsetInfo info;
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ info = ic_pre_attr_info;
+ num = XIMNumber(ic_pre_attr_info);
+ } else if(mode & XIM_STATUS_ATTR) {
+ info = ic_sts_attr_info;
+ num = XIMNumber(ic_sts_attr_info);
+ } else {
+ info = ic_attr_info;
+ num = XIMNumber(ic_attr_info);
+ }
+
+ return _XimDecodeAttr(info, num, res, top, val);
+}
+
+Public char *
+_XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list,
+ unsigned int list_num, XIMArg *values, unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ char *name;
+ int check;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ for(p = values; p->name != NULL; p++) {
+ if((res = _XimGetResourceListRec(res_list, list_num,
+ p->name)) == (XIMResourceList)NULL) {
+ return p->name;
+ }
+ if(res->xrm_name == pre_quark) {
+ if((name = _XimGetICValueData(ic,
+ (XPointer)(&((XimDefICValues *)top)->preedit_attr),
+ res_list, list_num, (XIMArg *)p->value,
+ (mode | XIM_PREEDIT_ATTR)))) {
+ return name;
+ }
+ } else if(res->xrm_name == sts_quark) {
+ if((name = _XimGetICValueData(ic,
+ (XPointer)(&((XimDefICValues *)top)->status_attr),
+ res_list, list_num, (XIMArg *)p->value,
+ (mode | XIM_STATUS_ATTR)))) {
+ return name;
+ }
+ } else {
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if(check == XIM_CHECK_ERROR) {
+ return p->name;
+ }
+
+ if(_XimDecodeLocalICAttr(res, top, p->value, mode) == False) {
+ return p->name;
+ }
+ }
+ }
+ return NULL;
+}
+
+Public void
+_XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values)
+{
+ bzero((char *)im_values, sizeof(XimDefIMValues));
+
+ im_values->styles = im->core.styles;
+ im_values->im_values_list = im->core.im_values_list;
+ im_values->ic_values_list = im->core.ic_values_list;
+ im_values->destroy_callback = im->core.destroy_callback;
+ im_values->res_name = im->core.res_name;
+ im_values->res_class = im->core.res_class;
+ im_values->visible_position = im->core.visible_position;
+}
+
+Public void
+_XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values)
+{
+ im->core.styles = im_values->styles;
+ im->core.im_values_list = im_values->im_values_list;
+ im->core.ic_values_list = im_values->ic_values_list;
+ im->core.destroy_callback = im_values->destroy_callback;
+ im->core.res_name = im_values->res_name;
+ im->core.res_class = im_values->res_class;
+ im->core.visible_position = im_values->visible_position;
+}
+
+Public void
+_XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values)
+{
+ bzero((char *)ic_values, sizeof(XimDefICValues));
+
+ ic_values->input_style = ic->core.input_style;
+ ic_values->client_window = ic->core.client_window;
+ ic_values->focus_window = ic->core.focus_window;
+ ic_values->filter_events = ic->core.filter_events;
+ ic_values->geometry_callback = ic->core.geometry_callback;
+ ic_values->res_name = ic->core.res_name;
+ ic_values->res_class = ic->core.res_class;
+ ic_values->destroy_callback = ic->core.destroy_callback;
+ ic_values->string_conversion_callback
+ = ic->core.string_conversion_callback;
+ ic_values->string_conversion = ic->core.string_conversion;
+ ic_values->reset_state = ic->core.reset_state;
+ ic_values->hotkey = ic->core.hotkey;
+ ic_values->hotkey_state = ic->core.hotkey_state;
+ ic_values->preedit_attr = ic->core.preedit_attr;
+ ic_values->status_attr = ic->core.status_attr;
+}
+
+Public void
+_XimSetCurrentICValues(
+ Xic ic,
+ XimDefICValues *ic_values)
+{
+ ic->core.input_style = ic_values->input_style;
+ ic->core.client_window = ic_values->client_window;
+ if (ic_values->focus_window)
+ ic->core.focus_window = ic_values->focus_window;
+ ic->core.filter_events = ic_values->filter_events;
+ ic->core.geometry_callback = ic_values->geometry_callback;
+ ic->core.res_name = ic_values->res_name;
+ ic->core.res_class = ic_values->res_class;
+ ic->core.destroy_callback = ic_values->destroy_callback;
+ ic->core.string_conversion_callback
+ = ic_values->string_conversion_callback;
+ ic->core.string_conversion = ic_values->string_conversion;
+ ic->core.reset_state = ic_values->reset_state;
+ ic->core.hotkey = ic_values->hotkey;
+ ic->core.hotkey_state = ic_values->hotkey_state;
+ ic->core.preedit_attr = ic_values->preedit_attr;
+ ic->core.status_attr = ic_values->status_attr;
+}
+
+Private void
+_XimInitialIMOffsetInfo(void)
+{
+ unsigned int n = XIMNumber(im_attr_info);
+ register int i;
+
+ for(i = 0; i < n; i++) {
+ im_attr_info[i].quark = XrmStringToQuark(GET_NAME(im_attr_info[i]));
+ }
+}
+
+Private void
+_XimInitialICOffsetInfo(void)
+{
+ unsigned int n;
+ register int i;
+
+ n = XIMNumber(ic_attr_info);
+ for(i = 0; i < n; i++) {
+ ic_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_attr_info[i]));
+ }
+
+ n = XIMNumber(ic_pre_attr_info);
+ for(i = 0; i < n; i++) {
+ ic_pre_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_pre_attr_info[i]));
+ }
+
+ n = XIMNumber(ic_sts_attr_info);
+ for(i = 0; i < n; i++) {
+ ic_sts_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_sts_attr_info[i]));
+ }
+}
+
+Private void
+_XimInitialIMMode(void)
+{
+ unsigned int n = XIMNumber(im_mode);
+ register int i;
+
+ for(i = 0; i < n; i++) {
+ im_mode_quark[i] = XrmStringToQuark(GET_NAME(im_mode[i]));
+ }
+}
+
+Private void
+_XimInitialICMode(void)
+{
+ unsigned int n = XIMNumber(ic_mode);
+ register int i;
+
+ for(i = 0; i < n; i++) {
+ ic_mode_quark[i] = XrmStringToQuark(GET_NAME(ic_mode[i]));
+ }
+}
+
+Public void
+_XimInitialResourceInfo(void)
+{
+ static Bool init_flag = False;
+
+ if(init_flag == True) {
+ return;
+ }
+ _XimInitialIMOffsetInfo();
+ _XimInitialICOffsetInfo();
+ _XimInitialIMMode();
+ _XimInitialICMode();
+ init_flag = True;
+}
diff --git a/libX11/modules/im/ximcp/imRmAttr.c b/libX11/modules/im/ximcp/imRmAttr.c
index ac47f3bbe..2e732658a 100644
--- a/libX11/modules/im/ximcp/imRmAttr.c
+++ b/libX11/modules/im/ximcp/imRmAttr.c
@@ -1,1515 +1,1515 @@
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-
-Private XIMResourceList
-_XimGetNestedListSeparator(
- XIMResourceList res_list, /* LISTofIMATTR or IMATTR */
- unsigned int res_num)
-{
- return _XimGetResourceListRec(res_list, res_num, XNSeparatorofNestedList);
-}
-
-Private Bool
-_XimCheckInnerIMAttributes(
- Xim im,
- XIMArg *arg,
- unsigned long mode)
-{
- XIMResourceList res;
- int check;
-
- if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
- im->private.proto.im_num_inner_resources, arg->name)))
- return False;
-
- check = _XimCheckIMMode(res, mode);
- if(check == XIM_CHECK_INVALID)
- return True;
- else if(check == XIM_CHECK_ERROR)
- return False;
-
- return True;
-}
-
-Public char *
-_XimMakeIMAttrIDList(
- Xim im,
- XIMResourceList res_list,
- unsigned int res_num,
- XIMArg *arg,
- CARD16 *buf,
- INT16 *len,
- unsigned long mode)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
-
- *len = 0;
- if (!arg)
- return (char *)NULL;
-
- for (p = arg; p->name; p++) {
- if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
- if (_XimCheckInnerIMAttributes(im, p, mode))
- continue;
- return p->name;
- }
-
- check = _XimCheckIMMode(res, mode);
- if (check == XIM_CHECK_INVALID)
- continue;
- else if (check == XIM_CHECK_ERROR)
- return p->name;
-
- *buf = res->id;
- *len += sizeof(CARD16);
- buf++;
- }
- return (char *)NULL;
-}
-
-Private Bool
-_XimCheckInnerICAttributes(
- Xic ic,
- XIMArg *arg,
- unsigned long mode)
-{
- XIMResourceList res;
- int check;
-
- if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
- ic->private.proto.ic_num_inner_resources, arg->name)))
- return False;
-
- check = _XimCheckICMode(res, mode);
- if(check == XIM_CHECK_INVALID)
- return True;
- else if(check == XIM_CHECK_ERROR)
- return False;
-
- return True;
-}
-
-Public char *
-_XimMakeICAttrIDList(
- Xic ic,
- XIMResourceList res_list,
- unsigned int res_num,
- XIMArg *arg,
- CARD16 *buf,
- INT16 *len,
- unsigned long mode)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
- XrmQuark pre_quark;
- XrmQuark sts_quark;
- char *name;
- INT16 new_len;
-
- *len = 0;
- if (!arg)
- return (char *)NULL;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- for (p = arg; p && p->name; p++) {
- if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
- if (_XimCheckInnerICAttributes(ic, p, mode))
- continue;
- *len = -1;
- return p->name;
- }
-
- check = _XimCheckICMode(res, mode);
- if(check == XIM_CHECK_INVALID)
- continue;
- else if(check == XIM_CHECK_ERROR) {
- *len = -1;
- return p->name;
- }
-
- *buf = res->id;
- *len += sizeof(CARD16);
- buf++;
- if (res->resource_size == XimType_NEST) {
- if (res->xrm_name == pre_quark) {
- if ((name = _XimMakeICAttrIDList(ic, res_list, res_num,
- (XIMArg *)p->value, buf, &new_len,
- (mode | XIM_PREEDIT_ATTR)))) {
- if (new_len < 0) *len = -1;
- else *len += new_len;
- return name;
- }
- } else if (res->xrm_name == sts_quark) {
- if ((name = _XimMakeICAttrIDList(ic, res_list, res_num,
- (XIMArg *)p->value, buf, &new_len,
- (mode | XIM_STATUS_ATTR)))) {
- if (new_len < 0) *len = -1;
- else *len += new_len;
- return name;
- }
- }
- *len += new_len;
- buf = (CARD16 *)((char *)buf + new_len);
- if (!(res = _XimGetNestedListSeparator(res_list, res_num))) {
- p++;
- if (p) {
- *len = -1;
- return p->name;
- }
- else {
- return (char *)NULL;
- }
- }
- *buf = res->id;
- *len += sizeof(CARD16);
- buf++;
- }
- }
- return (char *)NULL;
-}
-
-Private Bool
-_XimAttributeToValue(
- Xic ic,
- XIMResourceList res,
- CARD16 *data,
- INT16 data_len,
- XPointer value,
- BITMASK32 mode)
-{
- switch (res->resource_size) {
- case XimType_SeparatorOfNestedList:
- case XimType_NEST:
- break;
-
- case XimType_CARD8:
- case XimType_CARD16:
- case XimType_CARD32:
- case XimType_Window:
- case XimType_XIMHotKeyState:
- _XCopyToArg((XPointer)data, (XPointer *)&value, data_len);
- break;
-
- case XimType_STRING8:
- {
- char *str;
-
- if (!(value))
- return False;
-
- if (!(str = (char *)Xmalloc(data_len + 1)))
- return False;
-
- (void)memcpy(str, (char *)data, data_len);
- str[data_len] = '\0';
-
- *((char **)value) = str;
- break;
- }
-
- case XimType_XIMStyles:
- {
- INT16 num = data[0];
- register CARD32 *style_list = (CARD32 *)&data[2];
- XIMStyle *style;
- XIMStyles *rep;
- register int i;
- char *p;
- int alloc_len;
-
- if (!(value))
- return False;
-
- alloc_len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
- if (!(p = (char *)Xmalloc(alloc_len)))
- return False;
-
- rep = (XIMStyles *)p;
- style = (XIMStyle *)(p + sizeof(XIMStyles));
-
- for (i = 0; i < num; i++)
- style[i] = (XIMStyle)style_list[i];
-
- rep->count_styles = (unsigned short)num;
- rep->supported_styles = style;
- *((XIMStyles **)value) = rep;
- break;
- }
-
- case XimType_XRectangle:
- {
- XRectangle *rep;
-
- if (!(value))
- return False;
-
- if (!(rep = (XRectangle *)Xmalloc(sizeof(XRectangle))))
- return False;
-
- rep->x = data[0];
- rep->y = data[1];
- rep->width = data[2];
- rep->height = data[3];
- *((XRectangle **)value) = rep;
- break;
- }
-
- case XimType_XPoint:
- {
- XPoint *rep;
-
- if (!(value))
- return False;
-
- if (!(rep = (XPoint *)Xmalloc(sizeof(XPoint))))
- return False;
-
- rep->x = data[0];
- rep->y = data[1];
- *((XPoint **)value) = rep;
- break;
- }
-
- case XimType_XFontSet:
- {
- INT16 len = data[0];
- char *base_name;
- XFontSet rep = (XFontSet)NULL;
- char **missing_list = NULL;
- int missing_count;
- char *def_string;
-
- if (!(value))
- return False;
- if (!ic)
- return False;
-
- if (!(base_name = (char *)Xmalloc(len + 1)))
- return False;
-
- (void)strncpy(base_name, (char *)&data[1], (int)len);
- base_name[len] = '\0';
-
- if (mode & XIM_PREEDIT_ATTR) {
- if (!strcmp(base_name, ic->private.proto.preedit_font)) {
- rep = ic->core.preedit_attr.fontset;
- } else if (!ic->private.proto.preedit_font_length) {
- rep = XCreateFontSet(ic->core.im->core.display,
- base_name, &missing_list,
- &missing_count, &def_string);
- }
- } else if (mode & XIM_STATUS_ATTR) {
- if (!strcmp(base_name, ic->private.proto.status_font)) {
- rep = ic->core.status_attr.fontset;
- } else if (!ic->private.proto.status_font_length) {
- rep = XCreateFontSet(ic->core.im->core.display,
- base_name, &missing_list,
- &missing_count, &def_string);
- }
- }
-
- Xfree(base_name);
- Xfree(missing_list);
- *((XFontSet *)value) = rep;
- break;
- }
-
- case XimType_XIMHotKeyTriggers:
- {
- INT32 num = *((CARD32 *)data);
- register CARD32 *key_list = (CARD32 *)&data[2];
- XIMHotKeyTrigger *key;
- XIMHotKeyTriggers *rep;
- register int i;
- char *p;
- int alloc_len;
-
- if (!(value))
- return False;
-
- alloc_len = sizeof(XIMHotKeyTriggers)
- + sizeof(XIMHotKeyTrigger) * num;
- if (!(p = (char *)Xmalloc(alloc_len)))
- return False;
-
- rep = (XIMHotKeyTriggers *)p;
- key = (XIMHotKeyTrigger *)(p + sizeof(XIMHotKeyTriggers));
-
- for (i = 0; i < num; i++, key_list += 3) {
- key[i].keysym = (KeySym)key_list[0]; /* keysym */
- key[i].modifier = (int)key_list[1]; /* modifier */
- key[i].modifier_mask = (int)key_list[2]; /* modifier_mask */
- }
-
- rep->num_hot_key = (int)num;
- rep->key = key;
- *((XIMHotKeyTriggers **)value) = rep;
- break;
- }
-
- case XimType_XIMStringConversion:
- {
- break;
- }
-
- default:
- return False;
- }
- return True;
-}
-
-Private Bool
-_XimDecodeInnerIMATTRIBUTE(
- Xim im,
- XIMArg *arg)
-{
- XIMResourceList res;
- XimDefIMValues im_values;
-
- if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
- im->private.proto.im_num_inner_resources, arg->name)))
- return False;
-
- _XimGetCurrentIMValues(im, &im_values);
- return _XimDecodeLocalIMAttr(res, (XPointer)&im_values, arg->value);
-}
-
-Public char *
-_XimDecodeIMATTRIBUTE(
- Xim im,
- XIMResourceList res_list,
- unsigned int res_num,
- CARD16 *data,
- INT16 data_len,
- XIMArg *arg,
- BITMASK32 mode)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
- INT16 len;
- CARD16 *buf;
- INT16 total;
- INT16 min_len = sizeof(CARD16) /* sizeof attributeID */
- + sizeof(INT16); /* sizeof length */
-
- for (p = arg; p->name; p++) {
- if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
- if (_XimDecodeInnerIMATTRIBUTE(im, p))
- continue;
- return p->name;
- }
-
- check = _XimCheckIMMode(res, mode);
- if(check == XIM_CHECK_INVALID)
- continue;
- else if(check == XIM_CHECK_ERROR)
- return p->name;
-
- total = data_len;
- buf = data;
- while (total >= min_len) {
- if (res->id == buf[0])
- break;
-
- len = buf[1];
- len += XIM_PAD(len) + min_len;
- buf = (CARD16 *)((char *)buf + len);
- total -= len;
- }
- if (total < min_len)
- return p->name;
-
- if (!(_XimAttributeToValue((Xic) im->private.local.current_ic,
- res, &buf[2], buf[1], p->value, mode)))
- return p->name;
- }
- return (char *)NULL;
-}
-
-Private Bool
-_XimDecodeInnerICATTRIBUTE(
- Xic ic,
- XIMArg *arg,
- unsigned long mode)
-{
- XIMResourceList res;
- XimDefICValues ic_values;
-
- if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
- ic->private.proto.ic_num_inner_resources, arg->name)))
- return False;
-
- _XimGetCurrentICValues(ic, &ic_values);
- if (!_XimDecodeLocalICAttr(res, (XPointer)&ic_values, arg->value, mode))
- return False;
- _XimSetCurrentICValues(ic, &ic_values);
- return True;
-}
-
-Public char *
-_XimDecodeICATTRIBUTE(
- Xic ic,
- XIMResourceList res_list,
- unsigned int res_num,
- CARD16 *data,
- INT16 data_len,
- XIMArg *arg,
- BITMASK32 mode)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
- INT16 len;
- CARD16 *buf;
- INT16 total;
- char *name;
- INT16 min_len = sizeof(CARD16) /* sizeof attributeID */
- + sizeof(INT16); /* sizeof length */
- XrmQuark pre_quark;
- XrmQuark sts_quark;
-
- if (!arg)
- return (char *)NULL;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- for (p = arg; p->name; p++) {
- if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
- if (_XimDecodeInnerICATTRIBUTE(ic, p, mode))
- continue;
- return p->name;
- }
-
- check = _XimCheckICMode(res, mode);
- if (check == XIM_CHECK_INVALID)
- continue;
- else if (check == XIM_CHECK_ERROR)
- return p->name;
-
- total = data_len;
- buf = data;
- while (total >= min_len) {
- if (res->id == buf[0])
- break;
-
- len = buf[1];
- len += XIM_PAD(len) + min_len;
- buf = (CARD16 *)((char *)buf + len);
- total -= len;
- }
- if (total < min_len)
- return p->name;
-
- if (res->resource_size == XimType_NEST) {
- if (res->xrm_name == pre_quark) {
- if ((name = _XimDecodeICATTRIBUTE(ic, res_list, res_num,
- &buf[2], buf[1], (XIMArg *)p->value,
- (mode | XIM_PREEDIT_ATTR))))
- return name;
- } else if (res->xrm_name == sts_quark) {
- if ((name = _XimDecodeICATTRIBUTE(ic, res_list, res_num,
- &buf[2], buf[1], (XIMArg *)p->value,
- (mode | XIM_STATUS_ATTR))))
- return name;
- }
- } else {
- if (!(_XimAttributeToValue(ic, res, &buf[2], buf[1],
- p->value, mode)))
- return p->name;
- }
- }
- return (char *)NULL;
-}
-
-Private Bool
-_XimValueToAttribute(
- XIMResourceList res,
- XPointer buf,
- int buf_size,
- XPointer value,
- int *len,
- unsigned long mode,
- XPointer param)
-{
- int ret_len;
-
- switch (res->resource_size) {
- case XimType_SeparatorOfNestedList:
- case XimType_NEST:
- *len = 0;
- break;
-
- case XimType_CARD8:
- ret_len = sizeof(CARD8);
- if (buf_size < ret_len + XIM_PAD(ret_len)) {
- *len = -1;
- return False;
- }
-
- *((CARD8 *)buf) = (CARD8)(long)value;
- *len = ret_len;
- break;
-
- case XimType_CARD16:
- ret_len = sizeof(CARD16);
- if (buf_size < ret_len + XIM_PAD(ret_len)) {
- *len = -1;
- return False;
- }
-
- *((CARD16 *)buf) = (CARD16)(long)value;
- *len = ret_len;
- break;
-
- case XimType_CARD32:
- case XimType_Window:
- case XimType_XIMHotKeyState:
- ret_len = sizeof(CARD32);
- if (buf_size < ret_len + XIM_PAD(ret_len)) {
- *len = -1;
- return False;
- }
-
- *((CARD32 *)buf) = (CARD32)(long)value;
- *len = ret_len;
- break;
-
- case XimType_STRING8:
- if (!value) {
- *len = 0;
- return False;
- }
-
- ret_len = strlen((char *)value);
- if (buf_size < ret_len + XIM_PAD(ret_len)) {
- *len = -1;
- return False;
- }
-
- (void)memcpy((char *)buf, (char *)value, ret_len);
- *len = ret_len;
- break;
-
- case XimType_XRectangle:
- {
- XRectangle *rect = (XRectangle *)value;
- CARD16 *buf_s = (CARD16 *)buf;
-
- if (!rect) {
- *len = 0;
- return False;
- }
-
- ret_len = sizeof(INT16) /* sizeof X */
- + sizeof(INT16) /* sizeof Y */
- + sizeof(CARD16) /* sizeof width */
- + sizeof(CARD16); /* sizeof height */
- if (buf_size < ret_len + XIM_PAD(ret_len)) {
- *len = -1;
- return False;
- }
-
- buf_s[0] = (CARD16)rect->x; /* X */
- buf_s[1] = (CARD16)rect->y; /* Y */
- buf_s[2] = (CARD16)rect->width; /* width */
- buf_s[3] = (CARD16)rect->height; /* heght */
- *len = ret_len;
- break;
- }
-
- case XimType_XPoint:
- {
- XPoint *point = (XPoint *)value;
- CARD16 *buf_s = (CARD16 *)buf;
-
- if (!point) {
- *len = 0;
- return False;
- }
-
- ret_len = sizeof(INT16) /* sizeof X */
- + sizeof(INT16); /* sizeof Y */
- if (buf_size < ret_len + XIM_PAD(ret_len)) {
- *len = -1;
- return False;
- }
-
- buf_s[0] = (CARD16)point->x; /* X */
- buf_s[1] = (CARD16)point->y; /* Y */
- *len = ret_len;
- break;
- }
-
- case XimType_XFontSet:
- {
- XFontSet font = (XFontSet)value;
- Xic ic = (Xic)param;
- char *base_name = NULL;
- int length = 0;
- CARD16 *buf_s = (CARD16 *)buf;
-
- if (!font) {
- *len = 0;
- return False;
- }
-
- if (mode & XIM_PREEDIT_ATTR) {
- base_name = ic->private.proto.preedit_font;
- length = ic->private.proto.preedit_font_length;
- } else if (mode & XIM_STATUS_ATTR) {
- base_name = ic->private.proto.status_font;
- length = ic->private.proto.status_font_length;
- }
-
- if (!base_name) {
- *len = 0;
- return False;
- }
-
- ret_len = sizeof(CARD16) /* sizeof length of Base name */
- + length; /* sizeof Base font name list */
- if (buf_size < ret_len + XIM_PAD(ret_len)) {
- *len = -1;
- return False;
- }
-
- buf_s[0] = (INT16)length; /* length of Base font name */
- (void)memcpy((char *)&buf_s[1], base_name, length);
- /* Base font name list */
- *len = ret_len;
- break;
- }
-
- case XimType_XIMHotKeyTriggers:
- {
- XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)value;
- INT32 num;
- CARD32 *buf_l = (CARD32 *)buf;
- register CARD32 *key = (CARD32 *)&buf_l[1];
- register int i;
-
- if (!hotkey) {
- *len = 0;
- return False;
- }
- num = (INT32)hotkey->num_hot_key;
-
- ret_len = sizeof(INT32) /* sizeof number of key list */
- + (sizeof(CARD32) /* sizeof keysyn */
- + sizeof(CARD32) /* sizeof modifier */
- + sizeof(CARD32)) /* sizeof modifier_mask */
- * num; /* number of key list */
- if (buf_size < ret_len + XIM_PAD(ret_len)) {
- *len = -1;
- return False;
- }
-
- buf_l[0] = num; /* number of key list */
- for (i = 0; i < num; i++, key += 3) {
- key[0] = (CARD32)(hotkey->key[i].keysym);
- /* keysym */
- key[1] = (CARD32)(hotkey->key[i].modifier);
- /* modifier */
- key[2] = (CARD32)(hotkey->key[i].modifier_mask);
- /* modifier_mask */
- }
- *len = ret_len;
- break;
- }
-
- case XimType_XIMStringConversion:
- {
- *len = 0;
- break;
- }
-
- default:
- return False;
- }
- return True;
-}
-
-Private Bool
-_XimSetInnerIMAttributes(
- Xim im,
- XPointer top,
- XIMArg *arg,
- unsigned long mode)
-{
- XIMResourceList res;
- int check;
-
- if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
- im->private.proto.im_num_inner_resources, arg->name)))
- return False;
-
- check = _XimCheckIMMode(res, mode);
- if(check == XIM_CHECK_INVALID)
- return True;
- else if(check == XIM_CHECK_ERROR)
- return False;
-
- return _XimEncodeLocalIMAttr(res, top, arg->value);
-}
-
-Public char *
-_XimEncodeIMATTRIBUTE(
- Xim im,
- XIMResourceList res_list,
- unsigned int res_num,
- XIMArg *arg,
- XIMArg **arg_ret,
- char *buf,
- int size,
- int *ret_len,
- XPointer top,
- unsigned long mode)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
- CARD16 *buf_s;
- int len;
- int min_len = sizeof(CARD16) /* sizeof attribute ID */
- + sizeof(INT16); /* sizeof value length */
-
- *ret_len = 0;
- for (p = arg; p->name; p++) {
- if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
- if (_XimSetInnerIMAttributes(im, top, p, mode))
- continue;
- return p->name;
- }
-
- check = _XimCheckIMMode(res, mode);
- if (check == XIM_CHECK_INVALID)
- continue;
- else if (check == XIM_CHECK_ERROR)
- return p->name;
-
- if (!(_XimEncodeLocalIMAttr(res, top, p->value)))
- return p->name;
-
- buf_s = (CARD16 *)buf;
- if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2], (size - min_len),
- p->value, &len, mode, (XPointer)NULL)))
- return p->name;
-
- if (len == 0) {
- continue;
- } else if (len < 0) {
- *arg_ret = p;
- return (char *)NULL;
- }
-
- buf_s[0] = res->id; /* attribute ID */
- buf_s[1] = len; /* value length */
- XIM_SET_PAD(&buf_s[2], len); /* pad */
- len += min_len;
-
- buf += len;
- *ret_len += len;
- size -= len;
- }
- *arg_ret = (XIMArg *)NULL;
- return (char *)NULL;
-}
-
-#ifdef XIM_CONNECTABLE
-Public Bool
-_XimEncodeSavedIMATTRIBUTE(
- Xim im,
- XIMResourceList res_list,
- unsigned int res_num,
- int *idx,
- char *buf,
- int size,
- int *ret_len,
- XPointer top,
- unsigned long mode)
-{
- register int i;
- int num = im->private.proto.num_saved_imvalues;
- XrmQuark *quark_list = im->private.proto.saved_imvalues;
- XIMResourceList res;
- XPointer value;
- CARD16 *buf_s;
- int len;
- int min_len = sizeof(CARD16) /* sizeof attribute ID */
- + sizeof(INT16); /* sizeof value length */
-
- if (!im->private.proto.saved_imvalues) {
- *idx = -1;
- *ret_len = 0;
- return True;
- }
-
- *ret_len = 0;
- for (i = *idx; i < num; i++) {
- if (!(res = _XimGetResourceListRecByQuark(res_list,
- res_num, quark_list[i])))
- continue;
-
- if (!_XimDecodeLocalIMAttr(res, top, value))
- return False;
-
- buf_s = (CARD16 *)buf;
- if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
- (size - min_len), value, &len, mode, (XPointer)NULL)))
- return False;
-
- if (len == 0) {
- continue;
- } else if (len < 0) {
- *idx = i;
- return True;
- }
-
- buf_s[0] = res->id; /* attribute ID */
- buf_s[1] = len; /* value length */
- XIM_SET_PAD(&buf_s[2], len); /* pad */
- len += min_len;
-
- buf += len;
- *ret_len += len;
- size -= len;
- }
- *idx = -1;
- return True;
-}
-#endif /* XIM_CONNECTABLE */
-
-Private Bool
-_XimEncodeTopValue(
- Xic ic,
- XIMResourceList res,
- XIMArg *p)
-{
- if (res->xrm_name == XrmStringToQuark(XNClientWindow)) {
- ic->core.client_window = (Window)p->value;
- if (ic->core.focus_window == (Window)0)
- ic->core.focus_window = ic->core.client_window;
- _XimRegisterFilter(ic);
-
- } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
- if (ic->core.client_window) {
- _XimUnregisterFilter(ic);
- ic->core.focus_window = (Window)p->value;
- _XimRegisterFilter(ic);
- } else /* client_window not yet */
- ic->core.focus_window = (Window)p->value;
- }
- return True;
-}
-
-Private Bool
-_XimEncodePreeditValue(
- Xic ic,
- XIMResourceList res,
- XIMArg *p)
-{
- if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
- XStandardColormap *colormap_ret;
- int count;
-
- if (!(XGetRGBColormaps(ic->core.im->core.display,
- ic->core.focus_window, &colormap_ret,
- &count, (Atom)p->value)))
- return False;
-
- XFree(colormap_ret);
- } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
- int list_ret;
- XFontStruct **struct_list;
- char **name_list;
- char *tmp;
- int len;
- register int i;
-
- if (!p->value)
- return False;
-
- if (ic->private.proto.preedit_font)
- Xfree(ic->private.proto.preedit_font);
-
- list_ret = XFontsOfFontSet((XFontSet)p->value,
- &struct_list, &name_list);
- for (i = 0, len = 0; i < list_ret; i++) {
- len += (strlen(name_list[i]) + sizeof(char));
- }
- if (!(tmp = Xmalloc(len + 1))) {
- ic->private.proto.preedit_font = NULL;
- return False;
- }
-
- tmp[0] = '\0';
- for (i = 0; i < list_ret; i++) {
- strcat(tmp, name_list[i]);
- strcat(tmp, ",");
- }
- tmp[len - 1] = 0;
- ic->private.proto.preedit_font = tmp;
- ic->private.proto.preedit_font_length = len - 1;
- }
- return True;
-}
-
-Private Bool
-_XimEncodeStatusValue(
- Xic ic,
- XIMResourceList res,
- XIMArg *p)
-{
- if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
- XStandardColormap *colormap_ret = NULL;
- int count;
-
- if (!(XGetRGBColormaps(ic->core.im->core.display,
- ic->core.focus_window, &colormap_ret,
- &count, (Atom)p->value)))
- return False;
-
- XFree(colormap_ret);
- } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
- int list_ret;
- XFontStruct **struct_list;
- char **name_list;
- char *tmp;
- int len;
- register int i;
-
- if (!p->value)
- return False;
-
- if (ic->private.proto.status_font)
- Xfree(ic->private.proto.status_font);
-
- list_ret = XFontsOfFontSet((XFontSet)p->value,
- &struct_list, &name_list);
- for (i = 0, len = 0; i < list_ret; i++) {
- len += (strlen(name_list[i]) + sizeof(char));
- }
- if (!(tmp = Xmalloc(len+1))) {
- ic->private.proto.status_font = NULL;
- return False;
- }
-
- tmp[0] = '\0';
- for(i = 0; i < list_ret; i++) {
- strcat(tmp, name_list[i]);
- strcat(tmp, ",");
- }
- tmp[len - 1] = 0;
- ic->private.proto.status_font = tmp;
- ic->private.proto.status_font_length = len - 1;
- }
- return True;
-}
-
-Private Bool
-_XimSetInnerICAttributes(
- Xic ic,
- XPointer top,
- XIMArg *arg,
- unsigned long mode)
-{
- XIMResourceList res;
- int check;
-
- if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
- ic->private.proto.ic_num_inner_resources, arg->name)))
- return False;
-
- check = _XimCheckICMode(res, mode);
- if(check == XIM_CHECK_INVALID)
- return True;
- else if(check == XIM_CHECK_ERROR)
- return False;
-
- return _XimEncodeLocalICAttr(ic, res, top, arg, mode);
-}
-
-Public char *
-_XimEncodeICATTRIBUTE(
- Xic ic,
- XIMResourceList res_list,
- unsigned int res_num,
- XIMArg *arg,
- XIMArg **arg_ret,
- char *buf,
- int size,
- int *ret_len,
- XPointer top,
- BITMASK32 *flag,
- unsigned long mode)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
- CARD16 *buf_s;
- int len;
- int min_len = sizeof(CARD16) /* sizeof attribute ID */
- + sizeof(INT16); /* sizeof value length */
- XrmQuark pre_quark;
- XrmQuark sts_quark;
- char *name;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- *ret_len = 0;
- for (p = arg; p && p->name; p++) {
- buf_s = (CARD16 *)buf;
- if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
- if (_XimSetInnerICAttributes(ic, top, p, mode))
- continue;
- return p->name;
- }
-
- check = _XimCheckICMode(res, mode);
- if (check == XIM_CHECK_INVALID)
- continue;
- else if (check == XIM_CHECK_ERROR)
- return p->name;
-
- if (mode & XIM_PREEDIT_ATTR) {
- if (!(_XimEncodePreeditValue(ic, res, p)))
- return p->name;
- } else if (mode & XIM_STATUS_ATTR) {
- if (!(_XimEncodeStatusValue(ic, res, p)))
- return p->name;
- } else {
- if (!(_XimEncodeTopValue(ic, res, p)))
- return p->name;
- }
-
- if (res->resource_size == XimType_NEST) {
- XimDefICValues *ic_attr = (XimDefICValues *)top;
-
- if (res->xrm_name == pre_quark) {
- XIMArg *arg_rt;
- if ((name = _XimEncodeICATTRIBUTE(ic, res_list, res_num,
- (XIMArg *)p->value, &arg_rt,
- (char *)&buf_s[2], (size - min_len),
- &len, (XPointer)&ic_attr->preedit_attr, flag,
- (mode | XIM_PREEDIT_ATTR)))) {
- return name;
- }
-
- } else if (res->xrm_name == sts_quark) {
- XIMArg *arg_rt;
- if ((name = _XimEncodeICATTRIBUTE(ic, res_list, res_num,
- (XIMArg *)p->value, &arg_rt,
- (char *)&buf_s[2], (size - min_len),
- &len, (XPointer)&ic_attr->status_attr, flag,
- (mode | XIM_STATUS_ATTR)))) {
- return name;
- }
- }
- } else {
-#ifdef EXT_MOVE
- if (flag)
- *flag |= _XimExtenArgCheck(p);
-#endif
- if (!(_XimEncodeLocalICAttr(ic, res, top, p, mode)))
- return p->name;
-
- if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
- (size - min_len), p->value,
- &len, mode, (XPointer)ic)))
- return p->name;
- }
-
- if (len == 0) {
- continue;
- } else if (len < 0) {
- *arg_ret = p;
- return (char *)NULL;
- }
-
- buf_s[0] = res->id; /* attribute ID */
- buf_s[1] = len; /* value length */
- XIM_SET_PAD(&buf_s[2], len); /* pad */
- len += min_len;
-
- buf += len;
- *ret_len += len;
- size -= len;
- }
- *arg_ret = (XIMArg *)NULL;
- return (char *)NULL;
-}
-
-#ifdef XIM_CONNECTABLE
-Private Bool
-_XimEncodeSavedPreeditValue(
- Xic ic,
- XIMResourceList res,
- XPointer value)
-{
- int list_ret;
- XFontStruct **struct_list;
- char **name_list;
- char *tmp;
- int len;
- register int i;
-
- if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
- if (!value)
- return False;
-
- if (ic->private.proto.preedit_font)
- Xfree(ic->private.proto.preedit_font);
-
- list_ret = XFontsOfFontSet((XFontSet)value,
- &struct_list, &name_list);
- for(i = 0, len = 0; i < list_ret; i++) {
- len += (strlen(name_list[i]) + sizeof(char));
- }
- if(!(tmp = Xmalloc(len + 1))) {
- ic->private.proto.preedit_font = NULL;
- return False;
- }
-
- tmp[0] = '\0';
- for(i = 0; i < list_ret; i++) {
- strcat(tmp, name_list[i]);
- strcat(tmp, ",");
- }
- tmp[len - 1] = 0;
- ic->private.proto.preedit_font = tmp;
- ic->private.proto.preedit_font_length = len - 1;
- }
- return True;
-}
-
-Private Bool
-_XimEncodeSavedStatusValue(
- Xic ic,
- XIMResourceList res,
- XPointer value)
-{
- int list_ret;
- XFontStruct **struct_list;
- char **name_list;
- char *tmp;
- int len;
- register int i;
-
- if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
- if (!value)
- return False;
-
- if (ic->private.proto.status_font)
- Xfree(ic->private.proto.status_font);
-
- list_ret = XFontsOfFontSet((XFontSet)value,
- &struct_list, &name_list);
- for(i = 0, len = 0; i < list_ret; i++) {
- len += (strlen(name_list[i]) + sizeof(char));
- }
- if(!(tmp = Xmalloc(len + 1))) {
- ic->private.proto.status_font = NULL;
- return False;
- }
-
- tmp[0] = '\0';
- for(i = 0; i < list_ret; i++) {
- strcat(tmp, name_list[i]);
- strcat(tmp, ",");
- }
- tmp[len - 1] = 0;
- ic->private.proto.status_font = tmp;
- ic->private.proto.status_font_length = len - 1;
- }
- return True;
-}
-
-Public Bool
-_XimEncodeSavedICATTRIBUTE(
- Xic ic,
- XIMResourceList res_list,
- unsigned int res_num,
- int *idx,
- char *buf,
- int size,
- int *ret_len,
- XPointer top,
- unsigned long mode)
-{
- int i;
- int num = ic->private.proto.num_saved_icvalues;
- XrmQuark *quark_list = ic->private.proto.saved_icvalues;
- XIMResourceList res;
- XPointer value;
- CARD16 *buf_s;
- int len;
- int min_len = sizeof(CARD16) /* sizeof attribute ID */
- + sizeof(INT16); /* sizeof value length */
- XrmQuark pre_quark;
- XrmQuark sts_quark;
- XrmQuark separator;
-
- if (!ic->private.proto.saved_icvalues) {
- *idx = -1;
- *ret_len = 0;
- return True;
- }
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
- separator = XrmStringToQuark(XNSeparatorofNestedList);
-
- *ret_len = 0;
- for (i = *idx; i < num; i++) {
- if (quark_list[i] == separator) {
- *idx = i;
- return True;
- }
-
- if (!(res = _XimGetResourceListRecByQuark(res_list,
- res_num, quark_list[i])))
- continue;
-
- if (!_XimDecodeLocalICAttr(res, top,(XPointer)&value, mode))
- return False;
-
- if (mode & XIM_PREEDIT_ATTR) {
- if (!(_XimEncodeSavedPreeditValue(ic, res, value))) {
- return False;
- }
- } else if (mode & XIM_STATUS_ATTR) {
- if (!(_XimEncodeSavedStatusValue(ic, res, value))) {
- return False;
- }
- }
-
- buf_s = (CARD16 *)buf;
- if (res->resource_size == XimType_NEST) {
- XimDefICValues *ic_attr = (XimDefICValues *)top;
-
- i++;
- if (res->xrm_name == pre_quark) {
- if (!_XimEncodeSavedICATTRIBUTE(ic, res_list, res_num,
- &i, (char *)&buf_s[2], (size - min_len),
- &len, (XPointer)&ic_attr->preedit_attr,
- (mode | XIM_PREEDIT_ATTR))) {
- return False;
- }
-
- } else if (res->xrm_name == sts_quark) {
- if (!_XimEncodeSavedICATTRIBUTE(ic, res_list, res_num,
- &i, (char *)&buf_s[2], (size - min_len),
- &len, (XPointer)&ic_attr->status_attr,
- (mode | XIM_STATUS_ATTR))) {
- return False;
- }
- }
- } else {
- if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
- (size - min_len), value,
- &len, mode, (XPointer)ic))) {
- return False;
- }
- }
-
- if (len == 0) {
- continue;
- } else if (len < 0) {
- if (quark_list[i] == separator)
- i++;
- *idx = i;
- return True;
- }
-
- buf_s[0] = res->id; /* attribute ID */
- buf_s[1] = len; /* value length */
- XIM_SET_PAD(&buf_s[2], len); /* pad */
- len += min_len;
-
- buf += len;
- *ret_len += len;
- size -= len;
- }
- *idx = -1;
- return True;
-}
-#endif /* XIM_CONNECTABLE */
-
-Private unsigned int
-_XimCountNumberOfAttr(
- INT16 total,
- CARD16 *attr,
- int *names_len)
-{
- unsigned int n;
- INT16 len;
- INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */
- + sizeof(CARD16) /* sizeof type of value */
- + sizeof(INT16); /* sizeof length of attribute */
-
- n = 0;
- *names_len = 0;
- while (total > min_len) {
- len = attr[2];
- *names_len += (len + 1);
- len += (min_len + XIM_PAD(len + 2));
- total -= len;
- attr = (CARD16 *)((char *)attr + len);
- n++;
- }
- return n;
-}
-
-Public Bool
-_XimGetAttributeID(
- Xim im,
- CARD16 *buf)
-{
- unsigned int n;
- XIMResourceList res;
- char *names;
- int names_len;
- XPointer tmp;
- XIMValuesList *values_list;
- char **values;
- int values_len;
- register int i;
- INT16 len;
- INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */
- + sizeof(CARD16) /* sizeof type of value */
- + sizeof(INT16); /* sizeof length of attr */
- /*
- * IM attribute ID
- */
-
- if (!(n = _XimCountNumberOfAttr(buf[0], &buf[1], &names_len)))
- return False;
-
- if (!(res = Xcalloc(n, sizeof(XIMResource))))
- return False;
-
- values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len;
- if (!(tmp = Xcalloc(1, values_len))) {
- Xfree(res);
- return False;
- }
-
- values_list = (XIMValuesList *)tmp;
- values = (char **)((char *)tmp + sizeof(XIMValuesList));
- names = (char *)((char *)values + (sizeof(char **) * n));
-
- values_list->count_values = n;
- values_list->supported_values = values;
-
- buf++;
- for (i = 0; i < n; i++) {
- len = buf[2];
- (void)memcpy(names, (char *)&buf[3], len);
- values[i] = names;
- names[len] = '\0';
- res[i].resource_name = names;
- res[i].resource_size = buf[1];
- res[i].id = buf[0];
- names += (len + 1);
- len += (min_len + XIM_PAD(len + 2));
- buf = (CARD16 *)((char *)buf + len);
- }
- _XIMCompileResourceList(res, n);
-
- if (im->core.im_resources)
- Xfree(im->core.im_resources);
- if (im->core.im_values_list)
- Xfree(im->core.im_values_list);
- im->core.im_resources = res;
- im->core.im_num_resources = n;
- im->core.im_values_list = values_list;
-
- /*
- * IC attribute ID
- */
-
- if (!(n = _XimCountNumberOfAttr(buf[0], &buf[2], &names_len)))
- return False;
-
- if (!(res = Xcalloc(n, sizeof(XIMResource))))
- return False;
-
- values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len;
- if (!(tmp = Xcalloc(1, values_len))) {
- Xfree(res);
- return False;
- }
-
- values_list = (XIMValuesList *)tmp;
- values = (char **)((char *)tmp + sizeof(XIMValuesList));
- names = (char *)((char *)values + (sizeof(char **) * n));
-
- values_list->count_values = n;
- values_list->supported_values = values;
-
- buf += 2;
- for (i = 0; i < n; i++) {
- len = buf[2];
- (void)memcpy(names, (char *)&buf[3], len);
- values[i] = names;
- names[len] = '\0';
- res[i].resource_name = names;
- res[i].resource_size = buf[1];
- res[i].id = buf[0];
- names += (len + 1);
- len += (min_len + XIM_PAD(len + 2));
- buf = (CARD16 *)((char *)buf + len);
- }
- _XIMCompileResourceList(res, n);
-
- if (im->core.ic_resources)
- Xfree(im->core.ic_resources);
- if (im->core.ic_values_list)
- Xfree(im->core.ic_values_list);
- im->core.ic_resources = res;
- im->core.ic_num_resources = n;
- im->core.ic_values_list = values_list;
-
- return True;
-}
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+
+Private XIMResourceList
+_XimGetNestedListSeparator(
+ XIMResourceList res_list, /* LISTofIMATTR or IMATTR */
+ unsigned int res_num)
+{
+ return _XimGetResourceListRec(res_list, res_num, XNSeparatorofNestedList);
+}
+
+Private Bool
+_XimCheckInnerIMAttributes(
+ Xim im,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ int check;
+
+ if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
+ im->private.proto.im_num_inner_resources, arg->name)))
+ return False;
+
+ check = _XimCheckIMMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ return True;
+ else if(check == XIM_CHECK_ERROR)
+ return False;
+
+ return True;
+}
+
+Public char *
+_XimMakeIMAttrIDList(
+ Xim im,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ XIMArg *arg,
+ CARD16 *buf,
+ INT16 *len,
+ unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+
+ *len = 0;
+ if (!arg)
+ return (char *)NULL;
+
+ for (p = arg; p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimCheckInnerIMAttributes(im, p, mode))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckIMMode(res, mode);
+ if (check == XIM_CHECK_INVALID)
+ continue;
+ else if (check == XIM_CHECK_ERROR)
+ return p->name;
+
+ *buf = res->id;
+ *len += sizeof(CARD16);
+ buf++;
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimCheckInnerICAttributes(
+ Xic ic,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ int check;
+
+ if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
+ ic->private.proto.ic_num_inner_resources, arg->name)))
+ return False;
+
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ return True;
+ else if(check == XIM_CHECK_ERROR)
+ return False;
+
+ return True;
+}
+
+Public char *
+_XimMakeICAttrIDList(
+ Xic ic,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ XIMArg *arg,
+ CARD16 *buf,
+ INT16 *len,
+ unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+ char *name;
+ INT16 new_len;
+
+ *len = 0;
+ if (!arg)
+ return (char *)NULL;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ for (p = arg; p && p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimCheckInnerICAttributes(ic, p, mode))
+ continue;
+ *len = -1;
+ return p->name;
+ }
+
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ continue;
+ else if(check == XIM_CHECK_ERROR) {
+ *len = -1;
+ return p->name;
+ }
+
+ *buf = res->id;
+ *len += sizeof(CARD16);
+ buf++;
+ if (res->resource_size == XimType_NEST) {
+ if (res->xrm_name == pre_quark) {
+ if ((name = _XimMakeICAttrIDList(ic, res_list, res_num,
+ (XIMArg *)p->value, buf, &new_len,
+ (mode | XIM_PREEDIT_ATTR)))) {
+ if (new_len < 0) *len = -1;
+ else *len += new_len;
+ return name;
+ }
+ } else if (res->xrm_name == sts_quark) {
+ if ((name = _XimMakeICAttrIDList(ic, res_list, res_num,
+ (XIMArg *)p->value, buf, &new_len,
+ (mode | XIM_STATUS_ATTR)))) {
+ if (new_len < 0) *len = -1;
+ else *len += new_len;
+ return name;
+ }
+ }
+ *len += new_len;
+ buf = (CARD16 *)((char *)buf + new_len);
+ if (!(res = _XimGetNestedListSeparator(res_list, res_num))) {
+ p++;
+ if (p) {
+ *len = -1;
+ return p->name;
+ }
+ else {
+ return (char *)NULL;
+ }
+ }
+ *buf = res->id;
+ *len += sizeof(CARD16);
+ buf++;
+ }
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimAttributeToValue(
+ Xic ic,
+ XIMResourceList res,
+ CARD16 *data,
+ INT16 data_len,
+ XPointer value,
+ BITMASK32 mode)
+{
+ switch (res->resource_size) {
+ case XimType_SeparatorOfNestedList:
+ case XimType_NEST:
+ break;
+
+ case XimType_CARD8:
+ case XimType_CARD16:
+ case XimType_CARD32:
+ case XimType_Window:
+ case XimType_XIMHotKeyState:
+ _XCopyToArg((XPointer)data, (XPointer *)&value, data_len);
+ break;
+
+ case XimType_STRING8:
+ {
+ char *str;
+
+ if (!(value))
+ return False;
+
+ if (!(str = (char *)Xmalloc(data_len + 1)))
+ return False;
+
+ (void)memcpy(str, (char *)data, data_len);
+ str[data_len] = '\0';
+
+ *((char **)value) = str;
+ break;
+ }
+
+ case XimType_XIMStyles:
+ {
+ INT16 num = data[0];
+ register CARD32 *style_list = (CARD32 *)&data[2];
+ XIMStyle *style;
+ XIMStyles *rep;
+ register int i;
+ char *p;
+ int alloc_len;
+
+ if (!(value))
+ return False;
+
+ alloc_len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
+ if (!(p = (char *)Xmalloc(alloc_len)))
+ return False;
+
+ rep = (XIMStyles *)p;
+ style = (XIMStyle *)(p + sizeof(XIMStyles));
+
+ for (i = 0; i < num; i++)
+ style[i] = (XIMStyle)style_list[i];
+
+ rep->count_styles = (unsigned short)num;
+ rep->supported_styles = style;
+ *((XIMStyles **)value) = rep;
+ break;
+ }
+
+ case XimType_XRectangle:
+ {
+ XRectangle *rep;
+
+ if (!(value))
+ return False;
+
+ if (!(rep = (XRectangle *)Xmalloc(sizeof(XRectangle))))
+ return False;
+
+ rep->x = data[0];
+ rep->y = data[1];
+ rep->width = data[2];
+ rep->height = data[3];
+ *((XRectangle **)value) = rep;
+ break;
+ }
+
+ case XimType_XPoint:
+ {
+ XPoint *rep;
+
+ if (!(value))
+ return False;
+
+ if (!(rep = (XPoint *)Xmalloc(sizeof(XPoint))))
+ return False;
+
+ rep->x = data[0];
+ rep->y = data[1];
+ *((XPoint **)value) = rep;
+ break;
+ }
+
+ case XimType_XFontSet:
+ {
+ INT16 len = data[0];
+ char *base_name;
+ XFontSet rep = (XFontSet)NULL;
+ char **missing_list = NULL;
+ int missing_count;
+ char *def_string;
+
+ if (!(value))
+ return False;
+ if (!ic)
+ return False;
+
+ if (!(base_name = (char *)Xmalloc(len + 1)))
+ return False;
+
+ (void)strncpy(base_name, (char *)&data[1], (int)len);
+ base_name[len] = '\0';
+
+ if (mode & XIM_PREEDIT_ATTR) {
+ if (!strcmp(base_name, ic->private.proto.preedit_font)) {
+ rep = ic->core.preedit_attr.fontset;
+ } else if (!ic->private.proto.preedit_font_length) {
+ rep = XCreateFontSet(ic->core.im->core.display,
+ base_name, &missing_list,
+ &missing_count, &def_string);
+ }
+ } else if (mode & XIM_STATUS_ATTR) {
+ if (!strcmp(base_name, ic->private.proto.status_font)) {
+ rep = ic->core.status_attr.fontset;
+ } else if (!ic->private.proto.status_font_length) {
+ rep = XCreateFontSet(ic->core.im->core.display,
+ base_name, &missing_list,
+ &missing_count, &def_string);
+ }
+ }
+
+ Xfree(base_name);
+ Xfree(missing_list);
+ *((XFontSet *)value) = rep;
+ break;
+ }
+
+ case XimType_XIMHotKeyTriggers:
+ {
+ INT32 num = *((CARD32 *)data);
+ register CARD32 *key_list = (CARD32 *)&data[2];
+ XIMHotKeyTrigger *key;
+ XIMHotKeyTriggers *rep;
+ register int i;
+ char *p;
+ int alloc_len;
+
+ if (!(value))
+ return False;
+
+ alloc_len = sizeof(XIMHotKeyTriggers)
+ + sizeof(XIMHotKeyTrigger) * num;
+ if (!(p = (char *)Xmalloc(alloc_len)))
+ return False;
+
+ rep = (XIMHotKeyTriggers *)p;
+ key = (XIMHotKeyTrigger *)(p + sizeof(XIMHotKeyTriggers));
+
+ for (i = 0; i < num; i++, key_list += 3) {
+ key[i].keysym = (KeySym)key_list[0]; /* keysym */
+ key[i].modifier = (int)key_list[1]; /* modifier */
+ key[i].modifier_mask = (int)key_list[2]; /* modifier_mask */
+ }
+
+ rep->num_hot_key = (int)num;
+ rep->key = key;
+ *((XIMHotKeyTriggers **)value) = rep;
+ break;
+ }
+
+ case XimType_XIMStringConversion:
+ {
+ break;
+ }
+
+ default:
+ return False;
+ }
+ return True;
+}
+
+Private Bool
+_XimDecodeInnerIMATTRIBUTE(
+ Xim im,
+ XIMArg *arg)
+{
+ XIMResourceList res;
+ XimDefIMValues im_values;
+
+ if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
+ im->private.proto.im_num_inner_resources, arg->name)))
+ return False;
+
+ _XimGetCurrentIMValues(im, &im_values);
+ return _XimDecodeLocalIMAttr(res, (XPointer)&im_values, arg->value);
+}
+
+Public char *
+_XimDecodeIMATTRIBUTE(
+ Xim im,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ CARD16 *data,
+ INT16 data_len,
+ XIMArg *arg,
+ BITMASK32 mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ INT16 len;
+ CARD16 *buf;
+ INT16 total;
+ INT16 min_len = sizeof(CARD16) /* sizeof attributeID */
+ + sizeof(INT16); /* sizeof length */
+
+ for (p = arg; p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimDecodeInnerIMATTRIBUTE(im, p))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckIMMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ continue;
+ else if(check == XIM_CHECK_ERROR)
+ return p->name;
+
+ total = data_len;
+ buf = data;
+ while (total >= min_len) {
+ if (res->id == buf[0])
+ break;
+
+ len = buf[1];
+ len += XIM_PAD(len) + min_len;
+ buf = (CARD16 *)((char *)buf + len);
+ total -= len;
+ }
+ if (total < min_len)
+ return p->name;
+
+ if (!(_XimAttributeToValue((Xic) im->private.local.current_ic,
+ res, &buf[2], buf[1], p->value, mode)))
+ return p->name;
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimDecodeInnerICATTRIBUTE(
+ Xic ic,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ XimDefICValues ic_values;
+
+ if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
+ ic->private.proto.ic_num_inner_resources, arg->name)))
+ return False;
+
+ _XimGetCurrentICValues(ic, &ic_values);
+ if (!_XimDecodeLocalICAttr(res, (XPointer)&ic_values, arg->value, mode))
+ return False;
+ _XimSetCurrentICValues(ic, &ic_values);
+ return True;
+}
+
+Public char *
+_XimDecodeICATTRIBUTE(
+ Xic ic,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ CARD16 *data,
+ INT16 data_len,
+ XIMArg *arg,
+ BITMASK32 mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ INT16 len;
+ CARD16 *buf;
+ INT16 total;
+ char *name;
+ INT16 min_len = sizeof(CARD16) /* sizeof attributeID */
+ + sizeof(INT16); /* sizeof length */
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+
+ if (!arg)
+ return (char *)NULL;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ for (p = arg; p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimDecodeInnerICATTRIBUTE(ic, p, mode))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckICMode(res, mode);
+ if (check == XIM_CHECK_INVALID)
+ continue;
+ else if (check == XIM_CHECK_ERROR)
+ return p->name;
+
+ total = data_len;
+ buf = data;
+ while (total >= min_len) {
+ if (res->id == buf[0])
+ break;
+
+ len = buf[1];
+ len += XIM_PAD(len) + min_len;
+ buf = (CARD16 *)((char *)buf + len);
+ total -= len;
+ }
+ if (total < min_len)
+ return p->name;
+
+ if (res->resource_size == XimType_NEST) {
+ if (res->xrm_name == pre_quark) {
+ if ((name = _XimDecodeICATTRIBUTE(ic, res_list, res_num,
+ &buf[2], buf[1], (XIMArg *)p->value,
+ (mode | XIM_PREEDIT_ATTR))))
+ return name;
+ } else if (res->xrm_name == sts_quark) {
+ if ((name = _XimDecodeICATTRIBUTE(ic, res_list, res_num,
+ &buf[2], buf[1], (XIMArg *)p->value,
+ (mode | XIM_STATUS_ATTR))))
+ return name;
+ }
+ } else {
+ if (!(_XimAttributeToValue(ic, res, &buf[2], buf[1],
+ p->value, mode)))
+ return p->name;
+ }
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimValueToAttribute(
+ XIMResourceList res,
+ XPointer buf,
+ int buf_size,
+ XPointer value,
+ int *len,
+ unsigned long mode,
+ XPointer param)
+{
+ int ret_len;
+
+ switch (res->resource_size) {
+ case XimType_SeparatorOfNestedList:
+ case XimType_NEST:
+ *len = 0;
+ break;
+
+ case XimType_CARD8:
+ ret_len = sizeof(CARD8);
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ *((CARD8 *)buf) = (CARD8)(long)value;
+ *len = ret_len;
+ break;
+
+ case XimType_CARD16:
+ ret_len = sizeof(CARD16);
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ *((CARD16 *)buf) = (CARD16)(long)value;
+ *len = ret_len;
+ break;
+
+ case XimType_CARD32:
+ case XimType_Window:
+ case XimType_XIMHotKeyState:
+ ret_len = sizeof(CARD32);
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ *((CARD32 *)buf) = (CARD32)(long)value;
+ *len = ret_len;
+ break;
+
+ case XimType_STRING8:
+ if (!value) {
+ *len = 0;
+ return False;
+ }
+
+ ret_len = strlen((char *)value);
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ (void)memcpy((char *)buf, (char *)value, ret_len);
+ *len = ret_len;
+ break;
+
+ case XimType_XRectangle:
+ {
+ XRectangle *rect = (XRectangle *)value;
+ CARD16 *buf_s = (CARD16 *)buf;
+
+ if (!rect) {
+ *len = 0;
+ return False;
+ }
+
+ ret_len = sizeof(INT16) /* sizeof X */
+ + sizeof(INT16) /* sizeof Y */
+ + sizeof(CARD16) /* sizeof width */
+ + sizeof(CARD16); /* sizeof height */
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ buf_s[0] = (CARD16)rect->x; /* X */
+ buf_s[1] = (CARD16)rect->y; /* Y */
+ buf_s[2] = (CARD16)rect->width; /* width */
+ buf_s[3] = (CARD16)rect->height; /* heght */
+ *len = ret_len;
+ break;
+ }
+
+ case XimType_XPoint:
+ {
+ XPoint *point = (XPoint *)value;
+ CARD16 *buf_s = (CARD16 *)buf;
+
+ if (!point) {
+ *len = 0;
+ return False;
+ }
+
+ ret_len = sizeof(INT16) /* sizeof X */
+ + sizeof(INT16); /* sizeof Y */
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ buf_s[0] = (CARD16)point->x; /* X */
+ buf_s[1] = (CARD16)point->y; /* Y */
+ *len = ret_len;
+ break;
+ }
+
+ case XimType_XFontSet:
+ {
+ XFontSet font = (XFontSet)value;
+ Xic ic = (Xic)param;
+ char *base_name = NULL;
+ int length = 0;
+ CARD16 *buf_s = (CARD16 *)buf;
+
+ if (!font) {
+ *len = 0;
+ return False;
+ }
+
+ if (mode & XIM_PREEDIT_ATTR) {
+ base_name = ic->private.proto.preedit_font;
+ length = ic->private.proto.preedit_font_length;
+ } else if (mode & XIM_STATUS_ATTR) {
+ base_name = ic->private.proto.status_font;
+ length = ic->private.proto.status_font_length;
+ }
+
+ if (!base_name) {
+ *len = 0;
+ return False;
+ }
+
+ ret_len = sizeof(CARD16) /* sizeof length of Base name */
+ + length; /* sizeof Base font name list */
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ buf_s[0] = (INT16)length; /* length of Base font name */
+ (void)memcpy((char *)&buf_s[1], base_name, length);
+ /* Base font name list */
+ *len = ret_len;
+ break;
+ }
+
+ case XimType_XIMHotKeyTriggers:
+ {
+ XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)value;
+ INT32 num;
+ CARD32 *buf_l = (CARD32 *)buf;
+ register CARD32 *key = (CARD32 *)&buf_l[1];
+ register int i;
+
+ if (!hotkey) {
+ *len = 0;
+ return False;
+ }
+ num = (INT32)hotkey->num_hot_key;
+
+ ret_len = sizeof(INT32) /* sizeof number of key list */
+ + (sizeof(CARD32) /* sizeof keysyn */
+ + sizeof(CARD32) /* sizeof modifier */
+ + sizeof(CARD32)) /* sizeof modifier_mask */
+ * num; /* number of key list */
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ buf_l[0] = num; /* number of key list */
+ for (i = 0; i < num; i++, key += 3) {
+ key[0] = (CARD32)(hotkey->key[i].keysym);
+ /* keysym */
+ key[1] = (CARD32)(hotkey->key[i].modifier);
+ /* modifier */
+ key[2] = (CARD32)(hotkey->key[i].modifier_mask);
+ /* modifier_mask */
+ }
+ *len = ret_len;
+ break;
+ }
+
+ case XimType_XIMStringConversion:
+ {
+ *len = 0;
+ break;
+ }
+
+ default:
+ return False;
+ }
+ return True;
+}
+
+Private Bool
+_XimSetInnerIMAttributes(
+ Xim im,
+ XPointer top,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ int check;
+
+ if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
+ im->private.proto.im_num_inner_resources, arg->name)))
+ return False;
+
+ check = _XimCheckIMMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ return True;
+ else if(check == XIM_CHECK_ERROR)
+ return False;
+
+ return _XimEncodeLocalIMAttr(res, top, arg->value);
+}
+
+Public char *
+_XimEncodeIMATTRIBUTE(
+ Xim im,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ XIMArg *arg,
+ XIMArg **arg_ret,
+ char *buf,
+ int size,
+ int *ret_len,
+ XPointer top,
+ unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ CARD16 *buf_s;
+ int len;
+ int min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(INT16); /* sizeof value length */
+
+ *ret_len = 0;
+ for (p = arg; p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimSetInnerIMAttributes(im, top, p, mode))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckIMMode(res, mode);
+ if (check == XIM_CHECK_INVALID)
+ continue;
+ else if (check == XIM_CHECK_ERROR)
+ return p->name;
+
+ if (!(_XimEncodeLocalIMAttr(res, top, p->value)))
+ return p->name;
+
+ buf_s = (CARD16 *)buf;
+ if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2], (size - min_len),
+ p->value, &len, mode, (XPointer)NULL)))
+ return p->name;
+
+ if (len == 0) {
+ continue;
+ } else if (len < 0) {
+ *arg_ret = p;
+ return (char *)NULL;
+ }
+
+ buf_s[0] = res->id; /* attribute ID */
+ buf_s[1] = len; /* value length */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += min_len;
+
+ buf += len;
+ *ret_len += len;
+ size -= len;
+ }
+ *arg_ret = (XIMArg *)NULL;
+ return (char *)NULL;
+}
+
+#ifdef XIM_CONNECTABLE
+Public Bool
+_XimEncodeSavedIMATTRIBUTE(
+ Xim im,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ int *idx,
+ char *buf,
+ int size,
+ int *ret_len,
+ XPointer top,
+ unsigned long mode)
+{
+ register int i;
+ int num = im->private.proto.num_saved_imvalues;
+ XrmQuark *quark_list = im->private.proto.saved_imvalues;
+ XIMResourceList res;
+ XPointer value;
+ CARD16 *buf_s;
+ int len;
+ int min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(INT16); /* sizeof value length */
+
+ if (!im->private.proto.saved_imvalues) {
+ *idx = -1;
+ *ret_len = 0;
+ return True;
+ }
+
+ *ret_len = 0;
+ for (i = *idx; i < num; i++) {
+ if (!(res = _XimGetResourceListRecByQuark(res_list,
+ res_num, quark_list[i])))
+ continue;
+
+ if (!_XimDecodeLocalIMAttr(res, top, value))
+ return False;
+
+ buf_s = (CARD16 *)buf;
+ if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
+ (size - min_len), value, &len, mode, (XPointer)NULL)))
+ return False;
+
+ if (len == 0) {
+ continue;
+ } else if (len < 0) {
+ *idx = i;
+ return True;
+ }
+
+ buf_s[0] = res->id; /* attribute ID */
+ buf_s[1] = len; /* value length */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += min_len;
+
+ buf += len;
+ *ret_len += len;
+ size -= len;
+ }
+ *idx = -1;
+ return True;
+}
+#endif /* XIM_CONNECTABLE */
+
+Private Bool
+_XimEncodeTopValue(
+ Xic ic,
+ XIMResourceList res,
+ XIMArg *p)
+{
+ if (res->xrm_name == XrmStringToQuark(XNClientWindow)) {
+ ic->core.client_window = (Window)p->value;
+ if (ic->core.focus_window == (Window)0)
+ ic->core.focus_window = ic->core.client_window;
+ _XimRegisterFilter(ic);
+
+ } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
+ if (ic->core.client_window) {
+ _XimUnregisterFilter(ic);
+ ic->core.focus_window = (Window)p->value;
+ _XimRegisterFilter(ic);
+ } else /* client_window not yet */
+ ic->core.focus_window = (Window)p->value;
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodePreeditValue(
+ Xic ic,
+ XIMResourceList res,
+ XIMArg *p)
+{
+ if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
+ XStandardColormap *colormap_ret;
+ int count;
+
+ if (!(XGetRGBColormaps(ic->core.im->core.display,
+ ic->core.focus_window, &colormap_ret,
+ &count, (Atom)p->value)))
+ return False;
+
+ XFree(colormap_ret);
+ } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
+ int list_ret;
+ XFontStruct **struct_list;
+ char **name_list;
+ char *tmp;
+ int len;
+ register int i;
+
+ if (!p->value)
+ return False;
+
+ if (ic->private.proto.preedit_font)
+ Xfree(ic->private.proto.preedit_font);
+
+ list_ret = XFontsOfFontSet((XFontSet)p->value,
+ &struct_list, &name_list);
+ for (i = 0, len = 0; i < list_ret; i++) {
+ len += (strlen(name_list[i]) + sizeof(char));
+ }
+ if (!(tmp = Xmalloc(len + 1))) {
+ ic->private.proto.preedit_font = NULL;
+ return False;
+ }
+
+ tmp[0] = '\0';
+ for (i = 0; i < list_ret; i++) {
+ strcat(tmp, name_list[i]);
+ strcat(tmp, ",");
+ }
+ tmp[len - 1] = 0;
+ ic->private.proto.preedit_font = tmp;
+ ic->private.proto.preedit_font_length = len - 1;
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeStatusValue(
+ Xic ic,
+ XIMResourceList res,
+ XIMArg *p)
+{
+ if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
+ XStandardColormap *colormap_ret = NULL;
+ int count;
+
+ if (!(XGetRGBColormaps(ic->core.im->core.display,
+ ic->core.focus_window, &colormap_ret,
+ &count, (Atom)p->value)))
+ return False;
+
+ XFree(colormap_ret);
+ } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
+ int list_ret;
+ XFontStruct **struct_list;
+ char **name_list;
+ char *tmp;
+ int len;
+ register int i;
+
+ if (!p->value)
+ return False;
+
+ if (ic->private.proto.status_font)
+ Xfree(ic->private.proto.status_font);
+
+ list_ret = XFontsOfFontSet((XFontSet)p->value,
+ &struct_list, &name_list);
+ for (i = 0, len = 0; i < list_ret; i++) {
+ len += (strlen(name_list[i]) + sizeof(char));
+ }
+ if (!(tmp = Xmalloc(len+1))) {
+ ic->private.proto.status_font = NULL;
+ return False;
+ }
+
+ tmp[0] = '\0';
+ for(i = 0; i < list_ret; i++) {
+ strcat(tmp, name_list[i]);
+ strcat(tmp, ",");
+ }
+ tmp[len - 1] = 0;
+ ic->private.proto.status_font = tmp;
+ ic->private.proto.status_font_length = len - 1;
+ }
+ return True;
+}
+
+Private Bool
+_XimSetInnerICAttributes(
+ Xic ic,
+ XPointer top,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ int check;
+
+ if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
+ ic->private.proto.ic_num_inner_resources, arg->name)))
+ return False;
+
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ return True;
+ else if(check == XIM_CHECK_ERROR)
+ return False;
+
+ return _XimEncodeLocalICAttr(ic, res, top, arg, mode);
+}
+
+Public char *
+_XimEncodeICATTRIBUTE(
+ Xic ic,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ XIMArg *arg,
+ XIMArg **arg_ret,
+ char *buf,
+ int size,
+ int *ret_len,
+ XPointer top,
+ BITMASK32 *flag,
+ unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ CARD16 *buf_s;
+ int len;
+ int min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(INT16); /* sizeof value length */
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+ char *name;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ *ret_len = 0;
+ for (p = arg; p && p->name; p++) {
+ buf_s = (CARD16 *)buf;
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimSetInnerICAttributes(ic, top, p, mode))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckICMode(res, mode);
+ if (check == XIM_CHECK_INVALID)
+ continue;
+ else if (check == XIM_CHECK_ERROR)
+ return p->name;
+
+ if (mode & XIM_PREEDIT_ATTR) {
+ if (!(_XimEncodePreeditValue(ic, res, p)))
+ return p->name;
+ } else if (mode & XIM_STATUS_ATTR) {
+ if (!(_XimEncodeStatusValue(ic, res, p)))
+ return p->name;
+ } else {
+ if (!(_XimEncodeTopValue(ic, res, p)))
+ return p->name;
+ }
+
+ if (res->resource_size == XimType_NEST) {
+ XimDefICValues *ic_attr = (XimDefICValues *)top;
+
+ if (res->xrm_name == pre_quark) {
+ XIMArg *arg_rt;
+ if ((name = _XimEncodeICATTRIBUTE(ic, res_list, res_num,
+ (XIMArg *)p->value, &arg_rt,
+ (char *)&buf_s[2], (size - min_len),
+ &len, (XPointer)&ic_attr->preedit_attr, flag,
+ (mode | XIM_PREEDIT_ATTR)))) {
+ return name;
+ }
+
+ } else if (res->xrm_name == sts_quark) {
+ XIMArg *arg_rt;
+ if ((name = _XimEncodeICATTRIBUTE(ic, res_list, res_num,
+ (XIMArg *)p->value, &arg_rt,
+ (char *)&buf_s[2], (size - min_len),
+ &len, (XPointer)&ic_attr->status_attr, flag,
+ (mode | XIM_STATUS_ATTR)))) {
+ return name;
+ }
+ }
+ } else {
+#ifdef EXT_MOVE
+ if (flag)
+ *flag |= _XimExtenArgCheck(p);
+#endif
+ if (!(_XimEncodeLocalICAttr(ic, res, top, p, mode)))
+ return p->name;
+
+ if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
+ (size - min_len), p->value,
+ &len, mode, (XPointer)ic)))
+ return p->name;
+ }
+
+ if (len == 0) {
+ continue;
+ } else if (len < 0) {
+ *arg_ret = p;
+ return (char *)NULL;
+ }
+
+ buf_s[0] = res->id; /* attribute ID */
+ buf_s[1] = len; /* value length */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += min_len;
+
+ buf += len;
+ *ret_len += len;
+ size -= len;
+ }
+ *arg_ret = (XIMArg *)NULL;
+ return (char *)NULL;
+}
+
+#ifdef XIM_CONNECTABLE
+Private Bool
+_XimEncodeSavedPreeditValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer value)
+{
+ int list_ret;
+ XFontStruct **struct_list;
+ char **name_list;
+ char *tmp;
+ int len;
+ register int i;
+
+ if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
+ if (!value)
+ return False;
+
+ if (ic->private.proto.preedit_font)
+ Xfree(ic->private.proto.preedit_font);
+
+ list_ret = XFontsOfFontSet((XFontSet)value,
+ &struct_list, &name_list);
+ for(i = 0, len = 0; i < list_ret; i++) {
+ len += (strlen(name_list[i]) + sizeof(char));
+ }
+ if(!(tmp = Xmalloc(len + 1))) {
+ ic->private.proto.preedit_font = NULL;
+ return False;
+ }
+
+ tmp[0] = '\0';
+ for(i = 0; i < list_ret; i++) {
+ strcat(tmp, name_list[i]);
+ strcat(tmp, ",");
+ }
+ tmp[len - 1] = 0;
+ ic->private.proto.preedit_font = tmp;
+ ic->private.proto.preedit_font_length = len - 1;
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeSavedStatusValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer value)
+{
+ int list_ret;
+ XFontStruct **struct_list;
+ char **name_list;
+ char *tmp;
+ int len;
+ register int i;
+
+ if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
+ if (!value)
+ return False;
+
+ if (ic->private.proto.status_font)
+ Xfree(ic->private.proto.status_font);
+
+ list_ret = XFontsOfFontSet((XFontSet)value,
+ &struct_list, &name_list);
+ for(i = 0, len = 0; i < list_ret; i++) {
+ len += (strlen(name_list[i]) + sizeof(char));
+ }
+ if(!(tmp = Xmalloc(len + 1))) {
+ ic->private.proto.status_font = NULL;
+ return False;
+ }
+
+ tmp[0] = '\0';
+ for(i = 0; i < list_ret; i++) {
+ strcat(tmp, name_list[i]);
+ strcat(tmp, ",");
+ }
+ tmp[len - 1] = 0;
+ ic->private.proto.status_font = tmp;
+ ic->private.proto.status_font_length = len - 1;
+ }
+ return True;
+}
+
+Public Bool
+_XimEncodeSavedICATTRIBUTE(
+ Xic ic,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ int *idx,
+ char *buf,
+ int size,
+ int *ret_len,
+ XPointer top,
+ unsigned long mode)
+{
+ int i;
+ int num = ic->private.proto.num_saved_icvalues;
+ XrmQuark *quark_list = ic->private.proto.saved_icvalues;
+ XIMResourceList res;
+ XPointer value;
+ CARD16 *buf_s;
+ int len;
+ int min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(INT16); /* sizeof value length */
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+ XrmQuark separator;
+
+ if (!ic->private.proto.saved_icvalues) {
+ *idx = -1;
+ *ret_len = 0;
+ return True;
+ }
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+ separator = XrmStringToQuark(XNSeparatorofNestedList);
+
+ *ret_len = 0;
+ for (i = *idx; i < num; i++) {
+ if (quark_list[i] == separator) {
+ *idx = i;
+ return True;
+ }
+
+ if (!(res = _XimGetResourceListRecByQuark(res_list,
+ res_num, quark_list[i])))
+ continue;
+
+ if (!_XimDecodeLocalICAttr(res, top,(XPointer)&value, mode))
+ return False;
+
+ if (mode & XIM_PREEDIT_ATTR) {
+ if (!(_XimEncodeSavedPreeditValue(ic, res, value))) {
+ return False;
+ }
+ } else if (mode & XIM_STATUS_ATTR) {
+ if (!(_XimEncodeSavedStatusValue(ic, res, value))) {
+ return False;
+ }
+ }
+
+ buf_s = (CARD16 *)buf;
+ if (res->resource_size == XimType_NEST) {
+ XimDefICValues *ic_attr = (XimDefICValues *)top;
+
+ i++;
+ if (res->xrm_name == pre_quark) {
+ if (!_XimEncodeSavedICATTRIBUTE(ic, res_list, res_num,
+ &i, (char *)&buf_s[2], (size - min_len),
+ &len, (XPointer)&ic_attr->preedit_attr,
+ (mode | XIM_PREEDIT_ATTR))) {
+ return False;
+ }
+
+ } else if (res->xrm_name == sts_quark) {
+ if (!_XimEncodeSavedICATTRIBUTE(ic, res_list, res_num,
+ &i, (char *)&buf_s[2], (size - min_len),
+ &len, (XPointer)&ic_attr->status_attr,
+ (mode | XIM_STATUS_ATTR))) {
+ return False;
+ }
+ }
+ } else {
+ if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
+ (size - min_len), value,
+ &len, mode, (XPointer)ic))) {
+ return False;
+ }
+ }
+
+ if (len == 0) {
+ continue;
+ } else if (len < 0) {
+ if (quark_list[i] == separator)
+ i++;
+ *idx = i;
+ return True;
+ }
+
+ buf_s[0] = res->id; /* attribute ID */
+ buf_s[1] = len; /* value length */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += min_len;
+
+ buf += len;
+ *ret_len += len;
+ size -= len;
+ }
+ *idx = -1;
+ return True;
+}
+#endif /* XIM_CONNECTABLE */
+
+Private unsigned int
+_XimCountNumberOfAttr(
+ INT16 total,
+ CARD16 *attr,
+ int *names_len)
+{
+ unsigned int n;
+ INT16 len;
+ INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(CARD16) /* sizeof type of value */
+ + sizeof(INT16); /* sizeof length of attribute */
+
+ n = 0;
+ *names_len = 0;
+ while (total > min_len) {
+ len = attr[2];
+ *names_len += (len + 1);
+ len += (min_len + XIM_PAD(len + 2));
+ total -= len;
+ attr = (CARD16 *)((char *)attr + len);
+ n++;
+ }
+ return n;
+}
+
+Public Bool
+_XimGetAttributeID(
+ Xim im,
+ CARD16 *buf)
+{
+ unsigned int n;
+ XIMResourceList res;
+ char *names;
+ int names_len;
+ XPointer tmp;
+ XIMValuesList *values_list;
+ char **values;
+ int values_len;
+ register int i;
+ INT16 len;
+ INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(CARD16) /* sizeof type of value */
+ + sizeof(INT16); /* sizeof length of attr */
+ /*
+ * IM attribute ID
+ */
+
+ if (!(n = _XimCountNumberOfAttr(buf[0], &buf[1], &names_len)))
+ return False;
+
+ if (!(res = Xcalloc(n, sizeof(XIMResource))))
+ return False;
+
+ values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len;
+ if (!(tmp = Xcalloc(1, values_len))) {
+ Xfree(res);
+ return False;
+ }
+
+ values_list = (XIMValuesList *)tmp;
+ values = (char **)((char *)tmp + sizeof(XIMValuesList));
+ names = (char *)((char *)values + (sizeof(char **) * n));
+
+ values_list->count_values = n;
+ values_list->supported_values = values;
+
+ buf++;
+ for (i = 0; i < n; i++) {
+ len = buf[2];
+ (void)memcpy(names, (char *)&buf[3], len);
+ values[i] = names;
+ names[len] = '\0';
+ res[i].resource_name = names;
+ res[i].resource_size = buf[1];
+ res[i].id = buf[0];
+ names += (len + 1);
+ len += (min_len + XIM_PAD(len + 2));
+ buf = (CARD16 *)((char *)buf + len);
+ }
+ _XIMCompileResourceList(res, n);
+
+ if (im->core.im_resources)
+ Xfree(im->core.im_resources);
+ if (im->core.im_values_list)
+ Xfree(im->core.im_values_list);
+ im->core.im_resources = res;
+ im->core.im_num_resources = n;
+ im->core.im_values_list = values_list;
+
+ /*
+ * IC attribute ID
+ */
+
+ if (!(n = _XimCountNumberOfAttr(buf[0], &buf[2], &names_len)))
+ return False;
+
+ if (!(res = Xcalloc(n, sizeof(XIMResource))))
+ return False;
+
+ values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len;
+ if (!(tmp = Xcalloc(1, values_len))) {
+ Xfree(res);
+ return False;
+ }
+
+ values_list = (XIMValuesList *)tmp;
+ values = (char **)((char *)tmp + sizeof(XIMValuesList));
+ names = (char *)((char *)values + (sizeof(char **) * n));
+
+ values_list->count_values = n;
+ values_list->supported_values = values;
+
+ buf += 2;
+ for (i = 0; i < n; i++) {
+ len = buf[2];
+ (void)memcpy(names, (char *)&buf[3], len);
+ values[i] = names;
+ names[len] = '\0';
+ res[i].resource_name = names;
+ res[i].resource_size = buf[1];
+ res[i].id = buf[0];
+ names += (len + 1);
+ len += (min_len + XIM_PAD(len + 2));
+ buf = (CARD16 *)((char *)buf + len);
+ }
+ _XIMCompileResourceList(res, n);
+
+ if (im->core.ic_resources)
+ Xfree(im->core.ic_resources);
+ if (im->core.ic_values_list)
+ Xfree(im->core.ic_values_list);
+ im->core.ic_resources = res;
+ im->core.ic_num_resources = n;
+ im->core.ic_values_list = values_list;
+
+ return True;
+}
diff --git a/libX11/modules/im/ximcp/imThaiIc.c b/libX11/modules/im/ximcp/imThaiIc.c
index 6b8784387..95433f3d7 100644
--- a/libX11/modules/im/ximcp/imThaiIc.c
+++ b/libX11/modules/im/ximcp/imThaiIc.c
@@ -1,227 +1,227 @@
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
- Copyright 1993 by Digital Equipment Corporation
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of FUJITSU LIMITED and
-Digital Equipment Corporation not be used in advertising or publicity
-pertaining to distribution of the software without specific, written
-prior permission. FUJITSU LIMITED and Digital Equipment Corporation
-makes no representations about the suitability of this software for
-any purpose. It is provided "as is" without express or implied
-warranty.
-
-FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
-ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
- Modifier: Franky Ling Digital Equipment Corporation
- frankyling@hgrd01.enet.dec.com
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <X11/Xlib.h>
-#include <X11/Xmd.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-Private void
-_XimThaiUnSetFocus(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
-
- if (ic->core.focus_window)
- _XUnregisterFilter(ic->core.im->core.display, ic->core.focus_window,
- _XimThaiFilter, (XPointer)ic);
- return;
-}
-
-Private void
-_XimThaiDestroyIC(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- DefTreeBase *b = &ic->private.local.base;
-
- if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
- _XimThaiUnSetFocus(xic);
- }
- if(ic->private.local.ic_resources) {
- Xfree(ic->private.local.ic_resources);
- ic->private.local.ic_resources = NULL;
- }
-
- if (b->tree) Xfree (b->tree);
- if (b->mb) Xfree (b->mb);
- if (b->wc) Xfree (b->wc);
- if (b->utf8) Xfree (b->utf8);
- b->tree = NULL;
- b->mb = NULL;
- b->wc = NULL;
- b->utf8 = NULL;
- return;
-}
-
-Private void
-_XimThaiSetFocus(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
-
- if (current_ic == (XIC)ic)
- return;
-
- if (current_ic != (XIC)NULL) {
- _XimThaiUnSetFocus(current_ic);
- }
- ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
-
- if (ic->core.focus_window)
- _XRegisterFilterByType(ic->core.im->core.display, ic->core.focus_window,
- KeyPress, KeyPress, _XimThaiFilter, (XPointer)ic);
- return;
-}
-
-Private void
-_XimThaiReset(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- DefTreeBase *b = &ic->private.local.base;
- ic->private.local.thai.comp_state = 0;
- ic->private.local.thai.keysym = 0;
- b->mb[b->tree[ic->private.local.composed].mb] = '\0';
- b->wc[b->tree[ic->private.local.composed].wc] = '\0';
- b->utf8[b->tree[ic->private.local.composed].utf8] = '\0';
-}
-
-Private char *
-_XimThaiMbReset(
- XIC xic)
-{
- _XimThaiReset(xic);
- return (char *)NULL;
-}
-
-Private wchar_t *
-_XimThaiWcReset(
- XIC xic)
-{
- _XimThaiReset(xic);
- return (wchar_t *)NULL;
-}
-
-Private XICMethodsRec Thai_ic_methods = {
- _XimThaiDestroyIC, /* destroy */
- _XimThaiSetFocus, /* set_focus */
- _XimThaiUnSetFocus, /* unset_focus */
- _XimLocalSetICValues, /* set_values */
- _XimLocalGetICValues, /* get_values */
- _XimThaiMbReset, /* mb_reset */
- _XimThaiWcReset, /* wc_reset */
- _XimThaiMbReset, /* utf8_reset */
- _XimLocalMbLookupString, /* mb_lookup_string */
- _XimLocalWcLookupString, /* wc_lookup_string */
- _XimLocalUtf8LookupString /* utf8_lookup_string */
-};
-
-XIC
-_XimThaiCreateIC(
- XIM im,
- XIMArg *values)
-{
- Xic ic;
- XimDefICValues ic_values;
- XIMResourceList res;
- unsigned int num;
- int len;
- DefTree *tree;
-
- if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
- return ((XIC)NULL);
- }
-
- ic->methods = &Thai_ic_methods;
- ic->core.im = im;
- ic->core.filter_events = KeyPressMask;
-
- if (! (ic->private.local.base.tree = tree = (DefTree *)Xmalloc(sizeof(DefTree)*3)) )
- goto Set_Error;
- if (! (ic->private.local.base.mb = (char *)Xmalloc(21)) )
- goto Set_Error;
- if (! (ic->private.local.base.wc = (wchar_t*)Xmalloc(sizeof(wchar_t)*21)) )
- goto Set_Error;
- if (! (ic->private.local.base.utf8 = (char *)Xmalloc(21)) )
- goto Set_Error;
- ic->private.local.context = 1;
- tree[1].mb = 1;
- tree[1].wc = 1;
- tree[1].utf8 = 1;
- ic->private.local.composed = 2;
- tree[2].mb = 11;
- tree[2].wc = 11;
- tree[2].utf8 = 11;
-
- ic->private.local.thai.comp_state = 0;
- ic->private.local.thai.keysym = 0;
- ic->private.local.thai.input_mode = 0;
-
- num = im->core.ic_num_resources;
- len = sizeof(XIMResource) * num;
- if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) {
- goto Set_Error;
- }
- (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
- ic->private.local.ic_resources = res;
- ic->private.local.ic_num_resources = num;
-
- bzero((char *)&ic_values, sizeof(XimDefICValues));
- if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
- im->core.styles, res, num) == False) {
- goto Set_Error;
- }
-
- _XimSetICMode(res, num, ic_values.input_style);
-
- if(_XimSetICValueData(ic, (XPointer)&ic_values,
- ic->private.local.ic_resources,
- ic->private.local.ic_num_resources,
- values, XIM_CREATEIC, True)) {
- goto Set_Error;
- }
- if(_XimSetICDefaults(ic, (XPointer)&ic_values,
- XIM_SETICDEFAULTS, res, num) == False) {
- goto Set_Error;
- }
- ic_values.filter_events = KeyPressMask;
- _XimSetCurrentICValues(ic, &ic_values);
-
- return ((XIC)ic);
-
-Set_Error :
- if (ic->private.local.ic_resources) {
- Xfree(ic->private.local.ic_resources);
- }
- Xfree(ic);
- return((XIC)NULL);
-}
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+ Copyright 1993 by Digital Equipment Corporation
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of FUJITSU LIMITED and
+Digital Equipment Corporation not be used in advertising or publicity
+pertaining to distribution of the software without specific, written
+prior permission. FUJITSU LIMITED and Digital Equipment Corporation
+makes no representations about the suitability of this software for
+any purpose. It is provided "as is" without express or implied
+warranty.
+
+FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
+ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+ Modifier: Franky Ling Digital Equipment Corporation
+ frankyling@hgrd01.enet.dec.com
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlib.h>
+#include <X11/Xmd.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Private void
+_XimThaiUnSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
+
+ if (ic->core.focus_window)
+ _XUnregisterFilter(ic->core.im->core.display, ic->core.focus_window,
+ _XimThaiFilter, (XPointer)ic);
+ return;
+}
+
+Private void
+_XimThaiDestroyIC(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ DefTreeBase *b = &ic->private.local.base;
+
+ if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
+ _XimThaiUnSetFocus(xic);
+ }
+ if(ic->private.local.ic_resources) {
+ Xfree(ic->private.local.ic_resources);
+ ic->private.local.ic_resources = NULL;
+ }
+
+ if (b->tree) Xfree (b->tree);
+ if (b->mb) Xfree (b->mb);
+ if (b->wc) Xfree (b->wc);
+ if (b->utf8) Xfree (b->utf8);
+ b->tree = NULL;
+ b->mb = NULL;
+ b->wc = NULL;
+ b->utf8 = NULL;
+ return;
+}
+
+Private void
+_XimThaiSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
+
+ if (current_ic == (XIC)ic)
+ return;
+
+ if (current_ic != (XIC)NULL) {
+ _XimThaiUnSetFocus(current_ic);
+ }
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
+
+ if (ic->core.focus_window)
+ _XRegisterFilterByType(ic->core.im->core.display, ic->core.focus_window,
+ KeyPress, KeyPress, _XimThaiFilter, (XPointer)ic);
+ return;
+}
+
+Private void
+_XimThaiReset(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ DefTreeBase *b = &ic->private.local.base;
+ ic->private.local.thai.comp_state = 0;
+ ic->private.local.thai.keysym = 0;
+ b->mb[b->tree[ic->private.local.composed].mb] = '\0';
+ b->wc[b->tree[ic->private.local.composed].wc] = '\0';
+ b->utf8[b->tree[ic->private.local.composed].utf8] = '\0';
+}
+
+Private char *
+_XimThaiMbReset(
+ XIC xic)
+{
+ _XimThaiReset(xic);
+ return (char *)NULL;
+}
+
+Private wchar_t *
+_XimThaiWcReset(
+ XIC xic)
+{
+ _XimThaiReset(xic);
+ return (wchar_t *)NULL;
+}
+
+Private XICMethodsRec Thai_ic_methods = {
+ _XimThaiDestroyIC, /* destroy */
+ _XimThaiSetFocus, /* set_focus */
+ _XimThaiUnSetFocus, /* unset_focus */
+ _XimLocalSetICValues, /* set_values */
+ _XimLocalGetICValues, /* get_values */
+ _XimThaiMbReset, /* mb_reset */
+ _XimThaiWcReset, /* wc_reset */
+ _XimThaiMbReset, /* utf8_reset */
+ _XimLocalMbLookupString, /* mb_lookup_string */
+ _XimLocalWcLookupString, /* wc_lookup_string */
+ _XimLocalUtf8LookupString /* utf8_lookup_string */
+};
+
+XIC
+_XimThaiCreateIC(
+ XIM im,
+ XIMArg *values)
+{
+ Xic ic;
+ XimDefICValues ic_values;
+ XIMResourceList res;
+ unsigned int num;
+ int len;
+ DefTree *tree;
+
+ if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
+ return ((XIC)NULL);
+ }
+
+ ic->methods = &Thai_ic_methods;
+ ic->core.im = im;
+ ic->core.filter_events = KeyPressMask;
+
+ if (! (ic->private.local.base.tree = tree = (DefTree *)Xmalloc(sizeof(DefTree)*3)) )
+ goto Set_Error;
+ if (! (ic->private.local.base.mb = (char *)Xmalloc(21)) )
+ goto Set_Error;
+ if (! (ic->private.local.base.wc = (wchar_t*)Xmalloc(sizeof(wchar_t)*21)) )
+ goto Set_Error;
+ if (! (ic->private.local.base.utf8 = (char *)Xmalloc(21)) )
+ goto Set_Error;
+ ic->private.local.context = 1;
+ tree[1].mb = 1;
+ tree[1].wc = 1;
+ tree[1].utf8 = 1;
+ ic->private.local.composed = 2;
+ tree[2].mb = 11;
+ tree[2].wc = 11;
+ tree[2].utf8 = 11;
+
+ ic->private.local.thai.comp_state = 0;
+ ic->private.local.thai.keysym = 0;
+ ic->private.local.thai.input_mode = 0;
+
+ num = im->core.ic_num_resources;
+ len = sizeof(XIMResource) * num;
+ if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) {
+ goto Set_Error;
+ }
+ (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
+ ic->private.local.ic_resources = res;
+ ic->private.local.ic_num_resources = num;
+
+ bzero((char *)&ic_values, sizeof(XimDefICValues));
+ if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
+ im->core.styles, res, num) == False) {
+ goto Set_Error;
+ }
+
+ _XimSetICMode(res, num, ic_values.input_style);
+
+ if(_XimSetICValueData(ic, (XPointer)&ic_values,
+ ic->private.local.ic_resources,
+ ic->private.local.ic_num_resources,
+ values, XIM_CREATEIC, True)) {
+ goto Set_Error;
+ }
+ if(_XimSetICDefaults(ic, (XPointer)&ic_values,
+ XIM_SETICDEFAULTS, res, num) == False) {
+ goto Set_Error;
+ }
+ ic_values.filter_events = KeyPressMask;
+ _XimSetCurrentICValues(ic, &ic_values);
+
+ return ((XIC)ic);
+
+Set_Error :
+ if (ic->private.local.ic_resources) {
+ Xfree(ic->private.local.ic_resources);
+ }
+ Xfree(ic);
+ return((XIC)NULL);
+}
diff --git a/libX11/modules/im/ximcp/imTrX.c b/libX11/modules/im/ximcp/imTrX.c
index 27ef03e21..d85d1d114 100644
--- a/libX11/modules/im/ximcp/imTrX.c
+++ b/libX11/modules/im/ximcp/imTrX.c
@@ -1,518 +1,518 @@
-/*
- * Copyright 1992 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
- Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <string.h>
-#include <X11/Xatom.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "XimTrInt.h"
-#include "XimTrX.h"
-
-Private Bool
-_XimXRegisterDispatcher(
- Xim im,
- Bool (*callback)(
- Xim, INT16, XPointer, XPointer
- ),
- XPointer call_data)
-{
- XIntrCallbackPtr rec;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
-
- if (!(rec = (XIntrCallbackPtr)Xmalloc(sizeof(XIntrCallbackRec))))
- return False;
-
- rec->func = callback;
- rec->call_data = call_data;
- rec->next = spec->intr_cb;
- spec->intr_cb = rec;
- return True;
-}
-
-Private void
-_XimXFreeIntrCallback(
- Xim im)
-{
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- register XIntrCallbackPtr rec, next;
-
- for (rec = spec->intr_cb; rec;) {
- next = rec->next;
- Xfree(rec);
- rec = next;
- }
- return;
-}
-
-Private Bool
-_XimXCallDispatcher(Xim im, INT16 len, XPointer data)
-{
- register XIntrCallbackRec *rec;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
-
- for (rec = spec->intr_cb; rec; rec = rec->next) {
- if ((*rec->func)(im, len, data, rec->call_data))
- return True;
- }
- return False;
-}
-
-Private Bool
-_XimXFilterWaitEvent(
- Display *d,
- Window w,
- XEvent *ev,
- XPointer arg)
-{
- Xim im = (Xim)arg;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- Bool ret;
-
- spec->ev = (XPointer)ev;
- ret = _XimFilterWaitEvent(im);
-
- /*
- * If ev is a pointer to a stack variable, there could be
- * a coredump later on if the pointer is dereferenced.
- * Therefore, reset to NULL to force reinitialization in
- * _XimXRead().
- *
- * Keep in mind _XimXRead may be called again when the stack
- * is very different.
- */
- spec->ev = (XPointer)NULL;
-
- return ret;
-}
-
-Private Bool
-_CheckConnect(
- Display *display,
- XEvent *event,
- XPointer xim)
-{
- Xim im = (Xim)xim;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
-
- if ((event->type == ClientMessage)
- && (event->xclient.message_type == spec->imconnectid)) {
- return True;
- }
- return False;
-}
-
-Private Bool
-_XimXConnect(Xim im)
-{
- XEvent event;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- CARD32 major_code;
- CARD32 minor_code;
-
- if (!(spec->lib_connect_wid = XCreateSimpleWindow(im->core.display,
- DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0))) {
- return False;
- }
-
- event.xclient.type = ClientMessage;
- event.xclient.display = im->core.display;
- event.xclient.window = im->private.proto.im_window;
- event.xclient.message_type = spec->imconnectid;
- event.xclient.format = 32;
- event.xclient.data.l[0] = (CARD32)spec->lib_connect_wid;
- event.xclient.data.l[1] = spec->major_code;
- event.xclient.data.l[2] = spec->minor_code;
- event.xclient.data.l[3] = 0;
- event.xclient.data.l[4] = 0;
-
- if(event.xclient.data.l[1] == 1 || event.xclient.data.l[1] == 2) {
- XWindowAttributes atr;
- long event_mask;
-
- XGetWindowAttributes(im->core.display, spec->lib_connect_wid, &atr);
- event_mask = atr.your_event_mask | PropertyChangeMask;
- XSelectInput(im->core.display, spec->lib_connect_wid, event_mask);
- _XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
- PropertyNotify, PropertyNotify,
- _XimXFilterWaitEvent, (XPointer)im);
- }
-
- XSendEvent(im->core.display, im->private.proto.im_window,
- False, NoEventMask, &event);
- XFlush(im->core.display);
-
- for (;;) {
- XIfEvent(im->core.display, &event, _CheckConnect, (XPointer)im);
- if (event.xclient.type != ClientMessage) {
- return False;
- }
- if (event.xclient.message_type == spec->imconnectid)
- break;
- }
-
- spec->ims_connect_wid = (Window)event.xclient.data.l[0];
- major_code = (CARD32)event.xclient.data.l[1];
- minor_code = (CARD32)event.xclient.data.l[2];
-
- if (((major_code == 0) && (minor_code <= 2)) ||
- ((major_code == 1) && (minor_code == 0)) ||
- ((major_code == 2) && (minor_code <= 1))) {
- spec->major_code = major_code;
- spec->minor_code = minor_code;
- }
- if (((major_code == 0) && (minor_code == 2)) ||
- ((major_code == 2) && (minor_code == 1))) {
- spec->BoundarySize = (CARD32)event.xclient.data.l[3];
- }
-
- /* ClientMessage Event Filter */
- _XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
- ClientMessage, ClientMessage,
- _XimXFilterWaitEvent, (XPointer)im);
- return True;
-}
-
-Private Bool
-_XimXShutdown(Xim im)
-{
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
-
- if (!spec)
- return True;
-
- /* ClientMessage Event Filter */
- _XUnregisterFilter(im->core.display,
- ((XSpecRec *)im->private.proto.spec)->lib_connect_wid,
- _XimXFilterWaitEvent, (XPointer)im);
- XDestroyWindow(im->core.display,
- ((XSpecRec *)im->private.proto.spec)->lib_connect_wid);
- _XimXFreeIntrCallback(im);
- Xfree(spec);
- im->private.proto.spec = 0;
- return True;
-}
-
-Private char *
-_NewAtom(
- char *atomName)
-{
- static int sequence = 0;
-
- (void)sprintf(atomName, "_client%d", sequence);
- sequence = ((sequence < 20) ? sequence + 1 : 0);
- return atomName;
-}
-
-Private Bool
-_XimXWrite(Xim im, INT16 len, XPointer data)
-{
- Atom atom;
- char atomName[16];
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- XEvent event;
- CARD8 *p;
- CARD32 major_code = spec->major_code;
- CARD32 minor_code = spec->minor_code;
- int BoundSize;
-
- bzero(&event,sizeof(XEvent));
- event.xclient.type = ClientMessage;
- event.xclient.display = im->core.display;
- event.xclient.window = spec->ims_connect_wid;
- if(major_code == 1 && minor_code == 0) {
- BoundSize = 0;
- } else if((major_code == 0 && minor_code == 2) ||
- (major_code == 2 && minor_code == 1)) {
- BoundSize = spec->BoundarySize;
- } else if(major_code == 0 && minor_code == 1) {
- BoundSize = len;
- } else {
- BoundSize = XIM_CM_DATA_SIZE;
- }
- if (len > BoundSize) {
- event.xclient.message_type = spec->improtocolid;
- atom = XInternAtom(im->core.display, _NewAtom(atomName), False);
- XChangeProperty(im->core.display, spec->ims_connect_wid,
- atom, XA_STRING, 8, PropModeAppend,
- (unsigned char *)data, len);
- if(major_code == 0) {
- event.xclient.format = 32;
- event.xclient.data.l[0] = (long)len;
- event.xclient.data.l[1] = (long)atom;
- XSendEvent(im->core.display, spec->ims_connect_wid,
- False, NoEventMask, &event);
- }
- } else {
- int length;
-
- event.xclient.format = 8;
- for(length = 0 ; length < len ; length += XIM_CM_DATA_SIZE) {
- p = (CARD8 *)&event.xclient.data.b[0];
- if((length + XIM_CM_DATA_SIZE) >= len) {
- event.xclient.message_type = spec->improtocolid;
- bzero(p, XIM_CM_DATA_SIZE);
- memcpy((char *)p, (data + length), (len - length));
- } else {
- event.xclient.message_type = spec->immoredataid;
- memcpy((char *)p, (data + length), XIM_CM_DATA_SIZE);
- }
- XSendEvent(im->core.display, spec->ims_connect_wid,
- False, NoEventMask, &event);
- }
- }
-
- return True;
-}
-
-Private Bool
-_XimXGetReadData(
- Xim im,
- char *buf,
- int buf_len,
- int *ret_len,
- XEvent *event)
-{
- char *data;
- int len;
-
- char tmp_buf[XIM_CM_DATA_SIZE];
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- unsigned long length;
- Atom prop;
- int return_code;
- Atom type_ret;
- int format_ret;
- unsigned long nitems;
- unsigned long bytes_after_ret;
- unsigned char *prop_ret;
-
- if ((event->type == ClientMessage) &&
- !((event->xclient.message_type == spec->improtocolid) ||
- (event->xclient.message_type == spec->immoredataid))) {
- /* This event has nothing to do with us,
- * FIXME should not have gotten here then...
- */
- return False;
- } else if ((event->type == ClientMessage) && (event->xclient.format == 8)) {
- data = event->xclient.data.b;
- if (buf_len >= XIM_CM_DATA_SIZE) {
- (void)memcpy(buf, data, XIM_CM_DATA_SIZE);
- *ret_len = XIM_CM_DATA_SIZE;
- } else {
- (void)memcpy(buf, data, buf_len);
- len = XIM_CM_DATA_SIZE - buf_len;
- (void)memcpy(tmp_buf, &data[buf_len], len);
- bzero(data, XIM_CM_DATA_SIZE);
- (void)memcpy(data, tmp_buf, len);
- XPutBackEvent(im->core.display, event);
- *ret_len = buf_len;
- }
- } else if ((event->type == ClientMessage)
- && (event->xclient.format == 32)) {
- length = (unsigned long)event->xclient.data.l[0];
- prop = (Atom)event->xclient.data.l[1];
- return_code = XGetWindowProperty(im->core.display,
- spec->lib_connect_wid, prop, 0L,
- (long)((length + 3)/ 4), True, AnyPropertyType,
- &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
- if (return_code != Success || format_ret == 0 || nitems == 0) {
- if (return_code == Success)
- XFree(prop_ret);
- return False;
- }
- if (buf_len >= length) {
- (void)memcpy(buf, prop_ret, (int)nitems);
- *ret_len = (int)nitems;
- if (bytes_after_ret > 0) {
- XFree(prop_ret);
- if (XGetWindowProperty(im->core.display,
- spec->lib_connect_wid, prop, 0L,
- ((length + bytes_after_ret + 3)/ 4),
- True, AnyPropertyType,
- &type_ret, &format_ret, &nitems,
- &bytes_after_ret,
- &prop_ret) == Success) {
- XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
- XA_STRING, 8, PropModePrepend, &prop_ret[length],
- (nitems - length));
- } else {
- return False;
- }
- }
- } else {
- (void)memcpy(buf, prop_ret, buf_len);
- *ret_len = buf_len;
- len = nitems - buf_len;
-
- if (bytes_after_ret > 0) {
- XFree(prop_ret);
- if (XGetWindowProperty(im->core.display,
- spec->lib_connect_wid, prop, 0L,
- ((length + bytes_after_ret + 3)/ 4),
- True, AnyPropertyType,
- &type_ret, &format_ret, &nitems,
- &bytes_after_ret, &prop_ret) != Success) {
- return False;
- }
- }
- XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
- XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
- event->xclient.data.l[0] = (long)len;
- event->xclient.data.l[1] = (long)prop;
- XPutBackEvent(im->core.display, event);
- }
- XFree(prop_ret);
- } else if (event->type == PropertyNotify) {
- prop = event->xproperty.atom;
- return_code = XGetWindowProperty(im->core.display,
- spec->lib_connect_wid, prop, 0L,
- 1000000L, True, AnyPropertyType,
- &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
- if (return_code != Success || format_ret == 0 || nitems == 0) {
- if (return_code == Success)
- XFree(prop_ret);
- return False;
- }
- if (buf_len >= nitems) {
- (void)memcpy(buf, prop_ret, (int)nitems);
- *ret_len = (int)nitems;
- } else {
- (void)memcpy(buf, prop_ret, buf_len);
- *ret_len = buf_len;
- len = nitems - buf_len;
- XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
- XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
- }
- XFree(prop_ret);
- }
- return True;
-}
-
-Private Bool
-_CheckCMEvent(
- Display *display,
- XEvent *event,
- XPointer xim)
-{
- Xim im = (Xim)xim;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- CARD32 major_code = spec->major_code;
-
- if ((event->type == ClientMessage)
- &&((event->xclient.message_type == spec->improtocolid) ||
- (event->xclient.message_type == spec->immoredataid)))
- return True;
- if((major_code == 1 || major_code == 2) &&
- (event->type == PropertyNotify) &&
- (event->xproperty.state == PropertyNewValue))
- return True;
- return False;
-}
-
-Private Bool
-_XimXRead(Xim im, XPointer recv_buf, int buf_len, int *ret_len)
-{
- XEvent *ev;
- XEvent event;
- int len = 0;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- XPointer arg = spec->ev;
-
- if (!arg) {
- bzero(&event, sizeof(XEvent));
- ev = &event;
- XIfEvent(im->core.display, ev, _CheckCMEvent, (XPointer)im);
- } else {
- ev = (XEvent *)arg;
- spec->ev = (XPointer)NULL;
- }
- if (!(_XimXGetReadData(im, recv_buf, buf_len, &len, ev)))
- return False;
- *ret_len = len;
- return True;
-}
-
-Private void
-_XimXFlush(Xim im)
-{
- XFlush(im->core.display);
- return;
-}
-
-Public Bool
-_XimXConf(Xim im, char *address)
-{
- XSpecRec *spec;
-
- if (!(spec = Xcalloc(1, sizeof(XSpecRec))))
- return False;
-
- spec->improtocolid = XInternAtom(im->core.display, _XIM_PROTOCOL, False);
- spec->imconnectid = XInternAtom(im->core.display, _XIM_XCONNECT, False);
- spec->immoredataid = XInternAtom(im->core.display, _XIM_MOREDATA, False);
- spec->major_code = MAJOR_TRANSPORT_VERSION;
- spec->minor_code = MINOR_TRANSPORT_VERSION;
-
- im->private.proto.spec = (XPointer)spec;
- im->private.proto.connect = _XimXConnect;
- im->private.proto.shutdown = _XimXShutdown;
- im->private.proto.write = _XimXWrite;
- im->private.proto.read = _XimXRead;
- im->private.proto.flush = _XimXFlush;
- im->private.proto.register_dispatcher = _XimXRegisterDispatcher;
- im->private.proto.call_dispatcher = _XimXCallDispatcher;
-
- return True;
-}
+/*
+ * Copyright 1992 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
+ Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <string.h>
+#include <X11/Xatom.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "XimTrInt.h"
+#include "XimTrX.h"
+
+Private Bool
+_XimXRegisterDispatcher(
+ Xim im,
+ Bool (*callback)(
+ Xim, INT16, XPointer, XPointer
+ ),
+ XPointer call_data)
+{
+ XIntrCallbackPtr rec;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+
+ if (!(rec = (XIntrCallbackPtr)Xmalloc(sizeof(XIntrCallbackRec))))
+ return False;
+
+ rec->func = callback;
+ rec->call_data = call_data;
+ rec->next = spec->intr_cb;
+ spec->intr_cb = rec;
+ return True;
+}
+
+Private void
+_XimXFreeIntrCallback(
+ Xim im)
+{
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ register XIntrCallbackPtr rec, next;
+
+ for (rec = spec->intr_cb; rec;) {
+ next = rec->next;
+ Xfree(rec);
+ rec = next;
+ }
+ return;
+}
+
+Private Bool
+_XimXCallDispatcher(Xim im, INT16 len, XPointer data)
+{
+ register XIntrCallbackRec *rec;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+
+ for (rec = spec->intr_cb; rec; rec = rec->next) {
+ if ((*rec->func)(im, len, data, rec->call_data))
+ return True;
+ }
+ return False;
+}
+
+Private Bool
+_XimXFilterWaitEvent(
+ Display *d,
+ Window w,
+ XEvent *ev,
+ XPointer arg)
+{
+ Xim im = (Xim)arg;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ Bool ret;
+
+ spec->ev = (XPointer)ev;
+ ret = _XimFilterWaitEvent(im);
+
+ /*
+ * If ev is a pointer to a stack variable, there could be
+ * a coredump later on if the pointer is dereferenced.
+ * Therefore, reset to NULL to force reinitialization in
+ * _XimXRead().
+ *
+ * Keep in mind _XimXRead may be called again when the stack
+ * is very different.
+ */
+ spec->ev = (XPointer)NULL;
+
+ return ret;
+}
+
+Private Bool
+_CheckConnect(
+ Display *display,
+ XEvent *event,
+ XPointer xim)
+{
+ Xim im = (Xim)xim;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+
+ if ((event->type == ClientMessage)
+ && (event->xclient.message_type == spec->imconnectid)) {
+ return True;
+ }
+ return False;
+}
+
+Private Bool
+_XimXConnect(Xim im)
+{
+ XEvent event;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ CARD32 major_code;
+ CARD32 minor_code;
+
+ if (!(spec->lib_connect_wid = XCreateSimpleWindow(im->core.display,
+ DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0))) {
+ return False;
+ }
+
+ event.xclient.type = ClientMessage;
+ event.xclient.display = im->core.display;
+ event.xclient.window = im->private.proto.im_window;
+ event.xclient.message_type = spec->imconnectid;
+ event.xclient.format = 32;
+ event.xclient.data.l[0] = (CARD32)spec->lib_connect_wid;
+ event.xclient.data.l[1] = spec->major_code;
+ event.xclient.data.l[2] = spec->minor_code;
+ event.xclient.data.l[3] = 0;
+ event.xclient.data.l[4] = 0;
+
+ if(event.xclient.data.l[1] == 1 || event.xclient.data.l[1] == 2) {
+ XWindowAttributes atr;
+ long event_mask;
+
+ XGetWindowAttributes(im->core.display, spec->lib_connect_wid, &atr);
+ event_mask = atr.your_event_mask | PropertyChangeMask;
+ XSelectInput(im->core.display, spec->lib_connect_wid, event_mask);
+ _XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
+ PropertyNotify, PropertyNotify,
+ _XimXFilterWaitEvent, (XPointer)im);
+ }
+
+ XSendEvent(im->core.display, im->private.proto.im_window,
+ False, NoEventMask, &event);
+ XFlush(im->core.display);
+
+ for (;;) {
+ XIfEvent(im->core.display, &event, _CheckConnect, (XPointer)im);
+ if (event.xclient.type != ClientMessage) {
+ return False;
+ }
+ if (event.xclient.message_type == spec->imconnectid)
+ break;
+ }
+
+ spec->ims_connect_wid = (Window)event.xclient.data.l[0];
+ major_code = (CARD32)event.xclient.data.l[1];
+ minor_code = (CARD32)event.xclient.data.l[2];
+
+ if (((major_code == 0) && (minor_code <= 2)) ||
+ ((major_code == 1) && (minor_code == 0)) ||
+ ((major_code == 2) && (minor_code <= 1))) {
+ spec->major_code = major_code;
+ spec->minor_code = minor_code;
+ }
+ if (((major_code == 0) && (minor_code == 2)) ||
+ ((major_code == 2) && (minor_code == 1))) {
+ spec->BoundarySize = (CARD32)event.xclient.data.l[3];
+ }
+
+ /* ClientMessage Event Filter */
+ _XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
+ ClientMessage, ClientMessage,
+ _XimXFilterWaitEvent, (XPointer)im);
+ return True;
+}
+
+Private Bool
+_XimXShutdown(Xim im)
+{
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+
+ if (!spec)
+ return True;
+
+ /* ClientMessage Event Filter */
+ _XUnregisterFilter(im->core.display,
+ ((XSpecRec *)im->private.proto.spec)->lib_connect_wid,
+ _XimXFilterWaitEvent, (XPointer)im);
+ XDestroyWindow(im->core.display,
+ ((XSpecRec *)im->private.proto.spec)->lib_connect_wid);
+ _XimXFreeIntrCallback(im);
+ Xfree(spec);
+ im->private.proto.spec = 0;
+ return True;
+}
+
+Private char *
+_NewAtom(
+ char *atomName)
+{
+ static int sequence = 0;
+
+ (void)sprintf(atomName, "_client%d", sequence);
+ sequence = ((sequence < 20) ? sequence + 1 : 0);
+ return atomName;
+}
+
+Private Bool
+_XimXWrite(Xim im, INT16 len, XPointer data)
+{
+ Atom atom;
+ char atomName[16];
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ XEvent event;
+ CARD8 *p;
+ CARD32 major_code = spec->major_code;
+ CARD32 minor_code = spec->minor_code;
+ int BoundSize;
+
+ bzero(&event,sizeof(XEvent));
+ event.xclient.type = ClientMessage;
+ event.xclient.display = im->core.display;
+ event.xclient.window = spec->ims_connect_wid;
+ if(major_code == 1 && minor_code == 0) {
+ BoundSize = 0;
+ } else if((major_code == 0 && minor_code == 2) ||
+ (major_code == 2 && minor_code == 1)) {
+ BoundSize = spec->BoundarySize;
+ } else if(major_code == 0 && minor_code == 1) {
+ BoundSize = len;
+ } else {
+ BoundSize = XIM_CM_DATA_SIZE;
+ }
+ if (len > BoundSize) {
+ event.xclient.message_type = spec->improtocolid;
+ atom = XInternAtom(im->core.display, _NewAtom(atomName), False);
+ XChangeProperty(im->core.display, spec->ims_connect_wid,
+ atom, XA_STRING, 8, PropModeAppend,
+ (unsigned char *)data, len);
+ if(major_code == 0) {
+ event.xclient.format = 32;
+ event.xclient.data.l[0] = (long)len;
+ event.xclient.data.l[1] = (long)atom;
+ XSendEvent(im->core.display, spec->ims_connect_wid,
+ False, NoEventMask, &event);
+ }
+ } else {
+ int length;
+
+ event.xclient.format = 8;
+ for(length = 0 ; length < len ; length += XIM_CM_DATA_SIZE) {
+ p = (CARD8 *)&event.xclient.data.b[0];
+ if((length + XIM_CM_DATA_SIZE) >= len) {
+ event.xclient.message_type = spec->improtocolid;
+ bzero(p, XIM_CM_DATA_SIZE);
+ memcpy((char *)p, (data + length), (len - length));
+ } else {
+ event.xclient.message_type = spec->immoredataid;
+ memcpy((char *)p, (data + length), XIM_CM_DATA_SIZE);
+ }
+ XSendEvent(im->core.display, spec->ims_connect_wid,
+ False, NoEventMask, &event);
+ }
+ }
+
+ return True;
+}
+
+Private Bool
+_XimXGetReadData(
+ Xim im,
+ char *buf,
+ int buf_len,
+ int *ret_len,
+ XEvent *event)
+{
+ char *data;
+ int len;
+
+ char tmp_buf[XIM_CM_DATA_SIZE];
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ unsigned long length;
+ Atom prop;
+ int return_code;
+ Atom type_ret;
+ int format_ret;
+ unsigned long nitems;
+ unsigned long bytes_after_ret;
+ unsigned char *prop_ret;
+
+ if ((event->type == ClientMessage) &&
+ !((event->xclient.message_type == spec->improtocolid) ||
+ (event->xclient.message_type == spec->immoredataid))) {
+ /* This event has nothing to do with us,
+ * FIXME should not have gotten here then...
+ */
+ return False;
+ } else if ((event->type == ClientMessage) && (event->xclient.format == 8)) {
+ data = event->xclient.data.b;
+ if (buf_len >= XIM_CM_DATA_SIZE) {
+ (void)memcpy(buf, data, XIM_CM_DATA_SIZE);
+ *ret_len = XIM_CM_DATA_SIZE;
+ } else {
+ (void)memcpy(buf, data, buf_len);
+ len = XIM_CM_DATA_SIZE - buf_len;
+ (void)memcpy(tmp_buf, &data[buf_len], len);
+ bzero(data, XIM_CM_DATA_SIZE);
+ (void)memcpy(data, tmp_buf, len);
+ XPutBackEvent(im->core.display, event);
+ *ret_len = buf_len;
+ }
+ } else if ((event->type == ClientMessage)
+ && (event->xclient.format == 32)) {
+ length = (unsigned long)event->xclient.data.l[0];
+ prop = (Atom)event->xclient.data.l[1];
+ return_code = XGetWindowProperty(im->core.display,
+ spec->lib_connect_wid, prop, 0L,
+ (long)((length + 3)/ 4), True, AnyPropertyType,
+ &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
+ if (return_code != Success || format_ret == 0 || nitems == 0) {
+ if (return_code == Success)
+ XFree(prop_ret);
+ return False;
+ }
+ if (buf_len >= length) {
+ (void)memcpy(buf, prop_ret, (int)nitems);
+ *ret_len = (int)nitems;
+ if (bytes_after_ret > 0) {
+ XFree(prop_ret);
+ if (XGetWindowProperty(im->core.display,
+ spec->lib_connect_wid, prop, 0L,
+ ((length + bytes_after_ret + 3)/ 4),
+ True, AnyPropertyType,
+ &type_ret, &format_ret, &nitems,
+ &bytes_after_ret,
+ &prop_ret) == Success) {
+ XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
+ XA_STRING, 8, PropModePrepend, &prop_ret[length],
+ (nitems - length));
+ } else {
+ return False;
+ }
+ }
+ } else {
+ (void)memcpy(buf, prop_ret, buf_len);
+ *ret_len = buf_len;
+ len = nitems - buf_len;
+
+ if (bytes_after_ret > 0) {
+ XFree(prop_ret);
+ if (XGetWindowProperty(im->core.display,
+ spec->lib_connect_wid, prop, 0L,
+ ((length + bytes_after_ret + 3)/ 4),
+ True, AnyPropertyType,
+ &type_ret, &format_ret, &nitems,
+ &bytes_after_ret, &prop_ret) != Success) {
+ return False;
+ }
+ }
+ XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
+ XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
+ event->xclient.data.l[0] = (long)len;
+ event->xclient.data.l[1] = (long)prop;
+ XPutBackEvent(im->core.display, event);
+ }
+ XFree(prop_ret);
+ } else if (event->type == PropertyNotify) {
+ prop = event->xproperty.atom;
+ return_code = XGetWindowProperty(im->core.display,
+ spec->lib_connect_wid, prop, 0L,
+ 1000000L, True, AnyPropertyType,
+ &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
+ if (return_code != Success || format_ret == 0 || nitems == 0) {
+ if (return_code == Success)
+ XFree(prop_ret);
+ return False;
+ }
+ if (buf_len >= nitems) {
+ (void)memcpy(buf, prop_ret, (int)nitems);
+ *ret_len = (int)nitems;
+ } else {
+ (void)memcpy(buf, prop_ret, buf_len);
+ *ret_len = buf_len;
+ len = nitems - buf_len;
+ XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
+ XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
+ }
+ XFree(prop_ret);
+ }
+ return True;
+}
+
+Private Bool
+_CheckCMEvent(
+ Display *display,
+ XEvent *event,
+ XPointer xim)
+{
+ Xim im = (Xim)xim;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ CARD32 major_code = spec->major_code;
+
+ if ((event->type == ClientMessage)
+ &&((event->xclient.message_type == spec->improtocolid) ||
+ (event->xclient.message_type == spec->immoredataid)))
+ return True;
+ if((major_code == 1 || major_code == 2) &&
+ (event->type == PropertyNotify) &&
+ (event->xproperty.state == PropertyNewValue))
+ return True;
+ return False;
+}
+
+Private Bool
+_XimXRead(Xim im, XPointer recv_buf, int buf_len, int *ret_len)
+{
+ XEvent *ev;
+ XEvent event;
+ int len = 0;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ XPointer arg = spec->ev;
+
+ if (!arg) {
+ bzero(&event, sizeof(XEvent));
+ ev = &event;
+ XIfEvent(im->core.display, ev, _CheckCMEvent, (XPointer)im);
+ } else {
+ ev = (XEvent *)arg;
+ spec->ev = (XPointer)NULL;
+ }
+ if (!(_XimXGetReadData(im, recv_buf, buf_len, &len, ev)))
+ return False;
+ *ret_len = len;
+ return True;
+}
+
+Private void
+_XimXFlush(Xim im)
+{
+ XFlush(im->core.display);
+ return;
+}
+
+Public Bool
+_XimXConf(Xim im, char *address)
+{
+ XSpecRec *spec;
+
+ if (!(spec = Xcalloc(1, sizeof(XSpecRec))))
+ return False;
+
+ spec->improtocolid = XInternAtom(im->core.display, _XIM_PROTOCOL, False);
+ spec->imconnectid = XInternAtom(im->core.display, _XIM_XCONNECT, False);
+ spec->immoredataid = XInternAtom(im->core.display, _XIM_MOREDATA, False);
+ spec->major_code = MAJOR_TRANSPORT_VERSION;
+ spec->minor_code = MINOR_TRANSPORT_VERSION;
+
+ im->private.proto.spec = (XPointer)spec;
+ im->private.proto.connect = _XimXConnect;
+ im->private.proto.shutdown = _XimXShutdown;
+ im->private.proto.write = _XimXWrite;
+ im->private.proto.read = _XimXRead;
+ im->private.proto.flush = _XimXFlush;
+ im->private.proto.register_dispatcher = _XimXRegisterDispatcher;
+ im->private.proto.call_dispatcher = _XimXCallDispatcher;
+
+ return True;
+}
diff --git a/libX11/modules/im/ximcp/imTrans.c b/libX11/modules/im/ximcp/imTrans.c
index a601affda..5c23211a5 100644
--- a/libX11/modules/im/ximcp/imTrans.c
+++ b/libX11/modules/im/ximcp/imTrans.c
@@ -1,315 +1,315 @@
-/*
- * Copyright 1992 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
- Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <unistd.h>
-#include <X11/Xatom.h>
-#include <X11/Xmd.h>
-#include "Xlibint.h"
-#include <X11/Xwindows.h>
-#include <X11/Xtrans/Xtrans.h>
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "XimTrans.h"
-#include "XimTrInt.h"
-
-#ifdef WIN32
-#include <X11/Xwindows.h>
-#endif
-
-
-#ifndef XIM_CONNECTION_RETRIES
-#define XIM_CONNECTION_RETRIES 5
-#endif
-
-
-Private Bool
-_XimTransConnect(
- Xim im)
-{
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
- int connect_stat, retry;
- Window window;
-
- for (retry = XIM_CONNECTION_RETRIES; retry >= 0; retry--)
- {
- if ((spec->trans_conn = _XimXTransOpenCOTSClient (
- spec->address)) == NULL)
- {
- break;
- }
-
- if ((connect_stat = _XimXTransConnect (
- spec->trans_conn, spec->address)) < 0)
- {
- _XimXTransClose (spec->trans_conn);
- spec->trans_conn = NULL;
-
- if (connect_stat == TRANS_TRY_CONNECT_AGAIN)
- continue;
- else
- break;
- }
- else
- break;
- }
-
- if (spec->trans_conn == NULL)
- return False;
-
- spec->fd = _XimXTransGetConnectionNumber (spec->trans_conn);
-
- if (!(window = XCreateSimpleWindow(im->core.display,
- DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0)))
- return False;
- spec->window = window;
-
- _XRegisterFilterByType(im->core.display, window, KeyPress, KeyPress,
- _XimTransFilterWaitEvent, (XPointer)im);
-
- return _XRegisterInternalConnection(im->core.display, spec->fd,
- (_XInternalConnectionProc)_XimTransInternalConnection,
- (XPointer)im);
-}
-
-
-Private Bool
-_XimTransShutdown(
- Xim im)
-{
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
-
- _XimXTransDisconnect(spec->trans_conn);
- (void)_XimXTransClose(spec->trans_conn);
- _XimFreeTransIntrCallback(im);
- _XUnregisterInternalConnection(im->core.display, spec->fd);
- _XUnregisterFilter(im->core.display, spec->window,
- _XimTransFilterWaitEvent, (XPointer)im);
- XDestroyWindow(im->core.display, spec->window);
- Xfree(spec->address);
- Xfree(spec);
- return True;
-}
-
-
-
-Public Bool
-_XimTransRegisterDispatcher(
- Xim im,
- Bool (*callback)(
- Xim, INT16, XPointer, XPointer
- ),
- XPointer call_data)
-{
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
- TransIntrCallbackPtr rec;
-
- if (!(rec = (TransIntrCallbackPtr)Xmalloc(sizeof(TransIntrCallbackRec))))
- return False;
-
- rec->func = callback;
- rec->call_data = call_data;
- rec->next = spec->intr_cb;
- spec->intr_cb = rec;
- return True;
-}
-
-
-Public void
-_XimFreeTransIntrCallback(
- Xim im)
-{
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
- register TransIntrCallbackPtr rec, next;
-
- for (rec = spec->intr_cb; rec;) {
- next = rec->next;
- Xfree(rec);
- rec = next;
- }
- return;
-}
-
-
-Public Bool
-_XimTransCallDispatcher(Xim im, INT16 len, XPointer data)
-{
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
- TransIntrCallbackRec *rec;
-
- for (rec = spec->intr_cb; rec; rec = rec->next) {
- if ((*rec->func)(im, len, data, rec->call_data))
- return True;
- }
- return False;
-}
-
-
-Public Bool
-_XimTransFilterWaitEvent(
- Display *d,
- Window w,
- XEvent *ev,
- XPointer arg)
-{
- Xim im = (Xim)arg;
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
-
- spec->is_putback = False;
- return _XimFilterWaitEvent(im);
-}
-
-
-Public void
-_XimTransInternalConnection(
- Display *d,
- int fd,
- XPointer arg)
-{
- Xim im = (Xim)arg;
- XEvent ev;
- XKeyEvent *kev;
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
-
- if (spec->is_putback)
- return;
- kev = (XKeyEvent *)&ev;
- kev->type = KeyPress;
- kev->send_event = False;
- kev->display = im->core.display;
- kev->window = spec->window;
- kev->keycode = 0;
- XPutBackEvent(im->core.display, &ev);
- XFlush(im->core.display);
- spec->is_putback = True;
- return;
-}
-
-
-Public Bool
-_XimTransWrite(Xim im, INT16 len, XPointer data)
-{
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
- char *buf = (char *)data;
- register int nbyte;
-
- while (len > 0) {
- if ((nbyte = _XimXTransWrite(spec->trans_conn, buf, len)) <= 0)
- return False;
- len -= nbyte;
- buf += nbyte;
- }
- return True;
-}
-
-
-Public Bool
-_XimTransRead(
- Xim im,
- XPointer recv_buf,
- int buf_len,
- int *ret_len)
-{
- TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
- int len;
-
- if (buf_len == 0) {
- *ret_len = 0;
- return True;
- }
- if ((len = _XimXTransRead(spec->trans_conn, recv_buf, buf_len)) <= 0)
- return False;
- *ret_len = len;
- return True;
-}
-
-
-Public void
-_XimTransFlush(
- Xim im)
-{
- return;
-}
-
-
-
-Public Bool
-_XimTransConf(
- Xim im,
- char *address)
-{
- char *paddr;
- TransSpecRec *spec;
-
- if (!(paddr = strdup(address)))
- return False;
-
- if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) {
- Xfree(paddr);
- return False;
- }
-
- spec->address = paddr;
-
- im->private.proto.spec = (XPointer)spec;
- im->private.proto.connect = _XimTransConnect;
- im->private.proto.shutdown = _XimTransShutdown;
- im->private.proto.write = _XimTransWrite;
- im->private.proto.read = _XimTransRead;
- im->private.proto.flush = _XimTransFlush;
- im->private.proto.register_dispatcher = _XimTransRegisterDispatcher;
- im->private.proto.call_dispatcher = _XimTransCallDispatcher;
-
- return True;
-}
+/*
+ * Copyright 1992 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
+ Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <unistd.h>
+#include <X11/Xatom.h>
+#include <X11/Xmd.h>
+#include "Xlibint.h"
+#include <X11/Xwindows.h>
+#include <X11/Xtrans/Xtrans.h>
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "XimTrans.h"
+#include "XimTrInt.h"
+
+#ifdef WIN32
+#include <X11/Xwindows.h>
+#endif
+
+
+#ifndef XIM_CONNECTION_RETRIES
+#define XIM_CONNECTION_RETRIES 5
+#endif
+
+
+Private Bool
+_XimTransConnect(
+ Xim im)
+{
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+ int connect_stat, retry;
+ Window window;
+
+ for (retry = XIM_CONNECTION_RETRIES; retry >= 0; retry--)
+ {
+ if ((spec->trans_conn = _XimXTransOpenCOTSClient (
+ spec->address)) == NULL)
+ {
+ break;
+ }
+
+ if ((connect_stat = _XimXTransConnect (
+ spec->trans_conn, spec->address)) < 0)
+ {
+ _XimXTransClose (spec->trans_conn);
+ spec->trans_conn = NULL;
+
+ if (connect_stat == TRANS_TRY_CONNECT_AGAIN)
+ continue;
+ else
+ break;
+ }
+ else
+ break;
+ }
+
+ if (spec->trans_conn == NULL)
+ return False;
+
+ spec->fd = _XimXTransGetConnectionNumber (spec->trans_conn);
+
+ if (!(window = XCreateSimpleWindow(im->core.display,
+ DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0)))
+ return False;
+ spec->window = window;
+
+ _XRegisterFilterByType(im->core.display, window, KeyPress, KeyPress,
+ _XimTransFilterWaitEvent, (XPointer)im);
+
+ return _XRegisterInternalConnection(im->core.display, spec->fd,
+ (_XInternalConnectionProc)_XimTransInternalConnection,
+ (XPointer)im);
+}
+
+
+Private Bool
+_XimTransShutdown(
+ Xim im)
+{
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+
+ _XimXTransDisconnect(spec->trans_conn);
+ (void)_XimXTransClose(spec->trans_conn);
+ _XimFreeTransIntrCallback(im);
+ _XUnregisterInternalConnection(im->core.display, spec->fd);
+ _XUnregisterFilter(im->core.display, spec->window,
+ _XimTransFilterWaitEvent, (XPointer)im);
+ XDestroyWindow(im->core.display, spec->window);
+ Xfree(spec->address);
+ Xfree(spec);
+ return True;
+}
+
+
+
+Public Bool
+_XimTransRegisterDispatcher(
+ Xim im,
+ Bool (*callback)(
+ Xim, INT16, XPointer, XPointer
+ ),
+ XPointer call_data)
+{
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+ TransIntrCallbackPtr rec;
+
+ if (!(rec = (TransIntrCallbackPtr)Xmalloc(sizeof(TransIntrCallbackRec))))
+ return False;
+
+ rec->func = callback;
+ rec->call_data = call_data;
+ rec->next = spec->intr_cb;
+ spec->intr_cb = rec;
+ return True;
+}
+
+
+Public void
+_XimFreeTransIntrCallback(
+ Xim im)
+{
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+ register TransIntrCallbackPtr rec, next;
+
+ for (rec = spec->intr_cb; rec;) {
+ next = rec->next;
+ Xfree(rec);
+ rec = next;
+ }
+ return;
+}
+
+
+Public Bool
+_XimTransCallDispatcher(Xim im, INT16 len, XPointer data)
+{
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+ TransIntrCallbackRec *rec;
+
+ for (rec = spec->intr_cb; rec; rec = rec->next) {
+ if ((*rec->func)(im, len, data, rec->call_data))
+ return True;
+ }
+ return False;
+}
+
+
+Public Bool
+_XimTransFilterWaitEvent(
+ Display *d,
+ Window w,
+ XEvent *ev,
+ XPointer arg)
+{
+ Xim im = (Xim)arg;
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+
+ spec->is_putback = False;
+ return _XimFilterWaitEvent(im);
+}
+
+
+Public void
+_XimTransInternalConnection(
+ Display *d,
+ int fd,
+ XPointer arg)
+{
+ Xim im = (Xim)arg;
+ XEvent ev;
+ XKeyEvent *kev;
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+
+ if (spec->is_putback)
+ return;
+ kev = (XKeyEvent *)&ev;
+ kev->type = KeyPress;
+ kev->send_event = False;
+ kev->display = im->core.display;
+ kev->window = spec->window;
+ kev->keycode = 0;
+ XPutBackEvent(im->core.display, &ev);
+ XFlush(im->core.display);
+ spec->is_putback = True;
+ return;
+}
+
+
+Public Bool
+_XimTransWrite(Xim im, INT16 len, XPointer data)
+{
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+ char *buf = (char *)data;
+ register int nbyte;
+
+ while (len > 0) {
+ if ((nbyte = _XimXTransWrite(spec->trans_conn, buf, len)) <= 0)
+ return False;
+ len -= nbyte;
+ buf += nbyte;
+ }
+ return True;
+}
+
+
+Public Bool
+_XimTransRead(
+ Xim im,
+ XPointer recv_buf,
+ int buf_len,
+ int *ret_len)
+{
+ TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
+ int len;
+
+ if (buf_len == 0) {
+ *ret_len = 0;
+ return True;
+ }
+ if ((len = _XimXTransRead(spec->trans_conn, recv_buf, buf_len)) <= 0)
+ return False;
+ *ret_len = len;
+ return True;
+}
+
+
+Public void
+_XimTransFlush(
+ Xim im)
+{
+ return;
+}
+
+
+
+Public Bool
+_XimTransConf(
+ Xim im,
+ char *address)
+{
+ char *paddr;
+ TransSpecRec *spec;
+
+ if (!(paddr = strdup(address)))
+ return False;
+
+ if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) {
+ Xfree(paddr);
+ return False;
+ }
+
+ spec->address = paddr;
+
+ im->private.proto.spec = (XPointer)spec;
+ im->private.proto.connect = _XimTransConnect;
+ im->private.proto.shutdown = _XimTransShutdown;
+ im->private.proto.write = _XimTransWrite;
+ im->private.proto.read = _XimTransRead;
+ im->private.proto.flush = _XimTransFlush;
+ im->private.proto.register_dispatcher = _XimTransRegisterDispatcher;
+ im->private.proto.call_dispatcher = _XimTransCallDispatcher;
+
+ return True;
+}
diff --git a/libX11/modules/lc/gen/lcGenConv.c b/libX11/modules/lc/gen/lcGenConv.c
index c222c1f2a..7a113a78a 100644
--- a/libX11/modules/lc/gen/lcGenConv.c
+++ b/libX11/modules/lc/gen/lcGenConv.c
@@ -1,3148 +1,3148 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-/*
- * (c) Copyright 1995 FUJITSU LIMITED
- * This is source code modified by FUJITSU LIMITED under the Joint
- * Development Agreement for the CDE/Motif PST.
- *
- * Modifier: Masayoshi Shimamura FUJITSU LIMITED
- *
- */
-/*
- * 2000
- * Modifier: Ivan Pascal The XFree86 Project
- */
-
-/*
- * A generic locale loader for all kinds of ISO-2022 based codesets.
- * Supports: all locales.
- * How: Provides generic converters for ISO-2022 based codesets. Extensible as
- * far as ISO-2022 is extensible: codesets can be given by name in the
- * stream. Overall distinction between GL (0x00..0x7f) and GR (0x80..0xff).
- * In every chunk between escape sequences, the number of bytes per
- * character (char_size) is constant.
- * Platforms: all systems.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "XlcGeneric.h"
-#include <stdio.h>
-
-#if !defined(Lynx_22) && !defined(X_LOCALE)
-#define STDCVT
-#endif
-
-typedef struct _CTDataRec {
- const char *name;
- const char *encoding; /* Compound Text encoding */
-} CTDataRec, *CTData;
-
-static CTDataRec directionality_data[] =
-{
- { "BEGIN_LEFT-TO-RIGHT_TEXT", "\2331]" },
- { "BEGIN_RIGHT-TO-LEFT_TEXT", "\2332]" },
- { "END_OF_STRING", "\233]" },
-};
-
-typedef struct _StateRec {
- XLCd lcd;
- /* CT state */
- XlcCharSet charset; /* charset of current state */
- XlcCharSet GL_charset; /* charset of initial state in GL */
- XlcCharSet GR_charset; /* charset of initial state in GR */
- /* MB shift state */
- CodeSet GL_codeset;
- CodeSet GR_codeset;
-} StateRec, *State;
-
-#define GR 0x80 /* begins right-side (non-ascii) region */
-#define GL 0x7f /* ends left-side (ascii) region */
-#define ESC 0x1b
-#define CSI 0x9b
-#define STX 0x02
-
-#define isrightside(c) ((c) & GR)
-#define isleftside(c) (!isrightside(c))
-
-/* Forward declarations for local routines. */
-static int mbstocts (XlcConv conv, XPointer *from, int *from_left,
- XPointer *to, int *to_left, XPointer *args, int num_args);
-static int ctstombs (XlcConv conv, XPointer *from, int *from_left,
- XPointer *to, int *to_left, XPointer *args, int num_args);
-static int cstombs (XlcConv conv, XPointer *from, int *from_left,
- XPointer *to, int *to_left, XPointer *args, int num_args);
-
-/* ------------------------------------------------------------------------- */
-/* Misc */
-/* ------------------------------------------------------------------------- */
-
-static int
-compare(
- const char *src,
- const char *encoding,
- int length)
-{
- const char *start = src;
-
- while (length-- > 0) {
- if (*src++ != *encoding++)
- return 0;
- if (*encoding == '\0')
- return src - start;
- }
-
- return 0;
-}
-
-static unsigned long
-conv_to_dest(
- Conversion conv,
- unsigned long code)
-{
- int i;
- int conv_num = conv->conv_num;
- FontScope convlist = conv->convlist;
-
- for (i = 0; i < conv_num; i++) {
- if (convlist[i].start <= code && code <= convlist[i].end) {
- switch (convlist[i].shift_direction) {
- case '+':
- return(code + convlist[i].shift);
- case '-':
- return(code - convlist[i].shift);
- default:
- return(code);
- }
- }
- }
-
- return(code);
-}
-
-static unsigned long
-conv_to_source(
- Conversion conv,
- unsigned long code)
-{
- int i;
- int conv_num;
- FontScope convlist;
- unsigned long start_p;
- unsigned long start_m;
- unsigned long end_p;
- unsigned long end_m;
-
- if (!conv)
- return(code);
-
- conv_num = conv->conv_num;
- convlist = conv->convlist;
-
- for (i = 0; i < conv_num; i++) {
- switch (convlist[i].shift_direction) {
- case '+':
- start_p = convlist[i].start + convlist[i].shift;
- end_p = convlist[i].end + convlist[i].shift;
- if (start_p <= code && code <= end_p)
- return(code - convlist[i].shift);
- break;
- case '-':
- start_m = convlist[i].start - convlist[i].shift;
- end_m = convlist[i].end - convlist[i].shift;
- if (start_m <= code && code <= end_m)
- return(code + convlist[i].shift);
- break;
- default:
- continue;
- }
- }
-
- return(code);
-}
-
-static unsigned long
-mb_to_gi(
- unsigned long mb,
- CodeSet codeset)
-{
- int i;
- unsigned long mb_tmp, mask = 0;
-
- if (codeset->mbconv) {
- mb_tmp = conv_to_dest(codeset->mbconv, mb);
- if (mb_tmp != mb)
- return(mb_tmp);
- }
-
- if (codeset->side == XlcC0 || codeset->side == XlcGL ||
- codeset->side == XlcC1 || codeset->side == XlcGR) {
-
- for (i = 0; i < codeset->length; i++)
- mask = (mask << 8) | GL;
- mb = mb & mask;
- }
-
- return(mb);
-}
-
-static unsigned long
-gi_to_mb(
- unsigned long glyph_index,
- CodeSet codeset)
-{
- int i;
- unsigned long mask = 0;
-
- if (codeset->side == XlcC1 || codeset->side == XlcGR) {
- for (i = 0; i < codeset->length; i++)
- mask = (mask << 8) | GR;
- glyph_index = glyph_index | mask;
- }
-
- if (codeset->mbconv)
- return( conv_to_source(codeset->mbconv, glyph_index) );
-
- return(glyph_index);
-}
-
-static Bool
-gi_to_wc(
- XLCd lcd,
- unsigned long glyph_index,
- CodeSet codeset,
- wchar_t *wc)
-{
- unsigned char mask = 0;
- unsigned long wc_encoding = codeset->wc_encoding;
- int length = codeset->length;
- unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
-
- mask = (1 << wc_shift_bits) - 1 ;
-
- for (*wc = 0, length--; length >= 0; length--)
- *wc = (*wc << wc_shift_bits) | ((glyph_index >> (length * 8 )) & mask);
-
- *wc = *wc | wc_encoding;
-
- return(True);
-}
-
-static Bool
-wc_to_gi(
- XLCd lcd,
- wchar_t wc,
- unsigned long *glyph_index,
- CodeSet *codeset)
-{
- int i;
- unsigned char mask = 0;
- unsigned long wc_encoding;
- unsigned long wc_encode_mask = XLC_GENERIC(lcd, wc_encode_mask);
- unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
- int codeset_num = XLC_GENERIC(lcd, codeset_num);
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
-
- wc_encoding = wc & wc_encode_mask;
- for (*codeset = NULL, i = 0; i < codeset_num; i++) {
- if (wc_encoding == codeset_list[i]->wc_encoding) {
- *codeset = codeset_list[i];
- break;
- }
- }
- if (*codeset == NULL)
- return(False);
-
- mask = (1 << wc_shift_bits) - 1 ;
-
- wc = wc & ~wc_encode_mask;
- for (*glyph_index = 0, i = (*codeset)->length - 1; i >= 0; i--)
- *glyph_index = (*glyph_index << 8) |
- ( ((unsigned long)wc >> (i * wc_shift_bits)) & mask );
-
- return(True);
-}
-
-static CodeSet
-mb_parse_codeset(
- State state,
- int num,
- const char **inbufptr,
- int *from_left)
-{
- int len;
- int from_len = (*from_left) + 1;
- const char *src = (*inbufptr) - 1;
- ParseInfo *mb_parse_list = XLC_GENERIC(state->lcd, mb_parse_list);
- ParseInfo parse_info;
- CodeSet codeset;
-
- for (--num ; (parse_info = mb_parse_list[num]) != NULL; num++) {
- len = compare(src, parse_info->encoding, from_len);
- if (len > 0) {
- codeset = parse_info->codeset;
- if (parse_info->type == E_LSL)
- state->GL_codeset = codeset;
- else if (parse_info->type == E_LSR)
- state->GR_codeset = codeset;
- --len;
- *inbufptr += len;
- *from_left -= len;
- return codeset;
- }
- }
- return (CodeSet) NULL;
-}
-
-static CodeSet
-byteM_parse_codeset(
- XLCd lcd,
- const char *inbufptr)
-{
- unsigned char ch;
- CodeSet codeset;
- ByteInfoList byteM;
- ByteInfoListRec byteM_rec;
- ByteInfo byteinfo;
- ByteInfoRec byteinfo_rec;
- Bool hit = False;
- int i, j, k;
-
- int codeset_num = XLC_GENERIC(lcd, codeset_num);
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
-
- for (i = 0; i < codeset_num; i++) {
- codeset = codeset_list[i];
- byteM = codeset->byteM;
- if (codeset->side != XlcNONE || byteM == NULL)
- continue;
-
- for (j = 0; j < codeset->length; j++) {
- ch = *((unsigned char *)(inbufptr + j));
- byteM_rec = byteM[j];
- byteinfo = byteM_rec.byteinfo;
-
- for (hit = False, k = 0; k < byteM_rec.byteinfo_num; k++) {
- byteinfo_rec = byteinfo[k];
- if (byteinfo_rec.start <= ch && ch <= byteinfo_rec.end) {
- hit = True;
- break;
- }
- }
-
- if (!hit)
- break;
- }
-
- if (hit)
- return(codeset);
- }
-
- return(NULL);
-}
-
-#define GLGR_parse_codeset(ch) \
- (isrightside(ch) ? (state->GR_codeset) : \
- (state->GL_codeset) )
-
-static XlcCharSet
-gi_parse_charset(
- unsigned long glyph_index,
- CodeSet codeset)
-{
- int i;
- XlcCharSet *charset_list = codeset->charset_list;
- int num_charsets = codeset->num_charsets;
- ExtdSegment ctextseg = codeset->ctextseg;
- XlcCharSet charset = NULL;
- int area_num;
- FontScope area;
-
- /* lockup ct sequence */
- for (i = 0; i < num_charsets; i++) {
- charset = charset_list[i];
- if (*charset->ct_sequence != '\0')
- break;
- }
- if (i >= num_charsets)
- return(NULL);
-
- if (charset->source != CSsrcStd)
- return (charset);
-
- if (!ctextseg)
- return(charset);
-
- area = ctextseg->area;
- area_num = ctextseg->area_num;
-
- for (i = 0; i < area_num; i++) {
-
- if (area[i].start <= glyph_index && glyph_index <= area[i].end) {
-
- charset = ctextseg->charset;
-
- if (*charset->ct_sequence == '\0')
- return(NULL);
-
- break;
- }
- }
-
- return(charset);
-}
-
-static Bool
-ct_parse_csi(
- const char *inbufptr,
- int *ctr_seq_len)
-{
- int i;
- int num = sizeof(directionality_data) / sizeof(directionality_data[0]);
-
- for (i = 0; i < num; i++) {
- if ( !(*ctr_seq_len = strlen(directionality_data[i].encoding)) )
- continue;
-
- if ( strncmp(inbufptr, directionality_data[i].encoding,
- *ctr_seq_len) == 0)
- return(True);
- }
-
- return(False);
-}
-
-static int
-cmp_esc_sequence(
- const char *inbufptr,
- XlcCharSet charset)
-{
- int seq_len, name_len, total_len;
- unsigned char byte_m, byte_l;
- const char *ct_sequence = charset->ct_sequence;
- const char *encoding_name = charset->encoding_name;
-
- /* check esc sequence */
- if ( !(seq_len = strlen(ct_sequence) ) )
- return(0);
- if ( strncmp(inbufptr, ct_sequence, seq_len) != 0)
- return(0);
-
- /* Standard Character Set Encoding ? */
- if (charset->source == CSsrcStd)
- return(seq_len);
-
- /*
- * Non-Standard Character Set Encoding
- *
- * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+
- * | ctseq | M | L | encoding name | STX | contents |
- * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+
- * 4bytes 1byte 1byte variable length 1byte variable length
- * | |
- * +----------------------------------------------+
- * rest length = ((M - 128) * 128) + (L - 128)
- */
-
- /* get length of encoding name */
- inbufptr += seq_len;
- byte_m = *inbufptr++;
- byte_l = *inbufptr++;
- name_len = strlen(encoding_name);
-
- if (((byte_m - 128) * 128 + (byte_l - 128) - 1) < name_len)
- return(0);
-
- if ( _XlcNCompareISOLatin1(inbufptr, encoding_name, name_len) != 0 )
- return(0);
-
- /* check STX (Start of Text) */
- inbufptr = inbufptr + name_len;
- if ( *inbufptr != STX )
- return(0);
-
- total_len = seq_len + name_len + 3;
- return(total_len);
-}
-
-static Bool
-ct_parse_charset(
- XLCd lcd,
- const char *inbufptr,
- XlcCharSet *charset,
- int *ctr_seq_len)
-{
- int i, j;
- ExtdSegment ctextseg;
- int num_charsets;
- XlcCharSet *charset_list;
- CodeSet codeset;
- int codeset_num = XLC_GENERIC(lcd, codeset_num);
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
- int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
- SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
-
- /* get charset from XLC_XLOCALE by escape sequence */
-
- for (i = 0; i < codeset_num; i++) {
- codeset = codeset_list[i];
-
- num_charsets = codeset->num_charsets;
- charset_list = codeset->charset_list;
- ctextseg = codeset->ctextseg;
-
- for (j = 0; j < num_charsets; j++) {
- *charset = charset_list[j];
- if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
- return(True);
- }
-
- if (ctextseg) {
- *charset = ctextseg->charset;
- if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
- return(True);
- }
- }
-
- /* get charset from XLC_SEGMENTCONVERSION by escape sequence */
-
- if (!segment_conv)
- return(False);
-
- for (i = 0; i < segment_conv_num; i++) {
- *charset = segment_conv[i].source;
- if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
- return(True);
- *charset = segment_conv[i].dest;
- if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
- return(True);
- }
-
- return(False);
-}
-
-static Bool
-segment_conversion(
- XLCd lcd,
- XlcCharSet *charset,
- unsigned long *glyph_index)
-{
- int i;
- int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
- SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
- FontScopeRec range;
- ConversionRec conv_rec;
-
- if (!segment_conv)
- return(True);
-
- for (i = 0; i < segment_conv_num; i++) {
- if (segment_conv[i].source == *charset)
- break;
- }
-
- if (i >= segment_conv_num)
- return(True);
-
- range = segment_conv[i].range;
- if (*glyph_index < range.start || range.end < *glyph_index)
- return(True);
-
- *charset = segment_conv[i].dest;
- conv_rec.conv_num = segment_conv[i].conv_num;
- conv_rec.convlist = segment_conv[i].conv;
- *glyph_index = conv_to_dest(&conv_rec, *glyph_index);
-
- return(True);
-}
-
-static CodeSet
-_XlcGetCodeSetFromName(
- XLCd lcd,
- const char *name)
-{
- int i, j;
- XlcCharSet charset;
- int num_charsets;
- XlcCharSet *charset_list;
- CodeSet codeset;
-
- int codeset_num = XLC_GENERIC(lcd, codeset_num);
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
-
- for (i = 0; i < codeset_num; i++) {
- codeset = codeset_list[i];
-
- num_charsets = codeset->num_charsets;
- charset_list = codeset->charset_list;
-
- for (j = 0; j < num_charsets; j++) {
- charset = charset_list[j];
-
- if (!strlen(charset->name))
- continue;
- if ( strcmp(charset->name, name) == 0)
- return(codeset);
- }
- }
-
- return(NULL);
-}
-
-static Bool
-_XlcGetCodeSetFromCharSet(
- XLCd lcd,
- XlcCharSet charset,
- CodeSet *codeset,
- unsigned long *glyph_index)
-{
- int j, num;
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
- XlcCharSet *charset_list;
- int codeset_num, num_charsets;
- Conversion ctconv;
- unsigned long glyph_index_tmp = 0;
- ExtdSegment ctextseg;
-
- codeset_num = XLC_GENERIC(lcd, codeset_num);
-
- for (num = 0 ; num < codeset_num; num++) {
- *codeset = codeset_list[num];
- ctconv = (*codeset)->ctconv;
- ctextseg = (*codeset)->ctextseg;
-
- num_charsets = (*codeset)->num_charsets;
- charset_list = (*codeset)->charset_list;
-
- glyph_index_tmp = conv_to_source(ctconv, *glyph_index);
-
- if (charset->source == CSsrcStd) {
-
- /* Standard Character Set Encoding */
- if (glyph_index_tmp == *glyph_index) {
- for (j = 0; j < num_charsets; j++) {
- if (charset_list[j] == charset) {
- goto end_loop;
- }
- }
- }
-
- } else {
-
- /* Non-Standard Character Set Encoding */
- for (j = 0; j < num_charsets; j++) {
- if (charset_list[j] == charset) {
- goto end_loop;
- }
- }
-
- if (glyph_index_tmp != *glyph_index) {
- if (ctextseg && ctextseg->charset == charset) {
- goto end_loop;
- }
- }
-
- }
-
- }
-
-end_loop:
- if (num < codeset_num) {
- *glyph_index = glyph_index_tmp;
- return(True);
- }
-
- return(False);
-}
-
-#define check_string_encoding(codeset) (codeset->string_encoding)
-
-static void
-output_ulong_value(
- char *outbufptr,
- unsigned long code,
- int length,
- XlcSide side)
-{
- int i;
-
- for (i = (length - 1) * 8; i >= 0; i -= 8) {
- *outbufptr = ( code >> i) & 0xff;
-
- if (side == XlcC0 || side == XlcGL) {
- *outbufptr = *outbufptr & GL;
- } else if (side == XlcC1 || side == XlcGR) {
- *outbufptr = *outbufptr | GR;
- }
-
- outbufptr++;
- }
-}
-
-/* -------------------------------------------------------------------------- */
-/* Init */
-/* -------------------------------------------------------------------------- */
-
-static XlcCharSet default_GL_charset = 0;
-static XlcCharSet default_GR_charset = 0;
-
-static void
-init_state(
- XlcConv conv)
-{
- State state = (State) conv->state;
-
- /* for CT */
- state->charset = NULL;
- state->GL_charset = default_GL_charset;
- state->GR_charset = default_GR_charset;
-
- /* for MB shift state */
- state->GL_codeset = XLC_GENERIC(state->lcd, initial_state_GL);
- state->GR_codeset = XLC_GENERIC(state->lcd, initial_state_GR);
-}
-
-/* -------------------------------------------------------------------------- */
-/* Convert */
-/* -------------------------------------------------------------------------- */
-
-static int
-mbstowcs_org(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long mb = 0;
- wchar_t wc;
-
- int length = 0, len_left = 0;
- int unconv_num = 0;
- int num;
-
- CodeSet codeset = NULL;
-
- const char *inbufptr = *from;
- wchar_t *outbufptr = (wchar_t *) *to;
- int from_size = *from_left;
-
- unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
-
- if (from == NULL || *from == NULL) {
- _XlcResetConverter(conv);
- return( 0 );
- }
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = L'\0';}
- (*to_left)--;
-
- /* error check */
- if (len_left) {
- unconv_num += (length - len_left);
- len_left = 0;
- }
-
- continue;
- }
-
- /* same mb char data */
- if (len_left)
- goto output_one_wc;
-
- /* next mb char data for single shift ? */
- if (mb_parse_table && (num = mb_parse_table[ch]) ) {
- codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
- if (codeset != NULL) {
- length = len_left = codeset->length;
- mb = 0;
- continue;
- }
- }
-
- /* next mb char data for byteM ? */
- if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
- goto next_mb_char;
-
- /* next mb char data for GL or GR side ? */
- if ((codeset = GLGR_parse_codeset(ch)))
- goto next_mb_char;
-
- /* can't find codeset for the ch */
- unconv_num++;
- continue;
-
-next_mb_char:
- length = len_left = codeset->length;
- mb = 0;
-
-output_one_wc:
- mb = (mb << 8) | ch; /* 1 byte left shift */
- len_left--;
-
- /* last of one mb char data */
- if (!len_left) {
- gi_to_wc(lcd, mb_to_gi(mb, codeset), codeset, &wc);
- if (outbufptr) {*outbufptr++ = wc;}
- (*to_left)--;
- }
-
- } /* end of while */
-
- /* error check on last char */
- if (len_left) {
- inbufptr -= (length - len_left);
- (*from_left) += (length - len_left);
- unconv_num += (length - len_left);
- }
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_mbstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const char *src = *((const char **) from);
- wchar_t *dst = *((wchar_t **) to);
- int src_left = *from_left;
- int dst_left = *to_left;
- int length, unconv_num = 0;
-
- while (src_left > 0 && dst_left > 0) {
- length = mbtowc(dst, src, src_left);
-
- if (length > 0) {
- src += length;
- src_left -= length;
- if (dst)
- dst++;
- dst_left--;
- } else if (length < 0) {
- src++;
- src_left--;
- unconv_num++;
- } else {
- /* null ? */
- src++;
- src_left--;
- if (dst)
- *dst++ = L'\0';
- dst_left--;
- }
- }
-
- *from = (XPointer) src;
- if (dst)
- *to = (XPointer) dst;
- *from_left = src_left;
- *to_left = dst_left;
-
- return unconv_num;
-}
-
-static int
-wcstombs_org(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- char *encoding;
- unsigned long mb, glyph_index;
- wchar_t wc;
-
- int length;
- int unconv_num = 0;
-
- CodeSet codeset;
-
- const wchar_t *inbufptr = (const wchar_t *) *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- const char *default_string = XLC_PUBLIC(lcd, default_string);
- int defstr_len = strlen(default_string);
-
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- wc = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!wc) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
-
- /* output default_string of XDefaultString() */
- if (*to_left < defstr_len)
- break;
- if (outbufptr) {
- strncpy((char *)outbufptr, default_string, defstr_len);
- outbufptr += defstr_len;
- }
- (*to_left) -= defstr_len;
-
- unconv_num++;
-
- } else {
- mb = gi_to_mb(glyph_index, codeset);
- if (codeset->parse_info) {
- Bool need_shift = False;
- switch (codeset->parse_info->type) {
- case E_LSL :
- if (codeset != state->GL_codeset) {
- need_shift = True;
- state->GL_codeset = codeset;
- }
- break;
- case E_LSR :
- if (codeset != state->GR_codeset) {
- need_shift = True;
- state->GR_codeset = codeset;
- }
- break;
- /* case E_SS */
- default:
- need_shift = True;
- }
-
- /* output shift sequence */
- if (need_shift) {
- encoding = codeset->parse_info->encoding;
- length = strlen(encoding);
- if (*to_left < length)
- break;
- if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
- outbufptr += length;
- }
- (*to_left) -= length;
- }
- }
-
- /* output characters */
- length = codeset->length;
- if (*to_left < length)
- break;
-
- if (outbufptr) {
- output_ulong_value(outbufptr, mb, length, XlcNONE);
- outbufptr += length;
- }
-
- (*to_left) -= length;
- }
-
- } /* end of while */
-
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_wcstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const wchar_t *src = *((const wchar_t **) from);
- char *dst = *((char **) to);
- int src_left = *from_left;
- int dst_left = *to_left;
- int length, unconv_num = 0;
-
- while (src_left > 0 && dst_left >= MB_CUR_MAX) {
- length = wctomb(dst, *src); /* XXX */
-
- if (length > 0) {
- src++;
- src_left--;
- if (dst)
- dst += length;
- dst_left -= length;
- } else if (length < 0) {
- src++;
- src_left--;
- unconv_num++;
- }
- }
-
- *from = (XPointer) src;
- if (dst)
- *to = (XPointer) dst;
- *from_left = src_left;
- *to_left = dst_left;
-
- return unconv_num;
-}
-
-static int
-wcstocts(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned long glyph_index;
- wchar_t wc;
-
- int total_len, seq_len, name_len;
- int unconv_num = 0;
- Bool first_flag = True, standard_flag;
- XlcSide side;
-
- CodeSet codeset;
- XlcCharSet charset, old_charset = NULL;
- const char *ct_sequence;
-
- const wchar_t *inbufptr = (const wchar_t *) *from;
- char *outbufptr = *to;
- int from_size = *from_left;
- char *ext_seg_len = NULL;
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- wc = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!wc) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
- unconv_num++;
- continue;
- }
-
- /* parse charset */
- if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
- unconv_num++;
- continue;
- }
-
- /* Standard Character Set Encoding ? */
- standard_flag = charset->source == CSsrcStd ? True : False;
-
- /*
- * Non-Standard Character Set Encoding
- *
- * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
- * | esc sequence | M | L | encoding name | STX |
- * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
- * 4bytes 1byte 1byte variable length 1byte
- * | |
- * +-----------------------------------------+
- * name length = ((M - 128) * 128) + (L - 128)
- */
-
- /* make encoding data */
- ct_sequence = charset->ct_sequence;
- side = charset->side;
- seq_len = strlen(ct_sequence);
- if (standard_flag) {
- name_len = 0;
- total_len = seq_len;
- } else {
- name_len = strlen(charset->encoding_name) + 1;
- total_len = seq_len + name_len + 2;
- }
-
- /* output escape sequence of CT */
- if ( (charset != old_charset) &&
- !(first_flag && charset->string_encoding) ){
-
- if ( (ext_seg_len != NULL) && outbufptr) {
- int i = (outbufptr - ext_seg_len) - 2;
- *ext_seg_len++ = i / 128 + 128;
- *ext_seg_len = i % 128 + 128;
- ext_seg_len = NULL;
- }
-
- if (*to_left < total_len + 1) {
- unconv_num++;
- break;
- }
-
- if (outbufptr) {
- strcpy((char *)outbufptr, ct_sequence);
- outbufptr += seq_len;
-
- if (!standard_flag) {
- const char *i = charset->encoding_name;
- ext_seg_len = outbufptr;
- outbufptr += 2;
- for (; *i ; i++)
- *outbufptr++ = ((*i >= 'A') && (*i <= 'Z')) ?
- *i - 'A' + 'a' : *i;
- *outbufptr++ = STX;
- }
- }
-
- (*to_left) -= total_len;
-
- first_flag = False;
- old_charset = charset;
- }
-
- /* output glyph index */
- if (codeset->ctconv)
- glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
- if (*to_left < charset->char_size) {
- unconv_num++;
- break;
- }
-
- if (outbufptr) {
- output_ulong_value(outbufptr, glyph_index, charset->char_size, side);
- outbufptr += charset->char_size;
- }
-
- (*to_left) -= charset->char_size;
-
- } /* end of while */
-
- if ( (ext_seg_len != NULL) && outbufptr) {
- int i = (outbufptr - ext_seg_len) - 2;
- *ext_seg_len++ = i / 128 + 128;
- *ext_seg_len = i % 128 + 128;
- }
-
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_wcstocts(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = stdc_wcstombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = mbstocts(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-ctstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long glyph_index = 0;
- wchar_t wc;
-
- int ctr_seq_len = 0, gi_len_left = 0, gi_len = 0;
- int unconv_num = 0;
-
- CodeSet codeset = NULL;
- XlcCharSet charset_tmp;
-
- const char *inbufptr = *from;
- wchar_t *outbufptr = (wchar_t *) *to;
- int from_size = *from_left;
-
- _XlcResetConverter(conv); /* ??? */
-
- if (from == NULL || *from == NULL) {
- _XlcResetConverter(conv);
- return( 0 );
- }
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = L'\0';}
- (*to_left)--;
-
- /* error check */
- if (gi_len_left) {
- unconv_num += (gi_len - gi_len_left);
- gi_len_left = 0;
- }
-
- continue;
- }
-
- /* same glyph_index data */
- if (gi_len_left)
- goto output_one_wc;
-
- /* control sequence ? */
- if (ch == CSI) {
- if ( !ct_parse_csi(inbufptr - 1, &ctr_seq_len) )
- goto skip_the_seg;
-
- if (*from_left + 1 < ctr_seq_len) {
- inbufptr--;
- (*from_left)++;
- unconv_num += *from_left;
- break;
- }
-
- /* skip the control sequence */
- inbufptr += (ctr_seq_len - 1);
- *from_left -= (ctr_seq_len - 1);
-
- continue;
- }
-
- /* escape sequence ? */
- if (ch == ESC) {
- if ( !ct_parse_charset(lcd,
- inbufptr - 1, &state->charset, &ctr_seq_len) )
- goto skip_the_seg;
-
- if (state->charset->side == XlcC0 ||
- state->charset->side == XlcGL)
- {
- state->GL_charset = state->charset;
- }
- else if (state->charset->side == XlcC1 ||
- state->charset->side == XlcGR)
- {
- state->GR_charset = state->charset;
- }
- else if (state->charset->side == XlcGLGR)
- {
- state->GL_charset = state->charset;
- state->GR_charset = state->charset;
- }
-
- if (*from_left + 1 < ctr_seq_len) {
- inbufptr--;
- (*from_left)++;
- unconv_num += *from_left;
- break;
- }
-
- /* skip the escape sequence */
- inbufptr += (ctr_seq_len - 1);
- *from_left -= (ctr_seq_len - 1);
-
- continue;
- }
-
- /* check current state */
- if (isleftside(ch))
- state->charset = state->GL_charset;
- else
- state->charset = state->GR_charset;
-
- gi_len = gi_len_left = state->charset->char_size;
- glyph_index = 0;
-
-output_one_wc:
- if (state->charset->side == XlcC1 || state->charset->side == XlcGR)
- glyph_index = (glyph_index << 8) | (ch & GL);
- else
- glyph_index = (glyph_index << 8) | ch;
-
- gi_len_left--;
-
- /* last of one glyph_index data */
- if (!gi_len_left) {
-
- /* segment conversion */
- charset_tmp = state->charset;
- segment_conversion(lcd, &charset_tmp, &glyph_index);
-
- /* get codeset */
- if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
- &codeset, &glyph_index) ) {
- unconv_num += gi_len;
- continue;
- }
-
- /* convert glyph index to wicd char */
- gi_to_wc(lcd, glyph_index, codeset, &wc);
- if (outbufptr) {*outbufptr++ = wc;}
- (*to_left)--;
- }
-
- continue;
-
-skip_the_seg:
- /* skip until next escape or control sequence */
- while ( *from_left ) {
- ch = *inbufptr++;
- (*from_left)--;
- unconv_num++;
-
- if (ch == ESC || ch == CSI) {
- inbufptr--;
- (*from_left)++;
- unconv_num--;
- break;
- }
- }
-
- if ( !(*from_left) )
- break;
-
- } /* end of while */
-
- /* error check on last char */
- if (gi_len_left) {
- inbufptr -= (gi_len - gi_len_left);
- (*from_left) += (gi_len - gi_len_left);
- unconv_num += (gi_len - gi_len_left);
- }
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-cstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long glyph_index = 0;
- wchar_t wc;
- int gi_len_left = 0, gi_len = 0;
-
- int unconv_num = 0;
-
- CodeSet codeset = NULL;
- XlcCharSet charset, charset_tmp;
-
- const char *inbufptr = *from;
- wchar_t *outbufptr = (wchar_t *) *to;
- int from_size = *from_left;
-
- if (from == NULL || *from == NULL) {
- return( 0 );
- }
-
- charset = (XlcCharSet) args[0];
-
- while (*from_left && *to_left) {
-
- if (!gi_len_left) {
- gi_len_left = gi_len = charset->char_size;
- glyph_index = 0;
- }
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = L'\0';}
- (*to_left)--;
-
- /* error check */
- if (gi_len_left) {
- unconv_num += (gi_len - gi_len_left);
- gi_len_left = 0;
- }
- continue;
- }
-
- if (charset->side == XlcC1 || charset->side == XlcGR)
- glyph_index = (glyph_index << 8) | (ch & GL);
- else
- glyph_index = (glyph_index << 8) | ch;
-
- gi_len_left--;
-
- /* last of one glyph_index data */
- if (!gi_len_left) {
-
- /* segment conversion */
- charset_tmp = charset;
- segment_conversion(lcd, &charset_tmp, &glyph_index);
-
- /* get codeset */
- if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
- &codeset, &glyph_index) ) {
- unconv_num += gi_len;
- continue;
- }
-
- /* convert glyph index to wicd char */
- gi_to_wc(lcd, glyph_index, codeset, &wc);
- if (outbufptr) {*outbufptr++ = wc;}
- (*to_left)--;
- }
-
- } /* end of while */
-
- /* error check on last char */
- if (gi_len_left) {
- inbufptr -= (gi_len - gi_len_left);
- (*from_left) += (gi_len - gi_len_left);
- unconv_num += (gi_len - gi_len_left);
- }
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_ctstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = ctstombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = stdc_mbstowcs(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-stdc_cstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = cstombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = stdc_mbstowcs(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-mbstocts(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left);
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = mbstowcs_org(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
-
- unconv_num2 += wcstocts(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-mbstostr(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long mb = 0;
-
- int length = 0, len_left = 0;
- int unconv_num = 0;
- int num;
-
- CodeSet codeset = NULL;
-
- const char *inbufptr = *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
-
- if (from == NULL || *from == NULL) {
- _XlcResetConverter(conv);
- return( 0 );
- }
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- /* error check */
- if (len_left) {
- unconv_num += (length - len_left);
- len_left = 0;
- }
-
- continue;
- }
-
- /* same mb char data */
- if (len_left)
- goto output_one_mb;
-
- /* next mb char data for single shift ? */
- if (mb_parse_table && (num = mb_parse_table[ch]) ) {
- codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
- if (codeset != NULL) {
- length = len_left = codeset->length;
- mb = 0;
- continue;
- }
- }
-
- /* next char data : byteM ? */
- if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
- goto next_mb_char;
-
- /* next char data : GL or GR side ? */
- if ((codeset = GLGR_parse_codeset(ch)))
- goto next_mb_char;
-
- /* can't find codeset for the ch */
- unconv_num++;
- continue;
-
-next_mb_char:
- length = len_left = codeset->length;
- mb = 0;
-
-output_one_mb:
- mb = (mb << 8) | ch; /* 1 byte left shift */
- len_left--;
-
- /* last of one mb char data */
- if (!len_left) {
- if (check_string_encoding(codeset)) {
- if (outbufptr) {*outbufptr++ = mb & 0xff;}
- (*to_left)--;
- } else {
- unconv_num++;
- }
- }
-
- } /* end of while */
-
- /* error check on last char */
- if (len_left) {
- inbufptr -= (length - len_left);
- (*from_left) += (length - len_left);
- unconv_num += (length - len_left);
- }
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-mbtocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long mb = 0;
- unsigned long glyph_index;
-
- int length = 0, len_left = 0, char_len;
- int unconv_num = 0;
- int num;
- XlcSide side;
-
- CodeSet codeset = NULL;
- XlcCharSet charset = NULL;
-
- const char *inbufptr = *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
-
- if (from == NULL || *from == NULL) {
- _XlcResetConverter(conv);
- return( 0 );
- }
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- unconv_num = 1;
- if (len_left)
- unconv_num += (length - len_left);
- break;
- }
-
- /* same mb char data */
- if (len_left)
- goto output;
-
- /* next mb char data for single shift ? */
- if (mb_parse_table && (num = mb_parse_table[ch]) ) {
- codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
- if (codeset != NULL) {
- length = len_left = codeset->length;
- mb = 0;
- continue;
- }
- }
-
- /* next mb char data for byteM ? */
- if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
- goto next_mb_char;
-
- /* next mb char data for GL or GR side ? */
- if ((codeset = GLGR_parse_codeset(ch)))
- goto next_mb_char;
-
- /* can't find codeset for the ch */
- unconv_num = 1;
- break;
-
-next_mb_char:
- length = len_left = codeset->length;
- mb = 0;
-
-output:
- mb = (mb << 8) | ch; /* 1 byte left shift */
- len_left--;
-
- /* last of one mb char data */
- if (!len_left) {
- glyph_index = mb_to_gi(mb, codeset);
- if (!(charset = gi_parse_charset(glyph_index, codeset))) {
- unconv_num = length;
- break;
- }
- char_len = charset->char_size;
- side = charset->side;
-
- /* output glyph index */
- if (codeset->ctconv)
- glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
- if (*to_left < char_len) {
- unconv_num = length;
- break;
- }
-
- if (outbufptr) {
- output_ulong_value(outbufptr, glyph_index, char_len, side);
- outbufptr += char_len;
- }
-
- (*to_left) -= char_len;
-
- break;
- }
-
- } /* end of while */
-
- /* error end */
- if (unconv_num) {
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
- return -1;
- }
-
- /* nomal end */
- *from = (XPointer) inbufptr;
- *to = (XPointer) outbufptr;
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset;
-
- return 0;
-}
-
-static int
-mbstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- int ret;
- XlcCharSet charset_old, charset = NULL;
- XPointer tmp_args[1];
-
- const char *inbufptr;
- int in_left;
- char *outbufptr;
- int out_left;
- tmp_args[0] = (XPointer) &charset;
-
- ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
- charset_old = charset;
-
- while ( ret == 0 && *from_left && *to_left) {
- inbufptr = *from;
- in_left = *from_left;
- outbufptr = *to;
- out_left = *to_left;
- ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
- if (charset_old != charset) {
- *from = (XPointer) inbufptr;
- *from_left = in_left;
- *to = (XPointer) outbufptr;
- *to_left = out_left;
- break;
- }
- }
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset_old;
-
- /* error end */
- if (ret != 0)
- return( -1 );
-
- return(0);
-}
-
-static int
-wcstostr(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- char *encoding;
- unsigned long mb, glyph_index;
- wchar_t wc;
-
- int length;
- int unconv_num = 0;
-
- CodeSet codeset;
-
- const wchar_t *inbufptr = (const wchar_t *) *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- const char *default_string = XLC_PUBLIC(lcd, default_string);
- int defstr_len = strlen(default_string);
-
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- wc = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!wc) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
-
- /* output default_string of XDefaultString() */
- if (*to_left < defstr_len)
- break;
- if (outbufptr) {
- strncpy((char *)outbufptr, default_string, defstr_len);
- outbufptr += defstr_len;
- }
- (*to_left) -= defstr_len;
-
- unconv_num++;
-
- } else {
- mb = gi_to_mb(glyph_index, codeset);
-
- if (check_string_encoding(codeset)) {
- if (codeset->parse_info) {
- Bool need_shift = False;
- switch (codeset->parse_info->type) {
- case E_LSL :
- if (codeset != state->GL_codeset) {
- need_shift = True;
- state->GL_codeset = codeset;
- }
- break;
- case E_LSR :
- if (codeset != state->GR_codeset) {
- need_shift = True;
- state->GR_codeset = codeset;
- }
- break;
- /* case E_SS */
- default:
- need_shift = True;
- }
-
- /* output shift sequence */
- if (need_shift) {
- encoding = codeset->parse_info->encoding;
- length = strlen(encoding);
- if (*to_left < length)
- break;
-
- if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
- outbufptr += length;
- }
- (*to_left) -= length;
- }
- }
-
- /* output characters */
- length = codeset->length;
- if (*to_left < length)
- break;
-
- if (outbufptr) {
- output_ulong_value(outbufptr, mb, length, XlcNONE);
- outbufptr += length;
- }
-
- (*to_left) -= length;
- } else {
- unconv_num++;
- }
- }
-
- } /* end of while */
-
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_wcstostr(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = stdc_wcstombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = mbstostr(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-wctocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- wchar_t wc;
- unsigned long glyph_index;
-
- int char_len;
- int unconv_num = 0;
- XlcSide side;
-
- CodeSet codeset;
- XlcCharSet charset = NULL;
-
- const wchar_t *inbufptr = (const wchar_t *) *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- if (*from_left && *to_left) {
-
- wc = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!wc) {
- unconv_num = 1;
- goto end;
- }
-
- /* convert */
- if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
- unconv_num = 1;
- goto end;
- }
-
- if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
- unconv_num = 1;
- goto end;
- }
- char_len = charset->char_size;
- side = charset->side;
-
- /* output glyph index */
- if (codeset->ctconv)
- glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
- if (*to_left < char_len) {
- unconv_num++;
- goto end;
- }
-
- if (outbufptr) {
- output_ulong_value(outbufptr, glyph_index, char_len, side);
- outbufptr += char_len;
- }
-
- (*to_left) -= char_len;
-
- }
-
-end:
-
- /* error end */
- if (unconv_num) {
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
- return -1;
- }
-
- /* nomal end */
- *from = (XPointer) inbufptr;
- *to = (XPointer) outbufptr;
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset;
-
- return 0;
-}
-
-static int
-stdc_wctocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const wchar_t *src = *((const wchar_t **) from);
- wchar_t wch;
- XPointer tmp_from, save_from = *from;
- char tmp[32];
- int length, ret, src_left = *from_left;
- int from_size = *from_left;
-
- if (src_left > 0 && *to_left > 0) {
- if ((wch = *src)) {
- length = wctomb(tmp, wch);
- } else {
- goto end;
- }
-
- if (length < 0)
- goto end;
-
- tmp_from = (XPointer) tmp;
- ret = mbtocs(conv, &tmp_from, &length, to, to_left, args, num_args);
- if (ret < 0)
- goto end;
-
- src++;
- src_left--;
- }
-
-end:
- /* error end */
- if (save_from == (XPointer) src) {
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- return -1;
- }
-
- /* nomal end */
- *from = (XPointer) src;
- *from_left = src_left;
-
- return 0;
-}
-
-static int
-wcstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- int ret;
- XlcCharSet charset_old, charset = NULL;
- XPointer tmp_args[1];
-
- const wchar_t *inbufptr;
- int in_left;
- XPointer outbufptr;
- int out_left;
- tmp_args[0] = (XPointer) &charset;
-
- ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
- charset_old = charset;
-
- while ( ret == 0 && *from_left && *to_left) {
- inbufptr = (const wchar_t *) *from;
- in_left = *from_left;
- outbufptr = *to;
- out_left = *to_left;
- ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
- if (charset_old != charset) {
- *from = (XPointer) inbufptr;
- *from_left = in_left;
- *to = (XPointer) outbufptr;
- *to_left = out_left;
- break;
- }
- }
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset_old;
-
- /* error end */
- if (ret != 0)
- return( -1 );
-
- return(0);
-}
-
-#ifdef STDCVT
-
-static int
-stdc_wcstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- int ret;
- XlcCharSet charset_old, charset = NULL;
- XPointer tmp_args[1];
-
- const wchar_t *inbufptr;
- int in_left;
- XPointer outbufptr;
- int out_left;
- tmp_args[0] = (XPointer) &charset;
-
- ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
- charset_old = charset;
-
- while ( ret == 0 && *from_left && *to_left ) {
- inbufptr = (const wchar_t *) *from;
- in_left = *from_left;
- outbufptr = *to;
- out_left = *to_left;
- ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
- if (charset_old != charset) {
- *from = (XPointer) inbufptr;
- *from_left = in_left;
- *to = (XPointer) outbufptr;
- *to_left = out_left;
- break;
- }
- }
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset_old;
-
- /* error end */
- if (ret != 0)
- return( -1 );
-
- return(0);
-}
-
-#endif
-
-static int
-ctstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left);
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = ctstowcs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
-
- unconv_num2 += wcstombs_org(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-cstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left);
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = cstowcs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
-
- unconv_num2 += wcstombs_org(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-strtombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- char *encoding;
- unsigned long mb, glyph_index;
- unsigned char ch;
-
- int length;
- int unconv_num = 0;
-
- CodeSet codeset;
-
- const char *inbufptr = *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if (isleftside(ch)) {
- glyph_index = ch;
- codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL");
- } else {
- glyph_index = ch & GL;
- codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR");
- }
-
- if (!codeset) {
- unconv_num++;
- continue;
- }
-
- mb = gi_to_mb(glyph_index, codeset);
- if (codeset->parse_info) {
- Bool need_shift = False;
- switch (codeset->parse_info->type) {
- case E_LSL :
- if (codeset != state->GL_codeset) {
- need_shift = True;
- state->GL_codeset = codeset;
- }
- break;
- case E_LSR :
- if (codeset != state->GR_codeset) {
- need_shift = True;
- state->GR_codeset = codeset;
- }
- break;
- /* case E_SS */
- default:
- need_shift = True;
- }
-
- /* output shift sequence */
- if (need_shift) {
- encoding = codeset->parse_info->encoding;
- length = strlen(encoding);
- if (*to_left < length)
- break;
- if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
- outbufptr += length;
- }
- (*to_left) -= length;
- }
- }
-
- /* output characters */
- length = codeset->length;
- if (*to_left < length)
- break;
-
- if (outbufptr) {
- output_ulong_value(outbufptr, mb, length, XlcNONE);
- outbufptr += length;
- }
-
- (*to_left) -= length;
-
- } /* end of while */
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-strtowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long glyph_index;
- wchar_t wc;
-
- int unconv_num = 0;
- CodeSet codeset;
-
- const char *inbufptr = *from;
- wchar_t *outbufptr = (wchar_t *)*to;
- int from_size = *from_left;
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = L'\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if (isleftside(ch)) {
- glyph_index = ch;
- codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL");
- } else {
- glyph_index = ch & GL;
- codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR");
- }
-
- if (!codeset) {
- unconv_num++;
- continue;
- }
-
- gi_to_wc(lcd, glyph_index, codeset, &wc);
- if (outbufptr) {*outbufptr++ = wc;}
- (*to_left)--;
-
- } /* end of while */
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_strtowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = strtombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = stdc_mbstowcs(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-/* -------------------------------------------------------------------------- */
-/* Close */
-/* -------------------------------------------------------------------------- */
-
-static void
-close_converter(
- XlcConv conv)
-{
- if (conv->state) {
- Xfree((char *) conv->state);
- }
-
- if (conv->methods) {
- Xfree((char *) conv->methods);
- }
-
- Xfree((char *) conv);
-}
-
-/* -------------------------------------------------------------------------- */
-/* Open */
-/* -------------------------------------------------------------------------- */
-
-static XlcConv
-create_conv(
- XLCd lcd,
- XlcConvMethods methods)
-{
- XlcConv conv;
- State state;
-
- conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec));
- if (conv == NULL)
- return (XlcConv) NULL;
-
- conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
- if (conv->methods == NULL)
- goto err;
- *conv->methods = *methods;
- conv->methods->reset = init_state;
-
- conv->state = Xcalloc(1, sizeof(StateRec));
- if (conv->state == NULL)
- goto err;
-
- state = (State) conv->state;
- state->lcd = lcd;
-
- _XlcResetConverter(conv);
-
- return conv;
-
-err:
- close_converter(conv);
-
- return (XlcConv) NULL;
-}
-
-static XlcConvMethodsRec mbstocts_methods = {
- close_converter,
- mbstocts,
- NULL
-};
-
-static XlcConv
-open_mbstocts(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstocts_methods);
-}
-
-static XlcConvMethodsRec mbstostr_methods = {
- close_converter,
- mbstostr,
- NULL
-};
-
-static XlcConv
-open_mbstostr(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstostr_methods);
-}
-
-static XlcConvMethodsRec mbstocs_methods = {
- close_converter,
- mbstocs,
- NULL
-};
-
-static XlcConv
-open_mbstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstocs_methods);
-}
-
-static XlcConvMethodsRec mbtocs_methods = {
- close_converter,
- mbtocs,
- NULL
-};
-
-static XlcConv
-open_mbtocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbtocs_methods);
-}
-
-static XlcConvMethodsRec ctstombs_methods = {
- close_converter,
- ctstombs,
- NULL
-};
-
-static XlcConv
-open_ctstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &ctstombs_methods);
-}
-
-static XlcConvMethodsRec cstombs_methods = {
- close_converter,
- cstombs,
- NULL
-};
-
-static XlcConv
-open_cstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &cstombs_methods);
-}
-
-static XlcConvMethodsRec strtombs_methods = {
- close_converter,
- strtombs,
- NULL
-};
-
-static XlcConv
-open_strtombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &strtombs_methods);
-}
-
-#ifdef STDCVT
-
-static XlcConvMethodsRec stdc_mbstowcs_methods = {
- close_converter,
- stdc_mbstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_mbstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_mbstowcs_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstombs_methods = {
- close_converter,
- stdc_wcstombs,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstombs_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstocts_methods = {
- close_converter,
- stdc_wcstocts,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstocts(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstocts_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstostr_methods = {
- close_converter,
- stdc_wcstostr,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstostr(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstostr_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstocs_methods = {
- close_converter,
- stdc_wcstocs,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstocs_methods);
-}
-
-static XlcConvMethodsRec stdc_wctocs_methods = {
- close_converter,
- stdc_wctocs,
- NULL
-};
-
-static XlcConv
-open_stdc_wctocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wctocs_methods);
-}
-
-static XlcConvMethodsRec stdc_ctstowcs_methods = {
- close_converter,
- stdc_ctstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_ctstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_ctstowcs_methods);
-}
-
-static XlcConvMethodsRec stdc_cstowcs_methods = {
- close_converter,
- stdc_cstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_cstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_cstowcs_methods);
-}
-
-static XlcConvMethodsRec stdc_strtowcs_methods = {
- close_converter,
- stdc_strtowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_strtowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_strtowcs_methods);
-}
-
-#endif /* STDCVT */
-
-static XlcConvMethodsRec mbstowcs_methods = {
- close_converter,
- mbstowcs_org,
- NULL
-};
-
-static XlcConv
-open_mbstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstowcs_methods);
-}
-
-static XlcConvMethodsRec wcstombs_methods = {
- close_converter,
- wcstombs_org,
- NULL
-};
-
-static XlcConv
-open_wcstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstombs_methods);
-}
-
-static XlcConvMethodsRec wcstocts_methods = {
- close_converter,
- wcstocts,
- NULL
-};
-
-static XlcConv
-open_wcstocts(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstocts_methods);
-}
-
-static XlcConvMethodsRec wcstostr_methods = {
- close_converter,
- wcstostr,
- NULL
-};
-
-static XlcConv
-open_wcstostr(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstostr_methods);
-}
-
-static XlcConvMethodsRec wcstocs_methods = {
- close_converter,
- wcstocs,
- NULL
-};
-
-static XlcConv
-open_wcstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstocs_methods);
-}
-
-static XlcConvMethodsRec wctocs_methods = {
- close_converter,
- wctocs,
- NULL
-};
-
-static XlcConv
-open_wctocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wctocs_methods);
-}
-
-static XlcConvMethodsRec ctstowcs_methods = {
- close_converter,
- ctstowcs,
- NULL
-};
-
-static XlcConv
-open_ctstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &ctstowcs_methods);
-}
-
-static XlcConvMethodsRec cstowcs_methods = {
- close_converter,
- cstowcs,
- NULL
-};
-
-static XlcConv
-open_cstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &cstowcs_methods);
-}
-
-static XlcConvMethodsRec strtowcs_methods = {
- close_converter,
- strtowcs,
- NULL
-};
-
-static XlcConv
-open_strtowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &strtowcs_methods);
-}
-
-/* -------------------------------------------------------------------------- */
-/* Loader */
-/* -------------------------------------------------------------------------- */
-
-XLCd
-_XlcGenericLoader(
- const char *name)
-{
- XLCd lcd;
-#ifdef STDCVT
- XLCdGenericPart *gen;
-#endif
-
- lcd = _XlcCreateLC(name, _XlcGenericMethods);
-
- if (lcd == NULL)
- return lcd;
-
- default_GL_charset = _XlcGetCharSet("ISO8859-1:GL");
- default_GR_charset = _XlcGetCharSet("ISO8859-1:GR");
-
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts);
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNString, open_mbstostr);
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
- _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs);
- _XlcSetConverter(lcd, XlcNString, lcd, XlcNMultiByte, open_strtombs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
-
-#ifdef STDCVT
- gen = XLC_GENERIC_PART(lcd);
-
- if (gen->use_stdc_env != True) {
-#endif
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_wcstostr);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_wctocs);
- _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs);
- _XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_strtowcs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
-#ifdef STDCVT
- }
-#endif
-
-#ifdef STDCVT
- if (gen->use_stdc_env == True) {
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_stdc_mbstowcs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_stdc_wcstombs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_stdc_wcstocts);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_stdc_wcstostr);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_stdc_wcstocs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_stdc_wctocs);
- _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_stdc_ctstowcs);
- _XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_stdc_strtowcs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_stdc_cstowcs);
- }
-#endif
-
- _XlcAddUtf8Converters(lcd);
-
- return lcd;
-}
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+/*
+ * (c) Copyright 1995 FUJITSU LIMITED
+ * This is source code modified by FUJITSU LIMITED under the Joint
+ * Development Agreement for the CDE/Motif PST.
+ *
+ * Modifier: Masayoshi Shimamura FUJITSU LIMITED
+ *
+ */
+/*
+ * 2000
+ * Modifier: Ivan Pascal The XFree86 Project
+ */
+
+/*
+ * A generic locale loader for all kinds of ISO-2022 based codesets.
+ * Supports: all locales.
+ * How: Provides generic converters for ISO-2022 based codesets. Extensible as
+ * far as ISO-2022 is extensible: codesets can be given by name in the
+ * stream. Overall distinction between GL (0x00..0x7f) and GR (0x80..0xff).
+ * In every chunk between escape sequences, the number of bytes per
+ * character (char_size) is constant.
+ * Platforms: all systems.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "XlcGeneric.h"
+#include <stdio.h>
+
+#if !defined(Lynx_22) && !defined(X_LOCALE)
+#define STDCVT
+#endif
+
+typedef struct _CTDataRec {
+ const char *name;
+ const char *encoding; /* Compound Text encoding */
+} CTDataRec, *CTData;
+
+static CTDataRec directionality_data[] =
+{
+ { "BEGIN_LEFT-TO-RIGHT_TEXT", "\2331]" },
+ { "BEGIN_RIGHT-TO-LEFT_TEXT", "\2332]" },
+ { "END_OF_STRING", "\233]" },
+};
+
+typedef struct _StateRec {
+ XLCd lcd;
+ /* CT state */
+ XlcCharSet charset; /* charset of current state */
+ XlcCharSet GL_charset; /* charset of initial state in GL */
+ XlcCharSet GR_charset; /* charset of initial state in GR */
+ /* MB shift state */
+ CodeSet GL_codeset;
+ CodeSet GR_codeset;
+} StateRec, *State;
+
+#define GR 0x80 /* begins right-side (non-ascii) region */
+#define GL 0x7f /* ends left-side (ascii) region */
+#define ESC 0x1b
+#define CSI 0x9b
+#define STX 0x02
+
+#define isrightside(c) ((c) & GR)
+#define isleftside(c) (!isrightside(c))
+
+/* Forward declarations for local routines. */
+static int mbstocts (XlcConv conv, XPointer *from, int *from_left,
+ XPointer *to, int *to_left, XPointer *args, int num_args);
+static int ctstombs (XlcConv conv, XPointer *from, int *from_left,
+ XPointer *to, int *to_left, XPointer *args, int num_args);
+static int cstombs (XlcConv conv, XPointer *from, int *from_left,
+ XPointer *to, int *to_left, XPointer *args, int num_args);
+
+/* ------------------------------------------------------------------------- */
+/* Misc */
+/* ------------------------------------------------------------------------- */
+
+static int
+compare(
+ const char *src,
+ const char *encoding,
+ int length)
+{
+ const char *start = src;
+
+ while (length-- > 0) {
+ if (*src++ != *encoding++)
+ return 0;
+ if (*encoding == '\0')
+ return src - start;
+ }
+
+ return 0;
+}
+
+static unsigned long
+conv_to_dest(
+ Conversion conv,
+ unsigned long code)
+{
+ int i;
+ int conv_num = conv->conv_num;
+ FontScope convlist = conv->convlist;
+
+ for (i = 0; i < conv_num; i++) {
+ if (convlist[i].start <= code && code <= convlist[i].end) {
+ switch (convlist[i].shift_direction) {
+ case '+':
+ return(code + convlist[i].shift);
+ case '-':
+ return(code - convlist[i].shift);
+ default:
+ return(code);
+ }
+ }
+ }
+
+ return(code);
+}
+
+static unsigned long
+conv_to_source(
+ Conversion conv,
+ unsigned long code)
+{
+ int i;
+ int conv_num;
+ FontScope convlist;
+ unsigned long start_p;
+ unsigned long start_m;
+ unsigned long end_p;
+ unsigned long end_m;
+
+ if (!conv)
+ return(code);
+
+ conv_num = conv->conv_num;
+ convlist = conv->convlist;
+
+ for (i = 0; i < conv_num; i++) {
+ switch (convlist[i].shift_direction) {
+ case '+':
+ start_p = convlist[i].start + convlist[i].shift;
+ end_p = convlist[i].end + convlist[i].shift;
+ if (start_p <= code && code <= end_p)
+ return(code - convlist[i].shift);
+ break;
+ case '-':
+ start_m = convlist[i].start - convlist[i].shift;
+ end_m = convlist[i].end - convlist[i].shift;
+ if (start_m <= code && code <= end_m)
+ return(code + convlist[i].shift);
+ break;
+ default:
+ continue;
+ }
+ }
+
+ return(code);
+}
+
+static unsigned long
+mb_to_gi(
+ unsigned long mb,
+ CodeSet codeset)
+{
+ int i;
+ unsigned long mb_tmp, mask = 0;
+
+ if (codeset->mbconv) {
+ mb_tmp = conv_to_dest(codeset->mbconv, mb);
+ if (mb_tmp != mb)
+ return(mb_tmp);
+ }
+
+ if (codeset->side == XlcC0 || codeset->side == XlcGL ||
+ codeset->side == XlcC1 || codeset->side == XlcGR) {
+
+ for (i = 0; i < codeset->length; i++)
+ mask = (mask << 8) | GL;
+ mb = mb & mask;
+ }
+
+ return(mb);
+}
+
+static unsigned long
+gi_to_mb(
+ unsigned long glyph_index,
+ CodeSet codeset)
+{
+ int i;
+ unsigned long mask = 0;
+
+ if (codeset->side == XlcC1 || codeset->side == XlcGR) {
+ for (i = 0; i < codeset->length; i++)
+ mask = (mask << 8) | GR;
+ glyph_index = glyph_index | mask;
+ }
+
+ if (codeset->mbconv)
+ return( conv_to_source(codeset->mbconv, glyph_index) );
+
+ return(glyph_index);
+}
+
+static Bool
+gi_to_wc(
+ XLCd lcd,
+ unsigned long glyph_index,
+ CodeSet codeset,
+ wchar_t *wc)
+{
+ unsigned char mask = 0;
+ unsigned long wc_encoding = codeset->wc_encoding;
+ int length = codeset->length;
+ unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
+
+ mask = (1 << wc_shift_bits) - 1 ;
+
+ for (*wc = 0, length--; length >= 0; length--)
+ *wc = (*wc << wc_shift_bits) | ((glyph_index >> (length * 8 )) & mask);
+
+ *wc = *wc | wc_encoding;
+
+ return(True);
+}
+
+static Bool
+wc_to_gi(
+ XLCd lcd,
+ wchar_t wc,
+ unsigned long *glyph_index,
+ CodeSet *codeset)
+{
+ int i;
+ unsigned char mask = 0;
+ unsigned long wc_encoding;
+ unsigned long wc_encode_mask = XLC_GENERIC(lcd, wc_encode_mask);
+ unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
+ int codeset_num = XLC_GENERIC(lcd, codeset_num);
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+
+ wc_encoding = wc & wc_encode_mask;
+ for (*codeset = NULL, i = 0; i < codeset_num; i++) {
+ if (wc_encoding == codeset_list[i]->wc_encoding) {
+ *codeset = codeset_list[i];
+ break;
+ }
+ }
+ if (*codeset == NULL)
+ return(False);
+
+ mask = (1 << wc_shift_bits) - 1 ;
+
+ wc = wc & ~wc_encode_mask;
+ for (*glyph_index = 0, i = (*codeset)->length - 1; i >= 0; i--)
+ *glyph_index = (*glyph_index << 8) |
+ ( ((unsigned long)wc >> (i * wc_shift_bits)) & mask );
+
+ return(True);
+}
+
+static CodeSet
+mb_parse_codeset(
+ State state,
+ int num,
+ const char **inbufptr,
+ int *from_left)
+{
+ int len;
+ int from_len = (*from_left) + 1;
+ const char *src = (*inbufptr) - 1;
+ ParseInfo *mb_parse_list = XLC_GENERIC(state->lcd, mb_parse_list);
+ ParseInfo parse_info;
+ CodeSet codeset;
+
+ for (--num ; (parse_info = mb_parse_list[num]) != NULL; num++) {
+ len = compare(src, parse_info->encoding, from_len);
+ if (len > 0) {
+ codeset = parse_info->codeset;
+ if (parse_info->type == E_LSL)
+ state->GL_codeset = codeset;
+ else if (parse_info->type == E_LSR)
+ state->GR_codeset = codeset;
+ --len;
+ *inbufptr += len;
+ *from_left -= len;
+ return codeset;
+ }
+ }
+ return (CodeSet) NULL;
+}
+
+static CodeSet
+byteM_parse_codeset(
+ XLCd lcd,
+ const char *inbufptr)
+{
+ unsigned char ch;
+ CodeSet codeset;
+ ByteInfoList byteM;
+ ByteInfoListRec byteM_rec;
+ ByteInfo byteinfo;
+ ByteInfoRec byteinfo_rec;
+ Bool hit = False;
+ int i, j, k;
+
+ int codeset_num = XLC_GENERIC(lcd, codeset_num);
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+
+ for (i = 0; i < codeset_num; i++) {
+ codeset = codeset_list[i];
+ byteM = codeset->byteM;
+ if (codeset->side != XlcNONE || byteM == NULL)
+ continue;
+
+ for (j = 0; j < codeset->length; j++) {
+ ch = *((unsigned char *)(inbufptr + j));
+ byteM_rec = byteM[j];
+ byteinfo = byteM_rec.byteinfo;
+
+ for (hit = False, k = 0; k < byteM_rec.byteinfo_num; k++) {
+ byteinfo_rec = byteinfo[k];
+ if (byteinfo_rec.start <= ch && ch <= byteinfo_rec.end) {
+ hit = True;
+ break;
+ }
+ }
+
+ if (!hit)
+ break;
+ }
+
+ if (hit)
+ return(codeset);
+ }
+
+ return(NULL);
+}
+
+#define GLGR_parse_codeset(ch) \
+ (isrightside(ch) ? (state->GR_codeset) : \
+ (state->GL_codeset) )
+
+static XlcCharSet
+gi_parse_charset(
+ unsigned long glyph_index,
+ CodeSet codeset)
+{
+ int i;
+ XlcCharSet *charset_list = codeset->charset_list;
+ int num_charsets = codeset->num_charsets;
+ ExtdSegment ctextseg = codeset->ctextseg;
+ XlcCharSet charset = NULL;
+ int area_num;
+ FontScope area;
+
+ /* lockup ct sequence */
+ for (i = 0; i < num_charsets; i++) {
+ charset = charset_list[i];
+ if (*charset->ct_sequence != '\0')
+ break;
+ }
+ if (i >= num_charsets)
+ return(NULL);
+
+ if (charset->source != CSsrcStd)
+ return (charset);
+
+ if (!ctextseg)
+ return(charset);
+
+ area = ctextseg->area;
+ area_num = ctextseg->area_num;
+
+ for (i = 0; i < area_num; i++) {
+
+ if (area[i].start <= glyph_index && glyph_index <= area[i].end) {
+
+ charset = ctextseg->charset;
+
+ if (*charset->ct_sequence == '\0')
+ return(NULL);
+
+ break;
+ }
+ }
+
+ return(charset);
+}
+
+static Bool
+ct_parse_csi(
+ const char *inbufptr,
+ int *ctr_seq_len)
+{
+ int i;
+ int num = sizeof(directionality_data) / sizeof(directionality_data[0]);
+
+ for (i = 0; i < num; i++) {
+ if ( !(*ctr_seq_len = strlen(directionality_data[i].encoding)) )
+ continue;
+
+ if ( strncmp(inbufptr, directionality_data[i].encoding,
+ *ctr_seq_len) == 0)
+ return(True);
+ }
+
+ return(False);
+}
+
+static int
+cmp_esc_sequence(
+ const char *inbufptr,
+ XlcCharSet charset)
+{
+ int seq_len, name_len, total_len;
+ unsigned char byte_m, byte_l;
+ const char *ct_sequence = charset->ct_sequence;
+ const char *encoding_name = charset->encoding_name;
+
+ /* check esc sequence */
+ if ( !(seq_len = strlen(ct_sequence) ) )
+ return(0);
+ if ( strncmp(inbufptr, ct_sequence, seq_len) != 0)
+ return(0);
+
+ /* Standard Character Set Encoding ? */
+ if (charset->source == CSsrcStd)
+ return(seq_len);
+
+ /*
+ * Non-Standard Character Set Encoding
+ *
+ * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+
+ * | ctseq | M | L | encoding name | STX | contents |
+ * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+
+ * 4bytes 1byte 1byte variable length 1byte variable length
+ * | |
+ * +----------------------------------------------+
+ * rest length = ((M - 128) * 128) + (L - 128)
+ */
+
+ /* get length of encoding name */
+ inbufptr += seq_len;
+ byte_m = *inbufptr++;
+ byte_l = *inbufptr++;
+ name_len = strlen(encoding_name);
+
+ if (((byte_m - 128) * 128 + (byte_l - 128) - 1) < name_len)
+ return(0);
+
+ if ( _XlcNCompareISOLatin1(inbufptr, encoding_name, name_len) != 0 )
+ return(0);
+
+ /* check STX (Start of Text) */
+ inbufptr = inbufptr + name_len;
+ if ( *inbufptr != STX )
+ return(0);
+
+ total_len = seq_len + name_len + 3;
+ return(total_len);
+}
+
+static Bool
+ct_parse_charset(
+ XLCd lcd,
+ const char *inbufptr,
+ XlcCharSet *charset,
+ int *ctr_seq_len)
+{
+ int i, j;
+ ExtdSegment ctextseg;
+ int num_charsets;
+ XlcCharSet *charset_list;
+ CodeSet codeset;
+ int codeset_num = XLC_GENERIC(lcd, codeset_num);
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+ int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
+ SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
+
+ /* get charset from XLC_XLOCALE by escape sequence */
+
+ for (i = 0; i < codeset_num; i++) {
+ codeset = codeset_list[i];
+
+ num_charsets = codeset->num_charsets;
+ charset_list = codeset->charset_list;
+ ctextseg = codeset->ctextseg;
+
+ for (j = 0; j < num_charsets; j++) {
+ *charset = charset_list[j];
+ if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
+ return(True);
+ }
+
+ if (ctextseg) {
+ *charset = ctextseg->charset;
+ if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
+ return(True);
+ }
+ }
+
+ /* get charset from XLC_SEGMENTCONVERSION by escape sequence */
+
+ if (!segment_conv)
+ return(False);
+
+ for (i = 0; i < segment_conv_num; i++) {
+ *charset = segment_conv[i].source;
+ if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
+ return(True);
+ *charset = segment_conv[i].dest;
+ if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
+ return(True);
+ }
+
+ return(False);
+}
+
+static Bool
+segment_conversion(
+ XLCd lcd,
+ XlcCharSet *charset,
+ unsigned long *glyph_index)
+{
+ int i;
+ int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
+ SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
+ FontScopeRec range;
+ ConversionRec conv_rec;
+
+ if (!segment_conv)
+ return(True);
+
+ for (i = 0; i < segment_conv_num; i++) {
+ if (segment_conv[i].source == *charset)
+ break;
+ }
+
+ if (i >= segment_conv_num)
+ return(True);
+
+ range = segment_conv[i].range;
+ if (*glyph_index < range.start || range.end < *glyph_index)
+ return(True);
+
+ *charset = segment_conv[i].dest;
+ conv_rec.conv_num = segment_conv[i].conv_num;
+ conv_rec.convlist = segment_conv[i].conv;
+ *glyph_index = conv_to_dest(&conv_rec, *glyph_index);
+
+ return(True);
+}
+
+static CodeSet
+_XlcGetCodeSetFromName(
+ XLCd lcd,
+ const char *name)
+{
+ int i, j;
+ XlcCharSet charset;
+ int num_charsets;
+ XlcCharSet *charset_list;
+ CodeSet codeset;
+
+ int codeset_num = XLC_GENERIC(lcd, codeset_num);
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+
+ for (i = 0; i < codeset_num; i++) {
+ codeset = codeset_list[i];
+
+ num_charsets = codeset->num_charsets;
+ charset_list = codeset->charset_list;
+
+ for (j = 0; j < num_charsets; j++) {
+ charset = charset_list[j];
+
+ if (!strlen(charset->name))
+ continue;
+ if ( strcmp(charset->name, name) == 0)
+ return(codeset);
+ }
+ }
+
+ return(NULL);
+}
+
+static Bool
+_XlcGetCodeSetFromCharSet(
+ XLCd lcd,
+ XlcCharSet charset,
+ CodeSet *codeset,
+ unsigned long *glyph_index)
+{
+ int j, num;
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+ XlcCharSet *charset_list;
+ int codeset_num, num_charsets;
+ Conversion ctconv;
+ unsigned long glyph_index_tmp = 0;
+ ExtdSegment ctextseg;
+
+ codeset_num = XLC_GENERIC(lcd, codeset_num);
+
+ for (num = 0 ; num < codeset_num; num++) {
+ *codeset = codeset_list[num];
+ ctconv = (*codeset)->ctconv;
+ ctextseg = (*codeset)->ctextseg;
+
+ num_charsets = (*codeset)->num_charsets;
+ charset_list = (*codeset)->charset_list;
+
+ glyph_index_tmp = conv_to_source(ctconv, *glyph_index);
+
+ if (charset->source == CSsrcStd) {
+
+ /* Standard Character Set Encoding */
+ if (glyph_index_tmp == *glyph_index) {
+ for (j = 0; j < num_charsets; j++) {
+ if (charset_list[j] == charset) {
+ goto end_loop;
+ }
+ }
+ }
+
+ } else {
+
+ /* Non-Standard Character Set Encoding */
+ for (j = 0; j < num_charsets; j++) {
+ if (charset_list[j] == charset) {
+ goto end_loop;
+ }
+ }
+
+ if (glyph_index_tmp != *glyph_index) {
+ if (ctextseg && ctextseg->charset == charset) {
+ goto end_loop;
+ }
+ }
+
+ }
+
+ }
+
+end_loop:
+ if (num < codeset_num) {
+ *glyph_index = glyph_index_tmp;
+ return(True);
+ }
+
+ return(False);
+}
+
+#define check_string_encoding(codeset) (codeset->string_encoding)
+
+static void
+output_ulong_value(
+ char *outbufptr,
+ unsigned long code,
+ int length,
+ XlcSide side)
+{
+ int i;
+
+ for (i = (length - 1) * 8; i >= 0; i -= 8) {
+ *outbufptr = ( code >> i) & 0xff;
+
+ if (side == XlcC0 || side == XlcGL) {
+ *outbufptr = *outbufptr & GL;
+ } else if (side == XlcC1 || side == XlcGR) {
+ *outbufptr = *outbufptr | GR;
+ }
+
+ outbufptr++;
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+/* Init */
+/* -------------------------------------------------------------------------- */
+
+static XlcCharSet default_GL_charset = 0;
+static XlcCharSet default_GR_charset = 0;
+
+static void
+init_state(
+ XlcConv conv)
+{
+ State state = (State) conv->state;
+
+ /* for CT */
+ state->charset = NULL;
+ state->GL_charset = default_GL_charset;
+ state->GR_charset = default_GR_charset;
+
+ /* for MB shift state */
+ state->GL_codeset = XLC_GENERIC(state->lcd, initial_state_GL);
+ state->GR_codeset = XLC_GENERIC(state->lcd, initial_state_GR);
+}
+
+/* -------------------------------------------------------------------------- */
+/* Convert */
+/* -------------------------------------------------------------------------- */
+
+static int
+mbstowcs_org(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long mb = 0;
+ wchar_t wc;
+
+ int length = 0, len_left = 0;
+ int unconv_num = 0;
+ int num;
+
+ CodeSet codeset = NULL;
+
+ const char *inbufptr = *from;
+ wchar_t *outbufptr = (wchar_t *) *to;
+ int from_size = *from_left;
+
+ unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
+
+ if (from == NULL || *from == NULL) {
+ _XlcResetConverter(conv);
+ return( 0 );
+ }
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = L'\0';}
+ (*to_left)--;
+
+ /* error check */
+ if (len_left) {
+ unconv_num += (length - len_left);
+ len_left = 0;
+ }
+
+ continue;
+ }
+
+ /* same mb char data */
+ if (len_left)
+ goto output_one_wc;
+
+ /* next mb char data for single shift ? */
+ if (mb_parse_table && (num = mb_parse_table[ch]) ) {
+ codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
+ if (codeset != NULL) {
+ length = len_left = codeset->length;
+ mb = 0;
+ continue;
+ }
+ }
+
+ /* next mb char data for byteM ? */
+ if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
+ goto next_mb_char;
+
+ /* next mb char data for GL or GR side ? */
+ if ((codeset = GLGR_parse_codeset(ch)))
+ goto next_mb_char;
+
+ /* can't find codeset for the ch */
+ unconv_num++;
+ continue;
+
+next_mb_char:
+ length = len_left = codeset->length;
+ mb = 0;
+
+output_one_wc:
+ mb = (mb << 8) | ch; /* 1 byte left shift */
+ len_left--;
+
+ /* last of one mb char data */
+ if (!len_left) {
+ gi_to_wc(lcd, mb_to_gi(mb, codeset), codeset, &wc);
+ if (outbufptr) {*outbufptr++ = wc;}
+ (*to_left)--;
+ }
+
+ } /* end of while */
+
+ /* error check on last char */
+ if (len_left) {
+ inbufptr -= (length - len_left);
+ (*from_left) += (length - len_left);
+ unconv_num += (length - len_left);
+ }
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_mbstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const char *src = *((const char **) from);
+ wchar_t *dst = *((wchar_t **) to);
+ int src_left = *from_left;
+ int dst_left = *to_left;
+ int length, unconv_num = 0;
+
+ while (src_left > 0 && dst_left > 0) {
+ length = mbtowc(dst, src, src_left);
+
+ if (length > 0) {
+ src += length;
+ src_left -= length;
+ if (dst)
+ dst++;
+ dst_left--;
+ } else if (length < 0) {
+ src++;
+ src_left--;
+ unconv_num++;
+ } else {
+ /* null ? */
+ src++;
+ src_left--;
+ if (dst)
+ *dst++ = L'\0';
+ dst_left--;
+ }
+ }
+
+ *from = (XPointer) src;
+ if (dst)
+ *to = (XPointer) dst;
+ *from_left = src_left;
+ *to_left = dst_left;
+
+ return unconv_num;
+}
+
+static int
+wcstombs_org(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ char *encoding;
+ unsigned long mb, glyph_index;
+ wchar_t wc;
+
+ int length;
+ int unconv_num = 0;
+
+ CodeSet codeset;
+
+ const wchar_t *inbufptr = (const wchar_t *) *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ const char *default_string = XLC_PUBLIC(lcd, default_string);
+ int defstr_len = strlen(default_string);
+
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ wc = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!wc) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
+
+ /* output default_string of XDefaultString() */
+ if (*to_left < defstr_len)
+ break;
+ if (outbufptr) {
+ strncpy((char *)outbufptr, default_string, defstr_len);
+ outbufptr += defstr_len;
+ }
+ (*to_left) -= defstr_len;
+
+ unconv_num++;
+
+ } else {
+ mb = gi_to_mb(glyph_index, codeset);
+ if (codeset->parse_info) {
+ Bool need_shift = False;
+ switch (codeset->parse_info->type) {
+ case E_LSL :
+ if (codeset != state->GL_codeset) {
+ need_shift = True;
+ state->GL_codeset = codeset;
+ }
+ break;
+ case E_LSR :
+ if (codeset != state->GR_codeset) {
+ need_shift = True;
+ state->GR_codeset = codeset;
+ }
+ break;
+ /* case E_SS */
+ default:
+ need_shift = True;
+ }
+
+ /* output shift sequence */
+ if (need_shift) {
+ encoding = codeset->parse_info->encoding;
+ length = strlen(encoding);
+ if (*to_left < length)
+ break;
+ if (outbufptr) {
+ strncpy((char *)outbufptr, encoding, length);
+ outbufptr += length;
+ }
+ (*to_left) -= length;
+ }
+ }
+
+ /* output characters */
+ length = codeset->length;
+ if (*to_left < length)
+ break;
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, mb, length, XlcNONE);
+ outbufptr += length;
+ }
+
+ (*to_left) -= length;
+ }
+
+ } /* end of while */
+
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_wcstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const wchar_t *src = *((const wchar_t **) from);
+ char *dst = *((char **) to);
+ int src_left = *from_left;
+ int dst_left = *to_left;
+ int length, unconv_num = 0;
+
+ while (src_left > 0 && dst_left >= MB_CUR_MAX) {
+ length = wctomb(dst, *src); /* XXX */
+
+ if (length > 0) {
+ src++;
+ src_left--;
+ if (dst)
+ dst += length;
+ dst_left -= length;
+ } else if (length < 0) {
+ src++;
+ src_left--;
+ unconv_num++;
+ }
+ }
+
+ *from = (XPointer) src;
+ if (dst)
+ *to = (XPointer) dst;
+ *from_left = src_left;
+ *to_left = dst_left;
+
+ return unconv_num;
+}
+
+static int
+wcstocts(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned long glyph_index;
+ wchar_t wc;
+
+ int total_len, seq_len, name_len;
+ int unconv_num = 0;
+ Bool first_flag = True, standard_flag;
+ XlcSide side;
+
+ CodeSet codeset;
+ XlcCharSet charset, old_charset = NULL;
+ const char *ct_sequence;
+
+ const wchar_t *inbufptr = (const wchar_t *) *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+ char *ext_seg_len = NULL;
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ wc = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!wc) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
+ unconv_num++;
+ continue;
+ }
+
+ /* parse charset */
+ if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
+ unconv_num++;
+ continue;
+ }
+
+ /* Standard Character Set Encoding ? */
+ standard_flag = charset->source == CSsrcStd ? True : False;
+
+ /*
+ * Non-Standard Character Set Encoding
+ *
+ * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
+ * | esc sequence | M | L | encoding name | STX |
+ * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
+ * 4bytes 1byte 1byte variable length 1byte
+ * | |
+ * +-----------------------------------------+
+ * name length = ((M - 128) * 128) + (L - 128)
+ */
+
+ /* make encoding data */
+ ct_sequence = charset->ct_sequence;
+ side = charset->side;
+ seq_len = strlen(ct_sequence);
+ if (standard_flag) {
+ name_len = 0;
+ total_len = seq_len;
+ } else {
+ name_len = strlen(charset->encoding_name) + 1;
+ total_len = seq_len + name_len + 2;
+ }
+
+ /* output escape sequence of CT */
+ if ( (charset != old_charset) &&
+ !(first_flag && charset->string_encoding) ){
+
+ if ( (ext_seg_len != NULL) && outbufptr) {
+ int i = (outbufptr - ext_seg_len) - 2;
+ *ext_seg_len++ = i / 128 + 128;
+ *ext_seg_len = i % 128 + 128;
+ ext_seg_len = NULL;
+ }
+
+ if (*to_left < total_len + 1) {
+ unconv_num++;
+ break;
+ }
+
+ if (outbufptr) {
+ strcpy((char *)outbufptr, ct_sequence);
+ outbufptr += seq_len;
+
+ if (!standard_flag) {
+ const char *i = charset->encoding_name;
+ ext_seg_len = outbufptr;
+ outbufptr += 2;
+ for (; *i ; i++)
+ *outbufptr++ = ((*i >= 'A') && (*i <= 'Z')) ?
+ *i - 'A' + 'a' : *i;
+ *outbufptr++ = STX;
+ }
+ }
+
+ (*to_left) -= total_len;
+
+ first_flag = False;
+ old_charset = charset;
+ }
+
+ /* output glyph index */
+ if (codeset->ctconv)
+ glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
+ if (*to_left < charset->char_size) {
+ unconv_num++;
+ break;
+ }
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, glyph_index, charset->char_size, side);
+ outbufptr += charset->char_size;
+ }
+
+ (*to_left) -= charset->char_size;
+
+ } /* end of while */
+
+ if ( (ext_seg_len != NULL) && outbufptr) {
+ int i = (outbufptr - ext_seg_len) - 2;
+ *ext_seg_len++ = i / 128 + 128;
+ *ext_seg_len = i % 128 + 128;
+ }
+
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_wcstocts(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = stdc_wcstombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = mbstocts(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+ctstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long glyph_index = 0;
+ wchar_t wc;
+
+ int ctr_seq_len = 0, gi_len_left = 0, gi_len = 0;
+ int unconv_num = 0;
+
+ CodeSet codeset = NULL;
+ XlcCharSet charset_tmp;
+
+ const char *inbufptr = *from;
+ wchar_t *outbufptr = (wchar_t *) *to;
+ int from_size = *from_left;
+
+ _XlcResetConverter(conv); /* ??? */
+
+ if (from == NULL || *from == NULL) {
+ _XlcResetConverter(conv);
+ return( 0 );
+ }
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = L'\0';}
+ (*to_left)--;
+
+ /* error check */
+ if (gi_len_left) {
+ unconv_num += (gi_len - gi_len_left);
+ gi_len_left = 0;
+ }
+
+ continue;
+ }
+
+ /* same glyph_index data */
+ if (gi_len_left)
+ goto output_one_wc;
+
+ /* control sequence ? */
+ if (ch == CSI) {
+ if ( !ct_parse_csi(inbufptr - 1, &ctr_seq_len) )
+ goto skip_the_seg;
+
+ if (*from_left + 1 < ctr_seq_len) {
+ inbufptr--;
+ (*from_left)++;
+ unconv_num += *from_left;
+ break;
+ }
+
+ /* skip the control sequence */
+ inbufptr += (ctr_seq_len - 1);
+ *from_left -= (ctr_seq_len - 1);
+
+ continue;
+ }
+
+ /* escape sequence ? */
+ if (ch == ESC) {
+ if ( !ct_parse_charset(lcd,
+ inbufptr - 1, &state->charset, &ctr_seq_len) )
+ goto skip_the_seg;
+
+ if (state->charset->side == XlcC0 ||
+ state->charset->side == XlcGL)
+ {
+ state->GL_charset = state->charset;
+ }
+ else if (state->charset->side == XlcC1 ||
+ state->charset->side == XlcGR)
+ {
+ state->GR_charset = state->charset;
+ }
+ else if (state->charset->side == XlcGLGR)
+ {
+ state->GL_charset = state->charset;
+ state->GR_charset = state->charset;
+ }
+
+ if (*from_left + 1 < ctr_seq_len) {
+ inbufptr--;
+ (*from_left)++;
+ unconv_num += *from_left;
+ break;
+ }
+
+ /* skip the escape sequence */
+ inbufptr += (ctr_seq_len - 1);
+ *from_left -= (ctr_seq_len - 1);
+
+ continue;
+ }
+
+ /* check current state */
+ if (isleftside(ch))
+ state->charset = state->GL_charset;
+ else
+ state->charset = state->GR_charset;
+
+ gi_len = gi_len_left = state->charset->char_size;
+ glyph_index = 0;
+
+output_one_wc:
+ if (state->charset->side == XlcC1 || state->charset->side == XlcGR)
+ glyph_index = (glyph_index << 8) | (ch & GL);
+ else
+ glyph_index = (glyph_index << 8) | ch;
+
+ gi_len_left--;
+
+ /* last of one glyph_index data */
+ if (!gi_len_left) {
+
+ /* segment conversion */
+ charset_tmp = state->charset;
+ segment_conversion(lcd, &charset_tmp, &glyph_index);
+
+ /* get codeset */
+ if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
+ &codeset, &glyph_index) ) {
+ unconv_num += gi_len;
+ continue;
+ }
+
+ /* convert glyph index to wicd char */
+ gi_to_wc(lcd, glyph_index, codeset, &wc);
+ if (outbufptr) {*outbufptr++ = wc;}
+ (*to_left)--;
+ }
+
+ continue;
+
+skip_the_seg:
+ /* skip until next escape or control sequence */
+ while ( *from_left ) {
+ ch = *inbufptr++;
+ (*from_left)--;
+ unconv_num++;
+
+ if (ch == ESC || ch == CSI) {
+ inbufptr--;
+ (*from_left)++;
+ unconv_num--;
+ break;
+ }
+ }
+
+ if ( !(*from_left) )
+ break;
+
+ } /* end of while */
+
+ /* error check on last char */
+ if (gi_len_left) {
+ inbufptr -= (gi_len - gi_len_left);
+ (*from_left) += (gi_len - gi_len_left);
+ unconv_num += (gi_len - gi_len_left);
+ }
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+cstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long glyph_index = 0;
+ wchar_t wc;
+ int gi_len_left = 0, gi_len = 0;
+
+ int unconv_num = 0;
+
+ CodeSet codeset = NULL;
+ XlcCharSet charset, charset_tmp;
+
+ const char *inbufptr = *from;
+ wchar_t *outbufptr = (wchar_t *) *to;
+ int from_size = *from_left;
+
+ if (from == NULL || *from == NULL) {
+ return( 0 );
+ }
+
+ charset = (XlcCharSet) args[0];
+
+ while (*from_left && *to_left) {
+
+ if (!gi_len_left) {
+ gi_len_left = gi_len = charset->char_size;
+ glyph_index = 0;
+ }
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = L'\0';}
+ (*to_left)--;
+
+ /* error check */
+ if (gi_len_left) {
+ unconv_num += (gi_len - gi_len_left);
+ gi_len_left = 0;
+ }
+ continue;
+ }
+
+ if (charset->side == XlcC1 || charset->side == XlcGR)
+ glyph_index = (glyph_index << 8) | (ch & GL);
+ else
+ glyph_index = (glyph_index << 8) | ch;
+
+ gi_len_left--;
+
+ /* last of one glyph_index data */
+ if (!gi_len_left) {
+
+ /* segment conversion */
+ charset_tmp = charset;
+ segment_conversion(lcd, &charset_tmp, &glyph_index);
+
+ /* get codeset */
+ if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
+ &codeset, &glyph_index) ) {
+ unconv_num += gi_len;
+ continue;
+ }
+
+ /* convert glyph index to wicd char */
+ gi_to_wc(lcd, glyph_index, codeset, &wc);
+ if (outbufptr) {*outbufptr++ = wc;}
+ (*to_left)--;
+ }
+
+ } /* end of while */
+
+ /* error check on last char */
+ if (gi_len_left) {
+ inbufptr -= (gi_len - gi_len_left);
+ (*from_left) += (gi_len - gi_len_left);
+ unconv_num += (gi_len - gi_len_left);
+ }
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_ctstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = ctstombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = stdc_mbstowcs(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+stdc_cstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = cstombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = stdc_mbstowcs(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+mbstocts(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left);
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = mbstowcs_org(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
+
+ unconv_num2 += wcstocts(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+mbstostr(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long mb = 0;
+
+ int length = 0, len_left = 0;
+ int unconv_num = 0;
+ int num;
+
+ CodeSet codeset = NULL;
+
+ const char *inbufptr = *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
+
+ if (from == NULL || *from == NULL) {
+ _XlcResetConverter(conv);
+ return( 0 );
+ }
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ /* error check */
+ if (len_left) {
+ unconv_num += (length - len_left);
+ len_left = 0;
+ }
+
+ continue;
+ }
+
+ /* same mb char data */
+ if (len_left)
+ goto output_one_mb;
+
+ /* next mb char data for single shift ? */
+ if (mb_parse_table && (num = mb_parse_table[ch]) ) {
+ codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
+ if (codeset != NULL) {
+ length = len_left = codeset->length;
+ mb = 0;
+ continue;
+ }
+ }
+
+ /* next char data : byteM ? */
+ if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
+ goto next_mb_char;
+
+ /* next char data : GL or GR side ? */
+ if ((codeset = GLGR_parse_codeset(ch)))
+ goto next_mb_char;
+
+ /* can't find codeset for the ch */
+ unconv_num++;
+ continue;
+
+next_mb_char:
+ length = len_left = codeset->length;
+ mb = 0;
+
+output_one_mb:
+ mb = (mb << 8) | ch; /* 1 byte left shift */
+ len_left--;
+
+ /* last of one mb char data */
+ if (!len_left) {
+ if (check_string_encoding(codeset)) {
+ if (outbufptr) {*outbufptr++ = mb & 0xff;}
+ (*to_left)--;
+ } else {
+ unconv_num++;
+ }
+ }
+
+ } /* end of while */
+
+ /* error check on last char */
+ if (len_left) {
+ inbufptr -= (length - len_left);
+ (*from_left) += (length - len_left);
+ unconv_num += (length - len_left);
+ }
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+mbtocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long mb = 0;
+ unsigned long glyph_index;
+
+ int length = 0, len_left = 0, char_len;
+ int unconv_num = 0;
+ int num;
+ XlcSide side;
+
+ CodeSet codeset = NULL;
+ XlcCharSet charset = NULL;
+
+ const char *inbufptr = *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
+
+ if (from == NULL || *from == NULL) {
+ _XlcResetConverter(conv);
+ return( 0 );
+ }
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ unconv_num = 1;
+ if (len_left)
+ unconv_num += (length - len_left);
+ break;
+ }
+
+ /* same mb char data */
+ if (len_left)
+ goto output;
+
+ /* next mb char data for single shift ? */
+ if (mb_parse_table && (num = mb_parse_table[ch]) ) {
+ codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
+ if (codeset != NULL) {
+ length = len_left = codeset->length;
+ mb = 0;
+ continue;
+ }
+ }
+
+ /* next mb char data for byteM ? */
+ if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
+ goto next_mb_char;
+
+ /* next mb char data for GL or GR side ? */
+ if ((codeset = GLGR_parse_codeset(ch)))
+ goto next_mb_char;
+
+ /* can't find codeset for the ch */
+ unconv_num = 1;
+ break;
+
+next_mb_char:
+ length = len_left = codeset->length;
+ mb = 0;
+
+output:
+ mb = (mb << 8) | ch; /* 1 byte left shift */
+ len_left--;
+
+ /* last of one mb char data */
+ if (!len_left) {
+ glyph_index = mb_to_gi(mb, codeset);
+ if (!(charset = gi_parse_charset(glyph_index, codeset))) {
+ unconv_num = length;
+ break;
+ }
+ char_len = charset->char_size;
+ side = charset->side;
+
+ /* output glyph index */
+ if (codeset->ctconv)
+ glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
+ if (*to_left < char_len) {
+ unconv_num = length;
+ break;
+ }
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, glyph_index, char_len, side);
+ outbufptr += char_len;
+ }
+
+ (*to_left) -= char_len;
+
+ break;
+ }
+
+ } /* end of while */
+
+ /* error end */
+ if (unconv_num) {
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+ return -1;
+ }
+
+ /* nomal end */
+ *from = (XPointer) inbufptr;
+ *to = (XPointer) outbufptr;
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return 0;
+}
+
+static int
+mbstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ int ret;
+ XlcCharSet charset_old, charset = NULL;
+ XPointer tmp_args[1];
+
+ const char *inbufptr;
+ int in_left;
+ char *outbufptr;
+ int out_left;
+ tmp_args[0] = (XPointer) &charset;
+
+ ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ charset_old = charset;
+
+ while ( ret == 0 && *from_left && *to_left) {
+ inbufptr = *from;
+ in_left = *from_left;
+ outbufptr = *to;
+ out_left = *to_left;
+ ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ if (charset_old != charset) {
+ *from = (XPointer) inbufptr;
+ *from_left = in_left;
+ *to = (XPointer) outbufptr;
+ *to_left = out_left;
+ break;
+ }
+ }
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset_old;
+
+ /* error end */
+ if (ret != 0)
+ return( -1 );
+
+ return(0);
+}
+
+static int
+wcstostr(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ char *encoding;
+ unsigned long mb, glyph_index;
+ wchar_t wc;
+
+ int length;
+ int unconv_num = 0;
+
+ CodeSet codeset;
+
+ const wchar_t *inbufptr = (const wchar_t *) *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ const char *default_string = XLC_PUBLIC(lcd, default_string);
+ int defstr_len = strlen(default_string);
+
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ wc = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!wc) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
+
+ /* output default_string of XDefaultString() */
+ if (*to_left < defstr_len)
+ break;
+ if (outbufptr) {
+ strncpy((char *)outbufptr, default_string, defstr_len);
+ outbufptr += defstr_len;
+ }
+ (*to_left) -= defstr_len;
+
+ unconv_num++;
+
+ } else {
+ mb = gi_to_mb(glyph_index, codeset);
+
+ if (check_string_encoding(codeset)) {
+ if (codeset->parse_info) {
+ Bool need_shift = False;
+ switch (codeset->parse_info->type) {
+ case E_LSL :
+ if (codeset != state->GL_codeset) {
+ need_shift = True;
+ state->GL_codeset = codeset;
+ }
+ break;
+ case E_LSR :
+ if (codeset != state->GR_codeset) {
+ need_shift = True;
+ state->GR_codeset = codeset;
+ }
+ break;
+ /* case E_SS */
+ default:
+ need_shift = True;
+ }
+
+ /* output shift sequence */
+ if (need_shift) {
+ encoding = codeset->parse_info->encoding;
+ length = strlen(encoding);
+ if (*to_left < length)
+ break;
+
+ if (outbufptr) {
+ strncpy((char *)outbufptr, encoding, length);
+ outbufptr += length;
+ }
+ (*to_left) -= length;
+ }
+ }
+
+ /* output characters */
+ length = codeset->length;
+ if (*to_left < length)
+ break;
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, mb, length, XlcNONE);
+ outbufptr += length;
+ }
+
+ (*to_left) -= length;
+ } else {
+ unconv_num++;
+ }
+ }
+
+ } /* end of while */
+
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_wcstostr(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = stdc_wcstombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = mbstostr(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+wctocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ wchar_t wc;
+ unsigned long glyph_index;
+
+ int char_len;
+ int unconv_num = 0;
+ XlcSide side;
+
+ CodeSet codeset;
+ XlcCharSet charset = NULL;
+
+ const wchar_t *inbufptr = (const wchar_t *) *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ if (*from_left && *to_left) {
+
+ wc = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!wc) {
+ unconv_num = 1;
+ goto end;
+ }
+
+ /* convert */
+ if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
+ unconv_num = 1;
+ goto end;
+ }
+
+ if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
+ unconv_num = 1;
+ goto end;
+ }
+ char_len = charset->char_size;
+ side = charset->side;
+
+ /* output glyph index */
+ if (codeset->ctconv)
+ glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
+ if (*to_left < char_len) {
+ unconv_num++;
+ goto end;
+ }
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, glyph_index, char_len, side);
+ outbufptr += char_len;
+ }
+
+ (*to_left) -= char_len;
+
+ }
+
+end:
+
+ /* error end */
+ if (unconv_num) {
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+ return -1;
+ }
+
+ /* nomal end */
+ *from = (XPointer) inbufptr;
+ *to = (XPointer) outbufptr;
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return 0;
+}
+
+static int
+stdc_wctocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const wchar_t *src = *((const wchar_t **) from);
+ wchar_t wch;
+ XPointer tmp_from, save_from = *from;
+ char tmp[32];
+ int length, ret, src_left = *from_left;
+ int from_size = *from_left;
+
+ if (src_left > 0 && *to_left > 0) {
+ if ((wch = *src)) {
+ length = wctomb(tmp, wch);
+ } else {
+ goto end;
+ }
+
+ if (length < 0)
+ goto end;
+
+ tmp_from = (XPointer) tmp;
+ ret = mbtocs(conv, &tmp_from, &length, to, to_left, args, num_args);
+ if (ret < 0)
+ goto end;
+
+ src++;
+ src_left--;
+ }
+
+end:
+ /* error end */
+ if (save_from == (XPointer) src) {
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ return -1;
+ }
+
+ /* nomal end */
+ *from = (XPointer) src;
+ *from_left = src_left;
+
+ return 0;
+}
+
+static int
+wcstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ int ret;
+ XlcCharSet charset_old, charset = NULL;
+ XPointer tmp_args[1];
+
+ const wchar_t *inbufptr;
+ int in_left;
+ XPointer outbufptr;
+ int out_left;
+ tmp_args[0] = (XPointer) &charset;
+
+ ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ charset_old = charset;
+
+ while ( ret == 0 && *from_left && *to_left) {
+ inbufptr = (const wchar_t *) *from;
+ in_left = *from_left;
+ outbufptr = *to;
+ out_left = *to_left;
+ ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ if (charset_old != charset) {
+ *from = (XPointer) inbufptr;
+ *from_left = in_left;
+ *to = (XPointer) outbufptr;
+ *to_left = out_left;
+ break;
+ }
+ }
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset_old;
+
+ /* error end */
+ if (ret != 0)
+ return( -1 );
+
+ return(0);
+}
+
+#ifdef STDCVT
+
+static int
+stdc_wcstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ int ret;
+ XlcCharSet charset_old, charset = NULL;
+ XPointer tmp_args[1];
+
+ const wchar_t *inbufptr;
+ int in_left;
+ XPointer outbufptr;
+ int out_left;
+ tmp_args[0] = (XPointer) &charset;
+
+ ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ charset_old = charset;
+
+ while ( ret == 0 && *from_left && *to_left ) {
+ inbufptr = (const wchar_t *) *from;
+ in_left = *from_left;
+ outbufptr = *to;
+ out_left = *to_left;
+ ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ if (charset_old != charset) {
+ *from = (XPointer) inbufptr;
+ *from_left = in_left;
+ *to = (XPointer) outbufptr;
+ *to_left = out_left;
+ break;
+ }
+ }
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset_old;
+
+ /* error end */
+ if (ret != 0)
+ return( -1 );
+
+ return(0);
+}
+
+#endif
+
+static int
+ctstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left);
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = ctstowcs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
+
+ unconv_num2 += wcstombs_org(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+cstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left);
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = cstowcs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
+
+ unconv_num2 += wcstombs_org(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+strtombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ char *encoding;
+ unsigned long mb, glyph_index;
+ unsigned char ch;
+
+ int length;
+ int unconv_num = 0;
+
+ CodeSet codeset;
+
+ const char *inbufptr = *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if (isleftside(ch)) {
+ glyph_index = ch;
+ codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL");
+ } else {
+ glyph_index = ch & GL;
+ codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR");
+ }
+
+ if (!codeset) {
+ unconv_num++;
+ continue;
+ }
+
+ mb = gi_to_mb(glyph_index, codeset);
+ if (codeset->parse_info) {
+ Bool need_shift = False;
+ switch (codeset->parse_info->type) {
+ case E_LSL :
+ if (codeset != state->GL_codeset) {
+ need_shift = True;
+ state->GL_codeset = codeset;
+ }
+ break;
+ case E_LSR :
+ if (codeset != state->GR_codeset) {
+ need_shift = True;
+ state->GR_codeset = codeset;
+ }
+ break;
+ /* case E_SS */
+ default:
+ need_shift = True;
+ }
+
+ /* output shift sequence */
+ if (need_shift) {
+ encoding = codeset->parse_info->encoding;
+ length = strlen(encoding);
+ if (*to_left < length)
+ break;
+ if (outbufptr) {
+ strncpy((char *)outbufptr, encoding, length);
+ outbufptr += length;
+ }
+ (*to_left) -= length;
+ }
+ }
+
+ /* output characters */
+ length = codeset->length;
+ if (*to_left < length)
+ break;
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, mb, length, XlcNONE);
+ outbufptr += length;
+ }
+
+ (*to_left) -= length;
+
+ } /* end of while */
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+strtowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long glyph_index;
+ wchar_t wc;
+
+ int unconv_num = 0;
+ CodeSet codeset;
+
+ const char *inbufptr = *from;
+ wchar_t *outbufptr = (wchar_t *)*to;
+ int from_size = *from_left;
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = L'\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if (isleftside(ch)) {
+ glyph_index = ch;
+ codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL");
+ } else {
+ glyph_index = ch & GL;
+ codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR");
+ }
+
+ if (!codeset) {
+ unconv_num++;
+ continue;
+ }
+
+ gi_to_wc(lcd, glyph_index, codeset, &wc);
+ if (outbufptr) {*outbufptr++ = wc;}
+ (*to_left)--;
+
+ } /* end of while */
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_strtowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = strtombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = stdc_mbstowcs(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+/* -------------------------------------------------------------------------- */
+/* Close */
+/* -------------------------------------------------------------------------- */
+
+static void
+close_converter(
+ XlcConv conv)
+{
+ if (conv->state) {
+ Xfree((char *) conv->state);
+ }
+
+ if (conv->methods) {
+ Xfree((char *) conv->methods);
+ }
+
+ Xfree((char *) conv);
+}
+
+/* -------------------------------------------------------------------------- */
+/* Open */
+/* -------------------------------------------------------------------------- */
+
+static XlcConv
+create_conv(
+ XLCd lcd,
+ XlcConvMethods methods)
+{
+ XlcConv conv;
+ State state;
+
+ conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec));
+ if (conv == NULL)
+ return (XlcConv) NULL;
+
+ conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
+ if (conv->methods == NULL)
+ goto err;
+ *conv->methods = *methods;
+ conv->methods->reset = init_state;
+
+ conv->state = Xcalloc(1, sizeof(StateRec));
+ if (conv->state == NULL)
+ goto err;
+
+ state = (State) conv->state;
+ state->lcd = lcd;
+
+ _XlcResetConverter(conv);
+
+ return conv;
+
+err:
+ close_converter(conv);
+
+ return (XlcConv) NULL;
+}
+
+static XlcConvMethodsRec mbstocts_methods = {
+ close_converter,
+ mbstocts,
+ NULL
+};
+
+static XlcConv
+open_mbstocts(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstocts_methods);
+}
+
+static XlcConvMethodsRec mbstostr_methods = {
+ close_converter,
+ mbstostr,
+ NULL
+};
+
+static XlcConv
+open_mbstostr(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstostr_methods);
+}
+
+static XlcConvMethodsRec mbstocs_methods = {
+ close_converter,
+ mbstocs,
+ NULL
+};
+
+static XlcConv
+open_mbstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstocs_methods);
+}
+
+static XlcConvMethodsRec mbtocs_methods = {
+ close_converter,
+ mbtocs,
+ NULL
+};
+
+static XlcConv
+open_mbtocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbtocs_methods);
+}
+
+static XlcConvMethodsRec ctstombs_methods = {
+ close_converter,
+ ctstombs,
+ NULL
+};
+
+static XlcConv
+open_ctstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &ctstombs_methods);
+}
+
+static XlcConvMethodsRec cstombs_methods = {
+ close_converter,
+ cstombs,
+ NULL
+};
+
+static XlcConv
+open_cstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &cstombs_methods);
+}
+
+static XlcConvMethodsRec strtombs_methods = {
+ close_converter,
+ strtombs,
+ NULL
+};
+
+static XlcConv
+open_strtombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &strtombs_methods);
+}
+
+#ifdef STDCVT
+
+static XlcConvMethodsRec stdc_mbstowcs_methods = {
+ close_converter,
+ stdc_mbstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_mbstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_mbstowcs_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstombs_methods = {
+ close_converter,
+ stdc_wcstombs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstombs_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstocts_methods = {
+ close_converter,
+ stdc_wcstocts,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstocts(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstocts_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstostr_methods = {
+ close_converter,
+ stdc_wcstostr,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstostr(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstostr_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstocs_methods = {
+ close_converter,
+ stdc_wcstocs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstocs_methods);
+}
+
+static XlcConvMethodsRec stdc_wctocs_methods = {
+ close_converter,
+ stdc_wctocs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wctocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wctocs_methods);
+}
+
+static XlcConvMethodsRec stdc_ctstowcs_methods = {
+ close_converter,
+ stdc_ctstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_ctstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_ctstowcs_methods);
+}
+
+static XlcConvMethodsRec stdc_cstowcs_methods = {
+ close_converter,
+ stdc_cstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_cstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_cstowcs_methods);
+}
+
+static XlcConvMethodsRec stdc_strtowcs_methods = {
+ close_converter,
+ stdc_strtowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_strtowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_strtowcs_methods);
+}
+
+#endif /* STDCVT */
+
+static XlcConvMethodsRec mbstowcs_methods = {
+ close_converter,
+ mbstowcs_org,
+ NULL
+};
+
+static XlcConv
+open_mbstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstowcs_methods);
+}
+
+static XlcConvMethodsRec wcstombs_methods = {
+ close_converter,
+ wcstombs_org,
+ NULL
+};
+
+static XlcConv
+open_wcstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstombs_methods);
+}
+
+static XlcConvMethodsRec wcstocts_methods = {
+ close_converter,
+ wcstocts,
+ NULL
+};
+
+static XlcConv
+open_wcstocts(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstocts_methods);
+}
+
+static XlcConvMethodsRec wcstostr_methods = {
+ close_converter,
+ wcstostr,
+ NULL
+};
+
+static XlcConv
+open_wcstostr(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstostr_methods);
+}
+
+static XlcConvMethodsRec wcstocs_methods = {
+ close_converter,
+ wcstocs,
+ NULL
+};
+
+static XlcConv
+open_wcstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstocs_methods);
+}
+
+static XlcConvMethodsRec wctocs_methods = {
+ close_converter,
+ wctocs,
+ NULL
+};
+
+static XlcConv
+open_wctocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wctocs_methods);
+}
+
+static XlcConvMethodsRec ctstowcs_methods = {
+ close_converter,
+ ctstowcs,
+ NULL
+};
+
+static XlcConv
+open_ctstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &ctstowcs_methods);
+}
+
+static XlcConvMethodsRec cstowcs_methods = {
+ close_converter,
+ cstowcs,
+ NULL
+};
+
+static XlcConv
+open_cstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &cstowcs_methods);
+}
+
+static XlcConvMethodsRec strtowcs_methods = {
+ close_converter,
+ strtowcs,
+ NULL
+};
+
+static XlcConv
+open_strtowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &strtowcs_methods);
+}
+
+/* -------------------------------------------------------------------------- */
+/* Loader */
+/* -------------------------------------------------------------------------- */
+
+XLCd
+_XlcGenericLoader(
+ const char *name)
+{
+ XLCd lcd;
+#ifdef STDCVT
+ XLCdGenericPart *gen;
+#endif
+
+ lcd = _XlcCreateLC(name, _XlcGenericMethods);
+
+ if (lcd == NULL)
+ return lcd;
+
+ default_GL_charset = _XlcGetCharSet("ISO8859-1:GL");
+ default_GR_charset = _XlcGetCharSet("ISO8859-1:GR");
+
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts);
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNString, open_mbstostr);
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
+ _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs);
+ _XlcSetConverter(lcd, XlcNString, lcd, XlcNMultiByte, open_strtombs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
+
+#ifdef STDCVT
+ gen = XLC_GENERIC_PART(lcd);
+
+ if (gen->use_stdc_env != True) {
+#endif
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_wcstostr);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_wctocs);
+ _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs);
+ _XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_strtowcs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
+#ifdef STDCVT
+ }
+#endif
+
+#ifdef STDCVT
+ if (gen->use_stdc_env == True) {
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_stdc_mbstowcs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_stdc_wcstombs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_stdc_wcstocts);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_stdc_wcstostr);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_stdc_wcstocs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_stdc_wctocs);
+ _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_stdc_ctstowcs);
+ _XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_stdc_strtowcs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_stdc_cstowcs);
+ }
+#endif
+
+ _XlcAddUtf8Converters(lcd);
+
+ return lcd;
+}
diff --git a/libX11/modules/lc/xlocale/lcJis.c b/libX11/modules/lc/xlocale/lcJis.c
index c2ca2f560..551862d9b 100644
--- a/libX11/modules/lc/xlocale/lcJis.c
+++ b/libX11/modules/lc/xlocale/lcJis.c
@@ -1,944 +1,944 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-
-/*
- * A Japanese JIS locale.
- * Supports: all locales with codeset JIS7.
- * How: Provides converters for JIS.
- * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2).
- */
-
-#ifdef X_LOCALE
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "XlcGeneric.h"
-#include <stdio.h>
-
-#if !defined(X_LOCALE)
-#define STDCVT
-#endif
-
-typedef struct _StateRec {
- XLCd lcd;
- XlcCharSet charset;
- XlcCharSet GL_charset;
- XlcCharSet GR_charset;
-} StateRec, *State;
-
-static void
-init_state(
- XlcConv conv)
-{
- State state = (State) conv->state;
- XLCdGenericPart *gen = XLC_GENERIC_PART(state->lcd);
- CodeSet codeset;
-
- codeset = gen->initial_state_GL;
- if (codeset && codeset->charset_list)
- state->GL_charset = *codeset->charset_list;
- codeset = gen->initial_state_GR;
- if (codeset && codeset->charset_list)
- state->GR_charset = *codeset->charset_list;
-
- if (state->GL_charset == NULL)
- if ((codeset = *gen->codeset_list) != NULL)
- state->GL_charset = *codeset->charset_list;
-}
-
-static int
-compare(
- const char *src,
- const char *encoding,
- int length)
-{
- const char *start = src;
-
- while (length-- > 0) {
- if (*src++ != *encoding++)
- return 0;
- if (*encoding == '\0')
- return src - start;
- }
-
- return 0;
-}
-
-static int
-mbtocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
- const char *src;
- char *dst;
- unsigned char *mb_parse_table;
- ParseInfo *parse_list, parse_info;
- XlcCharSet charset;
- int length, number, encoding_len = 0;
- int i;
-
- src = *((const char **) from);
- dst = *((char **) to);
-
- mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
- if (mb_parse_table != NULL) {
- number = mb_parse_table[(unsigned char) *src];
- if (number > 0) {
- parse_list = XLC_GENERIC(lcd, mb_parse_list) + number - 1;
- for ( ; (parse_info = *parse_list) != NULL; parse_list++) {
- encoding_len = compare(src, parse_info->encoding, *from_left);
- if (encoding_len > 0) {
- switch (parse_info->type) {
- case E_SS:
- src += encoding_len;
- charset = *parse_info->codeset->charset_list;
- goto found;
- case E_LSL:
- case E_LSR:
- src += encoding_len;
- charset = *parse_info->codeset->charset_list;
- if (parse_info->type == E_LSL)
- state->GL_charset = charset;
- else
- state->GR_charset = charset;
- length = 0;
- goto end;
- case E_GL:
- charset = state->GL_charset;
- goto found;
- case E_GR:
- charset = state->GR_charset;
- goto found;
- default:
- break;
- }
- }
- }
- }
- }
-
- if ((*src & 0x80) && state->GR_charset)
- charset = state->GR_charset;
- else
- charset = state->GL_charset;
-
-found:
- if (charset == NULL ||
- (num_args == 2 && (XlcCharSet) args[1] != charset))
- return -1;
-
- length = charset->char_size;
- if (length > *from_left - encoding_len)
- return -1;
-
- if (dst) {
- if (length > *to_left)
- return -1;
- if (charset->side == XlcGL) {
- for (i = 0; i < length; i++)
- *dst++ = *src++ & 0x7f;
- } else if (charset->side == XlcGR) {
- for (i = 0; i < length; i++)
- *dst++ = *src++ | 0x80;
- } else {
- for (i = 0; i < length; i++)
- *dst++ = *src++;
- }
- *to = (XPointer) dst;
- *to_left -= length;
- }
-end:
- *from = (XPointer) src;
- *from_left -= encoding_len + length;
- state->charset = charset;
- if (num_args == 1)
- *((XlcCharSet *) args[0]) = charset;
-
- return 0;
-}
-
-static int
-mbstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XlcCharSet charset = NULL;
- XPointer tmp_args[2], save_from = *from;
- int ret, unconv_num = 0, tmp_num = 1;
-
- tmp_args[0] = (XPointer) &charset;
-
- while (*from_left > 0 && *to_left > 0) {
- ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, tmp_num);
- if (ret < 0)
- break;
- unconv_num += ret;
- if (tmp_num == 1 && charset) {
- tmp_args[1] = (XPointer) charset;
- tmp_num = 2;
- }
- }
-
- if (save_from == *from)
- return -1;
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset;
-
- return unconv_num;
-}
-
-static CodeSet
-wc_parse_codeset(
- XLCd lcd,
- const wchar_t *wcstr)
-{
- CodeSet *codeset;
- unsigned long wc_encoding;
- int num;
-
- wc_encoding = *wcstr & XLC_GENERIC(lcd, wc_encode_mask);
- num = XLC_GENERIC(lcd, codeset_num);
- codeset = XLC_GENERIC(lcd, codeset_list);
- while (num-- > 0) {
- if (wc_encoding == (*codeset)->wc_encoding)
- return *codeset;
- codeset++;
- }
-
- return NULL;
-}
-
-static int
-wcstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
- const wchar_t *wcptr;
- char *bufptr;
- wchar_t wch;
- char *tmpptr;
- int length;
- CodeSet codeset;
- unsigned long wc_encoding;
- int wcstr_len, buf_len;
-
- if (from == NULL || *from == NULL)
- return 0;
-
- wcptr = *((const wchar_t **) from);
- bufptr = *((char **) to);
- wcstr_len = *from_left;
- buf_len = *to_left;
-
- codeset = wc_parse_codeset(lcd, wcptr);
- if (codeset == NULL)
- return -1;
- wc_encoding = codeset->wc_encoding;
-
- if (wcstr_len < buf_len / codeset->length)
- buf_len = wcstr_len * codeset->length;
-
- for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) {
- wch = *wcptr;
- if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding)
- break;
- length = codeset->length;
- buf_len -= length;
- bufptr += length;
-
- tmpptr = bufptr - 1;
- if ((*codeset->charset_list)->side == XlcGL) {
- while (length--) {
- *tmpptr-- = (unsigned char) (wch & 0x7f);
- wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
- }
- } else if ((*codeset->charset_list)->side == XlcGR) {
- while (length--) {
- *tmpptr-- = (unsigned char) (wch | 0x80);
- wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
- }
- } else {
- while (length--) {
- *tmpptr-- = (unsigned char) wch;
- wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
- }
- }
- }
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = *codeset->charset_list;
-
- *from_left -= wcptr - *((wchar_t **) from);
- *from = (XPointer) wcptr;
-
- *to_left -= bufptr - *((char **) to);
- *to = bufptr;
-
- return 0;
-}
-
-static CodeSet
-GetCodeSetFromCharSet(
- XLCd lcd,
- XlcCharSet charset)
-{
- CodeSet *codeset = XLC_GENERIC(lcd, codeset_list);
- XlcCharSet *charset_list;
- int codeset_num, num_charsets;
-
- codeset_num = XLC_GENERIC(lcd, codeset_num);
-
- for ( ; codeset_num-- > 0; codeset++) {
- num_charsets = (*codeset)->num_charsets;
- charset_list = (*codeset)->charset_list;
-
- for ( ; num_charsets-- > 0; charset_list++)
- if (*charset_list == charset)
- return *codeset;
- }
-
- return (CodeSet) NULL;
-}
-
-static int
-cstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- const char *csptr;
- char *bufptr;
- int csstr_len;
- int buf_len;
- int num, encoding_len = 0;
- CodeSet codeset;
- XlcCharSet charset;
- EncodingType type;
- int cvt_length;
-
- csptr = *((const char **) from);
- bufptr = *((char **) to);
- csstr_len = *from_left;
- buf_len = *to_left;
-
- if (num_args < 1)
- return -1;
-
- charset = (XlcCharSet) args[0];
-
- codeset = GetCodeSetFromCharSet(state->lcd, charset);
- if (codeset == NULL)
- return -1;
-
- cvt_length = 0;
- if (codeset->parse_info) {
- switch (type = codeset->parse_info->type) {
- case E_SS:
- encoding_len = strlen(codeset->parse_info->encoding);
- break;
- case E_LSL:
- case E_LSR:
- if (type == E_LSL) {
- if (charset == state->GL_charset)
- break;
- } else {
- if (charset == state->GR_charset)
- break;
- }
- encoding_len = strlen(codeset->parse_info->encoding);
- if (encoding_len > buf_len)
- return -1;
- cvt_length += encoding_len;
- if (bufptr) {
- strcpy(bufptr, codeset->parse_info->encoding);
- bufptr += encoding_len;
- }
- buf_len -= encoding_len;
- encoding_len = 0;
- if (type == E_LSL)
- state->GL_charset = charset;
- else
- state->GR_charset = charset;
- break;
- default:
- break;
- }
- }
-
- csstr_len /= codeset->length;
- buf_len /= codeset->length + encoding_len;
- if (csstr_len < buf_len)
- buf_len = csstr_len;
-
- cvt_length += buf_len * (encoding_len + codeset->length);
- if (bufptr) {
- while (buf_len--) {
- if (encoding_len) {
- strcpy(bufptr, codeset->parse_info->encoding);
- bufptr += encoding_len;
- }
- num = codeset->length;
- if (codeset->side == XlcGL) {
- while (num--)
- *bufptr++ = *csptr++ & 0x7f;
- } else if (codeset->side == XlcGR) {
- while (num--)
- *bufptr++ = *csptr++ | 0x80;
- } else {
- while (num--)
- *bufptr++ = *csptr++;
- }
- }
- }
-
- *from_left -= csptr - *((char **) from);
- *from = (XPointer) csptr;
-
- if (bufptr)
- *to = (XPointer) bufptr;
- *to_left -= cvt_length;
-
- return 0;
-}
-
-static int
-cstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
- const char *csptr;
- wchar_t *bufptr;
- int csstr_len;
- int buf_len;
- wchar_t wch;
- unsigned long code_mask, wc_encoding;
- int num, length, wc_shift_bits;
- CodeSet codeset;
-
- csptr = *((const char **) from);
- bufptr = *((wchar_t **) to);
- csstr_len = *from_left;
- buf_len = *to_left;
-
- if (num_args < 1)
- return -1;
-
- codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]);
- if (codeset == NULL)
- return -1;
-
- length = codeset->length;
- csstr_len /= length;
- if (csstr_len < buf_len)
- buf_len = csstr_len;
-
- code_mask = ~XLC_GENERIC(lcd, wc_encode_mask);
- wc_encoding = codeset->wc_encoding;
- wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
-
- *to_left -= buf_len;
-
- if (bufptr) {
- while (buf_len--) {
- wch = (wchar_t) (*csptr++ & 0x7f);
- num = length - 1;
- while (num--)
- wch = (wch << wc_shift_bits) | (*csptr++ & 0x7f);
-
- *bufptr++ = (wch & code_mask) | wc_encoding;
- }
- }
-
- *from_left -= csptr - *((char **) from);
- *from = (XPointer) csptr;
-
- if (bufptr)
- *to = (XPointer) bufptr;
-
- return 0;
-}
-
-
-static void
-close_converter(
- XlcConv conv)
-{
- if (conv->state) {
- Xfree((char *) conv->state);
- }
-
- Xfree((char *) conv);
-}
-
-static XlcConv
-create_conv(
- XLCd lcd,
- XlcConvMethods methods)
-{
- XlcConv conv;
- State state;
-
- conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
- if (conv == NULL)
- return (XlcConv) NULL;
-
- conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
- if (conv->methods == NULL)
- goto err;
- *conv->methods = *methods;
- if (XLC_PUBLIC(lcd, is_state_depend))
- conv->methods->reset = init_state;
-
- conv->state = Xcalloc(1, sizeof(StateRec));
- if (conv->state == NULL)
- goto err;
-
- state = (State) conv->state;
- state->lcd = lcd;
- init_state(conv);
-
- return conv;
-
-err:
- close_converter(conv);
-
- return (XlcConv) NULL;
-}
-
-static XlcConvMethodsRec mbstocs_methods = {
- close_converter,
- mbstocs,
- NULL
-};
-
-static XlcConv
-open_mbstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstocs_methods);
-}
-
-static XlcConvMethodsRec wcstocs_methods = {
- close_converter,
- wcstocs,
- NULL
-};
-
-static XlcConv
-open_wcstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstocs_methods);
-}
-
-static XlcConvMethodsRec mbtocs_methods = {
- close_converter,
- mbtocs,
- NULL
-};
-
-static XlcConv
-open_mbtocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbtocs_methods);
-}
-
-static XlcConvMethodsRec cstombs_methods = {
- close_converter,
- cstombs,
- NULL
-};
-
-static XlcConv
-open_cstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &cstombs_methods);
-}
-
-static XlcConvMethodsRec cstowcs_methods = {
- close_converter,
- cstowcs,
- NULL
-};
-
-static XlcConv
-open_cstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &cstowcs_methods);
-}
-
-#ifdef STDCVT
-static int
-stdc_mbstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const char *src = *((const char **) from);
- wchar_t *dst = *((wchar_t **) to);
- int src_left = *from_left;
- int dst_left = *to_left;
- int length;
-
- while (src_left > 0 && dst_left > 0) {
- length = mbtowc(dst, src, src_left);
- if (length < 0)
- break;
-
- src += length;
- src_left -= length;
- if (dst)
- dst++;
- dst_left--;
-
- if (length == 0) {
- src++;
- src_left--;
- break;
- }
- }
-
- if (*from_left == src_left)
- return -1;
-
- *from = (XPointer) src;
- if (dst)
- *to = (XPointer) dst;
- *from_left = src_left;
- *to_left = dst_left;
-
- return 0;
-}
-
-static int
-stdc_wcstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const wchar_t *src = *((const wchar_t **) from);
- char *dst = *((char **) to);
- int src_left = *from_left;
- int dst_left = *to_left;
- int length;
-
- while (src_left > 0 && dst_left > 0) {
- length = wctomb(dst, *src); /* XXX */
- if (length < 0 || dst_left < length)
- break;
-
- src++;
- src_left--;
- dst += length;
- dst_left -= length;
-
- if (length == 0) {
- dst++;
- dst_left--;
- break;
- }
- }
-
- if (*from_left == src_left)
- return -1;
-
- *from = (XPointer) src;
- *to = (XPointer) dst;
- *from_left = src_left;
- *to_left = dst_left;
-
- return 0;
-}
-
-static int
-stdc_wcstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const wchar_t *src = *((const wchar_t **) from);
- wchar_t wch;
- XlcCharSet charset = NULL;
- XPointer tmp_args[2], tmp_from, save_from = *from;
- char tmp[32];
- int length, ret, src_left = *from_left;
- int unconv_num = 0, tmp_num = 1;
-
- tmp_args[0] = (XPointer) &charset;
-
- while (src_left > 0 && *to_left > 0) {
- if (wch = *src) {
- length = wctomb(tmp, wch);
- } else {
- length = 1;
- *tmp = '\0';
- }
-
- if (length < 0)
- break;
-
- tmp_from = (XPointer) tmp;
- ret = mbtocs(conv, &tmp_from, &length, to, to_left, tmp_args, tmp_num);
- if (ret < 0)
- break;
- unconv_num += ret;
- if (tmp_num == 1 && charset) {
- tmp_args[1] = (XPointer) charset;
- tmp_num = 2;
- }
-
- src++;
- src_left--;
- }
-
- if (save_from == (XPointer) src)
- return -1;
-
- *from = (XPointer) src;
- *from_left = src_left;
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset;
-
- return unconv_num;
-}
-
-#define DefineLocalBuf char local_buf[BUFSIZ]
-#define AllocLocalBuf(length) (length > BUFSIZ ? (char*) Xmalloc(length) : local_buf)
-#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
-
-static int
-stdc_cstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XLCd lcd = ((State) conv->state)->lcd;
- DefineLocalBuf;
- XPointer buf, save_buf;
- int length, left, ret;
-
- left = length = *to_left * XLC_PUBLIC(lcd, mb_cur_max);
- buf = save_buf = (XPointer) AllocLocalBuf(length);
- if (buf == NULL)
- return -1;
-
- ret = cstombs(conv, from, from_left, &buf, &left, args, num_args);
- if (ret < 0)
- goto err;
-
- buf = save_buf;
- length -= left;
- if (stdc_mbstowcs(conv, &buf, &length, to, to_left, args, num_args) < 0)
- ret = -1;
-
-err:
- FreeLocalBuf(save_buf);
-
- return ret;
-}
-
-static XlcConvMethodsRec stdc_mbstowcs_methods = {
- close_converter,
- stdc_mbstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_mbstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_mbstowcs_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstombs_methods = {
- close_converter,
- stdc_wcstombs,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstombs_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstocs_methods = {
- close_converter,
- stdc_wcstocs,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstocs_methods);
-}
-
-static XlcConvMethodsRec stdc_cstowcs_methods = {
- close_converter,
- stdc_cstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_cstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_cstowcs_methods);
-}
-#endif /* STDCVT */
-
-XLCd
-_XlcJisLoader(
- const char *name)
-{
- XLCd lcd;
-#ifdef STDCVT
- XLCdGenericPart *gen;
-#endif
-
- lcd = _XlcCreateLC(name, _XlcGenericMethods);
- if (lcd == NULL)
- return lcd;
-
- if (!XLC_PUBLIC_PART(lcd)->codeset ||
- (_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "JIS7"))) {
- _XlcDestroyLC(lcd);
- return (XLCd) NULL;
- }
-
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
-
-#ifdef STDCVT
- gen = XLC_GENERIC_PART(lcd);
-
- if (gen->use_stdc_env == True) {
- _XlcSetConverter(lcd,XlcNMultiByte,lcd,XlcNWideChar,open_stdc_mbstowcs);
- _XlcSetConverter(lcd,XlcNWideChar,lcd,XlcNMultiByte,open_stdc_wcstombs);
- }
- if (gen->force_convert_to_mb == True) {
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet,open_stdc_wcstocs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar,open_stdc_cstowcs);
- } else {
-#endif
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
-#ifdef STDCVT
- }
-#endif
-
- _XlcAddUtf8Converters(lcd);
-
- return lcd;
-}
-
-#else
-typedef int dummy;
-#endif /* X_LOCALE */
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+
+/*
+ * A Japanese JIS locale.
+ * Supports: all locales with codeset JIS7.
+ * How: Provides converters for JIS.
+ * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2).
+ */
+
+#ifdef X_LOCALE
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "XlcGeneric.h"
+#include <stdio.h>
+
+#if !defined(X_LOCALE)
+#define STDCVT
+#endif
+
+typedef struct _StateRec {
+ XLCd lcd;
+ XlcCharSet charset;
+ XlcCharSet GL_charset;
+ XlcCharSet GR_charset;
+} StateRec, *State;
+
+static void
+init_state(
+ XlcConv conv)
+{
+ State state = (State) conv->state;
+ XLCdGenericPart *gen = XLC_GENERIC_PART(state->lcd);
+ CodeSet codeset;
+
+ codeset = gen->initial_state_GL;
+ if (codeset && codeset->charset_list)
+ state->GL_charset = *codeset->charset_list;
+ codeset = gen->initial_state_GR;
+ if (codeset && codeset->charset_list)
+ state->GR_charset = *codeset->charset_list;
+
+ if (state->GL_charset == NULL)
+ if ((codeset = *gen->codeset_list) != NULL)
+ state->GL_charset = *codeset->charset_list;
+}
+
+static int
+compare(
+ const char *src,
+ const char *encoding,
+ int length)
+{
+ const char *start = src;
+
+ while (length-- > 0) {
+ if (*src++ != *encoding++)
+ return 0;
+ if (*encoding == '\0')
+ return src - start;
+ }
+
+ return 0;
+}
+
+static int
+mbtocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+ const char *src;
+ char *dst;
+ unsigned char *mb_parse_table;
+ ParseInfo *parse_list, parse_info;
+ XlcCharSet charset;
+ int length, number, encoding_len = 0;
+ int i;
+
+ src = *((const char **) from);
+ dst = *((char **) to);
+
+ mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
+ if (mb_parse_table != NULL) {
+ number = mb_parse_table[(unsigned char) *src];
+ if (number > 0) {
+ parse_list = XLC_GENERIC(lcd, mb_parse_list) + number - 1;
+ for ( ; (parse_info = *parse_list) != NULL; parse_list++) {
+ encoding_len = compare(src, parse_info->encoding, *from_left);
+ if (encoding_len > 0) {
+ switch (parse_info->type) {
+ case E_SS:
+ src += encoding_len;
+ charset = *parse_info->codeset->charset_list;
+ goto found;
+ case E_LSL:
+ case E_LSR:
+ src += encoding_len;
+ charset = *parse_info->codeset->charset_list;
+ if (parse_info->type == E_LSL)
+ state->GL_charset = charset;
+ else
+ state->GR_charset = charset;
+ length = 0;
+ goto end;
+ case E_GL:
+ charset = state->GL_charset;
+ goto found;
+ case E_GR:
+ charset = state->GR_charset;
+ goto found;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if ((*src & 0x80) && state->GR_charset)
+ charset = state->GR_charset;
+ else
+ charset = state->GL_charset;
+
+found:
+ if (charset == NULL ||
+ (num_args == 2 && (XlcCharSet) args[1] != charset))
+ return -1;
+
+ length = charset->char_size;
+ if (length > *from_left - encoding_len)
+ return -1;
+
+ if (dst) {
+ if (length > *to_left)
+ return -1;
+ if (charset->side == XlcGL) {
+ for (i = 0; i < length; i++)
+ *dst++ = *src++ & 0x7f;
+ } else if (charset->side == XlcGR) {
+ for (i = 0; i < length; i++)
+ *dst++ = *src++ | 0x80;
+ } else {
+ for (i = 0; i < length; i++)
+ *dst++ = *src++;
+ }
+ *to = (XPointer) dst;
+ *to_left -= length;
+ }
+end:
+ *from = (XPointer) src;
+ *from_left -= encoding_len + length;
+ state->charset = charset;
+ if (num_args == 1)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return 0;
+}
+
+static int
+mbstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XlcCharSet charset = NULL;
+ XPointer tmp_args[2], save_from = *from;
+ int ret, unconv_num = 0, tmp_num = 1;
+
+ tmp_args[0] = (XPointer) &charset;
+
+ while (*from_left > 0 && *to_left > 0) {
+ ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, tmp_num);
+ if (ret < 0)
+ break;
+ unconv_num += ret;
+ if (tmp_num == 1 && charset) {
+ tmp_args[1] = (XPointer) charset;
+ tmp_num = 2;
+ }
+ }
+
+ if (save_from == *from)
+ return -1;
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return unconv_num;
+}
+
+static CodeSet
+wc_parse_codeset(
+ XLCd lcd,
+ const wchar_t *wcstr)
+{
+ CodeSet *codeset;
+ unsigned long wc_encoding;
+ int num;
+
+ wc_encoding = *wcstr & XLC_GENERIC(lcd, wc_encode_mask);
+ num = XLC_GENERIC(lcd, codeset_num);
+ codeset = XLC_GENERIC(lcd, codeset_list);
+ while (num-- > 0) {
+ if (wc_encoding == (*codeset)->wc_encoding)
+ return *codeset;
+ codeset++;
+ }
+
+ return NULL;
+}
+
+static int
+wcstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+ const wchar_t *wcptr;
+ char *bufptr;
+ wchar_t wch;
+ char *tmpptr;
+ int length;
+ CodeSet codeset;
+ unsigned long wc_encoding;
+ int wcstr_len, buf_len;
+
+ if (from == NULL || *from == NULL)
+ return 0;
+
+ wcptr = *((const wchar_t **) from);
+ bufptr = *((char **) to);
+ wcstr_len = *from_left;
+ buf_len = *to_left;
+
+ codeset = wc_parse_codeset(lcd, wcptr);
+ if (codeset == NULL)
+ return -1;
+ wc_encoding = codeset->wc_encoding;
+
+ if (wcstr_len < buf_len / codeset->length)
+ buf_len = wcstr_len * codeset->length;
+
+ for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) {
+ wch = *wcptr;
+ if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding)
+ break;
+ length = codeset->length;
+ buf_len -= length;
+ bufptr += length;
+
+ tmpptr = bufptr - 1;
+ if ((*codeset->charset_list)->side == XlcGL) {
+ while (length--) {
+ *tmpptr-- = (unsigned char) (wch & 0x7f);
+ wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
+ }
+ } else if ((*codeset->charset_list)->side == XlcGR) {
+ while (length--) {
+ *tmpptr-- = (unsigned char) (wch | 0x80);
+ wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
+ }
+ } else {
+ while (length--) {
+ *tmpptr-- = (unsigned char) wch;
+ wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
+ }
+ }
+ }
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = *codeset->charset_list;
+
+ *from_left -= wcptr - *((wchar_t **) from);
+ *from = (XPointer) wcptr;
+
+ *to_left -= bufptr - *((char **) to);
+ *to = bufptr;
+
+ return 0;
+}
+
+static CodeSet
+GetCodeSetFromCharSet(
+ XLCd lcd,
+ XlcCharSet charset)
+{
+ CodeSet *codeset = XLC_GENERIC(lcd, codeset_list);
+ XlcCharSet *charset_list;
+ int codeset_num, num_charsets;
+
+ codeset_num = XLC_GENERIC(lcd, codeset_num);
+
+ for ( ; codeset_num-- > 0; codeset++) {
+ num_charsets = (*codeset)->num_charsets;
+ charset_list = (*codeset)->charset_list;
+
+ for ( ; num_charsets-- > 0; charset_list++)
+ if (*charset_list == charset)
+ return *codeset;
+ }
+
+ return (CodeSet) NULL;
+}
+
+static int
+cstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ const char *csptr;
+ char *bufptr;
+ int csstr_len;
+ int buf_len;
+ int num, encoding_len = 0;
+ CodeSet codeset;
+ XlcCharSet charset;
+ EncodingType type;
+ int cvt_length;
+
+ csptr = *((const char **) from);
+ bufptr = *((char **) to);
+ csstr_len = *from_left;
+ buf_len = *to_left;
+
+ if (num_args < 1)
+ return -1;
+
+ charset = (XlcCharSet) args[0];
+
+ codeset = GetCodeSetFromCharSet(state->lcd, charset);
+ if (codeset == NULL)
+ return -1;
+
+ cvt_length = 0;
+ if (codeset->parse_info) {
+ switch (type = codeset->parse_info->type) {
+ case E_SS:
+ encoding_len = strlen(codeset->parse_info->encoding);
+ break;
+ case E_LSL:
+ case E_LSR:
+ if (type == E_LSL) {
+ if (charset == state->GL_charset)
+ break;
+ } else {
+ if (charset == state->GR_charset)
+ break;
+ }
+ encoding_len = strlen(codeset->parse_info->encoding);
+ if (encoding_len > buf_len)
+ return -1;
+ cvt_length += encoding_len;
+ if (bufptr) {
+ strcpy(bufptr, codeset->parse_info->encoding);
+ bufptr += encoding_len;
+ }
+ buf_len -= encoding_len;
+ encoding_len = 0;
+ if (type == E_LSL)
+ state->GL_charset = charset;
+ else
+ state->GR_charset = charset;
+ break;
+ default:
+ break;
+ }
+ }
+
+ csstr_len /= codeset->length;
+ buf_len /= codeset->length + encoding_len;
+ if (csstr_len < buf_len)
+ buf_len = csstr_len;
+
+ cvt_length += buf_len * (encoding_len + codeset->length);
+ if (bufptr) {
+ while (buf_len--) {
+ if (encoding_len) {
+ strcpy(bufptr, codeset->parse_info->encoding);
+ bufptr += encoding_len;
+ }
+ num = codeset->length;
+ if (codeset->side == XlcGL) {
+ while (num--)
+ *bufptr++ = *csptr++ & 0x7f;
+ } else if (codeset->side == XlcGR) {
+ while (num--)
+ *bufptr++ = *csptr++ | 0x80;
+ } else {
+ while (num--)
+ *bufptr++ = *csptr++;
+ }
+ }
+ }
+
+ *from_left -= csptr - *((char **) from);
+ *from = (XPointer) csptr;
+
+ if (bufptr)
+ *to = (XPointer) bufptr;
+ *to_left -= cvt_length;
+
+ return 0;
+}
+
+static int
+cstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+ const char *csptr;
+ wchar_t *bufptr;
+ int csstr_len;
+ int buf_len;
+ wchar_t wch;
+ unsigned long code_mask, wc_encoding;
+ int num, length, wc_shift_bits;
+ CodeSet codeset;
+
+ csptr = *((const char **) from);
+ bufptr = *((wchar_t **) to);
+ csstr_len = *from_left;
+ buf_len = *to_left;
+
+ if (num_args < 1)
+ return -1;
+
+ codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]);
+ if (codeset == NULL)
+ return -1;
+
+ length = codeset->length;
+ csstr_len /= length;
+ if (csstr_len < buf_len)
+ buf_len = csstr_len;
+
+ code_mask = ~XLC_GENERIC(lcd, wc_encode_mask);
+ wc_encoding = codeset->wc_encoding;
+ wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
+
+ *to_left -= buf_len;
+
+ if (bufptr) {
+ while (buf_len--) {
+ wch = (wchar_t) (*csptr++ & 0x7f);
+ num = length - 1;
+ while (num--)
+ wch = (wch << wc_shift_bits) | (*csptr++ & 0x7f);
+
+ *bufptr++ = (wch & code_mask) | wc_encoding;
+ }
+ }
+
+ *from_left -= csptr - *((char **) from);
+ *from = (XPointer) csptr;
+
+ if (bufptr)
+ *to = (XPointer) bufptr;
+
+ return 0;
+}
+
+
+static void
+close_converter(
+ XlcConv conv)
+{
+ if (conv->state) {
+ Xfree((char *) conv->state);
+ }
+
+ Xfree((char *) conv);
+}
+
+static XlcConv
+create_conv(
+ XLCd lcd,
+ XlcConvMethods methods)
+{
+ XlcConv conv;
+ State state;
+
+ conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
+ if (conv == NULL)
+ return (XlcConv) NULL;
+
+ conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
+ if (conv->methods == NULL)
+ goto err;
+ *conv->methods = *methods;
+ if (XLC_PUBLIC(lcd, is_state_depend))
+ conv->methods->reset = init_state;
+
+ conv->state = Xcalloc(1, sizeof(StateRec));
+ if (conv->state == NULL)
+ goto err;
+
+ state = (State) conv->state;
+ state->lcd = lcd;
+ init_state(conv);
+
+ return conv;
+
+err:
+ close_converter(conv);
+
+ return (XlcConv) NULL;
+}
+
+static XlcConvMethodsRec mbstocs_methods = {
+ close_converter,
+ mbstocs,
+ NULL
+};
+
+static XlcConv
+open_mbstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstocs_methods);
+}
+
+static XlcConvMethodsRec wcstocs_methods = {
+ close_converter,
+ wcstocs,
+ NULL
+};
+
+static XlcConv
+open_wcstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstocs_methods);
+}
+
+static XlcConvMethodsRec mbtocs_methods = {
+ close_converter,
+ mbtocs,
+ NULL
+};
+
+static XlcConv
+open_mbtocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbtocs_methods);
+}
+
+static XlcConvMethodsRec cstombs_methods = {
+ close_converter,
+ cstombs,
+ NULL
+};
+
+static XlcConv
+open_cstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &cstombs_methods);
+}
+
+static XlcConvMethodsRec cstowcs_methods = {
+ close_converter,
+ cstowcs,
+ NULL
+};
+
+static XlcConv
+open_cstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &cstowcs_methods);
+}
+
+#ifdef STDCVT
+static int
+stdc_mbstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const char *src = *((const char **) from);
+ wchar_t *dst = *((wchar_t **) to);
+ int src_left = *from_left;
+ int dst_left = *to_left;
+ int length;
+
+ while (src_left > 0 && dst_left > 0) {
+ length = mbtowc(dst, src, src_left);
+ if (length < 0)
+ break;
+
+ src += length;
+ src_left -= length;
+ if (dst)
+ dst++;
+ dst_left--;
+
+ if (length == 0) {
+ src++;
+ src_left--;
+ break;
+ }
+ }
+
+ if (*from_left == src_left)
+ return -1;
+
+ *from = (XPointer) src;
+ if (dst)
+ *to = (XPointer) dst;
+ *from_left = src_left;
+ *to_left = dst_left;
+
+ return 0;
+}
+
+static int
+stdc_wcstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const wchar_t *src = *((const wchar_t **) from);
+ char *dst = *((char **) to);
+ int src_left = *from_left;
+ int dst_left = *to_left;
+ int length;
+
+ while (src_left > 0 && dst_left > 0) {
+ length = wctomb(dst, *src); /* XXX */
+ if (length < 0 || dst_left < length)
+ break;
+
+ src++;
+ src_left--;
+ dst += length;
+ dst_left -= length;
+
+ if (length == 0) {
+ dst++;
+ dst_left--;
+ break;
+ }
+ }
+
+ if (*from_left == src_left)
+ return -1;
+
+ *from = (XPointer) src;
+ *to = (XPointer) dst;
+ *from_left = src_left;
+ *to_left = dst_left;
+
+ return 0;
+}
+
+static int
+stdc_wcstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const wchar_t *src = *((const wchar_t **) from);
+ wchar_t wch;
+ XlcCharSet charset = NULL;
+ XPointer tmp_args[2], tmp_from, save_from = *from;
+ char tmp[32];
+ int length, ret, src_left = *from_left;
+ int unconv_num = 0, tmp_num = 1;
+
+ tmp_args[0] = (XPointer) &charset;
+
+ while (src_left > 0 && *to_left > 0) {
+ if (wch = *src) {
+ length = wctomb(tmp, wch);
+ } else {
+ length = 1;
+ *tmp = '\0';
+ }
+
+ if (length < 0)
+ break;
+
+ tmp_from = (XPointer) tmp;
+ ret = mbtocs(conv, &tmp_from, &length, to, to_left, tmp_args, tmp_num);
+ if (ret < 0)
+ break;
+ unconv_num += ret;
+ if (tmp_num == 1 && charset) {
+ tmp_args[1] = (XPointer) charset;
+ tmp_num = 2;
+ }
+
+ src++;
+ src_left--;
+ }
+
+ if (save_from == (XPointer) src)
+ return -1;
+
+ *from = (XPointer) src;
+ *from_left = src_left;
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return unconv_num;
+}
+
+#define DefineLocalBuf char local_buf[BUFSIZ]
+#define AllocLocalBuf(length) (length > BUFSIZ ? (char*) Xmalloc(length) : local_buf)
+#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
+
+static int
+stdc_cstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XLCd lcd = ((State) conv->state)->lcd;
+ DefineLocalBuf;
+ XPointer buf, save_buf;
+ int length, left, ret;
+
+ left = length = *to_left * XLC_PUBLIC(lcd, mb_cur_max);
+ buf = save_buf = (XPointer) AllocLocalBuf(length);
+ if (buf == NULL)
+ return -1;
+
+ ret = cstombs(conv, from, from_left, &buf, &left, args, num_args);
+ if (ret < 0)
+ goto err;
+
+ buf = save_buf;
+ length -= left;
+ if (stdc_mbstowcs(conv, &buf, &length, to, to_left, args, num_args) < 0)
+ ret = -1;
+
+err:
+ FreeLocalBuf(save_buf);
+
+ return ret;
+}
+
+static XlcConvMethodsRec stdc_mbstowcs_methods = {
+ close_converter,
+ stdc_mbstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_mbstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_mbstowcs_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstombs_methods = {
+ close_converter,
+ stdc_wcstombs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstombs_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstocs_methods = {
+ close_converter,
+ stdc_wcstocs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstocs_methods);
+}
+
+static XlcConvMethodsRec stdc_cstowcs_methods = {
+ close_converter,
+ stdc_cstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_cstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_cstowcs_methods);
+}
+#endif /* STDCVT */
+
+XLCd
+_XlcJisLoader(
+ const char *name)
+{
+ XLCd lcd;
+#ifdef STDCVT
+ XLCdGenericPart *gen;
+#endif
+
+ lcd = _XlcCreateLC(name, _XlcGenericMethods);
+ if (lcd == NULL)
+ return lcd;
+
+ if (!XLC_PUBLIC_PART(lcd)->codeset ||
+ (_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "JIS7"))) {
+ _XlcDestroyLC(lcd);
+ return (XLCd) NULL;
+ }
+
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
+
+#ifdef STDCVT
+ gen = XLC_GENERIC_PART(lcd);
+
+ if (gen->use_stdc_env == True) {
+ _XlcSetConverter(lcd,XlcNMultiByte,lcd,XlcNWideChar,open_stdc_mbstowcs);
+ _XlcSetConverter(lcd,XlcNWideChar,lcd,XlcNMultiByte,open_stdc_wcstombs);
+ }
+ if (gen->force_convert_to_mb == True) {
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet,open_stdc_wcstocs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar,open_stdc_cstowcs);
+ } else {
+#endif
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
+#ifdef STDCVT
+ }
+#endif
+
+ _XlcAddUtf8Converters(lcd);
+
+ return lcd;
+}
+
+#else
+typedef int dummy;
+#endif /* X_LOCALE */
diff --git a/libX11/modules/om/generic/omGeneric.c b/libX11/modules/om/generic/omGeneric.c
index 9f060cd5e..d34928784 100644
--- a/libX11/modules/om/generic/omGeneric.c
+++ b/libX11/modules/om/generic/omGeneric.c
@@ -1,2170 +1,2170 @@
-/* #define FONTDEBUG */
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-/*
- * Copyright 1995 by FUJITSU LIMITED
- * This is source code modified by FUJITSU LIMITED under the Joint
- * Development Agreement for the CDE/Motif PST.
- *
- * Modifier: Takanori Tateno FUJITSU LIMITED
- *
- */
-
-/*
- * Fixed the algorithms in parse_fontname() and parse_fontdata()
- * to improve the logic for determining which font should be
- * returned for a given CharSet. We even added some comments
- * so that you can figure out what in the heck we're doing. We
- * realize this is a departure from the norm, but hey, we're
- * rebels! :-) :-)
- *
- * Modifiers: Jeff Walls, Paul Anderson: HEWLETT-PACKARD
- */
-/*
- * Cleaned up mess, removed some blabla
- * Egbert Eich, SuSE Linux AG
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "XomGeneric.h"
-#include "XlcGeneric.h"
-#include <X11/Xos.h>
-#include <X11/Xatom.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-
-#define MAXFONTS 100
-#define PIXEL_SIZE_FIELD 7
-#define POINT_SIZE_FIELD 8
-#define CHARSET_ENCODING_FIELD 14
-#define XLFD_MAX_LEN 255
-
-#if 0
-extern int _XmbDefaultTextEscapement(), _XwcDefaultTextEscapement(),
- _Xutf8DefaultTextEscapement();
-extern int _XmbDefaultTextExtents(), _XwcDefaultTextExtents(),
- _Xutf8DefaultTextExtents();
-extern Status _XmbDefaultTextPerCharExtents(), _XwcDefaultTextPerCharExtents(),
- _Xutf8DefaultTextPerCharExtents();
-extern int _XmbDefaultDrawString(), _XwcDefaultDrawString(),
- _Xutf8DefaultDrawString();
-extern void _XmbDefaultDrawImageString(), _XwcDefaultDrawImageString(),
- _Xutf8DefaultDrawImageString();
-
-extern int _XmbGenericTextEscapement(), _XwcGenericTextEscapement(),
- _Xutf8GenericTextEscapement();
-extern int _XmbGenericTextExtents(), _XwcGenericTextExtents(),
- _Xutf8GenericTextExtents();
-extern Status _XmbGenericTextPerCharExtents(), _XwcGenericTextPerCharExtents(),
- _Xutf8GenericTextPerCharExtents();
-extern int _XmbGenericDrawString(), _XwcGenericDrawString(),
- _Xutf8GenericDrawString();
-extern void _XmbGenericDrawImageString(), _XwcGenericDrawImageString(),
- _Xutf8GenericDrawImageString();
-
-extern void _XlcDbg_printValue (const char *str, char **value, int num);
-#endif
-
-/* For VW/UDC start */
-
-static FontData
-init_fontdata(
- FontData font_data,
- int font_data_count)
-{
- FontData fd;
- int i;
-
- fd = (FontData)Xmalloc(sizeof(FontDataRec) * font_data_count);
- if(fd == (FontData) NULL)
- return False;
-
- memset(fd, 0x00, sizeof(FontData) * font_data_count);
- for(i = 0 ; i < font_data_count ; i++)
- fd[i] = font_data[i];
-
- return fd;
-}
-
-static VRotate
-init_vrotate(
- FontData font_data,
- int font_data_count,
- int type,
- CodeRange code_range,
- int code_range_num)
-{
- VRotate vrotate;
- int i;
-
- if(type == VROTATE_NONE)
- return (VRotate)NULL;
-
- vrotate = (VRotate)Xmalloc(sizeof(VRotateRec) * font_data_count);
- if(vrotate == (VRotate) NULL)
- return False;
-
- memset(vrotate, 0x00, sizeof(VRotateRec) * font_data_count);
- for(i = 0 ; i < font_data_count ; i++) {
- vrotate[i].charset_name = font_data[i].name;
- vrotate[i].side = font_data[i].side;
- if(type == VROTATE_PART) {
- vrotate[i].num_cr = code_range_num;
- vrotate[i].code_range = code_range;
- }
- }
-
- return vrotate;
-}
-
-static Bool
-init_fontset(
- XOC oc)
-{
- XOCGenericPart *gen;
- FontSet font_set;
- OMData data;
- int count;
-
- count = XOM_GENERIC(oc->core.om)->data_num;
- data = XOM_GENERIC(oc->core.om)->data;
-
- font_set = (FontSet) Xmalloc(sizeof(FontSetRec) * count);
- if (font_set == NULL)
- return False;
- memset((char *) font_set, 0x00, sizeof(FontSetRec) * count);
-
- gen = XOC_GENERIC(oc);
- gen->font_set_num = count;
- gen->font_set = font_set;
-
- for ( ; count-- > 0; data++, font_set++) {
- font_set->charset_count = data->charset_count;
- font_set->charset_list = data->charset_list;
-
- if((font_set->font_data = init_fontdata(data->font_data,
- data->font_data_count)) == NULL)
- goto err;
- font_set->font_data_count = data->font_data_count;
- if((font_set->substitute = init_fontdata(data->substitute,
- data->substitute_num)) == NULL)
- goto err;
- font_set->substitute_num = data->substitute_num;
- if((font_set->vmap = init_fontdata(data->vmap,
- data->vmap_num)) == NULL)
- goto err;
- font_set->vmap_num = data->vmap_num;
-
- if(data->vrotate_type != VROTATE_NONE) {
- /* A vrotate member is specified primary font data */
- /* as initial value. */
- if((font_set->vrotate = init_vrotate(data->font_data,
- data->font_data_count,
- data->vrotate_type,
- data->vrotate,
- data->vrotate_num)) == NULL)
- goto err;
- font_set->vrotate_num = data->font_data_count;
- }
- }
- return True;
-
-err:
- if(font_set->font_data)
- Xfree(font_set->font_data);
- if(font_set->substitute)
- Xfree(font_set->substitute);
- if(font_set->vmap)
- Xfree(font_set->vmap);
- if(font_set->vrotate)
- Xfree(font_set->vrotate);
- if(font_set)
- Xfree(font_set);
- gen->font_set = (FontSet) NULL;
- gen->font_set_num = 0;
- return False;
-}
-
-/* For VW/UDC end */
-
-static char *
-get_prop_name(
- Display *dpy,
- XFontStruct *fs)
-{
- unsigned long fp;
-
- if (XGetFontProperty(fs, XA_FONT, &fp))
- return XGetAtomName(dpy, fp);
-
- return (char *) NULL;
-}
-
-/* For VW/UDC start */
-
-static Bool
-load_fontdata(
- XOC oc,
- FontData font_data,
- int font_data_num)
-{
- Display *dpy = oc->core.om->core.display;
- FontData fd = font_data;
-
- if(font_data == NULL) return(True);
- for( ; font_data_num-- ; fd++) {
- if(fd->xlfd_name != (char *) NULL && fd->font == NULL) {
- fd->font = XLoadQueryFont(dpy, fd->xlfd_name);
- if (fd->font == NULL){
- return False;
- }
- }
- }
- return True;
-}
-
-static Bool
-load_fontset_data(
- XOC oc,
- FontSet font_set)
-{
- Display *dpy = oc->core.om->core.display;
-
- if(font_set->font_name == (char *)NULL) return False ;
-
- /* If font_set->font is not NULL, it contains the *best*
- * match font for this FontSet.
- * -- jjw/pma (HP)
- */
- if(font_set->font == NULL) {
- font_set->font = XLoadQueryFont(dpy, font_set->font_name);
- if (font_set->font == NULL){
- return False;
- }
- }
- return True;
-}
-
-static Bool
-load_font(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- int num = gen->font_set_num;
-
- for ( ; num-- > 0; font_set++) {
- if (font_set->font_name == NULL)
- continue;
-
- if (load_fontset_data (oc, font_set) != True)
- return False;
-#ifndef TESTVERSION
- if(load_fontdata(oc, font_set->font_data,
- font_set->font_data_count) != True)
- return False;
-
- if(load_fontdata(oc, font_set->substitute,
- font_set->substitute_num) != True)
- return False;
-#endif
-
-/* Add 1996.05.20 */
- if( oc->core.orientation == XOMOrientation_TTB_RTL ||
- oc->core.orientation == XOMOrientation_TTB_LTR ){
- if (font_set->vpart_initialize == 0) {
- load_fontdata(oc, font_set->vmap, font_set->vmap_num);
- load_fontdata(oc, (FontData) font_set->vrotate,
- font_set->vrotate_num);
- font_set->vpart_initialize = 1;
- }
- }
-
- if (font_set->font->min_byte1 || font_set->font->max_byte1)
- font_set->is_xchar2b = True;
- else
- font_set->is_xchar2b = False;
- }
-
- return True;
-}
-
-/* For VW/UDC end */
-
-static Bool
-load_font_info(
- XOC oc)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- char **fn_list;
- int fn_num, num = gen->font_set_num;
-
- for ( ; num-- > 0; font_set++) {
- if (font_set->font_name == NULL)
- continue;
-
- if (font_set->info == NULL) {
- fn_list = XListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num,
- &font_set->info);
- if (font_set->info == NULL)
- return False;
-
- XFreeFontNames(fn_list);
- }
- }
-
- return True;
-}
-
-/* For Vertical Writing start */
-
-static void
-check_fontset_extents(
- XCharStruct *overall,
- int *logical_ascent,
- int *logical_descent,
- XFontStruct *font)
-{
- overall->lbearing = min(overall->lbearing, font->min_bounds.lbearing);
- overall->rbearing = max(overall->rbearing, font->max_bounds.rbearing);
- overall->ascent = max(overall->ascent, font->max_bounds.ascent);
- overall->descent = max(overall->descent, font->max_bounds.descent);
- overall->width = max(overall->width, font->max_bounds.width);
- *logical_ascent = max(*logical_ascent, font->ascent);
- *logical_descent = max(*logical_descent, font->descent);
-}
-
-/* For Vertical Writing end */
-
-static void
-set_fontset_extents(
- XOC oc)
-{
- XRectangle *ink = &oc->core.font_set_extents.max_ink_extent;
- XRectangle *logical = &oc->core.font_set_extents.max_logical_extent;
- XFontStruct **font_list, *font;
- XCharStruct overall;
- int logical_ascent, logical_descent;
- int num = oc->core.font_info.num_font;
-
- font_list = oc->core.font_info.font_struct_list;
- font = *font_list++;
- overall = font->max_bounds;
- overall.lbearing = font->min_bounds.lbearing;
- logical_ascent = font->ascent;
- logical_descent = font->descent;
-
- /* For Vertical Writing start */
-
- while (--num > 0) {
- font = *font_list++;
- check_fontset_extents(&overall, &logical_ascent, &logical_descent,
- font);
- }
-
- {
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- FontData font_data;
- int font_set_num = gen->font_set_num;
- int font_data_count;
-
- for( ; font_set_num-- ; font_set++) {
- if(font_set->vmap_num > 0) {
- font_data = font_set->vmap;
- font_data_count = font_set->vmap_num;
- for( ; font_data_count-- ; font_data++) {
- if(font_data->font != NULL) {
- check_fontset_extents(&overall, &logical_ascent,
- &logical_descent,
- font_data->font);
- }
- }
- }
-
- if(font_set->vrotate_num > 0 && font_set->vrotate != NULL) {
- font_data = (FontData) font_set->vrotate;
- font_data_count = font_set->vrotate_num;
- for( ; font_data_count-- ; font_data++) {
- if(font_data->font != NULL) {
- check_fontset_extents(&overall, &logical_ascent,
- &logical_descent,
- font_data->font);
- }
- }
- }
- }
- }
-
- /* For Vertical Writing start */
-
- ink->x = overall.lbearing;
- ink->y = -(overall.ascent);
- ink->width = overall.rbearing - overall.lbearing;
- ink->height = overall.ascent + overall.descent;
-
- logical->x = 0;
- logical->y = -(logical_ascent);
- logical->width = overall.width;
- logical->height = logical_ascent + logical_descent;
-}
-
-static Bool
-init_core_part(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- int font_set_num;
- XFontStruct **font_struct_list;
- char **font_name_list, *font_name_buf;
- int count, length;
-
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- count = length = 0;
-
- for ( ; font_set_num-- > 0; font_set++) {
- if (font_set->font_name == NULL)
- continue;
-
- length += strlen(font_set->font_name) + 1;
-
- count++;
- }
- if (count == 0)
- return False;
-
- font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *) * count);
- if (font_struct_list == NULL)
- return False;
-
- font_name_list = (char **) Xmalloc(sizeof(char *) * count);
- if (font_name_list == NULL)
- goto err;
-
- font_name_buf = (char *) Xmalloc(length);
- if (font_name_buf == NULL)
- goto err;
-
- oc->core.font_info.num_font = count;
- oc->core.font_info.font_name_list = font_name_list;
- oc->core.font_info.font_struct_list = font_struct_list;
-
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
-
- for (count = 0; font_set_num-- > 0; font_set++) {
- if (font_set->font_name == NULL)
- continue;
-
- font_set->id = count;
- if (font_set->font)
- *font_struct_list++ = font_set->font;
- else
- *font_struct_list++ = font_set->info;
- strcpy(font_name_buf, font_set->font_name);
- Xfree(font_set->font_name);
- *font_name_list++ = font_set->font_name = font_name_buf;
- font_name_buf += strlen(font_name_buf) + 1;
-
- count++;
- }
-
- set_fontset_extents(oc);
-
- return True;
-
-err:
- if (font_name_list)
- Xfree(font_name_list);
- Xfree(font_struct_list);
-
- return False;
-}
-
-static char *
-get_font_name(
- XOC oc,
- char *pattern)
-{
- char **list, *name;
- int count = 0;
-
- list = XListFonts(oc->core.om->core.display, pattern, 1, &count);
- if (list == NULL)
- return NULL;
-
- name = strdup(*list);
-
- XFreeFontNames(list);
-
- return name;
-}
-
-/* For VW/UDC start*/
-
-static char *
-get_rotate_fontname(
- char *font_name)
-{
- char *pattern = NULL, *ptr = NULL;
- char *fields[CHARSET_ENCODING_FIELD];
- char str_pixel[32], str_point[4];
- char *rotate_font_ptr = NULL;
- int pixel_size = 0;
- int field_num = 0, len = 0;
-
- if(font_name == (char *) NULL || (len = strlen(font_name)) <= 0
- || len > XLFD_MAX_LEN)
- return NULL;
-
- pattern = strdup(font_name);
- if(!pattern)
- return NULL;
-
- memset(fields, 0, sizeof(char *) * 14);
- ptr = pattern;
- while(isspace(*ptr)) {
- ptr++;
- }
- if(*ptr == '-')
- ptr++;
-
- for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD && ptr && *ptr ;
- ptr++, field_num++) {
- fields[field_num] = ptr;
-
- if((ptr = strchr(ptr, '-'))) {
- *ptr = '\0';
- } else {
- field_num++; /* Count last field */
- break;
- }
- }
-
- if(field_num < CHARSET_ENCODING_FIELD)
- goto free_pattern;
-
- /* Pixel Size field : fields[6] */
- for(ptr = fields[PIXEL_SIZE_FIELD - 1] ; ptr && *ptr; ptr++) {
- if(!isdigit(*ptr)) {
- if(*ptr == '['){ /* 960730 */
- strcpy(pattern, font_name);
- return(pattern);
- }
- goto free_pattern;
- }
- }
- pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]);
- sprintf(str_pixel, "[ 0 ~%d %d 0 ]", pixel_size, pixel_size);
- fields[6] = str_pixel;
-
- /* Point Size field : fields[7] */
- strcpy(str_point, "*");
- fields[POINT_SIZE_FIELD - 1] = str_point;
-
- len = 0;
- for (field_num = 0; field_num < CHARSET_ENCODING_FIELD &&
- fields[field_num]; field_num++) {
- len += 1 + strlen(fields[field_num]);
- }
-
- /* Max XLFD length is 255 */
- if (len > XLFD_MAX_LEN)
- goto free_pattern;
-
- rotate_font_ptr = (char *)Xmalloc(len + 1);
- if(!rotate_font_ptr)
- goto free_pattern;
-
- rotate_font_ptr[0] = '\0';
-
- for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD &&
- fields[field_num] ; field_num++) {
- strcat(rotate_font_ptr, "-");
- strcat(rotate_font_ptr, fields[field_num]);
- }
-
-free_pattern:
- Xfree(pattern);
-
- return rotate_font_ptr;
-}
-
-static Bool
-is_match_charset(
- FontData font_data,
- char *font_name)
-{
- char *last;
- int length, name_len;
-
- name_len = strlen(font_name);
- last = font_name + name_len;
-
- length = strlen(font_data->name);
- if (length > name_len)
- return False;
-
- if (_XlcCompareISOLatin1(last - length, font_data->name) == 0)
- return True;
-
- return False;
-}
-
-#if 0
-static char *
-get_font_name_from_list(
- XOC oc,
- char *pattern,
- FontData font_data)
-{
- char **list, *name = (char *)NULL, *fname;
- int count = 0, i;
-
- list = XListFonts(oc->core.om->core.display, pattern, MAXFONTS, &count);
- if (list == NULL)
- return NULL;
-
- for (i = 0; i < count; i++) {
- fname = list[i];
- if(is_match_charset(font_data, fname) == True) {
- name = strdup(fname);
- break;
- }
- }
-
- XFreeFontNames(list);
-
- return name;
-}
-#endif
-
-static int
-parse_all_name(
- XOC oc,
- FontData font_data,
- char *pattern)
-{
-
-#ifdef OLDCODE
- if(is_match_charset(font_data, pattern) != True)
- return False;
-
- font_data->xlfd_name = strdup(pattern);
- if(font_data->xlfd_name == NULL)
- return (-1);
-
- return True;
-#else /* OLDCODE */
- Display *dpy = oc->core.om->core.display;
- char **fn_list = NULL, *prop_fname = NULL;
- int list_num;
- XFontStruct *fs_list;
- if(is_match_charset(font_data, pattern) != True) {
- /*
- * pattern should not contain any wildcard (execpt '?')
- * this was probably added to make this case insensitive.
- */
- if ((fn_list = XListFontsWithInfo(dpy, pattern,
- MAXFONTS,
- &list_num, &fs_list)) == NULL) {
- return False;
- }
- /* shouldn't we loop here ? */
- else if ((prop_fname = get_prop_name(dpy, fs_list)) == NULL) {
- XFreeFontInfo(fn_list, fs_list, list_num);
- return False;
- }
- else if ((is_match_charset(font_data, prop_fname) != True)) {
- XFree(prop_fname);
- XFreeFontInfo(fn_list, fs_list, list_num);
- return False;
- }
- else {
- font_data->xlfd_name = prop_fname;
- XFreeFontInfo(fn_list, fs_list, list_num);
- return True;
- }
- }
-
- font_data->xlfd_name = strdup(pattern);
- if(font_data->xlfd_name == NULL)
- return (-1);
-
- return True;
-#endif /* OLDCODE */
-}
-
-static int
-parse_omit_name(
- XOC oc,
- FontData font_data,
- char *pattern)
-{
- char* last = (char *) NULL;
- char* base_name;
- char buf[XLFD_MAX_LEN + 1];
- int length = 0;
- int num_fields;
- /*
- * If the font specified by "pattern" is expandable to be
- * a member of "font_data"'s FontSet, we've found a match.
- */
- if(is_match_charset(font_data, pattern) == True) {
- if ((font_data->xlfd_name = get_font_name(oc, pattern)) != NULL) {
- return True;
- }
- }
-
- length = strlen (pattern);
-
- if (length > XLFD_MAX_LEN)
- return -1;
-
- strcpy(buf, pattern);
- last = buf + length - 1;
-
- /* Replace the original encoding with the encoding for this FontSet. */
-
- /* Figure out how many fields have been specified in this xlfd. */
- for (num_fields = 0, base_name = buf; *base_name != '\0'; base_name++)
- if (*base_name == '-') num_fields++;
-
- switch (num_fields) {
- case 12:
- /* This is the best way to have specifed the fontset. In this
- * case, there is no original encoding. E.g.,
- * -*-*-*-*-*-*-14-*-*-*-*-*
- * To this, we'll append a dash:
- * -*-*-*-*-*-*-14-*-*-*-*-*-
- * then append the encoding to get:
- * -*-*-*-*-*-*-14-*-*-*-*-*-JISX0208.1990-0
- */
- /*
- * Take care of:
- * -*-*-*-*-*-*-14-*-*-*-*-
- */
- if (*(last) == '-')
- *++last = '*';
-
- *++last = '-';
- break;
- case 13:
- /* Got the charset, not the encoding, zap the charset In this
- * case, there is no original encoding, but there is a charset. E.g.,
- * -*-*-*-*-*-*-14-*-*-*-*-*-jisx0212.1990
- * To this, we remove the charset:
- * -*-*-*-*-*-*-14-*-*-*-*-*-
- * then append the new encoding to get:
- * -*-*-*-*-*-*-14-*-*-*-*-*-JISX0208.1990-0
- */
- last = strrchr (buf, '-');
- num_fields = 12;
- break;
- case 14:
- /* Both the charset and the encoding are specified. Get rid
- * of them so that we can append the new charset encoding. E.g.,
- * -*-*-*-*-*-*-14-*-*-*-*-*-jisx0212.1990-0
- * To this, we'll remove the encoding and charset to get:
- * -*-*-*-*-*-*-14-*-*-*-*-*-
- * then append the new encoding to get:
- * -*-*-*-*-*-*-14-*-*-*-*-*-JISX0208.1990-0
- */
- last = strrchr (buf, '-');
- *last = '\0';
- last = strrchr (buf, '-');
- num_fields = 12;
- break;
- default:
- if (*last != '-')
- *++last = '-';
- break;
- }
-
- /* At this point, "last" is pointing to the last "-" in the
- * xlfd, and all xlfd's at this point take a form similar to:
- * -*-*-*-*-*-*-14-*-*-*-*-*-
- * (i.e., no encoding).
- * After the strcpy, we'll end up with something similar to:
- * -*-*-*-*-*-*-14-*-*-*-*-*-JISX0208.1990-0
- *
- * If the modified font is found in the current FontSet,
- * we've found a match.
- */
-
- last++;
-
- if ((last - buf) + strlen(font_data->name) > XLFD_MAX_LEN)
- return -1;
-
- strcpy(last, font_data->name);
- if ((font_data->xlfd_name = get_font_name(oc, buf)) != NULL)
- return True;
-
- /* This may mot be needed anymore as XListFonts() takes care of this */
- while (num_fields < 12) {
- if ((last - buf) > (XLFD_MAX_LEN - 2))
- return -1;
- *last = '*';
- *(last + 1) = '-';
- strcpy(last + 2, font_data->name);
- num_fields++;
- last+=2;
- if ((font_data->xlfd_name = get_font_name(oc, buf)) != NULL)
- return True;
- }
-
-
- return False;
-}
-
-
-typedef enum{C_PRIMARY, C_SUBSTITUTE, C_VMAP, C_VROTATE } ClassType;
-
-static int
-parse_fontdata(
- XOC oc,
- FontSet font_set,
- FontData font_data,
- int font_data_count,
- char **name_list,
- int name_list_count,
- ClassType class,
- FontDataRec *font_data_return)
-{
-
- char **cur_name_list = name_list;
- char *font_name = (char *) NULL;
- char *pattern = (char *) NULL;
- int found_num = 0, ret = 0;
- int count = name_list_count;
-
- if(name_list == NULL || count <= 0) {
- return False;
- }
-
- if(font_data == NULL || font_data_count <= 0) {
- return False;
- }
-
- /* Loop through each font encoding defined in the "font_data" FontSet. */
- for ( ; font_data_count-- > 0; font_data++) {
- Bool is_found = False;
- font_name = (char *) NULL;
- count = name_list_count;
- cur_name_list = name_list;
-
- /*
- * Loop through each font specified by the user
- * in the call to XCreateFontset().
- */
- while (count-- > 0) {
- pattern = *cur_name_list++;
- if (pattern == NULL || *pattern == '\0')
- continue;
-#ifdef FONTDEBUG
- fprintf(stderr,"Font pattern: %s %s\n",
- pattern,font_data->name);
-#endif
-
- /*
- * If the current font is fully specified (i.e., the
- * xlfd contains no wildcards) and the font exists on
- * the X Server, we have a match.
- */
- if (strchr(pattern, '*') == NULL &&
- (font_name = get_font_name(oc, pattern))) {
- /*
- * Find the full xlfd name for this font. If the font is
- * already in xlfd format, it is simply returned. If the
- * font is an alias for another font, the xlfd of the
- * aliased font is returned.
- */
- ret = parse_all_name(oc, font_data, font_name);
- Xfree(font_name);
-
- if (ret == -1) return -1;
- if (ret == False) continue;
- /*
- * Since there was an exact match of a fully-specified font
- * or a font alias, we can return now since the desired font
- * was found for the current font encoding for this FontSet.
- *
- * Previous implementations of this algorithm would
- * not return here. Instead, they continued searching
- * through the font encodings for this FontSet. The side-effect
- * of that behavior is you may return a "substitute" match
- * instead of an "exact" match. We believe there should be a
- * preference on exact matches. Therefore, as soon as we
- * find one, we bail.
- *
- * Also, previous implementations seemed to think it was
- * important to find either a primary or substitute font
- * for each Font encoding in the FontSet before returning an
- * acceptable font. We don't believe this is necessary.
- * All the client cares about is finding a reasonable font
- * for what was passed in. If we find an exact match,
- * there's no reason to look any further.
- *
- * -- jjw/pma (HP)
- */
- if (font_data_return) {
- font_data_return->xlfd_name = strdup(font_data->xlfd_name);
- if (!font_data_return->xlfd_name) return -1;
-
- font_data_return->side = font_data->side;
- }
-#ifdef FONTDEBUG
- fprintf(stderr,"XLFD name: %s\n",font_data->xlfd_name);
-#endif
-
- return True;
- }
- /*
- * If the font name is not fully specified
- * (i.e., it has wildcards), we have more work to do.
- * See the comments in parse_omit_name()
- * for the list of things to do.
- */
- ret = parse_omit_name(oc, font_data, pattern);
-
- if (ret == -1) return -1;
- if (ret == False) continue;
-
- /*
- * A font which matched the wild-carded specification was found.
- * Only update the return data if a font has not yet been found.
- * This maintains the convention that FontSets listed higher in
- * a CodeSet in the Locale Database have higher priority than
- * those FontSets listed lower in the CodeSet. In the following
- * example:
- *
- * fs1 {
- * charset HP-JIS:GR
- * font JISX0208.1990-0:GL;\
- * JISX0208.1990-1:GR;\
- * JISX0208.1983-0:GL;\
- * JISX0208.1983-1:GR
- * }
- *
- * a font found in the JISX0208.1990-0 FontSet will have a
- * higher priority than a font found in the JISX0208.1983-0
- * FontSet.
- */
- if (font_data_return && font_data_return->xlfd_name == NULL) {
-
-#ifdef FONTDEBUG
- fprintf(stderr,"XLFD name: %s\n",font_data->xlfd_name);
-#endif
- font_data_return->xlfd_name = strdup(font_data->xlfd_name);
- if (!font_data_return->xlfd_name) return -1;
-
- font_data_return->side = font_data->side;
- }
-
- found_num++;
- is_found = True;
-
- break;
- }
-
- switch(class) {
- case C_PRIMARY:
- if(is_found == False) {
- /*
- * Did not find a font for the current FontSet. Check the
- * FontSet's "substitute" font for a match. If we find a
- * match, we'll keep searching in hopes of finding an exact
- * match later down the FontSet list.
- *
- * when we return and we have found a font font_data_return
- * contains the first (ie. best) match no matter if this
- * is a C_PRIMARY or a C_SUBSTITUTE font
- */
- ret = parse_fontdata(oc, font_set, font_set->substitute,
- font_set->substitute_num, name_list,
- name_list_count, C_SUBSTITUTE,
- font_data_return);
- if (ret == -1) return -1;
- if (ret == False) continue;
-
- found_num++;
- is_found = True;
- }
-#ifdef TESTVERSION
- else
- return True;
-#endif
- break;
-
- case C_SUBSTITUTE:
- case C_VMAP:
- if(is_found == True)
- return True;
- break;
-
- case C_VROTATE:
- if(is_found == True) {
- char *rotate_name;
-
- if((rotate_name = get_rotate_fontname(font_data->xlfd_name))
- != NULL) {
- Xfree(font_data->xlfd_name);
- font_data->xlfd_name = rotate_name;
-
- return True;
- }
- Xfree(font_data->xlfd_name);
- font_data->xlfd_name = NULL;
- return False;
- }
- break;
- }
- }
-
- if(class == C_PRIMARY && found_num >= 1)
- return True;
-
- return False;
-}
-
-
-static int
-parse_vw(
- XOC oc,
- FontSet font_set,
- char **name_list,
- int count)
-{
- FontData vmap = font_set->vmap;
- VRotate vrotate = font_set->vrotate;
- int vmap_num = font_set->vmap_num;
- int vrotate_num = font_set->vrotate_num;
- int ret = 0, i = 0;
-
- if(vmap_num > 0) {
- if(parse_fontdata(oc, font_set, vmap, vmap_num, name_list,
- count, C_VMAP,NULL) == -1)
- return (-1);
- }
-
- if(vrotate_num > 0) {
- ret = parse_fontdata(oc, font_set, (FontData) vrotate, vrotate_num,
- name_list, count, C_VROTATE, NULL);
- if(ret == -1) {
- return (-1);
- } else if(ret == False) {
- CodeRange code_range;
- int num_cr;
- int sub_num = font_set->substitute_num;
-
- code_range = vrotate[0].code_range; /* ? */
- num_cr = vrotate[0].num_cr; /* ? */
- for(i = 0 ; i < vrotate_num ; i++) {
- if(vrotate[i].xlfd_name)
- Xfree(vrotate[i].xlfd_name);
- }
- Xfree(vrotate);
-
- if(sub_num > 0) {
- vrotate = font_set->vrotate = (VRotate)Xmalloc
- (sizeof(VRotateRec) * sub_num);
- if(font_set->vrotate == (VRotate)NULL)
- return (-1);
- memset(font_set->vrotate, 0x00, sizeof(VRotateRec) * sub_num);
-
- for(i = 0 ; i < sub_num ; i++) {
- vrotate[i].charset_name = font_set->substitute[i].name;
- vrotate[i].side = font_set->substitute[i].side;
- vrotate[i].code_range = code_range;
- vrotate[i].num_cr = num_cr;
- }
- vrotate_num = font_set->vrotate_num = sub_num;
- } else {
- vrotate = font_set->vrotate = (VRotate)NULL;
- }
-
- ret = parse_fontdata(oc, font_set, (FontData) vrotate, vrotate_num,
- name_list, count, C_VROTATE, NULL);
- if(ret == -1)
- return (-1);
- }
- }
-
- return True;
-}
-
-static int
-parse_fontname(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- FontDataRec font_data_return;
- char *base_name, **name_list;
- int font_set_num = 0;
- int found_num = 0;
- int count = 0;
- int ret;
- int i;
-
- name_list = _XParseBaseFontNameList(oc->core.base_name_list, &count);
- if (name_list == NULL)
- return -1;
-
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
-
- /* Loop through all of the CharSets defined in the Locale
- * database for the current Locale.
- */
- for( ; font_set_num-- > 0 ; font_set++) {
- if(font_set->font_name)
- continue;
-
- if(font_set->font_data_count > 0) {
-
- /*
- * If there are a non-zero number of FontSets defined
- * for this CharSet.
- * Try to find a font for this CharSet. If we find an
- * acceptable font, we save the information for return
- * to the client. If we do not find an acceptable font,
- * a "missing_charset" will be reported to the client
- * for this CharSet.
- */
- font_data_return. xlfd_name = NULL;
- font_data_return.side = XlcUnknown;
-
- ret = parse_fontdata(oc, font_set, font_set->font_data,
- font_set->font_data_count,
- name_list, count, C_PRIMARY,
- &font_data_return);
- if(ret == -1) {
- goto err;
- } else if(ret == True) {
- /*
- * We can't just loop thru fontset->font_data to
- * find the first (ie. best) match: parse_fontdata
- * will try a substitute font if no primary one could
- * be matched. It returns the required information in
- * font_data_return.
- */
- font_set->font_name = strdup(font_data_return.xlfd_name);
- if(font_set->font_name == (char *) NULL)
- goto err;
-
- font_set->side = font_data_return.side;
-
- Xfree (font_data_return.xlfd_name);
- font_data_return.xlfd_name = NULL;
-
- if(parse_vw(oc, font_set, name_list, count) == -1)
- goto err;
- found_num++;
- }
-
- } else if(font_set->substitute_num > 0) {
- /*
- * If there are no FontSets defined for this
- * CharSet. We can only find "substitute" fonts.
- */
- ret = parse_fontdata(oc, font_set, font_set->substitute,
- font_set->substitute_num,
- name_list, count, C_SUBSTITUTE, NULL);
- if(ret == -1) {
- goto err;
- } else if(ret == True) {
- for(i=0;i<font_set->substitute_num;i++){
- if(font_set->substitute[i].xlfd_name != NULL){
- break;
- }
- }
- font_set->font_name = strdup(font_set->substitute[i].xlfd_name);
- if(font_set->font_name == (char *) NULL)
- goto err;
-
- font_set->side = font_set->substitute[i].side;
- if(parse_vw(oc, font_set, name_list, count) == -1)
- goto err;
-
- found_num++;
- }
- }
- }
-
- base_name = strdup(oc->core.base_name_list);
- if (base_name == NULL)
- goto err;
-
- oc->core.base_name_list = base_name;
-
- XFreeStringList(name_list);
-
- return found_num;
-
-err:
- XFreeStringList(name_list);
- /* Prevent this from being freed twice */
- oc->core.base_name_list = NULL;
-
- return -1;
-}
-
-/* For VW/UDC end*/
-
-static Bool
-set_missing_list(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- char **charset_list, *charset_buf;
- int count, length, font_set_num;
- int result = 1;
-
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- count = length = 0;
-
- for ( ; font_set_num-- > 0; font_set++) {
- if (font_set->info || font_set->font) {
- continue;
- }
-
- /* Change 1996.01.23 start */
- if(font_set->font_data_count <= 0 ||
- font_set->font_data == (FontData)NULL) {
- if(font_set->substitute_num <= 0 ||
- font_set->substitute == (FontData)NULL) {
- if(font_set->charset_list != NULL){
- length +=
- strlen(font_set->charset_list[0]->encoding_name) + 1;
- } else {
- length += 1;
- }
- } else {
- length += strlen(font_set->substitute->name) + 1;
- }
- } else {
- length += strlen(font_set->font_data->name) + 1;
- }
- /* Change 1996.01.23 end */
- count++;
- }
-
- if (count < 1) {
- return True;
- }
-
- charset_list = (char **) Xmalloc(sizeof(char *) * count);
- if (charset_list == NULL) {
- return False;
- }
-
- charset_buf = (char *) Xmalloc(length);
- if (charset_buf == NULL) {
- Xfree(charset_list);
- return False;
- }
-
- oc->core.missing_list.charset_list = charset_list;
- oc->core.missing_list.charset_count = count;
-
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
-
- for ( ; font_set_num-- > 0; font_set++) {
- if (font_set->info || font_set->font) {
- continue;
- }
-
- /* Change 1996.01.23 start */
- if(font_set->font_data_count <= 0 ||
- font_set->font_data == (FontData)NULL) {
- if(font_set->substitute_num <= 0 ||
- font_set->substitute == (FontData)NULL) {
- if(font_set->charset_list != NULL){
- strcpy(charset_buf,
- font_set->charset_list[0]->encoding_name);
- } else {
- strcpy(charset_buf, "");
- }
- result = 0;
- } else {
- strcpy(charset_buf, font_set->substitute->name);
- }
- } else {
- strcpy(charset_buf, font_set->font_data->name);
- }
- /* Change 1996.01.23 end */
- *charset_list++ = charset_buf;
- charset_buf += strlen(charset_buf) + 1;
- }
-
- if(result == 0) {
- return(False);
- }
-
- return True;
-}
-
-static Bool
-create_fontset(
- XOC oc)
-{
- XOMGenericPart *gen = XOM_GENERIC(oc->core.om);
- int found_num;
-
- if (init_fontset(oc) == False)
- return False;
-
- found_num = parse_fontname(oc);
- if (found_num <= 0) {
- if (found_num == 0)
- set_missing_list(oc);
- return False;
- }
-
- if (gen->on_demand_loading == True) {
- if (load_font_info(oc) == False)
- return False;
- } else {
- if (load_font(oc) == False)
- return False;
- }
-
- if (init_core_part(oc) == False)
- return False;
-
- if (set_missing_list(oc) == False)
- return False;
-
- return True;
-}
-
-/* For VW/UDC start */
-static void
-free_fontdataOC(
- Display *dpy,
- FontData font_data,
- int font_data_count)
-{
- for( ; font_data_count-- ; font_data++) {
- if(font_data->xlfd_name){
- Xfree(font_data->xlfd_name);
- font_data->xlfd_name = NULL;
- }
- if(font_data->font){ /* ADD 1996.01.7 */
- if(font_data->font->fid) /* Add 1996.01.23 */
- XFreeFont(dpy,font_data->font); /* ADD 1996.01.7 */
- else /* Add 1996.01.23 */
- XFreeFontInfo(NULL, font_data->font, 1);/* Add 1996.01.23 */
- font_data->font = NULL;
- }
-/*
- * font_data->name and font_data->scopes belong to the OM not OC.
- * To save space this data is shared between OM and OC. We are
- * not allowed to free it here.
- * It has been moved to free_fontdataOM()
- */
-/*
- if(font_data->scopes){
- Xfree(font_data->scopes);
- font_data->scopes = NULL;
- }
- if(font_data->name){
- Xfree(font_data->name);
- font_data->name = NULL;
- }
-*/
- }
-}
-
-static void destroy_fontdata(
- XOCGenericPart *gen,
- Display *dpy)
-{
- FontSet font_set = (FontSet) NULL;
- int font_set_num = 0;
-
- if (gen->font_set) {
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- for( ; font_set_num-- ; font_set++) {
- if (font_set->font) {
- if(font_set->font->fid)
- XFreeFont(dpy,font_set->font);
- else
- XFreeFontInfo(NULL, font_set->font, 1);
- font_set->font = NULL;
- }
- if(font_set->font_data) {
- if (font_set->info)
- XFreeFontInfo(NULL, font_set->info, 1);
- free_fontdataOC(dpy,
- font_set->font_data, font_set->font_data_count);
- Xfree(font_set->font_data);
- font_set->font_data = NULL;
- }
- if(font_set->substitute) {
- free_fontdataOC(dpy,
- font_set->substitute, font_set->substitute_num);
- Xfree(font_set->substitute);
- font_set->substitute = NULL;
- }
- if(font_set->vmap) {
- free_fontdataOC(dpy,
- font_set->vmap, font_set->vmap_num);
- Xfree(font_set->vmap);
- font_set->vmap = NULL;
- }
- if(font_set->vrotate) {
- free_fontdataOC(dpy,
- (FontData)font_set->vrotate,
- font_set->vrotate_num);
- Xfree(font_set->vrotate);
- font_set->vrotate = NULL;
- }
- }
- Xfree(gen->font_set);
- gen->font_set = NULL;
- }
-}
-/* For VW/UDC end */
-
-static void
-destroy_oc(
- XOC oc)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
-
- if (gen->mbs_to_cs)
- _XlcCloseConverter(gen->mbs_to_cs);
-
- if (gen->wcs_to_cs)
- _XlcCloseConverter(gen->wcs_to_cs);
-
- if (gen->utf8_to_cs)
- _XlcCloseConverter(gen->utf8_to_cs);
-
-/* For VW/UDC start */ /* Change 1996.01.8 */
- destroy_fontdata(gen,dpy);
-/*
-*/
-/* For VW/UDC end */
-
- if (oc->core.base_name_list)
- Xfree(oc->core.base_name_list);
-
- if (oc->core.font_info.font_name_list)
- XFreeStringList(oc->core.font_info.font_name_list);
-
- if (oc->core.font_info.font_struct_list) {
- Xfree(oc->core.font_info.font_struct_list);
- }
-
- if (oc->core.missing_list.charset_list)
- XFreeStringList(oc->core.missing_list.charset_list);
-
-#ifdef notdef
- if (oc->core.res_name)
- Xfree(oc->core.res_name);
- if (oc->core.res_class)
- Xfree(oc->core.res_class);
-#endif
-
- Xfree(oc);
-}
-
-static char *
-set_oc_values(
- XOC oc,
- XlcArgList args,
- int num_args)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- char *ret;
- int num = gen->font_set_num;
-
- if (oc->core.resources == NULL)
- return NULL;
-
- ret = _XlcSetValues((XPointer) oc, oc->core.resources,
- oc->core.num_resources, args, num_args, XlcSetMask);
- if(ret != NULL){
- return(ret);
- } else {
- for ( ; num-- > 0; font_set++) {
- if (font_set->font_name == NULL)
- continue;
- if (font_set->vpart_initialize != 0)
- continue;
- if( oc->core.orientation == XOMOrientation_TTB_RTL ||
- oc->core.orientation == XOMOrientation_TTB_LTR ){
- load_fontdata(oc, font_set->vmap, font_set->vmap_num);
- load_fontdata(oc, (FontData) font_set->vrotate,
- font_set->vrotate_num);
- font_set->vpart_initialize = 1;
- }
- }
- return(NULL);
- }
-}
-
-static char *
-get_oc_values(
- XOC oc,
- XlcArgList args,
- int num_args)
-{
- if (oc->core.resources == NULL)
- return NULL;
-
- return _XlcGetValues((XPointer) oc, oc->core.resources,
- oc->core.num_resources, args, num_args, XlcGetMask);
-}
-
-static XOCMethodsRec oc_default_methods = {
- destroy_oc,
- set_oc_values,
- get_oc_values,
- _XmbDefaultTextEscapement,
- _XmbDefaultTextExtents,
- _XmbDefaultTextPerCharExtents,
- _XmbDefaultDrawString,
- _XmbDefaultDrawImageString,
- _XwcDefaultTextEscapement,
- _XwcDefaultTextExtents,
- _XwcDefaultTextPerCharExtents,
- _XwcDefaultDrawString,
- _XwcDefaultDrawImageString,
- _Xutf8DefaultTextEscapement,
- _Xutf8DefaultTextExtents,
- _Xutf8DefaultTextPerCharExtents,
- _Xutf8DefaultDrawString,
- _Xutf8DefaultDrawImageString
-};
-
-static XOCMethodsRec oc_generic_methods = {
- destroy_oc,
- set_oc_values,
- get_oc_values,
- _XmbGenericTextEscapement,
- _XmbGenericTextExtents,
- _XmbGenericTextPerCharExtents,
- _XmbGenericDrawString,
- _XmbGenericDrawImageString,
- _XwcGenericTextEscapement,
- _XwcGenericTextExtents,
- _XwcGenericTextPerCharExtents,
- _XwcGenericDrawString,
- _XwcGenericDrawImageString,
- _Xutf8GenericTextEscapement,
- _Xutf8GenericTextExtents,
- _Xutf8GenericTextPerCharExtents,
- _Xutf8GenericDrawString,
- _Xutf8GenericDrawImageString
-};
-
-typedef struct _XOCMethodsListRec {
- const char *name;
- XOCMethods methods;
-} XOCMethodsListRec, *XOCMethodsList;
-
-static XOCMethodsListRec oc_methods_list[] = {
- { "default", &oc_default_methods },
- { "generic", &oc_generic_methods }
-};
-
-static XlcResource oc_resources[] = {
- { XNBaseFontName, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask },
- { XNOMAutomatic, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOCRec, core.om_automatic), XlcGetMask },
- { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList),
- XOffsetOf(XOCRec, core.missing_list), XlcGetMask },
- { XNDefaultString, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.default_string), XlcGetMask },
- { XNOrientation, NULLQUARK, sizeof(XOrientation),
- XOffsetOf(XOCRec, core.orientation), XlcDefaultMask | XlcSetMask | XlcGetMask },
- { XNResourceName, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask },
- { XNResourceClass, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask },
- { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo),
- XOffsetOf(XOCRec, core.font_info), XlcGetMask }
-};
-
-static XOC
-create_oc(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- XOC oc;
- XOMGenericPart *gen = XOM_GENERIC(om);
- XOCMethodsList methods_list = oc_methods_list;
- int count;
-
- oc = Xcalloc(1, sizeof(XOCGenericRec));
- if (oc == NULL)
- return (XOC) NULL;
-
- oc->core.om = om;
-
- if (oc_resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(oc_resources, XlcNumber(oc_resources));
-
- if (_XlcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources),
- args, num_args, XlcCreateMask | XlcDefaultMask))
- goto err;
-
- if (oc->core.base_name_list == NULL)
- goto err;
-
- oc->core.resources = oc_resources;
- oc->core.num_resources = XlcNumber(oc_resources);
-
- if (create_fontset(oc) == False)
- goto err;
-
- oc->methods = &oc_generic_methods;
-
- if (gen->object_name) {
- count = XlcNumber(oc_methods_list);
-
- for ( ; count-- > 0; methods_list++) {
- if (!_XlcCompareISOLatin1(gen->object_name, methods_list->name)) {
- oc->methods = methods_list->methods;
- break;
- }
- }
- }
-
- return oc;
-
-err:
- destroy_oc(oc);
-
- return (XOC) NULL;
-}
-
-static void
-free_fontdataOM(
- FontData font_data,
- int font_data_count)
-{
- for( ; font_data_count-- ; font_data++) {
- if(font_data->name){
- Xfree(font_data->name);
- font_data->name = NULL;
- }
- if(font_data->scopes){
- Xfree(font_data->scopes);
- font_data->scopes = NULL;
- }
- }
-}
-
-static Status
-close_om(
- XOM om)
-{
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData data;
- int count;
-
- if ((data = gen->data)) {
- for (count = gen->data_num; count-- > 0; data++) {
- if (data->charset_list){
- Xfree(data->charset_list);
- data->charset_list = NULL;
- }
- /* free font_data for om */
- if (data->font_data) {
- free_fontdataOM(data->font_data,data->font_data_count);
- Xfree(data->font_data);
- data->font_data = NULL;
- }
- /* free substitute for om */
- if (data->substitute) {
- free_fontdataOM(data->substitute,data->substitute_num);
- Xfree(data->substitute);
- data->substitute = NULL;
- }
- /* free vmap for om */
- if (data->vmap) {
- free_fontdataOM(data->vmap,data->vmap_num);
- Xfree(data->vmap);
- data->vmap = NULL;
- }
- /* free vrotate for om */
- if (data->vrotate) {
- Xfree(data->vrotate);
- data->vrotate = NULL;
- }
- }
- Xfree(gen->data);
- gen->data = NULL;
- }
-
- if (gen->object_name){
- Xfree(gen->object_name);
- gen->object_name = NULL;
- }
-
- if (om->core.res_name){
- Xfree(om->core.res_name);
- om->core.res_name = NULL;
- }
- if (om->core.res_class){
- Xfree(om->core.res_class);
- om->core.res_class = NULL;
- }
- if (om->core.required_charset.charset_list &&
- om->core.required_charset.charset_count > 0){
- XFreeStringList(om->core.required_charset.charset_list);
- om->core.required_charset.charset_list = NULL;
- } else {
- Xfree((char*)om->core.required_charset.charset_list);
- om->core.required_charset.charset_list = NULL;
- }
- if (om->core.orientation_list.orientation){
- Xfree(om->core.orientation_list.orientation);
- om->core.orientation_list.orientation = NULL;
- }
-
- Xfree(om);
-
- return 1;
-}
-
-static char *
-set_om_values(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- if (om->core.resources == NULL)
- return NULL;
-
- return _XlcSetValues((XPointer) om, om->core.resources,
- om->core.num_resources, args, num_args, XlcSetMask);
-}
-
-static char *
-get_om_values(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- if (om->core.resources == NULL)
- return NULL;
-
- return _XlcGetValues((XPointer) om, om->core.resources,
- om->core.num_resources, args, num_args, XlcGetMask);
-}
-
-static XOMMethodsRec methods = {
- close_om,
- set_om_values,
- get_om_values,
- create_oc
-};
-
-static XlcResource om_resources[] = {
- { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList),
- XOffsetOf(XOMRec, core.required_charset), XlcGetMask },
- { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation),
- XOffsetOf(XOMRec, core.orientation_list), XlcGetMask },
- { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask },
- { XNContextualDrawing, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask }
-};
-
-static XOM
-create_om(
- XLCd lcd,
- Display *dpy,
- XrmDatabase rdb,
- _Xconst char *res_name,
- _Xconst char *res_class)
-{
- XOM om;
-
- om = Xcalloc(1, sizeof(XOMGenericRec));
- if (om == NULL)
- return (XOM) NULL;
-
- om->methods = &methods;
- om->core.lcd = lcd;
- om->core.display = dpy;
- om->core.rdb = rdb;
- if (res_name) {
- om->core.res_name = strdup(res_name);
- if (om->core.res_name == NULL)
- goto err;
- }
- if (res_class) {
- om->core.res_class = strdup(res_class);
- if (om->core.res_class == NULL)
- goto err;
- }
-
- if (om_resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(om_resources, XlcNumber(om_resources));
-
- om->core.resources = om_resources;
- om->core.num_resources = XlcNumber(om_resources);
-
- return om;
-
-err:
- close_om(om);
-
- return (XOM) NULL;
-}
-
-static OMData
-add_data(
- XOM om)
-{
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData new;
- int num;
-
- if ((num = gen->data_num))
- new = (OMData) Xrealloc(gen->data, (num + 1) * sizeof(OMDataRec));
- else
- new = (OMData) Xmalloc(sizeof(OMDataRec));
-
- if (new == NULL)
- return NULL;
-
- gen->data_num = num + 1;
- gen->data = new;
-
- new += num;
- bzero((char *) new, sizeof(OMDataRec));
-
- return new;
-}
-
-/* For VW/UDC */
-
-FontData
-read_EncodingInfo(
- int count,
- char **value)
-{
- FontData font_data,ret;
- char *buf, *bufptr,*scp;
- int len;
- font_data = Xcalloc(count, sizeof(FontDataRec));
- if (font_data == NULL)
- return NULL;
-
- ret = font_data;
- for ( ; count-- > 0; font_data++) {
-/*
- strcpy(buf, *value++);
-*/
- buf = *value; value++;
- if ((bufptr = strchr(buf, ':'))) {
- len = (int)(bufptr - buf);
- bufptr++ ;
- } else
- len = strlen(buf);
- font_data->name = (char *) Xmalloc(len + 1);
- if (font_data->name == NULL) {
- Xfree(font_data);
- return NULL;
- }
- strncpy(font_data->name, buf,len);
- font_data->name[len] = 0;
- if (bufptr && _XlcCompareISOLatin1(bufptr, "GL") == 0)
- font_data->side = XlcGL;
- else if (bufptr && _XlcCompareISOLatin1(bufptr, "GR") == 0)
- font_data->side = XlcGR;
- else
- font_data->side = XlcGLGR;
-
- if (bufptr && (scp = strchr(bufptr, '['))){
- font_data->scopes = _XlcParse_scopemaps(scp,&(font_data->scopes_num));
- }
- }
- return(ret);
-}
-
-static CodeRange read_vrotate(
- int count,
- char **value,
- int *type,
- int *vrotate_num)
-{
- CodeRange range;
- if(!strcmp(value[0],"all")){
- *type = VROTATE_ALL ;
- *vrotate_num = 0 ;
- return (NULL);
- } else if(*(value[0]) == '['){
- *type = VROTATE_PART ;
- range = (CodeRange) _XlcParse_scopemaps(value[0],vrotate_num);
- return (range);
- } else {
- *type = VROTATE_NONE ;
- *vrotate_num = 0 ;
- return (NULL);
- }
-}
-
-static void read_vw(
- XLCd lcd,
- OMData font_set,
- int num)
-{
- char **value, buf[BUFSIZ];
- int count;
-
- sprintf(buf, "fs%d.font.vertical_map", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count > 0){
- _XlcDbg_printValue(buf,value,count);
- font_set->vmap_num = count;
- font_set->vmap = read_EncodingInfo(count,value);
- }
-
- sprintf(buf, "fs%d.font.vertical_rotate", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count > 0){
- _XlcDbg_printValue(buf,value,count);
- font_set->vrotate = read_vrotate(count,value,&(font_set->vrotate_type),
- &(font_set->vrotate_num));
- }
-}
-/* VW/UDC end */
-static Bool
-init_om(
- XOM om)
-{
- XLCd lcd = om->core.lcd;
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData data;
- XlcCharSet *charset_list;
- FontData font_data;
- char **required_list;
- XOrientation *orientation;
- char **value, buf[BUFSIZ], *bufptr;
- int count = 0, num = 0, length = 0;
-
- _XlcGetResource(lcd, "XLC_FONTSET", "on_demand_loading", &value, &count);
- if (count > 0 && _XlcCompareISOLatin1(*value, "True") == 0)
- gen->on_demand_loading = True;
-
- _XlcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count);
- if (count > 0) {
- gen->object_name = strdup(*value);
- if (gen->object_name == NULL)
- return False;
- }
-
- for (num = 0; ; num++) {
-
- sprintf(buf, "fs%d.charset.name", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
-
- if( count < 1){
- sprintf(buf, "fs%d.charset", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count < 1)
- break;
- }
-
- data = add_data(om);
- if (data == NULL)
- return False;
-
- charset_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet) * count);
- if (charset_list == NULL)
- return False;
- data->charset_list = charset_list;
- data->charset_count = count;
-
- while (count-- > 0){
- *charset_list++ = _XlcGetCharSet(*value++);
- }
- sprintf(buf, "fs%d.charset.udc_area", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if( count > 0){
- UDCArea udc;
- int i,flag = 0;
- udc = (UDCArea)Xmalloc(count * sizeof(UDCAreaRec));
- if (udc == NULL)
- return False;
- for(i=0;i<count;i++){
- sscanf(value[i],"\\x%lx,\\x%lx", &(udc[i].start),
- &(udc[i].end));
- }
- for(i=0;i<data->charset_count;i++){
- if(data->charset_list[i]->udc_area == NULL){
- data->charset_list[i]->udc_area = udc;
- data->charset_list[i]->udc_area_num = count;
- flag = 1;
- }
- }
- if(flag == 0){
- Xfree(udc);
- }
- }
-
- sprintf(buf, "fs%d.font.primary", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count < 1){
- sprintf(buf, "fs%d.font", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count < 1)
- return False;
- }
-
- font_data = read_EncodingInfo(count,value);
- if (font_data == NULL)
- return False;
-
- data->font_data = font_data;
- data->font_data_count = count;
-
- sprintf(buf, "fs%d.font.substitute", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count > 0){
- font_data = read_EncodingInfo(count,value);
- if (font_data == NULL)
- return False;
- data->substitute = font_data;
- data->substitute_num = count;
- } else {
- sprintf(buf, "fs%d.font", num);
- _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count < 1) {
- data->substitute = NULL;
- data->substitute_num = 0;
- } else {
- font_data = read_EncodingInfo(count,value);
- data->substitute = font_data;
- data->substitute_num = count;
- }
- }
- read_vw(lcd,data,num);
- length += strlen(data->font_data->name) + 1;
- }
-
- /* required charset list */
- required_list = (char **) Xmalloc(sizeof(char *) * gen->data_num);
- if (required_list == NULL)
- return False;
-
- om->core.required_charset.charset_list = required_list;
- om->core.required_charset.charset_count = gen->data_num;
-
- count = gen->data_num;
- data = gen->data;
-
- if (count > 0) {
- bufptr = (char *) Xmalloc(length);
- if (bufptr == NULL) {
- Xfree(required_list);
- return False;
- }
-
- for ( ; count-- > 0; data++) {
- strcpy(bufptr, data->font_data->name);
- *required_list++ = bufptr;
- bufptr += strlen(bufptr) + 1;
- }
- }
-
- /* orientation list */
- orientation = (XOrientation *) Xmalloc(sizeof(XOrientation) * 2);
- if (orientation == NULL)
- return False;
-
- orientation[0] = XOMOrientation_LTR_TTB;
- orientation[1] = XOMOrientation_TTB_RTL;
- om->core.orientation_list.orientation = orientation;
- om->core.orientation_list.num_orientation = 2;
-
- /* directional dependent drawing */
- om->core.directional_dependent = False;
-
- /* contexual drawing */
- om->core.contextual_drawing = False;
-
- /* context dependent */
- om->core.context_dependent = False;
-
- return True;
-}
-
-XOM
-_XomGenericOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
- _Xconst char *res_name, _Xconst char *res_class)
-{
- XOM om;
-
- om = create_om(lcd, dpy, rdb, res_name, res_class);
- if (om == NULL)
- return (XOM) NULL;
-
- if (init_om(om) == False)
- goto err;
-
- return om;
-
-err:
- close_om(om);
-
- return (XOM) NULL;
-}
-
-Bool
-_XInitOM(
- XLCd lcd)
-{
- lcd->methods->open_om = _XomGenericOpenOM;
-
- return True;
-}
+/* #define FONTDEBUG */
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+/*
+ * Copyright 1995 by FUJITSU LIMITED
+ * This is source code modified by FUJITSU LIMITED under the Joint
+ * Development Agreement for the CDE/Motif PST.
+ *
+ * Modifier: Takanori Tateno FUJITSU LIMITED
+ *
+ */
+
+/*
+ * Fixed the algorithms in parse_fontname() and parse_fontdata()
+ * to improve the logic for determining which font should be
+ * returned for a given CharSet. We even added some comments
+ * so that you can figure out what in the heck we're doing. We
+ * realize this is a departure from the norm, but hey, we're
+ * rebels! :-) :-)
+ *
+ * Modifiers: Jeff Walls, Paul Anderson: HEWLETT-PACKARD
+ */
+/*
+ * Cleaned up mess, removed some blabla
+ * Egbert Eich, SuSE Linux AG
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "XomGeneric.h"
+#include "XlcGeneric.h"
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <ctype.h>
+
+#define MAXFONTS 100
+#define PIXEL_SIZE_FIELD 7
+#define POINT_SIZE_FIELD 8
+#define CHARSET_ENCODING_FIELD 14
+#define XLFD_MAX_LEN 255
+
+#if 0
+extern int _XmbDefaultTextEscapement(), _XwcDefaultTextEscapement(),
+ _Xutf8DefaultTextEscapement();
+extern int _XmbDefaultTextExtents(), _XwcDefaultTextExtents(),
+ _Xutf8DefaultTextExtents();
+extern Status _XmbDefaultTextPerCharExtents(), _XwcDefaultTextPerCharExtents(),
+ _Xutf8DefaultTextPerCharExtents();
+extern int _XmbDefaultDrawString(), _XwcDefaultDrawString(),
+ _Xutf8DefaultDrawString();
+extern void _XmbDefaultDrawImageString(), _XwcDefaultDrawImageString(),
+ _Xutf8DefaultDrawImageString();
+
+extern int _XmbGenericTextEscapement(), _XwcGenericTextEscapement(),
+ _Xutf8GenericTextEscapement();
+extern int _XmbGenericTextExtents(), _XwcGenericTextExtents(),
+ _Xutf8GenericTextExtents();
+extern Status _XmbGenericTextPerCharExtents(), _XwcGenericTextPerCharExtents(),
+ _Xutf8GenericTextPerCharExtents();
+extern int _XmbGenericDrawString(), _XwcGenericDrawString(),
+ _Xutf8GenericDrawString();
+extern void _XmbGenericDrawImageString(), _XwcGenericDrawImageString(),
+ _Xutf8GenericDrawImageString();
+
+extern void _XlcDbg_printValue (const char *str, char **value, int num);
+#endif
+
+/* For VW/UDC start */
+
+static FontData
+init_fontdata(
+ FontData font_data,
+ int font_data_count)
+{
+ FontData fd;
+ int i;
+
+ fd = (FontData)Xmalloc(sizeof(FontDataRec) * font_data_count);
+ if(fd == (FontData) NULL)
+ return False;
+
+ memset(fd, 0x00, sizeof(FontData) * font_data_count);
+ for(i = 0 ; i < font_data_count ; i++)
+ fd[i] = font_data[i];
+
+ return fd;
+}
+
+static VRotate
+init_vrotate(
+ FontData font_data,
+ int font_data_count,
+ int type,
+ CodeRange code_range,
+ int code_range_num)
+{
+ VRotate vrotate;
+ int i;
+
+ if(type == VROTATE_NONE)
+ return (VRotate)NULL;
+
+ vrotate = (VRotate)Xmalloc(sizeof(VRotateRec) * font_data_count);
+ if(vrotate == (VRotate) NULL)
+ return False;
+
+ memset(vrotate, 0x00, sizeof(VRotateRec) * font_data_count);
+ for(i = 0 ; i < font_data_count ; i++) {
+ vrotate[i].charset_name = font_data[i].name;
+ vrotate[i].side = font_data[i].side;
+ if(type == VROTATE_PART) {
+ vrotate[i].num_cr = code_range_num;
+ vrotate[i].code_range = code_range;
+ }
+ }
+
+ return vrotate;
+}
+
+static Bool
+init_fontset(
+ XOC oc)
+{
+ XOCGenericPart *gen;
+ FontSet font_set;
+ OMData data;
+ int count;
+
+ count = XOM_GENERIC(oc->core.om)->data_num;
+ data = XOM_GENERIC(oc->core.om)->data;
+
+ font_set = (FontSet) Xmalloc(sizeof(FontSetRec) * count);
+ if (font_set == NULL)
+ return False;
+ memset((char *) font_set, 0x00, sizeof(FontSetRec) * count);
+
+ gen = XOC_GENERIC(oc);
+ gen->font_set_num = count;
+ gen->font_set = font_set;
+
+ for ( ; count-- > 0; data++, font_set++) {
+ font_set->charset_count = data->charset_count;
+ font_set->charset_list = data->charset_list;
+
+ if((font_set->font_data = init_fontdata(data->font_data,
+ data->font_data_count)) == NULL)
+ goto err;
+ font_set->font_data_count = data->font_data_count;
+ if((font_set->substitute = init_fontdata(data->substitute,
+ data->substitute_num)) == NULL)
+ goto err;
+ font_set->substitute_num = data->substitute_num;
+ if((font_set->vmap = init_fontdata(data->vmap,
+ data->vmap_num)) == NULL)
+ goto err;
+ font_set->vmap_num = data->vmap_num;
+
+ if(data->vrotate_type != VROTATE_NONE) {
+ /* A vrotate member is specified primary font data */
+ /* as initial value. */
+ if((font_set->vrotate = init_vrotate(data->font_data,
+ data->font_data_count,
+ data->vrotate_type,
+ data->vrotate,
+ data->vrotate_num)) == NULL)
+ goto err;
+ font_set->vrotate_num = data->font_data_count;
+ }
+ }
+ return True;
+
+err:
+ if(font_set->font_data)
+ Xfree(font_set->font_data);
+ if(font_set->substitute)
+ Xfree(font_set->substitute);
+ if(font_set->vmap)
+ Xfree(font_set->vmap);
+ if(font_set->vrotate)
+ Xfree(font_set->vrotate);
+ if(font_set)
+ Xfree(font_set);
+ gen->font_set = (FontSet) NULL;
+ gen->font_set_num = 0;
+ return False;
+}
+
+/* For VW/UDC end */
+
+static char *
+get_prop_name(
+ Display *dpy,
+ XFontStruct *fs)
+{
+ unsigned long fp;
+
+ if (XGetFontProperty(fs, XA_FONT, &fp))
+ return XGetAtomName(dpy, fp);
+
+ return (char *) NULL;
+}
+
+/* For VW/UDC start */
+
+static Bool
+load_fontdata(
+ XOC oc,
+ FontData font_data,
+ int font_data_num)
+{
+ Display *dpy = oc->core.om->core.display;
+ FontData fd = font_data;
+
+ if(font_data == NULL) return(True);
+ for( ; font_data_num-- ; fd++) {
+ if(fd->xlfd_name != (char *) NULL && fd->font == NULL) {
+ fd->font = XLoadQueryFont(dpy, fd->xlfd_name);
+ if (fd->font == NULL){
+ return False;
+ }
+ }
+ }
+ return True;
+}
+
+static Bool
+load_fontset_data(
+ XOC oc,
+ FontSet font_set)
+{
+ Display *dpy = oc->core.om->core.display;
+
+ if(font_set->font_name == (char *)NULL) return False ;
+
+ /* If font_set->font is not NULL, it contains the *best*
+ * match font for this FontSet.
+ * -- jjw/pma (HP)
+ */
+ if(font_set->font == NULL) {
+ font_set->font = XLoadQueryFont(dpy, font_set->font_name);
+ if (font_set->font == NULL){
+ return False;
+ }
+ }
+ return True;
+}
+
+static Bool
+load_font(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set = gen->font_set;
+ int num = gen->font_set_num;
+
+ for ( ; num-- > 0; font_set++) {
+ if (font_set->font_name == NULL)
+ continue;
+
+ if (load_fontset_data (oc, font_set) != True)
+ return False;
+#ifndef TESTVERSION
+ if(load_fontdata(oc, font_set->font_data,
+ font_set->font_data_count) != True)
+ return False;
+
+ if(load_fontdata(oc, font_set->substitute,
+ font_set->substitute_num) != True)
+ return False;
+#endif
+
+/* Add 1996.05.20 */
+ if( oc->core.orientation == XOMOrientation_TTB_RTL ||
+ oc->core.orientation == XOMOrientation_TTB_LTR ){
+ if (font_set->vpart_initialize == 0) {
+ load_fontdata(oc, font_set->vmap, font_set->vmap_num);
+ load_fontdata(oc, (FontData) font_set->vrotate,
+ font_set->vrotate_num);
+ font_set->vpart_initialize = 1;
+ }
+ }
+
+ if (font_set->font->min_byte1 || font_set->font->max_byte1)
+ font_set->is_xchar2b = True;
+ else
+ font_set->is_xchar2b = False;
+ }
+
+ return True;
+}
+
+/* For VW/UDC end */
+
+static Bool
+load_font_info(
+ XOC oc)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set = gen->font_set;
+ char **fn_list;
+ int fn_num, num = gen->font_set_num;
+
+ for ( ; num-- > 0; font_set++) {
+ if (font_set->font_name == NULL)
+ continue;
+
+ if (font_set->info == NULL) {
+ fn_list = XListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num,
+ &font_set->info);
+ if (font_set->info == NULL)
+ return False;
+
+ XFreeFontNames(fn_list);
+ }
+ }
+
+ return True;
+}
+
+/* For Vertical Writing start */
+
+static void
+check_fontset_extents(
+ XCharStruct *overall,
+ int *logical_ascent,
+ int *logical_descent,
+ XFontStruct *font)
+{
+ overall->lbearing = min(overall->lbearing, font->min_bounds.lbearing);
+ overall->rbearing = max(overall->rbearing, font->max_bounds.rbearing);
+ overall->ascent = max(overall->ascent, font->max_bounds.ascent);
+ overall->descent = max(overall->descent, font->max_bounds.descent);
+ overall->width = max(overall->width, font->max_bounds.width);
+ *logical_ascent = max(*logical_ascent, font->ascent);
+ *logical_descent = max(*logical_descent, font->descent);
+}
+
+/* For Vertical Writing end */
+
+static void
+set_fontset_extents(
+ XOC oc)
+{
+ XRectangle *ink = &oc->core.font_set_extents.max_ink_extent;
+ XRectangle *logical = &oc->core.font_set_extents.max_logical_extent;
+ XFontStruct **font_list, *font;
+ XCharStruct overall;
+ int logical_ascent, logical_descent;
+ int num = oc->core.font_info.num_font;
+
+ font_list = oc->core.font_info.font_struct_list;
+ font = *font_list++;
+ overall = font->max_bounds;
+ overall.lbearing = font->min_bounds.lbearing;
+ logical_ascent = font->ascent;
+ logical_descent = font->descent;
+
+ /* For Vertical Writing start */
+
+ while (--num > 0) {
+ font = *font_list++;
+ check_fontset_extents(&overall, &logical_ascent, &logical_descent,
+ font);
+ }
+
+ {
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set = gen->font_set;
+ FontData font_data;
+ int font_set_num = gen->font_set_num;
+ int font_data_count;
+
+ for( ; font_set_num-- ; font_set++) {
+ if(font_set->vmap_num > 0) {
+ font_data = font_set->vmap;
+ font_data_count = font_set->vmap_num;
+ for( ; font_data_count-- ; font_data++) {
+ if(font_data->font != NULL) {
+ check_fontset_extents(&overall, &logical_ascent,
+ &logical_descent,
+ font_data->font);
+ }
+ }
+ }
+
+ if(font_set->vrotate_num > 0 && font_set->vrotate != NULL) {
+ font_data = (FontData) font_set->vrotate;
+ font_data_count = font_set->vrotate_num;
+ for( ; font_data_count-- ; font_data++) {
+ if(font_data->font != NULL) {
+ check_fontset_extents(&overall, &logical_ascent,
+ &logical_descent,
+ font_data->font);
+ }
+ }
+ }
+ }
+ }
+
+ /* For Vertical Writing start */
+
+ ink->x = overall.lbearing;
+ ink->y = -(overall.ascent);
+ ink->width = overall.rbearing - overall.lbearing;
+ ink->height = overall.ascent + overall.descent;
+
+ logical->x = 0;
+ logical->y = -(logical_ascent);
+ logical->width = overall.width;
+ logical->height = logical_ascent + logical_descent;
+}
+
+static Bool
+init_core_part(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ int font_set_num;
+ XFontStruct **font_struct_list;
+ char **font_name_list, *font_name_buf;
+ int count, length;
+
+ font_set = gen->font_set;
+ font_set_num = gen->font_set_num;
+ count = length = 0;
+
+ for ( ; font_set_num-- > 0; font_set++) {
+ if (font_set->font_name == NULL)
+ continue;
+
+ length += strlen(font_set->font_name) + 1;
+
+ count++;
+ }
+ if (count == 0)
+ return False;
+
+ font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *) * count);
+ if (font_struct_list == NULL)
+ return False;
+
+ font_name_list = (char **) Xmalloc(sizeof(char *) * count);
+ if (font_name_list == NULL)
+ goto err;
+
+ font_name_buf = (char *) Xmalloc(length);
+ if (font_name_buf == NULL)
+ goto err;
+
+ oc->core.font_info.num_font = count;
+ oc->core.font_info.font_name_list = font_name_list;
+ oc->core.font_info.font_struct_list = font_struct_list;
+
+ font_set = gen->font_set;
+ font_set_num = gen->font_set_num;
+
+ for (count = 0; font_set_num-- > 0; font_set++) {
+ if (font_set->font_name == NULL)
+ continue;
+
+ font_set->id = count;
+ if (font_set->font)
+ *font_struct_list++ = font_set->font;
+ else
+ *font_struct_list++ = font_set->info;
+ strcpy(font_name_buf, font_set->font_name);
+ Xfree(font_set->font_name);
+ *font_name_list++ = font_set->font_name = font_name_buf;
+ font_name_buf += strlen(font_name_buf) + 1;
+
+ count++;
+ }
+
+ set_fontset_extents(oc);
+
+ return True;
+
+err:
+ if (font_name_list)
+ Xfree(font_name_list);
+ Xfree(font_struct_list);
+
+ return False;
+}
+
+static char *
+get_font_name(
+ XOC oc,
+ char *pattern)
+{
+ char **list, *name;
+ int count = 0;
+
+ list = XListFonts(oc->core.om->core.display, pattern, 1, &count);
+ if (list == NULL)
+ return NULL;
+
+ name = strdup(*list);
+
+ XFreeFontNames(list);
+
+ return name;
+}
+
+/* For VW/UDC start*/
+
+static char *
+get_rotate_fontname(
+ char *font_name)
+{
+ char *pattern = NULL, *ptr = NULL;
+ char *fields[CHARSET_ENCODING_FIELD];
+ char str_pixel[32], str_point[4];
+ char *rotate_font_ptr = NULL;
+ int pixel_size = 0;
+ int field_num = 0, len = 0;
+
+ if(font_name == (char *) NULL || (len = strlen(font_name)) <= 0
+ || len > XLFD_MAX_LEN)
+ return NULL;
+
+ pattern = strdup(font_name);
+ if(!pattern)
+ return NULL;
+
+ memset(fields, 0, sizeof(char *) * 14);
+ ptr = pattern;
+ while(isspace(*ptr)) {
+ ptr++;
+ }
+ if(*ptr == '-')
+ ptr++;
+
+ for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD && ptr && *ptr ;
+ ptr++, field_num++) {
+ fields[field_num] = ptr;
+
+ if((ptr = strchr(ptr, '-'))) {
+ *ptr = '\0';
+ } else {
+ field_num++; /* Count last field */
+ break;
+ }
+ }
+
+ if(field_num < CHARSET_ENCODING_FIELD)
+ goto free_pattern;
+
+ /* Pixel Size field : fields[6] */
+ for(ptr = fields[PIXEL_SIZE_FIELD - 1] ; ptr && *ptr; ptr++) {
+ if(!isdigit(*ptr)) {
+ if(*ptr == '['){ /* 960730 */
+ strcpy(pattern, font_name);
+ return(pattern);
+ }
+ goto free_pattern;
+ }
+ }
+ pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]);
+ sprintf(str_pixel, "[ 0 ~%d %d 0 ]", pixel_size, pixel_size);
+ fields[6] = str_pixel;
+
+ /* Point Size field : fields[7] */
+ strcpy(str_point, "*");
+ fields[POINT_SIZE_FIELD - 1] = str_point;
+
+ len = 0;
+ for (field_num = 0; field_num < CHARSET_ENCODING_FIELD &&
+ fields[field_num]; field_num++) {
+ len += 1 + strlen(fields[field_num]);
+ }
+
+ /* Max XLFD length is 255 */
+ if (len > XLFD_MAX_LEN)
+ goto free_pattern;
+
+ rotate_font_ptr = (char *)Xmalloc(len + 1);
+ if(!rotate_font_ptr)
+ goto free_pattern;
+
+ rotate_font_ptr[0] = '\0';
+
+ for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD &&
+ fields[field_num] ; field_num++) {
+ strcat(rotate_font_ptr, "-");
+ strcat(rotate_font_ptr, fields[field_num]);
+ }
+
+free_pattern:
+ Xfree(pattern);
+
+ return rotate_font_ptr;
+}
+
+static Bool
+is_match_charset(
+ FontData font_data,
+ char *font_name)
+{
+ char *last;
+ int length, name_len;
+
+ name_len = strlen(font_name);
+ last = font_name + name_len;
+
+ length = strlen(font_data->name);
+ if (length > name_len)
+ return False;
+
+ if (_XlcCompareISOLatin1(last - length, font_data->name) == 0)
+ return True;
+
+ return False;
+}
+
+#if 0
+static char *
+get_font_name_from_list(
+ XOC oc,
+ char *pattern,
+ FontData font_data)
+{
+ char **list, *name = (char *)NULL, *fname;
+ int count = 0, i;
+
+ list = XListFonts(oc->core.om->core.display, pattern, MAXFONTS, &count);
+ if (list == NULL)
+ return NULL;
+
+ for (i = 0; i < count; i++) {
+ fname = list[i];
+ if(is_match_charset(font_data, fname) == True) {
+ name = strdup(fname);
+ break;
+ }
+ }
+
+ XFreeFontNames(list);
+
+ return name;
+}
+#endif
+
+static int
+parse_all_name(
+ XOC oc,
+ FontData font_data,
+ char *pattern)
+{
+
+#ifdef OLDCODE
+ if(is_match_charset(font_data, pattern) != True)
+ return False;
+
+ font_data->xlfd_name = strdup(pattern);
+ if(font_data->xlfd_name == NULL)
+ return (-1);
+
+ return True;
+#else /* OLDCODE */
+ Display *dpy = oc->core.om->core.display;
+ char **fn_list = NULL, *prop_fname = NULL;
+ int list_num;
+ XFontStruct *fs_list;
+ if(is_match_charset(font_data, pattern) != True) {
+ /*
+ * pattern should not contain any wildcard (execpt '?')
+ * this was probably added to make this case insensitive.
+ */
+ if ((fn_list = XListFontsWithInfo(dpy, pattern,
+ MAXFONTS,
+ &list_num, &fs_list)) == NULL) {
+ return False;
+ }
+ /* shouldn't we loop here ? */
+ else if ((prop_fname = get_prop_name(dpy, fs_list)) == NULL) {
+ XFreeFontInfo(fn_list, fs_list, list_num);
+ return False;
+ }
+ else if ((is_match_charset(font_data, prop_fname) != True)) {
+ XFree(prop_fname);
+ XFreeFontInfo(fn_list, fs_list, list_num);
+ return False;
+ }
+ else {
+ font_data->xlfd_name = prop_fname;
+ XFreeFontInfo(fn_list, fs_list, list_num);
+ return True;
+ }
+ }
+
+ font_data->xlfd_name = strdup(pattern);
+ if(font_data->xlfd_name == NULL)
+ return (-1);
+
+ return True;
+#endif /* OLDCODE */
+}
+
+static int
+parse_omit_name(
+ XOC oc,
+ FontData font_data,
+ char *pattern)
+{
+ char* last = (char *) NULL;
+ char* base_name;
+ char buf[XLFD_MAX_LEN + 1];
+ int length = 0;
+ int num_fields;
+ /*
+ * If the font specified by "pattern" is expandable to be
+ * a member of "font_data"'s FontSet, we've found a match.
+ */
+ if(is_match_charset(font_data, pattern) == True) {
+ if ((font_data->xlfd_name = get_font_name(oc, pattern)) != NULL) {
+ return True;
+ }
+ }
+
+ length = strlen (pattern);
+
+ if (length > XLFD_MAX_LEN)
+ return -1;
+
+ strcpy(buf, pattern);
+ last = buf + length - 1;
+
+ /* Replace the original encoding with the encoding for this FontSet. */
+
+ /* Figure out how many fields have been specified in this xlfd. */
+ for (num_fields = 0, base_name = buf; *base_name != '\0'; base_name++)
+ if (*base_name == '-') num_fields++;
+
+ switch (num_fields) {
+ case 12:
+ /* This is the best way to have specifed the fontset. In this
+ * case, there is no original encoding. E.g.,
+ * -*-*-*-*-*-*-14-*-*-*-*-*
+ * To this, we'll append a dash:
+ * -*-*-*-*-*-*-14-*-*-*-*-*-
+ * then append the encoding to get:
+ * -*-*-*-*-*-*-14-*-*-*-*-*-JISX0208.1990-0
+ */
+ /*
+ * Take care of:
+ * -*-*-*-*-*-*-14-*-*-*-*-
+ */
+ if (*(last) == '-')
+ *++last = '*';
+
+ *++last = '-';
+ break;
+ case 13:
+ /* Got the charset, not the encoding, zap the charset In this
+ * case, there is no original encoding, but there is a charset. E.g.,
+ * -*-*-*-*-*-*-14-*-*-*-*-*-jisx0212.1990
+ * To this, we remove the charset:
+ * -*-*-*-*-*-*-14-*-*-*-*-*-
+ * then append the new encoding to get:
+ * -*-*-*-*-*-*-14-*-*-*-*-*-JISX0208.1990-0
+ */
+ last = strrchr (buf, '-');
+ num_fields = 12;
+ break;
+ case 14:
+ /* Both the charset and the encoding are specified. Get rid
+ * of them so that we can append the new charset encoding. E.g.,
+ * -*-*-*-*-*-*-14-*-*-*-*-*-jisx0212.1990-0
+ * To this, we'll remove the encoding and charset to get:
+ * -*-*-*-*-*-*-14-*-*-*-*-*-
+ * then append the new encoding to get:
+ * -*-*-*-*-*-*-14-*-*-*-*-*-JISX0208.1990-0
+ */
+ last = strrchr (buf, '-');
+ *last = '\0';
+ last = strrchr (buf, '-');
+ num_fields = 12;
+ break;
+ default:
+ if (*last != '-')
+ *++last = '-';
+ break;
+ }
+
+ /* At this point, "last" is pointing to the last "-" in the
+ * xlfd, and all xlfd's at this point take a form similar to:
+ * -*-*-*-*-*-*-14-*-*-*-*-*-
+ * (i.e., no encoding).
+ * After the strcpy, we'll end up with something similar to:
+ * -*-*-*-*-*-*-14-*-*-*-*-*-JISX0208.1990-0
+ *
+ * If the modified font is found in the current FontSet,
+ * we've found a match.
+ */
+
+ last++;
+
+ if ((last - buf) + strlen(font_data->name) > XLFD_MAX_LEN)
+ return -1;
+
+ strcpy(last, font_data->name);
+ if ((font_data->xlfd_name = get_font_name(oc, buf)) != NULL)
+ return True;
+
+ /* This may mot be needed anymore as XListFonts() takes care of this */
+ while (num_fields < 12) {
+ if ((last - buf) > (XLFD_MAX_LEN - 2))
+ return -1;
+ *last = '*';
+ *(last + 1) = '-';
+ strcpy(last + 2, font_data->name);
+ num_fields++;
+ last+=2;
+ if ((font_data->xlfd_name = get_font_name(oc, buf)) != NULL)
+ return True;
+ }
+
+
+ return False;
+}
+
+
+typedef enum{C_PRIMARY, C_SUBSTITUTE, C_VMAP, C_VROTATE } ClassType;
+
+static int
+parse_fontdata(
+ XOC oc,
+ FontSet font_set,
+ FontData font_data,
+ int font_data_count,
+ char **name_list,
+ int name_list_count,
+ ClassType class,
+ FontDataRec *font_data_return)
+{
+
+ char **cur_name_list = name_list;
+ char *font_name = (char *) NULL;
+ char *pattern = (char *) NULL;
+ int found_num = 0, ret = 0;
+ int count = name_list_count;
+
+ if(name_list == NULL || count <= 0) {
+ return False;
+ }
+
+ if(font_data == NULL || font_data_count <= 0) {
+ return False;
+ }
+
+ /* Loop through each font encoding defined in the "font_data" FontSet. */
+ for ( ; font_data_count-- > 0; font_data++) {
+ Bool is_found = False;
+ font_name = (char *) NULL;
+ count = name_list_count;
+ cur_name_list = name_list;
+
+ /*
+ * Loop through each font specified by the user
+ * in the call to XCreateFontset().
+ */
+ while (count-- > 0) {
+ pattern = *cur_name_list++;
+ if (pattern == NULL || *pattern == '\0')
+ continue;
+#ifdef FONTDEBUG
+ fprintf(stderr,"Font pattern: %s %s\n",
+ pattern,font_data->name);
+#endif
+
+ /*
+ * If the current font is fully specified (i.e., the
+ * xlfd contains no wildcards) and the font exists on
+ * the X Server, we have a match.
+ */
+ if (strchr(pattern, '*') == NULL &&
+ (font_name = get_font_name(oc, pattern))) {
+ /*
+ * Find the full xlfd name for this font. If the font is
+ * already in xlfd format, it is simply returned. If the
+ * font is an alias for another font, the xlfd of the
+ * aliased font is returned.
+ */
+ ret = parse_all_name(oc, font_data, font_name);
+ Xfree(font_name);
+
+ if (ret == -1) return -1;
+ if (ret == False) continue;
+ /*
+ * Since there was an exact match of a fully-specified font
+ * or a font alias, we can return now since the desired font
+ * was found for the current font encoding for this FontSet.
+ *
+ * Previous implementations of this algorithm would
+ * not return here. Instead, they continued searching
+ * through the font encodings for this FontSet. The side-effect
+ * of that behavior is you may return a "substitute" match
+ * instead of an "exact" match. We believe there should be a
+ * preference on exact matches. Therefore, as soon as we
+ * find one, we bail.
+ *
+ * Also, previous implementations seemed to think it was
+ * important to find either a primary or substitute font
+ * for each Font encoding in the FontSet before returning an
+ * acceptable font. We don't believe this is necessary.
+ * All the client cares about is finding a reasonable font
+ * for what was passed in. If we find an exact match,
+ * there's no reason to look any further.
+ *
+ * -- jjw/pma (HP)
+ */
+ if (font_data_return) {
+ font_data_return->xlfd_name = strdup(font_data->xlfd_name);
+ if (!font_data_return->xlfd_name) return -1;
+
+ font_data_return->side = font_data->side;
+ }
+#ifdef FONTDEBUG
+ fprintf(stderr,"XLFD name: %s\n",font_data->xlfd_name);
+#endif
+
+ return True;
+ }
+ /*
+ * If the font name is not fully specified
+ * (i.e., it has wildcards), we have more work to do.
+ * See the comments in parse_omit_name()
+ * for the list of things to do.
+ */
+ ret = parse_omit_name(oc, font_data, pattern);
+
+ if (ret == -1) return -1;
+ if (ret == False) continue;
+
+ /*
+ * A font which matched the wild-carded specification was found.
+ * Only update the return data if a font has not yet been found.
+ * This maintains the convention that FontSets listed higher in
+ * a CodeSet in the Locale Database have higher priority than
+ * those FontSets listed lower in the CodeSet. In the following
+ * example:
+ *
+ * fs1 {
+ * charset HP-JIS:GR
+ * font JISX0208.1990-0:GL;\
+ * JISX0208.1990-1:GR;\
+ * JISX0208.1983-0:GL;\
+ * JISX0208.1983-1:GR
+ * }
+ *
+ * a font found in the JISX0208.1990-0 FontSet will have a
+ * higher priority than a font found in the JISX0208.1983-0
+ * FontSet.
+ */
+ if (font_data_return && font_data_return->xlfd_name == NULL) {
+
+#ifdef FONTDEBUG
+ fprintf(stderr,"XLFD name: %s\n",font_data->xlfd_name);
+#endif
+ font_data_return->xlfd_name = strdup(font_data->xlfd_name);
+ if (!font_data_return->xlfd_name) return -1;
+
+ font_data_return->side = font_data->side;
+ }
+
+ found_num++;
+ is_found = True;
+
+ break;
+ }
+
+ switch(class) {
+ case C_PRIMARY:
+ if(is_found == False) {
+ /*
+ * Did not find a font for the current FontSet. Check the
+ * FontSet's "substitute" font for a match. If we find a
+ * match, we'll keep searching in hopes of finding an exact
+ * match later down the FontSet list.
+ *
+ * when we return and we have found a font font_data_return
+ * contains the first (ie. best) match no matter if this
+ * is a C_PRIMARY or a C_SUBSTITUTE font
+ */
+ ret = parse_fontdata(oc, font_set, font_set->substitute,
+ font_set->substitute_num, name_list,
+ name_list_count, C_SUBSTITUTE,
+ font_data_return);
+ if (ret == -1) return -1;
+ if (ret == False) continue;
+
+ found_num++;
+ is_found = True;
+ }
+#ifdef TESTVERSION
+ else
+ return True;
+#endif
+ break;
+
+ case C_SUBSTITUTE:
+ case C_VMAP:
+ if(is_found == True)
+ return True;
+ break;
+
+ case C_VROTATE:
+ if(is_found == True) {
+ char *rotate_name;
+
+ if((rotate_name = get_rotate_fontname(font_data->xlfd_name))
+ != NULL) {
+ Xfree(font_data->xlfd_name);
+ font_data->xlfd_name = rotate_name;
+
+ return True;
+ }
+ Xfree(font_data->xlfd_name);
+ font_data->xlfd_name = NULL;
+ return False;
+ }
+ break;
+ }
+ }
+
+ if(class == C_PRIMARY && found_num >= 1)
+ return True;
+
+ return False;
+}
+
+
+static int
+parse_vw(
+ XOC oc,
+ FontSet font_set,
+ char **name_list,
+ int count)
+{
+ FontData vmap = font_set->vmap;
+ VRotate vrotate = font_set->vrotate;
+ int vmap_num = font_set->vmap_num;
+ int vrotate_num = font_set->vrotate_num;
+ int ret = 0, i = 0;
+
+ if(vmap_num > 0) {
+ if(parse_fontdata(oc, font_set, vmap, vmap_num, name_list,
+ count, C_VMAP,NULL) == -1)
+ return (-1);
+ }
+
+ if(vrotate_num > 0) {
+ ret = parse_fontdata(oc, font_set, (FontData) vrotate, vrotate_num,
+ name_list, count, C_VROTATE, NULL);
+ if(ret == -1) {
+ return (-1);
+ } else if(ret == False) {
+ CodeRange code_range;
+ int num_cr;
+ int sub_num = font_set->substitute_num;
+
+ code_range = vrotate[0].code_range; /* ? */
+ num_cr = vrotate[0].num_cr; /* ? */
+ for(i = 0 ; i < vrotate_num ; i++) {
+ if(vrotate[i].xlfd_name)
+ Xfree(vrotate[i].xlfd_name);
+ }
+ Xfree(vrotate);
+
+ if(sub_num > 0) {
+ vrotate = font_set->vrotate = (VRotate)Xmalloc
+ (sizeof(VRotateRec) * sub_num);
+ if(font_set->vrotate == (VRotate)NULL)
+ return (-1);
+ memset(font_set->vrotate, 0x00, sizeof(VRotateRec) * sub_num);
+
+ for(i = 0 ; i < sub_num ; i++) {
+ vrotate[i].charset_name = font_set->substitute[i].name;
+ vrotate[i].side = font_set->substitute[i].side;
+ vrotate[i].code_range = code_range;
+ vrotate[i].num_cr = num_cr;
+ }
+ vrotate_num = font_set->vrotate_num = sub_num;
+ } else {
+ vrotate = font_set->vrotate = (VRotate)NULL;
+ }
+
+ ret = parse_fontdata(oc, font_set, (FontData) vrotate, vrotate_num,
+ name_list, count, C_VROTATE, NULL);
+ if(ret == -1)
+ return (-1);
+ }
+ }
+
+ return True;
+}
+
+static int
+parse_fontname(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ FontDataRec font_data_return;
+ char *base_name, **name_list;
+ int font_set_num = 0;
+ int found_num = 0;
+ int count = 0;
+ int ret;
+ int i;
+
+ name_list = _XParseBaseFontNameList(oc->core.base_name_list, &count);
+ if (name_list == NULL)
+ return -1;
+
+ font_set = gen->font_set;
+ font_set_num = gen->font_set_num;
+
+ /* Loop through all of the CharSets defined in the Locale
+ * database for the current Locale.
+ */
+ for( ; font_set_num-- > 0 ; font_set++) {
+ if(font_set->font_name)
+ continue;
+
+ if(font_set->font_data_count > 0) {
+
+ /*
+ * If there are a non-zero number of FontSets defined
+ * for this CharSet.
+ * Try to find a font for this CharSet. If we find an
+ * acceptable font, we save the information for return
+ * to the client. If we do not find an acceptable font,
+ * a "missing_charset" will be reported to the client
+ * for this CharSet.
+ */
+ font_data_return. xlfd_name = NULL;
+ font_data_return.side = XlcUnknown;
+
+ ret = parse_fontdata(oc, font_set, font_set->font_data,
+ font_set->font_data_count,
+ name_list, count, C_PRIMARY,
+ &font_data_return);
+ if(ret == -1) {
+ goto err;
+ } else if(ret == True) {
+ /*
+ * We can't just loop thru fontset->font_data to
+ * find the first (ie. best) match: parse_fontdata
+ * will try a substitute font if no primary one could
+ * be matched. It returns the required information in
+ * font_data_return.
+ */
+ font_set->font_name = strdup(font_data_return.xlfd_name);
+ if(font_set->font_name == (char *) NULL)
+ goto err;
+
+ font_set->side = font_data_return.side;
+
+ Xfree (font_data_return.xlfd_name);
+ font_data_return.xlfd_name = NULL;
+
+ if(parse_vw(oc, font_set, name_list, count) == -1)
+ goto err;
+ found_num++;
+ }
+
+ } else if(font_set->substitute_num > 0) {
+ /*
+ * If there are no FontSets defined for this
+ * CharSet. We can only find "substitute" fonts.
+ */
+ ret = parse_fontdata(oc, font_set, font_set->substitute,
+ font_set->substitute_num,
+ name_list, count, C_SUBSTITUTE, NULL);
+ if(ret == -1) {
+ goto err;
+ } else if(ret == True) {
+ for(i=0;i<font_set->substitute_num;i++){
+ if(font_set->substitute[i].xlfd_name != NULL){
+ break;
+ }
+ }
+ font_set->font_name = strdup(font_set->substitute[i].xlfd_name);
+ if(font_set->font_name == (char *) NULL)
+ goto err;
+
+ font_set->side = font_set->substitute[i].side;
+ if(parse_vw(oc, font_set, name_list, count) == -1)
+ goto err;
+
+ found_num++;
+ }
+ }
+ }
+
+ base_name = strdup(oc->core.base_name_list);
+ if (base_name == NULL)
+ goto err;
+
+ oc->core.base_name_list = base_name;
+
+ XFreeStringList(name_list);
+
+ return found_num;
+
+err:
+ XFreeStringList(name_list);
+ /* Prevent this from being freed twice */
+ oc->core.base_name_list = NULL;
+
+ return -1;
+}
+
+/* For VW/UDC end*/
+
+static Bool
+set_missing_list(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ char **charset_list, *charset_buf;
+ int count, length, font_set_num;
+ int result = 1;
+
+ font_set = gen->font_set;
+ font_set_num = gen->font_set_num;
+ count = length = 0;
+
+ for ( ; font_set_num-- > 0; font_set++) {
+ if (font_set->info || font_set->font) {
+ continue;
+ }
+
+ /* Change 1996.01.23 start */
+ if(font_set->font_data_count <= 0 ||
+ font_set->font_data == (FontData)NULL) {
+ if(font_set->substitute_num <= 0 ||
+ font_set->substitute == (FontData)NULL) {
+ if(font_set->charset_list != NULL){
+ length +=
+ strlen(font_set->charset_list[0]->encoding_name) + 1;
+ } else {
+ length += 1;
+ }
+ } else {
+ length += strlen(font_set->substitute->name) + 1;
+ }
+ } else {
+ length += strlen(font_set->font_data->name) + 1;
+ }
+ /* Change 1996.01.23 end */
+ count++;
+ }
+
+ if (count < 1) {
+ return True;
+ }
+
+ charset_list = (char **) Xmalloc(sizeof(char *) * count);
+ if (charset_list == NULL) {
+ return False;
+ }
+
+ charset_buf = (char *) Xmalloc(length);
+ if (charset_buf == NULL) {
+ Xfree(charset_list);
+ return False;
+ }
+
+ oc->core.missing_list.charset_list = charset_list;
+ oc->core.missing_list.charset_count = count;
+
+ font_set = gen->font_set;
+ font_set_num = gen->font_set_num;
+
+ for ( ; font_set_num-- > 0; font_set++) {
+ if (font_set->info || font_set->font) {
+ continue;
+ }
+
+ /* Change 1996.01.23 start */
+ if(font_set->font_data_count <= 0 ||
+ font_set->font_data == (FontData)NULL) {
+ if(font_set->substitute_num <= 0 ||
+ font_set->substitute == (FontData)NULL) {
+ if(font_set->charset_list != NULL){
+ strcpy(charset_buf,
+ font_set->charset_list[0]->encoding_name);
+ } else {
+ strcpy(charset_buf, "");
+ }
+ result = 0;
+ } else {
+ strcpy(charset_buf, font_set->substitute->name);
+ }
+ } else {
+ strcpy(charset_buf, font_set->font_data->name);
+ }
+ /* Change 1996.01.23 end */
+ *charset_list++ = charset_buf;
+ charset_buf += strlen(charset_buf) + 1;
+ }
+
+ if(result == 0) {
+ return(False);
+ }
+
+ return True;
+}
+
+static Bool
+create_fontset(
+ XOC oc)
+{
+ XOMGenericPart *gen = XOM_GENERIC(oc->core.om);
+ int found_num;
+
+ if (init_fontset(oc) == False)
+ return False;
+
+ found_num = parse_fontname(oc);
+ if (found_num <= 0) {
+ if (found_num == 0)
+ set_missing_list(oc);
+ return False;
+ }
+
+ if (gen->on_demand_loading == True) {
+ if (load_font_info(oc) == False)
+ return False;
+ } else {
+ if (load_font(oc) == False)
+ return False;
+ }
+
+ if (init_core_part(oc) == False)
+ return False;
+
+ if (set_missing_list(oc) == False)
+ return False;
+
+ return True;
+}
+
+/* For VW/UDC start */
+static void
+free_fontdataOC(
+ Display *dpy,
+ FontData font_data,
+ int font_data_count)
+{
+ for( ; font_data_count-- ; font_data++) {
+ if(font_data->xlfd_name){
+ Xfree(font_data->xlfd_name);
+ font_data->xlfd_name = NULL;
+ }
+ if(font_data->font){ /* ADD 1996.01.7 */
+ if(font_data->font->fid) /* Add 1996.01.23 */
+ XFreeFont(dpy,font_data->font); /* ADD 1996.01.7 */
+ else /* Add 1996.01.23 */
+ XFreeFontInfo(NULL, font_data->font, 1);/* Add 1996.01.23 */
+ font_data->font = NULL;
+ }
+/*
+ * font_data->name and font_data->scopes belong to the OM not OC.
+ * To save space this data is shared between OM and OC. We are
+ * not allowed to free it here.
+ * It has been moved to free_fontdataOM()
+ */
+/*
+ if(font_data->scopes){
+ Xfree(font_data->scopes);
+ font_data->scopes = NULL;
+ }
+ if(font_data->name){
+ Xfree(font_data->name);
+ font_data->name = NULL;
+ }
+*/
+ }
+}
+
+static void destroy_fontdata(
+ XOCGenericPart *gen,
+ Display *dpy)
+{
+ FontSet font_set = (FontSet) NULL;
+ int font_set_num = 0;
+
+ if (gen->font_set) {
+ font_set = gen->font_set;
+ font_set_num = gen->font_set_num;
+ for( ; font_set_num-- ; font_set++) {
+ if (font_set->font) {
+ if(font_set->font->fid)
+ XFreeFont(dpy,font_set->font);
+ else
+ XFreeFontInfo(NULL, font_set->font, 1);
+ font_set->font = NULL;
+ }
+ if(font_set->font_data) {
+ if (font_set->info)
+ XFreeFontInfo(NULL, font_set->info, 1);
+ free_fontdataOC(dpy,
+ font_set->font_data, font_set->font_data_count);
+ Xfree(font_set->font_data);
+ font_set->font_data = NULL;
+ }
+ if(font_set->substitute) {
+ free_fontdataOC(dpy,
+ font_set->substitute, font_set->substitute_num);
+ Xfree(font_set->substitute);
+ font_set->substitute = NULL;
+ }
+ if(font_set->vmap) {
+ free_fontdataOC(dpy,
+ font_set->vmap, font_set->vmap_num);
+ Xfree(font_set->vmap);
+ font_set->vmap = NULL;
+ }
+ if(font_set->vrotate) {
+ free_fontdataOC(dpy,
+ (FontData)font_set->vrotate,
+ font_set->vrotate_num);
+ Xfree(font_set->vrotate);
+ font_set->vrotate = NULL;
+ }
+ }
+ Xfree(gen->font_set);
+ gen->font_set = NULL;
+ }
+}
+/* For VW/UDC end */
+
+static void
+destroy_oc(
+ XOC oc)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+
+ if (gen->mbs_to_cs)
+ _XlcCloseConverter(gen->mbs_to_cs);
+
+ if (gen->wcs_to_cs)
+ _XlcCloseConverter(gen->wcs_to_cs);
+
+ if (gen->utf8_to_cs)
+ _XlcCloseConverter(gen->utf8_to_cs);
+
+/* For VW/UDC start */ /* Change 1996.01.8 */
+ destroy_fontdata(gen,dpy);
+/*
+*/
+/* For VW/UDC end */
+
+ if (oc->core.base_name_list)
+ Xfree(oc->core.base_name_list);
+
+ if (oc->core.font_info.font_name_list)
+ XFreeStringList(oc->core.font_info.font_name_list);
+
+ if (oc->core.font_info.font_struct_list) {
+ Xfree(oc->core.font_info.font_struct_list);
+ }
+
+ if (oc->core.missing_list.charset_list)
+ XFreeStringList(oc->core.missing_list.charset_list);
+
+#ifdef notdef
+ if (oc->core.res_name)
+ Xfree(oc->core.res_name);
+ if (oc->core.res_class)
+ Xfree(oc->core.res_class);
+#endif
+
+ Xfree(oc);
+}
+
+static char *
+set_oc_values(
+ XOC oc,
+ XlcArgList args,
+ int num_args)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set = gen->font_set;
+ char *ret;
+ int num = gen->font_set_num;
+
+ if (oc->core.resources == NULL)
+ return NULL;
+
+ ret = _XlcSetValues((XPointer) oc, oc->core.resources,
+ oc->core.num_resources, args, num_args, XlcSetMask);
+ if(ret != NULL){
+ return(ret);
+ } else {
+ for ( ; num-- > 0; font_set++) {
+ if (font_set->font_name == NULL)
+ continue;
+ if (font_set->vpart_initialize != 0)
+ continue;
+ if( oc->core.orientation == XOMOrientation_TTB_RTL ||
+ oc->core.orientation == XOMOrientation_TTB_LTR ){
+ load_fontdata(oc, font_set->vmap, font_set->vmap_num);
+ load_fontdata(oc, (FontData) font_set->vrotate,
+ font_set->vrotate_num);
+ font_set->vpart_initialize = 1;
+ }
+ }
+ return(NULL);
+ }
+}
+
+static char *
+get_oc_values(
+ XOC oc,
+ XlcArgList args,
+ int num_args)
+{
+ if (oc->core.resources == NULL)
+ return NULL;
+
+ return _XlcGetValues((XPointer) oc, oc->core.resources,
+ oc->core.num_resources, args, num_args, XlcGetMask);
+}
+
+static XOCMethodsRec oc_default_methods = {
+ destroy_oc,
+ set_oc_values,
+ get_oc_values,
+ _XmbDefaultTextEscapement,
+ _XmbDefaultTextExtents,
+ _XmbDefaultTextPerCharExtents,
+ _XmbDefaultDrawString,
+ _XmbDefaultDrawImageString,
+ _XwcDefaultTextEscapement,
+ _XwcDefaultTextExtents,
+ _XwcDefaultTextPerCharExtents,
+ _XwcDefaultDrawString,
+ _XwcDefaultDrawImageString,
+ _Xutf8DefaultTextEscapement,
+ _Xutf8DefaultTextExtents,
+ _Xutf8DefaultTextPerCharExtents,
+ _Xutf8DefaultDrawString,
+ _Xutf8DefaultDrawImageString
+};
+
+static XOCMethodsRec oc_generic_methods = {
+ destroy_oc,
+ set_oc_values,
+ get_oc_values,
+ _XmbGenericTextEscapement,
+ _XmbGenericTextExtents,
+ _XmbGenericTextPerCharExtents,
+ _XmbGenericDrawString,
+ _XmbGenericDrawImageString,
+ _XwcGenericTextEscapement,
+ _XwcGenericTextExtents,
+ _XwcGenericTextPerCharExtents,
+ _XwcGenericDrawString,
+ _XwcGenericDrawImageString,
+ _Xutf8GenericTextEscapement,
+ _Xutf8GenericTextExtents,
+ _Xutf8GenericTextPerCharExtents,
+ _Xutf8GenericDrawString,
+ _Xutf8GenericDrawImageString
+};
+
+typedef struct _XOCMethodsListRec {
+ const char *name;
+ XOCMethods methods;
+} XOCMethodsListRec, *XOCMethodsList;
+
+static XOCMethodsListRec oc_methods_list[] = {
+ { "default", &oc_default_methods },
+ { "generic", &oc_generic_methods }
+};
+
+static XlcResource oc_resources[] = {
+ { XNBaseFontName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask },
+ { XNOMAutomatic, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOCRec, core.om_automatic), XlcGetMask },
+ { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList),
+ XOffsetOf(XOCRec, core.missing_list), XlcGetMask },
+ { XNDefaultString, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.default_string), XlcGetMask },
+ { XNOrientation, NULLQUARK, sizeof(XOrientation),
+ XOffsetOf(XOCRec, core.orientation), XlcDefaultMask | XlcSetMask | XlcGetMask },
+ { XNResourceName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask },
+ { XNResourceClass, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask },
+ { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo),
+ XOffsetOf(XOCRec, core.font_info), XlcGetMask }
+};
+
+static XOC
+create_oc(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ XOC oc;
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ XOCMethodsList methods_list = oc_methods_list;
+ int count;
+
+ oc = Xcalloc(1, sizeof(XOCGenericRec));
+ if (oc == NULL)
+ return (XOC) NULL;
+
+ oc->core.om = om;
+
+ if (oc_resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(oc_resources, XlcNumber(oc_resources));
+
+ if (_XlcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources),
+ args, num_args, XlcCreateMask | XlcDefaultMask))
+ goto err;
+
+ if (oc->core.base_name_list == NULL)
+ goto err;
+
+ oc->core.resources = oc_resources;
+ oc->core.num_resources = XlcNumber(oc_resources);
+
+ if (create_fontset(oc) == False)
+ goto err;
+
+ oc->methods = &oc_generic_methods;
+
+ if (gen->object_name) {
+ count = XlcNumber(oc_methods_list);
+
+ for ( ; count-- > 0; methods_list++) {
+ if (!_XlcCompareISOLatin1(gen->object_name, methods_list->name)) {
+ oc->methods = methods_list->methods;
+ break;
+ }
+ }
+ }
+
+ return oc;
+
+err:
+ destroy_oc(oc);
+
+ return (XOC) NULL;
+}
+
+static void
+free_fontdataOM(
+ FontData font_data,
+ int font_data_count)
+{
+ for( ; font_data_count-- ; font_data++) {
+ if(font_data->name){
+ Xfree(font_data->name);
+ font_data->name = NULL;
+ }
+ if(font_data->scopes){
+ Xfree(font_data->scopes);
+ font_data->scopes = NULL;
+ }
+ }
+}
+
+static Status
+close_om(
+ XOM om)
+{
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData data;
+ int count;
+
+ if ((data = gen->data)) {
+ for (count = gen->data_num; count-- > 0; data++) {
+ if (data->charset_list){
+ Xfree(data->charset_list);
+ data->charset_list = NULL;
+ }
+ /* free font_data for om */
+ if (data->font_data) {
+ free_fontdataOM(data->font_data,data->font_data_count);
+ Xfree(data->font_data);
+ data->font_data = NULL;
+ }
+ /* free substitute for om */
+ if (data->substitute) {
+ free_fontdataOM(data->substitute,data->substitute_num);
+ Xfree(data->substitute);
+ data->substitute = NULL;
+ }
+ /* free vmap for om */
+ if (data->vmap) {
+ free_fontdataOM(data->vmap,data->vmap_num);
+ Xfree(data->vmap);
+ data->vmap = NULL;
+ }
+ /* free vrotate for om */
+ if (data->vrotate) {
+ Xfree(data->vrotate);
+ data->vrotate = NULL;
+ }
+ }
+ Xfree(gen->data);
+ gen->data = NULL;
+ }
+
+ if (gen->object_name){
+ Xfree(gen->object_name);
+ gen->object_name = NULL;
+ }
+
+ if (om->core.res_name){
+ Xfree(om->core.res_name);
+ om->core.res_name = NULL;
+ }
+ if (om->core.res_class){
+ Xfree(om->core.res_class);
+ om->core.res_class = NULL;
+ }
+ if (om->core.required_charset.charset_list &&
+ om->core.required_charset.charset_count > 0){
+ XFreeStringList(om->core.required_charset.charset_list);
+ om->core.required_charset.charset_list = NULL;
+ } else {
+ Xfree((char*)om->core.required_charset.charset_list);
+ om->core.required_charset.charset_list = NULL;
+ }
+ if (om->core.orientation_list.orientation){
+ Xfree(om->core.orientation_list.orientation);
+ om->core.orientation_list.orientation = NULL;
+ }
+
+ Xfree(om);
+
+ return 1;
+}
+
+static char *
+set_om_values(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ if (om->core.resources == NULL)
+ return NULL;
+
+ return _XlcSetValues((XPointer) om, om->core.resources,
+ om->core.num_resources, args, num_args, XlcSetMask);
+}
+
+static char *
+get_om_values(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ if (om->core.resources == NULL)
+ return NULL;
+
+ return _XlcGetValues((XPointer) om, om->core.resources,
+ om->core.num_resources, args, num_args, XlcGetMask);
+}
+
+static XOMMethodsRec methods = {
+ close_om,
+ set_om_values,
+ get_om_values,
+ create_oc
+};
+
+static XlcResource om_resources[] = {
+ { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList),
+ XOffsetOf(XOMRec, core.required_charset), XlcGetMask },
+ { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation),
+ XOffsetOf(XOMRec, core.orientation_list), XlcGetMask },
+ { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask },
+ { XNContextualDrawing, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask }
+};
+
+static XOM
+create_om(
+ XLCd lcd,
+ Display *dpy,
+ XrmDatabase rdb,
+ _Xconst char *res_name,
+ _Xconst char *res_class)
+{
+ XOM om;
+
+ om = Xcalloc(1, sizeof(XOMGenericRec));
+ if (om == NULL)
+ return (XOM) NULL;
+
+ om->methods = &methods;
+ om->core.lcd = lcd;
+ om->core.display = dpy;
+ om->core.rdb = rdb;
+ if (res_name) {
+ om->core.res_name = strdup(res_name);
+ if (om->core.res_name == NULL)
+ goto err;
+ }
+ if (res_class) {
+ om->core.res_class = strdup(res_class);
+ if (om->core.res_class == NULL)
+ goto err;
+ }
+
+ if (om_resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(om_resources, XlcNumber(om_resources));
+
+ om->core.resources = om_resources;
+ om->core.num_resources = XlcNumber(om_resources);
+
+ return om;
+
+err:
+ close_om(om);
+
+ return (XOM) NULL;
+}
+
+static OMData
+add_data(
+ XOM om)
+{
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData new;
+ int num;
+
+ if ((num = gen->data_num))
+ new = (OMData) Xrealloc(gen->data, (num + 1) * sizeof(OMDataRec));
+ else
+ new = (OMData) Xmalloc(sizeof(OMDataRec));
+
+ if (new == NULL)
+ return NULL;
+
+ gen->data_num = num + 1;
+ gen->data = new;
+
+ new += num;
+ bzero((char *) new, sizeof(OMDataRec));
+
+ return new;
+}
+
+/* For VW/UDC */
+
+FontData
+read_EncodingInfo(
+ int count,
+ char **value)
+{
+ FontData font_data,ret;
+ char *buf, *bufptr,*scp;
+ int len;
+ font_data = Xcalloc(count, sizeof(FontDataRec));
+ if (font_data == NULL)
+ return NULL;
+
+ ret = font_data;
+ for ( ; count-- > 0; font_data++) {
+/*
+ strcpy(buf, *value++);
+*/
+ buf = *value; value++;
+ if ((bufptr = strchr(buf, ':'))) {
+ len = (int)(bufptr - buf);
+ bufptr++ ;
+ } else
+ len = strlen(buf);
+ font_data->name = (char *) Xmalloc(len + 1);
+ if (font_data->name == NULL) {
+ Xfree(font_data);
+ return NULL;
+ }
+ strncpy(font_data->name, buf,len);
+ font_data->name[len] = 0;
+ if (bufptr && _XlcCompareISOLatin1(bufptr, "GL") == 0)
+ font_data->side = XlcGL;
+ else if (bufptr && _XlcCompareISOLatin1(bufptr, "GR") == 0)
+ font_data->side = XlcGR;
+ else
+ font_data->side = XlcGLGR;
+
+ if (bufptr && (scp = strchr(bufptr, '['))){
+ font_data->scopes = _XlcParse_scopemaps(scp,&(font_data->scopes_num));
+ }
+ }
+ return(ret);
+}
+
+static CodeRange read_vrotate(
+ int count,
+ char **value,
+ int *type,
+ int *vrotate_num)
+{
+ CodeRange range;
+ if(!strcmp(value[0],"all")){
+ *type = VROTATE_ALL ;
+ *vrotate_num = 0 ;
+ return (NULL);
+ } else if(*(value[0]) == '['){
+ *type = VROTATE_PART ;
+ range = (CodeRange) _XlcParse_scopemaps(value[0],vrotate_num);
+ return (range);
+ } else {
+ *type = VROTATE_NONE ;
+ *vrotate_num = 0 ;
+ return (NULL);
+ }
+}
+
+static void read_vw(
+ XLCd lcd,
+ OMData font_set,
+ int num)
+{
+ char **value, buf[BUFSIZ];
+ int count;
+
+ sprintf(buf, "fs%d.font.vertical_map", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+ if (count > 0){
+ _XlcDbg_printValue(buf,value,count);
+ font_set->vmap_num = count;
+ font_set->vmap = read_EncodingInfo(count,value);
+ }
+
+ sprintf(buf, "fs%d.font.vertical_rotate", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+ if (count > 0){
+ _XlcDbg_printValue(buf,value,count);
+ font_set->vrotate = read_vrotate(count,value,&(font_set->vrotate_type),
+ &(font_set->vrotate_num));
+ }
+}
+/* VW/UDC end */
+static Bool
+init_om(
+ XOM om)
+{
+ XLCd lcd = om->core.lcd;
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData data;
+ XlcCharSet *charset_list;
+ FontData font_data;
+ char **required_list;
+ XOrientation *orientation;
+ char **value, buf[BUFSIZ], *bufptr;
+ int count = 0, num = 0, length = 0;
+
+ _XlcGetResource(lcd, "XLC_FONTSET", "on_demand_loading", &value, &count);
+ if (count > 0 && _XlcCompareISOLatin1(*value, "True") == 0)
+ gen->on_demand_loading = True;
+
+ _XlcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count);
+ if (count > 0) {
+ gen->object_name = strdup(*value);
+ if (gen->object_name == NULL)
+ return False;
+ }
+
+ for (num = 0; ; num++) {
+
+ sprintf(buf, "fs%d.charset.name", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+
+ if( count < 1){
+ sprintf(buf, "fs%d.charset", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+ if (count < 1)
+ break;
+ }
+
+ data = add_data(om);
+ if (data == NULL)
+ return False;
+
+ charset_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet) * count);
+ if (charset_list == NULL)
+ return False;
+ data->charset_list = charset_list;
+ data->charset_count = count;
+
+ while (count-- > 0){
+ *charset_list++ = _XlcGetCharSet(*value++);
+ }
+ sprintf(buf, "fs%d.charset.udc_area", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+ if( count > 0){
+ UDCArea udc;
+ int i,flag = 0;
+ udc = (UDCArea)Xmalloc(count * sizeof(UDCAreaRec));
+ if (udc == NULL)
+ return False;
+ for(i=0;i<count;i++){
+ sscanf(value[i],"\\x%lx,\\x%lx", &(udc[i].start),
+ &(udc[i].end));
+ }
+ for(i=0;i<data->charset_count;i++){
+ if(data->charset_list[i]->udc_area == NULL){
+ data->charset_list[i]->udc_area = udc;
+ data->charset_list[i]->udc_area_num = count;
+ flag = 1;
+ }
+ }
+ if(flag == 0){
+ Xfree(udc);
+ }
+ }
+
+ sprintf(buf, "fs%d.font.primary", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+ if (count < 1){
+ sprintf(buf, "fs%d.font", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+ if (count < 1)
+ return False;
+ }
+
+ font_data = read_EncodingInfo(count,value);
+ if (font_data == NULL)
+ return False;
+
+ data->font_data = font_data;
+ data->font_data_count = count;
+
+ sprintf(buf, "fs%d.font.substitute", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+ if (count > 0){
+ font_data = read_EncodingInfo(count,value);
+ if (font_data == NULL)
+ return False;
+ data->substitute = font_data;
+ data->substitute_num = count;
+ } else {
+ sprintf(buf, "fs%d.font", num);
+ _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
+ if (count < 1) {
+ data->substitute = NULL;
+ data->substitute_num = 0;
+ } else {
+ font_data = read_EncodingInfo(count,value);
+ data->substitute = font_data;
+ data->substitute_num = count;
+ }
+ }
+ read_vw(lcd,data,num);
+ length += strlen(data->font_data->name) + 1;
+ }
+
+ /* required charset list */
+ required_list = (char **) Xmalloc(sizeof(char *) * gen->data_num);
+ if (required_list == NULL)
+ return False;
+
+ om->core.required_charset.charset_list = required_list;
+ om->core.required_charset.charset_count = gen->data_num;
+
+ count = gen->data_num;
+ data = gen->data;
+
+ if (count > 0) {
+ bufptr = (char *) Xmalloc(length);
+ if (bufptr == NULL) {
+ Xfree(required_list);
+ return False;
+ }
+
+ for ( ; count-- > 0; data++) {
+ strcpy(bufptr, data->font_data->name);
+ *required_list++ = bufptr;
+ bufptr += strlen(bufptr) + 1;
+ }
+ }
+
+ /* orientation list */
+ orientation = (XOrientation *) Xmalloc(sizeof(XOrientation) * 2);
+ if (orientation == NULL)
+ return False;
+
+ orientation[0] = XOMOrientation_LTR_TTB;
+ orientation[1] = XOMOrientation_TTB_RTL;
+ om->core.orientation_list.orientation = orientation;
+ om->core.orientation_list.num_orientation = 2;
+
+ /* directional dependent drawing */
+ om->core.directional_dependent = False;
+
+ /* contexual drawing */
+ om->core.contextual_drawing = False;
+
+ /* context dependent */
+ om->core.context_dependent = False;
+
+ return True;
+}
+
+XOM
+_XomGenericOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
+ _Xconst char *res_name, _Xconst char *res_class)
+{
+ XOM om;
+
+ om = create_om(lcd, dpy, rdb, res_name, res_class);
+ if (om == NULL)
+ return (XOM) NULL;
+
+ if (init_om(om) == False)
+ goto err;
+
+ return om;
+
+err:
+ close_om(om);
+
+ return (XOM) NULL;
+}
+
+Bool
+_XInitOM(
+ XLCd lcd)
+{
+ lcd->methods->open_om = _XomGenericOpenOM;
+
+ return True;
+}