aboutsummaryrefslogtreecommitdiff
path: root/libX11/modules/im
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-07-08 08:36:18 +0000
committermarha <marha@users.sourceforge.net>2010-07-08 08:36:18 +0000
commit29c7981777a6fa7d962977d2a7bdce68c116206d (patch)
tree78ed3f1b4d5c559fa6fa0e8fc3dbdc51c8c1f321 /libX11/modules/im
parentc23b5379fd9f4da7bcd627e973abb6868274fc75 (diff)
parentd1e8cd61e0fa02a5b415a5c161b355c95f45ae14 (diff)
downloadvcxsrv-29c7981777a6fa7d962977d2a7bdce68c116206d.tar.gz
vcxsrv-29c7981777a6fa7d962977d2a7bdce68c116206d.tar.bz2
vcxsrv-29c7981777a6fa7d962977d2a7bdce68c116206d.zip
svn merge ^/branches/released .
Diffstat (limited to 'libX11/modules/im')
-rw-r--r--libX11/modules/im/ximcp/imDefFlt.c835
-rw-r--r--libX11/modules/im/ximcp/imDefIm.c4091
-rw-r--r--libX11/modules/im/ximcp/imDefLkup.c2337
-rw-r--r--libX11/modules/im/ximcp/imEvToWire.c1578
-rw-r--r--libX11/modules/im/ximcp/imExten.c1153
-rw-r--r--libX11/modules/im/ximcp/imInsClbk.c577
-rw-r--r--libX11/modules/im/ximcp/imLcFlt.c231
-rw-r--r--libX11/modules/im/ximcp/imLcGIc.c95
-rw-r--r--libX11/modules/im/ximcp/imTrX.c1021
-rw-r--r--libX11/modules/im/ximcp/imTrans.c635
10 files changed, 6271 insertions, 6282 deletions
diff --git a/libX11/modules/im/ximcp/imDefFlt.c b/libX11/modules/im/ximcp/imDefFlt.c
index 9dad08872..3de28be4f 100644
--- a/libX11/modules/im/ximcp/imDefFlt.c
+++ b/libX11/modules/im/ximcp/imDefFlt.c
@@ -1,418 +1,417 @@
-/******************************************************************
-
- 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>
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include "Xutil.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-Private long
-_XimTriggerCheck(
- Xim im,
- XKeyEvent *ev,
- INT32 len,
- CARD32 *keylist)
-{
- register long i;
- KeySym keysym;
- CARD32 buf32[BUFSIZE/4];
- char *buf = (char *)buf32;
- int modifier;
- int modifier_mask;
- CARD32 min_len = sizeof(CARD32) /* sizeof keysym */
- + sizeof(CARD32) /* sizeof modifier */
- + sizeof(CARD32); /* sizeof modifier mask */
-
- XLookupString(ev, buf, BUFSIZE, &keysym, NULL);
- if (!keysym)
- return -1;
-
- for (i = 0; len >= min_len; i += 3, len -= min_len) {
- modifier = keylist[i + 1];
- modifier_mask = keylist[i + 2];
- if (((KeySym)keylist[i] == keysym)
- && ((ev->state & modifier_mask) == modifier))
- return i;
- }
- return -1;
-}
-
-Private long
-_XimTriggerOnCheck(
- Xim im,
- XKeyEvent *ev)
-{
- return _XimTriggerCheck(im, ev, (INT32)im->private.proto.im_onkeylist[0],
- &im->private.proto.im_onkeylist[1]);
-}
-
-Private long
-_XimTriggerOffCheck(
- Xim im,
- XKeyEvent *ev)
-{
- return _XimTriggerCheck(im, ev, (INT32)im->private.proto.im_offkeylist[0],
- &im->private.proto.im_offkeylist[1]);
-}
-
-Private Bool
-_XimOnKeysCheck(
- Xic ic,
- XKeyEvent *ev)
-{
- Xim im = (Xim)ic->core.im;
- long idx;
-
- if (IS_DYNAMIC_EVENT_FLOW(ic->core.im) &&
- im->private.proto.im_onkeylist &&
- im->private.proto.im_onkeylist[0]) {
- if ((idx = _XimTriggerOnCheck(im, ev)) >= 0) {
- (void)_XimTriggerNotify(im, ic, 0, (CARD32)idx); /* Trigger on */
- return True;
- }
- }
- return False;
-}
-
-Private Bool
-_XimOffKeysCheck(
- Xic ic,
- XKeyEvent *ev)
-{
- Xim im = (Xim)ic->core.im;
- long idx;
-
- if (IS_DYNAMIC_EVENT_FLOW(ic->core.im) &&
- im->private.proto.im_offkeylist &&
- im->private.proto.im_offkeylist[0]) {
- if ((idx = _XimTriggerOffCheck(im, ev)) >= 0) {
- _XimTriggerNotify(im, ic, 1, (CARD32)idx); /* Trigger off */
- return True;
- }
- }
- return False;
-}
-
-Private void
-_XimPendingFilter(
- Xic ic)
-{
- Xim im = (Xim)ic->core.im;
-
- if (IS_NEED_SYNC_REPLY(ic)) {
- (void)_XimProcSyncReply(im, ic);
- UNMARK_NEED_SYNC_REPLY(ic);
- }
- return;
-}
-
-Private Bool
-_XimProtoKeypressFilter(
- Xic ic,
- XKeyEvent *ev)
-{
-#ifdef XIM_CONNECTABLE
- Xim im = (Xim)ic->core.im;
-#endif
-
- if (IS_FABLICATED(ic)) {
- _XimPendingFilter(ic);
- UNMARK_FABLICATED(ic);
- return NOTFILTERD;
- }
-
- if (IS_NEGLECT_EVENT(ic, KeyPressMask))
- return FILTERD;
-
-#ifdef XIM_CONNECTABLE
- if (!IS_IC_CONNECTED(ic)) {
- if (IS_CONNECTABLE(im)) {
- if (_XimConnectServer(im)) {
- if (!_XimReCreateIC(ic)) {
- _XimDelayModeSetAttr(im);
- return NOTFILTERD;
- }
- } else {
- return NOTFILTERD;
- }
- } else {
- return NOTFILTERD;
- }
- }
-#else
- if (!IS_IC_CONNECTED(ic))
- return NOTFILTERD;
-#endif /* XIM_CONNECTABLE */
-
- if (!IS_FORWARD_EVENT(ic, KeyPressMask)) {
- if (_XimOnKeysCheck(ic, ev))
- return FILTERD;
- return NOTFILTERD;
- }
- if (_XimOffKeysCheck(ic, ev))
- return FILTERD;
-
- if (_XimForwardEvent(ic, (XEvent *)ev,
- IS_SYNCHRONOUS_EVENT(ic, KeyPressMask)))
- return FILTERD;
-
- return NOTFILTERD;
-}
-
-Private Bool
-_XimFilterKeypress(
- Display *d,
- Window w,
- XEvent *ev,
- XPointer client_data)
-{
- return _XimProtoKeypressFilter((Xic)client_data, (XKeyEvent *)ev );
-}
-
-Private Bool
-_XimProtoKeyreleaseFilter(
- Xic ic,
- XKeyEvent *ev)
-{
-#ifdef XIM_CONNECTABLE
- Xim im = (Xim)ic->core.im;
-#endif
-
- if (IS_FABLICATED(ic)) {
- _XimPendingFilter(ic);
- UNMARK_FABLICATED(ic);
- return NOTFILTERD;
- }
-
- if (IS_NEGLECT_EVENT(ic, KeyReleaseMask))
- return FILTERD;
-
-#ifdef XIM_CONNECTABLE
- if (!IS_IC_CONNECTED(ic)) {
- if (IS_CONNECTABLE(im)) {
- if (_XimConnectServer(im)) {
- if (!_XimReCreateIC(ic)) {
- _XimDelayModeSetAttr(im);
- return NOTFILTERD;
- }
- } else {
- return NOTFILTERD;
- }
- } else {
- return NOTFILTERD;
- }
- }
-#else
- if (!IS_IC_CONNECTED(ic))
- return NOTFILTERD;
-#endif /* XIM_CONNECTABLE */
-
- if (!IS_FORWARD_EVENT(ic, KeyReleaseMask)) {
- if (_XimOnKeysCheck(ic, ev))
- return FILTERD;
- return NOTFILTERD;
- }
- if (_XimOffKeysCheck(ic, ev))
- return FILTERD;
-
- if (_XimForwardEvent(ic, (XEvent *)ev,
- IS_SYNCHRONOUS_EVENT(ic, KeyPressMask)))
- return FILTERD;
-
- return NOTFILTERD;
-}
-
-Private Bool
-_XimFilterKeyrelease(
- Display *d,
- Window w,
- XEvent *ev,
- XPointer client_data)
-{
- return _XimProtoKeyreleaseFilter((Xic)client_data, (XKeyEvent *)ev);
-}
-
-Private void
-_XimRegisterKeyPressFilter(
- Xic ic)
-{
- if (ic->core.focus_window) {
- if (!(ic->private.proto.registed_filter_event & KEYPRESS_MASK)) {
- _XRegisterFilterByType (ic->core.im->core.display,
- ic->core.focus_window,
- KeyPress, KeyPress,
- _XimFilterKeypress,
- (XPointer)ic);
- ic->private.proto.registed_filter_event |= KEYPRESS_MASK;
- }
- }
- return;
-}
-
-Private void
-_XimRegisterKeyReleaseFilter(
- Xic ic)
-{
- if (ic->core.focus_window) {
- if (!(ic->private.proto.registed_filter_event & KEYRELEASE_MASK)) {
- _XRegisterFilterByType (ic->core.im->core.display,
- ic->core.focus_window,
- KeyRelease, KeyRelease,
- _XimFilterKeyrelease,
- (XPointer)ic);
- ic->private.proto.registed_filter_event |= KEYRELEASE_MASK;
- }
- }
- return;
-}
-
-Private void
-_XimUnregisterKeyPressFilter(
- Xic ic)
-{
- if (ic->core.focus_window) {
- if (ic->private.proto.registed_filter_event & KEYPRESS_MASK) {
- _XUnregisterFilter (ic->core.im->core.display,
- ic->core.focus_window,
- _XimFilterKeypress,
- (XPointer)ic);
- ic->private.proto.registed_filter_event &= ~KEYPRESS_MASK;
- }
- }
- return;
-}
-
-Private void
-_XimUnregisterKeyReleaseFilter(
- Xic ic)
-{
- if (ic->core.focus_window) {
- if (ic->private.proto.registed_filter_event & KEYRELEASE_MASK) {
- _XUnregisterFilter (ic->core.im->core.display,
- ic->core.focus_window,
- _XimFilterKeyrelease,
- (XPointer)ic);
- ic->private.proto.registed_filter_event &= ~KEYRELEASE_MASK;
- }
- }
- return;
-}
-
-Public void
-_XimRegisterFilter(
- Xic ic)
-{
- _XimRegisterKeyPressFilter(ic);
- if (IS_FORWARD_EVENT(ic, KeyReleaseMask))
- _XimRegisterKeyReleaseFilter(ic);
- return;
-}
-
-Public void
-_XimUnregisterFilter(
- Xic ic)
-{
- _XimUnregisterKeyPressFilter(ic);
- _XimUnregisterKeyReleaseFilter(ic);
- return;
-}
-
-Public void
-_XimReregisterFilter(
- Xic ic)
-{
- if (IS_FORWARD_EVENT(ic, KeyReleaseMask))
- _XimRegisterKeyReleaseFilter(ic);
- else
- _XimUnregisterKeyReleaseFilter(ic);
-
- return;
-}
-
-Private Bool
-_XimFilterServerDestroy(
- Display *d,
- Window w,
- XEvent *ev,
- XPointer client_data)
-{
- Xim im = (Xim)client_data;
-
- if (ev->type == DestroyNotify) {
- UNMARK_SERVER_CONNECTED(im);
-#ifdef XIM_CONNECTABLE
- if (!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
- _XimServerReconectableDestroy();
- return True;
- }
-#endif /* XIM_CONNECTABLE */
- _XimServerDestroy(im);
- }
- return True;
-}
-
-Public void
-_XimRegisterServerFilter(
- Xim im)
-{
- if (im->private.proto.im_window) {
- if (!(im->private.proto.registed_filter_event & DESTROYNOTIFY_MASK)) {
- _XRegisterFilterByMask(im->core.display,
- im->private.proto.im_window,
- StructureNotifyMask,
- _XimFilterServerDestroy,
- (XPointer)im);
- XSelectInput(im->core.display, im->private.proto.im_window,
- StructureNotifyMask);
- im->private.proto.registed_filter_event |= DESTROYNOTIFY_MASK;
- }
- }
- return;
-}
-
-Public void
-_XimUnregisterServerFilter(
- Xim im)
-{
- if (im->private.proto.im_window) {
- if (im->private.proto.registed_filter_event & DESTROYNOTIFY_MASK) {
- _XUnregisterFilter(im->core.display,
- im->private.proto.im_window,
- _XimFilterServerDestroy,
- (XPointer)im);
- im->private.proto.registed_filter_event &= ~DESTROYNOTIFY_MASK;
- }
- }
- return;
-}
-
+/******************************************************************
+
+ 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 "Xutil.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Private long
+_XimTriggerCheck(
+ Xim im,
+ XKeyEvent *ev,
+ INT32 len,
+ CARD32 *keylist)
+{
+ register long i;
+ KeySym keysym;
+ CARD32 buf32[BUFSIZE/4];
+ char *buf = (char *)buf32;
+ int modifier;
+ int modifier_mask;
+ CARD32 min_len = sizeof(CARD32) /* sizeof keysym */
+ + sizeof(CARD32) /* sizeof modifier */
+ + sizeof(CARD32); /* sizeof modifier mask */
+
+ XLookupString(ev, buf, BUFSIZE, &keysym, NULL);
+ if (!keysym)
+ return -1;
+
+ for (i = 0; len >= min_len; i += 3, len -= min_len) {
+ modifier = keylist[i + 1];
+ modifier_mask = keylist[i + 2];
+ if (((KeySym)keylist[i] == keysym)
+ && ((ev->state & modifier_mask) == modifier))
+ return i;
+ }
+ return -1;
+}
+
+Private long
+_XimTriggerOnCheck(
+ Xim im,
+ XKeyEvent *ev)
+{
+ return _XimTriggerCheck(im, ev, (INT32)im->private.proto.im_onkeylist[0],
+ &im->private.proto.im_onkeylist[1]);
+}
+
+Private long
+_XimTriggerOffCheck(
+ Xim im,
+ XKeyEvent *ev)
+{
+ return _XimTriggerCheck(im, ev, (INT32)im->private.proto.im_offkeylist[0],
+ &im->private.proto.im_offkeylist[1]);
+}
+
+Private Bool
+_XimOnKeysCheck(
+ Xic ic,
+ XKeyEvent *ev)
+{
+ Xim im = (Xim)ic->core.im;
+ long idx;
+
+ if (IS_DYNAMIC_EVENT_FLOW(ic->core.im) &&
+ im->private.proto.im_onkeylist &&
+ im->private.proto.im_onkeylist[0]) {
+ if ((idx = _XimTriggerOnCheck(im, ev)) >= 0) {
+ (void)_XimTriggerNotify(im, ic, 0, (CARD32)idx); /* Trigger on */
+ return True;
+ }
+ }
+ return False;
+}
+
+Private Bool
+_XimOffKeysCheck(
+ Xic ic,
+ XKeyEvent *ev)
+{
+ Xim im = (Xim)ic->core.im;
+ long idx;
+
+ if (IS_DYNAMIC_EVENT_FLOW(ic->core.im) &&
+ im->private.proto.im_offkeylist &&
+ im->private.proto.im_offkeylist[0]) {
+ if ((idx = _XimTriggerOffCheck(im, ev)) >= 0) {
+ _XimTriggerNotify(im, ic, 1, (CARD32)idx); /* Trigger off */
+ return True;
+ }
+ }
+ return False;
+}
+
+Private void
+_XimPendingFilter(
+ Xic ic)
+{
+ Xim im = (Xim)ic->core.im;
+
+ if (IS_NEED_SYNC_REPLY(ic)) {
+ (void)_XimProcSyncReply(im, ic);
+ UNMARK_NEED_SYNC_REPLY(ic);
+ }
+ return;
+}
+
+Private Bool
+_XimProtoKeypressFilter(
+ Xic ic,
+ XKeyEvent *ev)
+{
+#ifdef XIM_CONNECTABLE
+ Xim im = (Xim)ic->core.im;
+#endif
+
+ if (IS_FABLICATED(ic)) {
+ _XimPendingFilter(ic);
+ UNMARK_FABLICATED(ic);
+ return NOTFILTERD;
+ }
+
+ if (IS_NEGLECT_EVENT(ic, KeyPressMask))
+ return FILTERD;
+
+#ifdef XIM_CONNECTABLE
+ if (!IS_IC_CONNECTED(ic)) {
+ if (IS_CONNECTABLE(im)) {
+ if (_XimConnectServer(im)) {
+ if (!_XimReCreateIC(ic)) {
+ _XimDelayModeSetAttr(im);
+ return NOTFILTERD;
+ }
+ } else {
+ return NOTFILTERD;
+ }
+ } else {
+ return NOTFILTERD;
+ }
+ }
+#else
+ if (!IS_IC_CONNECTED(ic))
+ return NOTFILTERD;
+#endif /* XIM_CONNECTABLE */
+
+ if (!IS_FORWARD_EVENT(ic, KeyPressMask)) {
+ if (_XimOnKeysCheck(ic, ev))
+ return FILTERD;
+ return NOTFILTERD;
+ }
+ if (_XimOffKeysCheck(ic, ev))
+ return FILTERD;
+
+ if (_XimForwardEvent(ic, (XEvent *)ev,
+ IS_SYNCHRONOUS_EVENT(ic, KeyPressMask)))
+ return FILTERD;
+
+ return NOTFILTERD;
+}
+
+Private Bool
+_XimFilterKeypress(
+ Display *d,
+ Window w,
+ XEvent *ev,
+ XPointer client_data)
+{
+ return _XimProtoKeypressFilter((Xic)client_data, (XKeyEvent *)ev );
+}
+
+Private Bool
+_XimProtoKeyreleaseFilter(
+ Xic ic,
+ XKeyEvent *ev)
+{
+#ifdef XIM_CONNECTABLE
+ Xim im = (Xim)ic->core.im;
+#endif
+
+ if (IS_FABLICATED(ic)) {
+ _XimPendingFilter(ic);
+ UNMARK_FABLICATED(ic);
+ return NOTFILTERD;
+ }
+
+ if (IS_NEGLECT_EVENT(ic, KeyReleaseMask))
+ return FILTERD;
+
+#ifdef XIM_CONNECTABLE
+ if (!IS_IC_CONNECTED(ic)) {
+ if (IS_CONNECTABLE(im)) {
+ if (_XimConnectServer(im)) {
+ if (!_XimReCreateIC(ic)) {
+ _XimDelayModeSetAttr(im);
+ return NOTFILTERD;
+ }
+ } else {
+ return NOTFILTERD;
+ }
+ } else {
+ return NOTFILTERD;
+ }
+ }
+#else
+ if (!IS_IC_CONNECTED(ic))
+ return NOTFILTERD;
+#endif /* XIM_CONNECTABLE */
+
+ if (!IS_FORWARD_EVENT(ic, KeyReleaseMask)) {
+ if (_XimOnKeysCheck(ic, ev))
+ return FILTERD;
+ return NOTFILTERD;
+ }
+ if (_XimOffKeysCheck(ic, ev))
+ return FILTERD;
+
+ if (_XimForwardEvent(ic, (XEvent *)ev,
+ IS_SYNCHRONOUS_EVENT(ic, KeyPressMask)))
+ return FILTERD;
+
+ return NOTFILTERD;
+}
+
+Private Bool
+_XimFilterKeyrelease(
+ Display *d,
+ Window w,
+ XEvent *ev,
+ XPointer client_data)
+{
+ return _XimProtoKeyreleaseFilter((Xic)client_data, (XKeyEvent *)ev);
+}
+
+Private void
+_XimRegisterKeyPressFilter(
+ Xic ic)
+{
+ if (ic->core.focus_window) {
+ if (!(ic->private.proto.registed_filter_event & KEYPRESS_MASK)) {
+ _XRegisterFilterByType (ic->core.im->core.display,
+ ic->core.focus_window,
+ KeyPress, KeyPress,
+ _XimFilterKeypress,
+ (XPointer)ic);
+ ic->private.proto.registed_filter_event |= KEYPRESS_MASK;
+ }
+ }
+ return;
+}
+
+Private void
+_XimRegisterKeyReleaseFilter(
+ Xic ic)
+{
+ if (ic->core.focus_window) {
+ if (!(ic->private.proto.registed_filter_event & KEYRELEASE_MASK)) {
+ _XRegisterFilterByType (ic->core.im->core.display,
+ ic->core.focus_window,
+ KeyRelease, KeyRelease,
+ _XimFilterKeyrelease,
+ (XPointer)ic);
+ ic->private.proto.registed_filter_event |= KEYRELEASE_MASK;
+ }
+ }
+ return;
+}
+
+Private void
+_XimUnregisterKeyPressFilter(
+ Xic ic)
+{
+ if (ic->core.focus_window) {
+ if (ic->private.proto.registed_filter_event & KEYPRESS_MASK) {
+ _XUnregisterFilter (ic->core.im->core.display,
+ ic->core.focus_window,
+ _XimFilterKeypress,
+ (XPointer)ic);
+ ic->private.proto.registed_filter_event &= ~KEYPRESS_MASK;
+ }
+ }
+ return;
+}
+
+Private void
+_XimUnregisterKeyReleaseFilter(
+ Xic ic)
+{
+ if (ic->core.focus_window) {
+ if (ic->private.proto.registed_filter_event & KEYRELEASE_MASK) {
+ _XUnregisterFilter (ic->core.im->core.display,
+ ic->core.focus_window,
+ _XimFilterKeyrelease,
+ (XPointer)ic);
+ ic->private.proto.registed_filter_event &= ~KEYRELEASE_MASK;
+ }
+ }
+ return;
+}
+
+Public void
+_XimRegisterFilter(
+ Xic ic)
+{
+ _XimRegisterKeyPressFilter(ic);
+ if (IS_FORWARD_EVENT(ic, KeyReleaseMask))
+ _XimRegisterKeyReleaseFilter(ic);
+ return;
+}
+
+Public void
+_XimUnregisterFilter(
+ Xic ic)
+{
+ _XimUnregisterKeyPressFilter(ic);
+ _XimUnregisterKeyReleaseFilter(ic);
+ return;
+}
+
+Public void
+_XimReregisterFilter(
+ Xic ic)
+{
+ if (IS_FORWARD_EVENT(ic, KeyReleaseMask))
+ _XimRegisterKeyReleaseFilter(ic);
+ else
+ _XimUnregisterKeyReleaseFilter(ic);
+
+ return;
+}
+
+Private Bool
+_XimFilterServerDestroy(
+ Display *d,
+ Window w,
+ XEvent *ev,
+ XPointer client_data)
+{
+ Xim im = (Xim)client_data;
+
+ if (ev->type == DestroyNotify) {
+ UNMARK_SERVER_CONNECTED(im);
+#ifdef XIM_CONNECTABLE
+ if (!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
+ _XimServerReconectableDestroy();
+ return True;
+ }
+#endif /* XIM_CONNECTABLE */
+ _XimServerDestroy(im);
+ }
+ return True;
+}
+
+Public void
+_XimRegisterServerFilter(
+ Xim im)
+{
+ if (im->private.proto.im_window) {
+ if (!(im->private.proto.registed_filter_event & DESTROYNOTIFY_MASK)) {
+ _XRegisterFilterByMask(im->core.display,
+ im->private.proto.im_window,
+ StructureNotifyMask,
+ _XimFilterServerDestroy,
+ (XPointer)im);
+ XSelectInput(im->core.display, im->private.proto.im_window,
+ StructureNotifyMask);
+ im->private.proto.registed_filter_event |= DESTROYNOTIFY_MASK;
+ }
+ }
+ return;
+}
+
+Public void
+_XimUnregisterServerFilter(
+ Xim im)
+{
+ if (im->private.proto.im_window) {
+ if (im->private.proto.registed_filter_event & DESTROYNOTIFY_MASK) {
+ _XUnregisterFilter(im->core.display,
+ im->private.proto.im_window,
+ _XimFilterServerDestroy,
+ (XPointer)im);
+ im->private.proto.registed_filter_event &= ~DESTROYNOTIFY_MASK;
+ }
+ }
+ return;
+}
+
diff --git a/libX11/modules/im/ximcp/imDefIm.c b/libX11/modules/im/ximcp/imDefIm.c
index aa623eca6..ddcfc3bf6 100644
--- a/libX11/modules/im/ximcp/imDefIm.c
+++ b/libX11/modules/im/ximcp/imDefIm.c
@@ -1,2046 +1,2045 @@
-/*
- * Copyright 1990, 1991, 1992 Sun Microsystems, Inc. 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>
-#define NEED_EVENTS
-#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))) {
- if (name_ptr)
- Xfree(name_ptr);
- return False;
- }
-
- 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))) {
- if (name_ptr)
- Xfree(name_ptr);
- if (detail_ptr)
- Xfree(detail_ptr);
- return False;
- }
- 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);
- return False;
- }
- _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) {
- 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 (!(_XimGetEncoding(im, &buf_s[1], name_ptr, name_len,
- detail_ptr, detail_len))) {
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- if (name_ptr)
- Xfree(name_ptr);
- if (detail_ptr)
- Xfree(detail_ptr);
-
- if(reply != preply)
- Xfree(preply);
-
- return True;
-}
-
-#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 Sun Microsystems, Inc. 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))) {
+ if (name_ptr)
+ Xfree(name_ptr);
+ return False;
+ }
+
+ 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))) {
+ if (name_ptr)
+ Xfree(name_ptr);
+ if (detail_ptr)
+ Xfree(detail_ptr);
+ return False;
+ }
+ 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);
+ return False;
+ }
+ _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) {
+ 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 (!(_XimGetEncoding(im, &buf_s[1], name_ptr, name_len,
+ detail_ptr, detail_len))) {
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ if (name_ptr)
+ Xfree(name_ptr);
+ if (detail_ptr)
+ Xfree(detail_ptr);
+
+ if(reply != preply)
+ Xfree(preply);
+
+ return True;
+}
+
+#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 93631b65f..a269df062 100644
--- a/libX11/modules/im/ximcp/imDefLkup.c
+++ b/libX11/modules/im/ximcp/imDefLkup.c
@@ -1,1169 +1,1168 @@
-/******************************************************************
-
- 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>
-#define NEED_EVENTS
-#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)))
- 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)))
+ 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/imEvToWire.c b/libX11/modules/im/ximcp/imEvToWire.c
index bae5e7ffb..8dd263381 100644
--- a/libX11/modules/im/ximcp/imEvToWire.c
+++ b/libX11/modules/im/ximcp/imEvToWire.c
@@ -1,790 +1,788 @@
-/***********************************************************
-Copyright 1993 by Digital Equipment Corporation, Maynard, Massachusetts,
-
- 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 name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL 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.
-
-******************************************************************/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-#include <X11/Xlib.h>
-#undef NEED_EVENTS
-#include "Ximint.h"
-
-
-#define sw16(n, s) ((s) ? \
- (((n) << 8 & 0xff00) | \
- ((n) >> 8 & 0xff) \
- ) : n)
-
-#define sw32(n, s) ((s) ? \
- (((n) << 24 & 0xff000000) | \
- ((n) << 8 & 0xff0000) | \
- ((n) >> 8 & 0xff00) | \
- ((n) >> 24 & 0xff) \
- ) : n)
-
-Status
-_XimProtoEventToWire(
- register XEvent *re, /* pointer to where event should be reformatted */
- register xEvent *event, /* wire protocol event */
- Bool sw) /* swap byte? */
-{
- switch (event->u.u.type = re->type) {
- case KeyPress:
- case KeyRelease:
- {
- register XKeyEvent *ev = (XKeyEvent*) re;
- event->u.keyButtonPointer.root = sw32(ev->root, sw);
- event->u.keyButtonPointer.event =
- sw32(ev->window, sw);
- event->u.keyButtonPointer.child =
- sw32(ev->subwindow, sw);
- event->u.keyButtonPointer.time = sw32(ev->time, sw);
- event->u.keyButtonPointer.eventX = sw16(ev->x, sw) ;
- event->u.keyButtonPointer.eventY = sw16(ev->y, sw) ;
- event->u.keyButtonPointer.rootX =
- sw16(ev->x_root, sw);
- event->u.keyButtonPointer.rootY =
- sw16(ev->y_root, sw);
- event->u.keyButtonPointer.state = sw16(ev->state, sw);
- event->u.keyButtonPointer.sameScreen = ev->same_screen;
- event->u.u.detail = ev->keycode;
- }
- break;
- case ButtonPress:
- case ButtonRelease:
- {
- register XButtonEvent *ev = (XButtonEvent *) re;
- event->u.keyButtonPointer.root = sw32(ev->root, sw);
- event->u.keyButtonPointer.event = sw32(ev->window, sw);
- event->u.keyButtonPointer.child = sw32(ev->subwindow, sw);
- event->u.keyButtonPointer.time = sw32(ev->time, sw);
- event->u.keyButtonPointer.eventX = sw16(ev->x, sw);
- event->u.keyButtonPointer.eventY = sw16(ev->y, sw);
- event->u.keyButtonPointer.rootX = sw16(ev->x_root, sw);
- event->u.keyButtonPointer.rootY = sw16(ev->y_root, sw);
- event->u.keyButtonPointer.state = sw16(ev->state, sw);
- event->u.keyButtonPointer.sameScreen = ev->same_screen;
- event->u.u.detail = ev->button;
- }
- break;
- case MotionNotify:
- {
- register XMotionEvent *ev = (XMotionEvent *)re;
- event->u.keyButtonPointer.root = sw32(ev->root, sw);
- event->u.keyButtonPointer.event = sw32(ev->window, sw);
- event->u.keyButtonPointer.child = sw32(ev->subwindow, sw);
- event->u.keyButtonPointer.time = sw32(ev->time, sw);
- event->u.keyButtonPointer.eventX= sw16(ev->x, sw);
- event->u.keyButtonPointer.eventY= sw16(ev->y, sw);
- event->u.keyButtonPointer.rootX = sw16(ev->x_root, sw);
- event->u.keyButtonPointer.rootY = sw16(ev->y_root, sw);
- event->u.keyButtonPointer.state = sw16(ev->state, sw);
- event->u.keyButtonPointer.sameScreen= ev->same_screen;
- event->u.u.detail = ev->is_hint;
- }
- break;
- case EnterNotify:
- case LeaveNotify:
- {
- register XCrossingEvent *ev = (XCrossingEvent *) re;
- event->u.enterLeave.root = sw32(ev->root, sw);
- event->u.enterLeave.event = sw32(ev->window, sw);
- event->u.enterLeave.child = sw32(ev->subwindow, sw);
- event->u.enterLeave.time = sw32(ev->time, sw);
- event->u.enterLeave.eventX = sw16(ev->x, sw);
- event->u.enterLeave.eventY = sw16(ev->y, sw);
- event->u.enterLeave.rootX = sw16(ev->x_root, sw);
- event->u.enterLeave.rootY = sw16(ev->y_root, sw);
- event->u.enterLeave.state = sw16(ev->state, sw);
- event->u.enterLeave.mode = ev->mode;
- event->u.enterLeave.flags = 0;
- if (ev->same_screen) {
- event->u.enterLeave.flags |= ELFlagSameScreen;
- }
- if (ev->focus) {
- event->u.enterLeave.flags |= ELFlagFocus;
- }
- event->u.u.detail = ev->detail;
- }
- break;
- case FocusIn:
- case FocusOut:
- {
- register XFocusChangeEvent *ev = (XFocusChangeEvent *) re;
- event->u.focus.window = sw32(ev->window, sw);
- event->u.focus.mode = ev->mode;
- event->u.u.detail = ev->detail;
- }
- break;
- case KeymapNotify:
- {
- register XKeymapEvent *ev = (XKeymapEvent *) re;
- memcpy((char *)(((xKeymapEvent *) event)->map),
- &ev->key_vector[1],
- sizeof (((xKeymapEvent *) event)->map));
- }
- break;
- case Expose:
- {
- register XExposeEvent *ev = (XExposeEvent *) re;
- event->u.expose.window = sw32(ev->window, sw);
- event->u.expose.x = sw16(ev->x, sw);
- event->u.expose.y = sw16(ev->y, sw);
- event->u.expose.width = sw16(ev->width, sw);
- event->u.expose.height = sw16(ev->height, sw);
- event->u.expose.count = sw16(ev->count, sw);
- }
- break;
- case GraphicsExpose:
- {
- register XGraphicsExposeEvent *ev =
- (XGraphicsExposeEvent *) re;
- event->u.graphicsExposure.drawable = sw32(ev->drawable, sw);
- event->u.graphicsExposure.x = sw16(ev->x, sw);
- event->u.graphicsExposure.y = sw16(ev->y, sw);
- event->u.graphicsExposure.width = sw16(ev->width, sw);
- event->u.graphicsExposure.height = sw16(ev->height, sw);
- event->u.graphicsExposure.count = sw16(ev->count, sw);
- event->u.graphicsExposure.majorEvent= ev->major_code;
- event->u.graphicsExposure.minorEvent= sw16(ev->minor_code, sw);
- }
- break;
- case NoExpose:
- {
- register XNoExposeEvent *ev = (XNoExposeEvent *) re;
- event->u.noExposure.drawable = sw32(ev->drawable, sw);
- event->u.noExposure.majorEvent = ev->major_code;
- event->u.noExposure.minorEvent = sw16(ev->minor_code, sw);
- }
- break;
- case VisibilityNotify:
- {
- register XVisibilityEvent *ev = (XVisibilityEvent *) re;
- event->u.visibility.window = sw32(ev->window, sw);
- event->u.visibility.state = ev->state;
- }
- break;
- case CreateNotify:
- {
- register XCreateWindowEvent *ev =
- (XCreateWindowEvent *) re;
- event->u.createNotify.window = sw32(ev->window, sw);
- event->u.createNotify.parent = sw32(ev->parent, sw);
- event->u.createNotify.x = sw16(ev->x, sw);
- event->u.createNotify.y = sw16(ev->y, sw);
- event->u.createNotify.width = sw16(ev->width, sw);
- event->u.createNotify.height = sw16(ev->height, sw);
- event->u.createNotify.borderWidth = sw16(ev->border_width, sw);
- event->u.createNotify.override = ev->override_redirect;
- }
- break;
- case DestroyNotify:
- {
- register XDestroyWindowEvent *ev =
- (XDestroyWindowEvent *) re;
- event->u.destroyNotify.window = sw32(ev->window, sw);
- event->u.destroyNotify.event = sw32(ev->event, sw);
- }
- break;
- case UnmapNotify:
- {
- register XUnmapEvent *ev = (XUnmapEvent *) re;
- event->u.unmapNotify.window = sw32(ev->window, sw);
- event->u.unmapNotify.event = sw32(ev->event, sw);
- event->u.unmapNotify.fromConfigure = ev->from_configure;
- }
- break;
- case MapNotify:
- {
- register XMapEvent *ev = (XMapEvent *) re;
- event->u.mapNotify.window = sw32(ev->window, sw);
- event->u.mapNotify.event = sw32(ev->event, sw);
- event->u.mapNotify.override = ev->override_redirect;
- }
- break;
- case MapRequest:
- {
- register XMapRequestEvent *ev = (XMapRequestEvent *) re;
- event->u.mapRequest.window = sw32(ev->window, sw);
- event->u.mapRequest.parent = sw32(ev->parent, sw);
- }
- break;
- case ReparentNotify:
- {
- register XReparentEvent *ev = (XReparentEvent *) re;
- event->u.reparent.window = sw32(ev->window, sw);
- event->u.reparent.event = sw32(ev->event, sw);
- event->u.reparent.parent = sw32(ev->parent, sw);
- event->u.reparent.x = sw16(ev->x, sw);
- event->u.reparent.y = sw16(ev->y, sw);
- event->u.reparent.override = ev->override_redirect;
- }
- break;
- case ConfigureNotify:
- {
- register XConfigureEvent *ev = (XConfigureEvent *) re;
- event->u.configureNotify.window = sw32(ev->window, sw);
- event->u.configureNotify.event = sw32(ev->event, sw);
- event->u.configureNotify.aboveSibling = sw32(ev->above, sw);
- event->u.configureNotify.x = sw16(ev->x, sw);
- event->u.configureNotify.y = sw16(ev->y, sw);
- event->u.configureNotify.width = sw16(ev->width, sw);
- event->u.configureNotify.height = sw16(ev->height, sw);
- event->u.configureNotify.borderWidth= sw16(ev->border_width, sw);
- event->u.configureNotify.override = ev->override_redirect;
- }
- break;
- case ConfigureRequest:
- {
- register XConfigureRequestEvent *ev =
- (XConfigureRequestEvent *) re;
- event->u.configureRequest.window = sw32(ev->window, sw);
- event->u.configureRequest.parent = sw32(ev->parent, sw);
- event->u.configureRequest.sibling = sw32(ev->above, sw);
- event->u.configureRequest.x = sw16(ev->x, sw);
- event->u.configureRequest.y = sw16(ev->y, sw);
- event->u.configureRequest.width = sw16(ev->width, sw);
- event->u.configureRequest.height = sw16(ev->height, sw);
- event->u.configureRequest.borderWidth= sw16(ev->border_width, sw);
- event->u.configureRequest.valueMask= sw16(ev->value_mask, sw);
- event->u.u.detail = ev->detail;
- }
- break;
- case GravityNotify:
- {
- register XGravityEvent *ev = (XGravityEvent *) re;
- event->u.gravity.window = sw32(ev->window, sw);
- event->u.gravity.event = sw32(ev->event, sw);
- event->u.gravity.x = sw16(ev->x, sw);
- event->u.gravity.y = sw16(ev->y, sw);
- }
- break;
- case ResizeRequest:
- {
- register XResizeRequestEvent *ev =
- (XResizeRequestEvent *) re;
- event->u.resizeRequest.window = sw32(ev->window, sw);
- event->u.resizeRequest.width = sw16(ev->width, sw);
- event->u.resizeRequest.height = sw16(ev->height, sw);
- }
- break;
- case CirculateNotify:
- {
- register XCirculateEvent *ev = (XCirculateEvent *) re;
- event->u.circulate.window = sw32(ev->window, sw);
- event->u.circulate.event = sw32(ev->event, sw);
- event->u.circulate.place = ev->place;
- }
- break;
- case CirculateRequest:
- {
- register XCirculateRequestEvent *ev =
- (XCirculateRequestEvent *) re;
- event->u.circulate.window = sw32(ev->window, sw);
- event->u.circulate.event = sw32(ev->parent, sw);
- event->u.circulate.place = ev->place;
- }
- break;
- case PropertyNotify:
- {
- register XPropertyEvent *ev = (XPropertyEvent *) re;
- event->u.property.window = sw32(ev->window, sw);
- event->u.property.atom = sw32(ev->atom, sw);
- event->u.property.time = sw32(ev->time, sw);
- event->u.property.state = ev->state;
- }
- break;
- case SelectionClear:
- {
- register XSelectionClearEvent *ev =
- (XSelectionClearEvent *) re;
- event->u.selectionClear.window = sw32(ev->window, sw);
- event->u.selectionClear.atom = sw32(ev->selection, sw);
- event->u.selectionClear.time = sw32(ev->time, sw);
- }
- break;
- case SelectionRequest:
- {
- register XSelectionRequestEvent *ev =
- (XSelectionRequestEvent *) re;
- event->u.selectionRequest.owner = sw32(ev->owner, sw);
- event->u.selectionRequest.requestor = sw32(ev->requestor, sw);
- event->u.selectionRequest.selection = sw32(ev->selection, sw);
- event->u.selectionRequest.target = sw32(ev->target, sw);
- event->u.selectionRequest.property = sw32(ev->property, sw);
- event->u.selectionRequest.time = sw32(ev->time, sw);
- }
- break;
- case SelectionNotify:
- {
- register XSelectionEvent *ev = (XSelectionEvent *) re;
- event->u.selectionNotify.requestor = sw32(ev->requestor, sw);
- event->u.selectionNotify.selection = sw32(ev->selection, sw);
- event->u.selectionNotify.target = sw32(ev->target, sw);
- event->u.selectionNotify.property = sw32(ev->property, sw);
- event->u.selectionNotify.time = sw32(ev->time, sw);
- }
- break;
- case ColormapNotify:
- {
- register XColormapEvent *ev = (XColormapEvent *) re;
- event->u.colormap.window = sw32(ev->window, sw);
- event->u.colormap.colormap = sw32(ev->colormap, sw);
- event->u.colormap.new = ev->new;
- event->u.colormap.state = ev->state;
- }
- break;
- case ClientMessage:
- {
- register int i;
- register XClientMessageEvent *ev
- = (XClientMessageEvent *) re;
- event->u.clientMessage.window = sw32(ev->window, sw);
- event->u.u.detail = ev->format;
- switch (ev->format) {
- case 8:
- event->u.clientMessage.u.b.type = sw32(ev->message_type, sw);
- for (i = 0; i < 20; i++)
- event->u.clientMessage.u.b.bytes[i] = ev->data.b[i];
- break;
- case 16:
- event->u.clientMessage.u.s.type = sw32(ev->message_type, sw);
- event->u.clientMessage.u.s.shorts0 = sw16(ev->data.s[0], sw);
- event->u.clientMessage.u.s.shorts1 = sw16(ev->data.s[1], sw);
- event->u.clientMessage.u.s.shorts2 = sw16(ev->data.s[2], sw);
- event->u.clientMessage.u.s.shorts3 = sw16(ev->data.s[3], sw);
- event->u.clientMessage.u.s.shorts4 = sw16(ev->data.s[4], sw);
- event->u.clientMessage.u.s.shorts5 = sw16(ev->data.s[5], sw);
- event->u.clientMessage.u.s.shorts6 = sw16(ev->data.s[6], sw);
- event->u.clientMessage.u.s.shorts7 = sw16(ev->data.s[7], sw);
- event->u.clientMessage.u.s.shorts8 = sw16(ev->data.s[8], sw);
- event->u.clientMessage.u.s.shorts9 = sw16(ev->data.s[9], sw);
- break;
- case 32:
- event->u.clientMessage.u.l.type = sw32(ev->message_type, sw);
- event->u.clientMessage.u.l.longs0 = sw32(ev->data.l[0], sw);
- event->u.clientMessage.u.l.longs1 = sw32(ev->data.l[1], sw);
- event->u.clientMessage.u.l.longs2 = sw32(ev->data.l[2], sw);
- event->u.clientMessage.u.l.longs3 = sw32(ev->data.l[3], sw);
- event->u.clientMessage.u.l.longs4 = sw32(ev->data.l[4], sw);
- break;
- default:
- /* client passing bogus data, let server complain */
- break;
- }
- }
- break;
- case MappingNotify:
- {
- register XMappingEvent *ev = (XMappingEvent *) re;
- event->u.mappingNotify.firstKeyCode = ev->first_keycode;
- event->u.mappingNotify.request = ev->request;
- event->u.mappingNotify.count = ev->count;
- }
- break;
-
- default:
- return(0);
- }
- /* Common process */
- if (((XAnyEvent *)re)->send_event)
- event->u.u.type |= 0x80;
- event->u.u.sequenceNumber =
- ((XAnyEvent *)re)->serial & ~((unsigned long)0xffff);
- event->u.u.sequenceNumber = sw16(event->u.u.sequenceNumber, sw);
- return(1);
-}
-
-
-/*
- * reformat a wire event into an XEvent structure of the right type.
- */
-Bool
-_XimProtoWireToEvent(
- register XEvent *re, /* pointer to where event should be reformatted */
- register xEvent *event, /* wire protocol event */
- Bool sw) /* swap byte? */
-{
-
- re->type = event->u.u.type & 0x7f;
- ((XAnyEvent *)re)->serial = sw16(event->u.u.sequenceNumber, sw);
- ((XAnyEvent *)re)->send_event = ((event->u.u.type & 0x80) != 0);
- ((XAnyEvent *)re)->display = NULL;
-
- /* Ignore the leading bit of the event type since it is set when a
- client sends an event rather than the server. */
-
- switch (event-> u.u.type & 0177) {
- case KeyPress:
- case KeyRelease:
- {
- register XKeyEvent *ev = (XKeyEvent*) re;
- ev->root = sw32(event->u.keyButtonPointer.root, sw);
- ev->window = sw32(event->u.keyButtonPointer.event, sw);
- ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
- ev->time = sw32(event->u.keyButtonPointer.time, sw);
- ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
- ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
- ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
- ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
- ev->state = sw16(event->u.keyButtonPointer.state, sw);
- ev->same_screen = event->u.keyButtonPointer.sameScreen;
- ev->keycode = event->u.u.detail;
- }
- break;
- case ButtonPress:
- case ButtonRelease:
- {
- register XButtonEvent *ev = (XButtonEvent *) re;
- ev->root = sw32(event->u.keyButtonPointer.root, sw);
- ev->window = sw32(event->u.keyButtonPointer.event, sw);
- ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
- ev->time = sw32(event->u.keyButtonPointer.time, sw);
- ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
- ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
- ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
- ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
- ev->state = sw16(event->u.keyButtonPointer.state, sw);
- ev->same_screen = event->u.keyButtonPointer.sameScreen;
- ev->button = event->u.u.detail;
- }
- break;
- case MotionNotify:
- {
- register XMotionEvent *ev = (XMotionEvent *)re;
- ev->root = sw32(event->u.keyButtonPointer.root, sw);
- ev->window = sw32(event->u.keyButtonPointer.event, sw);
- ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
- ev->time = sw32(event->u.keyButtonPointer.time, sw);
- ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
- ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
- ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
- ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
- ev->state = sw16(event->u.keyButtonPointer.state, sw);
- ev->same_screen = event->u.keyButtonPointer.sameScreen;
- ev->is_hint = event->u.u.detail;
- }
- break;
- case EnterNotify:
- case LeaveNotify:
- {
- register XCrossingEvent *ev = (XCrossingEvent *) re;
- ev->root = sw32(event->u.enterLeave.root, sw);
- ev->window = sw32(event->u.enterLeave.event, sw);
- ev->subwindow = sw32(event->u.enterLeave.child, sw);
- ev->time = sw32(event->u.enterLeave.time, sw);
- ev->x = cvtINT16toInt(sw16(event->u.enterLeave.eventX, sw));
- ev->y = cvtINT16toInt(sw16(event->u.enterLeave.eventY, sw));
- ev->x_root = cvtINT16toInt(sw16(event->u.enterLeave.rootX, sw));
- ev->y_root = cvtINT16toInt(sw16(event->u.enterLeave.rootY, sw));
- ev->state = sw16(event->u.enterLeave.state, sw);
- ev->mode = event->u.enterLeave.mode;
- ev->same_screen = (event->u.enterLeave.flags &
- ELFlagSameScreen) && True;
- ev->focus = (event->u.enterLeave.flags &
- ELFlagFocus) && True;
- ev->detail = event->u.u.detail;
- }
- break;
- case FocusIn:
- case FocusOut:
- {
- register XFocusChangeEvent *ev = (XFocusChangeEvent *) re;
- ev->window = sw32(event->u.focus.window, sw);
- ev->mode = event->u.focus.mode;
- ev->detail = event->u.u.detail;
- }
- break;
- case KeymapNotify:
- {
- register XKeymapEvent *ev = (XKeymapEvent *) re;
- ev->window = None;
- memcpy(&ev->key_vector[1],
- (char *)((xKeymapEvent *) event)->map,
- sizeof (((xKeymapEvent *) event)->map));
- }
- break;
- case Expose:
- {
- register XExposeEvent *ev = (XExposeEvent *) re;
- ev->window = sw32(event->u.expose.window, sw);
- ev->x = sw16(event->u.expose.x, sw);
- ev->y = sw16(event->u.expose.y, sw);
- ev->width = sw16(event->u.expose.width, sw);
- ev->height = sw16(event->u.expose.height, sw);
- ev->count = sw16(event->u.expose.count, sw);
- }
- break;
- case GraphicsExpose:
- {
- register XGraphicsExposeEvent *ev =
- (XGraphicsExposeEvent *) re;
- ev->drawable = sw32(event->u.graphicsExposure.drawable, sw);
- ev->x = sw16(event->u.graphicsExposure.x, sw);
- ev->y = sw16(event->u.graphicsExposure.y, sw);
- ev->width = sw16(event->u.graphicsExposure.width, sw);
- ev->height = sw16(event->u.graphicsExposure.height, sw);
- ev->count = sw16(event->u.graphicsExposure.count, sw);
- ev->major_code = event->u.graphicsExposure.majorEvent;
- ev->minor_code = sw16(event->u.graphicsExposure.minorEvent, sw);
- }
- break;
- case NoExpose:
- {
- register XNoExposeEvent *ev = (XNoExposeEvent *) re;
- ev->drawable = sw32(event->u.noExposure.drawable, sw);
- ev->major_code = event->u.noExposure.majorEvent;
- ev->minor_code = sw16(event->u.noExposure.minorEvent, sw);
- }
- break;
- case VisibilityNotify:
- {
- register XVisibilityEvent *ev = (XVisibilityEvent *) re;
- ev->window = sw32(event->u.visibility.window, sw);
- ev->state = event->u.visibility.state;
- }
- break;
- case CreateNotify:
- {
- register XCreateWindowEvent *ev =
- (XCreateWindowEvent *) re;
- ev->window = sw32(event->u.createNotify.window, sw);
- ev->parent = sw32(event->u.createNotify.parent, sw);
- ev->x = cvtINT16toInt(sw16(event->u.createNotify.x, sw));
- ev->y = cvtINT16toInt(sw16(event->u.createNotify.y, sw));
- ev->width = sw16(event->u.createNotify.width, sw);
- ev->height = sw16(event->u.createNotify.height, sw);
- ev->border_width = sw16(event->u.createNotify.borderWidth, sw);
- ev->override_redirect = event->u.createNotify.override;
- }
- break;
- case DestroyNotify:
- {
- register XDestroyWindowEvent *ev =
- (XDestroyWindowEvent *) re;
- ev->window = sw32(event->u.destroyNotify.window, sw);
- ev->event = sw32(event->u.destroyNotify.event, sw);
- }
- break;
- case UnmapNotify:
- {
- register XUnmapEvent *ev = (XUnmapEvent *) re;
- ev->window = sw32(event->u.unmapNotify.window, sw);
- ev->event = sw32(event->u.unmapNotify.event, sw);
- ev->from_configure = event->u.unmapNotify.fromConfigure;
- }
- break;
- case MapNotify:
- {
- register XMapEvent *ev = (XMapEvent *) re;
- ev->window = sw32(event->u.mapNotify.window, sw);
- ev->event = sw32(event->u.mapNotify.event, sw);
- ev->override_redirect = event->u.mapNotify.override;
- }
- break;
- case MapRequest:
- {
- register XMapRequestEvent *ev = (XMapRequestEvent *) re;
- ev->window = sw32(event->u.mapRequest.window, sw);
- ev->parent = sw32(event->u.mapRequest.parent, sw);
- }
- break;
- case ReparentNotify:
- {
- register XReparentEvent *ev = (XReparentEvent *) re;
- ev->event = sw32(event->u.reparent.event, sw);
- ev->window = sw32(event->u.reparent.window, sw);
- ev->parent = sw32(event->u.reparent.parent, sw);
- ev->x = cvtINT16toInt(sw16(event->u.reparent.x, sw));
- ev->y = cvtINT16toInt(sw16(event->u.reparent.y, sw));
- ev->override_redirect = event->u.reparent.override;
- }
- break;
- case ConfigureNotify:
- {
- register XConfigureEvent *ev = (XConfigureEvent *) re;
- ev->event = sw32(event->u.configureNotify.event, sw);
- ev->window = sw32(event->u.configureNotify.window, sw);
- ev->above = sw32(event->u.configureNotify.aboveSibling, sw);
- ev->x = cvtINT16toInt(sw16(event->u.configureNotify.x, sw));
- ev->y = cvtINT16toInt(sw16(event->u.configureNotify.y, sw));
- ev->width = sw16(event->u.configureNotify.width, sw);
- ev->height = sw16(event->u.configureNotify.height, sw);
- ev->border_width = sw16(event->u.configureNotify.borderWidth, sw);
- ev->override_redirect = event->u.configureNotify.override;
- }
- break;
- case ConfigureRequest:
- {
- register XConfigureRequestEvent *ev =
- (XConfigureRequestEvent *) re;
- ev->window = sw32(event->u.configureRequest.window, sw);
- ev->parent = sw32(event->u.configureRequest.parent, sw);
- ev->above = sw32(event->u.configureRequest.sibling, sw);
- ev->x = cvtINT16toInt(sw16(event->u.configureRequest.x, sw));
- ev->y = cvtINT16toInt(sw16(event->u.configureRequest.y, sw));
- ev->width = sw16(event->u.configureRequest.width, sw);
- ev->height = sw16(event->u.configureRequest.height, sw);
- ev->border_width = sw16(event->u.configureRequest.borderWidth, sw);
- ev->value_mask = sw16(event->u.configureRequest.valueMask, sw);
- ev->detail = event->u.u.detail;
- }
- break;
- case GravityNotify:
- {
- register XGravityEvent *ev = (XGravityEvent *) re;
- ev->window = sw32(event->u.gravity.window, sw);
- ev->event = sw32(event->u.gravity.event, sw);
- ev->x = cvtINT16toInt(sw16(event->u.gravity.x, sw));
- ev->y = cvtINT16toInt(sw16(event->u.gravity.y, sw));
- }
- break;
- case ResizeRequest:
- {
- register XResizeRequestEvent *ev =
- (XResizeRequestEvent *) re;
- ev->window = sw32(event->u.resizeRequest.window, sw);
- ev->width = sw16(event->u.resizeRequest.width, sw);
- ev->height = sw16(event->u.resizeRequest.height, sw);
- }
- break;
- case CirculateNotify:
- {
- register XCirculateEvent *ev = (XCirculateEvent *) re;
- ev->window = sw32(event->u.circulate.window, sw);
- ev->event = sw32(event->u.circulate.event, sw);
- ev->place = event->u.circulate.place;
- }
- break;
- case CirculateRequest:
- {
- register XCirculateRequestEvent *ev =
- (XCirculateRequestEvent *) re;
- ev->window = sw32(event->u.circulate.window, sw);
- ev->parent = sw32(event->u.circulate.event, sw);
- ev->place = event->u.circulate.place;
- }
- break;
- case PropertyNotify:
- {
- register XPropertyEvent *ev = (XPropertyEvent *) re;
- ev->window = sw32(event->u.property.window, sw);
- ev->atom = sw32(event->u.property.atom, sw);
- ev->time = sw32(event->u.property.time, sw);
- ev->state = event->u.property.state;
- }
- break;
- case SelectionClear:
- {
- register XSelectionClearEvent *ev =
- (XSelectionClearEvent *) re;
- ev->window = sw32(event->u.selectionClear.window, sw);
- ev->selection = sw32(event->u.selectionClear.atom, sw);
- ev->time = sw32(event->u.selectionClear.time, sw);
- }
- break;
- case SelectionRequest:
- {
- register XSelectionRequestEvent *ev =
- (XSelectionRequestEvent *) re;
- ev->owner = sw32(event->u.selectionRequest.owner, sw);
- ev->requestor = sw32(event->u.selectionRequest.requestor, sw);
- ev->selection = sw32(event->u.selectionRequest.selection, sw);
- ev->target = sw32(event->u.selectionRequest.target, sw);
- ev->property = sw32(event->u.selectionRequest.property, sw);
- ev->time = sw32(event->u.selectionRequest.time, sw);
- }
- break;
- case SelectionNotify:
- {
- register XSelectionEvent *ev = (XSelectionEvent *) re;
- ev->requestor = sw32(event->u.selectionNotify.requestor, sw);
- ev->selection = sw32(event->u.selectionNotify.selection, sw);
- ev->target = sw32(event->u.selectionNotify.target, sw);
- ev->property = sw32(event->u.selectionNotify.property, sw);
- ev->time = sw32(event->u.selectionNotify.time, sw);
- }
- break;
- case ColormapNotify:
- {
- register XColormapEvent *ev = (XColormapEvent *) re;
- ev->window = sw32(event->u.colormap.window, sw);
- ev->colormap = sw32(event->u.colormap.colormap, sw);
- ev->new = event->u.colormap.new;
- ev->state = event->u.colormap.state;
- }
- break;
- case ClientMessage:
- {
- register int i;
- register XClientMessageEvent *ev
- = (XClientMessageEvent *) re;
- ev->window = sw32(event->u.clientMessage.window, sw);
- ev->format = event->u.u.detail;
- switch (ev->format) {
- case 8:
- ev->message_type = sw32(event->u.clientMessage.u.b.type, sw);
- for (i = 0; i < 20; i++)
- ev->data.b[i] = event->u.clientMessage.u.b.bytes[i];
- break;
- case 16:
- ev->message_type = sw32(event->u.clientMessage.u.s.type, sw);
- ev->data.s[0] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts0, sw));
- ev->data.s[1] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts1, sw));
- ev->data.s[2] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts2, sw));
- ev->data.s[3] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts3, sw));
- ev->data.s[4] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts4, sw));
- ev->data.s[5] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts5, sw));
- ev->data.s[6] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts6, sw));
- ev->data.s[7] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts7, sw));
- ev->data.s[8] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts8, sw));
- ev->data.s[9] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts9, sw));
- break;
- case 32:
- ev->message_type = sw32(event->u.clientMessage.u.l.type, sw);
- ev->data.l[0] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs0, sw));
- ev->data.l[1] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs1, sw));
- ev->data.l[2] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs2, sw));
- ev->data.l[3] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs3, sw));
- ev->data.l[4] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs4, sw));
- break;
- default: /* XXX should never occur */
- break;
- }
- }
- break;
- case MappingNotify:
- {
- register XMappingEvent *ev = (XMappingEvent *)re;
- ev->window = 0;
- ev->first_keycode = event->u.mappingNotify.firstKeyCode;
- ev->request = event->u.mappingNotify.request;
- ev->count = event->u.mappingNotify.count;
- }
- break;
- default:
- return(False);
- }
- return(True);
-}
+/***********************************************************
+Copyright 1993 by Digital Equipment Corporation, Maynard, Massachusetts,
+
+ 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 name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL 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.
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/Xlib.h>
+#include "Ximint.h"
+
+
+#define sw16(n, s) ((s) ? \
+ (((n) << 8 & 0xff00) | \
+ ((n) >> 8 & 0xff) \
+ ) : n)
+
+#define sw32(n, s) ((s) ? \
+ (((n) << 24 & 0xff000000) | \
+ ((n) << 8 & 0xff0000) | \
+ ((n) >> 8 & 0xff00) | \
+ ((n) >> 24 & 0xff) \
+ ) : n)
+
+Status
+_XimProtoEventToWire(
+ register XEvent *re, /* pointer to where event should be reformatted */
+ register xEvent *event, /* wire protocol event */
+ Bool sw) /* swap byte? */
+{
+ switch (event->u.u.type = re->type) {
+ case KeyPress:
+ case KeyRelease:
+ {
+ register XKeyEvent *ev = (XKeyEvent*) re;
+ event->u.keyButtonPointer.root = sw32(ev->root, sw);
+ event->u.keyButtonPointer.event =
+ sw32(ev->window, sw);
+ event->u.keyButtonPointer.child =
+ sw32(ev->subwindow, sw);
+ event->u.keyButtonPointer.time = sw32(ev->time, sw);
+ event->u.keyButtonPointer.eventX = sw16(ev->x, sw) ;
+ event->u.keyButtonPointer.eventY = sw16(ev->y, sw) ;
+ event->u.keyButtonPointer.rootX =
+ sw16(ev->x_root, sw);
+ event->u.keyButtonPointer.rootY =
+ sw16(ev->y_root, sw);
+ event->u.keyButtonPointer.state = sw16(ev->state, sw);
+ event->u.keyButtonPointer.sameScreen = ev->same_screen;
+ event->u.u.detail = ev->keycode;
+ }
+ break;
+ case ButtonPress:
+ case ButtonRelease:
+ {
+ register XButtonEvent *ev = (XButtonEvent *) re;
+ event->u.keyButtonPointer.root = sw32(ev->root, sw);
+ event->u.keyButtonPointer.event = sw32(ev->window, sw);
+ event->u.keyButtonPointer.child = sw32(ev->subwindow, sw);
+ event->u.keyButtonPointer.time = sw32(ev->time, sw);
+ event->u.keyButtonPointer.eventX = sw16(ev->x, sw);
+ event->u.keyButtonPointer.eventY = sw16(ev->y, sw);
+ event->u.keyButtonPointer.rootX = sw16(ev->x_root, sw);
+ event->u.keyButtonPointer.rootY = sw16(ev->y_root, sw);
+ event->u.keyButtonPointer.state = sw16(ev->state, sw);
+ event->u.keyButtonPointer.sameScreen = ev->same_screen;
+ event->u.u.detail = ev->button;
+ }
+ break;
+ case MotionNotify:
+ {
+ register XMotionEvent *ev = (XMotionEvent *)re;
+ event->u.keyButtonPointer.root = sw32(ev->root, sw);
+ event->u.keyButtonPointer.event = sw32(ev->window, sw);
+ event->u.keyButtonPointer.child = sw32(ev->subwindow, sw);
+ event->u.keyButtonPointer.time = sw32(ev->time, sw);
+ event->u.keyButtonPointer.eventX= sw16(ev->x, sw);
+ event->u.keyButtonPointer.eventY= sw16(ev->y, sw);
+ event->u.keyButtonPointer.rootX = sw16(ev->x_root, sw);
+ event->u.keyButtonPointer.rootY = sw16(ev->y_root, sw);
+ event->u.keyButtonPointer.state = sw16(ev->state, sw);
+ event->u.keyButtonPointer.sameScreen= ev->same_screen;
+ event->u.u.detail = ev->is_hint;
+ }
+ break;
+ case EnterNotify:
+ case LeaveNotify:
+ {
+ register XCrossingEvent *ev = (XCrossingEvent *) re;
+ event->u.enterLeave.root = sw32(ev->root, sw);
+ event->u.enterLeave.event = sw32(ev->window, sw);
+ event->u.enterLeave.child = sw32(ev->subwindow, sw);
+ event->u.enterLeave.time = sw32(ev->time, sw);
+ event->u.enterLeave.eventX = sw16(ev->x, sw);
+ event->u.enterLeave.eventY = sw16(ev->y, sw);
+ event->u.enterLeave.rootX = sw16(ev->x_root, sw);
+ event->u.enterLeave.rootY = sw16(ev->y_root, sw);
+ event->u.enterLeave.state = sw16(ev->state, sw);
+ event->u.enterLeave.mode = ev->mode;
+ event->u.enterLeave.flags = 0;
+ if (ev->same_screen) {
+ event->u.enterLeave.flags |= ELFlagSameScreen;
+ }
+ if (ev->focus) {
+ event->u.enterLeave.flags |= ELFlagFocus;
+ }
+ event->u.u.detail = ev->detail;
+ }
+ break;
+ case FocusIn:
+ case FocusOut:
+ {
+ register XFocusChangeEvent *ev = (XFocusChangeEvent *) re;
+ event->u.focus.window = sw32(ev->window, sw);
+ event->u.focus.mode = ev->mode;
+ event->u.u.detail = ev->detail;
+ }
+ break;
+ case KeymapNotify:
+ {
+ register XKeymapEvent *ev = (XKeymapEvent *) re;
+ memcpy((char *)(((xKeymapEvent *) event)->map),
+ &ev->key_vector[1],
+ sizeof (((xKeymapEvent *) event)->map));
+ }
+ break;
+ case Expose:
+ {
+ register XExposeEvent *ev = (XExposeEvent *) re;
+ event->u.expose.window = sw32(ev->window, sw);
+ event->u.expose.x = sw16(ev->x, sw);
+ event->u.expose.y = sw16(ev->y, sw);
+ event->u.expose.width = sw16(ev->width, sw);
+ event->u.expose.height = sw16(ev->height, sw);
+ event->u.expose.count = sw16(ev->count, sw);
+ }
+ break;
+ case GraphicsExpose:
+ {
+ register XGraphicsExposeEvent *ev =
+ (XGraphicsExposeEvent *) re;
+ event->u.graphicsExposure.drawable = sw32(ev->drawable, sw);
+ event->u.graphicsExposure.x = sw16(ev->x, sw);
+ event->u.graphicsExposure.y = sw16(ev->y, sw);
+ event->u.graphicsExposure.width = sw16(ev->width, sw);
+ event->u.graphicsExposure.height = sw16(ev->height, sw);
+ event->u.graphicsExposure.count = sw16(ev->count, sw);
+ event->u.graphicsExposure.majorEvent= ev->major_code;
+ event->u.graphicsExposure.minorEvent= sw16(ev->minor_code, sw);
+ }
+ break;
+ case NoExpose:
+ {
+ register XNoExposeEvent *ev = (XNoExposeEvent *) re;
+ event->u.noExposure.drawable = sw32(ev->drawable, sw);
+ event->u.noExposure.majorEvent = ev->major_code;
+ event->u.noExposure.minorEvent = sw16(ev->minor_code, sw);
+ }
+ break;
+ case VisibilityNotify:
+ {
+ register XVisibilityEvent *ev = (XVisibilityEvent *) re;
+ event->u.visibility.window = sw32(ev->window, sw);
+ event->u.visibility.state = ev->state;
+ }
+ break;
+ case CreateNotify:
+ {
+ register XCreateWindowEvent *ev =
+ (XCreateWindowEvent *) re;
+ event->u.createNotify.window = sw32(ev->window, sw);
+ event->u.createNotify.parent = sw32(ev->parent, sw);
+ event->u.createNotify.x = sw16(ev->x, sw);
+ event->u.createNotify.y = sw16(ev->y, sw);
+ event->u.createNotify.width = sw16(ev->width, sw);
+ event->u.createNotify.height = sw16(ev->height, sw);
+ event->u.createNotify.borderWidth = sw16(ev->border_width, sw);
+ event->u.createNotify.override = ev->override_redirect;
+ }
+ break;
+ case DestroyNotify:
+ {
+ register XDestroyWindowEvent *ev =
+ (XDestroyWindowEvent *) re;
+ event->u.destroyNotify.window = sw32(ev->window, sw);
+ event->u.destroyNotify.event = sw32(ev->event, sw);
+ }
+ break;
+ case UnmapNotify:
+ {
+ register XUnmapEvent *ev = (XUnmapEvent *) re;
+ event->u.unmapNotify.window = sw32(ev->window, sw);
+ event->u.unmapNotify.event = sw32(ev->event, sw);
+ event->u.unmapNotify.fromConfigure = ev->from_configure;
+ }
+ break;
+ case MapNotify:
+ {
+ register XMapEvent *ev = (XMapEvent *) re;
+ event->u.mapNotify.window = sw32(ev->window, sw);
+ event->u.mapNotify.event = sw32(ev->event, sw);
+ event->u.mapNotify.override = ev->override_redirect;
+ }
+ break;
+ case MapRequest:
+ {
+ register XMapRequestEvent *ev = (XMapRequestEvent *) re;
+ event->u.mapRequest.window = sw32(ev->window, sw);
+ event->u.mapRequest.parent = sw32(ev->parent, sw);
+ }
+ break;
+ case ReparentNotify:
+ {
+ register XReparentEvent *ev = (XReparentEvent *) re;
+ event->u.reparent.window = sw32(ev->window, sw);
+ event->u.reparent.event = sw32(ev->event, sw);
+ event->u.reparent.parent = sw32(ev->parent, sw);
+ event->u.reparent.x = sw16(ev->x, sw);
+ event->u.reparent.y = sw16(ev->y, sw);
+ event->u.reparent.override = ev->override_redirect;
+ }
+ break;
+ case ConfigureNotify:
+ {
+ register XConfigureEvent *ev = (XConfigureEvent *) re;
+ event->u.configureNotify.window = sw32(ev->window, sw);
+ event->u.configureNotify.event = sw32(ev->event, sw);
+ event->u.configureNotify.aboveSibling = sw32(ev->above, sw);
+ event->u.configureNotify.x = sw16(ev->x, sw);
+ event->u.configureNotify.y = sw16(ev->y, sw);
+ event->u.configureNotify.width = sw16(ev->width, sw);
+ event->u.configureNotify.height = sw16(ev->height, sw);
+ event->u.configureNotify.borderWidth= sw16(ev->border_width, sw);
+ event->u.configureNotify.override = ev->override_redirect;
+ }
+ break;
+ case ConfigureRequest:
+ {
+ register XConfigureRequestEvent *ev =
+ (XConfigureRequestEvent *) re;
+ event->u.configureRequest.window = sw32(ev->window, sw);
+ event->u.configureRequest.parent = sw32(ev->parent, sw);
+ event->u.configureRequest.sibling = sw32(ev->above, sw);
+ event->u.configureRequest.x = sw16(ev->x, sw);
+ event->u.configureRequest.y = sw16(ev->y, sw);
+ event->u.configureRequest.width = sw16(ev->width, sw);
+ event->u.configureRequest.height = sw16(ev->height, sw);
+ event->u.configureRequest.borderWidth= sw16(ev->border_width, sw);
+ event->u.configureRequest.valueMask= sw16(ev->value_mask, sw);
+ event->u.u.detail = ev->detail;
+ }
+ break;
+ case GravityNotify:
+ {
+ register XGravityEvent *ev = (XGravityEvent *) re;
+ event->u.gravity.window = sw32(ev->window, sw);
+ event->u.gravity.event = sw32(ev->event, sw);
+ event->u.gravity.x = sw16(ev->x, sw);
+ event->u.gravity.y = sw16(ev->y, sw);
+ }
+ break;
+ case ResizeRequest:
+ {
+ register XResizeRequestEvent *ev =
+ (XResizeRequestEvent *) re;
+ event->u.resizeRequest.window = sw32(ev->window, sw);
+ event->u.resizeRequest.width = sw16(ev->width, sw);
+ event->u.resizeRequest.height = sw16(ev->height, sw);
+ }
+ break;
+ case CirculateNotify:
+ {
+ register XCirculateEvent *ev = (XCirculateEvent *) re;
+ event->u.circulate.window = sw32(ev->window, sw);
+ event->u.circulate.event = sw32(ev->event, sw);
+ event->u.circulate.place = ev->place;
+ }
+ break;
+ case CirculateRequest:
+ {
+ register XCirculateRequestEvent *ev =
+ (XCirculateRequestEvent *) re;
+ event->u.circulate.window = sw32(ev->window, sw);
+ event->u.circulate.event = sw32(ev->parent, sw);
+ event->u.circulate.place = ev->place;
+ }
+ break;
+ case PropertyNotify:
+ {
+ register XPropertyEvent *ev = (XPropertyEvent *) re;
+ event->u.property.window = sw32(ev->window, sw);
+ event->u.property.atom = sw32(ev->atom, sw);
+ event->u.property.time = sw32(ev->time, sw);
+ event->u.property.state = ev->state;
+ }
+ break;
+ case SelectionClear:
+ {
+ register XSelectionClearEvent *ev =
+ (XSelectionClearEvent *) re;
+ event->u.selectionClear.window = sw32(ev->window, sw);
+ event->u.selectionClear.atom = sw32(ev->selection, sw);
+ event->u.selectionClear.time = sw32(ev->time, sw);
+ }
+ break;
+ case SelectionRequest:
+ {
+ register XSelectionRequestEvent *ev =
+ (XSelectionRequestEvent *) re;
+ event->u.selectionRequest.owner = sw32(ev->owner, sw);
+ event->u.selectionRequest.requestor = sw32(ev->requestor, sw);
+ event->u.selectionRequest.selection = sw32(ev->selection, sw);
+ event->u.selectionRequest.target = sw32(ev->target, sw);
+ event->u.selectionRequest.property = sw32(ev->property, sw);
+ event->u.selectionRequest.time = sw32(ev->time, sw);
+ }
+ break;
+ case SelectionNotify:
+ {
+ register XSelectionEvent *ev = (XSelectionEvent *) re;
+ event->u.selectionNotify.requestor = sw32(ev->requestor, sw);
+ event->u.selectionNotify.selection = sw32(ev->selection, sw);
+ event->u.selectionNotify.target = sw32(ev->target, sw);
+ event->u.selectionNotify.property = sw32(ev->property, sw);
+ event->u.selectionNotify.time = sw32(ev->time, sw);
+ }
+ break;
+ case ColormapNotify:
+ {
+ register XColormapEvent *ev = (XColormapEvent *) re;
+ event->u.colormap.window = sw32(ev->window, sw);
+ event->u.colormap.colormap = sw32(ev->colormap, sw);
+ event->u.colormap.new = ev->new;
+ event->u.colormap.state = ev->state;
+ }
+ break;
+ case ClientMessage:
+ {
+ register int i;
+ register XClientMessageEvent *ev
+ = (XClientMessageEvent *) re;
+ event->u.clientMessage.window = sw32(ev->window, sw);
+ event->u.u.detail = ev->format;
+ switch (ev->format) {
+ case 8:
+ event->u.clientMessage.u.b.type = sw32(ev->message_type, sw);
+ for (i = 0; i < 20; i++)
+ event->u.clientMessage.u.b.bytes[i] = ev->data.b[i];
+ break;
+ case 16:
+ event->u.clientMessage.u.s.type = sw32(ev->message_type, sw);
+ event->u.clientMessage.u.s.shorts0 = sw16(ev->data.s[0], sw);
+ event->u.clientMessage.u.s.shorts1 = sw16(ev->data.s[1], sw);
+ event->u.clientMessage.u.s.shorts2 = sw16(ev->data.s[2], sw);
+ event->u.clientMessage.u.s.shorts3 = sw16(ev->data.s[3], sw);
+ event->u.clientMessage.u.s.shorts4 = sw16(ev->data.s[4], sw);
+ event->u.clientMessage.u.s.shorts5 = sw16(ev->data.s[5], sw);
+ event->u.clientMessage.u.s.shorts6 = sw16(ev->data.s[6], sw);
+ event->u.clientMessage.u.s.shorts7 = sw16(ev->data.s[7], sw);
+ event->u.clientMessage.u.s.shorts8 = sw16(ev->data.s[8], sw);
+ event->u.clientMessage.u.s.shorts9 = sw16(ev->data.s[9], sw);
+ break;
+ case 32:
+ event->u.clientMessage.u.l.type = sw32(ev->message_type, sw);
+ event->u.clientMessage.u.l.longs0 = sw32(ev->data.l[0], sw);
+ event->u.clientMessage.u.l.longs1 = sw32(ev->data.l[1], sw);
+ event->u.clientMessage.u.l.longs2 = sw32(ev->data.l[2], sw);
+ event->u.clientMessage.u.l.longs3 = sw32(ev->data.l[3], sw);
+ event->u.clientMessage.u.l.longs4 = sw32(ev->data.l[4], sw);
+ break;
+ default:
+ /* client passing bogus data, let server complain */
+ break;
+ }
+ }
+ break;
+ case MappingNotify:
+ {
+ register XMappingEvent *ev = (XMappingEvent *) re;
+ event->u.mappingNotify.firstKeyCode = ev->first_keycode;
+ event->u.mappingNotify.request = ev->request;
+ event->u.mappingNotify.count = ev->count;
+ }
+ break;
+
+ default:
+ return(0);
+ }
+ /* Common process */
+ if (((XAnyEvent *)re)->send_event)
+ event->u.u.type |= 0x80;
+ event->u.u.sequenceNumber =
+ ((XAnyEvent *)re)->serial & ~((unsigned long)0xffff);
+ event->u.u.sequenceNumber = sw16(event->u.u.sequenceNumber, sw);
+ return(1);
+}
+
+
+/*
+ * reformat a wire event into an XEvent structure of the right type.
+ */
+Bool
+_XimProtoWireToEvent(
+ register XEvent *re, /* pointer to where event should be reformatted */
+ register xEvent *event, /* wire protocol event */
+ Bool sw) /* swap byte? */
+{
+
+ re->type = event->u.u.type & 0x7f;
+ ((XAnyEvent *)re)->serial = sw16(event->u.u.sequenceNumber, sw);
+ ((XAnyEvent *)re)->send_event = ((event->u.u.type & 0x80) != 0);
+ ((XAnyEvent *)re)->display = NULL;
+
+ /* Ignore the leading bit of the event type since it is set when a
+ client sends an event rather than the server. */
+
+ switch (event-> u.u.type & 0177) {
+ case KeyPress:
+ case KeyRelease:
+ {
+ register XKeyEvent *ev = (XKeyEvent*) re;
+ ev->root = sw32(event->u.keyButtonPointer.root, sw);
+ ev->window = sw32(event->u.keyButtonPointer.event, sw);
+ ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
+ ev->time = sw32(event->u.keyButtonPointer.time, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
+ ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
+ ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
+ ev->state = sw16(event->u.keyButtonPointer.state, sw);
+ ev->same_screen = event->u.keyButtonPointer.sameScreen;
+ ev->keycode = event->u.u.detail;
+ }
+ break;
+ case ButtonPress:
+ case ButtonRelease:
+ {
+ register XButtonEvent *ev = (XButtonEvent *) re;
+ ev->root = sw32(event->u.keyButtonPointer.root, sw);
+ ev->window = sw32(event->u.keyButtonPointer.event, sw);
+ ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
+ ev->time = sw32(event->u.keyButtonPointer.time, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
+ ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
+ ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
+ ev->state = sw16(event->u.keyButtonPointer.state, sw);
+ ev->same_screen = event->u.keyButtonPointer.sameScreen;
+ ev->button = event->u.u.detail;
+ }
+ break;
+ case MotionNotify:
+ {
+ register XMotionEvent *ev = (XMotionEvent *)re;
+ ev->root = sw32(event->u.keyButtonPointer.root, sw);
+ ev->window = sw32(event->u.keyButtonPointer.event, sw);
+ ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
+ ev->time = sw32(event->u.keyButtonPointer.time, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
+ ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
+ ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
+ ev->state = sw16(event->u.keyButtonPointer.state, sw);
+ ev->same_screen = event->u.keyButtonPointer.sameScreen;
+ ev->is_hint = event->u.u.detail;
+ }
+ break;
+ case EnterNotify:
+ case LeaveNotify:
+ {
+ register XCrossingEvent *ev = (XCrossingEvent *) re;
+ ev->root = sw32(event->u.enterLeave.root, sw);
+ ev->window = sw32(event->u.enterLeave.event, sw);
+ ev->subwindow = sw32(event->u.enterLeave.child, sw);
+ ev->time = sw32(event->u.enterLeave.time, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.enterLeave.eventX, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.enterLeave.eventY, sw));
+ ev->x_root = cvtINT16toInt(sw16(event->u.enterLeave.rootX, sw));
+ ev->y_root = cvtINT16toInt(sw16(event->u.enterLeave.rootY, sw));
+ ev->state = sw16(event->u.enterLeave.state, sw);
+ ev->mode = event->u.enterLeave.mode;
+ ev->same_screen = (event->u.enterLeave.flags &
+ ELFlagSameScreen) && True;
+ ev->focus = (event->u.enterLeave.flags &
+ ELFlagFocus) && True;
+ ev->detail = event->u.u.detail;
+ }
+ break;
+ case FocusIn:
+ case FocusOut:
+ {
+ register XFocusChangeEvent *ev = (XFocusChangeEvent *) re;
+ ev->window = sw32(event->u.focus.window, sw);
+ ev->mode = event->u.focus.mode;
+ ev->detail = event->u.u.detail;
+ }
+ break;
+ case KeymapNotify:
+ {
+ register XKeymapEvent *ev = (XKeymapEvent *) re;
+ ev->window = None;
+ memcpy(&ev->key_vector[1],
+ (char *)((xKeymapEvent *) event)->map,
+ sizeof (((xKeymapEvent *) event)->map));
+ }
+ break;
+ case Expose:
+ {
+ register XExposeEvent *ev = (XExposeEvent *) re;
+ ev->window = sw32(event->u.expose.window, sw);
+ ev->x = sw16(event->u.expose.x, sw);
+ ev->y = sw16(event->u.expose.y, sw);
+ ev->width = sw16(event->u.expose.width, sw);
+ ev->height = sw16(event->u.expose.height, sw);
+ ev->count = sw16(event->u.expose.count, sw);
+ }
+ break;
+ case GraphicsExpose:
+ {
+ register XGraphicsExposeEvent *ev =
+ (XGraphicsExposeEvent *) re;
+ ev->drawable = sw32(event->u.graphicsExposure.drawable, sw);
+ ev->x = sw16(event->u.graphicsExposure.x, sw);
+ ev->y = sw16(event->u.graphicsExposure.y, sw);
+ ev->width = sw16(event->u.graphicsExposure.width, sw);
+ ev->height = sw16(event->u.graphicsExposure.height, sw);
+ ev->count = sw16(event->u.graphicsExposure.count, sw);
+ ev->major_code = event->u.graphicsExposure.majorEvent;
+ ev->minor_code = sw16(event->u.graphicsExposure.minorEvent, sw);
+ }
+ break;
+ case NoExpose:
+ {
+ register XNoExposeEvent *ev = (XNoExposeEvent *) re;
+ ev->drawable = sw32(event->u.noExposure.drawable, sw);
+ ev->major_code = event->u.noExposure.majorEvent;
+ ev->minor_code = sw16(event->u.noExposure.minorEvent, sw);
+ }
+ break;
+ case VisibilityNotify:
+ {
+ register XVisibilityEvent *ev = (XVisibilityEvent *) re;
+ ev->window = sw32(event->u.visibility.window, sw);
+ ev->state = event->u.visibility.state;
+ }
+ break;
+ case CreateNotify:
+ {
+ register XCreateWindowEvent *ev =
+ (XCreateWindowEvent *) re;
+ ev->window = sw32(event->u.createNotify.window, sw);
+ ev->parent = sw32(event->u.createNotify.parent, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.createNotify.x, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.createNotify.y, sw));
+ ev->width = sw16(event->u.createNotify.width, sw);
+ ev->height = sw16(event->u.createNotify.height, sw);
+ ev->border_width = sw16(event->u.createNotify.borderWidth, sw);
+ ev->override_redirect = event->u.createNotify.override;
+ }
+ break;
+ case DestroyNotify:
+ {
+ register XDestroyWindowEvent *ev =
+ (XDestroyWindowEvent *) re;
+ ev->window = sw32(event->u.destroyNotify.window, sw);
+ ev->event = sw32(event->u.destroyNotify.event, sw);
+ }
+ break;
+ case UnmapNotify:
+ {
+ register XUnmapEvent *ev = (XUnmapEvent *) re;
+ ev->window = sw32(event->u.unmapNotify.window, sw);
+ ev->event = sw32(event->u.unmapNotify.event, sw);
+ ev->from_configure = event->u.unmapNotify.fromConfigure;
+ }
+ break;
+ case MapNotify:
+ {
+ register XMapEvent *ev = (XMapEvent *) re;
+ ev->window = sw32(event->u.mapNotify.window, sw);
+ ev->event = sw32(event->u.mapNotify.event, sw);
+ ev->override_redirect = event->u.mapNotify.override;
+ }
+ break;
+ case MapRequest:
+ {
+ register XMapRequestEvent *ev = (XMapRequestEvent *) re;
+ ev->window = sw32(event->u.mapRequest.window, sw);
+ ev->parent = sw32(event->u.mapRequest.parent, sw);
+ }
+ break;
+ case ReparentNotify:
+ {
+ register XReparentEvent *ev = (XReparentEvent *) re;
+ ev->event = sw32(event->u.reparent.event, sw);
+ ev->window = sw32(event->u.reparent.window, sw);
+ ev->parent = sw32(event->u.reparent.parent, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.reparent.x, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.reparent.y, sw));
+ ev->override_redirect = event->u.reparent.override;
+ }
+ break;
+ case ConfigureNotify:
+ {
+ register XConfigureEvent *ev = (XConfigureEvent *) re;
+ ev->event = sw32(event->u.configureNotify.event, sw);
+ ev->window = sw32(event->u.configureNotify.window, sw);
+ ev->above = sw32(event->u.configureNotify.aboveSibling, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.configureNotify.x, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.configureNotify.y, sw));
+ ev->width = sw16(event->u.configureNotify.width, sw);
+ ev->height = sw16(event->u.configureNotify.height, sw);
+ ev->border_width = sw16(event->u.configureNotify.borderWidth, sw);
+ ev->override_redirect = event->u.configureNotify.override;
+ }
+ break;
+ case ConfigureRequest:
+ {
+ register XConfigureRequestEvent *ev =
+ (XConfigureRequestEvent *) re;
+ ev->window = sw32(event->u.configureRequest.window, sw);
+ ev->parent = sw32(event->u.configureRequest.parent, sw);
+ ev->above = sw32(event->u.configureRequest.sibling, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.configureRequest.x, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.configureRequest.y, sw));
+ ev->width = sw16(event->u.configureRequest.width, sw);
+ ev->height = sw16(event->u.configureRequest.height, sw);
+ ev->border_width = sw16(event->u.configureRequest.borderWidth, sw);
+ ev->value_mask = sw16(event->u.configureRequest.valueMask, sw);
+ ev->detail = event->u.u.detail;
+ }
+ break;
+ case GravityNotify:
+ {
+ register XGravityEvent *ev = (XGravityEvent *) re;
+ ev->window = sw32(event->u.gravity.window, sw);
+ ev->event = sw32(event->u.gravity.event, sw);
+ ev->x = cvtINT16toInt(sw16(event->u.gravity.x, sw));
+ ev->y = cvtINT16toInt(sw16(event->u.gravity.y, sw));
+ }
+ break;
+ case ResizeRequest:
+ {
+ register XResizeRequestEvent *ev =
+ (XResizeRequestEvent *) re;
+ ev->window = sw32(event->u.resizeRequest.window, sw);
+ ev->width = sw16(event->u.resizeRequest.width, sw);
+ ev->height = sw16(event->u.resizeRequest.height, sw);
+ }
+ break;
+ case CirculateNotify:
+ {
+ register XCirculateEvent *ev = (XCirculateEvent *) re;
+ ev->window = sw32(event->u.circulate.window, sw);
+ ev->event = sw32(event->u.circulate.event, sw);
+ ev->place = event->u.circulate.place;
+ }
+ break;
+ case CirculateRequest:
+ {
+ register XCirculateRequestEvent *ev =
+ (XCirculateRequestEvent *) re;
+ ev->window = sw32(event->u.circulate.window, sw);
+ ev->parent = sw32(event->u.circulate.event, sw);
+ ev->place = event->u.circulate.place;
+ }
+ break;
+ case PropertyNotify:
+ {
+ register XPropertyEvent *ev = (XPropertyEvent *) re;
+ ev->window = sw32(event->u.property.window, sw);
+ ev->atom = sw32(event->u.property.atom, sw);
+ ev->time = sw32(event->u.property.time, sw);
+ ev->state = event->u.property.state;
+ }
+ break;
+ case SelectionClear:
+ {
+ register XSelectionClearEvent *ev =
+ (XSelectionClearEvent *) re;
+ ev->window = sw32(event->u.selectionClear.window, sw);
+ ev->selection = sw32(event->u.selectionClear.atom, sw);
+ ev->time = sw32(event->u.selectionClear.time, sw);
+ }
+ break;
+ case SelectionRequest:
+ {
+ register XSelectionRequestEvent *ev =
+ (XSelectionRequestEvent *) re;
+ ev->owner = sw32(event->u.selectionRequest.owner, sw);
+ ev->requestor = sw32(event->u.selectionRequest.requestor, sw);
+ ev->selection = sw32(event->u.selectionRequest.selection, sw);
+ ev->target = sw32(event->u.selectionRequest.target, sw);
+ ev->property = sw32(event->u.selectionRequest.property, sw);
+ ev->time = sw32(event->u.selectionRequest.time, sw);
+ }
+ break;
+ case SelectionNotify:
+ {
+ register XSelectionEvent *ev = (XSelectionEvent *) re;
+ ev->requestor = sw32(event->u.selectionNotify.requestor, sw);
+ ev->selection = sw32(event->u.selectionNotify.selection, sw);
+ ev->target = sw32(event->u.selectionNotify.target, sw);
+ ev->property = sw32(event->u.selectionNotify.property, sw);
+ ev->time = sw32(event->u.selectionNotify.time, sw);
+ }
+ break;
+ case ColormapNotify:
+ {
+ register XColormapEvent *ev = (XColormapEvent *) re;
+ ev->window = sw32(event->u.colormap.window, sw);
+ ev->colormap = sw32(event->u.colormap.colormap, sw);
+ ev->new = event->u.colormap.new;
+ ev->state = event->u.colormap.state;
+ }
+ break;
+ case ClientMessage:
+ {
+ register int i;
+ register XClientMessageEvent *ev
+ = (XClientMessageEvent *) re;
+ ev->window = sw32(event->u.clientMessage.window, sw);
+ ev->format = event->u.u.detail;
+ switch (ev->format) {
+ case 8:
+ ev->message_type = sw32(event->u.clientMessage.u.b.type, sw);
+ for (i = 0; i < 20; i++)
+ ev->data.b[i] = event->u.clientMessage.u.b.bytes[i];
+ break;
+ case 16:
+ ev->message_type = sw32(event->u.clientMessage.u.s.type, sw);
+ ev->data.s[0] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts0, sw));
+ ev->data.s[1] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts1, sw));
+ ev->data.s[2] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts2, sw));
+ ev->data.s[3] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts3, sw));
+ ev->data.s[4] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts4, sw));
+ ev->data.s[5] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts5, sw));
+ ev->data.s[6] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts6, sw));
+ ev->data.s[7] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts7, sw));
+ ev->data.s[8] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts8, sw));
+ ev->data.s[9] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts9, sw));
+ break;
+ case 32:
+ ev->message_type = sw32(event->u.clientMessage.u.l.type, sw);
+ ev->data.l[0] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs0, sw));
+ ev->data.l[1] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs1, sw));
+ ev->data.l[2] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs2, sw));
+ ev->data.l[3] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs3, sw));
+ ev->data.l[4] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs4, sw));
+ break;
+ default: /* XXX should never occur */
+ break;
+ }
+ }
+ break;
+ case MappingNotify:
+ {
+ register XMappingEvent *ev = (XMappingEvent *)re;
+ ev->window = 0;
+ ev->first_keycode = event->u.mappingNotify.firstKeyCode;
+ ev->request = event->u.mappingNotify.request;
+ ev->count = event->u.mappingNotify.count;
+ }
+ break;
+ default:
+ return(False);
+ }
+ return(True);
+}
diff --git a/libX11/modules/im/ximcp/imExten.c b/libX11/modules/im/ximcp/imExten.c
index 199368cbb..97309136e 100644
--- a/libX11/modules/im/ximcp/imExten.c
+++ b/libX11/modules/im/ximcp/imExten.c
@@ -1,577 +1,576 @@
-/******************************************************************
-
- 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>
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-/*
- * index of extensions
- */
-
-#define XIM_EXT_SET_EVENT_MASK_IDX 0
-#ifdef EXT_FORWARD
-#define XIM_EXT_FORWARD_KEYEVENT_IDX 1
-#endif
-#ifdef EXT_MOVE
-#define XIM_EXT_MOVE_IDX 2
-#endif
-
-typedef struct _XIM_QueryExtRec {
- Bool is_support;
- const char *name;
- int name_len;
- CARD16 major_opcode;
- CARD16 minor_opcode;
- int idx;
-} XIM_QueryExtRec;
-
-Private XIM_QueryExtRec extensions[] = {
- {False, "XIM_EXT_SET_EVENT_MASK", 0, 0, 0,
- XIM_EXT_SET_EVENT_MASK_IDX},
-#ifdef EXT_FORWARD
- {False, "XIM_EXT_FORWARD_KEYEVENT", 0, 0, 0,
- XIM_EXT_FORWARD_KEYEVENT_IDX},
-#endif
-#ifdef EXT_MOVE
- {False, "XIM_EXT_MOVE", 0, 0, 0, XIM_EXT_MOVE_IDX},
-#endif
- {False, NULL, 0, 0, 0, 0} /* dummy */
-};
-
-Private int
-_XimIsSupportExt(
- int idx)
-{
- register int i;
- int n = XIMNumber(extensions) - 1;
-
- for (i = 0; i < n; i++) {
- if (extensions[i].idx == idx) {
- if (extensions[i].is_support)
- return i;
- else
- break;
- }
- }
- return -1;
-}
-
-Private Bool
-_XimProcExtSetEventMask(
- Xim im,
- Xic ic,
- XPointer buf)
-{
- EVENTMASK *buf_l = (EVENTMASK *)buf;
- EVENTMASK select_mask = _XimGetWindowEventmask(ic);
-
- ic->private.proto.filter_event_mask = buf_l[0];
- ic->private.proto.intercept_event_mask = buf_l[1];
- ic->private.proto.select_event_mask = buf_l[2];
- ic->private.proto.forward_event_mask = buf_l[3];
- ic->private.proto.synchronous_event_mask = buf_l[4];
-
- select_mask &= ~ic->private.proto.intercept_event_mask;
- /* deselected event mask */
- select_mask |= ic->private.proto.select_event_mask;
- /* selected event mask */
- XSelectInput(im->core.display, ic->core.focus_window, select_mask);
- _XimReregisterFilter(ic);
-
- if (!(_XimProcSyncReply(im, ic)))
- return False;
- return True;
-}
-
-Private Bool
-_XimExtSetEventMaskCallback(
- 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)_XimProcExtSetEventMask(im, ic, (XPointer)&buf_s[2]);
- return True;
- }
- return False;
-}
-
-#ifdef EXT_FORWARD
-Private Bool
-_XimProcExtForwardKeyEvent(
- Xim im,
- Xic ic,
- XPointer buf)
-{
- CARD8 *buf_b = (CARD8 *)buf;
- CARD16 *buf_s = (CARD16 *)buf;
- CARD32 *buf_l = (CARD32 *)buf;
- XEvent ev;
- XKeyEvent *kev = (XKeyEvent *)&ev;
-
- bzero(&ev, sizeof(XEvent));
- kev->send_event = False;
- kev->display = im->core.display;
- kev->serial = buf_s[1]; /* sequence number */
- kev->type = buf_b[4] & 0x7f; /* xEvent.u.u.type */
- kev->keycode = buf_b[5]; /* Keycode */
- kev->state = buf_s[3]; /* state */
- kev->time = buf_l[2]; /* time */
-
- XPutBackEvent(im->core.display, &ev);
-
- _XimRespSyncReply(ic, buf_s[0]);
- MARK_FABLICATED(ic);
-
- return True;
-}
-
-Private Bool
-_XimExtForwardKeyEventCallback(
- 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)_XimProcExtForwardKeyEvent(im, ic, (XPointer)&buf_s[2]);
- return True;
- }
- return False;
-}
-
-Private Bool
-_XimExtForwardKeyEventCheck(
- 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))
- 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
-_XimExtForwardKeyEvent(
- Xic ic,
- XKeyEvent *ev,
- Bool sync)
-{
- Xim im = (Xim) ic->core.im;
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD8 *buf_b = &buf[XIM_HEADER_SIZE];
- CARD16 *buf_s = (CARD16 *)buf_b;
- CARD32 *buf_l = (CARD32 *)buf_b;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
- INT16 len;
- int idx;
-
- if ((idx = _XimIsSupportExt(XIM_EXT_FORWARD_KEYEVENT_IDX)) < 0)
- return False;
-
- 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));
- /* sequence number */
- buf_b[8] = ev->type; /* xEvent.u.u.type */
- buf_b[9] = ev->keycode; /* keycode */
- buf_s[5] = ev->state; /* state */
- buf_l[3] = ev->time; /* time */
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16) /* sizeof icid */
- + sizeof(BITMASK16) /* sizeof flag */
- + sizeof(CARD16) /* sizeof sequence number */
- + sizeof(BYTE) /* sizeof xEvent.u.u.type */
- + sizeof(BYTE) /* sizeof keycode */
- + sizeof(CARD16) /* sizeof state */
- + sizeof(CARD32); /* sizeof time */
-
- _XimSetHeader((XPointer)buf,
- extensions[idx].major_opcode,
- extensions[idx].minor_opcode, &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,
- _XimExtForwardKeyEventCheck, (XPointer)ic);
- if(ret_code == XIM_TRUE) {
- preply = reply;
- } else if(ret_code == XIM_OVERFLOW) {
- if(len <= 0) {
- preply = reply;
- } else {
- buf_sizex = len;
- preply = (XPointer)Xmalloc(buf_size);
- ret_code = _XimRead(im, &len, preply, buf_size,
- _XimExtForwardKeyEventCheck, (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;
-}
-#endif /* EXT_FORWARD */
-
-Private int
-_XimCheckExtensionListSize(void)
-{
- register int i;
- int len;
- int total = 0;
- int n = XIMNumber(extensions) - 1;
-
- for (i = 0; i < n; i++) {
- len = strlen(extensions[i].name);
- extensions[i].name_len = len;
- len += sizeof(BYTE);
- total += len;
- }
- return total;
-}
-
-Private void
-_XimSetExtensionList(
- CARD8 *buf)
-{
- register int i;
- int len;
- int n = XIMNumber(extensions) - 1;
-
- for (i = 0; i < n; i++) {
- len = extensions[i].name_len;
- buf[0] = (BYTE)len;
- (void)strcpy((char *)&buf[1], extensions[i].name);
- len += sizeof(BYTE);
- buf += len;
- }
- return;
-}
-
-Private unsigned int
-_XimCountNumberOfExtension(
- INT16 total,
- CARD8 *ext)
-{
- unsigned int n;
- INT16 len;
- INT16 min_len = sizeof(CARD8)
- + sizeof(CARD8)
- + sizeof(INT16);
-
- n = 0;
- while (total > min_len) {
- len = *((INT16 *)(&ext[2]));
- len += (min_len + XIM_PAD(len));
- total -= len;
- ext += len;
- n++;
- }
- return n;
-}
-
-Private Bool
-_XimParseExtensionList(
- Xim im,
- CARD16 *data)
-{
- int num = XIMNumber(extensions) - 1;
- unsigned int n;
- CARD8 *buf;
- register int i;
- register int j;
- INT16 len;
-
- if (!(n = _XimCountNumberOfExtension(data[0], (CARD8 *)&data[1])))
- return True;
-
- buf = (CARD8 *)&data[1];;
- for (i = 0; i < n; i++) {
- len = *((INT16 *)(&buf[2]));
- for (j = 0; j < num; j++) {
- if (!(strncmp(extensions[j].name, (char *)&buf[4], len))) {
- extensions[j].major_opcode = buf[0];
- extensions[j].minor_opcode = buf[1];
- extensions[j].is_support = True;
- break;
- }
- }
- len += sizeof(CARD8) /* sizeof major_opcode */
- + sizeof(CARD8) /* sizeof minor_opcode */
- + sizeof(INT16) /* sizeof length */
- + XIM_PAD(len); /* sizeof pad */
- buf += len;
- }
-
- return True;
-}
-
-Private Bool
-_XimQueryExtensionCheck(
- 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_QUERY_EXTENSION_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;
-}
-
-Public Bool
-_XimExtension(
- Xim im)
-{
- CARD8 *buf;
- CARD16 *buf_s;
- int buf_len;
- INT16 len;
- CARD32 reply32[BUFSIZE/4];
- char *reply = (char *)reply32;
- XPointer preply;
- int buf_size;
- int ret_code;
- int idx;
-
- if (!(len = _XimCheckExtensionListSize()))
- return True;
-
- buf_len = XIM_HEADER_SIZE
- + sizeof(CARD16)
- + sizeof(INT16)
- + len
- + XIM_PAD(len);
-
- if (!(buf = (CARD8 *)Xmalloc(buf_len)))
- return False;
- buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = len; /* length of Extensions */
- _XimSetExtensionList((CARD8 *)&buf_s[2]);
- /* extensions supported */
- XIM_SET_PAD(&buf_s[2], len); /* pad */
- len += sizeof(CARD16) /* sizeof imid */
- + sizeof(INT16); /* sizeof length of extensions */
-
- _XimSetHeader((XPointer)buf, XIM_QUERY_EXTENSION, 0, &len);
- if (!(_XimWrite(im, len, (XPointer)buf))) {
- XFree(buf);
- return False;
- }
- XFree(buf);
- _XimFlush(im);
- buf_size = BUFSIZE;
- ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
- _XimQueryExtensionCheck, 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, reply, buf_size,
- _XimQueryExtensionCheck, 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 (!(_XimParseExtensionList(im, &buf_s[1]))) {
- if(reply != preply)
- Xfree(preply);
- return False;
- }
- if(reply != preply)
- Xfree(preply);
-
- if ((idx = _XimIsSupportExt(XIM_EXT_SET_EVENT_MASK_IDX)) >= 0)
- _XimRegProtoIntrCallback(im,
- extensions[idx].major_opcode,
- extensions[idx].minor_opcode,
- _XimExtSetEventMaskCallback, (XPointer)im);
-#ifdef EXT_FORWARD
- if ((idx = _XimIsSupportExt(XIM_EXT_FORWARD_KEYEVENT_IDX)) >= 0)
- _XimRegProtoIntrCallback(im,
- extensions[idx].major_opcode,
- extensions[idx].minor_opcode,
- _XimExtForwardKeyEventCallback, (XPointer)im);
-#endif
-
- return True;
-}
-
-#ifdef EXT_MOVE
-/* flag of ExtenArgCheck */
-#define EXT_XNSPOTLOCATION (1L<<0)
-
-/* macro for ExtenArgCheck */
-#define SET_EXT_XNSPOTLOCATION(flag) (flag |= EXT_XNSPOTLOCATION)
-#define IS_EXT_XNSPOTLOCATION(flag) (flag & EXT_XNSPOTLOCATION)
-
-/* length of XPoint attribute */
-#define XIM_Xpoint_length 12
-
-Private Bool
-_XimExtMove(
- Xim im,
- Xic ic,
- CARD16 x,
- CARD16 y)
-{
- CARD32 buf32[BUFSIZE/4];
- CARD8 *buf = (CARD8 *)buf32;
- CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
- INT16 len;
- int idx;
-
- if ((idx = _XimIsSupportExt(XIM_EXT_MOVE_IDX)) < 0)
- return False;
-
- buf_s[0] = im->private.proto.imid; /* imid */
- buf_s[1] = ic->private.proto.icid; /* icid */
- buf_s[2] = x; /* X */
- buf_s[3] = y; /* Y */
- len = sizeof(CARD16) /* sizeof imid */
- + sizeof(CARD16) /* sizeof icid */
- + sizeof(INT16) /* sizeof X */
- + sizeof(INT16); /* sizeof Y */
-
- _XimSetHeader((XPointer)buf, extensions[idx].major_opcode,
- extensions[idx].minor_opcode, &len);
- if (!(_XimWrite(im, len, (XPointer)buf)))
- return False;
- _XimFlush(im);
- return True;
-}
-
-Public BITMASK32
-_XimExtenArgCheck(
- XIMArg *arg)
-{
- CARD32 flag = 0L;
- if (!strcmp(arg->name, XNSpotLocation))
- SET_EXT_XNSPOTLOCATION(flag);
- return flag;
-}
-
-Public Bool
-_XimExtenMove(
- Xim im,
- Xic ic,
- CARD32 flag,
- CARD16 *buf,
- INT16 length)
-{
- if ((IS_EXT_XNSPOTLOCATION(flag)) && (length == XIM_Xpoint_length))
- return _XimExtMove(im, ic, buf[4], buf[5]);
- return False;
-}
-#endif /* EXT_MOVE */
+/******************************************************************
+
+ 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"
+
+/*
+ * index of extensions
+ */
+
+#define XIM_EXT_SET_EVENT_MASK_IDX 0
+#ifdef EXT_FORWARD
+#define XIM_EXT_FORWARD_KEYEVENT_IDX 1
+#endif
+#ifdef EXT_MOVE
+#define XIM_EXT_MOVE_IDX 2
+#endif
+
+typedef struct _XIM_QueryExtRec {
+ Bool is_support;
+ const char *name;
+ int name_len;
+ CARD16 major_opcode;
+ CARD16 minor_opcode;
+ int idx;
+} XIM_QueryExtRec;
+
+Private XIM_QueryExtRec extensions[] = {
+ {False, "XIM_EXT_SET_EVENT_MASK", 0, 0, 0,
+ XIM_EXT_SET_EVENT_MASK_IDX},
+#ifdef EXT_FORWARD
+ {False, "XIM_EXT_FORWARD_KEYEVENT", 0, 0, 0,
+ XIM_EXT_FORWARD_KEYEVENT_IDX},
+#endif
+#ifdef EXT_MOVE
+ {False, "XIM_EXT_MOVE", 0, 0, 0, XIM_EXT_MOVE_IDX},
+#endif
+ {False, NULL, 0, 0, 0, 0} /* dummy */
+};
+
+Private int
+_XimIsSupportExt(
+ int idx)
+{
+ register int i;
+ int n = XIMNumber(extensions) - 1;
+
+ for (i = 0; i < n; i++) {
+ if (extensions[i].idx == idx) {
+ if (extensions[i].is_support)
+ return i;
+ else
+ break;
+ }
+ }
+ return -1;
+}
+
+Private Bool
+_XimProcExtSetEventMask(
+ Xim im,
+ Xic ic,
+ XPointer buf)
+{
+ EVENTMASK *buf_l = (EVENTMASK *)buf;
+ EVENTMASK select_mask = _XimGetWindowEventmask(ic);
+
+ ic->private.proto.filter_event_mask = buf_l[0];
+ ic->private.proto.intercept_event_mask = buf_l[1];
+ ic->private.proto.select_event_mask = buf_l[2];
+ ic->private.proto.forward_event_mask = buf_l[3];
+ ic->private.proto.synchronous_event_mask = buf_l[4];
+
+ select_mask &= ~ic->private.proto.intercept_event_mask;
+ /* deselected event mask */
+ select_mask |= ic->private.proto.select_event_mask;
+ /* selected event mask */
+ XSelectInput(im->core.display, ic->core.focus_window, select_mask);
+ _XimReregisterFilter(ic);
+
+ if (!(_XimProcSyncReply(im, ic)))
+ return False;
+ return True;
+}
+
+Private Bool
+_XimExtSetEventMaskCallback(
+ 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)_XimProcExtSetEventMask(im, ic, (XPointer)&buf_s[2]);
+ return True;
+ }
+ return False;
+}
+
+#ifdef EXT_FORWARD
+Private Bool
+_XimProcExtForwardKeyEvent(
+ Xim im,
+ Xic ic,
+ XPointer buf)
+{
+ CARD8 *buf_b = (CARD8 *)buf;
+ CARD16 *buf_s = (CARD16 *)buf;
+ CARD32 *buf_l = (CARD32 *)buf;
+ XEvent ev;
+ XKeyEvent *kev = (XKeyEvent *)&ev;
+
+ bzero(&ev, sizeof(XEvent));
+ kev->send_event = False;
+ kev->display = im->core.display;
+ kev->serial = buf_s[1]; /* sequence number */
+ kev->type = buf_b[4] & 0x7f; /* xEvent.u.u.type */
+ kev->keycode = buf_b[5]; /* Keycode */
+ kev->state = buf_s[3]; /* state */
+ kev->time = buf_l[2]; /* time */
+
+ XPutBackEvent(im->core.display, &ev);
+
+ _XimRespSyncReply(ic, buf_s[0]);
+ MARK_FABLICATED(ic);
+
+ return True;
+}
+
+Private Bool
+_XimExtForwardKeyEventCallback(
+ 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)_XimProcExtForwardKeyEvent(im, ic, (XPointer)&buf_s[2]);
+ return True;
+ }
+ return False;
+}
+
+Private Bool
+_XimExtForwardKeyEventCheck(
+ 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))
+ 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
+_XimExtForwardKeyEvent(
+ Xic ic,
+ XKeyEvent *ev,
+ Bool sync)
+{
+ Xim im = (Xim) ic->core.im;
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD8 *buf_b = &buf[XIM_HEADER_SIZE];
+ CARD16 *buf_s = (CARD16 *)buf_b;
+ CARD32 *buf_l = (CARD32 *)buf_b;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+ INT16 len;
+ int idx;
+
+ if ((idx = _XimIsSupportExt(XIM_EXT_FORWARD_KEYEVENT_IDX)) < 0)
+ return False;
+
+ 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));
+ /* sequence number */
+ buf_b[8] = ev->type; /* xEvent.u.u.type */
+ buf_b[9] = ev->keycode; /* keycode */
+ buf_s[5] = ev->state; /* state */
+ buf_l[3] = ev->time; /* time */
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16) /* sizeof icid */
+ + sizeof(BITMASK16) /* sizeof flag */
+ + sizeof(CARD16) /* sizeof sequence number */
+ + sizeof(BYTE) /* sizeof xEvent.u.u.type */
+ + sizeof(BYTE) /* sizeof keycode */
+ + sizeof(CARD16) /* sizeof state */
+ + sizeof(CARD32); /* sizeof time */
+
+ _XimSetHeader((XPointer)buf,
+ extensions[idx].major_opcode,
+ extensions[idx].minor_opcode, &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,
+ _XimExtForwardKeyEventCheck, (XPointer)ic);
+ if(ret_code == XIM_TRUE) {
+ preply = reply;
+ } else if(ret_code == XIM_OVERFLOW) {
+ if(len <= 0) {
+ preply = reply;
+ } else {
+ buf_sizex = len;
+ preply = (XPointer)Xmalloc(buf_size);
+ ret_code = _XimRead(im, &len, preply, buf_size,
+ _XimExtForwardKeyEventCheck, (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;
+}
+#endif /* EXT_FORWARD */
+
+Private int
+_XimCheckExtensionListSize(void)
+{
+ register int i;
+ int len;
+ int total = 0;
+ int n = XIMNumber(extensions) - 1;
+
+ for (i = 0; i < n; i++) {
+ len = strlen(extensions[i].name);
+ extensions[i].name_len = len;
+ len += sizeof(BYTE);
+ total += len;
+ }
+ return total;
+}
+
+Private void
+_XimSetExtensionList(
+ CARD8 *buf)
+{
+ register int i;
+ int len;
+ int n = XIMNumber(extensions) - 1;
+
+ for (i = 0; i < n; i++) {
+ len = extensions[i].name_len;
+ buf[0] = (BYTE)len;
+ (void)strcpy((char *)&buf[1], extensions[i].name);
+ len += sizeof(BYTE);
+ buf += len;
+ }
+ return;
+}
+
+Private unsigned int
+_XimCountNumberOfExtension(
+ INT16 total,
+ CARD8 *ext)
+{
+ unsigned int n;
+ INT16 len;
+ INT16 min_len = sizeof(CARD8)
+ + sizeof(CARD8)
+ + sizeof(INT16);
+
+ n = 0;
+ while (total > min_len) {
+ len = *((INT16 *)(&ext[2]));
+ len += (min_len + XIM_PAD(len));
+ total -= len;
+ ext += len;
+ n++;
+ }
+ return n;
+}
+
+Private Bool
+_XimParseExtensionList(
+ Xim im,
+ CARD16 *data)
+{
+ int num = XIMNumber(extensions) - 1;
+ unsigned int n;
+ CARD8 *buf;
+ register int i;
+ register int j;
+ INT16 len;
+
+ if (!(n = _XimCountNumberOfExtension(data[0], (CARD8 *)&data[1])))
+ return True;
+
+ buf = (CARD8 *)&data[1];;
+ for (i = 0; i < n; i++) {
+ len = *((INT16 *)(&buf[2]));
+ for (j = 0; j < num; j++) {
+ if (!(strncmp(extensions[j].name, (char *)&buf[4], len))) {
+ extensions[j].major_opcode = buf[0];
+ extensions[j].minor_opcode = buf[1];
+ extensions[j].is_support = True;
+ break;
+ }
+ }
+ len += sizeof(CARD8) /* sizeof major_opcode */
+ + sizeof(CARD8) /* sizeof minor_opcode */
+ + sizeof(INT16) /* sizeof length */
+ + XIM_PAD(len); /* sizeof pad */
+ buf += len;
+ }
+
+ return True;
+}
+
+Private Bool
+_XimQueryExtensionCheck(
+ 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_QUERY_EXTENSION_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;
+}
+
+Public Bool
+_XimExtension(
+ Xim im)
+{
+ CARD8 *buf;
+ CARD16 *buf_s;
+ int buf_len;
+ INT16 len;
+ CARD32 reply32[BUFSIZE/4];
+ char *reply = (char *)reply32;
+ XPointer preply;
+ int buf_size;
+ int ret_code;
+ int idx;
+
+ if (!(len = _XimCheckExtensionListSize()))
+ return True;
+
+ buf_len = XIM_HEADER_SIZE
+ + sizeof(CARD16)
+ + sizeof(INT16)
+ + len
+ + XIM_PAD(len);
+
+ if (!(buf = (CARD8 *)Xmalloc(buf_len)))
+ return False;
+ buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = len; /* length of Extensions */
+ _XimSetExtensionList((CARD8 *)&buf_s[2]);
+ /* extensions supported */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += sizeof(CARD16) /* sizeof imid */
+ + sizeof(INT16); /* sizeof length of extensions */
+
+ _XimSetHeader((XPointer)buf, XIM_QUERY_EXTENSION, 0, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf))) {
+ XFree(buf);
+ return False;
+ }
+ XFree(buf);
+ _XimFlush(im);
+ buf_size = BUFSIZE;
+ ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
+ _XimQueryExtensionCheck, 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, reply, buf_size,
+ _XimQueryExtensionCheck, 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 (!(_XimParseExtensionList(im, &buf_s[1]))) {
+ if(reply != preply)
+ Xfree(preply);
+ return False;
+ }
+ if(reply != preply)
+ Xfree(preply);
+
+ if ((idx = _XimIsSupportExt(XIM_EXT_SET_EVENT_MASK_IDX)) >= 0)
+ _XimRegProtoIntrCallback(im,
+ extensions[idx].major_opcode,
+ extensions[idx].minor_opcode,
+ _XimExtSetEventMaskCallback, (XPointer)im);
+#ifdef EXT_FORWARD
+ if ((idx = _XimIsSupportExt(XIM_EXT_FORWARD_KEYEVENT_IDX)) >= 0)
+ _XimRegProtoIntrCallback(im,
+ extensions[idx].major_opcode,
+ extensions[idx].minor_opcode,
+ _XimExtForwardKeyEventCallback, (XPointer)im);
+#endif
+
+ return True;
+}
+
+#ifdef EXT_MOVE
+/* flag of ExtenArgCheck */
+#define EXT_XNSPOTLOCATION (1L<<0)
+
+/* macro for ExtenArgCheck */
+#define SET_EXT_XNSPOTLOCATION(flag) (flag |= EXT_XNSPOTLOCATION)
+#define IS_EXT_XNSPOTLOCATION(flag) (flag & EXT_XNSPOTLOCATION)
+
+/* length of XPoint attribute */
+#define XIM_Xpoint_length 12
+
+Private Bool
+_XimExtMove(
+ Xim im,
+ Xic ic,
+ CARD16 x,
+ CARD16 y)
+{
+ CARD32 buf32[BUFSIZE/4];
+ CARD8 *buf = (CARD8 *)buf32;
+ CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
+ INT16 len;
+ int idx;
+
+ if ((idx = _XimIsSupportExt(XIM_EXT_MOVE_IDX)) < 0)
+ return False;
+
+ buf_s[0] = im->private.proto.imid; /* imid */
+ buf_s[1] = ic->private.proto.icid; /* icid */
+ buf_s[2] = x; /* X */
+ buf_s[3] = y; /* Y */
+ len = sizeof(CARD16) /* sizeof imid */
+ + sizeof(CARD16) /* sizeof icid */
+ + sizeof(INT16) /* sizeof X */
+ + sizeof(INT16); /* sizeof Y */
+
+ _XimSetHeader((XPointer)buf, extensions[idx].major_opcode,
+ extensions[idx].minor_opcode, &len);
+ if (!(_XimWrite(im, len, (XPointer)buf)))
+ return False;
+ _XimFlush(im);
+ return True;
+}
+
+Public BITMASK32
+_XimExtenArgCheck(
+ XIMArg *arg)
+{
+ CARD32 flag = 0L;
+ if (!strcmp(arg->name, XNSpotLocation))
+ SET_EXT_XNSPOTLOCATION(flag);
+ return flag;
+}
+
+Public Bool
+_XimExtenMove(
+ Xim im,
+ Xic ic,
+ CARD32 flag,
+ CARD16 *buf,
+ INT16 length)
+{
+ if ((IS_EXT_XNSPOTLOCATION(flag)) && (length == XIM_Xpoint_length))
+ return _XimExtMove(im, ic, buf[4], buf[5]);
+ return False;
+}
+#endif /* EXT_MOVE */
diff --git a/libX11/modules/im/ximcp/imInsClbk.c b/libX11/modules/im/ximcp/imInsClbk.c
index 93a855223..263dec6d9 100644
--- a/libX11/modules/im/ximcp/imInsClbk.c
+++ b/libX11/modules/im/ximcp/imInsClbk.c
@@ -1,289 +1,288 @@
-/******************************************************************
-
- Copyright 1993, 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 Sony Corporation
- not be used in advertising or publicity pertaining to distribution
- of the software without specific, written prior permission.
-Sony Corporation makes no representations about the suitability of
- this software for any purpose. It is provided "as is" without
- express or implied warranty.
-
-SONY CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL 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: Makoto Wakamatsu Sony Corporation
- makoto@sm.sony.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xatom.h>
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcPublic.h"
-#include "Ximint.h"
-
-
-typedef struct _XimInstCallback {
- Bool call;
- Bool destroy;
- Display *display;
- XLCd lcd;
- char name[XIM_MAXLCNAMELEN];
- char *modifiers;
- XrmDatabase rdb;
- char *res_name;
- char *res_class;
- XIDProc callback;
- XPointer client_data;
- struct _XimInstCallback *next;
-} XimInstCallbackRec, *XimInstCallback;
-
-
-Private XimInstCallback callback_list = NULL;
-Private Bool lock = False;
-
-
-Private void
-MakeLocale( XLCd lcd, char locale[] )
-{
- char *language, *territory, *codeset;
-
- _XGetLCValues( lcd, XlcNLanguage, &language, XlcNTerritory, &territory,
- XlcNCodeset, &codeset, NULL );
-
- strcpy( locale, language );
- if( territory && *territory ) {
- strcat( locale, "_" );
- strcat( locale, territory );
- }
- if( codeset && *codeset ) {
- strcat( locale, "." );
- strcat( locale, codeset );
- }
-}
-
-
-Private Bool
-_XimFilterPropertyNotify(
- Display *display,
- Window window,
- XEvent *event,
- XPointer client_data)
-{
- Atom ims, actual_type, *atoms;
- int actual_format;
- unsigned long nitems, bytes_after;
- int ii;
- XIM xim;
- Bool flag = False;
- XimInstCallback icb, picb, tmp;
-
- if( (ims = XInternAtom( display, XIM_SERVERS, True )) == None ||
- event->xproperty.atom != ims ||
- event->xproperty.state == PropertyDelete )
- return( False );
-
- if( XGetWindowProperty( display, RootWindow(display, 0), ims, 0L, 1000000L,
- False, XA_ATOM, &actual_type, &actual_format,
- &nitems, &bytes_after, (unsigned char **)&atoms )
- != Success ) {
- return( False );
- }
- if( actual_type != XA_ATOM || actual_format != 32 ) {
- XFree( atoms );
- return( False );
- }
-
- lock = True;
- for( ii = 0; ii < nitems; ii++, atoms ) {
- if(XGetSelectionOwner (display, atoms[ii])) {
- for( icb = callback_list; icb; icb = icb->next ) {
- if( !icb->call && !icb->destroy ) {
- xim = (*icb->lcd->methods->open_im)( icb->lcd, display,
- icb->rdb,
- icb->res_name,
- icb->res_class );
- if( xim ) {
- xim->methods->close( (XIM)xim );
- flag = True;
- icb->call = True;
- icb->callback( icb->display, icb->client_data, NULL );
- }
- }
- }
- break;
- }
- }
- XFree( atoms );
-
- for( icb = callback_list, picb = NULL; icb; ) {
- if( icb->destroy ) {
- if( picb )
- picb->next = icb->next;
- else
- callback_list = icb->next;
- tmp = icb;
- icb = icb->next;
- XFree( tmp );
- }
- else {
- picb = icb;
- icb = icb->next;
- }
- }
- lock = False;
-
- return( flag );
-}
-
-
-Public Bool
-_XimRegisterIMInstantiateCallback(
- XLCd lcd,
- Display *display,
- XrmDatabase rdb,
- char *res_name,
- char *res_class,
- XIDProc callback,
- XPointer client_data)
-{
- XimInstCallback icb, tmp;
- XIM xim;
- Window root;
- XWindowAttributes attr;
-
- if( lock )
- return( False );
-
- icb = (XimInstCallback)Xmalloc(sizeof(XimInstCallbackRec));
- if( !icb )
- return( False );
- icb->call = icb->destroy = False;
- icb->display = display;
- icb->lcd = lcd;
- MakeLocale( lcd, icb->name );
- icb->modifiers = lcd->core->modifiers; /* XXXXX */
- icb->rdb = rdb;
- icb->res_name = res_name;
- icb->res_class = res_class;
- icb->callback = callback;
- icb->client_data = client_data;
- icb->next = NULL;
-
- if( !callback_list )
- callback_list = icb;
- else {
- for( tmp = callback_list; tmp->next; tmp = tmp->next );
- tmp->next = icb;
- }
-
- xim = (*lcd->methods->open_im)( lcd, display, rdb, res_name, res_class );
-
- if( icb == callback_list ) {
- root = RootWindow( display, 0 );
- XGetWindowAttributes( display, root, &attr );
- _XRegisterFilterByType( display, root, PropertyNotify, PropertyNotify,
- _XimFilterPropertyNotify, (XPointer)NULL );
- XSelectInput( display, root,
- attr.your_event_mask | PropertyChangeMask );
- }
-
- if( xim ) {
- lock = True;
- xim->methods->close( (XIM)xim );
- lock = False;
- icb->call = True;
- callback( display, client_data, NULL );
- }
-
- return( True );
-}
-
-
-Public Bool
-_XimUnRegisterIMInstantiateCallback(
- XLCd lcd,
- Display *display,
- XrmDatabase rdb,
- char *res_name,
- char *res_class,
- XIDProc callback,
- XPointer client_data)
-{
- char locale[XIM_MAXLCNAMELEN];
- XimInstCallback icb, picb;
-
- if( !callback_list )
- return( False );
-
- MakeLocale( lcd, locale );
-
- for( icb = callback_list, picb = NULL; icb; picb = icb, icb = icb->next ) {
- if( !strcmp( locale, icb->name ) &&
- (lcd->core->modifiers == icb->modifiers || /* XXXXX */
- (lcd->core->modifiers && icb->modifiers &&
- !strcmp( lcd->core->modifiers, icb->modifiers ))) &&
- rdb == icb->rdb && /* XXXXX */
- ((res_name == NULL && icb->res_name == NULL) ||
- (res_name != NULL && icb->res_name != NULL &&
- !strcmp( res_name, icb->res_name ))) &&
- ((res_class == NULL && icb->res_class == NULL) ||
- (res_class != NULL && icb->res_class != NULL &&
- !strcmp( res_class, icb->res_class ))) &&
- (callback == icb->callback) &&
- (client_data == icb->client_data) && /* XXXXX */
- !icb->destroy ) {
- if( lock )
- icb->destroy = True;
- else {
- if( !picb ) {
- callback_list = icb->next;
- _XUnregisterFilter( display, RootWindow(display, 0),
- _XimFilterPropertyNotify,
- (XPointer)NULL );
- }
- else
- picb->next = icb->next;
- _XCloseLC( icb->lcd );
- XFree( icb );
- }
- return( True );
- }
- }
- return( False );
-}
-
-
-Public void
-_XimResetIMInstantiateCallback(Xim xim)
-{
- char locale[XIM_MAXLCNAMELEN];
- XimInstCallback icb;
- XLCd lcd = xim->core.lcd;
-
- if( !callback_list && lock )
- return;
-
- MakeLocale( lcd, locale );
-
- for( icb = callback_list; icb; icb = icb->next )
- if( !strcmp( locale, icb->name ) &&
- (lcd->core->modifiers == icb->modifiers ||
- (lcd->core->modifiers && icb->modifiers &&
- !strcmp( lcd->core->modifiers, icb->modifiers ))) )
- icb->call = False;
-}
+/******************************************************************
+
+ Copyright 1993, 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 Sony Corporation
+ not be used in advertising or publicity pertaining to distribution
+ of the software without specific, written prior permission.
+Sony Corporation makes no representations about the suitability of
+ this software for any purpose. It is provided "as is" without
+ express or implied warranty.
+
+SONY CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL 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: 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 "Ximint.h"
+
+
+typedef struct _XimInstCallback {
+ Bool call;
+ Bool destroy;
+ Display *display;
+ XLCd lcd;
+ char name[XIM_MAXLCNAMELEN];
+ char *modifiers;
+ XrmDatabase rdb;
+ char *res_name;
+ char *res_class;
+ XIDProc callback;
+ XPointer client_data;
+ struct _XimInstCallback *next;
+} XimInstCallbackRec, *XimInstCallback;
+
+
+Private XimInstCallback callback_list = NULL;
+Private Bool lock = False;
+
+
+Private void
+MakeLocale( XLCd lcd, char locale[] )
+{
+ char *language, *territory, *codeset;
+
+ _XGetLCValues( lcd, XlcNLanguage, &language, XlcNTerritory, &territory,
+ XlcNCodeset, &codeset, NULL );
+
+ strcpy( locale, language );
+ if( territory && *territory ) {
+ strcat( locale, "_" );
+ strcat( locale, territory );
+ }
+ if( codeset && *codeset ) {
+ strcat( locale, "." );
+ strcat( locale, codeset );
+ }
+}
+
+
+Private Bool
+_XimFilterPropertyNotify(
+ Display *display,
+ Window window,
+ XEvent *event,
+ XPointer client_data)
+{
+ Atom ims, actual_type, *atoms;
+ int actual_format;
+ unsigned long nitems, bytes_after;
+ int ii;
+ XIM xim;
+ Bool flag = False;
+ XimInstCallback icb, picb, tmp;
+
+ if( (ims = XInternAtom( display, XIM_SERVERS, True )) == None ||
+ event->xproperty.atom != ims ||
+ event->xproperty.state == PropertyDelete )
+ return( False );
+
+ if( XGetWindowProperty( display, RootWindow(display, 0), ims, 0L, 1000000L,
+ False, XA_ATOM, &actual_type, &actual_format,
+ &nitems, &bytes_after, (unsigned char **)&atoms )
+ != Success ) {
+ return( False );
+ }
+ if( actual_type != XA_ATOM || actual_format != 32 ) {
+ XFree( atoms );
+ return( False );
+ }
+
+ lock = True;
+ for( ii = 0; ii < nitems; ii++, atoms ) {
+ if(XGetSelectionOwner (display, atoms[ii])) {
+ for( icb = callback_list; icb; icb = icb->next ) {
+ if( !icb->call && !icb->destroy ) {
+ xim = (*icb->lcd->methods->open_im)( icb->lcd, display,
+ icb->rdb,
+ icb->res_name,
+ icb->res_class );
+ if( xim ) {
+ xim->methods->close( (XIM)xim );
+ flag = True;
+ icb->call = True;
+ icb->callback( icb->display, icb->client_data, NULL );
+ }
+ }
+ }
+ break;
+ }
+ }
+ XFree( atoms );
+
+ for( icb = callback_list, picb = NULL; icb; ) {
+ if( icb->destroy ) {
+ if( picb )
+ picb->next = icb->next;
+ else
+ callback_list = icb->next;
+ tmp = icb;
+ icb = icb->next;
+ XFree( tmp );
+ }
+ else {
+ picb = icb;
+ icb = icb->next;
+ }
+ }
+ lock = False;
+
+ return( flag );
+}
+
+
+Public Bool
+_XimRegisterIMInstantiateCallback(
+ XLCd lcd,
+ Display *display,
+ XrmDatabase rdb,
+ char *res_name,
+ char *res_class,
+ XIDProc callback,
+ XPointer client_data)
+{
+ XimInstCallback icb, tmp;
+ XIM xim;
+ Window root;
+ XWindowAttributes attr;
+
+ if( lock )
+ return( False );
+
+ icb = (XimInstCallback)Xmalloc(sizeof(XimInstCallbackRec));
+ if( !icb )
+ return( False );
+ icb->call = icb->destroy = False;
+ icb->display = display;
+ icb->lcd = lcd;
+ MakeLocale( lcd, icb->name );
+ icb->modifiers = lcd->core->modifiers; /* XXXXX */
+ icb->rdb = rdb;
+ icb->res_name = res_name;
+ icb->res_class = res_class;
+ icb->callback = callback;
+ icb->client_data = client_data;
+ icb->next = NULL;
+
+ if( !callback_list )
+ callback_list = icb;
+ else {
+ for( tmp = callback_list; tmp->next; tmp = tmp->next );
+ tmp->next = icb;
+ }
+
+ xim = (*lcd->methods->open_im)( lcd, display, rdb, res_name, res_class );
+
+ if( icb == callback_list ) {
+ root = RootWindow( display, 0 );
+ XGetWindowAttributes( display, root, &attr );
+ _XRegisterFilterByType( display, root, PropertyNotify, PropertyNotify,
+ _XimFilterPropertyNotify, (XPointer)NULL );
+ XSelectInput( display, root,
+ attr.your_event_mask | PropertyChangeMask );
+ }
+
+ if( xim ) {
+ lock = True;
+ xim->methods->close( (XIM)xim );
+ lock = False;
+ icb->call = True;
+ callback( display, client_data, NULL );
+ }
+
+ return( True );
+}
+
+
+Public Bool
+_XimUnRegisterIMInstantiateCallback(
+ XLCd lcd,
+ Display *display,
+ XrmDatabase rdb,
+ char *res_name,
+ char *res_class,
+ XIDProc callback,
+ XPointer client_data)
+{
+ char locale[XIM_MAXLCNAMELEN];
+ XimInstCallback icb, picb;
+
+ if( !callback_list )
+ return( False );
+
+ MakeLocale( lcd, locale );
+
+ for( icb = callback_list, picb = NULL; icb; picb = icb, icb = icb->next ) {
+ if( !strcmp( locale, icb->name ) &&
+ (lcd->core->modifiers == icb->modifiers || /* XXXXX */
+ (lcd->core->modifiers && icb->modifiers &&
+ !strcmp( lcd->core->modifiers, icb->modifiers ))) &&
+ rdb == icb->rdb && /* XXXXX */
+ ((res_name == NULL && icb->res_name == NULL) ||
+ (res_name != NULL && icb->res_name != NULL &&
+ !strcmp( res_name, icb->res_name ))) &&
+ ((res_class == NULL && icb->res_class == NULL) ||
+ (res_class != NULL && icb->res_class != NULL &&
+ !strcmp( res_class, icb->res_class ))) &&
+ (callback == icb->callback) &&
+ (client_data == icb->client_data) && /* XXXXX */
+ !icb->destroy ) {
+ if( lock )
+ icb->destroy = True;
+ else {
+ if( !picb ) {
+ callback_list = icb->next;
+ _XUnregisterFilter( display, RootWindow(display, 0),
+ _XimFilterPropertyNotify,
+ (XPointer)NULL );
+ }
+ else
+ picb->next = icb->next;
+ _XCloseLC( icb->lcd );
+ XFree( icb );
+ }
+ return( True );
+ }
+ }
+ return( False );
+}
+
+
+Public void
+_XimResetIMInstantiateCallback(Xim xim)
+{
+ char locale[XIM_MAXLCNAMELEN];
+ XimInstCallback icb;
+ XLCd lcd = xim->core.lcd;
+
+ if( !callback_list && lock )
+ return;
+
+ MakeLocale( lcd, locale );
+
+ for( icb = callback_list; icb; icb = icb->next )
+ if( !strcmp( locale, icb->name ) &&
+ (lcd->core->modifiers == icb->modifiers ||
+ (lcd->core->modifiers && icb->modifiers &&
+ !strcmp( lcd->core->modifiers, icb->modifiers ))) )
+ icb->call = False;
+}
diff --git a/libX11/modules/im/ximcp/imLcFlt.c b/libX11/modules/im/ximcp/imLcFlt.c
index cef4dbff2..014ad6add 100644
--- a/libX11/modules/im/ximcp/imLcFlt.c
+++ b/libX11/modules/im/ximcp/imLcFlt.c
@@ -1,116 +1,115 @@
-/******************************************************************
-
- 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
-
-******************************************************************/
-
-#define NEED_EVENTS
-#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;
-
- 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);
- } 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) {
- if(ic->private.local.brl_committing) {
- ic->private.local.brl_committed =
- ic->private.local.brl_committing;
- ic->private.local.composed = 0;
- ev->type = KeyPress;
- ev->xkey.keycode = 0;
- _XPutBackEvent(d, ev);
- }
- }
- }
- return(True);
- }
-
- if( (ev->type != KeyPress)
- || (((Xim)ic->core.im)->private.local.top == 0 ) )
- return(False);
-
- 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) {
- return(False);
- }
- /* Error (Sequence Unmatch occured) */
- /* initialize internal state for next key sequence */
- ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
- return(True);
- }
-}
+/******************************************************************
+
+ 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;
+
+ 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);
+ } 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) {
+ if(ic->private.local.brl_committing) {
+ ic->private.local.brl_committed =
+ ic->private.local.brl_committing;
+ ic->private.local.composed = 0;
+ ev->type = KeyPress;
+ ev->xkey.keycode = 0;
+ _XPutBackEvent(d, ev);
+ }
+ }
+ }
+ return(True);
+ }
+
+ if( (ev->type != KeyPress)
+ || (((Xim)ic->core.im)->private.local.top == 0 ) )
+ return(False);
+
+ 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) {
+ return(False);
+ }
+ /* Error (Sequence Unmatch occured) */
+ /* initialize internal state for next key sequence */
+ ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
+ return(True);
+ }
+}
diff --git a/libX11/modules/im/ximcp/imLcGIc.c b/libX11/modules/im/ximcp/imLcGIc.c
index e3a4d10e3..2ee5adbc2 100644
--- a/libX11/modules/im/ximcp/imLcGIc.c
+++ b/libX11/modules/im/ximcp/imLcGIc.c
@@ -1,48 +1,47 @@
-/******************************************************************
-
- 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
-
-******************************************************************/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-Public char *
-_XimLocalGetICValues(XIC xic, XIMArg *values)
-{
- Xic ic = (Xic)xic;
- XimDefICValues ic_values;
-
- _XimGetCurrentICValues(ic, &ic_values);
- return(_XimGetICValueData(ic, (XPointer)&ic_values,
- ic->private.local.ic_resources,
- ic->private.local.ic_num_resources,
- values, XIM_GETICVALUES));
-}
+/******************************************************************
+
+ 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"
+
+Public char *
+_XimLocalGetICValues(XIC xic, XIMArg *values)
+{
+ Xic ic = (Xic)xic;
+ XimDefICValues ic_values;
+
+ _XimGetCurrentICValues(ic, &ic_values);
+ return(_XimGetICValueData(ic, (XPointer)&ic_values,
+ ic->private.local.ic_resources,
+ ic->private.local.ic_num_resources,
+ values, XIM_GETICVALUES));
+}
diff --git a/libX11/modules/im/ximcp/imTrX.c b/libX11/modules/im/ximcp/imTrX.c
index 9bb353792..83f204d54 100644
--- a/libX11/modules/im/ximcp/imTrX.c
+++ b/libX11/modules/im/ximcp/imTrX.c
@@ -1,511 +1,510 @@
-/*
- * Copyright 1992 Sun Microsystems, Inc. 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>
-#define NEED_EVENTS
-#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);
- 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);
- XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
- XA_STRING, 8, PropModePrepend, &prop_ret[length],
- (nitems - length));
- }
- } else {
- (void)memcpy(buf, prop_ret, buf_len);
- *ret_len = buf_len;
- len = nitems - buf_len;
-
- if (bytes_after_ret > 0) {
- XFree(prop_ret);
- 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);
- }
- 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 = (XSpecRec *)Xmalloc(sizeof(XSpecRec))))
- return False;
- bzero(spec, sizeof(XSpecRec));
-
- 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 Sun Microsystems, Inc. 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);
+ 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);
+ XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
+ XA_STRING, 8, PropModePrepend, &prop_ret[length],
+ (nitems - length));
+ }
+ } else {
+ (void)memcpy(buf, prop_ret, buf_len);
+ *ret_len = buf_len;
+ len = nitems - buf_len;
+
+ if (bytes_after_ret > 0) {
+ XFree(prop_ret);
+ 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);
+ }
+ 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 = (XSpecRec *)Xmalloc(sizeof(XSpecRec))))
+ return False;
+ bzero(spec, sizeof(XSpecRec));
+
+ 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 a6f3d03de..c54a0a9c4 100644
--- a/libX11/modules/im/ximcp/imTrans.c
+++ b/libX11/modules/im/ximcp/imTrans.c
@@ -1,318 +1,317 @@
-/*
- * Copyright 1992 Sun Microsystems, Inc. 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 <X11/Xatom.h>
-#include <X11/Xmd.h>
-#define NEED_EVENTS
-#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 = (char *)Xmalloc(strlen(address) + 1)))
- return False;
-
- if (!(spec = (TransSpecRec *) Xmalloc(sizeof(TransSpecRec)))) {
- Xfree(paddr);
- return False;
- }
-
- bzero(spec, sizeof(TransSpecRec));
-
- (void)strcpy(paddr, address);
- 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 Sun Microsystems, Inc. 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 <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 = (char *)Xmalloc(strlen(address) + 1)))
+ return False;
+
+ if (!(spec = (TransSpecRec *) Xmalloc(sizeof(TransSpecRec)))) {
+ Xfree(paddr);
+ return False;
+ }
+
+ bzero(spec, sizeof(TransSpecRec));
+
+ (void)strcpy(paddr, address);
+ 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;
+}