aboutsummaryrefslogtreecommitdiff
path: root/libX11
diff options
context:
space:
mode:
Diffstat (limited to 'libX11')
-rw-r--r--libX11/include/X11/Xlibint.h6
-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
-rw-r--r--libX11/src/AllCells.c128
-rw-r--r--libX11/src/AllPlanes.c149
-rw-r--r--libX11/src/ChkIfEv.c167
-rw-r--r--libX11/src/ChkMaskEv.c181
-rw-r--r--libX11/src/ChkTypEv.c161
-rw-r--r--libX11/src/ChkTypWEv.c165
-rw-r--r--libX11/src/ChkWinEv.c183
-rw-r--r--libX11/src/EvToWire.c814
-rw-r--r--libX11/src/FilterEv.c213
-rw-r--r--libX11/src/Font.c1461
-rw-r--r--libX11/src/FontInfo.c507
-rw-r--r--libX11/src/FontNames.c227
-rw-r--r--libX11/src/GetAtomNm.c379
-rw-r--r--libX11/src/GetColor.c223
-rw-r--r--libX11/src/GetFPath.c183
-rw-r--r--libX11/src/GetGeom.c127
-rw-r--r--libX11/src/GetHColor.c117
-rw-r--r--libX11/src/GetIFocus.c99
-rw-r--r--libX11/src/GetImage.c257
-rw-r--r--libX11/src/GetKCnt.c111
-rw-r--r--libX11/src/GetMoEv.c171
-rw-r--r--libX11/src/GetPCnt.c105
-rw-r--r--libX11/src/GetPntMap.c247
-rw-r--r--libX11/src/GetProp.c267
-rw-r--r--libX11/src/GetSOwner.c91
-rw-r--r--libX11/src/GetSSaver.c113
-rw-r--r--libX11/src/GetWAttrs.c311
-rw-r--r--libX11/src/GrKeybd.c117
-rw-r--r--libX11/src/GrPointer.c129
-rw-r--r--libX11/src/Iconify.c171
-rw-r--r--libX11/src/IfEvent.c147
-rw-r--r--libX11/src/ImText.c203
-rw-r--r--libX11/src/ImText16.c207
-rw-r--r--libX11/src/IntAtom.c595
-rw-r--r--libX11/src/KeyBind.c2155
-rw-r--r--libX11/src/LiHosts.c313
-rw-r--r--libX11/src/LiICmaps.c143
-rw-r--r--libX11/src/LiProps.c139
-rw-r--r--libX11/src/ListExt.c195
-rw-r--r--libX11/src/LookupCol.c209
-rw-r--r--libX11/src/MaskEvent.c161
-rw-r--r--libX11/src/ModMap.c363
-rw-r--r--libX11/src/NextEvent.c117
-rw-r--r--libX11/src/OpenDis.c2
-rw-r--r--libX11/src/ParseCol.c277
-rw-r--r--libX11/src/PeekEvent.c111
-rw-r--r--libX11/src/PeekIfEv.c157
-rw-r--r--libX11/src/PutBEvent.c175
-rw-r--r--libX11/src/QuBest.c123
-rw-r--r--libX11/src/QuColor.c123
-rw-r--r--libX11/src/QuColors.c155
-rw-r--r--libX11/src/QuCurShp.c121
-rw-r--r--libX11/src/QuExt.c113
-rw-r--r--libX11/src/QuKeybd.c107
-rw-r--r--libX11/src/QuPntr.c131
-rw-r--r--libX11/src/QuStipShp.c121
-rw-r--r--libX11/src/QuTextE16.c163
-rw-r--r--libX11/src/QuTextExt.c161
-rw-r--r--libX11/src/QuTileShp.c123
-rw-r--r--libX11/src/QuTree.c145
-rw-r--r--libX11/src/ReconfWM.c280
-rw-r--r--libX11/src/SendEvent.c163
-rw-r--r--libX11/src/SetPntMap.c2
-rw-r--r--libX11/src/Sync.c122
-rw-r--r--libX11/src/TrCoords.c129
-rw-r--r--libX11/src/WinEvent.c169
-rw-r--r--libX11/src/Withdraw.c165
-rw-r--r--libX11/src/XlibAsync.c309
-rw-r--r--libX11/src/XlibInt.c2
-rw-r--r--libX11/src/globals.c471
-rw-r--r--libX11/src/imConv.c713
-rw-r--r--libX11/src/xcms/cmsAllNCol.c397
-rw-r--r--libX11/src/xcms/cmsCmap.c988
-rw-r--r--libX11/src/xcms/cmsInt.c825
-rw-r--r--libX11/src/xcms/cmsLkCol.c387
-rw-r--r--libX11/src/xkb/XKB.c1546
-rw-r--r--libX11/src/xkb/XKBAlloc.c1000
-rw-r--r--libX11/src/xkb/XKBBell.c358
-rw-r--r--libX11/src/xkb/XKBBind.c1753
-rw-r--r--libX11/src/xkb/XKBCompat.c496
-rw-r--r--libX11/src/xkb/XKBCtrls.c706
-rw-r--r--libX11/src/xkb/XKBCvt.c675
-rw-r--r--libX11/src/xkb/XKBExtDev.c1640
-rw-r--r--libX11/src/xkb/XKBGAlloc.c2035
-rw-r--r--libX11/src/xkb/XKBGeom.c1378
-rw-r--r--libX11/src/xkb/XKBGetByName.c430
-rw-r--r--libX11/src/xkb/XKBGetMap.c1715
-rw-r--r--libX11/src/xkb/XKBList.c496
-rw-r--r--libX11/src/xkb/XKBMAlloc.c1984
-rw-r--r--libX11/src/xkb/XKBMisc.c1962
-rw-r--r--libX11/src/xkb/XKBNames.c1776
-rw-r--r--libX11/src/xkb/XKBRdBuf.c462
-rw-r--r--libX11/src/xkb/XKBSetGeom.c926
-rw-r--r--libX11/src/xkb/XKBSetMap.c1184
-rw-r--r--libX11/src/xkb/XKBUse.c1652
-rw-r--r--libX11/src/xkb/XKBleds.c668
-rw-r--r--libX11/src/xlibi18n/ICWrap.c859
-rw-r--r--libX11/src/xlibi18n/XDefaultIMIF.c943
109 files changed, 29502 insertions, 29652 deletions
diff --git a/libX11/include/X11/Xlibint.h b/libX11/include/X11/Xlibint.h
index 1b8fd5158..ef2ccd109 100644
--- a/libX11/include/X11/Xlibint.h
+++ b/libX11/include/X11/Xlibint.h
@@ -220,12 +220,6 @@ typedef struct _XSQEvent
} _XQEvent;
#endif
-#ifdef XTHREADS /* for xReply */
-#define NEED_REPLIES
-#endif
-
-#define NEED_EVENTS
-#define NEED_REPLIES
#include <X11/Xproto.h>
#ifdef __sgi
#define _SGI_MP_SOURCE /* turn this on to get MP safe errno */
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;
+}
diff --git a/libX11/src/AllCells.c b/libX11/src/AllCells.c
index 0c188aab4..01644b186 100644
--- a/libX11/src/AllCells.c
+++ b/libX11/src/AllCells.c
@@ -1,65 +1,63 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XAllocColorCells(
- register Display *dpy,
- Colormap cmap,
- Bool contig,
- unsigned long *masks, /* LISTofCARD32 */ /* RETURN */
- unsigned int nplanes, /* CARD16 */
- unsigned long *pixels, /* LISTofCARD32 */ /* RETURN */
- unsigned int ncolors) /* CARD16 */
-{
-
- Status status;
- xAllocColorCellsReply rep;
- register xAllocColorCellsReq *req;
- LockDisplay(dpy);
- GetReq(AllocColorCells, req);
-
- req->cmap = cmap;
- req->colors = ncolors;
- req->planes = nplanes;
- req->contiguous = contig;
-
- status = _XReply(dpy, (xReply *)&rep, 0, xFalse);
-
- if (status) {
- _XRead32 (dpy, (long *) pixels, 4L * (long) (rep.nPixels));
- _XRead32 (dpy, (long *) masks, 4L * (long) (rep.nMasks));
- }
-
- UnlockDisplay(dpy);
- SyncHandle();
- return(status);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XAllocColorCells(
+ register Display *dpy,
+ Colormap cmap,
+ Bool contig,
+ unsigned long *masks, /* LISTofCARD32 */ /* RETURN */
+ unsigned int nplanes, /* CARD16 */
+ unsigned long *pixels, /* LISTofCARD32 */ /* RETURN */
+ unsigned int ncolors) /* CARD16 */
+{
+
+ Status status;
+ xAllocColorCellsReply rep;
+ register xAllocColorCellsReq *req;
+ LockDisplay(dpy);
+ GetReq(AllocColorCells, req);
+
+ req->cmap = cmap;
+ req->colors = ncolors;
+ req->planes = nplanes;
+ req->contiguous = contig;
+
+ status = _XReply(dpy, (xReply *)&rep, 0, xFalse);
+
+ if (status) {
+ _XRead32 (dpy, (long *) pixels, 4L * (long) (rep.nPixels));
+ _XRead32 (dpy, (long *) masks, 4L * (long) (rep.nMasks));
+ }
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(status);
+}
diff --git a/libX11/src/AllPlanes.c b/libX11/src/AllPlanes.c
index 7d422a6f4..02fff2340 100644
--- a/libX11/src/AllPlanes.c
+++ b/libX11/src/AllPlanes.c
@@ -1,75 +1,74 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XAllocColorPlanes(
- register Display *dpy,
- Colormap cmap,
- Bool contig,
- unsigned long *pixels, /* LISTofCARD32 */ /* RETURN */
- int ncolors,
- int nreds,
- int ngreens,
- int nblues,
- unsigned long *rmask,
- unsigned long *gmask,
- unsigned long *bmask) /* CARD32 */ /* RETURN */
-{
- xAllocColorPlanesReply rep;
- Status status;
- register xAllocColorPlanesReq *req;
-
- LockDisplay(dpy);
- GetReq(AllocColorPlanes,req);
-
- req->cmap = cmap;
- req->colors = ncolors;
- req->red = nreds;
- req->green = ngreens;
- req->blue = nblues;
- req->contiguous = contig;
-
- status = _XReply(dpy, (xReply *)&rep, 0, xFalse);
-
-
- if (status) {
- *rmask = rep.redMask;
- *gmask = rep.greenMask;
- *bmask = rep.blueMask;
-
- /* sizeof(CARD32) = 4 */
- _XRead32 (dpy, (long *) pixels, (long)(ncolors * 4));
- }
-
- UnlockDisplay(dpy);
- SyncHandle();
- return(status);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XAllocColorPlanes(
+ register Display *dpy,
+ Colormap cmap,
+ Bool contig,
+ unsigned long *pixels, /* LISTofCARD32 */ /* RETURN */
+ int ncolors,
+ int nreds,
+ int ngreens,
+ int nblues,
+ unsigned long *rmask,
+ unsigned long *gmask,
+ unsigned long *bmask) /* CARD32 */ /* RETURN */
+{
+ xAllocColorPlanesReply rep;
+ Status status;
+ register xAllocColorPlanesReq *req;
+
+ LockDisplay(dpy);
+ GetReq(AllocColorPlanes,req);
+
+ req->cmap = cmap;
+ req->colors = ncolors;
+ req->red = nreds;
+ req->green = ngreens;
+ req->blue = nblues;
+ req->contiguous = contig;
+
+ status = _XReply(dpy, (xReply *)&rep, 0, xFalse);
+
+
+ if (status) {
+ *rmask = rep.redMask;
+ *gmask = rep.greenMask;
+ *bmask = rep.blueMask;
+
+ /* sizeof(CARD32) = 4 */
+ _XRead32 (dpy, (long *) pixels, (long)(ncolors * 4));
+ }
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(status);
+}
diff --git a/libX11/src/ChkIfEv.c b/libX11/src/ChkIfEv.c
index 5c1dd2b9b..12065638d 100644
--- a/libX11/src/ChkIfEv.c
+++ b/libX11/src/ChkIfEv.c
@@ -1,84 +1,83 @@
-/*
-
-Copyright 1985, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * Check existing events in queue to find if any match. If so, return.
- * If not, flush buffer and see if any more events are readable. If one
- * matches, return. If all else fails, tell the user no events found.
- */
-
-Bool XCheckIfEvent (
- register Display *dpy,
- register XEvent *event, /* XEvent to be filled in. */
- Bool (*predicate)(
- Display* /* display */,
- XEvent* /* event */,
- char* /* arg */
- ), /* function to call */
- char *arg)
-{
- register _XQEvent *prev, *qelt;
- unsigned long qe_serial = 0;
- int n; /* time through count */
-
- LockDisplay(dpy);
- prev = NULL;
- for (n = 3; --n >= 0;) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if(qelt->qserial_num > qe_serial
- && (*predicate)(dpy, &qelt->event, arg)) {
- *event = qelt->event;
- _XDeq(dpy, prev, qelt);
- _XStoreEventCookie(dpy, event);
- UnlockDisplay(dpy);
- return True;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- switch (n) {
- case 2:
- _XEventsQueued(dpy, QueuedAfterReading);
- break;
- case 1:
- _XFlush(dpy);
- break;
- }
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
- UnlockDisplay(dpy);
- return False;
-}
+/*
+
+Copyright 1985, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * Check existing events in queue to find if any match. If so, return.
+ * If not, flush buffer and see if any more events are readable. If one
+ * matches, return. If all else fails, tell the user no events found.
+ */
+
+Bool XCheckIfEvent (
+ register Display *dpy,
+ register XEvent *event, /* XEvent to be filled in. */
+ Bool (*predicate)(
+ Display* /* display */,
+ XEvent* /* event */,
+ char* /* arg */
+ ), /* function to call */
+ char *arg)
+{
+ register _XQEvent *prev, *qelt;
+ unsigned long qe_serial = 0;
+ int n; /* time through count */
+
+ LockDisplay(dpy);
+ prev = NULL;
+ for (n = 3; --n >= 0;) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if(qelt->qserial_num > qe_serial
+ && (*predicate)(dpy, &qelt->event, arg)) {
+ *event = qelt->event;
+ _XDeq(dpy, prev, qelt);
+ _XStoreEventCookie(dpy, event);
+ UnlockDisplay(dpy);
+ return True;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ switch (n) {
+ case 2:
+ _XEventsQueued(dpy, QueuedAfterReading);
+ break;
+ case 1:
+ _XFlush(dpy);
+ break;
+ }
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+ UnlockDisplay(dpy);
+ return False;
+}
diff --git a/libX11/src/ChkMaskEv.c b/libX11/src/ChkMaskEv.c
index 71f724613..cd3af5d99 100644
--- a/libX11/src/ChkMaskEv.c
+++ b/libX11/src/ChkMaskEv.c
@@ -1,91 +1,90 @@
-/*
-
-Copyright 1985, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-extern long const _Xevent_to_mask[];
-
-#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
-#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
- Button4MotionMask|Button5MotionMask)
-
-/*
- * Check existing events in queue to find if any match. If so, return.
- * If not, flush buffer and see if any more events are readable. If one
- * matches, return. If all else fails, tell the user no events found.
- */
-
-Bool XCheckMaskEvent (
- register Display *dpy,
- long mask, /* Selected event mask. */
- register XEvent *event) /* XEvent to be filled in. */
-{
- register _XQEvent *prev, *qelt;
- unsigned long qe_serial = 0;
- int n; /* time through count */
-
- LockDisplay(dpy);
-
- /* Delete unclaimed cookies */
- _XFreeEventCookies(dpy);
-
- prev = NULL;
- for (n = 3; --n >= 0;) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if ((qelt->event.type < GenericEvent) &&
- (_Xevent_to_mask[qelt->event.type] & mask) &&
- ((qelt->event.type != MotionNotify) ||
- (mask & AllPointers) ||
- (mask & AllButtons & qelt->event.xmotion.state))) {
- *event = qelt->event;
- _XDeq(dpy, prev, qelt);
- UnlockDisplay(dpy);
- return True;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- switch (n) {
- case 2:
- _XEventsQueued(dpy, QueuedAfterReading);
- break;
- case 1:
- _XFlush(dpy);
- break;
- }
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
- UnlockDisplay(dpy);
- return False;
-}
+/*
+
+Copyright 1985, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+extern long const _Xevent_to_mask[];
+
+#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
+#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
+ Button4MotionMask|Button5MotionMask)
+
+/*
+ * Check existing events in queue to find if any match. If so, return.
+ * If not, flush buffer and see if any more events are readable. If one
+ * matches, return. If all else fails, tell the user no events found.
+ */
+
+Bool XCheckMaskEvent (
+ register Display *dpy,
+ long mask, /* Selected event mask. */
+ register XEvent *event) /* XEvent to be filled in. */
+{
+ register _XQEvent *prev, *qelt;
+ unsigned long qe_serial = 0;
+ int n; /* time through count */
+
+ LockDisplay(dpy);
+
+ /* Delete unclaimed cookies */
+ _XFreeEventCookies(dpy);
+
+ prev = NULL;
+ for (n = 3; --n >= 0;) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if ((qelt->event.type < GenericEvent) &&
+ (_Xevent_to_mask[qelt->event.type] & mask) &&
+ ((qelt->event.type != MotionNotify) ||
+ (mask & AllPointers) ||
+ (mask & AllButtons & qelt->event.xmotion.state))) {
+ *event = qelt->event;
+ _XDeq(dpy, prev, qelt);
+ UnlockDisplay(dpy);
+ return True;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ switch (n) {
+ case 2:
+ _XEventsQueued(dpy, QueuedAfterReading);
+ break;
+ case 1:
+ _XFlush(dpy);
+ break;
+ }
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+ UnlockDisplay(dpy);
+ return False;
+}
diff --git a/libX11/src/ChkTypEv.c b/libX11/src/ChkTypEv.c
index bb1dbe74c..ccc05edc0 100644
--- a/libX11/src/ChkTypEv.c
+++ b/libX11/src/ChkTypEv.c
@@ -1,81 +1,80 @@
-/*
-
-Copyright 1985, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * Check existing events in queue to find if any match. If so, return.
- * If not, flush buffer and see if any more events are readable. If one
- * matches, return. If all else fails, tell the user no events found.
- */
-
-Bool XCheckTypedEvent (
- register Display *dpy,
- int type, /* Selected event type. */
- register XEvent *event) /* XEvent to be filled in. */
-{
- register _XQEvent *prev, *qelt;
- unsigned long qe_serial = 0;
- int n; /* time through count */
-
- LockDisplay(dpy);
-
- /* Delete unclaimed cookies */
- _XFreeEventCookies(dpy);
-
- prev = NULL;
- for (n = 3; --n >= 0;) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if (qelt->event.type == type) {
- *event = qelt->event;
- _XDeq(dpy, prev, qelt);
- UnlockDisplay(dpy);
- return True;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- switch (n) {
- case 2:
- _XEventsQueued(dpy, QueuedAfterReading);
- break;
- case 1:
- _XFlush(dpy);
- break;
- }
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
- UnlockDisplay(dpy);
- return False;
-}
+/*
+
+Copyright 1985, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * Check existing events in queue to find if any match. If so, return.
+ * If not, flush buffer and see if any more events are readable. If one
+ * matches, return. If all else fails, tell the user no events found.
+ */
+
+Bool XCheckTypedEvent (
+ register Display *dpy,
+ int type, /* Selected event type. */
+ register XEvent *event) /* XEvent to be filled in. */
+{
+ register _XQEvent *prev, *qelt;
+ unsigned long qe_serial = 0;
+ int n; /* time through count */
+
+ LockDisplay(dpy);
+
+ /* Delete unclaimed cookies */
+ _XFreeEventCookies(dpy);
+
+ prev = NULL;
+ for (n = 3; --n >= 0;) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if (qelt->event.type == type) {
+ *event = qelt->event;
+ _XDeq(dpy, prev, qelt);
+ UnlockDisplay(dpy);
+ return True;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ switch (n) {
+ case 2:
+ _XEventsQueued(dpy, QueuedAfterReading);
+ break;
+ case 1:
+ _XFlush(dpy);
+ break;
+ }
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+ UnlockDisplay(dpy);
+ return False;
+}
diff --git a/libX11/src/ChkTypWEv.c b/libX11/src/ChkTypWEv.c
index e2fd6bf48..84abd6dcc 100644
--- a/libX11/src/ChkTypWEv.c
+++ b/libX11/src/ChkTypWEv.c
@@ -1,83 +1,82 @@
-/*
-
-Copyright 1985, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * Check existing events in queue to find if any match. If so, return.
- * If not, flush buffer and see if any more events are readable. If one
- * matches, return. If all else fails, tell the user no events found.
- */
-
-Bool XCheckTypedWindowEvent (
- register Display *dpy,
- Window w, /* Selected window. */
- int type, /* Selected event type. */
- register XEvent *event) /* XEvent to be filled in. */
-{
- register _XQEvent *prev, *qelt;
- unsigned long qe_serial = 0;
- int n; /* time through count */
-
- LockDisplay(dpy);
-
- /* Delete unclaimed cookies */
- _XFreeEventCookies(dpy);
-
- prev = NULL;
- for (n = 3; --n >= 0;) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if ((qelt->event.xany.window == w) &&
- (qelt->event.type == type)) {
- *event = qelt->event;
- _XDeq(dpy, prev, qelt);
- UnlockDisplay(dpy);
- return True;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- switch (n) {
- case 2:
- _XEventsQueued(dpy, QueuedAfterReading);
- break;
- case 1:
- _XFlush(dpy);
- break;
- }
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
- UnlockDisplay(dpy);
- return False;
-}
+/*
+
+Copyright 1985, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * Check existing events in queue to find if any match. If so, return.
+ * If not, flush buffer and see if any more events are readable. If one
+ * matches, return. If all else fails, tell the user no events found.
+ */
+
+Bool XCheckTypedWindowEvent (
+ register Display *dpy,
+ Window w, /* Selected window. */
+ int type, /* Selected event type. */
+ register XEvent *event) /* XEvent to be filled in. */
+{
+ register _XQEvent *prev, *qelt;
+ unsigned long qe_serial = 0;
+ int n; /* time through count */
+
+ LockDisplay(dpy);
+
+ /* Delete unclaimed cookies */
+ _XFreeEventCookies(dpy);
+
+ prev = NULL;
+ for (n = 3; --n >= 0;) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if ((qelt->event.xany.window == w) &&
+ (qelt->event.type == type)) {
+ *event = qelt->event;
+ _XDeq(dpy, prev, qelt);
+ UnlockDisplay(dpy);
+ return True;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ switch (n) {
+ case 2:
+ _XEventsQueued(dpy, QueuedAfterReading);
+ break;
+ case 1:
+ _XFlush(dpy);
+ break;
+ }
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+ UnlockDisplay(dpy);
+ return False;
+}
diff --git a/libX11/src/ChkWinEv.c b/libX11/src/ChkWinEv.c
index 683c8f1c9..299086399 100644
--- a/libX11/src/ChkWinEv.c
+++ b/libX11/src/ChkWinEv.c
@@ -1,92 +1,91 @@
-/*
-
-Copyright 1985, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-extern long const _Xevent_to_mask[];
-#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
-#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
- Button4MotionMask|Button5MotionMask)
-
-/*
- * Check existing events in queue to find if any match. If so, return.
- * If not, flush buffer and see if any more events are readable. If one
- * matches, return. If all else fails, tell the user no events found.
- */
-
-Bool XCheckWindowEvent (
- register Display *dpy,
- Window w, /* Selected window. */
- long mask, /* Selected event mask. */
- register XEvent *event) /* XEvent to be filled in. */
-{
- register _XQEvent *prev, *qelt;
- unsigned long qe_serial = 0;
- int n; /* time through count */
-
- LockDisplay(dpy);
-
- /* Delete unclaimed cookies */
- _XFreeEventCookies(dpy);
-
- prev = NULL;
- for (n = 3; --n >= 0;) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if ((qelt->event.xany.window == w) &&
- (qelt->event.type < GenericEvent) &&
- (_Xevent_to_mask[qelt->event.type] & mask) &&
- ((qelt->event.type != MotionNotify) ||
- (mask & AllPointers) ||
- (mask & AllButtons & qelt->event.xmotion.state))) {
- *event = qelt->event;
- _XDeq(dpy, prev, qelt);
- UnlockDisplay(dpy);
- return True;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- switch (n) {
- case 2:
- _XEventsQueued(dpy, QueuedAfterReading);
- break;
- case 1:
- _XFlush(dpy);
- break;
- }
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
- UnlockDisplay(dpy);
- return False;
-}
+/*
+
+Copyright 1985, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+extern long const _Xevent_to_mask[];
+#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
+#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
+ Button4MotionMask|Button5MotionMask)
+
+/*
+ * Check existing events in queue to find if any match. If so, return.
+ * If not, flush buffer and see if any more events are readable. If one
+ * matches, return. If all else fails, tell the user no events found.
+ */
+
+Bool XCheckWindowEvent (
+ register Display *dpy,
+ Window w, /* Selected window. */
+ long mask, /* Selected event mask. */
+ register XEvent *event) /* XEvent to be filled in. */
+{
+ register _XQEvent *prev, *qelt;
+ unsigned long qe_serial = 0;
+ int n; /* time through count */
+
+ LockDisplay(dpy);
+
+ /* Delete unclaimed cookies */
+ _XFreeEventCookies(dpy);
+
+ prev = NULL;
+ for (n = 3; --n >= 0;) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if ((qelt->event.xany.window == w) &&
+ (qelt->event.type < GenericEvent) &&
+ (_Xevent_to_mask[qelt->event.type] & mask) &&
+ ((qelt->event.type != MotionNotify) ||
+ (mask & AllPointers) ||
+ (mask & AllButtons & qelt->event.xmotion.state))) {
+ *event = qelt->event;
+ _XDeq(dpy, prev, qelt);
+ UnlockDisplay(dpy);
+ return True;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ switch (n) {
+ case 2:
+ _XEventsQueued(dpy, QueuedAfterReading);
+ break;
+ case 1:
+ _XFlush(dpy);
+ break;
+ }
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+ UnlockDisplay(dpy);
+ return False;
+}
diff --git a/libX11/src/EvToWire.c b/libX11/src/EvToWire.c
index 77e70f34a..6e2db3901 100644
--- a/libX11/src/EvToWire.c
+++ b/libX11/src/EvToWire.c
@@ -1,408 +1,406 @@
-
-/*
-
-Copyright 1985, 1986, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-/*
- * XEvToWire.c - Internal support routines for the C subroutine
- * interface library (Xlib) to the X Window System Protocol V11.0.
- */
-#define NEED_EVENTS
-#define NEED_REPLIES
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * Reformat an XEvent structure to a wire event of the right type.
- * Return True on success. If the type is unrecognized, return what
- * _XUnknownNativeEvent returns (i.e., False).
- */
-Status
-_XEventToWire(
- register Display *dpy,
- register XEvent *re, /* in: from */
- register xEvent *event) /* out: to */
-{
- switch (event->u.u.type = re->type) {
- case KeyPress:
- case KeyRelease:
- {
- register XKeyEvent *ev = (XKeyEvent*) re;
- event->u.keyButtonPointer.root = ev->root;
- event->u.keyButtonPointer.event = ev->window;
- event->u.keyButtonPointer.child = ev->subwindow;
- event->u.keyButtonPointer.time = ev->time;
- event->u.keyButtonPointer.eventX = ev->x ;
- event->u.keyButtonPointer.eventY = ev->y ;
- event->u.keyButtonPointer.rootX = ev->x_root;
- event->u.keyButtonPointer.rootY = ev->y_root;
- event->u.keyButtonPointer.state = ev->state;
- 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 = ev->root;
- event->u.keyButtonPointer.event = ev->window;
- event->u.keyButtonPointer.child = ev->subwindow;
- event->u.keyButtonPointer.time = ev->time;
- event->u.keyButtonPointer.eventX = ev->x;
- event->u.keyButtonPointer.eventY = ev->y;
- event->u.keyButtonPointer.rootX = ev->x_root;
- event->u.keyButtonPointer.rootY = ev->y_root;
- event->u.keyButtonPointer.state = ev->state;
- 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 = ev->root;
- event->u.keyButtonPointer.event = ev->window;
- event->u.keyButtonPointer.child = ev->subwindow;
- event->u.keyButtonPointer.time = ev->time;
- event->u.keyButtonPointer.eventX= ev->x;
- event->u.keyButtonPointer.eventY= ev->y;
- event->u.keyButtonPointer.rootX = ev->x_root;
- event->u.keyButtonPointer.rootY = ev->y_root;
- event->u.keyButtonPointer.state = ev->state;
- 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 = ev->root;
- event->u.enterLeave.event = ev->window;
- event->u.enterLeave.child = ev->subwindow;
- event->u.enterLeave.time = ev->time;
- event->u.enterLeave.eventX = ev->x;
- event->u.enterLeave.eventY = ev->y;
- event->u.enterLeave.rootX = ev->x_root;
- event->u.enterLeave.rootY = ev->y_root;
- event->u.enterLeave.state = ev->state;
- 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 = ev->window;
- 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 = ev->window;
- event->u.expose.x = ev->x;
- event->u.expose.y = ev->y;
- event->u.expose.width = ev->width;
- event->u.expose.height = ev->height;
- event->u.expose.count = ev->count;
- }
- break;
- case GraphicsExpose:
- {
- register XGraphicsExposeEvent *ev =
- (XGraphicsExposeEvent *) re;
- event->u.graphicsExposure.drawable = ev->drawable;
- event->u.graphicsExposure.x = ev->x;
- event->u.graphicsExposure.y = ev->y;
- event->u.graphicsExposure.width = ev->width;
- event->u.graphicsExposure.height = ev->height;
- event->u.graphicsExposure.count = ev->count;
- event->u.graphicsExposure.majorEvent= ev->major_code;
- event->u.graphicsExposure.minorEvent= ev->minor_code;
- }
- break;
- case NoExpose:
- {
- register XNoExposeEvent *ev = (XNoExposeEvent *) re;
- event->u.noExposure.drawable = ev->drawable;
- event->u.noExposure.majorEvent = ev->major_code;
- event->u.noExposure.minorEvent = ev->minor_code;
- }
- break;
- case VisibilityNotify:
- {
- register XVisibilityEvent *ev = (XVisibilityEvent *) re;
- event->u.visibility.window = ev->window;
- event->u.visibility.state = ev->state;
- }
- break;
- case CreateNotify:
- {
- register XCreateWindowEvent *ev =
- (XCreateWindowEvent *) re;
- event->u.createNotify.window = ev->window;
- event->u.createNotify.parent = ev->parent;
- event->u.createNotify.x = ev->x;
- event->u.createNotify.y = ev->y;
- event->u.createNotify.width = ev->width;
- event->u.createNotify.height = ev->height;
- event->u.createNotify.borderWidth = ev->border_width;
- event->u.createNotify.override = ev->override_redirect;
- }
- break;
- case DestroyNotify:
- {
- register XDestroyWindowEvent *ev =
- (XDestroyWindowEvent *) re;
- event->u.destroyNotify.window = ev->window;
- event->u.destroyNotify.event = ev->event;
- }
- break;
- case UnmapNotify:
- {
- register XUnmapEvent *ev = (XUnmapEvent *) re;
- event->u.unmapNotify.window = ev->window;
- event->u.unmapNotify.event = ev->event;
- event->u.unmapNotify.fromConfigure = ev->from_configure;
- }
- break;
- case MapNotify:
- {
- register XMapEvent *ev = (XMapEvent *) re;
- event->u.mapNotify.window = ev->window;
- event->u.mapNotify.event = ev->event;
- event->u.mapNotify.override = ev->override_redirect;
- }
- break;
- case MapRequest:
- {
- register XMapRequestEvent *ev = (XMapRequestEvent *) re;
- event->u.mapRequest.window = ev->window;
- event->u.mapRequest.parent = ev->parent;
- }
- break;
- case ReparentNotify:
- {
- register XReparentEvent *ev = (XReparentEvent *) re;
- event->u.reparent.window = ev->window;
- event->u.reparent.event = ev->event;
- event->u.reparent.parent = ev->parent;
- event->u.reparent.x = ev->x;
- event->u.reparent.y = ev->y;
- event->u.reparent.override = ev->override_redirect;
- }
- break;
- case ConfigureNotify:
- {
- register XConfigureEvent *ev = (XConfigureEvent *) re;
- event->u.configureNotify.window = ev->window;
- event->u.configureNotify.event = ev->event;
- event->u.configureNotify.aboveSibling = ev->above;
- event->u.configureNotify.x = ev->x;
- event->u.configureNotify.y = ev->y;
- event->u.configureNotify.width = ev->width;
- event->u.configureNotify.height = ev->height;
- event->u.configureNotify.borderWidth= ev->border_width;
- event->u.configureNotify.override = ev->override_redirect;
- }
- break;
- case ConfigureRequest:
- {
- register XConfigureRequestEvent *ev =
- (XConfigureRequestEvent *) re;
- event->u.configureRequest.window = ev->window;
- event->u.configureRequest.parent = ev->parent;
- event->u.configureRequest.sibling = ev->above;
- event->u.configureRequest.x = ev->x;
- event->u.configureRequest.y = ev->y;
- event->u.configureRequest.width = ev->width;
- event->u.configureRequest.height = ev->height;
- event->u.configureRequest.borderWidth= ev->border_width;
- event->u.configureRequest.valueMask= ev->value_mask;
- event->u.u.detail = ev->detail;
- }
- break;
- case GravityNotify:
- {
- register XGravityEvent *ev = (XGravityEvent *) re;
- event->u.gravity.window = ev->window;
- event->u.gravity.event = ev->event;
- event->u.gravity.x = ev->x;
- event->u.gravity.y = ev->y;
- }
- break;
- case ResizeRequest:
- {
- register XResizeRequestEvent *ev =
- (XResizeRequestEvent *) re;
- event->u.resizeRequest.window = ev->window;
- event->u.resizeRequest.width = ev->width;
- event->u.resizeRequest.height = ev->height;
- }
- break;
- case CirculateNotify:
- {
- register XCirculateEvent *ev = (XCirculateEvent *) re;
- event->u.circulate.window = ev->window;
- event->u.circulate.event = ev->event;
- event->u.circulate.place = ev->place;
- }
- break;
- case CirculateRequest:
- {
- register XCirculateRequestEvent *ev =
- (XCirculateRequestEvent *) re;
- event->u.circulate.window = ev->window;
- event->u.circulate.event = ev->parent;
- event->u.circulate.place = ev->place;
- }
- break;
- case PropertyNotify:
- {
- register XPropertyEvent *ev = (XPropertyEvent *) re;
- event->u.property.window = ev->window;
- event->u.property.atom = ev->atom;
- event->u.property.time = ev->time;
- event->u.property.state = ev->state;
- }
- break;
- case SelectionClear:
- {
- register XSelectionClearEvent *ev =
- (XSelectionClearEvent *) re;
- event->u.selectionClear.window = ev->window;
- event->u.selectionClear.atom = ev->selection;
- event->u.selectionClear.time = ev->time;
- }
- break;
- case SelectionRequest:
- {
- register XSelectionRequestEvent *ev =
- (XSelectionRequestEvent *) re;
- event->u.selectionRequest.owner = ev->owner;
- event->u.selectionRequest.requestor = ev->requestor;
- event->u.selectionRequest.selection = ev->selection;
- event->u.selectionRequest.target = ev->target;
- event->u.selectionRequest.property = ev->property;
- event->u.selectionRequest.time = ev->time;
- }
- break;
- case SelectionNotify:
- {
- register XSelectionEvent *ev = (XSelectionEvent *) re;
- event->u.selectionNotify.requestor = ev->requestor;
- event->u.selectionNotify.selection = ev->selection;
- event->u.selectionNotify.target = ev->target;
- event->u.selectionNotify.property = ev->property;
- event->u.selectionNotify.time = ev->time;
- }
- break;
- case ColormapNotify:
- {
- register XColormapEvent *ev = (XColormapEvent *) re;
- event->u.colormap.window = ev->window;
- event->u.colormap.colormap = ev->colormap;
- 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 = ev->window;
- event->u.u.detail = ev->format;
- switch (ev->format) {
- case 8:
- event->u.clientMessage.u.b.type = ev->message_type;
- 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 = ev->message_type;
- event->u.clientMessage.u.s.shorts0 = ev->data.s[0];
- event->u.clientMessage.u.s.shorts1 = ev->data.s[1];
- event->u.clientMessage.u.s.shorts2 = ev->data.s[2];
- event->u.clientMessage.u.s.shorts3 = ev->data.s[3];
- event->u.clientMessage.u.s.shorts4 = ev->data.s[4];
- event->u.clientMessage.u.s.shorts5 = ev->data.s[5];
- event->u.clientMessage.u.s.shorts6 = ev->data.s[6];
- event->u.clientMessage.u.s.shorts7 = ev->data.s[7];
- event->u.clientMessage.u.s.shorts8 = ev->data.s[8];
- event->u.clientMessage.u.s.shorts9 = ev->data.s[9];
- break;
- case 32:
- event->u.clientMessage.u.l.type = ev->message_type;
- event->u.clientMessage.u.l.longs0 = ev->data.l[0];
- event->u.clientMessage.u.l.longs1 = ev->data.l[1];
- event->u.clientMessage.u.l.longs2 = ev->data.l[2];
- event->u.clientMessage.u.l.longs3 = ev->data.l[3];
- event->u.clientMessage.u.l.longs4 = ev->data.l[4];
- 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(_XUnknownNativeEvent(dpy, re, event));
- }
- return(1);
-}
+
+/*
+
+Copyright 1985, 1986, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+/*
+ * XEvToWire.c - Internal support routines for the C subroutine
+ * interface library (Xlib) to the X Window System Protocol V11.0.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * Reformat an XEvent structure to a wire event of the right type.
+ * Return True on success. If the type is unrecognized, return what
+ * _XUnknownNativeEvent returns (i.e., False).
+ */
+Status
+_XEventToWire(
+ register Display *dpy,
+ register XEvent *re, /* in: from */
+ register xEvent *event) /* out: to */
+{
+ switch (event->u.u.type = re->type) {
+ case KeyPress:
+ case KeyRelease:
+ {
+ register XKeyEvent *ev = (XKeyEvent*) re;
+ event->u.keyButtonPointer.root = ev->root;
+ event->u.keyButtonPointer.event = ev->window;
+ event->u.keyButtonPointer.child = ev->subwindow;
+ event->u.keyButtonPointer.time = ev->time;
+ event->u.keyButtonPointer.eventX = ev->x ;
+ event->u.keyButtonPointer.eventY = ev->y ;
+ event->u.keyButtonPointer.rootX = ev->x_root;
+ event->u.keyButtonPointer.rootY = ev->y_root;
+ event->u.keyButtonPointer.state = ev->state;
+ 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 = ev->root;
+ event->u.keyButtonPointer.event = ev->window;
+ event->u.keyButtonPointer.child = ev->subwindow;
+ event->u.keyButtonPointer.time = ev->time;
+ event->u.keyButtonPointer.eventX = ev->x;
+ event->u.keyButtonPointer.eventY = ev->y;
+ event->u.keyButtonPointer.rootX = ev->x_root;
+ event->u.keyButtonPointer.rootY = ev->y_root;
+ event->u.keyButtonPointer.state = ev->state;
+ 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 = ev->root;
+ event->u.keyButtonPointer.event = ev->window;
+ event->u.keyButtonPointer.child = ev->subwindow;
+ event->u.keyButtonPointer.time = ev->time;
+ event->u.keyButtonPointer.eventX= ev->x;
+ event->u.keyButtonPointer.eventY= ev->y;
+ event->u.keyButtonPointer.rootX = ev->x_root;
+ event->u.keyButtonPointer.rootY = ev->y_root;
+ event->u.keyButtonPointer.state = ev->state;
+ 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 = ev->root;
+ event->u.enterLeave.event = ev->window;
+ event->u.enterLeave.child = ev->subwindow;
+ event->u.enterLeave.time = ev->time;
+ event->u.enterLeave.eventX = ev->x;
+ event->u.enterLeave.eventY = ev->y;
+ event->u.enterLeave.rootX = ev->x_root;
+ event->u.enterLeave.rootY = ev->y_root;
+ event->u.enterLeave.state = ev->state;
+ 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 = ev->window;
+ 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 = ev->window;
+ event->u.expose.x = ev->x;
+ event->u.expose.y = ev->y;
+ event->u.expose.width = ev->width;
+ event->u.expose.height = ev->height;
+ event->u.expose.count = ev->count;
+ }
+ break;
+ case GraphicsExpose:
+ {
+ register XGraphicsExposeEvent *ev =
+ (XGraphicsExposeEvent *) re;
+ event->u.graphicsExposure.drawable = ev->drawable;
+ event->u.graphicsExposure.x = ev->x;
+ event->u.graphicsExposure.y = ev->y;
+ event->u.graphicsExposure.width = ev->width;
+ event->u.graphicsExposure.height = ev->height;
+ event->u.graphicsExposure.count = ev->count;
+ event->u.graphicsExposure.majorEvent= ev->major_code;
+ event->u.graphicsExposure.minorEvent= ev->minor_code;
+ }
+ break;
+ case NoExpose:
+ {
+ register XNoExposeEvent *ev = (XNoExposeEvent *) re;
+ event->u.noExposure.drawable = ev->drawable;
+ event->u.noExposure.majorEvent = ev->major_code;
+ event->u.noExposure.minorEvent = ev->minor_code;
+ }
+ break;
+ case VisibilityNotify:
+ {
+ register XVisibilityEvent *ev = (XVisibilityEvent *) re;
+ event->u.visibility.window = ev->window;
+ event->u.visibility.state = ev->state;
+ }
+ break;
+ case CreateNotify:
+ {
+ register XCreateWindowEvent *ev =
+ (XCreateWindowEvent *) re;
+ event->u.createNotify.window = ev->window;
+ event->u.createNotify.parent = ev->parent;
+ event->u.createNotify.x = ev->x;
+ event->u.createNotify.y = ev->y;
+ event->u.createNotify.width = ev->width;
+ event->u.createNotify.height = ev->height;
+ event->u.createNotify.borderWidth = ev->border_width;
+ event->u.createNotify.override = ev->override_redirect;
+ }
+ break;
+ case DestroyNotify:
+ {
+ register XDestroyWindowEvent *ev =
+ (XDestroyWindowEvent *) re;
+ event->u.destroyNotify.window = ev->window;
+ event->u.destroyNotify.event = ev->event;
+ }
+ break;
+ case UnmapNotify:
+ {
+ register XUnmapEvent *ev = (XUnmapEvent *) re;
+ event->u.unmapNotify.window = ev->window;
+ event->u.unmapNotify.event = ev->event;
+ event->u.unmapNotify.fromConfigure = ev->from_configure;
+ }
+ break;
+ case MapNotify:
+ {
+ register XMapEvent *ev = (XMapEvent *) re;
+ event->u.mapNotify.window = ev->window;
+ event->u.mapNotify.event = ev->event;
+ event->u.mapNotify.override = ev->override_redirect;
+ }
+ break;
+ case MapRequest:
+ {
+ register XMapRequestEvent *ev = (XMapRequestEvent *) re;
+ event->u.mapRequest.window = ev->window;
+ event->u.mapRequest.parent = ev->parent;
+ }
+ break;
+ case ReparentNotify:
+ {
+ register XReparentEvent *ev = (XReparentEvent *) re;
+ event->u.reparent.window = ev->window;
+ event->u.reparent.event = ev->event;
+ event->u.reparent.parent = ev->parent;
+ event->u.reparent.x = ev->x;
+ event->u.reparent.y = ev->y;
+ event->u.reparent.override = ev->override_redirect;
+ }
+ break;
+ case ConfigureNotify:
+ {
+ register XConfigureEvent *ev = (XConfigureEvent *) re;
+ event->u.configureNotify.window = ev->window;
+ event->u.configureNotify.event = ev->event;
+ event->u.configureNotify.aboveSibling = ev->above;
+ event->u.configureNotify.x = ev->x;
+ event->u.configureNotify.y = ev->y;
+ event->u.configureNotify.width = ev->width;
+ event->u.configureNotify.height = ev->height;
+ event->u.configureNotify.borderWidth= ev->border_width;
+ event->u.configureNotify.override = ev->override_redirect;
+ }
+ break;
+ case ConfigureRequest:
+ {
+ register XConfigureRequestEvent *ev =
+ (XConfigureRequestEvent *) re;
+ event->u.configureRequest.window = ev->window;
+ event->u.configureRequest.parent = ev->parent;
+ event->u.configureRequest.sibling = ev->above;
+ event->u.configureRequest.x = ev->x;
+ event->u.configureRequest.y = ev->y;
+ event->u.configureRequest.width = ev->width;
+ event->u.configureRequest.height = ev->height;
+ event->u.configureRequest.borderWidth= ev->border_width;
+ event->u.configureRequest.valueMask= ev->value_mask;
+ event->u.u.detail = ev->detail;
+ }
+ break;
+ case GravityNotify:
+ {
+ register XGravityEvent *ev = (XGravityEvent *) re;
+ event->u.gravity.window = ev->window;
+ event->u.gravity.event = ev->event;
+ event->u.gravity.x = ev->x;
+ event->u.gravity.y = ev->y;
+ }
+ break;
+ case ResizeRequest:
+ {
+ register XResizeRequestEvent *ev =
+ (XResizeRequestEvent *) re;
+ event->u.resizeRequest.window = ev->window;
+ event->u.resizeRequest.width = ev->width;
+ event->u.resizeRequest.height = ev->height;
+ }
+ break;
+ case CirculateNotify:
+ {
+ register XCirculateEvent *ev = (XCirculateEvent *) re;
+ event->u.circulate.window = ev->window;
+ event->u.circulate.event = ev->event;
+ event->u.circulate.place = ev->place;
+ }
+ break;
+ case CirculateRequest:
+ {
+ register XCirculateRequestEvent *ev =
+ (XCirculateRequestEvent *) re;
+ event->u.circulate.window = ev->window;
+ event->u.circulate.event = ev->parent;
+ event->u.circulate.place = ev->place;
+ }
+ break;
+ case PropertyNotify:
+ {
+ register XPropertyEvent *ev = (XPropertyEvent *) re;
+ event->u.property.window = ev->window;
+ event->u.property.atom = ev->atom;
+ event->u.property.time = ev->time;
+ event->u.property.state = ev->state;
+ }
+ break;
+ case SelectionClear:
+ {
+ register XSelectionClearEvent *ev =
+ (XSelectionClearEvent *) re;
+ event->u.selectionClear.window = ev->window;
+ event->u.selectionClear.atom = ev->selection;
+ event->u.selectionClear.time = ev->time;
+ }
+ break;
+ case SelectionRequest:
+ {
+ register XSelectionRequestEvent *ev =
+ (XSelectionRequestEvent *) re;
+ event->u.selectionRequest.owner = ev->owner;
+ event->u.selectionRequest.requestor = ev->requestor;
+ event->u.selectionRequest.selection = ev->selection;
+ event->u.selectionRequest.target = ev->target;
+ event->u.selectionRequest.property = ev->property;
+ event->u.selectionRequest.time = ev->time;
+ }
+ break;
+ case SelectionNotify:
+ {
+ register XSelectionEvent *ev = (XSelectionEvent *) re;
+ event->u.selectionNotify.requestor = ev->requestor;
+ event->u.selectionNotify.selection = ev->selection;
+ event->u.selectionNotify.target = ev->target;
+ event->u.selectionNotify.property = ev->property;
+ event->u.selectionNotify.time = ev->time;
+ }
+ break;
+ case ColormapNotify:
+ {
+ register XColormapEvent *ev = (XColormapEvent *) re;
+ event->u.colormap.window = ev->window;
+ event->u.colormap.colormap = ev->colormap;
+ 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 = ev->window;
+ event->u.u.detail = ev->format;
+ switch (ev->format) {
+ case 8:
+ event->u.clientMessage.u.b.type = ev->message_type;
+ 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 = ev->message_type;
+ event->u.clientMessage.u.s.shorts0 = ev->data.s[0];
+ event->u.clientMessage.u.s.shorts1 = ev->data.s[1];
+ event->u.clientMessage.u.s.shorts2 = ev->data.s[2];
+ event->u.clientMessage.u.s.shorts3 = ev->data.s[3];
+ event->u.clientMessage.u.s.shorts4 = ev->data.s[4];
+ event->u.clientMessage.u.s.shorts5 = ev->data.s[5];
+ event->u.clientMessage.u.s.shorts6 = ev->data.s[6];
+ event->u.clientMessage.u.s.shorts7 = ev->data.s[7];
+ event->u.clientMessage.u.s.shorts8 = ev->data.s[8];
+ event->u.clientMessage.u.s.shorts9 = ev->data.s[9];
+ break;
+ case 32:
+ event->u.clientMessage.u.l.type = ev->message_type;
+ event->u.clientMessage.u.l.longs0 = ev->data.l[0];
+ event->u.clientMessage.u.l.longs1 = ev->data.l[1];
+ event->u.clientMessage.u.l.longs2 = ev->data.l[2];
+ event->u.clientMessage.u.l.longs3 = ev->data.l[3];
+ event->u.clientMessage.u.l.longs4 = ev->data.l[4];
+ 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(_XUnknownNativeEvent(dpy, re, event));
+ }
+ return(1);
+}
diff --git a/libX11/src/FilterEv.c b/libX11/src/FilterEv.c
index 2611a7f71..a4a21027f 100644
--- a/libX11/src/FilterEv.c
+++ b/libX11/src/FilterEv.c
@@ -1,107 +1,106 @@
-
- /*
- * Copyright 1990, 1991 by OMRON 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 OMRON not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. OMRON makes no representations
- * about the suitability of this software for any purpose. It is provided
- * "as is" without express or implied warranty.
- *
- * OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL OMRON 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
- * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Seiji Kuwari OMRON Corporation
- * kuwa@omron.co.jp
- * kuwa%omron.co.jp@uunet.uu.net
- */
-
-/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#else
-#define XLOCALE 1
-#endif
-#include "Xlibint.h"
-#if XLOCALE
-#include "Xlcint.h"
-#endif
-
-extern long const _Xevent_to_mask[];
-
-/*
- * Look up if there is a specified filter for the event.
- */
-Bool
-XFilterEvent(
- XEvent *ev,
- Window window)
-{
-#if XLOCALE
- XFilterEventList p;
- Window win;
- long mask;
- Bool ret;
-
- if (window)
- win = window;
- else
- win = ev->xany.window;
- if (ev->type >= LASTEvent)
- mask = 0;
- else
- mask = _Xevent_to_mask[ev->type];
-
- LockDisplay(ev->xany.display);
- for (p = ev->xany.display->im_filters; p != NULL; p = p->next) {
- if (win == p->window) {
- if ((mask & p->event_mask) ||
- (ev->type >= p->start_type && ev->type <= p->end_type)) {
- UnlockDisplay(ev->xany.display);
- ret = (*(p->filter))(ev->xany.display, p->window, ev,
- p->client_data);
- return(ret);
- }
- }
- }
- UnlockDisplay(ev->xany.display);
-#endif
- return(False);
-}
+
+ /*
+ * Copyright 1990, 1991 by OMRON 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 OMRON not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. OMRON makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL OMRON 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
+ * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Seiji Kuwari OMRON Corporation
+ * kuwa@omron.co.jp
+ * kuwa%omron.co.jp@uunet.uu.net
+ */
+
+/*
+
+Copyright 1991, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#define XLOCALE 1
+#endif
+#include "Xlibint.h"
+#if XLOCALE
+#include "Xlcint.h"
+#endif
+
+extern long const _Xevent_to_mask[];
+
+/*
+ * Look up if there is a specified filter for the event.
+ */
+Bool
+XFilterEvent(
+ XEvent *ev,
+ Window window)
+{
+#if XLOCALE
+ XFilterEventList p;
+ Window win;
+ long mask;
+ Bool ret;
+
+ if (window)
+ win = window;
+ else
+ win = ev->xany.window;
+ if (ev->type >= LASTEvent)
+ mask = 0;
+ else
+ mask = _Xevent_to_mask[ev->type];
+
+ LockDisplay(ev->xany.display);
+ for (p = ev->xany.display->im_filters; p != NULL; p = p->next) {
+ if (win == p->window) {
+ if ((mask & p->event_mask) ||
+ (ev->type >= p->start_type && ev->type <= p->end_type)) {
+ UnlockDisplay(ev->xany.display);
+ ret = (*(p->filter))(ev->xany.display, p->window, ev,
+ p->client_data);
+ return(ret);
+ }
+ }
+ }
+ UnlockDisplay(ev->xany.display);
+#endif
+ return(False);
+}
diff --git a/libX11/src/Font.c b/libX11/src/Font.c
index b664b8dd1..857136a34 100644
--- a/libX11/src/Font.c
+++ b/libX11/src/Font.c
@@ -1,731 +1,730 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-Copyright (c) 2000 The XFree86 Project, Inc.
-
-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.
-
-The above copyright notice and this permission notice 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
-X CONSORTIUM OR THE XFREE86 PROJECT 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.
-
-Except as contained in this notice, the name of the X Consortium or of the
-XFree86 Project shall not be used in advertising or otherwise to promote the
-sale, use or other dealings in this Software without prior written
-authorization from the X Consortium and the XFree86 Project.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-#if defined(XF86BIGFONT) && !defined(MUSTCOPY)
-#define USE_XF86BIGFONT
-#endif
-#ifdef USE_XF86BIGFONT
-#include <sys/types.h>
-#ifdef HAS_SHM
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <X11/extensions/xf86bigfstr.h>
-#endif
-
-#include "Xlcint.h"
-#include "XlcPubI.h"
-
-
-static XFontStruct *_XQueryFont(
- Display* /* dpy */,
- Font /* fid */,
- unsigned long /* seq */
-);
-
-#ifdef USE_XF86BIGFONT
-
-/* Private data for this extension. */
-typedef struct {
- XExtCodes *codes;
- CARD32 serverSignature;
- CARD32 serverCapabilities;
-} XF86BigfontCodes;
-
-/* Additional bit masks that can be set in serverCapabilities */
-#define CAP_VerifiedLocal 256
-
-static XF86BigfontCodes *_XF86BigfontCodes(
- Display* /* dpy */
-);
-
-static XFontStruct *_XF86BigfontQueryFont(
- Display* /* dpy */,
- XF86BigfontCodes* /* extcodes */,
- Font /* fid */,
- unsigned long /* seq */
-);
-
-void _XF86BigfontFreeFontMetrics(
- XFontStruct* /* fs */
-);
-
-#endif /* USE_XF86BIGFONT */
-
-
-XFontStruct *XLoadQueryFont(
- register Display *dpy,
- _Xconst char *name)
-{
- XFontStruct *font_result;
- register long nbytes;
- Font fid;
- xOpenFontReq *req;
- unsigned long seq;
-#ifdef USE_XF86BIGFONT
- XF86BigfontCodes *extcodes = _XF86BigfontCodes(dpy);
-#endif
-
- if (_XF86LoadQueryLocaleFont(dpy, name, &font_result, (Font *)0))
- return font_result;
- LockDisplay(dpy);
- GetReq(OpenFont, req);
- seq = dpy->request;
- nbytes = req->nbytes = name ? strlen(name) : 0;
- req->fid = fid = XAllocID(dpy);
- req->length += (nbytes+3)>>2;
- Data (dpy, name, nbytes);
- font_result = NULL;
-#ifdef USE_XF86BIGFONT
- if (extcodes) {
- font_result = _XF86BigfontQueryFont(dpy, extcodes, fid, seq);
- seq = 0;
- }
-#endif
- if (!font_result)
- font_result = _XQueryFont(dpy, fid, seq);
- UnlockDisplay(dpy);
- SyncHandle();
- return font_result;
-}
-
-XFontStruct *XQueryFont (
- register Display *dpy,
- Font fid)
-{
- XFontStruct *font_result;
-#ifdef USE_XF86BIGFONT
- XF86BigfontCodes *extcodes = _XF86BigfontCodes(dpy);
-#endif
-
- LockDisplay(dpy);
- font_result = NULL;
-#ifdef USE_XF86BIGFONT
- if (extcodes) {
- font_result = _XF86BigfontQueryFont(dpy, extcodes, fid, 0L);
- }
-#endif
- if (!font_result)
- font_result = _XQueryFont(dpy, fid, 0L);
- UnlockDisplay(dpy);
- SyncHandle();
- return font_result;
-}
-
-int
-XFreeFont(
- register Display *dpy,
- XFontStruct *fs)
-{
- register xResourceReq *req;
- register _XExtension *ext;
-
- LockDisplay(dpy);
- /* call out to any extensions interested */
- for (ext = dpy->ext_procs; ext; ext = ext->next)
- if (ext->free_Font) (*ext->free_Font)(dpy, fs, &ext->codes);
- GetResReq (CloseFont, fs->fid, req);
- UnlockDisplay(dpy);
- SyncHandle();
- if (fs->per_char) {
-#ifdef USE_XF86BIGFONT
- _XF86BigfontFreeFontMetrics(fs);
-#else
- Xfree ((char *) fs->per_char);
-#endif
- }
- _XFreeExtData(fs->ext_data);
- if (fs->properties)
- Xfree ((char *) fs->properties);
- Xfree ((char *) fs);
- return 1;
-}
-
-
-static XFontStruct *
-_XQueryFont (
- register Display *dpy,
- Font fid,
- unsigned long seq)
-{
- register XFontStruct *fs;
- register long nbytes;
- xQueryFontReply reply;
- register xResourceReq *req;
- register _XExtension *ext;
- _XAsyncHandler async;
- _XAsyncErrorState async_state;
-
- if (seq) {
- async_state.min_sequence_number = seq;
- async_state.max_sequence_number = seq;
- async_state.error_code = BadName;
- async_state.major_opcode = X_OpenFont;
- async_state.minor_opcode = 0;
- async_state.error_count = 0;
- async.next = dpy->async_handlers;
- async.handler = _XAsyncErrorHandler;
- async.data = (XPointer)&async_state;
- dpy->async_handlers = &async;
- }
- GetResReq(QueryFont, fid, req);
- if (!_XReply (dpy, (xReply *) &reply,
- ((SIZEOF(xQueryFontReply) - SIZEOF(xReply)) >> 2), xFalse)) {
- if (seq)
- DeqAsyncHandler(dpy, &async);
- return (XFontStruct *)NULL;
- }
- if (seq)
- DeqAsyncHandler(dpy, &async);
- if (! (fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct)))) {
- _XEatData(dpy, (unsigned long)(reply.nFontProps * SIZEOF(xFontProp) +
- reply.nCharInfos * SIZEOF(xCharInfo)));
- return (XFontStruct *)NULL;
- }
- fs->ext_data = NULL;
- fs->fid = fid;
- fs->direction = reply.drawDirection;
- fs->min_char_or_byte2 = reply.minCharOrByte2;
- fs->max_char_or_byte2 = reply.maxCharOrByte2;
- fs->min_byte1 = reply.minByte1;
- fs->max_byte1 = reply.maxByte1;
- fs->default_char = reply.defaultChar;
- fs->all_chars_exist = reply.allCharsExist;
- fs->ascent = cvtINT16toInt (reply.fontAscent);
- fs->descent = cvtINT16toInt (reply.fontDescent);
-
-#ifdef MUSTCOPY
- {
- xCharInfo *xcip;
-
- xcip = (xCharInfo *) &reply.minBounds;
- fs->min_bounds.lbearing = cvtINT16toShort(xcip->leftSideBearing);
- fs->min_bounds.rbearing = cvtINT16toShort(xcip->rightSideBearing);
- fs->min_bounds.width = cvtINT16toShort(xcip->characterWidth);
- fs->min_bounds.ascent = cvtINT16toShort(xcip->ascent);
- fs->min_bounds.descent = cvtINT16toShort(xcip->descent);
- fs->min_bounds.attributes = xcip->attributes;
-
- xcip = (xCharInfo *) &reply.maxBounds;
- fs->max_bounds.lbearing = cvtINT16toShort(xcip->leftSideBearing);
- fs->max_bounds.rbearing = cvtINT16toShort(xcip->rightSideBearing);
- fs->max_bounds.width = cvtINT16toShort(xcip->characterWidth);
- fs->max_bounds.ascent = cvtINT16toShort(xcip->ascent);
- fs->max_bounds.descent = cvtINT16toShort(xcip->descent);
- fs->max_bounds.attributes = xcip->attributes;
- }
-#else
- /* XXX the next two statements won't work if short isn't 16 bits */
- fs->min_bounds = * (XCharStruct *) &reply.minBounds;
- fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
-#endif /* MUSTCOPY */
-
- fs->n_properties = reply.nFontProps;
- /*
- * if no properties defined for the font, then it is bad
- * font, but shouldn't try to read nothing.
- */
- fs->properties = NULL;
- if (fs->n_properties > 0) {
- nbytes = reply.nFontProps * sizeof(XFontProp);
- fs->properties = (XFontProp *) Xmalloc ((unsigned) nbytes);
- nbytes = reply.nFontProps * SIZEOF(xFontProp);
- if (! fs->properties) {
- Xfree((char *) fs);
- _XEatData(dpy, (unsigned long)
- (nbytes + reply.nCharInfos * SIZEOF(xCharInfo)));
- return (XFontStruct *)NULL;
- }
- _XRead32 (dpy, (long *)fs->properties, nbytes);
- }
- /*
- * If no characters in font, then it is a bad font, but
- * shouldn't try to read nothing.
- */
- /* have to unpack charinfos on some machines (CRAY) */
- fs->per_char = NULL;
- if (reply.nCharInfos > 0){
- nbytes = reply.nCharInfos * sizeof(XCharStruct);
- if (! (fs->per_char = (XCharStruct *) Xmalloc ((unsigned) nbytes))) {
- if (fs->properties) Xfree((char *) fs->properties);
- Xfree((char *) fs);
- _XEatData(dpy, (unsigned long)
- (reply.nCharInfos * SIZEOF(xCharInfo)));
- return (XFontStruct *)NULL;
- }
-
-#ifdef MUSTCOPY
- {
- register XCharStruct *cs = fs->per_char;
- register int i;
-
- for (i = 0; i < reply.nCharInfos; i++, cs++) {
- xCharInfo xcip;
-
- _XRead(dpy, (char *)&xcip, SIZEOF(xCharInfo));
- cs->lbearing = cvtINT16toShort(xcip.leftSideBearing);
- cs->rbearing = cvtINT16toShort(xcip.rightSideBearing);
- cs->width = cvtINT16toShort(xcip.characterWidth);
- cs->ascent = cvtINT16toShort(xcip.ascent);
- cs->descent = cvtINT16toShort(xcip.descent);
- cs->attributes = xcip.attributes;
- }
- }
-#else
- nbytes = reply.nCharInfos * SIZEOF(xCharInfo);
- _XRead16 (dpy, (char *)fs->per_char, nbytes);
-#endif
- }
-
- /* call out to any extensions interested */
- for (ext = dpy->ext_procs; ext; ext = ext->next)
- if (ext->create_Font) (*ext->create_Font)(dpy, fs, &ext->codes);
- return fs;
-}
-
-#ifdef USE_XF86BIGFONT
-
-/* Magic cookie for finding the right XExtData structure on the display's
- extension list. */
-static int XF86BigfontNumber = 1040697125;
-
-static int
-_XF86BigfontFreeCodes (
- XExtData *extension)
-{
- /* Don't Xfree(extension->private_data) because it is on the same malloc
- chunk as extension. */
- /* Don't Xfree(extension->private_data->codes) because this is shared with
- the display's ext_procs list. */
- return 0;
-}
-
-static XF86BigfontCodes *
-_XF86BigfontCodes (
- register Display *dpy)
-{
- XEDataObject dpy_union;
- XExtData *pData;
- XF86BigfontCodes *pCodes;
- char *envval;
-
- dpy_union.display = dpy;
-
- /* If the server is known to support the XF86Bigfont extension,
- * return the extension codes. If the server is known to not support
- * the extension, don't bother checking again.
- */
- pData = XFindOnExtensionList(XEHeadOfExtensionList(dpy_union),
- XF86BigfontNumber);
- if (pData)
- return (XF86BigfontCodes *) pData->private_data;
-
- pData = (XExtData *) Xmalloc(sizeof(XExtData) + sizeof(XF86BigfontCodes));
- if (!pData) {
- /* Out of luck. */
- return (XF86BigfontCodes *) NULL;
- }
-
- /* See if the server supports the XF86Bigfont extension. */
- envval = getenv("XF86BIGFONT_DISABLE"); /* Let the user disable it. */
- if (envval != NULL && envval[0] != '\0')
- pCodes = NULL;
- else {
- XExtCodes *codes = XInitExtension(dpy, XF86BIGFONTNAME);
- if (codes == NULL)
- pCodes = NULL;
- else {
- pCodes = (XF86BigfontCodes *) &pData[1];
- pCodes->codes = codes;
- }
- }
- pData->number = XF86BigfontNumber;
- pData->private_data = (XPointer) pCodes;
- pData->free_private = _XF86BigfontFreeCodes;
- XAddToExtensionList(XEHeadOfExtensionList(dpy_union), pData);
- if (pCodes) {
- int result;
-
- /* See if the server supports the XF86BigfontQueryFont request. */
- xXF86BigfontQueryVersionReply reply;
- register xXF86BigfontQueryVersionReq *req;
-
- LockDisplay(dpy);
-
- GetReq(XF86BigfontQueryVersion, req);
- req->reqType = pCodes->codes->major_opcode;
- req->xf86bigfontReqType = X_XF86BigfontQueryVersion;
-
- result = _XReply (dpy, (xReply *) &reply,
- (SIZEOF(xXF86BigfontQueryVersionReply) - SIZEOF(xReply)) >> 2,
- xFalse);
-
- UnlockDisplay(dpy);
- SyncHandle();
-
- if(!result)
- goto ignore_extension;
-
- /* No need to provide backward compatibility with version 1.0. It
- was never widely distributed. */
- if (!(reply.majorVersion > 1
- || (reply.majorVersion == 1 && reply.minorVersion >= 1)))
- goto ignore_extension;
-
- pCodes->serverSignature = reply.signature;
- pCodes->serverCapabilities = reply.capabilities;
- }
- return pCodes;
-
- ignore_extension:
- /* No need to Xfree(pCodes) or Xfree(pCodes->codes), see
- _XF86BigfontFreeCodes comment. */
- pCodes = (XF86BigfontCodes *) NULL;
- pData->private_data = (XPointer) pCodes;
- return pCodes;
-}
-
-static int
-_XF86BigfontFreeNop (
- XExtData *extension)
-{
- return 0;
-}
-
-static XFontStruct *
-_XF86BigfontQueryFont (
- register Display *dpy,
- XF86BigfontCodes *extcodes,
- Font fid,
- unsigned long seq)
-{
- register XFontStruct *fs;
- register long nbytes;
- xXF86BigfontQueryFontReply reply;
- register xXF86BigfontQueryFontReq *req;
- register _XExtension *ext;
- _XAsyncHandler async1;
- _XAsyncErrorState async1_state;
- _XAsyncHandler async2;
- _XAsyncErrorState async2_state;
-
- if (seq) {
- async1_state.min_sequence_number = seq;
- async1_state.max_sequence_number = seq;
- async1_state.error_code = BadName;
- async1_state.major_opcode = X_OpenFont;
- async1_state.minor_opcode = 0;
- async1_state.error_count = 0;
- async1.next = dpy->async_handlers;
- async1.handler = _XAsyncErrorHandler;
- async1.data = (XPointer)&async1_state;
- dpy->async_handlers = &async1;
- }
-
- GetReq(XF86BigfontQueryFont, req);
- req->reqType = extcodes->codes->major_opcode;
- req->xf86bigfontReqType = X_XF86BigfontQueryFont;
- req->id = fid;
- req->flags = (extcodes->serverCapabilities & XF86Bigfont_CAP_LocalShm
- ? XF86Bigfont_FLAGS_Shm : 0);
-
- /* The function _XQueryFont benefits from a "magic" error handler for
- BadFont coming from a X_QueryFont request. (See function _XReply.)
- We have to establish an error handler ourselves. */
- async2_state.min_sequence_number = dpy->request;
- async2_state.max_sequence_number = dpy->request;
- async2_state.error_code = BadFont;
- async2_state.major_opcode = extcodes->codes->major_opcode;
- async2_state.minor_opcode = X_XF86BigfontQueryFont;
- async2_state.error_count = 0;
- async2.next = dpy->async_handlers;
- async2.handler = _XAsyncErrorHandler;
- async2.data = (XPointer)&async2_state;
- dpy->async_handlers = &async2;
-
- if (!_XReply (dpy, (xReply *) &reply,
- ((SIZEOF(xXF86BigfontQueryFontReply) - SIZEOF(xReply)) >> 2), xFalse)) {
- DeqAsyncHandler(dpy, &async2);
- if (seq)
- DeqAsyncHandler(dpy, &async1);
- return (XFontStruct *)NULL;
- }
- DeqAsyncHandler(dpy, &async2);
- if (seq)
- DeqAsyncHandler(dpy, &async1);
- if (! (fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct)))) {
- _XEatData(dpy,
- reply.nFontProps * SIZEOF(xFontProp)
- + (reply.nCharInfos > 0 && reply.shmid == (CARD32)(-1)
- ? reply.nUniqCharInfos * SIZEOF(xCharInfo)
- + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16)
- : 0));
- return (XFontStruct *)NULL;
- }
- fs->ext_data = NULL;
- fs->fid = fid;
- fs->direction = reply.drawDirection;
- fs->min_char_or_byte2 = reply.minCharOrByte2;
- fs->max_char_or_byte2 = reply.maxCharOrByte2;
- fs->min_byte1 = reply.minByte1;
- fs->max_byte1 = reply.maxByte1;
- fs->default_char = reply.defaultChar;
- fs->all_chars_exist = reply.allCharsExist;
- fs->ascent = cvtINT16toInt (reply.fontAscent);
- fs->descent = cvtINT16toInt (reply.fontDescent);
-
- /* XXX the next two statements won't work if short isn't 16 bits */
- fs->min_bounds = * (XCharStruct *) &reply.minBounds;
- fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
-
- fs->n_properties = reply.nFontProps;
- /*
- * if no properties defined for the font, then it is bad
- * font, but shouldn't try to read nothing.
- */
- fs->properties = NULL;
- if (fs->n_properties > 0) {
- nbytes = reply.nFontProps * sizeof(XFontProp);
- fs->properties = (XFontProp *) Xmalloc ((unsigned) nbytes);
- nbytes = reply.nFontProps * SIZEOF(xFontProp);
- if (! fs->properties) {
- Xfree((char *) fs);
- _XEatData(dpy,
- nbytes
- + (reply.nCharInfos > 0 && reply.shmid == (CARD32)(-1)
- ? reply.nUniqCharInfos * SIZEOF(xCharInfo)
- + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16)
- : 0));
- return (XFontStruct *)NULL;
- }
- _XRead32 (dpy, (long *)fs->properties, nbytes);
- }
-
- fs->per_char = NULL;
- if (reply.nCharInfos > 0) {
- /* fprintf(stderr, "received font metrics, nCharInfos = %d, nUniqCharInfos = %d, shmid = %d\n", reply.nCharInfos, reply.nUniqCharInfos, reply.shmid); */
- if (reply.shmid == (CARD32)(-1)) {
- xCharInfo* pUniqCI;
- CARD16* pIndex2UniqIndex;
- int i;
-
- nbytes = reply.nUniqCharInfos * SIZEOF(xCharInfo)
- + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16);
- pUniqCI = (xCharInfo *) Xmalloc (nbytes);
- if (!pUniqCI) {
- if (fs->properties) Xfree((char *) fs->properties);
- Xfree((char *) fs);
- _XEatData(dpy, nbytes);
- return (XFontStruct *)NULL;
- }
- if (! (fs->per_char = (XCharStruct *) Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) {
- Xfree((char *) pUniqCI);
- if (fs->properties) Xfree((char *) fs->properties);
- Xfree((char *) fs);
- _XEatData(dpy, nbytes);
- return (XFontStruct *)NULL;
- }
- _XRead16 (dpy, (char *) pUniqCI, nbytes);
- pIndex2UniqIndex = (CARD16*) (pUniqCI + reply.nUniqCharInfos);
- for (i = 0; i < reply.nCharInfos; i++) {
- if (pIndex2UniqIndex[i] >= reply.nUniqCharInfos) {
- fprintf(stderr, "_XF86BigfontQueryFont: server returned wrong data\n");
- Xfree((char *) pUniqCI);
- if (fs->properties) Xfree((char *) fs->properties);
- Xfree((char *) fs);
- return (XFontStruct *)NULL;
- }
- /* XXX the next statement won't work if short isn't 16 bits */
- fs->per_char[i] = * (XCharStruct *) &pUniqCI[pIndex2UniqIndex[i]];
- }
- Xfree((char *) pUniqCI);
- } else {
-#ifdef HAS_SHM
- XExtData *pData;
- XEDataObject fs_union;
- char *addr;
-
- pData = (XExtData *) Xmalloc(sizeof(XExtData));
- if (!pData) {
- if (fs->properties) Xfree((char *) fs->properties);
- Xfree((char *) fs);
- return (XFontStruct *)NULL;
- }
-
- /* In some cases (e.g. an ssh daemon forwarding an X session to
- a remote machine) it is possible that the X server thinks we
- are running on the same machine (because getpeername() and
- LocalClient() cannot know about the forwarding) but we are
- not really local. Therefore, when we attach the first shared
- memory segment, we verify that we are on the same machine as
- the X server by checking that 1. shmat() succeeds, 2. the
- segment has a sufficient size, 3. it contains the X server's
- signature. Then we set the CAP_VerifiedLocal bit to indicate
- the verification was successful. */
-
- if ((addr = shmat(reply.shmid, NULL, SHM_RDONLY)) == (char *)-1) {
- if (extcodes->serverCapabilities & CAP_VerifiedLocal)
- fprintf(stderr, "_XF86BigfontQueryFont: could not attach shm segment\n");
- Xfree((char *) pData);
- if (fs->properties) Xfree((char *) fs->properties);
- Xfree((char *) fs);
- /* Stop requesting shared memory transport from now on. */
- extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
- return (XFontStruct *)NULL;
- }
-
- if (!(extcodes->serverCapabilities & CAP_VerifiedLocal)) {
- struct shmid_ds buf;
- if (!(shmctl(reply.shmid, IPC_STAT, &buf) >= 0
- && buf.shm_segsz >= reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct) + sizeof(CARD32)
- && *(CARD32 *)(addr + reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct)) == extcodes->serverSignature)) {
- shmdt(addr);
- Xfree((char *) pData);
- if (fs->properties) Xfree((char *) fs->properties);
- Xfree((char *) fs);
- /* Stop requesting shared memory transport from now on. */
- extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
- return (XFontStruct *)NULL;
- }
- extcodes->serverCapabilities |= CAP_VerifiedLocal;
- }
-
- pData->number = XF86BigfontNumber;
- pData->private_data = (XPointer) addr;
- pData->free_private = _XF86BigfontFreeNop;
- fs_union.font = fs;
- XAddToExtensionList(XEHeadOfExtensionList(fs_union), pData);
-
- fs->per_char = (XCharStruct *) (addr + reply.shmsegoffset);
-#else
- fprintf(stderr, "_XF86BigfontQueryFont: try recompiling libX11 with HasShm, Xserver has shm support\n");
- if (fs->properties) Xfree((char *) fs->properties);
- Xfree((char *) fs);
- /* Stop requesting shared memory transport from now on. */
- extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
- return (XFontStruct *)NULL;
-#endif
- }
- }
-
- /* call out to any extensions interested */
- for (ext = dpy->ext_procs; ext; ext = ext->next)
- if (ext->create_Font) (*ext->create_Font)(dpy, fs, &ext->codes);
- return fs;
-}
-
-void
-_XF86BigfontFreeFontMetrics (XFontStruct *fs)
-{
-#ifdef HAS_SHM
- XExtData *pData;
- XEDataObject fs_union;
-
- fs_union.font = fs;
- if ((pData = XFindOnExtensionList(XEHeadOfExtensionList(fs_union),
- XF86BigfontNumber)))
- shmdt ((char *) pData->private_data);
- else
- Xfree ((char *) fs->per_char);
-#else
- Xfree ((char *) fs->per_char);
-#endif
-}
-
-#endif /* USE_XF86BIGFONT */
-
-int _XF86LoadQueryLocaleFont(
- Display *dpy,
- _Xconst char *name,
- XFontStruct **xfp,
- Font *fidp)
-{
- int l;
- const char *charset, *p;
- char buf[256];
- XFontStruct *fs;
- XLCd lcd;
-
- if (!name)
- return 0;
- l = strlen(name);
- if (l < 2 || name[l - 1] != '*' || name[l - 2] != '-')
- return 0;
- charset = NULL;
- /* next three lines stolen from _XkbGetCharset() */
- lcd = _XlcCurrentLC();
- if ((lcd = _XlcCurrentLC()) != 0)
- charset = XLC_PUBLIC(lcd, encoding_name);
- if (!charset || (p = strrchr(charset, '-')) == 0 || p == charset || p[1] == 0 || (p[1] == '*' && p[2] == 0)) {
- /* prefer latin1 if no encoding found */
- charset = "ISO8859-1";
- p = charset + 7;
- }
- if (l - 2 - (p - charset) < 0)
- return 0;
- if (_XlcNCompareISOLatin1(name + l - 2 - (p - charset), charset, p - charset))
- return 0;
- if (strlen(p + 1) + l - 1 >= sizeof(buf) - 1)
- return 0;
- strcpy(buf, name);
- strcpy(buf + l - 1, p + 1);
- fs = XLoadQueryFont(dpy, buf);
- if (!fs)
- return 0;
- if (xfp) {
- *xfp = fs;
- if (fidp)
- *fidp = fs->fid;
- } else if (fidp) {
- if (fs->per_char) {
-#ifdef USE_XF86BIGFONT
- _XF86BigfontFreeFontMetrics(fs);
-#else
- Xfree ((char *) fs->per_char);
-#endif
- }
- _XFreeExtData(fs->ext_data);
- if (fs->properties)
- Xfree ((char *) fs->properties);
- *fidp = fs->fid;
- Xfree ((char *) fs);
- } else {
- XFreeFont(dpy, fs);
- }
- return 1;
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+Copyright (c) 2000 The XFree86 Project, Inc.
+
+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.
+
+The above copyright notice and this permission notice 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
+X CONSORTIUM OR THE XFREE86 PROJECT 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.
+
+Except as contained in this notice, the name of the X Consortium or of the
+XFree86 Project shall not be used in advertising or otherwise to promote the
+sale, use or other dealings in this Software without prior written
+authorization from the X Consortium and the XFree86 Project.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+#if defined(XF86BIGFONT) && !defined(MUSTCOPY)
+#define USE_XF86BIGFONT
+#endif
+#ifdef USE_XF86BIGFONT
+#include <sys/types.h>
+#ifdef HAS_SHM
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/extensions/xf86bigfstr.h>
+#endif
+
+#include "Xlcint.h"
+#include "XlcPubI.h"
+
+
+static XFontStruct *_XQueryFont(
+ Display* /* dpy */,
+ Font /* fid */,
+ unsigned long /* seq */
+);
+
+#ifdef USE_XF86BIGFONT
+
+/* Private data for this extension. */
+typedef struct {
+ XExtCodes *codes;
+ CARD32 serverSignature;
+ CARD32 serverCapabilities;
+} XF86BigfontCodes;
+
+/* Additional bit masks that can be set in serverCapabilities */
+#define CAP_VerifiedLocal 256
+
+static XF86BigfontCodes *_XF86BigfontCodes(
+ Display* /* dpy */
+);
+
+static XFontStruct *_XF86BigfontQueryFont(
+ Display* /* dpy */,
+ XF86BigfontCodes* /* extcodes */,
+ Font /* fid */,
+ unsigned long /* seq */
+);
+
+void _XF86BigfontFreeFontMetrics(
+ XFontStruct* /* fs */
+);
+
+#endif /* USE_XF86BIGFONT */
+
+
+XFontStruct *XLoadQueryFont(
+ register Display *dpy,
+ _Xconst char *name)
+{
+ XFontStruct *font_result;
+ register long nbytes;
+ Font fid;
+ xOpenFontReq *req;
+ unsigned long seq;
+#ifdef USE_XF86BIGFONT
+ XF86BigfontCodes *extcodes = _XF86BigfontCodes(dpy);
+#endif
+
+ if (_XF86LoadQueryLocaleFont(dpy, name, &font_result, (Font *)0))
+ return font_result;
+ LockDisplay(dpy);
+ GetReq(OpenFont, req);
+ seq = dpy->request;
+ nbytes = req->nbytes = name ? strlen(name) : 0;
+ req->fid = fid = XAllocID(dpy);
+ req->length += (nbytes+3)>>2;
+ Data (dpy, name, nbytes);
+ font_result = NULL;
+#ifdef USE_XF86BIGFONT
+ if (extcodes) {
+ font_result = _XF86BigfontQueryFont(dpy, extcodes, fid, seq);
+ seq = 0;
+ }
+#endif
+ if (!font_result)
+ font_result = _XQueryFont(dpy, fid, seq);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return font_result;
+}
+
+XFontStruct *XQueryFont (
+ register Display *dpy,
+ Font fid)
+{
+ XFontStruct *font_result;
+#ifdef USE_XF86BIGFONT
+ XF86BigfontCodes *extcodes = _XF86BigfontCodes(dpy);
+#endif
+
+ LockDisplay(dpy);
+ font_result = NULL;
+#ifdef USE_XF86BIGFONT
+ if (extcodes) {
+ font_result = _XF86BigfontQueryFont(dpy, extcodes, fid, 0L);
+ }
+#endif
+ if (!font_result)
+ font_result = _XQueryFont(dpy, fid, 0L);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return font_result;
+}
+
+int
+XFreeFont(
+ register Display *dpy,
+ XFontStruct *fs)
+{
+ register xResourceReq *req;
+ register _XExtension *ext;
+
+ LockDisplay(dpy);
+ /* call out to any extensions interested */
+ for (ext = dpy->ext_procs; ext; ext = ext->next)
+ if (ext->free_Font) (*ext->free_Font)(dpy, fs, &ext->codes);
+ GetResReq (CloseFont, fs->fid, req);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if (fs->per_char) {
+#ifdef USE_XF86BIGFONT
+ _XF86BigfontFreeFontMetrics(fs);
+#else
+ Xfree ((char *) fs->per_char);
+#endif
+ }
+ _XFreeExtData(fs->ext_data);
+ if (fs->properties)
+ Xfree ((char *) fs->properties);
+ Xfree ((char *) fs);
+ return 1;
+}
+
+
+static XFontStruct *
+_XQueryFont (
+ register Display *dpy,
+ Font fid,
+ unsigned long seq)
+{
+ register XFontStruct *fs;
+ register long nbytes;
+ xQueryFontReply reply;
+ register xResourceReq *req;
+ register _XExtension *ext;
+ _XAsyncHandler async;
+ _XAsyncErrorState async_state;
+
+ if (seq) {
+ async_state.min_sequence_number = seq;
+ async_state.max_sequence_number = seq;
+ async_state.error_code = BadName;
+ async_state.major_opcode = X_OpenFont;
+ async_state.minor_opcode = 0;
+ async_state.error_count = 0;
+ async.next = dpy->async_handlers;
+ async.handler = _XAsyncErrorHandler;
+ async.data = (XPointer)&async_state;
+ dpy->async_handlers = &async;
+ }
+ GetResReq(QueryFont, fid, req);
+ if (!_XReply (dpy, (xReply *) &reply,
+ ((SIZEOF(xQueryFontReply) - SIZEOF(xReply)) >> 2), xFalse)) {
+ if (seq)
+ DeqAsyncHandler(dpy, &async);
+ return (XFontStruct *)NULL;
+ }
+ if (seq)
+ DeqAsyncHandler(dpy, &async);
+ if (! (fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct)))) {
+ _XEatData(dpy, (unsigned long)(reply.nFontProps * SIZEOF(xFontProp) +
+ reply.nCharInfos * SIZEOF(xCharInfo)));
+ return (XFontStruct *)NULL;
+ }
+ fs->ext_data = NULL;
+ fs->fid = fid;
+ fs->direction = reply.drawDirection;
+ fs->min_char_or_byte2 = reply.minCharOrByte2;
+ fs->max_char_or_byte2 = reply.maxCharOrByte2;
+ fs->min_byte1 = reply.minByte1;
+ fs->max_byte1 = reply.maxByte1;
+ fs->default_char = reply.defaultChar;
+ fs->all_chars_exist = reply.allCharsExist;
+ fs->ascent = cvtINT16toInt (reply.fontAscent);
+ fs->descent = cvtINT16toInt (reply.fontDescent);
+
+#ifdef MUSTCOPY
+ {
+ xCharInfo *xcip;
+
+ xcip = (xCharInfo *) &reply.minBounds;
+ fs->min_bounds.lbearing = cvtINT16toShort(xcip->leftSideBearing);
+ fs->min_bounds.rbearing = cvtINT16toShort(xcip->rightSideBearing);
+ fs->min_bounds.width = cvtINT16toShort(xcip->characterWidth);
+ fs->min_bounds.ascent = cvtINT16toShort(xcip->ascent);
+ fs->min_bounds.descent = cvtINT16toShort(xcip->descent);
+ fs->min_bounds.attributes = xcip->attributes;
+
+ xcip = (xCharInfo *) &reply.maxBounds;
+ fs->max_bounds.lbearing = cvtINT16toShort(xcip->leftSideBearing);
+ fs->max_bounds.rbearing = cvtINT16toShort(xcip->rightSideBearing);
+ fs->max_bounds.width = cvtINT16toShort(xcip->characterWidth);
+ fs->max_bounds.ascent = cvtINT16toShort(xcip->ascent);
+ fs->max_bounds.descent = cvtINT16toShort(xcip->descent);
+ fs->max_bounds.attributes = xcip->attributes;
+ }
+#else
+ /* XXX the next two statements won't work if short isn't 16 bits */
+ fs->min_bounds = * (XCharStruct *) &reply.minBounds;
+ fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
+#endif /* MUSTCOPY */
+
+ fs->n_properties = reply.nFontProps;
+ /*
+ * if no properties defined for the font, then it is bad
+ * font, but shouldn't try to read nothing.
+ */
+ fs->properties = NULL;
+ if (fs->n_properties > 0) {
+ nbytes = reply.nFontProps * sizeof(XFontProp);
+ fs->properties = (XFontProp *) Xmalloc ((unsigned) nbytes);
+ nbytes = reply.nFontProps * SIZEOF(xFontProp);
+ if (! fs->properties) {
+ Xfree((char *) fs);
+ _XEatData(dpy, (unsigned long)
+ (nbytes + reply.nCharInfos * SIZEOF(xCharInfo)));
+ return (XFontStruct *)NULL;
+ }
+ _XRead32 (dpy, (long *)fs->properties, nbytes);
+ }
+ /*
+ * If no characters in font, then it is a bad font, but
+ * shouldn't try to read nothing.
+ */
+ /* have to unpack charinfos on some machines (CRAY) */
+ fs->per_char = NULL;
+ if (reply.nCharInfos > 0){
+ nbytes = reply.nCharInfos * sizeof(XCharStruct);
+ if (! (fs->per_char = (XCharStruct *) Xmalloc ((unsigned) nbytes))) {
+ if (fs->properties) Xfree((char *) fs->properties);
+ Xfree((char *) fs);
+ _XEatData(dpy, (unsigned long)
+ (reply.nCharInfos * SIZEOF(xCharInfo)));
+ return (XFontStruct *)NULL;
+ }
+
+#ifdef MUSTCOPY
+ {
+ register XCharStruct *cs = fs->per_char;
+ register int i;
+
+ for (i = 0; i < reply.nCharInfos; i++, cs++) {
+ xCharInfo xcip;
+
+ _XRead(dpy, (char *)&xcip, SIZEOF(xCharInfo));
+ cs->lbearing = cvtINT16toShort(xcip.leftSideBearing);
+ cs->rbearing = cvtINT16toShort(xcip.rightSideBearing);
+ cs->width = cvtINT16toShort(xcip.characterWidth);
+ cs->ascent = cvtINT16toShort(xcip.ascent);
+ cs->descent = cvtINT16toShort(xcip.descent);
+ cs->attributes = xcip.attributes;
+ }
+ }
+#else
+ nbytes = reply.nCharInfos * SIZEOF(xCharInfo);
+ _XRead16 (dpy, (char *)fs->per_char, nbytes);
+#endif
+ }
+
+ /* call out to any extensions interested */
+ for (ext = dpy->ext_procs; ext; ext = ext->next)
+ if (ext->create_Font) (*ext->create_Font)(dpy, fs, &ext->codes);
+ return fs;
+}
+
+#ifdef USE_XF86BIGFONT
+
+/* Magic cookie for finding the right XExtData structure on the display's
+ extension list. */
+static int XF86BigfontNumber = 1040697125;
+
+static int
+_XF86BigfontFreeCodes (
+ XExtData *extension)
+{
+ /* Don't Xfree(extension->private_data) because it is on the same malloc
+ chunk as extension. */
+ /* Don't Xfree(extension->private_data->codes) because this is shared with
+ the display's ext_procs list. */
+ return 0;
+}
+
+static XF86BigfontCodes *
+_XF86BigfontCodes (
+ register Display *dpy)
+{
+ XEDataObject dpy_union;
+ XExtData *pData;
+ XF86BigfontCodes *pCodes;
+ char *envval;
+
+ dpy_union.display = dpy;
+
+ /* If the server is known to support the XF86Bigfont extension,
+ * return the extension codes. If the server is known to not support
+ * the extension, don't bother checking again.
+ */
+ pData = XFindOnExtensionList(XEHeadOfExtensionList(dpy_union),
+ XF86BigfontNumber);
+ if (pData)
+ return (XF86BigfontCodes *) pData->private_data;
+
+ pData = (XExtData *) Xmalloc(sizeof(XExtData) + sizeof(XF86BigfontCodes));
+ if (!pData) {
+ /* Out of luck. */
+ return (XF86BigfontCodes *) NULL;
+ }
+
+ /* See if the server supports the XF86Bigfont extension. */
+ envval = getenv("XF86BIGFONT_DISABLE"); /* Let the user disable it. */
+ if (envval != NULL && envval[0] != '\0')
+ pCodes = NULL;
+ else {
+ XExtCodes *codes = XInitExtension(dpy, XF86BIGFONTNAME);
+ if (codes == NULL)
+ pCodes = NULL;
+ else {
+ pCodes = (XF86BigfontCodes *) &pData[1];
+ pCodes->codes = codes;
+ }
+ }
+ pData->number = XF86BigfontNumber;
+ pData->private_data = (XPointer) pCodes;
+ pData->free_private = _XF86BigfontFreeCodes;
+ XAddToExtensionList(XEHeadOfExtensionList(dpy_union), pData);
+ if (pCodes) {
+ int result;
+
+ /* See if the server supports the XF86BigfontQueryFont request. */
+ xXF86BigfontQueryVersionReply reply;
+ register xXF86BigfontQueryVersionReq *req;
+
+ LockDisplay(dpy);
+
+ GetReq(XF86BigfontQueryVersion, req);
+ req->reqType = pCodes->codes->major_opcode;
+ req->xf86bigfontReqType = X_XF86BigfontQueryVersion;
+
+ result = _XReply (dpy, (xReply *) &reply,
+ (SIZEOF(xXF86BigfontQueryVersionReply) - SIZEOF(xReply)) >> 2,
+ xFalse);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ if(!result)
+ goto ignore_extension;
+
+ /* No need to provide backward compatibility with version 1.0. It
+ was never widely distributed. */
+ if (!(reply.majorVersion > 1
+ || (reply.majorVersion == 1 && reply.minorVersion >= 1)))
+ goto ignore_extension;
+
+ pCodes->serverSignature = reply.signature;
+ pCodes->serverCapabilities = reply.capabilities;
+ }
+ return pCodes;
+
+ ignore_extension:
+ /* No need to Xfree(pCodes) or Xfree(pCodes->codes), see
+ _XF86BigfontFreeCodes comment. */
+ pCodes = (XF86BigfontCodes *) NULL;
+ pData->private_data = (XPointer) pCodes;
+ return pCodes;
+}
+
+static int
+_XF86BigfontFreeNop (
+ XExtData *extension)
+{
+ return 0;
+}
+
+static XFontStruct *
+_XF86BigfontQueryFont (
+ register Display *dpy,
+ XF86BigfontCodes *extcodes,
+ Font fid,
+ unsigned long seq)
+{
+ register XFontStruct *fs;
+ register long nbytes;
+ xXF86BigfontQueryFontReply reply;
+ register xXF86BigfontQueryFontReq *req;
+ register _XExtension *ext;
+ _XAsyncHandler async1;
+ _XAsyncErrorState async1_state;
+ _XAsyncHandler async2;
+ _XAsyncErrorState async2_state;
+
+ if (seq) {
+ async1_state.min_sequence_number = seq;
+ async1_state.max_sequence_number = seq;
+ async1_state.error_code = BadName;
+ async1_state.major_opcode = X_OpenFont;
+ async1_state.minor_opcode = 0;
+ async1_state.error_count = 0;
+ async1.next = dpy->async_handlers;
+ async1.handler = _XAsyncErrorHandler;
+ async1.data = (XPointer)&async1_state;
+ dpy->async_handlers = &async1;
+ }
+
+ GetReq(XF86BigfontQueryFont, req);
+ req->reqType = extcodes->codes->major_opcode;
+ req->xf86bigfontReqType = X_XF86BigfontQueryFont;
+ req->id = fid;
+ req->flags = (extcodes->serverCapabilities & XF86Bigfont_CAP_LocalShm
+ ? XF86Bigfont_FLAGS_Shm : 0);
+
+ /* The function _XQueryFont benefits from a "magic" error handler for
+ BadFont coming from a X_QueryFont request. (See function _XReply.)
+ We have to establish an error handler ourselves. */
+ async2_state.min_sequence_number = dpy->request;
+ async2_state.max_sequence_number = dpy->request;
+ async2_state.error_code = BadFont;
+ async2_state.major_opcode = extcodes->codes->major_opcode;
+ async2_state.minor_opcode = X_XF86BigfontQueryFont;
+ async2_state.error_count = 0;
+ async2.next = dpy->async_handlers;
+ async2.handler = _XAsyncErrorHandler;
+ async2.data = (XPointer)&async2_state;
+ dpy->async_handlers = &async2;
+
+ if (!_XReply (dpy, (xReply *) &reply,
+ ((SIZEOF(xXF86BigfontQueryFontReply) - SIZEOF(xReply)) >> 2), xFalse)) {
+ DeqAsyncHandler(dpy, &async2);
+ if (seq)
+ DeqAsyncHandler(dpy, &async1);
+ return (XFontStruct *)NULL;
+ }
+ DeqAsyncHandler(dpy, &async2);
+ if (seq)
+ DeqAsyncHandler(dpy, &async1);
+ if (! (fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct)))) {
+ _XEatData(dpy,
+ reply.nFontProps * SIZEOF(xFontProp)
+ + (reply.nCharInfos > 0 && reply.shmid == (CARD32)(-1)
+ ? reply.nUniqCharInfos * SIZEOF(xCharInfo)
+ + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16)
+ : 0));
+ return (XFontStruct *)NULL;
+ }
+ fs->ext_data = NULL;
+ fs->fid = fid;
+ fs->direction = reply.drawDirection;
+ fs->min_char_or_byte2 = reply.minCharOrByte2;
+ fs->max_char_or_byte2 = reply.maxCharOrByte2;
+ fs->min_byte1 = reply.minByte1;
+ fs->max_byte1 = reply.maxByte1;
+ fs->default_char = reply.defaultChar;
+ fs->all_chars_exist = reply.allCharsExist;
+ fs->ascent = cvtINT16toInt (reply.fontAscent);
+ fs->descent = cvtINT16toInt (reply.fontDescent);
+
+ /* XXX the next two statements won't work if short isn't 16 bits */
+ fs->min_bounds = * (XCharStruct *) &reply.minBounds;
+ fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
+
+ fs->n_properties = reply.nFontProps;
+ /*
+ * if no properties defined for the font, then it is bad
+ * font, but shouldn't try to read nothing.
+ */
+ fs->properties = NULL;
+ if (fs->n_properties > 0) {
+ nbytes = reply.nFontProps * sizeof(XFontProp);
+ fs->properties = (XFontProp *) Xmalloc ((unsigned) nbytes);
+ nbytes = reply.nFontProps * SIZEOF(xFontProp);
+ if (! fs->properties) {
+ Xfree((char *) fs);
+ _XEatData(dpy,
+ nbytes
+ + (reply.nCharInfos > 0 && reply.shmid == (CARD32)(-1)
+ ? reply.nUniqCharInfos * SIZEOF(xCharInfo)
+ + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16)
+ : 0));
+ return (XFontStruct *)NULL;
+ }
+ _XRead32 (dpy, (long *)fs->properties, nbytes);
+ }
+
+ fs->per_char = NULL;
+ if (reply.nCharInfos > 0) {
+ /* fprintf(stderr, "received font metrics, nCharInfos = %d, nUniqCharInfos = %d, shmid = %d\n", reply.nCharInfos, reply.nUniqCharInfos, reply.shmid); */
+ if (reply.shmid == (CARD32)(-1)) {
+ xCharInfo* pUniqCI;
+ CARD16* pIndex2UniqIndex;
+ int i;
+
+ nbytes = reply.nUniqCharInfos * SIZEOF(xCharInfo)
+ + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16);
+ pUniqCI = (xCharInfo *) Xmalloc (nbytes);
+ if (!pUniqCI) {
+ if (fs->properties) Xfree((char *) fs->properties);
+ Xfree((char *) fs);
+ _XEatData(dpy, nbytes);
+ return (XFontStruct *)NULL;
+ }
+ if (! (fs->per_char = (XCharStruct *) Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) {
+ Xfree((char *) pUniqCI);
+ if (fs->properties) Xfree((char *) fs->properties);
+ Xfree((char *) fs);
+ _XEatData(dpy, nbytes);
+ return (XFontStruct *)NULL;
+ }
+ _XRead16 (dpy, (char *) pUniqCI, nbytes);
+ pIndex2UniqIndex = (CARD16*) (pUniqCI + reply.nUniqCharInfos);
+ for (i = 0; i < reply.nCharInfos; i++) {
+ if (pIndex2UniqIndex[i] >= reply.nUniqCharInfos) {
+ fprintf(stderr, "_XF86BigfontQueryFont: server returned wrong data\n");
+ Xfree((char *) pUniqCI);
+ if (fs->properties) Xfree((char *) fs->properties);
+ Xfree((char *) fs);
+ return (XFontStruct *)NULL;
+ }
+ /* XXX the next statement won't work if short isn't 16 bits */
+ fs->per_char[i] = * (XCharStruct *) &pUniqCI[pIndex2UniqIndex[i]];
+ }
+ Xfree((char *) pUniqCI);
+ } else {
+#ifdef HAS_SHM
+ XExtData *pData;
+ XEDataObject fs_union;
+ char *addr;
+
+ pData = (XExtData *) Xmalloc(sizeof(XExtData));
+ if (!pData) {
+ if (fs->properties) Xfree((char *) fs->properties);
+ Xfree((char *) fs);
+ return (XFontStruct *)NULL;
+ }
+
+ /* In some cases (e.g. an ssh daemon forwarding an X session to
+ a remote machine) it is possible that the X server thinks we
+ are running on the same machine (because getpeername() and
+ LocalClient() cannot know about the forwarding) but we are
+ not really local. Therefore, when we attach the first shared
+ memory segment, we verify that we are on the same machine as
+ the X server by checking that 1. shmat() succeeds, 2. the
+ segment has a sufficient size, 3. it contains the X server's
+ signature. Then we set the CAP_VerifiedLocal bit to indicate
+ the verification was successful. */
+
+ if ((addr = shmat(reply.shmid, NULL, SHM_RDONLY)) == (char *)-1) {
+ if (extcodes->serverCapabilities & CAP_VerifiedLocal)
+ fprintf(stderr, "_XF86BigfontQueryFont: could not attach shm segment\n");
+ Xfree((char *) pData);
+ if (fs->properties) Xfree((char *) fs->properties);
+ Xfree((char *) fs);
+ /* Stop requesting shared memory transport from now on. */
+ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
+ return (XFontStruct *)NULL;
+ }
+
+ if (!(extcodes->serverCapabilities & CAP_VerifiedLocal)) {
+ struct shmid_ds buf;
+ if (!(shmctl(reply.shmid, IPC_STAT, &buf) >= 0
+ && buf.shm_segsz >= reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct) + sizeof(CARD32)
+ && *(CARD32 *)(addr + reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct)) == extcodes->serverSignature)) {
+ shmdt(addr);
+ Xfree((char *) pData);
+ if (fs->properties) Xfree((char *) fs->properties);
+ Xfree((char *) fs);
+ /* Stop requesting shared memory transport from now on. */
+ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
+ return (XFontStruct *)NULL;
+ }
+ extcodes->serverCapabilities |= CAP_VerifiedLocal;
+ }
+
+ pData->number = XF86BigfontNumber;
+ pData->private_data = (XPointer) addr;
+ pData->free_private = _XF86BigfontFreeNop;
+ fs_union.font = fs;
+ XAddToExtensionList(XEHeadOfExtensionList(fs_union), pData);
+
+ fs->per_char = (XCharStruct *) (addr + reply.shmsegoffset);
+#else
+ fprintf(stderr, "_XF86BigfontQueryFont: try recompiling libX11 with HasShm, Xserver has shm support\n");
+ if (fs->properties) Xfree((char *) fs->properties);
+ Xfree((char *) fs);
+ /* Stop requesting shared memory transport from now on. */
+ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
+ return (XFontStruct *)NULL;
+#endif
+ }
+ }
+
+ /* call out to any extensions interested */
+ for (ext = dpy->ext_procs; ext; ext = ext->next)
+ if (ext->create_Font) (*ext->create_Font)(dpy, fs, &ext->codes);
+ return fs;
+}
+
+void
+_XF86BigfontFreeFontMetrics (XFontStruct *fs)
+{
+#ifdef HAS_SHM
+ XExtData *pData;
+ XEDataObject fs_union;
+
+ fs_union.font = fs;
+ if ((pData = XFindOnExtensionList(XEHeadOfExtensionList(fs_union),
+ XF86BigfontNumber)))
+ shmdt ((char *) pData->private_data);
+ else
+ Xfree ((char *) fs->per_char);
+#else
+ Xfree ((char *) fs->per_char);
+#endif
+}
+
+#endif /* USE_XF86BIGFONT */
+
+int _XF86LoadQueryLocaleFont(
+ Display *dpy,
+ _Xconst char *name,
+ XFontStruct **xfp,
+ Font *fidp)
+{
+ int l;
+ const char *charset, *p;
+ char buf[256];
+ XFontStruct *fs;
+ XLCd lcd;
+
+ if (!name)
+ return 0;
+ l = strlen(name);
+ if (l < 2 || name[l - 1] != '*' || name[l - 2] != '-')
+ return 0;
+ charset = NULL;
+ /* next three lines stolen from _XkbGetCharset() */
+ lcd = _XlcCurrentLC();
+ if ((lcd = _XlcCurrentLC()) != 0)
+ charset = XLC_PUBLIC(lcd, encoding_name);
+ if (!charset || (p = strrchr(charset, '-')) == 0 || p == charset || p[1] == 0 || (p[1] == '*' && p[2] == 0)) {
+ /* prefer latin1 if no encoding found */
+ charset = "ISO8859-1";
+ p = charset + 7;
+ }
+ if (l - 2 - (p - charset) < 0)
+ return 0;
+ if (_XlcNCompareISOLatin1(name + l - 2 - (p - charset), charset, p - charset))
+ return 0;
+ if (strlen(p + 1) + l - 1 >= sizeof(buf) - 1)
+ return 0;
+ strcpy(buf, name);
+ strcpy(buf + l - 1, p + 1);
+ fs = XLoadQueryFont(dpy, buf);
+ if (!fs)
+ return 0;
+ if (xfp) {
+ *xfp = fs;
+ if (fidp)
+ *fidp = fs->fid;
+ } else if (fidp) {
+ if (fs->per_char) {
+#ifdef USE_XF86BIGFONT
+ _XF86BigfontFreeFontMetrics(fs);
+#else
+ Xfree ((char *) fs->per_char);
+#endif
+ }
+ _XFreeExtData(fs->ext_data);
+ if (fs->properties)
+ Xfree ((char *) fs->properties);
+ *fidp = fs->fid;
+ Xfree ((char *) fs);
+ } else {
+ XFreeFont(dpy, fs);
+ }
+ return 1;
+}
diff --git a/libX11/src/FontInfo.c b/libX11/src/FontInfo.c
index d1e9f023b..dd0b83f24 100644
--- a/libX11/src/FontInfo.c
+++ b/libX11/src/FontInfo.c
@@ -1,254 +1,253 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-#if defined(XF86BIGFONT) && !defined(MUSTCOPY)
-#define USE_XF86BIGFONT
-#endif
-#ifdef USE_XF86BIGFONT
-extern void _XF86BigfontFreeFontMetrics(
- XFontStruct* /* fs */
-);
-#endif
-
-char **XListFontsWithInfo(
-register Display *dpy,
-_Xconst char *pattern, /* null-terminated */
-int maxNames,
-int *actualCount, /* RETURN */
-XFontStruct **info) /* RETURN */
-{
- register long nbytes;
- register int i;
- register XFontStruct *fs;
- register int size = 0;
- XFontStruct *finfo = NULL;
- char **flist = NULL;
- xListFontsWithInfoReply reply;
- register xListFontsReq *req;
- int j;
-
- LockDisplay(dpy);
- GetReq(ListFontsWithInfo, req);
- req->maxNames = maxNames;
- nbytes = req->nbytes = pattern ? strlen (pattern) : 0;
- req->length += (nbytes + 3) >> 2;
- _XSend (dpy, pattern, nbytes);
- /* use _XSend instead of Data, since subsequent _XReply will flush buffer */
-
- for (i = 0; ; i++) {
- if (!_XReply (dpy, (xReply *) &reply,
- ((SIZEOF(xListFontsWithInfoReply) -
- SIZEOF(xGenericReply)) >> 2), xFalse)) {
- for (j=(i-1); (j >= 0); j--) {
- Xfree(flist[j]);
- if (finfo[j].properties) Xfree((char *) finfo[j].properties);
- }
- if (flist) Xfree((char *) flist);
- if (finfo) Xfree((char *) finfo);
- UnlockDisplay(dpy);
- SyncHandle();
- return ((char **) NULL);
- }
- if (reply.nameLength == 0)
- break;
- if ((i + reply.nReplies) >= size) {
- size = i + reply.nReplies + 1;
-
- if (finfo) {
- XFontStruct * tmp_finfo = (XFontStruct *)
- Xrealloc ((char *) finfo,
- (unsigned) (sizeof(XFontStruct) * size));
- char ** tmp_flist = (char **)
- Xrealloc ((char *) flist,
- (unsigned) (sizeof(char *) * (size+1)));
-
- if ((! tmp_finfo) || (! tmp_flist)) {
- /* free all the memory that we allocated */
- for (j=(i-1); (j >= 0); j--) {
- Xfree(flist[j]);
- if (finfo[j].properties)
- Xfree((char *) finfo[j].properties);
- }
- if (tmp_flist) Xfree((char *) tmp_flist);
- else Xfree((char *) flist);
- if (tmp_finfo) Xfree((char *) tmp_finfo);
- else Xfree((char *) finfo);
- goto clearwire;
- }
- finfo = tmp_finfo;
- flist = tmp_flist;
- }
- else {
- if (! (finfo = (XFontStruct *)
- Xmalloc((unsigned) (sizeof(XFontStruct) * size))))
- goto clearwire;
- if (! (flist = (char **)
- Xmalloc((unsigned) (sizeof(char *) * (size+1))))) {
- Xfree((char *) finfo);
- goto clearwire;
- }
- }
- }
- fs = &finfo[i];
-
- fs->ext_data = NULL;
- fs->per_char = NULL;
- fs->fid = None;
- fs->direction = reply.drawDirection;
- fs->min_char_or_byte2 = reply.minCharOrByte2;
- fs->max_char_or_byte2 = reply.maxCharOrByte2;
- fs->min_byte1 = reply.minByte1;
- fs->max_byte1 = reply.maxByte1;
- fs->default_char = reply.defaultChar;
- fs->all_chars_exist = reply.allCharsExist;
- fs->ascent = cvtINT16toInt (reply.fontAscent);
- fs->descent = cvtINT16toInt (reply.fontDescent);
-
-#ifdef MUSTCOPY
- {
- xCharInfo *xcip;
-
- xcip = (xCharInfo *) &reply.minBounds;
- fs->min_bounds.lbearing = xcip->leftSideBearing;
- fs->min_bounds.rbearing = xcip->rightSideBearing;
- fs->min_bounds.width = xcip->characterWidth;
- fs->min_bounds.ascent = xcip->ascent;
- fs->min_bounds.descent = xcip->descent;
- fs->min_bounds.attributes = xcip->attributes;
-
- xcip = (xCharInfo *) &reply.maxBounds;
- fs->max_bounds.lbearing = xcip->leftSideBearing;
- fs->max_bounds.rbearing = xcip->rightSideBearing;
- fs->max_bounds.width = xcip->characterWidth;
- fs->max_bounds.ascent = xcip->ascent;
- fs->max_bounds.descent = xcip->descent;
- fs->max_bounds.attributes = xcip->attributes;
- }
-#else
- /* XXX the next two statements won't work if short isn't 16 bits */
- fs->min_bounds = * (XCharStruct *) &reply.minBounds;
- fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
-#endif /* MUSTCOPY */
-
- fs->n_properties = reply.nFontProps;
- if (fs->n_properties > 0) {
- nbytes = reply.nFontProps * sizeof(XFontProp);
- if (! (fs->properties = (XFontProp *) Xmalloc((unsigned) nbytes)))
- goto badmem;
- nbytes = reply.nFontProps * SIZEOF(xFontProp);
- _XRead32 (dpy, (long *)fs->properties, nbytes);
-
- } else
- fs->properties = NULL;
-
- j = reply.nameLength + 1;
- if (!i)
- j++; /* make first string 1 byte longer, to match XListFonts */
- flist[i] = (char *) Xmalloc ((unsigned int) j);
- if (! flist[i]) {
- if (finfo[i].properties) Xfree((char *) finfo[i].properties);
- nbytes = (reply.nameLength + 3) & ~3;
- _XEatData(dpy, (unsigned long) nbytes);
- goto badmem;
- }
- if (!i) {
- *flist[0] = 0; /* zero to distinguish from XListFonts */
- flist[0]++;
- }
- flist[i][reply.nameLength] = '\0';
- _XReadPad (dpy, flist[i], (long) reply.nameLength);
- }
- *info = finfo;
- *actualCount = i;
- if (flist)
- flist[i] = NULL; /* required in case XFreeFontNames is called */
- UnlockDisplay(dpy);
- SyncHandle();
- return (flist);
-
-
- badmem:
- /* Free all memory allocated by this function. */
- for (j=(i-1); (j >= 0); j--) {
- Xfree(flist[j]);
- if (finfo[j].properties) Xfree((char *) finfo[j].properties);
- }
- if (flist) Xfree((char *) flist);
- if (finfo) Xfree((char *) finfo);
-
- clearwire:
- /* Clear the wire. */
- do {
- if (reply.nFontProps)
- _XEatData(dpy, (unsigned long)
- (reply.nFontProps * SIZEOF(xFontProp)));
- nbytes = (reply.nameLength + 3) & ~3;
- _XEatData(dpy, (unsigned long) nbytes);
- }
- while (_XReply(dpy,(xReply *) &reply, ((SIZEOF(xListFontsWithInfoReply) -
- SIZEOF(xGenericReply)) >> 2),
- xFalse) && (reply.nameLength != 0));
-
- UnlockDisplay(dpy);
- SyncHandle();
- return (char **) NULL;
-}
-
-int
-XFreeFontInfo (
- char **names,
- XFontStruct *info,
- int actualCount)
-{
- register int i;
- if (names) {
- Xfree (names[0]-1);
- for (i = 1; i < actualCount; i++) {
- Xfree (names[i]);
- }
- Xfree((char *) names);
- }
- if (info) {
- for (i = 0; i < actualCount; i++) {
- if (info[i].per_char)
-#ifdef USE_XF86BIGFONT
- _XF86BigfontFreeFontMetrics(&info[i]);
-#else
- Xfree ((char *) info[i].per_char);
-#endif
- if (info[i].properties)
- Xfree ((char *) info[i].properties);
- }
- Xfree((char *) info);
- }
- return 1;
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+#if defined(XF86BIGFONT) && !defined(MUSTCOPY)
+#define USE_XF86BIGFONT
+#endif
+#ifdef USE_XF86BIGFONT
+extern void _XF86BigfontFreeFontMetrics(
+ XFontStruct* /* fs */
+);
+#endif
+
+char **XListFontsWithInfo(
+register Display *dpy,
+_Xconst char *pattern, /* null-terminated */
+int maxNames,
+int *actualCount, /* RETURN */
+XFontStruct **info) /* RETURN */
+{
+ register long nbytes;
+ register int i;
+ register XFontStruct *fs;
+ register int size = 0;
+ XFontStruct *finfo = NULL;
+ char **flist = NULL;
+ xListFontsWithInfoReply reply;
+ register xListFontsReq *req;
+ int j;
+
+ LockDisplay(dpy);
+ GetReq(ListFontsWithInfo, req);
+ req->maxNames = maxNames;
+ nbytes = req->nbytes = pattern ? strlen (pattern) : 0;
+ req->length += (nbytes + 3) >> 2;
+ _XSend (dpy, pattern, nbytes);
+ /* use _XSend instead of Data, since subsequent _XReply will flush buffer */
+
+ for (i = 0; ; i++) {
+ if (!_XReply (dpy, (xReply *) &reply,
+ ((SIZEOF(xListFontsWithInfoReply) -
+ SIZEOF(xGenericReply)) >> 2), xFalse)) {
+ for (j=(i-1); (j >= 0); j--) {
+ Xfree(flist[j]);
+ if (finfo[j].properties) Xfree((char *) finfo[j].properties);
+ }
+ if (flist) Xfree((char *) flist);
+ if (finfo) Xfree((char *) finfo);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return ((char **) NULL);
+ }
+ if (reply.nameLength == 0)
+ break;
+ if ((i + reply.nReplies) >= size) {
+ size = i + reply.nReplies + 1;
+
+ if (finfo) {
+ XFontStruct * tmp_finfo = (XFontStruct *)
+ Xrealloc ((char *) finfo,
+ (unsigned) (sizeof(XFontStruct) * size));
+ char ** tmp_flist = (char **)
+ Xrealloc ((char *) flist,
+ (unsigned) (sizeof(char *) * (size+1)));
+
+ if ((! tmp_finfo) || (! tmp_flist)) {
+ /* free all the memory that we allocated */
+ for (j=(i-1); (j >= 0); j--) {
+ Xfree(flist[j]);
+ if (finfo[j].properties)
+ Xfree((char *) finfo[j].properties);
+ }
+ if (tmp_flist) Xfree((char *) tmp_flist);
+ else Xfree((char *) flist);
+ if (tmp_finfo) Xfree((char *) tmp_finfo);
+ else Xfree((char *) finfo);
+ goto clearwire;
+ }
+ finfo = tmp_finfo;
+ flist = tmp_flist;
+ }
+ else {
+ if (! (finfo = (XFontStruct *)
+ Xmalloc((unsigned) (sizeof(XFontStruct) * size))))
+ goto clearwire;
+ if (! (flist = (char **)
+ Xmalloc((unsigned) (sizeof(char *) * (size+1))))) {
+ Xfree((char *) finfo);
+ goto clearwire;
+ }
+ }
+ }
+ fs = &finfo[i];
+
+ fs->ext_data = NULL;
+ fs->per_char = NULL;
+ fs->fid = None;
+ fs->direction = reply.drawDirection;
+ fs->min_char_or_byte2 = reply.minCharOrByte2;
+ fs->max_char_or_byte2 = reply.maxCharOrByte2;
+ fs->min_byte1 = reply.minByte1;
+ fs->max_byte1 = reply.maxByte1;
+ fs->default_char = reply.defaultChar;
+ fs->all_chars_exist = reply.allCharsExist;
+ fs->ascent = cvtINT16toInt (reply.fontAscent);
+ fs->descent = cvtINT16toInt (reply.fontDescent);
+
+#ifdef MUSTCOPY
+ {
+ xCharInfo *xcip;
+
+ xcip = (xCharInfo *) &reply.minBounds;
+ fs->min_bounds.lbearing = xcip->leftSideBearing;
+ fs->min_bounds.rbearing = xcip->rightSideBearing;
+ fs->min_bounds.width = xcip->characterWidth;
+ fs->min_bounds.ascent = xcip->ascent;
+ fs->min_bounds.descent = xcip->descent;
+ fs->min_bounds.attributes = xcip->attributes;
+
+ xcip = (xCharInfo *) &reply.maxBounds;
+ fs->max_bounds.lbearing = xcip->leftSideBearing;
+ fs->max_bounds.rbearing = xcip->rightSideBearing;
+ fs->max_bounds.width = xcip->characterWidth;
+ fs->max_bounds.ascent = xcip->ascent;
+ fs->max_bounds.descent = xcip->descent;
+ fs->max_bounds.attributes = xcip->attributes;
+ }
+#else
+ /* XXX the next two statements won't work if short isn't 16 bits */
+ fs->min_bounds = * (XCharStruct *) &reply.minBounds;
+ fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
+#endif /* MUSTCOPY */
+
+ fs->n_properties = reply.nFontProps;
+ if (fs->n_properties > 0) {
+ nbytes = reply.nFontProps * sizeof(XFontProp);
+ if (! (fs->properties = (XFontProp *) Xmalloc((unsigned) nbytes)))
+ goto badmem;
+ nbytes = reply.nFontProps * SIZEOF(xFontProp);
+ _XRead32 (dpy, (long *)fs->properties, nbytes);
+
+ } else
+ fs->properties = NULL;
+
+ j = reply.nameLength + 1;
+ if (!i)
+ j++; /* make first string 1 byte longer, to match XListFonts */
+ flist[i] = (char *) Xmalloc ((unsigned int) j);
+ if (! flist[i]) {
+ if (finfo[i].properties) Xfree((char *) finfo[i].properties);
+ nbytes = (reply.nameLength + 3) & ~3;
+ _XEatData(dpy, (unsigned long) nbytes);
+ goto badmem;
+ }
+ if (!i) {
+ *flist[0] = 0; /* zero to distinguish from XListFonts */
+ flist[0]++;
+ }
+ flist[i][reply.nameLength] = '\0';
+ _XReadPad (dpy, flist[i], (long) reply.nameLength);
+ }
+ *info = finfo;
+ *actualCount = i;
+ if (flist)
+ flist[i] = NULL; /* required in case XFreeFontNames is called */
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (flist);
+
+
+ badmem:
+ /* Free all memory allocated by this function. */
+ for (j=(i-1); (j >= 0); j--) {
+ Xfree(flist[j]);
+ if (finfo[j].properties) Xfree((char *) finfo[j].properties);
+ }
+ if (flist) Xfree((char *) flist);
+ if (finfo) Xfree((char *) finfo);
+
+ clearwire:
+ /* Clear the wire. */
+ do {
+ if (reply.nFontProps)
+ _XEatData(dpy, (unsigned long)
+ (reply.nFontProps * SIZEOF(xFontProp)));
+ nbytes = (reply.nameLength + 3) & ~3;
+ _XEatData(dpy, (unsigned long) nbytes);
+ }
+ while (_XReply(dpy,(xReply *) &reply, ((SIZEOF(xListFontsWithInfoReply) -
+ SIZEOF(xGenericReply)) >> 2),
+ xFalse) && (reply.nameLength != 0));
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (char **) NULL;
+}
+
+int
+XFreeFontInfo (
+ char **names,
+ XFontStruct *info,
+ int actualCount)
+{
+ register int i;
+ if (names) {
+ Xfree (names[0]-1);
+ for (i = 1; i < actualCount; i++) {
+ Xfree (names[i]);
+ }
+ Xfree((char *) names);
+ }
+ if (info) {
+ for (i = 0; i < actualCount; i++) {
+ if (info[i].per_char)
+#ifdef USE_XF86BIGFONT
+ _XF86BigfontFreeFontMetrics(&info[i]);
+#else
+ Xfree ((char *) info[i].per_char);
+#endif
+ if (info[i].properties)
+ Xfree ((char *) info[i].properties);
+ }
+ Xfree((char *) info);
+ }
+ return 1;
+}
diff --git a/libX11/src/FontNames.c b/libX11/src/FontNames.c
index c073592c4..bf133f1b7 100644
--- a/libX11/src/FontNames.c
+++ b/libX11/src/FontNames.c
@@ -1,114 +1,113 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-char **
-XListFonts(
-register Display *dpy,
-_Xconst char *pattern, /* null-terminated */
-int maxNames,
-int *actualCount) /* RETURN */
-{
- register long nbytes;
- register unsigned i;
- register int length;
- char **flist;
- char *ch;
- xListFontsReply rep;
- register xListFontsReq *req;
- register long rlen;
-
- LockDisplay(dpy);
- GetReq(ListFonts, req);
- req->maxNames = maxNames;
- nbytes = req->nbytes = pattern ? strlen (pattern) : 0;
- req->length += (nbytes + 3) >> 2;
- _XSend (dpy, pattern, nbytes);
- /* use _XSend instead of Data, since following _XReply will flush buffer */
-
- if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
- *actualCount = 0;
- UnlockDisplay(dpy);
- SyncHandle();
- return (char **) NULL;
- }
-
- if (rep.nFonts) {
- flist = (char **)Xmalloc ((unsigned)rep.nFonts * sizeof(char *));
- rlen = rep.length << 2;
- ch = (char *) Xmalloc((unsigned) (rlen + 1));
- /* +1 to leave room for last null-terminator */
-
- if ((! flist) || (! ch)) {
- if (flist) Xfree((char *) flist);
- if (ch) Xfree(ch);
- _XEatData(dpy, (unsigned long) rlen);
- *actualCount = 0;
- UnlockDisplay(dpy);
- SyncHandle();
- return (char **) NULL;
- }
-
- _XReadPad (dpy, ch, rlen);
- /*
- * unpack into null terminated strings.
- */
- length = *(unsigned char *)ch;
- *ch = 1; /* make sure it is non-zero for XFreeFontNames */
- for (i = 0; i < rep.nFonts; i++) {
- flist[i] = ch + 1; /* skip over length */
- ch += length + 1; /* find next length ... */
- length = *(unsigned char *)ch;
- *ch = '\0'; /* and replace with null-termination */
- }
- }
- else flist = (char **) NULL;
- *actualCount = rep.nFonts;
- UnlockDisplay(dpy);
- SyncHandle();
- return (flist);
-}
-
-int
-XFreeFontNames(char **list)
-{
- if (list) {
- if (!*(list[0]-1)) { /* from ListFontsWithInfo */
- register char **names;
- for (names = list+1; *names; names++)
- Xfree (*names);
- }
- Xfree (list[0]-1);
- Xfree ((char *)list);
- }
- return 1;
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+char **
+XListFonts(
+register Display *dpy,
+_Xconst char *pattern, /* null-terminated */
+int maxNames,
+int *actualCount) /* RETURN */
+{
+ register long nbytes;
+ register unsigned i;
+ register int length;
+ char **flist;
+ char *ch;
+ xListFontsReply rep;
+ register xListFontsReq *req;
+ register long rlen;
+
+ LockDisplay(dpy);
+ GetReq(ListFonts, req);
+ req->maxNames = maxNames;
+ nbytes = req->nbytes = pattern ? strlen (pattern) : 0;
+ req->length += (nbytes + 3) >> 2;
+ _XSend (dpy, pattern, nbytes);
+ /* use _XSend instead of Data, since following _XReply will flush buffer */
+
+ if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
+ *actualCount = 0;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (char **) NULL;
+ }
+
+ if (rep.nFonts) {
+ flist = (char **)Xmalloc ((unsigned)rep.nFonts * sizeof(char *));
+ rlen = rep.length << 2;
+ ch = (char *) Xmalloc((unsigned) (rlen + 1));
+ /* +1 to leave room for last null-terminator */
+
+ if ((! flist) || (! ch)) {
+ if (flist) Xfree((char *) flist);
+ if (ch) Xfree(ch);
+ _XEatData(dpy, (unsigned long) rlen);
+ *actualCount = 0;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (char **) NULL;
+ }
+
+ _XReadPad (dpy, ch, rlen);
+ /*
+ * unpack into null terminated strings.
+ */
+ length = *(unsigned char *)ch;
+ *ch = 1; /* make sure it is non-zero for XFreeFontNames */
+ for (i = 0; i < rep.nFonts; i++) {
+ flist[i] = ch + 1; /* skip over length */
+ ch += length + 1; /* find next length ... */
+ length = *(unsigned char *)ch;
+ *ch = '\0'; /* and replace with null-termination */
+ }
+ }
+ else flist = (char **) NULL;
+ *actualCount = rep.nFonts;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (flist);
+}
+
+int
+XFreeFontNames(char **list)
+{
+ if (list) {
+ if (!*(list[0]-1)) { /* from ListFontsWithInfo */
+ register char **names;
+ for (names = list+1; *names; names++)
+ Xfree (*names);
+ }
+ Xfree (list[0]-1);
+ Xfree ((char *)list);
+ }
+ return 1;
+}
diff --git a/libX11/src/GetAtomNm.c b/libX11/src/GetAtomNm.c
index 169486b06..a2d6b183d 100644
--- a/libX11/src/GetAtomNm.c
+++ b/libX11/src/GetAtomNm.c
@@ -1,190 +1,189 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xintatom.h"
-
-static
-char *_XGetAtomName(
- Display *dpy,
- Atom atom)
-{
- xResourceReq *req;
- char *name;
- register Entry *table;
- register int idx;
- register Entry e;
-
- if (dpy->atoms) {
- table = dpy->atoms->table;
- for (idx = TABLESIZE; --idx >= 0; ) {
- if ((e = *table++) && (e->atom == atom)) {
- idx = strlen(EntryName(e)) + 1;
- if ((name = (char *)Xmalloc(idx)))
- strcpy(name, EntryName(e));
- return name;
- }
- }
- }
- GetResReq(GetAtomName, atom, req);
- return (char *)NULL;
-}
-
-char *XGetAtomName(
- register Display *dpy,
- Atom atom)
-{
- xGetAtomNameReply rep;
- char *name;
-
- LockDisplay(dpy);
- if ((name = _XGetAtomName(dpy, atom))) {
- UnlockDisplay(dpy);
- return name;
- }
- if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- return(NULL);
- }
- if ((name = (char *) Xmalloc(rep.nameLength+1))) {
- _XReadPad(dpy, name, (long)rep.nameLength);
- name[rep.nameLength] = '\0';
- _XUpdateAtomCache(dpy, name, atom, 0, -1, 0);
- } else {
- _XEatData(dpy, (unsigned long) (rep.nameLength + 3) & ~3);
- name = (char *) NULL;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return(name);
-}
-
-typedef struct {
- unsigned long start_seq;
- unsigned long stop_seq;
- Atom *atoms;
- char **names;
- int idx;
- int count;
- Status status;
-} _XGetAtomNameState;
-
-static
-Bool _XGetAtomNameHandler(
- register Display *dpy,
- register xReply *rep,
- char *buf,
- int len,
- XPointer data)
-{
- register _XGetAtomNameState *state;
- xGetAtomNameReply replbuf;
- register xGetAtomNameReply *repl;
-
- state = (_XGetAtomNameState *)data;
- if (dpy->last_request_read < state->start_seq ||
- dpy->last_request_read > state->stop_seq)
- return False;
- while (state->idx < state->count && state->names[state->idx])
- state->idx++;
- if (state->idx >= state->count)
- return False;
- if (rep->generic.type == X_Error) {
- state->status = 0;
- return False;
- }
- repl = (xGetAtomNameReply *)
- _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
- (SIZEOF(xGetAtomNameReply) - SIZEOF(xReply)) >> 2,
- False);
- state->names[state->idx] = (char *) Xmalloc(repl->nameLength+1);
- _XGetAsyncData(dpy, state->names[state->idx], buf, len,
- SIZEOF(xGetAtomNameReply), repl->nameLength,
- repl->length << 2);
- if (state->names[state->idx]) {
- state->names[state->idx][repl->nameLength] = '\0';
- _XUpdateAtomCache(dpy, state->names[state->idx],
- state->atoms[state->idx], 0, -1, 0);
- } else {
- state->status = 0;
- }
- return True;
-}
-
-Status
-XGetAtomNames (
- Display *dpy,
- Atom *atoms,
- int count,
- char **names_return)
-{
- _XAsyncHandler async;
- _XGetAtomNameState async_state;
- xGetAtomNameReply rep;
- int i;
- int missed = -1;
-
- LockDisplay(dpy);
- async_state.start_seq = dpy->request + 1;
- async_state.atoms = atoms;
- async_state.names = names_return;
- async_state.idx = 0;
- async_state.count = count - 1;
- async_state.status = 1;
- async.next = dpy->async_handlers;
- async.handler = _XGetAtomNameHandler;
- async.data = (XPointer)&async_state;
- dpy->async_handlers = &async;
- for (i = 0; i < count; i++) {
- if (!(names_return[i] = _XGetAtomName(dpy, atoms[i]))) {
- missed = i;
- async_state.stop_seq = dpy->request;
- }
- }
- if (missed >= 0) {
- if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- if ((names_return[missed] = (char *) Xmalloc(rep.nameLength+1))) {
- _XReadPad(dpy, names_return[missed], (long)rep.nameLength);
- names_return[missed][rep.nameLength] = '\0';
- _XUpdateAtomCache(dpy, names_return[missed], atoms[missed],
- 0, -1, 0);
- } else {
- _XEatData(dpy, (unsigned long) (rep.nameLength + 3) & ~3);
- async_state.status = 0;
- }
- }
- }
- DeqAsyncHandler(dpy, &async);
- UnlockDisplay(dpy);
- if (missed >= 0)
- SyncHandle();
- return async_state.status;
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xintatom.h"
+
+static
+char *_XGetAtomName(
+ Display *dpy,
+ Atom atom)
+{
+ xResourceReq *req;
+ char *name;
+ register Entry *table;
+ register int idx;
+ register Entry e;
+
+ if (dpy->atoms) {
+ table = dpy->atoms->table;
+ for (idx = TABLESIZE; --idx >= 0; ) {
+ if ((e = *table++) && (e->atom == atom)) {
+ idx = strlen(EntryName(e)) + 1;
+ if ((name = (char *)Xmalloc(idx)))
+ strcpy(name, EntryName(e));
+ return name;
+ }
+ }
+ }
+ GetResReq(GetAtomName, atom, req);
+ return (char *)NULL;
+}
+
+char *XGetAtomName(
+ register Display *dpy,
+ Atom atom)
+{
+ xGetAtomNameReply rep;
+ char *name;
+
+ LockDisplay(dpy);
+ if ((name = _XGetAtomName(dpy, atom))) {
+ UnlockDisplay(dpy);
+ return name;
+ }
+ if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(NULL);
+ }
+ if ((name = (char *) Xmalloc(rep.nameLength+1))) {
+ _XReadPad(dpy, name, (long)rep.nameLength);
+ name[rep.nameLength] = '\0';
+ _XUpdateAtomCache(dpy, name, atom, 0, -1, 0);
+ } else {
+ _XEatData(dpy, (unsigned long) (rep.nameLength + 3) & ~3);
+ name = (char *) NULL;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(name);
+}
+
+typedef struct {
+ unsigned long start_seq;
+ unsigned long stop_seq;
+ Atom *atoms;
+ char **names;
+ int idx;
+ int count;
+ Status status;
+} _XGetAtomNameState;
+
+static
+Bool _XGetAtomNameHandler(
+ register Display *dpy,
+ register xReply *rep,
+ char *buf,
+ int len,
+ XPointer data)
+{
+ register _XGetAtomNameState *state;
+ xGetAtomNameReply replbuf;
+ register xGetAtomNameReply *repl;
+
+ state = (_XGetAtomNameState *)data;
+ if (dpy->last_request_read < state->start_seq ||
+ dpy->last_request_read > state->stop_seq)
+ return False;
+ while (state->idx < state->count && state->names[state->idx])
+ state->idx++;
+ if (state->idx >= state->count)
+ return False;
+ if (rep->generic.type == X_Error) {
+ state->status = 0;
+ return False;
+ }
+ repl = (xGetAtomNameReply *)
+ _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
+ (SIZEOF(xGetAtomNameReply) - SIZEOF(xReply)) >> 2,
+ False);
+ state->names[state->idx] = (char *) Xmalloc(repl->nameLength+1);
+ _XGetAsyncData(dpy, state->names[state->idx], buf, len,
+ SIZEOF(xGetAtomNameReply), repl->nameLength,
+ repl->length << 2);
+ if (state->names[state->idx]) {
+ state->names[state->idx][repl->nameLength] = '\0';
+ _XUpdateAtomCache(dpy, state->names[state->idx],
+ state->atoms[state->idx], 0, -1, 0);
+ } else {
+ state->status = 0;
+ }
+ return True;
+}
+
+Status
+XGetAtomNames (
+ Display *dpy,
+ Atom *atoms,
+ int count,
+ char **names_return)
+{
+ _XAsyncHandler async;
+ _XGetAtomNameState async_state;
+ xGetAtomNameReply rep;
+ int i;
+ int missed = -1;
+
+ LockDisplay(dpy);
+ async_state.start_seq = dpy->request + 1;
+ async_state.atoms = atoms;
+ async_state.names = names_return;
+ async_state.idx = 0;
+ async_state.count = count - 1;
+ async_state.status = 1;
+ async.next = dpy->async_handlers;
+ async.handler = _XGetAtomNameHandler;
+ async.data = (XPointer)&async_state;
+ dpy->async_handlers = &async;
+ for (i = 0; i < count; i++) {
+ if (!(names_return[i] = _XGetAtomName(dpy, atoms[i]))) {
+ missed = i;
+ async_state.stop_seq = dpy->request;
+ }
+ }
+ if (missed >= 0) {
+ if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ if ((names_return[missed] = (char *) Xmalloc(rep.nameLength+1))) {
+ _XReadPad(dpy, names_return[missed], (long)rep.nameLength);
+ names_return[missed][rep.nameLength] = '\0';
+ _XUpdateAtomCache(dpy, names_return[missed], atoms[missed],
+ 0, -1, 0);
+ } else {
+ _XEatData(dpy, (unsigned long) (rep.nameLength + 3) & ~3);
+ async_state.status = 0;
+ }
+ }
+ }
+ DeqAsyncHandler(dpy, &async);
+ UnlockDisplay(dpy);
+ if (missed >= 0)
+ SyncHandle();
+ return async_state.status;
+}
diff --git a/libX11/src/GetColor.c b/libX11/src/GetColor.c
index 1fa79601b..fc5de7c9b 100644
--- a/libX11/src/GetColor.c
+++ b/libX11/src/GetColor.c
@@ -1,112 +1,111 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "Xcmsint.h"
-
-Status
-XAllocNamedColor(
-register Display *dpy,
-Colormap cmap,
-_Xconst char *colorname, /* STRING8 */
-XColor *hard_def, /* RETURN */
-XColor *exact_def) /* RETURN */
-{
-
- long nbytes;
- xAllocNamedColorReply rep;
- xAllocNamedColorReq *req;
-
- XcmsCCC ccc;
- XcmsColor cmsColor_exact;
- Status ret;
-
-#ifdef XCMS
- /*
- * Let's Attempt to use Xcms and i18n approach to Parse Color
- */
- if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
- const char *tmpName = colorname;
-
- switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact,
- XcmsRGBFormat)) {
- case XcmsSuccess:
- case XcmsSuccessWithCompression:
- _XcmsRGB_to_XColor(&cmsColor_exact, exact_def, 1);
- memcpy((char *)hard_def, (char *)exact_def, sizeof(XColor));
- ret = XAllocColor(dpy, cmap, hard_def);
- exact_def->pixel = hard_def->pixel;
- return(ret);
- case XcmsFailure:
- case _XCMS_NEWNAME:
- /*
- * if the result was _XCMS_NEWNAME tmpName points to
- * a string in cmsColNm.c:pairs table, for example,
- * gray70 would become tekhvc:0.0/70.0/0.0
- */
- break;
- }
- }
-#endif
-
- /*
- * Xcms and i18n approach failed.
- */
- LockDisplay(dpy);
- GetReq(AllocNamedColor, req);
-
- req->cmap = cmap;
- nbytes = req->nbytes = strlen(colorname);
- req->length += (nbytes + 3) >> 2; /* round up to mult of 4 */
-
- _XSend(dpy, colorname, nbytes);
- /* _XSend is more efficient that Data, since _XReply follows */
-
- if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (0);
- }
-
- exact_def->red = rep.exactRed;
- exact_def->green = rep.exactGreen;
- exact_def->blue = rep.exactBlue;
-
- hard_def->red = rep.screenRed;
- hard_def->green = rep.screenGreen;
- hard_def->blue = rep.screenBlue;
-
- exact_def->pixel = hard_def->pixel = rep.pixel;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return (1);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+
+Status
+XAllocNamedColor(
+register Display *dpy,
+Colormap cmap,
+_Xconst char *colorname, /* STRING8 */
+XColor *hard_def, /* RETURN */
+XColor *exact_def) /* RETURN */
+{
+
+ long nbytes;
+ xAllocNamedColorReply rep;
+ xAllocNamedColorReq *req;
+
+ XcmsCCC ccc;
+ XcmsColor cmsColor_exact;
+ Status ret;
+
+#ifdef XCMS
+ /*
+ * Let's Attempt to use Xcms and i18n approach to Parse Color
+ */
+ if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
+ const char *tmpName = colorname;
+
+ switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact,
+ XcmsRGBFormat)) {
+ case XcmsSuccess:
+ case XcmsSuccessWithCompression:
+ _XcmsRGB_to_XColor(&cmsColor_exact, exact_def, 1);
+ memcpy((char *)hard_def, (char *)exact_def, sizeof(XColor));
+ ret = XAllocColor(dpy, cmap, hard_def);
+ exact_def->pixel = hard_def->pixel;
+ return(ret);
+ case XcmsFailure:
+ case _XCMS_NEWNAME:
+ /*
+ * if the result was _XCMS_NEWNAME tmpName points to
+ * a string in cmsColNm.c:pairs table, for example,
+ * gray70 would become tekhvc:0.0/70.0/0.0
+ */
+ break;
+ }
+ }
+#endif
+
+ /*
+ * Xcms and i18n approach failed.
+ */
+ LockDisplay(dpy);
+ GetReq(AllocNamedColor, req);
+
+ req->cmap = cmap;
+ nbytes = req->nbytes = strlen(colorname);
+ req->length += (nbytes + 3) >> 2; /* round up to mult of 4 */
+
+ _XSend(dpy, colorname, nbytes);
+ /* _XSend is more efficient that Data, since _XReply follows */
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (0);
+ }
+
+ exact_def->red = rep.exactRed;
+ exact_def->green = rep.exactGreen;
+ exact_def->blue = rep.exactBlue;
+
+ hard_def->red = rep.screenRed;
+ hard_def->green = rep.screenGreen;
+ hard_def->blue = rep.screenBlue;
+
+ exact_def->pixel = hard_def->pixel = rep.pixel;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (1);
+}
diff --git a/libX11/src/GetFPath.c b/libX11/src/GetFPath.c
index 484d16276..b5643b5d8 100644
--- a/libX11/src/GetFPath.c
+++ b/libX11/src/GetFPath.c
@@ -1,92 +1,91 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-char **XGetFontPath(
- register Display *dpy,
- int *npaths) /* RETURN */
-{
- xGetFontPathReply rep;
- register long nbytes;
- char **flist;
- char *ch;
- register unsigned i;
- register int length;
- register xReq *req;
-
- LockDisplay(dpy);
- GetEmptyReq (GetFontPath, req);
- (void) _XReply (dpy, (xReply *) &rep, 0, xFalse);
-
- if (rep.nPaths) {
- flist = (char **)
- Xmalloc((unsigned) rep.nPaths * sizeof (char *));
- nbytes = (long)rep.length << 2;
- ch = (char *) Xmalloc ((unsigned) (nbytes + 1));
- /* +1 to leave room for last null-terminator */
-
- if ((! flist) || (! ch)) {
- if (flist) Xfree((char *) flist);
- if (ch) Xfree(ch);
- _XEatData(dpy, (unsigned long) nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return (char **) NULL;
- }
-
- _XReadPad (dpy, ch, nbytes);
- /*
- * unpack into null terminated strings.
- */
- length = *ch;
- for (i = 0; i < rep.nPaths; i++) {
- flist[i] = ch+1; /* skip over length */
- ch += length + 1; /* find next length ... */
- length = *ch;
- *ch = '\0'; /* and replace with null-termination */
- }
- }
- else flist = NULL;
- *npaths = rep.nPaths;
- UnlockDisplay(dpy);
- SyncHandle();
- return (flist);
-}
-
-int
-XFreeFontPath (char **list)
-{
- if (list != NULL) {
- Xfree (list[0]-1);
- Xfree ((char *)list);
- }
- return 1;
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+char **XGetFontPath(
+ register Display *dpy,
+ int *npaths) /* RETURN */
+{
+ xGetFontPathReply rep;
+ register long nbytes;
+ char **flist;
+ char *ch;
+ register unsigned i;
+ register int length;
+ register xReq *req;
+
+ LockDisplay(dpy);
+ GetEmptyReq (GetFontPath, req);
+ (void) _XReply (dpy, (xReply *) &rep, 0, xFalse);
+
+ if (rep.nPaths) {
+ flist = (char **)
+ Xmalloc((unsigned) rep.nPaths * sizeof (char *));
+ nbytes = (long)rep.length << 2;
+ ch = (char *) Xmalloc ((unsigned) (nbytes + 1));
+ /* +1 to leave room for last null-terminator */
+
+ if ((! flist) || (! ch)) {
+ if (flist) Xfree((char *) flist);
+ if (ch) Xfree(ch);
+ _XEatData(dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (char **) NULL;
+ }
+
+ _XReadPad (dpy, ch, nbytes);
+ /*
+ * unpack into null terminated strings.
+ */
+ length = *ch;
+ for (i = 0; i < rep.nPaths; i++) {
+ flist[i] = ch+1; /* skip over length */
+ ch += length + 1; /* find next length ... */
+ length = *ch;
+ *ch = '\0'; /* and replace with null-termination */
+ }
+ }
+ else flist = NULL;
+ *npaths = rep.nPaths;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (flist);
+}
+
+int
+XFreeFontPath (char **list)
+{
+ if (list != NULL) {
+ Xfree (list[0]-1);
+ Xfree ((char *)list);
+ }
+ return 1;
+}
diff --git a/libX11/src/GetGeom.c b/libX11/src/GetGeom.c
index 9f55c210b..eac36b064 100644
--- a/libX11/src/GetGeom.c
+++ b/libX11/src/GetGeom.c
@@ -1,64 +1,63 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XGetGeometry (
- register Display *dpy,
- Drawable d,
- Window *root, /* RETURN */
- int *x,
- int *y, /* RETURN */
- unsigned int *width,
- unsigned int *height,
- unsigned int *borderWidth,
- unsigned int *depth) /* RETURN */
-{
- xGetGeometryReply rep;
- register xResourceReq *req;
- LockDisplay(dpy);
- GetResReq(GetGeometry, d, req);
- if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (0);
- }
- *root = rep.root;
- *x = cvtINT16toInt (rep.x);
- *y = cvtINT16toInt (rep.y);
- *width = rep.width;
- *height = rep.height;
- *borderWidth = rep.borderWidth;
- *depth = rep.depth;
- UnlockDisplay(dpy);
- SyncHandle();
- return (1);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XGetGeometry (
+ register Display *dpy,
+ Drawable d,
+ Window *root, /* RETURN */
+ int *x,
+ int *y, /* RETURN */
+ unsigned int *width,
+ unsigned int *height,
+ unsigned int *borderWidth,
+ unsigned int *depth) /* RETURN */
+{
+ xGetGeometryReply rep;
+ register xResourceReq *req;
+ LockDisplay(dpy);
+ GetResReq(GetGeometry, d, req);
+ if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (0);
+ }
+ *root = rep.root;
+ *x = cvtINT16toInt (rep.x);
+ *y = cvtINT16toInt (rep.y);
+ *width = rep.width;
+ *height = rep.height;
+ *borderWidth = rep.borderWidth;
+ *depth = rep.depth;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (1);
+}
+
diff --git a/libX11/src/GetHColor.c b/libX11/src/GetHColor.c
index 6bdd4faed..2a633c323 100644
--- a/libX11/src/GetHColor.c
+++ b/libX11/src/GetHColor.c
@@ -1,59 +1,58 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XAllocColor(
- register Display *dpy,
- Colormap cmap,
- XColor *def)
-{
- Status status;
- xAllocColorReply rep;
- register xAllocColorReq *req;
- LockDisplay(dpy);
- GetReq(AllocColor, req);
-
- req->cmap = cmap;
- req->red = def->red;
- req->green = def->green;
- req->blue = def->blue;
-
- status = _XReply(dpy, (xReply *) &rep, 0, xTrue);
- if (status) {
- def->pixel = rep.pixel;
- def->red = rep.red;
- def->green = rep.green;
- def->blue = rep.blue;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return(status);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XAllocColor(
+ register Display *dpy,
+ Colormap cmap,
+ XColor *def)
+{
+ Status status;
+ xAllocColorReply rep;
+ register xAllocColorReq *req;
+ LockDisplay(dpy);
+ GetReq(AllocColor, req);
+
+ req->cmap = cmap;
+ req->red = def->red;
+ req->green = def->green;
+ req->blue = def->blue;
+
+ status = _XReply(dpy, (xReply *) &rep, 0, xTrue);
+ if (status) {
+ def->pixel = rep.pixel;
+ def->red = rep.red;
+ def->green = rep.green;
+ def->blue = rep.blue;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(status);
+}
diff --git a/libX11/src/GetIFocus.c b/libX11/src/GetIFocus.c
index 815f21bab..eccd60af5 100644
--- a/libX11/src/GetIFocus.c
+++ b/libX11/src/GetIFocus.c
@@ -1,50 +1,49 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XGetInputFocus(
- register Display *dpy,
- Window *focus,
- int *revert_to)
-{
- xGetInputFocusReply rep;
- register xReq *req;
- LockDisplay(dpy);
- GetEmptyReq(GetInputFocus, req);
- (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
- *focus = rep.focus;
- *revert_to = rep.revertTo;
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XGetInputFocus(
+ register Display *dpy,
+ Window *focus,
+ int *revert_to)
+{
+ xGetInputFocusReply rep;
+ register xReq *req;
+ LockDisplay(dpy);
+ GetEmptyReq(GetInputFocus, req);
+ (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
+ *focus = rep.focus;
+ *revert_to = rep.revertTo;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/GetImage.c b/libX11/src/GetImage.c
index 602ba6588..2017b30c6 100644
--- a/libX11/src/GetImage.c
+++ b/libX11/src/GetImage.c
@@ -1,129 +1,128 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include <X11/Xutil.h> /* for XDestroyImage */
-#include "ImUtil.h"
-
-#define ROUNDUP(nbytes, pad) (((((nbytes) - 1) + (pad)) / (pad)) * (pad))
-
-static unsigned int Ones( /* HACKMEM 169 */
- unsigned long mask)
-{
- register unsigned long y;
-
- y = (mask >> 1) &033333333333;
- y = mask - y - ((y >>1) & 033333333333);
- return ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
-}
-
-XImage *XGetImage (
- register Display *dpy,
- Drawable d,
- int x,
- int y,
- unsigned int width,
- unsigned int height,
- unsigned long plane_mask,
- int format) /* either XYPixmap or ZPixmap */
-{
- xGetImageReply rep;
- register xGetImageReq *req;
- char *data;
- long nbytes;
- XImage *image;
- LockDisplay(dpy);
- GetReq (GetImage, req);
- /*
- * first set up the standard stuff in the request
- */
- req->drawable = d;
- req->x = x;
- req->y = y;
- req->width = width;
- req->height = height;
- req->planeMask = plane_mask;
- req->format = format;
-
- if (_XReply (dpy, (xReply *) &rep, 0, xFalse) == 0 ||
- rep.length == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (XImage *)NULL;
- }
-
- nbytes = (long)rep.length << 2;
- data = (char *) Xmalloc((unsigned) nbytes);
- if (! data) {
- _XEatData(dpy, (unsigned long) nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return (XImage *) NULL;
- }
- _XReadPad (dpy, data, nbytes);
- if (format == XYPixmap)
- image = XCreateImage(dpy, _XVIDtoVisual(dpy, rep.visual),
- Ones (plane_mask &
- (((unsigned long)0xFFFFFFFF) >> (32 - rep.depth))),
- format, 0, data, width, height, dpy->bitmap_pad, 0);
- else /* format == ZPixmap */
- image = XCreateImage (dpy, _XVIDtoVisual(dpy, rep.visual),
- rep.depth, ZPixmap, 0, data, width, height,
- _XGetScanlinePad(dpy, (int) rep.depth), 0);
-
- if (!image)
- Xfree(data);
- UnlockDisplay(dpy);
- SyncHandle();
- return (image);
-}
-
-XImage *XGetSubImage(
- register Display *dpy,
- Drawable d,
- int x,
- int y,
- unsigned int width,
- unsigned int height,
- unsigned long plane_mask,
- int format, /* either XYPixmap or ZPixmap */
- XImage *dest_image,
- int dest_x,
- int dest_y)
-{
- XImage *temp_image;
- temp_image = XGetImage(dpy, d, x, y, width, height,
- plane_mask, format);
- if (!temp_image)
- return (XImage *)NULL;
- _XSetImage(temp_image, dest_image, dest_x, dest_y);
- XDestroyImage(temp_image);
- return (dest_image);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include "ImUtil.h"
+
+#define ROUNDUP(nbytes, pad) (((((nbytes) - 1) + (pad)) / (pad)) * (pad))
+
+static unsigned int Ones( /* HACKMEM 169 */
+ unsigned long mask)
+{
+ register unsigned long y;
+
+ y = (mask >> 1) &033333333333;
+ y = mask - y - ((y >>1) & 033333333333);
+ return ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
+}
+
+XImage *XGetImage (
+ register Display *dpy,
+ Drawable d,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height,
+ unsigned long plane_mask,
+ int format) /* either XYPixmap or ZPixmap */
+{
+ xGetImageReply rep;
+ register xGetImageReq *req;
+ char *data;
+ long nbytes;
+ XImage *image;
+ LockDisplay(dpy);
+ GetReq (GetImage, req);
+ /*
+ * first set up the standard stuff in the request
+ */
+ req->drawable = d;
+ req->x = x;
+ req->y = y;
+ req->width = width;
+ req->height = height;
+ req->planeMask = plane_mask;
+ req->format = format;
+
+ if (_XReply (dpy, (xReply *) &rep, 0, xFalse) == 0 ||
+ rep.length == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (XImage *)NULL;
+ }
+
+ nbytes = (long)rep.length << 2;
+ data = (char *) Xmalloc((unsigned) nbytes);
+ if (! data) {
+ _XEatData(dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (XImage *) NULL;
+ }
+ _XReadPad (dpy, data, nbytes);
+ if (format == XYPixmap)
+ image = XCreateImage(dpy, _XVIDtoVisual(dpy, rep.visual),
+ Ones (plane_mask &
+ (((unsigned long)0xFFFFFFFF) >> (32 - rep.depth))),
+ format, 0, data, width, height, dpy->bitmap_pad, 0);
+ else /* format == ZPixmap */
+ image = XCreateImage (dpy, _XVIDtoVisual(dpy, rep.visual),
+ rep.depth, ZPixmap, 0, data, width, height,
+ _XGetScanlinePad(dpy, (int) rep.depth), 0);
+
+ if (!image)
+ Xfree(data);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (image);
+}
+
+XImage *XGetSubImage(
+ register Display *dpy,
+ Drawable d,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height,
+ unsigned long plane_mask,
+ int format, /* either XYPixmap or ZPixmap */
+ XImage *dest_image,
+ int dest_x,
+ int dest_y)
+{
+ XImage *temp_image;
+ temp_image = XGetImage(dpy, d, x, y, width, height,
+ plane_mask, format);
+ if (!temp_image)
+ return (XImage *)NULL;
+ _XSetImage(temp_image, dest_image, dest_x, dest_y);
+ XDestroyImage(temp_image);
+ return (dest_image);
+}
diff --git a/libX11/src/GetKCnt.c b/libX11/src/GetKCnt.c
index 4ac69d16c..94c82af83 100644
--- a/libX11/src/GetKCnt.c
+++ b/libX11/src/GetKCnt.c
@@ -1,56 +1,55 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XGetKeyboardControl (
- register Display *dpy,
- register XKeyboardState *state)
-{
- xGetKeyboardControlReply rep;
- register xReq *req;
- LockDisplay(dpy);
- GetEmptyReq (GetKeyboardControl, req);
- (void) _XReply (dpy, (xReply *) &rep,
- (SIZEOF(xGetKeyboardControlReply) - SIZEOF(xReply)) >> 2, xTrue);
-
- state->key_click_percent = rep.keyClickPercent;
- state->bell_percent = rep.bellPercent;
- state->bell_pitch = rep.bellPitch;
- state->bell_duration = rep.bellDuration;
- state->led_mask = rep.ledMask;
- state->global_auto_repeat = rep.globalAutoRepeat;
- memcpy (state->auto_repeats, rep.map, sizeof state->auto_repeats);
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
- }
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XGetKeyboardControl (
+ register Display *dpy,
+ register XKeyboardState *state)
+{
+ xGetKeyboardControlReply rep;
+ register xReq *req;
+ LockDisplay(dpy);
+ GetEmptyReq (GetKeyboardControl, req);
+ (void) _XReply (dpy, (xReply *) &rep,
+ (SIZEOF(xGetKeyboardControlReply) - SIZEOF(xReply)) >> 2, xTrue);
+
+ state->key_click_percent = rep.keyClickPercent;
+ state->bell_percent = rep.bellPercent;
+ state->bell_pitch = rep.bellPitch;
+ state->bell_duration = rep.bellDuration;
+ state->led_mask = rep.ledMask;
+ state->global_auto_repeat = rep.globalAutoRepeat;
+ memcpy (state->auto_repeats, rep.map, sizeof state->auto_repeats);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+ }
+
diff --git a/libX11/src/GetMoEv.c b/libX11/src/GetMoEv.c
index 05e2f04d8..d66604217 100644
--- a/libX11/src/GetMoEv.c
+++ b/libX11/src/GetMoEv.c
@@ -1,86 +1,85 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-XTimeCoord *XGetMotionEvents(
- register Display *dpy,
- Window w,
- Time start,
- Time stop,
- int *nEvents) /* RETURN */
-{
- xGetMotionEventsReply rep;
- register xGetMotionEventsReq *req;
- XTimeCoord *tc = NULL;
- long nbytes;
- LockDisplay(dpy);
- GetReq(GetMotionEvents, req);
- req->window = w;
-/* XXX is this right for all machines? */
- req->start = start;
- req->stop = stop;
- if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (NULL);
- }
-
- if (rep.nEvents) {
- if (! (tc = (XTimeCoord *)
- Xmalloc( (unsigned)
- (nbytes = (long) rep.nEvents * sizeof(XTimeCoord))))) {
- _XEatData (dpy, (unsigned long) nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return (NULL);
- }
- }
-
- *nEvents = rep.nEvents;
- nbytes = SIZEOF (xTimecoord);
- {
- register XTimeCoord *tcptr;
- register int i;
- xTimecoord xtc;
-
- for (i = rep.nEvents, tcptr = tc; i > 0; i--, tcptr++) {
- _XRead (dpy, (char *) &xtc, nbytes);
- tcptr->time = xtc.time;
- tcptr->x = cvtINT16toShort (xtc.x);
- tcptr->y = cvtINT16toShort (xtc.y);
- }
- }
-
- UnlockDisplay(dpy);
- SyncHandle();
- return (tc);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+XTimeCoord *XGetMotionEvents(
+ register Display *dpy,
+ Window w,
+ Time start,
+ Time stop,
+ int *nEvents) /* RETURN */
+{
+ xGetMotionEventsReply rep;
+ register xGetMotionEventsReq *req;
+ XTimeCoord *tc = NULL;
+ long nbytes;
+ LockDisplay(dpy);
+ GetReq(GetMotionEvents, req);
+ req->window = w;
+/* XXX is this right for all machines? */
+ req->start = start;
+ req->stop = stop;
+ if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (NULL);
+ }
+
+ if (rep.nEvents) {
+ if (! (tc = (XTimeCoord *)
+ Xmalloc( (unsigned)
+ (nbytes = (long) rep.nEvents * sizeof(XTimeCoord))))) {
+ _XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (NULL);
+ }
+ }
+
+ *nEvents = rep.nEvents;
+ nbytes = SIZEOF (xTimecoord);
+ {
+ register XTimeCoord *tcptr;
+ register int i;
+ xTimecoord xtc;
+
+ for (i = rep.nEvents, tcptr = tc; i > 0; i--, tcptr++) {
+ _XRead (dpy, (char *) &xtc, nbytes);
+ tcptr->time = xtc.time;
+ tcptr->x = cvtINT16toShort (xtc.x);
+ tcptr->y = cvtINT16toShort (xtc.y);
+ }
+ }
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (tc);
+}
+
diff --git a/libX11/src/GetPCnt.c b/libX11/src/GetPCnt.c
index 474a69153..616a13cba 100644
--- a/libX11/src/GetPCnt.c
+++ b/libX11/src/GetPCnt.c
@@ -1,53 +1,52 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XGetPointerControl(
- register Display *dpy,
- /* the following are return only vars */
- int *accel_numer,
- int *accel_denom,
- int *threshold)
-{
- xGetPointerControlReply rep;
- xReq *req;
- LockDisplay(dpy);
- GetEmptyReq(GetPointerControl, req);
- (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
- *accel_numer = rep.accelNumerator;
- *accel_denom = rep.accelDenominator;
- *threshold = rep.threshold;
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XGetPointerControl(
+ register Display *dpy,
+ /* the following are return only vars */
+ int *accel_numer,
+ int *accel_denom,
+ int *threshold)
+{
+ xGetPointerControlReply rep;
+ xReq *req;
+ LockDisplay(dpy);
+ GetEmptyReq(GetPointerControl, req);
+ (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
+ *accel_numer = rep.accelNumerator;
+ *accel_denom = rep.accelDenominator;
+ *threshold = rep.threshold;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/GetPntMap.c b/libX11/src/GetPntMap.c
index 5f65ffe61..a89d28aed 100644
--- a/libX11/src/GetPntMap.c
+++ b/libX11/src/GetPntMap.c
@@ -1,124 +1,123 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-#ifdef MIN /* some systems define this in <sys/param.h> */
-#undef MIN
-#endif
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-
-int XGetPointerMapping (
- register Display *dpy,
- unsigned char *map, /* RETURN */
- int nmaps)
-
-{
- unsigned char mapping[256]; /* known fixed size */
- long nbytes, remainder = 0;
- xGetPointerMappingReply rep;
- register xReq *req;
-
- LockDisplay(dpy);
- GetEmptyReq(GetPointerMapping, req);
- if (! _XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return 0;
- }
-
- nbytes = (long)rep.length << 2;
-
- /* Don't count on the server returning a valid value */
- if (nbytes > sizeof mapping) {
- remainder = nbytes - sizeof mapping;
- nbytes = sizeof mapping;
- }
- _XRead (dpy, (char *)mapping, nbytes);
- /* don't return more data than the user asked for. */
- if (rep.nElts) {
- memcpy ((char *) map, (char *) mapping,
- MIN((int)rep.nElts, nmaps) );
- }
-
- if (remainder)
- _XEatData(dpy, (unsigned long)remainder);
-
- UnlockDisplay(dpy);
- SyncHandle();
- return ((int) rep.nElts);
-}
-
-KeySym *
-XGetKeyboardMapping (Display *dpy,
-#if NeedWidePrototypes
- unsigned int first_keycode,
-#else
- KeyCode first_keycode,
-#endif
- int count,
- int *keysyms_per_keycode)
-{
- long nbytes;
- unsigned long nkeysyms;
- register KeySym *mapping = NULL;
- xGetKeyboardMappingReply rep;
- register xGetKeyboardMappingReq *req;
-
- LockDisplay(dpy);
- GetReq(GetKeyboardMapping, req);
- req->firstKeyCode = first_keycode;
- req->count = count;
- if (! _XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (KeySym *) NULL;
- }
-
- nkeysyms = (unsigned long) rep.length;
- if (nkeysyms > 0) {
- nbytes = nkeysyms * sizeof (KeySym);
- mapping = (KeySym *) Xmalloc ((unsigned) nbytes);
- nbytes = nkeysyms << 2;
- if (! mapping) {
- _XEatData(dpy, (unsigned long) nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return (KeySym *) NULL;
- }
- _XRead32 (dpy, (long *) mapping, nbytes);
- }
- *keysyms_per_keycode = rep.keySymsPerKeyCode;
- UnlockDisplay(dpy);
- SyncHandle();
- return (mapping);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+#ifdef MIN /* some systems define this in <sys/param.h> */
+#undef MIN
+#endif
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
+int XGetPointerMapping (
+ register Display *dpy,
+ unsigned char *map, /* RETURN */
+ int nmaps)
+
+{
+ unsigned char mapping[256]; /* known fixed size */
+ long nbytes, remainder = 0;
+ xGetPointerMappingReply rep;
+ register xReq *req;
+
+ LockDisplay(dpy);
+ GetEmptyReq(GetPointerMapping, req);
+ if (! _XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+
+ nbytes = (long)rep.length << 2;
+
+ /* Don't count on the server returning a valid value */
+ if (nbytes > sizeof mapping) {
+ remainder = nbytes - sizeof mapping;
+ nbytes = sizeof mapping;
+ }
+ _XRead (dpy, (char *)mapping, nbytes);
+ /* don't return more data than the user asked for. */
+ if (rep.nElts) {
+ memcpy ((char *) map, (char *) mapping,
+ MIN((int)rep.nElts, nmaps) );
+ }
+
+ if (remainder)
+ _XEatData(dpy, (unsigned long)remainder);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return ((int) rep.nElts);
+}
+
+KeySym *
+XGetKeyboardMapping (Display *dpy,
+#if NeedWidePrototypes
+ unsigned int first_keycode,
+#else
+ KeyCode first_keycode,
+#endif
+ int count,
+ int *keysyms_per_keycode)
+{
+ long nbytes;
+ unsigned long nkeysyms;
+ register KeySym *mapping = NULL;
+ xGetKeyboardMappingReply rep;
+ register xGetKeyboardMappingReq *req;
+
+ LockDisplay(dpy);
+ GetReq(GetKeyboardMapping, req);
+ req->firstKeyCode = first_keycode;
+ req->count = count;
+ if (! _XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (KeySym *) NULL;
+ }
+
+ nkeysyms = (unsigned long) rep.length;
+ if (nkeysyms > 0) {
+ nbytes = nkeysyms * sizeof (KeySym);
+ mapping = (KeySym *) Xmalloc ((unsigned) nbytes);
+ nbytes = nkeysyms << 2;
+ if (! mapping) {
+ _XEatData(dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (KeySym *) NULL;
+ }
+ _XRead32 (dpy, (long *) mapping, nbytes);
+ }
+ *keysyms_per_keycode = rep.keySymsPerKeyCode;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (mapping);
+}
+
diff --git a/libX11/src/GetProp.c b/libX11/src/GetProp.c
index 75d772bd0..fc4643b95 100644
--- a/libX11/src/GetProp.c
+++ b/libX11/src/GetProp.c
@@ -1,134 +1,133 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XGetWindowProperty(
- register Display *dpy,
- Window w,
- Atom property,
- long offset,
- long length,
- Bool delete,
- Atom req_type,
- Atom *actual_type, /* RETURN */
- int *actual_format, /* RETURN 8, 16, or 32 */
- unsigned long *nitems, /* RETURN # of 8-, 16-, or 32-bit entities */
- unsigned long *bytesafter, /* RETURN */
- unsigned char **prop) /* RETURN */
-{
- xGetPropertyReply reply;
- register xGetPropertyReq *req;
- xError error;
-
- LockDisplay(dpy);
- GetReq (GetProperty, req);
- req->window = w;
- req->property = property;
- req->type = req_type;
- req->delete = delete;
- req->longOffset = offset;
- req->longLength = length;
- error.sequenceNumber = dpy->request;
-
- if (!_XReply (dpy, (xReply *) &reply, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (1); /* not Success */
- }
-
- *prop = (unsigned char *) NULL;
- if (reply.propertyType != None) {
- long nbytes, netbytes;
- switch (reply.format) {
- /*
- * One extra byte is malloced than is needed to contain the property
- * data, but this last byte is null terminated and convenient for
- * returning string properties, so the client doesn't then have to
- * recopy the string to make it null terminated.
- */
- case 8:
- nbytes = netbytes = reply.nItems;
- if (nbytes + 1 > 0 &&
- (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
- _XReadPad (dpy, (char *) *prop, netbytes);
- break;
-
- case 16:
- nbytes = reply.nItems * sizeof (short);
- netbytes = reply.nItems << 1;
- if (nbytes + 1 > 0 &&
- (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
- _XRead16Pad (dpy, (short *) *prop, netbytes);
- break;
-
- case 32:
- nbytes = reply.nItems * sizeof (long);
- netbytes = reply.nItems << 2;
- if (nbytes + 1 > 0 &&
- (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
- _XRead32 (dpy, (long *) *prop, netbytes);
- break;
-
- default:
- /*
- * This part of the code should never be reached. If it is,
- * the server sent back a property with an invalid format.
- * This is a BadImplementation error.
- */
- {
- /* sequence number stored above */
- error.type = X_Error;
- error.majorCode = X_GetProperty;
- error.minorCode = 0;
- error.errorCode = BadImplementation;
- _XError(dpy, &error);
- }
- nbytes = netbytes = 0L;
- break;
- }
- if (! *prop) {
- _XEatData(dpy, (unsigned long) netbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return(BadAlloc); /* not Success */
- }
- (*prop)[nbytes] = '\0';
- }
- *actual_type = reply.propertyType;
- *actual_format = reply.format;
- *nitems = reply.nItems;
- *bytesafter = reply.bytesAfter;
- UnlockDisplay(dpy);
- SyncHandle();
- return(Success);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XGetWindowProperty(
+ register Display *dpy,
+ Window w,
+ Atom property,
+ long offset,
+ long length,
+ Bool delete,
+ Atom req_type,
+ Atom *actual_type, /* RETURN */
+ int *actual_format, /* RETURN 8, 16, or 32 */
+ unsigned long *nitems, /* RETURN # of 8-, 16-, or 32-bit entities */
+ unsigned long *bytesafter, /* RETURN */
+ unsigned char **prop) /* RETURN */
+{
+ xGetPropertyReply reply;
+ register xGetPropertyReq *req;
+ xError error;
+
+ LockDisplay(dpy);
+ GetReq (GetProperty, req);
+ req->window = w;
+ req->property = property;
+ req->type = req_type;
+ req->delete = delete;
+ req->longOffset = offset;
+ req->longLength = length;
+ error.sequenceNumber = dpy->request;
+
+ if (!_XReply (dpy, (xReply *) &reply, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (1); /* not Success */
+ }
+
+ *prop = (unsigned char *) NULL;
+ if (reply.propertyType != None) {
+ long nbytes, netbytes;
+ switch (reply.format) {
+ /*
+ * One extra byte is malloced than is needed to contain the property
+ * data, but this last byte is null terminated and convenient for
+ * returning string properties, so the client doesn't then have to
+ * recopy the string to make it null terminated.
+ */
+ case 8:
+ nbytes = netbytes = reply.nItems;
+ if (nbytes + 1 > 0 &&
+ (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
+ _XReadPad (dpy, (char *) *prop, netbytes);
+ break;
+
+ case 16:
+ nbytes = reply.nItems * sizeof (short);
+ netbytes = reply.nItems << 1;
+ if (nbytes + 1 > 0 &&
+ (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
+ _XRead16Pad (dpy, (short *) *prop, netbytes);
+ break;
+
+ case 32:
+ nbytes = reply.nItems * sizeof (long);
+ netbytes = reply.nItems << 2;
+ if (nbytes + 1 > 0 &&
+ (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
+ _XRead32 (dpy, (long *) *prop, netbytes);
+ break;
+
+ default:
+ /*
+ * This part of the code should never be reached. If it is,
+ * the server sent back a property with an invalid format.
+ * This is a BadImplementation error.
+ */
+ {
+ /* sequence number stored above */
+ error.type = X_Error;
+ error.majorCode = X_GetProperty;
+ error.minorCode = 0;
+ error.errorCode = BadImplementation;
+ _XError(dpy, &error);
+ }
+ nbytes = netbytes = 0L;
+ break;
+ }
+ if (! *prop) {
+ _XEatData(dpy, (unsigned long) netbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(BadAlloc); /* not Success */
+ }
+ (*prop)[nbytes] = '\0';
+ }
+ *actual_type = reply.propertyType;
+ *actual_format = reply.format;
+ *nitems = reply.nItems;
+ *bytesafter = reply.bytesAfter;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(Success);
+}
+
diff --git a/libX11/src/GetSOwner.c b/libX11/src/GetSOwner.c
index 2c93f2bd2..a54816a84 100644
--- a/libX11/src/GetSOwner.c
+++ b/libX11/src/GetSOwner.c
@@ -1,46 +1,45 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Window XGetSelectionOwner(
- register Display *dpy,
- Atom selection)
-{
- xGetSelectionOwnerReply rep;
- register xResourceReq *req;
- LockDisplay(dpy);
- GetResReq(GetSelectionOwner, selection, req);
-
- if (_XReply(dpy, (xReply *)&rep, 0, xTrue) == 0) rep.owner = None;
- UnlockDisplay(dpy);
- SyncHandle();
- return(rep.owner);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Window XGetSelectionOwner(
+ register Display *dpy,
+ Atom selection)
+{
+ xGetSelectionOwnerReply rep;
+ register xResourceReq *req;
+ LockDisplay(dpy);
+ GetResReq(GetSelectionOwner, selection, req);
+
+ if (_XReply(dpy, (xReply *)&rep, 0, xTrue) == 0) rep.owner = None;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(rep.owner);
+}
diff --git a/libX11/src/GetSSaver.c b/libX11/src/GetSSaver.c
index f63b4fec5..dcd4c64bc 100644
--- a/libX11/src/GetSSaver.c
+++ b/libX11/src/GetSSaver.c
@@ -1,57 +1,56 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XGetScreenSaver(
- register Display *dpy,
- /* the following are return only vars */
- int *timeout,
- int *interval,
- int *prefer_blanking,
- int *allow_exp) /*boolean */
-
-{
- xGetScreenSaverReply rep;
- register xReq *req;
- LockDisplay(dpy);
- GetEmptyReq(GetScreenSaver, req);
-
- (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
- *timeout = rep.timeout;
- *interval = rep.interval;
- *prefer_blanking = rep.preferBlanking;
- *allow_exp = rep.allowExposures;
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XGetScreenSaver(
+ register Display *dpy,
+ /* the following are return only vars */
+ int *timeout,
+ int *interval,
+ int *prefer_blanking,
+ int *allow_exp) /*boolean */
+
+{
+ xGetScreenSaverReply rep;
+ register xReq *req;
+ LockDisplay(dpy);
+ GetEmptyReq(GetScreenSaver, req);
+
+ (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
+ *timeout = rep.timeout;
+ *interval = rep.interval;
+ *prefer_blanking = rep.preferBlanking;
+ *allow_exp = rep.allowExposures;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/GetWAttrs.c b/libX11/src/GetWAttrs.c
index b0af60b7f..874cb1b46 100644
--- a/libX11/src/GetWAttrs.c
+++ b/libX11/src/GetWAttrs.c
@@ -1,156 +1,155 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-typedef struct _WAttrsState {
- unsigned long attr_seq;
- unsigned long geom_seq;
- XWindowAttributes *attr;
-} _XWAttrsState;
-
-static Bool
-_XWAttrsHandler(
- register Display *dpy,
- register xReply *rep,
- char *buf,
- int len,
- XPointer data)
-{
- register _XWAttrsState *state;
- xGetWindowAttributesReply replbuf;
- register xGetWindowAttributesReply *repl;
- register XWindowAttributes *attr;
-
- state = (_XWAttrsState *)data;
- if (dpy->last_request_read != state->attr_seq) {
- if (dpy->last_request_read == state->geom_seq &&
- !state->attr &&
- rep->generic.type == X_Error &&
- rep->error.errorCode == BadDrawable)
- return True;
- return False;
- }
- if (rep->generic.type == X_Error) {
- state->attr = (XWindowAttributes *)NULL;
- return False;
- }
- repl = (xGetWindowAttributesReply *)
- _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
- (SIZEOF(xGetWindowAttributesReply) - SIZEOF(xReply)) >> 2,
- True);
- attr = state->attr;
- attr->class = repl->class;
- attr->bit_gravity = repl->bitGravity;
- attr->win_gravity = repl->winGravity;
- attr->backing_store = repl->backingStore;
- attr->backing_planes = repl->backingBitPlanes;
- attr->backing_pixel = repl->backingPixel;
- attr->save_under = repl->saveUnder;
- attr->colormap = repl->colormap;
- attr->map_installed = repl->mapInstalled;
- attr->map_state = repl->mapState;
- attr->all_event_masks = repl->allEventMasks;
- attr->your_event_mask = repl->yourEventMask;
- attr->do_not_propagate_mask = repl->doNotPropagateMask;
- attr->override_redirect = repl->override;
- attr->visual = _XVIDtoVisual (dpy, repl->visualID);
- return True;
-}
-
-Status
-_XGetWindowAttributes(
- register Display *dpy,
- Window w,
- XWindowAttributes *attr)
-{
- xGetGeometryReply rep;
- register xResourceReq *req;
- register int i;
- register Screen *sp;
- _XAsyncHandler async;
- _XWAttrsState async_state;
-
- GetResReq(GetWindowAttributes, w, req);
-
- async_state.attr_seq = dpy->request;
- async_state.geom_seq = 0;
- async_state.attr = attr;
- async.next = dpy->async_handlers;
- async.handler = _XWAttrsHandler;
- async.data = (XPointer)&async_state;
- dpy->async_handlers = &async;
-
- GetResReq(GetGeometry, w, req);
-
- async_state.geom_seq = dpy->request;
-
- if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
- DeqAsyncHandler(dpy, &async);
- return (0);
- }
- DeqAsyncHandler(dpy, &async);
- if (!async_state.attr) {
- return (0);
- }
- attr->x = cvtINT16toInt (rep.x);
- attr->y = cvtINT16toInt (rep.y);
- attr->width = rep.width;
- attr->height = rep.height;
- attr->border_width = rep.borderWidth;
- attr->depth = rep.depth;
- attr->root = rep.root;
- /* find correct screen so that applications find it easier.... */
- for (i = 0; i < dpy->nscreens; i++) {
- sp = &dpy->screens[i];
- if (sp->root == attr->root) {
- attr->screen = sp;
- break;
- }
- }
- return(1);
-}
-
-Status
-XGetWindowAttributes(
- Display *dpy,
- Window w,
- XWindowAttributes *attr)
-{
- Status ret;
-
- LockDisplay(dpy);
- ret = _XGetWindowAttributes(dpy, w, attr);
- UnlockDisplay(dpy);
- SyncHandle();
-
- return ret;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+typedef struct _WAttrsState {
+ unsigned long attr_seq;
+ unsigned long geom_seq;
+ XWindowAttributes *attr;
+} _XWAttrsState;
+
+static Bool
+_XWAttrsHandler(
+ register Display *dpy,
+ register xReply *rep,
+ char *buf,
+ int len,
+ XPointer data)
+{
+ register _XWAttrsState *state;
+ xGetWindowAttributesReply replbuf;
+ register xGetWindowAttributesReply *repl;
+ register XWindowAttributes *attr;
+
+ state = (_XWAttrsState *)data;
+ if (dpy->last_request_read != state->attr_seq) {
+ if (dpy->last_request_read == state->geom_seq &&
+ !state->attr &&
+ rep->generic.type == X_Error &&
+ rep->error.errorCode == BadDrawable)
+ return True;
+ return False;
+ }
+ if (rep->generic.type == X_Error) {
+ state->attr = (XWindowAttributes *)NULL;
+ return False;
+ }
+ repl = (xGetWindowAttributesReply *)
+ _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
+ (SIZEOF(xGetWindowAttributesReply) - SIZEOF(xReply)) >> 2,
+ True);
+ attr = state->attr;
+ attr->class = repl->class;
+ attr->bit_gravity = repl->bitGravity;
+ attr->win_gravity = repl->winGravity;
+ attr->backing_store = repl->backingStore;
+ attr->backing_planes = repl->backingBitPlanes;
+ attr->backing_pixel = repl->backingPixel;
+ attr->save_under = repl->saveUnder;
+ attr->colormap = repl->colormap;
+ attr->map_installed = repl->mapInstalled;
+ attr->map_state = repl->mapState;
+ attr->all_event_masks = repl->allEventMasks;
+ attr->your_event_mask = repl->yourEventMask;
+ attr->do_not_propagate_mask = repl->doNotPropagateMask;
+ attr->override_redirect = repl->override;
+ attr->visual = _XVIDtoVisual (dpy, repl->visualID);
+ return True;
+}
+
+Status
+_XGetWindowAttributes(
+ register Display *dpy,
+ Window w,
+ XWindowAttributes *attr)
+{
+ xGetGeometryReply rep;
+ register xResourceReq *req;
+ register int i;
+ register Screen *sp;
+ _XAsyncHandler async;
+ _XWAttrsState async_state;
+
+ GetResReq(GetWindowAttributes, w, req);
+
+ async_state.attr_seq = dpy->request;
+ async_state.geom_seq = 0;
+ async_state.attr = attr;
+ async.next = dpy->async_handlers;
+ async.handler = _XWAttrsHandler;
+ async.data = (XPointer)&async_state;
+ dpy->async_handlers = &async;
+
+ GetResReq(GetGeometry, w, req);
+
+ async_state.geom_seq = dpy->request;
+
+ if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
+ DeqAsyncHandler(dpy, &async);
+ return (0);
+ }
+ DeqAsyncHandler(dpy, &async);
+ if (!async_state.attr) {
+ return (0);
+ }
+ attr->x = cvtINT16toInt (rep.x);
+ attr->y = cvtINT16toInt (rep.y);
+ attr->width = rep.width;
+ attr->height = rep.height;
+ attr->border_width = rep.borderWidth;
+ attr->depth = rep.depth;
+ attr->root = rep.root;
+ /* find correct screen so that applications find it easier.... */
+ for (i = 0; i < dpy->nscreens; i++) {
+ sp = &dpy->screens[i];
+ if (sp->root == attr->root) {
+ attr->screen = sp;
+ break;
+ }
+ }
+ return(1);
+}
+
+Status
+XGetWindowAttributes(
+ Display *dpy,
+ Window w,
+ XWindowAttributes *attr)
+{
+ Status ret;
+
+ LockDisplay(dpy);
+ ret = _XGetWindowAttributes(dpy, w, attr);
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ return ret;
+}
+
diff --git a/libX11/src/GrKeybd.c b/libX11/src/GrKeybd.c
index f5d37a1de..c723450b7 100644
--- a/libX11/src/GrKeybd.c
+++ b/libX11/src/GrKeybd.c
@@ -1,59 +1,58 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-int XGrabKeyboard (
- register Display *dpy,
- Window window,
- Bool ownerEvents,
- int pointerMode,
- int keyboardMode,
- Time time)
-{
- xGrabKeyboardReply rep;
- register xGrabKeyboardReq *req;
- register int status;
- LockDisplay(dpy);
- GetReq(GrabKeyboard, req);
- req->grabWindow = window;
- req->ownerEvents = ownerEvents;
- req->pointerMode = pointerMode;
- req->keyboardMode = keyboardMode;
- req->time = time;
-
- /* if we ever return, suppress the error */
- if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0)
- rep.status = GrabSuccess;
- status = rep.status;
- UnlockDisplay(dpy);
- SyncHandle();
- return (status);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+int XGrabKeyboard (
+ register Display *dpy,
+ Window window,
+ Bool ownerEvents,
+ int pointerMode,
+ int keyboardMode,
+ Time time)
+{
+ xGrabKeyboardReply rep;
+ register xGrabKeyboardReq *req;
+ register int status;
+ LockDisplay(dpy);
+ GetReq(GrabKeyboard, req);
+ req->grabWindow = window;
+ req->ownerEvents = ownerEvents;
+ req->pointerMode = pointerMode;
+ req->keyboardMode = keyboardMode;
+ req->time = time;
+
+ /* if we ever return, suppress the error */
+ if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0)
+ rep.status = GrabSuccess;
+ status = rep.status;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (status);
+}
+
diff --git a/libX11/src/GrPointer.c b/libX11/src/GrPointer.c
index 08d0f287e..fc8922231 100644
--- a/libX11/src/GrPointer.c
+++ b/libX11/src/GrPointer.c
@@ -1,65 +1,64 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int XGrabPointer(
- register Display *dpy,
- Window grab_window,
- Bool owner_events,
- unsigned int event_mask, /* CARD16 */
- int pointer_mode,
- int keyboard_mode,
- Window confine_to,
- Cursor curs,
- Time time)
-{
- xGrabPointerReply rep;
- register xGrabPointerReq *req;
- register int status;
- LockDisplay(dpy);
- GetReq(GrabPointer, req);
- req->grabWindow = grab_window;
- req->ownerEvents = owner_events;
- req->eventMask = event_mask;
- req->pointerMode = pointer_mode;
- req->keyboardMode = keyboard_mode;
- req->confineTo = confine_to;
- req->cursor = curs;
- req->time = time;
-
- /* if we ever return, suppress the error */
- if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0)
- rep.status = GrabSuccess;
- status = rep.status;
- UnlockDisplay(dpy);
- SyncHandle();
- return (status);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int XGrabPointer(
+ register Display *dpy,
+ Window grab_window,
+ Bool owner_events,
+ unsigned int event_mask, /* CARD16 */
+ int pointer_mode,
+ int keyboard_mode,
+ Window confine_to,
+ Cursor curs,
+ Time time)
+{
+ xGrabPointerReply rep;
+ register xGrabPointerReq *req;
+ register int status;
+ LockDisplay(dpy);
+ GetReq(GrabPointer, req);
+ req->grabWindow = grab_window;
+ req->ownerEvents = owner_events;
+ req->eventMask = event_mask;
+ req->pointerMode = pointer_mode;
+ req->keyboardMode = keyboard_mode;
+ req->confineTo = confine_to;
+ req->cursor = curs;
+ req->time = time;
+
+ /* if we ever return, suppress the error */
+ if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0)
+ rep.status = GrabSuccess;
+ status = rep.status;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (status);
+}
diff --git a/libX11/src/Iconify.c b/libX11/src/Iconify.c
index 3831102a2..38bd00246 100644
--- a/libX11/src/Iconify.c
+++ b/libX11/src/Iconify.c
@@ -1,86 +1,85 @@
-
-/***********************************************************
-Copyright 1988 by Wyse Technology, Inc., San Jose, Ca.
-
- 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 Wyse not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-WYSE 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.
-
-******************************************************************/
-/*
-
-Copyright 1988, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-#include <X11/Xatom.h>
-#include <X11/Xos.h>
-#include <X11/Xutil.h>
-#include <stdio.h>
-
-/*
- * This function instructs the window manager to change this window from
- * NormalState to IconicState.
- */
-Status XIconifyWindow (
- Display *dpy,
- Window w,
- int screen)
-{
- XClientMessageEvent ev;
- Window root = RootWindow (dpy, screen);
- Atom prop;
-
- prop = XInternAtom (dpy, "WM_CHANGE_STATE", False);
- if (prop == None) return False;
-
- ev.type = ClientMessage;
- ev.window = w;
- ev.message_type = prop;
- ev.format = 32;
- ev.data.l[0] = IconicState;
- return (XSendEvent (dpy, root, False,
- SubstructureRedirectMask|SubstructureNotifyMask,
- (XEvent *)&ev));
-}
+
+/***********************************************************
+Copyright 1988 by Wyse Technology, Inc., San Jose, Ca.
+
+ 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 Wyse not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+WYSE 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.
+
+******************************************************************/
+/*
+
+Copyright 1988, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/Xatom.h>
+#include <X11/Xos.h>
+#include <X11/Xutil.h>
+#include <stdio.h>
+
+/*
+ * This function instructs the window manager to change this window from
+ * NormalState to IconicState.
+ */
+Status XIconifyWindow (
+ Display *dpy,
+ Window w,
+ int screen)
+{
+ XClientMessageEvent ev;
+ Window root = RootWindow (dpy, screen);
+ Atom prop;
+
+ prop = XInternAtom (dpy, "WM_CHANGE_STATE", False);
+ if (prop == None) return False;
+
+ ev.type = ClientMessage;
+ ev.window = w;
+ ev.message_type = prop;
+ ev.format = 32;
+ ev.data.l[0] = IconicState;
+ return (XSendEvent (dpy, root, False,
+ SubstructureRedirectMask|SubstructureNotifyMask,
+ (XEvent *)&ev));
+}
diff --git a/libX11/src/IfEvent.c b/libX11/src/IfEvent.c
index e22ee5dd9..546025062 100644
--- a/libX11/src/IfEvent.c
+++ b/libX11/src/IfEvent.c
@@ -1,74 +1,73 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * Flush output and (wait for and) return the next event matching the
- * predicate in the queue.
- */
-
-int
-XIfEvent (
- register Display *dpy,
- register XEvent *event,
- Bool (*predicate)(
- Display* /* display */,
- XEvent* /* event */,
- char* /* arg */
- ), /* function to call */
- char *arg)
-{
- register _XQEvent *qelt, *prev;
- unsigned long qe_serial = 0;
-
- LockDisplay(dpy);
- prev = NULL;
- while (1) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if(qelt->qserial_num > qe_serial
- && (*predicate)(dpy, &qelt->event, arg)) {
- *event = qelt->event;
- _XDeq(dpy, prev, qelt);
- _XStoreEventCookie(dpy, event);
- UnlockDisplay(dpy);
- return 0;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- _XReadEvents(dpy);
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * Flush output and (wait for and) return the next event matching the
+ * predicate in the queue.
+ */
+
+int
+XIfEvent (
+ register Display *dpy,
+ register XEvent *event,
+ Bool (*predicate)(
+ Display* /* display */,
+ XEvent* /* event */,
+ char* /* arg */
+ ), /* function to call */
+ char *arg)
+{
+ register _XQEvent *qelt, *prev;
+ unsigned long qe_serial = 0;
+
+ LockDisplay(dpy);
+ prev = NULL;
+ while (1) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if(qelt->qserial_num > qe_serial
+ && (*predicate)(dpy, &qelt->event, arg)) {
+ *event = qelt->event;
+ _XDeq(dpy, prev, qelt);
+ _XStoreEventCookie(dpy, event);
+ UnlockDisplay(dpy);
+ return 0;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ _XReadEvents(dpy);
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+}
diff --git a/libX11/src/ImText.c b/libX11/src/ImText.c
index bbdc8377a..434c682d9 100644
--- a/libX11/src/ImText.c
+++ b/libX11/src/ImText.c
@@ -1,102 +1,101 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XDrawImageString(
- register Display *dpy,
- Drawable d,
- GC gc,
- int x,
- int y,
- _Xconst char *string,
- int length)
-{
- register xImageText8Req *req;
- char *CharacterOffset = (char *)string;
- int FirstTimeThrough = True;
- int lastX = 0;
-
- LockDisplay(dpy);
- FlushGC(dpy, gc);
-
- while (length > 0)
- {
- int Unit;
-
- if (length > 255) Unit = 255;
- else Unit = length;
-
- if (FirstTimeThrough)
- {
- FirstTimeThrough = False;
- }
- else
- {
- char buf[512];
- char *ptr, *str;
- xQueryTextExtentsReq *qreq;
- xQueryTextExtentsReply rep;
- int i;
-
- GetReq(QueryTextExtents, qreq);
- qreq->fid = gc->gid;
- qreq->length += (510 + 3)>>2;
- qreq->oddLength = 1;
- str = CharacterOffset - 255;
- for (ptr = buf, i = 255; --i >= 0; ) {
- *ptr++ = 0;
- *ptr++ = *str++;
- }
- Data (dpy, buf, 510);
- if (!_XReply (dpy, (xReply *)&rep, 0, xTrue))
- break;
-
- x = lastX + cvtINT32toInt (rep.overallWidth);
- }
-
- GetReq (ImageText8, req);
- req->length += (Unit + 3) >> 2;
- req->nChars = Unit;
- req->drawable = d;
- req->gc = gc->gid;
- req->y = y;
-
- lastX = req->x = x;
- Data (dpy, CharacterOffset, (long)Unit);
- CharacterOffset += Unit;
- length -= Unit;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return 0;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XDrawImageString(
+ register Display *dpy,
+ Drawable d,
+ GC gc,
+ int x,
+ int y,
+ _Xconst char *string,
+ int length)
+{
+ register xImageText8Req *req;
+ char *CharacterOffset = (char *)string;
+ int FirstTimeThrough = True;
+ int lastX = 0;
+
+ LockDisplay(dpy);
+ FlushGC(dpy, gc);
+
+ while (length > 0)
+ {
+ int Unit;
+
+ if (length > 255) Unit = 255;
+ else Unit = length;
+
+ if (FirstTimeThrough)
+ {
+ FirstTimeThrough = False;
+ }
+ else
+ {
+ char buf[512];
+ char *ptr, *str;
+ xQueryTextExtentsReq *qreq;
+ xQueryTextExtentsReply rep;
+ int i;
+
+ GetReq(QueryTextExtents, qreq);
+ qreq->fid = gc->gid;
+ qreq->length += (510 + 3)>>2;
+ qreq->oddLength = 1;
+ str = CharacterOffset - 255;
+ for (ptr = buf, i = 255; --i >= 0; ) {
+ *ptr++ = 0;
+ *ptr++ = *str++;
+ }
+ Data (dpy, buf, 510);
+ if (!_XReply (dpy, (xReply *)&rep, 0, xTrue))
+ break;
+
+ x = lastX + cvtINT32toInt (rep.overallWidth);
+ }
+
+ GetReq (ImageText8, req);
+ req->length += (Unit + 3) >> 2;
+ req->nChars = Unit;
+ req->drawable = d;
+ req->gc = gc->gid;
+ req->y = y;
+
+ lastX = req->x = x;
+ Data (dpy, CharacterOffset, (long)Unit);
+ CharacterOffset += Unit;
+ length -= Unit;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+}
+
diff --git a/libX11/src/ImText16.c b/libX11/src/ImText16.c
index 3338ec78a..49859aa53 100644
--- a/libX11/src/ImText16.c
+++ b/libX11/src/ImText16.c
@@ -1,104 +1,103 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XDrawImageString16(
- register Display *dpy,
- Drawable d,
- GC gc,
- int x,
- int y,
- _Xconst XChar2b *string,
- int length)
-{
- register xImageText16Req *req;
- XChar2b *CharacterOffset = (XChar2b *)string;
- int FirstTimeThrough = True;
- int lastX = 0;
-
- LockDisplay(dpy);
- FlushGC(dpy, gc);
-
- while (length > 0)
- {
- int Unit, Datalength;
-
- if (length > 255) Unit = 255;
- else Unit = length;
-
- if (FirstTimeThrough)
- {
- FirstTimeThrough = False;
- }
- else
- {
- char buf[512];
- xQueryTextExtentsReq *qreq;
- xQueryTextExtentsReply rep;
- unsigned char *ptr;
- XChar2b *str;
- int i;
-
- GetReq(QueryTextExtents, qreq);
- qreq->fid = gc->gid;
- qreq->length += (510 + 3)>>2;
- qreq->oddLength = 1;
- str = CharacterOffset - 255;
- for (ptr = (unsigned char *)buf, i = 255; --i >= 0; str++) {
- *ptr++ = str->byte1;
- *ptr++ = str->byte2;
- }
- Data (dpy, buf, 510);
- if (!_XReply (dpy, (xReply *)&rep, 0, xTrue))
- break;
-
- x = lastX + cvtINT32toInt (rep.overallWidth);
- }
-
- GetReq (ImageText16, req);
- req->length += ((Unit << 1) + 3) >> 2;
- req->nChars = Unit;
- req->drawable = d;
- req->gc = gc->gid;
- req->y = y;
-
- lastX = req->x = x;
- Datalength = Unit << 1;
- Data (dpy, (char *)CharacterOffset, (long)Datalength);
- CharacterOffset += Unit;
- length -= Unit;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return 0;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XDrawImageString16(
+ register Display *dpy,
+ Drawable d,
+ GC gc,
+ int x,
+ int y,
+ _Xconst XChar2b *string,
+ int length)
+{
+ register xImageText16Req *req;
+ XChar2b *CharacterOffset = (XChar2b *)string;
+ int FirstTimeThrough = True;
+ int lastX = 0;
+
+ LockDisplay(dpy);
+ FlushGC(dpy, gc);
+
+ while (length > 0)
+ {
+ int Unit, Datalength;
+
+ if (length > 255) Unit = 255;
+ else Unit = length;
+
+ if (FirstTimeThrough)
+ {
+ FirstTimeThrough = False;
+ }
+ else
+ {
+ char buf[512];
+ xQueryTextExtentsReq *qreq;
+ xQueryTextExtentsReply rep;
+ unsigned char *ptr;
+ XChar2b *str;
+ int i;
+
+ GetReq(QueryTextExtents, qreq);
+ qreq->fid = gc->gid;
+ qreq->length += (510 + 3)>>2;
+ qreq->oddLength = 1;
+ str = CharacterOffset - 255;
+ for (ptr = (unsigned char *)buf, i = 255; --i >= 0; str++) {
+ *ptr++ = str->byte1;
+ *ptr++ = str->byte2;
+ }
+ Data (dpy, buf, 510);
+ if (!_XReply (dpy, (xReply *)&rep, 0, xTrue))
+ break;
+
+ x = lastX + cvtINT32toInt (rep.overallWidth);
+ }
+
+ GetReq (ImageText16, req);
+ req->length += ((Unit << 1) + 3) >> 2;
+ req->nChars = Unit;
+ req->drawable = d;
+ req->gc = gc->gid;
+ req->y = y;
+
+ lastX = req->x = x;
+ Datalength = Unit << 1;
+ Data (dpy, (char *)CharacterOffset, (long)Datalength);
+ CharacterOffset += Unit;
+ length -= Unit;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+}
+
diff --git a/libX11/src/IntAtom.c b/libX11/src/IntAtom.c
index 5763ed7c6..61a7f6d2f 100644
--- a/libX11/src/IntAtom.c
+++ b/libX11/src/IntAtom.c
@@ -1,298 +1,297 @@
-/*
-
-Copyright 1986, 1990, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xintatom.h"
-
-#define HASH(sig) ((sig) & (TABLESIZE-1))
-#define REHASHVAL(sig) ((((sig) % (TABLESIZE-3)) + 2) | 1)
-#define REHASH(idx,rehash) ((idx + rehash) & (TABLESIZE-1))
-
-void
-_XFreeAtomTable(Display *dpy)
-{
- register Entry *table;
- register int i;
- register Entry e;
-
- if (dpy->atoms) {
- table = dpy->atoms->table;
- for (i = TABLESIZE; --i >= 0; ) {
- if ((e = *table++) && (e != RESERVED))
- Xfree((char *)e);
- }
- Xfree((char *)dpy->atoms);
- }
-}
-
-static
-Atom _XInternAtom(
- Display *dpy,
- _Xconst char *name,
- Bool onlyIfExists,
- unsigned long *psig,
- int *pidx,
- int *pn)
-{
- register AtomTable *atoms;
- register char *s1, c, *s2;
- register unsigned long sig;
- register int idx = 0, i;
- Entry e;
- int n, firstidx, rehash = 0;
- xInternAtomReq *req;
-
- /* look in the cache first */
- if (!(atoms = dpy->atoms)) {
- dpy->atoms = atoms = (AtomTable *)Xcalloc(1, sizeof(AtomTable));
- dpy->free_funcs->atoms = _XFreeAtomTable;
- }
- sig = 0;
- for (s1 = (char *)name; (c = *s1++); )
- sig += c;
- n = s1 - (char *)name - 1;
- if (atoms) {
- firstidx = idx = HASH(sig);
- while ((e = atoms->table[idx])) {
- if (e != RESERVED && e->sig == sig) {
- for (i = n, s1 = (char *)name, s2 = EntryName(e); --i >= 0; ) {
- if (*s1++ != *s2++)
- goto nomatch;
- }
- if (!*s2)
- return e->atom;
- }
-nomatch: if (idx == firstidx)
- rehash = REHASHVAL(sig);
- idx = REHASH(idx, rehash);
- if (idx == firstidx)
- break;
- }
- }
- *psig = sig;
- *pidx = idx;
- if (atoms && !atoms->table[idx])
- atoms->table[idx] = RESERVED; /* reserve slot */
- *pn = n;
- /* not found, go to the server */
- GetReq(InternAtom, req);
- req->nbytes = n;
- req->onlyIfExists = onlyIfExists;
- req->length += (n+3)>>2;
- Data(dpy, name, n);
- return None;
-}
-
-void
-_XUpdateAtomCache(
- Display *dpy,
- const char *name,
- Atom atom,
- unsigned long sig,
- int idx,
- int n)
-{
- Entry e, oe;
- register char *s1;
- register char c;
- int firstidx, rehash;
-
- if (!dpy->atoms) {
- if (idx < 0) {
- dpy->atoms = (AtomTable *)Xcalloc(1, sizeof(AtomTable));
- dpy->free_funcs->atoms = _XFreeAtomTable;
- }
- if (!dpy->atoms)
- return;
- }
- if (!sig) {
- for (s1 = (char *)name; (c = *s1++); )
- sig += c;
- n = s1 - (char *)name - 1;
- if (idx < 0) {
- firstidx = idx = HASH(sig);
- if (dpy->atoms->table[idx]) {
- rehash = REHASHVAL(sig);
- do
- idx = REHASH(idx, rehash);
- while (idx != firstidx && dpy->atoms->table[idx]);
- }
- }
- }
- e = (Entry)Xmalloc(sizeof(EntryRec) + n + 1);
- if (e) {
- e->sig = sig;
- e->atom = atom;
- strcpy(EntryName(e), name);
- if ((oe = dpy->atoms->table[idx]) && (oe != RESERVED))
- Xfree((char *)oe);
- dpy->atoms->table[idx] = e;
- }
-}
-
-Atom
-XInternAtom (
- Display *dpy,
- const char *name,
- Bool onlyIfExists)
-{
- Atom atom;
- unsigned long sig;
- int idx, n;
- xInternAtomReply rep;
-
- if (!name)
- name = "";
- LockDisplay(dpy);
- if ((atom = _XInternAtom(dpy, name, onlyIfExists, &sig, &idx, &n))) {
- UnlockDisplay(dpy);
- return atom;
- }
- if (dpy->atoms && dpy->atoms->table[idx] == RESERVED)
- dpy->atoms->table[idx] = NULL; /* unreserve slot */
- if (_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
- if ((atom = rep.atom))
- _XUpdateAtomCache(dpy, name, atom, sig, idx, n);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return (rep.atom);
-}
-
-typedef struct {
- unsigned long start_seq;
- unsigned long stop_seq;
- char **names;
- Atom *atoms;
- int count;
- Status status;
-} _XIntAtomState;
-
-static
-Bool _XIntAtomHandler(
- register Display *dpy,
- register xReply *rep,
- char *buf,
- int len,
- XPointer data)
-{
- register _XIntAtomState *state;
- register int i, idx = 0;
- xInternAtomReply replbuf;
- register xInternAtomReply *repl;
-
- state = (_XIntAtomState *)data;
- if (dpy->last_request_read < state->start_seq ||
- dpy->last_request_read > state->stop_seq)
- return False;
- for (i = 0; i < state->count; i++) {
- if (state->atoms[i] & 0x80000000) {
- idx = ~state->atoms[i];
- state->atoms[i] = None;
- break;
- }
- }
- if (i >= state->count)
- return False;
- if (rep->generic.type == X_Error) {
- state->status = 0;
- return False;
- }
- repl = (xInternAtomReply *)
- _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
- (SIZEOF(xInternAtomReply) - SIZEOF(xReply)) >> 2,
- True);
- if ((state->atoms[i] = repl->atom))
- _XUpdateAtomCache(dpy, state->names[i], (Atom) repl->atom,
- (unsigned long)0, idx, 0);
- return True;
-}
-
-Status
-XInternAtoms (
- Display *dpy,
- char **names,
- int count,
- Bool onlyIfExists,
- Atom *atoms_return)
-{
- int i, idx, n, tidx;
- unsigned long sig;
- _XAsyncHandler async;
- _XIntAtomState async_state;
- int missed = -1;
- xInternAtomReply rep;
-
- LockDisplay(dpy);
- async_state.start_seq = dpy->request + 1;
- async_state.atoms = atoms_return;
- async_state.names = names;
- async_state.count = count - 1;
- async_state.status = 1;
- async.next = dpy->async_handlers;
- async.handler = _XIntAtomHandler;
- async.data = (XPointer)&async_state;
- dpy->async_handlers = &async;
- for (i = 0; i < count; i++) {
- if (!(atoms_return[i] = _XInternAtom(dpy, names[i], onlyIfExists,
- &sig, &idx, &n))) {
- missed = i;
- atoms_return[i] = ~((Atom)idx);
- async_state.stop_seq = dpy->request;
- }
- }
- if (missed >= 0) {
- if (dpy->atoms) {
- /* unreserve anything we just reserved */
- for (i = 0; i < count; i++) {
- if (atoms_return[i] & 0x80000000) {
- tidx = ~atoms_return[i];
- if (dpy->atoms->table[tidx] == RESERVED)
- dpy->atoms->table[tidx] = NULL;
- }
- }
- }
- if (_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
- if ((atoms_return[missed] = rep.atom))
- _XUpdateAtomCache(dpy, names[missed], (Atom) rep.atom,
- sig, idx, n);
- } else {
- atoms_return[missed] = None;
- async_state.status = 0;
- }
- }
- DeqAsyncHandler(dpy, &async);
- UnlockDisplay(dpy);
- if (missed >= 0)
- SyncHandle();
- return async_state.status;
-}
+/*
+
+Copyright 1986, 1990, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xintatom.h"
+
+#define HASH(sig) ((sig) & (TABLESIZE-1))
+#define REHASHVAL(sig) ((((sig) % (TABLESIZE-3)) + 2) | 1)
+#define REHASH(idx,rehash) ((idx + rehash) & (TABLESIZE-1))
+
+void
+_XFreeAtomTable(Display *dpy)
+{
+ register Entry *table;
+ register int i;
+ register Entry e;
+
+ if (dpy->atoms) {
+ table = dpy->atoms->table;
+ for (i = TABLESIZE; --i >= 0; ) {
+ if ((e = *table++) && (e != RESERVED))
+ Xfree((char *)e);
+ }
+ Xfree((char *)dpy->atoms);
+ }
+}
+
+static
+Atom _XInternAtom(
+ Display *dpy,
+ _Xconst char *name,
+ Bool onlyIfExists,
+ unsigned long *psig,
+ int *pidx,
+ int *pn)
+{
+ register AtomTable *atoms;
+ register char *s1, c, *s2;
+ register unsigned long sig;
+ register int idx = 0, i;
+ Entry e;
+ int n, firstidx, rehash = 0;
+ xInternAtomReq *req;
+
+ /* look in the cache first */
+ if (!(atoms = dpy->atoms)) {
+ dpy->atoms = atoms = (AtomTable *)Xcalloc(1, sizeof(AtomTable));
+ dpy->free_funcs->atoms = _XFreeAtomTable;
+ }
+ sig = 0;
+ for (s1 = (char *)name; (c = *s1++); )
+ sig += c;
+ n = s1 - (char *)name - 1;
+ if (atoms) {
+ firstidx = idx = HASH(sig);
+ while ((e = atoms->table[idx])) {
+ if (e != RESERVED && e->sig == sig) {
+ for (i = n, s1 = (char *)name, s2 = EntryName(e); --i >= 0; ) {
+ if (*s1++ != *s2++)
+ goto nomatch;
+ }
+ if (!*s2)
+ return e->atom;
+ }
+nomatch: if (idx == firstidx)
+ rehash = REHASHVAL(sig);
+ idx = REHASH(idx, rehash);
+ if (idx == firstidx)
+ break;
+ }
+ }
+ *psig = sig;
+ *pidx = idx;
+ if (atoms && !atoms->table[idx])
+ atoms->table[idx] = RESERVED; /* reserve slot */
+ *pn = n;
+ /* not found, go to the server */
+ GetReq(InternAtom, req);
+ req->nbytes = n;
+ req->onlyIfExists = onlyIfExists;
+ req->length += (n+3)>>2;
+ Data(dpy, name, n);
+ return None;
+}
+
+void
+_XUpdateAtomCache(
+ Display *dpy,
+ const char *name,
+ Atom atom,
+ unsigned long sig,
+ int idx,
+ int n)
+{
+ Entry e, oe;
+ register char *s1;
+ register char c;
+ int firstidx, rehash;
+
+ if (!dpy->atoms) {
+ if (idx < 0) {
+ dpy->atoms = (AtomTable *)Xcalloc(1, sizeof(AtomTable));
+ dpy->free_funcs->atoms = _XFreeAtomTable;
+ }
+ if (!dpy->atoms)
+ return;
+ }
+ if (!sig) {
+ for (s1 = (char *)name; (c = *s1++); )
+ sig += c;
+ n = s1 - (char *)name - 1;
+ if (idx < 0) {
+ firstidx = idx = HASH(sig);
+ if (dpy->atoms->table[idx]) {
+ rehash = REHASHVAL(sig);
+ do
+ idx = REHASH(idx, rehash);
+ while (idx != firstidx && dpy->atoms->table[idx]);
+ }
+ }
+ }
+ e = (Entry)Xmalloc(sizeof(EntryRec) + n + 1);
+ if (e) {
+ e->sig = sig;
+ e->atom = atom;
+ strcpy(EntryName(e), name);
+ if ((oe = dpy->atoms->table[idx]) && (oe != RESERVED))
+ Xfree((char *)oe);
+ dpy->atoms->table[idx] = e;
+ }
+}
+
+Atom
+XInternAtom (
+ Display *dpy,
+ const char *name,
+ Bool onlyIfExists)
+{
+ Atom atom;
+ unsigned long sig;
+ int idx, n;
+ xInternAtomReply rep;
+
+ if (!name)
+ name = "";
+ LockDisplay(dpy);
+ if ((atom = _XInternAtom(dpy, name, onlyIfExists, &sig, &idx, &n))) {
+ UnlockDisplay(dpy);
+ return atom;
+ }
+ if (dpy->atoms && dpy->atoms->table[idx] == RESERVED)
+ dpy->atoms->table[idx] = NULL; /* unreserve slot */
+ if (_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
+ if ((atom = rep.atom))
+ _XUpdateAtomCache(dpy, name, atom, sig, idx, n);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (rep.atom);
+}
+
+typedef struct {
+ unsigned long start_seq;
+ unsigned long stop_seq;
+ char **names;
+ Atom *atoms;
+ int count;
+ Status status;
+} _XIntAtomState;
+
+static
+Bool _XIntAtomHandler(
+ register Display *dpy,
+ register xReply *rep,
+ char *buf,
+ int len,
+ XPointer data)
+{
+ register _XIntAtomState *state;
+ register int i, idx = 0;
+ xInternAtomReply replbuf;
+ register xInternAtomReply *repl;
+
+ state = (_XIntAtomState *)data;
+ if (dpy->last_request_read < state->start_seq ||
+ dpy->last_request_read > state->stop_seq)
+ return False;
+ for (i = 0; i < state->count; i++) {
+ if (state->atoms[i] & 0x80000000) {
+ idx = ~state->atoms[i];
+ state->atoms[i] = None;
+ break;
+ }
+ }
+ if (i >= state->count)
+ return False;
+ if (rep->generic.type == X_Error) {
+ state->status = 0;
+ return False;
+ }
+ repl = (xInternAtomReply *)
+ _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
+ (SIZEOF(xInternAtomReply) - SIZEOF(xReply)) >> 2,
+ True);
+ if ((state->atoms[i] = repl->atom))
+ _XUpdateAtomCache(dpy, state->names[i], (Atom) repl->atom,
+ (unsigned long)0, idx, 0);
+ return True;
+}
+
+Status
+XInternAtoms (
+ Display *dpy,
+ char **names,
+ int count,
+ Bool onlyIfExists,
+ Atom *atoms_return)
+{
+ int i, idx, n, tidx;
+ unsigned long sig;
+ _XAsyncHandler async;
+ _XIntAtomState async_state;
+ int missed = -1;
+ xInternAtomReply rep;
+
+ LockDisplay(dpy);
+ async_state.start_seq = dpy->request + 1;
+ async_state.atoms = atoms_return;
+ async_state.names = names;
+ async_state.count = count - 1;
+ async_state.status = 1;
+ async.next = dpy->async_handlers;
+ async.handler = _XIntAtomHandler;
+ async.data = (XPointer)&async_state;
+ dpy->async_handlers = &async;
+ for (i = 0; i < count; i++) {
+ if (!(atoms_return[i] = _XInternAtom(dpy, names[i], onlyIfExists,
+ &sig, &idx, &n))) {
+ missed = i;
+ atoms_return[i] = ~((Atom)idx);
+ async_state.stop_seq = dpy->request;
+ }
+ }
+ if (missed >= 0) {
+ if (dpy->atoms) {
+ /* unreserve anything we just reserved */
+ for (i = 0; i < count; i++) {
+ if (atoms_return[i] & 0x80000000) {
+ tidx = ~atoms_return[i];
+ if (dpy->atoms->table[tidx] == RESERVED)
+ dpy->atoms->table[tidx] = NULL;
+ }
+ }
+ }
+ if (_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
+ if ((atoms_return[missed] = rep.atom))
+ _XUpdateAtomCache(dpy, names[missed], (Atom) rep.atom,
+ sig, idx, n);
+ } else {
+ atoms_return[missed] = None;
+ async_state.status = 0;
+ }
+ }
+ DeqAsyncHandler(dpy, &async);
+ UnlockDisplay(dpy);
+ if (missed >= 0)
+ SyncHandle();
+ return async_state.status;
+}
diff --git a/libX11/src/KeyBind.c b/libX11/src/KeyBind.c
index 2bf2cb294..cc1906fad 100644
--- a/libX11/src/KeyBind.c
+++ b/libX11/src/KeyBind.c
@@ -1,1078 +1,1077 @@
-/*
-
-Copyright 1985, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/* Beware, here be monsters (still under construction... - JG */
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-#include <X11/Xutil.h>
-#define XK_MISCELLANY
-#define XK_LATIN1
-#define XK_LATIN2
-#define XK_LATIN3
-#define XK_LATIN4
-#define XK_LATIN8
-#define XK_LATIN9
-#define XK_CYRILLIC
-#define XK_GREEK
-#define XK_ARMENIAN
-#define XK_CAUCASUS
-#define XK_VIETNAMESE
-#define XK_XKB_KEYS
-#include <X11/keysymdef.h>
-#include <stdio.h>
-
-#ifdef USE_OWN_COMPOSE
-#include "imComp.h"
-
-#endif
-
-#include "Xresource.h"
-#include "Key.h"
-
-#ifdef XKB
-#include "XKBlib.h"
-#include "XKBlibint.h"
-#define XKeycodeToKeysym _XKeycodeToKeysym
-#define XKeysymToKeycode _XKeysymToKeycode
-#define XLookupKeysym _XLookupKeysym
-#define XRefreshKeyboardMapping _XRefreshKeyboardMapping
-#define XLookupString _XLookupString
-/* XKBBind.c */
-#else
-#define XkbKeysymToModifiers _XKeysymToModifiers
-#endif
-
-#define AllMods (ShiftMask|LockMask|ControlMask| \
- Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)
-
-static void
-ComputeMaskFromKeytrans(
- Display *dpy,
- register struct _XKeytrans *p);
-
-struct _XKeytrans {
- struct _XKeytrans *next;/* next on list */
- char *string; /* string to return when the time comes */
- int len; /* length of string (since NULL is legit)*/
- KeySym key; /* keysym rebound */
- unsigned int state; /* modifier state */
- KeySym *modifiers; /* modifier keysyms you want */
- int mlen; /* length of modifier list */
-};
-
-static KeySym
-KeyCodetoKeySym(register Display *dpy, KeyCode keycode, int col)
-{
- register int per = dpy->keysyms_per_keycode;
- register KeySym *syms;
- KeySym lsym, usym;
-
- if ((col < 0) || ((col >= per) && (col > 3)) ||
- ((int)keycode < dpy->min_keycode) || ((int)keycode > dpy->max_keycode))
- return NoSymbol;
-
- syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
- if (col < 4) {
- if (col > 1) {
- while ((per > 2) && (syms[per - 1] == NoSymbol))
- per--;
- if (per < 3)
- col -= 2;
- }
- if ((per <= (col|1)) || (syms[col|1] == NoSymbol)) {
- XConvertCase(syms[col&~1], &lsym, &usym);
- if (!(col & 1))
- return lsym;
- else if (usym == lsym)
- return NoSymbol;
- else
- return usym;
- }
- }
- return syms[col];
-}
-
-KeySym
-XKeycodeToKeysym(Display *dpy,
-#if NeedWidePrototypes
- unsigned int kc,
-#else
- KeyCode kc,
-#endif
- int col)
-{
- if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
- return NoSymbol;
- return KeyCodetoKeySym(dpy, kc, col);
-}
-
-KeyCode
-XKeysymToKeycode(
- Display *dpy,
- KeySym ks)
-{
- register int i, j;
-
- if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
- return (KeyCode) 0;
- for (j = 0; j < dpy->keysyms_per_keycode; j++) {
- for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) {
- if (KeyCodetoKeySym(dpy, (KeyCode) i, j) == ks)
- return i;
- }
- }
- return 0;
-}
-
-KeySym
-XLookupKeysym(
- register XKeyEvent *event,
- int col)
-{
- if ((! event->display->keysyms) && (! _XKeyInitialize(event->display)))
- return NoSymbol;
- return KeyCodetoKeySym(event->display, event->keycode, col);
-}
-
-static void
-ResetModMap(
- Display *dpy)
-{
- register XModifierKeymap *map;
- register int i, j, n;
- KeySym sym;
- register struct _XKeytrans *p;
-
- map = dpy->modifiermap;
- /* If any Lock key contains Caps_Lock, then interpret as Caps_Lock,
- * else if any contains Shift_Lock, then interpret as Shift_Lock,
- * else ignore Lock altogether.
- */
- dpy->lock_meaning = NoSymbol;
- /* Lock modifiers are in the second row of the matrix */
- n = 2 * map->max_keypermod;
- for (i = map->max_keypermod; i < n; i++) {
- for (j = 0; j < dpy->keysyms_per_keycode; j++) {
- sym = KeyCodetoKeySym(dpy, map->modifiermap[i], j);
- if (sym == XK_Caps_Lock) {
- dpy->lock_meaning = XK_Caps_Lock;
- break;
- } else if (sym == XK_Shift_Lock) {
- dpy->lock_meaning = XK_Shift_Lock;
- }
- else if (sym == XK_ISO_Lock) {
- dpy->lock_meaning = XK_Caps_Lock;
- break;
- }
- }
- }
- /* Now find any Mod<n> modifier acting as the Group or Numlock modifier */
- dpy->mode_switch = 0;
- dpy->num_lock = 0;
- n *= 4;
- for (i = 3*map->max_keypermod; i < n; i++) {
- for (j = 0; j < dpy->keysyms_per_keycode; j++) {
- sym = KeyCodetoKeySym(dpy, map->modifiermap[i], j);
- if (sym == XK_Mode_switch)
- dpy->mode_switch |= 1 << (i / map->max_keypermod);
- if (sym == XK_Num_Lock)
- dpy->num_lock |= 1 << (i / map->max_keypermod);
- }
- }
- for (p = dpy->key_bindings; p; p = p->next)
- ComputeMaskFromKeytrans(dpy, p);
-}
-
-static int
-InitModMap(
- Display *dpy)
-{
- register XModifierKeymap *map;
-
- if (! (map = XGetModifierMapping(dpy)))
- return 0;
- LockDisplay(dpy);
- if (dpy->modifiermap)
- XFreeModifiermap(dpy->modifiermap);
- dpy->modifiermap = map;
- dpy->free_funcs->modifiermap = XFreeModifiermap;
- if (dpy->keysyms)
- ResetModMap(dpy);
- UnlockDisplay(dpy);
- return 1;
-}
-
-int
-XRefreshKeyboardMapping(register XMappingEvent *event)
-{
-
- if(event->request == MappingKeyboard) {
- /* XXX should really only refresh what is necessary
- * for now, make initialize test fail
- */
- LockDisplay(event->display);
- if (event->display->keysyms) {
- Xfree ((char *)event->display->keysyms);
- event->display->keysyms = NULL;
- }
- UnlockDisplay(event->display);
- }
- if(event->request == MappingModifier) {
- LockDisplay(event->display);
- if (event->display->modifiermap) {
- XFreeModifiermap(event->display->modifiermap);
- event->display->modifiermap = NULL;
- }
- UnlockDisplay(event->display);
- /* go ahead and get it now, since initialize test may not fail */
- if (event->display->keysyms)
- (void) InitModMap(event->display);
- }
- return 1;
-}
-
-int
-_XKeyInitialize(
- Display *dpy)
-{
- int per, n;
- KeySym *keysyms;
-
- /*
- * lets go get the keysyms from the server.
- */
- if (!dpy->keysyms) {
- n = dpy->max_keycode - dpy->min_keycode + 1;
- keysyms = XGetKeyboardMapping (dpy, (KeyCode) dpy->min_keycode,
- n, &per);
- /* keysyms may be NULL */
- if (! keysyms) return 0;
-
- LockDisplay(dpy);
- if (dpy->keysyms)
- Xfree ((char *)dpy->keysyms);
- dpy->keysyms = keysyms;
- dpy->keysyms_per_keycode = per;
- if (dpy->modifiermap)
- ResetModMap(dpy);
- UnlockDisplay(dpy);
- }
- if (!dpy->modifiermap)
- return InitModMap(dpy);
- return 1;
-}
-
-static void
-UCSConvertCase( register unsigned code,
- KeySym *lower,
- KeySym *upper )
-{
- /* Case conversion for UCS, as in Unicode Data version 4.0.0 */
- /* NB: Only converts simple one-to-one mappings. */
-
- /* Tables are used where they take less space than */
- /* the code to work out the mappings. Zero values mean */
- /* undefined code points. */
-
- static unsigned short const IPAExt_upper_mapping[] = { /* part only */
- 0x0181, 0x0186, 0x0255, 0x0189, 0x018A,
- 0x0258, 0x018F, 0x025A, 0x0190, 0x025C, 0x025D, 0x025E, 0x025F,
- 0x0193, 0x0261, 0x0262, 0x0194, 0x0264, 0x0265, 0x0266, 0x0267,
- 0x0197, 0x0196, 0x026A, 0x026B, 0x026C, 0x026D, 0x026E, 0x019C,
- 0x0270, 0x0271, 0x019D, 0x0273, 0x0274, 0x019F, 0x0276, 0x0277,
- 0x0278, 0x0279, 0x027A, 0x027B, 0x027C, 0x027D, 0x027E, 0x027F,
- 0x01A6, 0x0281, 0x0282, 0x01A9, 0x0284, 0x0285, 0x0286, 0x0287,
- 0x01AE, 0x0289, 0x01B1, 0x01B2, 0x028C, 0x028D, 0x028E, 0x028F,
- 0x0290, 0x0291, 0x01B7
- };
-
- static unsigned short const LatinExtB_upper_mapping[] = { /* first part only */
- 0x0180, 0x0181, 0x0182, 0x0182, 0x0184, 0x0184, 0x0186, 0x0187,
- 0x0187, 0x0189, 0x018A, 0x018B, 0x018B, 0x018D, 0x018E, 0x018F,
- 0x0190, 0x0191, 0x0191, 0x0193, 0x0194, 0x01F6, 0x0196, 0x0197,
- 0x0198, 0x0198, 0x019A, 0x019B, 0x019C, 0x019D, 0x0220, 0x019F,
- 0x01A0, 0x01A0, 0x01A2, 0x01A2, 0x01A4, 0x01A4, 0x01A6, 0x01A7,
- 0x01A7, 0x01A9, 0x01AA, 0x01AB, 0x01AC, 0x01AC, 0x01AE, 0x01AF,
- 0x01AF, 0x01B1, 0x01B2, 0x01B3, 0x01B3, 0x01B5, 0x01B5, 0x01B7,
- 0x01B8, 0x01B8, 0x01BA, 0x01BB, 0x01BC, 0x01BC, 0x01BE, 0x01F7,
- 0x01C0, 0x01C1, 0x01C2, 0x01C3, 0x01C4, 0x01C4, 0x01C4, 0x01C7,
- 0x01C7, 0x01C7, 0x01CA, 0x01CA, 0x01CA
- };
-
- static unsigned short const LatinExtB_lower_mapping[] = { /* first part only */
- 0x0180, 0x0253, 0x0183, 0x0183, 0x0185, 0x0185, 0x0254, 0x0188,
- 0x0188, 0x0256, 0x0257, 0x018C, 0x018C, 0x018D, 0x01DD, 0x0259,
- 0x025B, 0x0192, 0x0192, 0x0260, 0x0263, 0x0195, 0x0269, 0x0268,
- 0x0199, 0x0199, 0x019A, 0x019B, 0x026F, 0x0272, 0x019E, 0x0275,
- 0x01A1, 0x01A1, 0x01A3, 0x01A3, 0x01A5, 0x01A5, 0x0280, 0x01A8,
- 0x01A8, 0x0283, 0x01AA, 0x01AB, 0x01AD, 0x01AD, 0x0288, 0x01B0,
- 0x01B0, 0x028A, 0x028B, 0x01B4, 0x01B4, 0x01B6, 0x01B6, 0x0292,
- 0x01B9, 0x01B9, 0x01BA, 0x01BB, 0x01BD, 0x01BD, 0x01BE, 0x01BF,
- 0x01C0, 0x01C1, 0x01C2, 0x01C3, 0x01C6, 0x01C6, 0x01C6, 0x01C9,
- 0x01C9, 0x01C9, 0x01CC, 0x01CC, 0x01CC
- };
-
- static unsigned short const Greek_upper_mapping[] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0374, 0x0375, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x037A, 0x0000, 0x0000, 0x0000, 0x037E, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0384, 0x0385, 0x0386, 0x0387,
- 0x0388, 0x0389, 0x038A, 0x0000, 0x038C, 0x0000, 0x038E, 0x038F,
- 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
- 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
- 0x03A0, 0x03A1, 0x0000, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
- 0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x0386, 0x0388, 0x0389, 0x038A,
- 0x03B0, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
- 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
- 0x03A0, 0x03A1, 0x03A3, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
- 0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x038C, 0x038E, 0x038F, 0x0000,
- 0x0392, 0x0398, 0x03D2, 0x03D3, 0x03D4, 0x03A6, 0x03A0, 0x03D7,
- 0x03D8, 0x03D8, 0x03DA, 0x03DA, 0x03DC, 0x03DC, 0x03DE, 0x03DE,
- 0x03E0, 0x03E0, 0x03E2, 0x03E2, 0x03E4, 0x03E4, 0x03E6, 0x03E6,
- 0x03E8, 0x03E8, 0x03EA, 0x03EA, 0x03EC, 0x03EC, 0x03EE, 0x03EE,
- 0x039A, 0x03A1, 0x03F9, 0x03F3, 0x03F4, 0x0395, 0x03F6, 0x03F7,
- 0x03F7, 0x03F9, 0x03FA, 0x03FA, 0x0000, 0x0000, 0x0000, 0x0000
- };
-
- static unsigned short const Greek_lower_mapping[] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0374, 0x0375, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x037A, 0x0000, 0x0000, 0x0000, 0x037E, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0384, 0x0385, 0x03AC, 0x0387,
- 0x03AD, 0x03AE, 0x03AF, 0x0000, 0x03CC, 0x0000, 0x03CD, 0x03CE,
- 0x0390, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
- 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
- 0x03C0, 0x03C1, 0x0000, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
- 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
- 0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
- 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
- 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
- 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0000,
- 0x03D0, 0x03D1, 0x03D2, 0x03D3, 0x03D4, 0x03D5, 0x03D6, 0x03D7,
- 0x03D9, 0x03D9, 0x03DB, 0x03DB, 0x03DD, 0x03DD, 0x03DF, 0x03DF,
- 0x03E1, 0x03E1, 0x03E3, 0x03E3, 0x03E5, 0x03E5, 0x03E7, 0x03E7,
- 0x03E9, 0x03E9, 0x03EB, 0x03EB, 0x03ED, 0x03ED, 0x03EF, 0x03EF,
- 0x03F0, 0x03F1, 0x03F2, 0x03F3, 0x03B8, 0x03F5, 0x03F6, 0x03F8,
- 0x03F8, 0x03F2, 0x03FB, 0x03FB, 0x0000, 0x0000, 0x0000, 0x0000
- };
-
- static unsigned short const GreekExt_lower_mapping[] = {
- 0x1F00, 0x1F01, 0x1F02, 0x1F03, 0x1F04, 0x1F05, 0x1F06, 0x1F07,
- 0x1F00, 0x1F01, 0x1F02, 0x1F03, 0x1F04, 0x1F05, 0x1F06, 0x1F07,
- 0x1F10, 0x1F11, 0x1F12, 0x1F13, 0x1F14, 0x1F15, 0x0000, 0x0000,
- 0x1F10, 0x1F11, 0x1F12, 0x1F13, 0x1F14, 0x1F15, 0x0000, 0x0000,
- 0x1F20, 0x1F21, 0x1F22, 0x1F23, 0x1F24, 0x1F25, 0x1F26, 0x1F27,
- 0x1F20, 0x1F21, 0x1F22, 0x1F23, 0x1F24, 0x1F25, 0x1F26, 0x1F27,
- 0x1F30, 0x1F31, 0x1F32, 0x1F33, 0x1F34, 0x1F35, 0x1F36, 0x1F37,
- 0x1F30, 0x1F31, 0x1F32, 0x1F33, 0x1F34, 0x1F35, 0x1F36, 0x1F37,
- 0x1F40, 0x1F41, 0x1F42, 0x1F43, 0x1F44, 0x1F45, 0x0000, 0x0000,
- 0x1F40, 0x1F41, 0x1F42, 0x1F43, 0x1F44, 0x1F45, 0x0000, 0x0000,
- 0x1F50, 0x1F51, 0x1F52, 0x1F53, 0x1F54, 0x1F55, 0x1F56, 0x1F57,
- 0x0000, 0x1F51, 0x0000, 0x1F53, 0x0000, 0x1F55, 0x0000, 0x1F57,
- 0x1F60, 0x1F61, 0x1F62, 0x1F63, 0x1F64, 0x1F65, 0x1F66, 0x1F67,
- 0x1F60, 0x1F61, 0x1F62, 0x1F63, 0x1F64, 0x1F65, 0x1F66, 0x1F67,
- 0x1F70, 0x1F71, 0x1F72, 0x1F73, 0x1F74, 0x1F75, 0x1F76, 0x1F77,
- 0x1F78, 0x1F79, 0x1F7A, 0x1F7B, 0x1F7C, 0x1F7D, 0x0000, 0x0000,
- 0x1F80, 0x1F81, 0x1F82, 0x1F83, 0x1F84, 0x1F85, 0x1F86, 0x1F87,
- 0x1F80, 0x1F81, 0x1F82, 0x1F83, 0x1F84, 0x1F85, 0x1F86, 0x1F87,
- 0x1F90, 0x1F91, 0x1F92, 0x1F93, 0x1F94, 0x1F95, 0x1F96, 0x1F97,
- 0x1F90, 0x1F91, 0x1F92, 0x1F93, 0x1F94, 0x1F95, 0x1F96, 0x1F97,
- 0x1FA0, 0x1FA1, 0x1FA2, 0x1FA3, 0x1FA4, 0x1FA5, 0x1FA6, 0x1FA7,
- 0x1FA0, 0x1FA1, 0x1FA2, 0x1FA3, 0x1FA4, 0x1FA5, 0x1FA6, 0x1FA7,
- 0x1FB0, 0x1FB1, 0x1FB2, 0x1FB3, 0x1FB4, 0x0000, 0x1FB6, 0x1FB7,
- 0x1FB0, 0x1FB1, 0x1F70, 0x1F71, 0x1FB3, 0x1FBD, 0x1FBE, 0x1FBF,
- 0x1FC0, 0x1FC1, 0x1FC2, 0x1FC3, 0x1FC4, 0x0000, 0x1FC6, 0x1FC7,
- 0x1F72, 0x1F73, 0x1F74, 0x1F75, 0x1FC3, 0x1FCD, 0x1FCE, 0x1FCF,
- 0x1FD0, 0x1FD1, 0x1FD2, 0x1FD3, 0x0000, 0x0000, 0x1FD6, 0x1FD7,
- 0x1FD0, 0x1FD1, 0x1F76, 0x1F77, 0x0000, 0x1FDD, 0x1FDE, 0x1FDF,
- 0x1FE0, 0x1FE1, 0x1FE2, 0x1FE3, 0x1FE4, 0x1FE5, 0x1FE6, 0x1FE7,
- 0x1FE0, 0x1FE1, 0x1F7A, 0x1F7B, 0x1FE5, 0x1FED, 0x1FEE, 0x1FEF,
- 0x0000, 0x0000, 0x1FF2, 0x1FF3, 0x1FF4, 0x0000, 0x1FF6, 0x1FF7,
- 0x1F78, 0x1F79, 0x1F7C, 0x1F7D, 0x1FF3, 0x1FFD, 0x1FFE, 0x0000
- };
-
- static unsigned short const GreekExt_upper_mapping[] = {
- 0x1F08, 0x1F09, 0x1F0A, 0x1F0B, 0x1F0C, 0x1F0D, 0x1F0E, 0x1F0F,
- 0x1F08, 0x1F09, 0x1F0A, 0x1F0B, 0x1F0C, 0x1F0D, 0x1F0E, 0x1F0F,
- 0x1F18, 0x1F19, 0x1F1A, 0x1F1B, 0x1F1C, 0x1F1D, 0x0000, 0x0000,
- 0x1F18, 0x1F19, 0x1F1A, 0x1F1B, 0x1F1C, 0x1F1D, 0x0000, 0x0000,
- 0x1F28, 0x1F29, 0x1F2A, 0x1F2B, 0x1F2C, 0x1F2D, 0x1F2E, 0x1F2F,
- 0x1F28, 0x1F29, 0x1F2A, 0x1F2B, 0x1F2C, 0x1F2D, 0x1F2E, 0x1F2F,
- 0x1F38, 0x1F39, 0x1F3A, 0x1F3B, 0x1F3C, 0x1F3D, 0x1F3E, 0x1F3F,
- 0x1F38, 0x1F39, 0x1F3A, 0x1F3B, 0x1F3C, 0x1F3D, 0x1F3E, 0x1F3F,
- 0x1F48, 0x1F49, 0x1F4A, 0x1F4B, 0x1F4C, 0x1F4D, 0x0000, 0x0000,
- 0x1F48, 0x1F49, 0x1F4A, 0x1F4B, 0x1F4C, 0x1F4D, 0x0000, 0x0000,
- 0x1F50, 0x1F59, 0x1F52, 0x1F5B, 0x1F54, 0x1F5D, 0x1F56, 0x1F5F,
- 0x0000, 0x1F59, 0x0000, 0x1F5B, 0x0000, 0x1F5D, 0x0000, 0x1F5F,
- 0x1F68, 0x1F69, 0x1F6A, 0x1F6B, 0x1F6C, 0x1F6D, 0x1F6E, 0x1F6F,
- 0x1F68, 0x1F69, 0x1F6A, 0x1F6B, 0x1F6C, 0x1F6D, 0x1F6E, 0x1F6F,
- 0x1FBA, 0x1FBB, 0x1FC8, 0x1FC9, 0x1FCA, 0x1FCB, 0x1FDA, 0x1FDB,
- 0x1FF8, 0x1FF9, 0x1FEA, 0x1FEB, 0x1FFA, 0x1FFB, 0x0000, 0x0000,
- 0x1F88, 0x1F89, 0x1F8A, 0x1F8B, 0x1F8C, 0x1F8D, 0x1F8E, 0x1F8F,
- 0x1F88, 0x1F89, 0x1F8A, 0x1F8B, 0x1F8C, 0x1F8D, 0x1F8E, 0x1F8F,
- 0x1F98, 0x1F99, 0x1F9A, 0x1F9B, 0x1F9C, 0x1F9D, 0x1F9E, 0x1F9F,
- 0x1F98, 0x1F99, 0x1F9A, 0x1F9B, 0x1F9C, 0x1F9D, 0x1F9E, 0x1F9F,
- 0x1FA8, 0x1FA9, 0x1FAA, 0x1FAB, 0x1FAC, 0x1FAD, 0x1FAE, 0x1FAF,
- 0x1FA8, 0x1FA9, 0x1FAA, 0x1FAB, 0x1FAC, 0x1FAD, 0x1FAE, 0x1FAF,
- 0x1FB8, 0x1FB9, 0x1FB2, 0x1FBC, 0x1FB4, 0x0000, 0x1FB6, 0x1FB7,
- 0x1FB8, 0x1FB9, 0x1FBA, 0x1FBB, 0x1FBC, 0x1FBD, 0x0399, 0x1FBF,
- 0x1FC0, 0x1FC1, 0x1FC2, 0x1FCC, 0x1FC4, 0x0000, 0x1FC6, 0x1FC7,
- 0x1FC8, 0x1FC9, 0x1FCA, 0x1FCB, 0x1FCC, 0x1FCD, 0x1FCE, 0x1FCF,
- 0x1FD8, 0x1FD9, 0x1FD2, 0x1FD3, 0x0000, 0x0000, 0x1FD6, 0x1FD7,
- 0x1FD8, 0x1FD9, 0x1FDA, 0x1FDB, 0x0000, 0x1FDD, 0x1FDE, 0x1FDF,
- 0x1FE8, 0x1FE9, 0x1FE2, 0x1FE3, 0x1FE4, 0x1FEC, 0x1FE6, 0x1FE7,
- 0x1FE8, 0x1FE9, 0x1FEA, 0x1FEB, 0x1FEC, 0x1FED, 0x1FEE, 0x1FEF,
- 0x0000, 0x0000, 0x1FF2, 0x1FFC, 0x1FF4, 0x0000, 0x1FF6, 0x1FF7,
- 0x1FF8, 0x1FF9, 0x1FFA, 0x1FFB, 0x1FFC, 0x1FFD, 0x1FFE, 0x0000
- };
-
- *lower = code;
- *upper = code;
-
- /* Basic Latin and Latin-1 Supplement, U+0000 to U+00FF */
- if (code <= 0x00ff) {
- if (code >= 0x0041 && code <= 0x005a) /* A-Z */
- *lower += 0x20;
- else if (code >= 0x0061 && code <= 0x007a) /* a-z */
- *upper -= 0x20;
- else if ( (code >= 0x00c0 && code <= 0x00d6) ||
- (code >= 0x00d8 && code <= 0x00de) )
- *lower += 0x20;
- else if ( (code >= 0x00e0 && code <= 0x00f6) ||
- (code >= 0x00f8 && code <= 0x00fe) )
- *upper -= 0x20;
- else if (code == 0x00ff) /* y with diaeresis */
- *upper = 0x0178;
- else if (code == 0x00b5) /* micro sign */
- *upper = 0x039c;
- return;
- }
-
- /* Latin Extended-A, U+0100 to U+017F */
- if (code >= 0x0100 && code <= 0x017f) {
- if ( (code >= 0x0100 && code <= 0x012f) ||
- (code >= 0x0132 && code <= 0x0137) ||
- (code >= 0x014a && code <= 0x0177) ) {
- *upper = code & ~1;
- *lower = code | 1;
- }
- else if ( (code >= 0x0139 && code <= 0x0148) ||
- (code >= 0x0179 && code <= 0x017e) ) {
- if (code & 1)
- *lower += 1;
- else
- *upper -= 1;
- }
- else if (code == 0x0130)
- *lower = 0x0069;
- else if (code == 0x0131)
- *upper = 0x0049;
- else if (code == 0x0178)
- *lower = 0x00ff;
- else if (code == 0x017f)
- *upper = 0x0053;
- return;
- }
-
- /* Latin Extended-B, U+0180 to U+024F */
- if (code >= 0x0180 && code <= 0x024f) {
- if (code >= 0x01cd && code <= 0x01dc) {
- if (code & 1)
- *lower += 1;
- else
- *upper -= 1;
- }
- else if ( (code >= 0x01de && code <= 0x01ef) ||
- (code >= 0x01f4 && code <= 0x01f5) ||
- (code >= 0x01f8 && code <= 0x021f) ||
- (code >= 0x0222 && code <= 0x0233) ) {
- *lower |= 1;
- *upper &= ~1;
- }
- else if (code >= 0x0180 && code <= 0x01cc) {
- *lower = LatinExtB_lower_mapping[code - 0x0180];
- *upper = LatinExtB_upper_mapping[code - 0x0180];
- }
- else if (code == 0x01dd)
- *upper = 0x018e;
- else if (code == 0x01f1 || code == 0x01f2) {
- *lower = 0x01f3;
- *upper = 0x01f1;
- }
- else if (code == 0x01f3)
- *upper = 0x01f1;
- else if (code == 0x01f6)
- *lower = 0x0195;
- else if (code == 0x01f7)
- *lower = 0x01bf;
- else if (code == 0x0220)
- *lower = 0x019e;
- return;
- }
-
- /* IPA Extensions, U+0250 to U+02AF */
- if (code >= 0x0253 && code <= 0x0292) {
- *upper = IPAExt_upper_mapping[code - 0x0253];
- }
-
- /* Combining Diacritical Marks, U+0300 to U+036F */
- if (code == 0x0345) {
- *upper = 0x0399;
- }
-
- /* Greek and Coptic, U+0370 to U+03FF */
- if (code >= 0x0370 && code <= 0x03ff) {
- *lower = Greek_lower_mapping[code - 0x0370];
- *upper = Greek_upper_mapping[code - 0x0370];
- if (*upper == 0)
- *upper = code;
- if (*lower == 0)
- *lower = code;
- }
-
- /* Cyrillic and Cyrillic Supplementary, U+0400 to U+052F */
- if ( (code >= 0x0400 && code <= 0x04ff) ||
- (code >= 0x0500 && code <= 0x052f) ) {
- if (code >= 0x0400 && code <= 0x040f)
- *lower += 0x50;
- else if (code >= 0x0410 && code <= 0x042f)
- *lower += 0x20;
- else if (code >= 0x0430 && code <= 0x044f)
- *upper -= 0x20;
- else if (code >= 0x0450 && code <= 0x045f)
- *upper -= 0x50;
- else if ( (code >= 0x0460 && code <= 0x0481) ||
- (code >= 0x048a && code <= 0x04bf) ||
- (code >= 0x04d0 && code <= 0x04f5) ||
- (code >= 0x04f8 && code <= 0x04f9) ||
- (code >= 0x0500 && code <= 0x050f) ) {
- *upper &= ~1;
- *lower |= 1;
- }
- else if (code >= 0x04c1 && code <= 0x04ce) {
- if (code & 1)
- *lower += 1;
- else
- *upper -= 1;
- }
- }
-
- /* Armenian, U+0530 to U+058F */
- if (code >= 0x0530 && code <= 0x058f) {
- if (code >= 0x0531 && code <= 0x0556)
- *lower += 0x30;
- else if (code >=0x0561 && code <= 0x0586)
- *upper -= 0x30;
- }
-
- /* Latin Extended Additional, U+1E00 to U+1EFF */
- if (code >= 0x1e00 && code <= 0x1eff) {
- if ( (code >= 0x1e00 && code <= 0x1e95) ||
- (code >= 0x1ea0 && code <= 0x1ef9) ) {
- *upper &= ~1;
- *lower |= 1;
- }
- else if (code == 0x1e9b)
- *upper = 0x1e60;
- }
-
- /* Greek Extended, U+1F00 to U+1FFF */
- if (code >= 0x1f00 && code <= 0x1fff) {
- *lower = GreekExt_lower_mapping[code - 0x1f00];
- *upper = GreekExt_upper_mapping[code - 0x1f00];
- if (*upper == 0)
- *upper = code;
- if (*lower == 0)
- *lower = code;
- }
-
- /* Letterlike Symbols, U+2100 to U+214F */
- if (code >= 0x2100 && code <= 0x214f) {
- switch (code) {
- case 0x2126: *lower = 0x03c9; break;
- case 0x212a: *lower = 0x006b; break;
- case 0x212b: *lower = 0x00e5; break;
- }
- }
- /* Number Forms, U+2150 to U+218F */
- else if (code >= 0x2160 && code <= 0x216f)
- *lower += 0x10;
- else if (code >= 0x2170 && code <= 0x217f)
- *upper -= 0x10;
- /* Enclosed Alphanumerics, U+2460 to U+24FF */
- else if (code >= 0x24b6 && code <= 0x24cf)
- *lower += 0x1a;
- else if (code >= 0x24d0 && code <= 0x24e9)
- *upper -= 0x1a;
- /* Halfwidth and Fullwidth Forms, U+FF00 to U+FFEF */
- else if (code >= 0xff21 && code <= 0xff3a)
- *lower += 0x20;
- else if (code >= 0xff41 && code <= 0xff5a)
- *upper -= 0x20;
- /* Deseret, U+10400 to U+104FF */
- else if (code >= 0x10400 && code <= 0x10427)
- *lower += 0x28;
- else if (code >= 0x10428 && code <= 0x1044f)
- *upper -= 0x28;
-}
-
-void
-XConvertCase(
- register KeySym sym,
- KeySym *lower,
- KeySym *upper)
-{
- /* Latin 1 keysym */
- if (sym < 0x100) {
- UCSConvertCase(sym, lower, upper);
- return;
- }
-
- /* Unicode keysym */
- if ((sym & 0xff000000) == 0x01000000) {
- UCSConvertCase((sym & 0x00ffffff), lower, upper);
- *upper |= 0x01000000;
- *lower |= 0x01000000;
- return;
- }
-
- /* Legacy keysym */
-
- *lower = sym;
- *upper = sym;
-
- switch(sym >> 8) {
- case 1: /* Latin 2 */
- /* Assume the KeySym is a legal value (ignore discontinuities) */
- if (sym == XK_Aogonek)
- *lower = XK_aogonek;
- else if (sym >= XK_Lstroke && sym <= XK_Sacute)
- *lower += (XK_lstroke - XK_Lstroke);
- else if (sym >= XK_Scaron && sym <= XK_Zacute)
- *lower += (XK_scaron - XK_Scaron);
- else if (sym >= XK_Zcaron && sym <= XK_Zabovedot)
- *lower += (XK_zcaron - XK_Zcaron);
- else if (sym == XK_aogonek)
- *upper = XK_Aogonek;
- else if (sym >= XK_lstroke && sym <= XK_sacute)
- *upper -= (XK_lstroke - XK_Lstroke);
- else if (sym >= XK_scaron && sym <= XK_zacute)
- *upper -= (XK_scaron - XK_Scaron);
- else if (sym >= XK_zcaron && sym <= XK_zabovedot)
- *upper -= (XK_zcaron - XK_Zcaron);
- else if (sym >= XK_Racute && sym <= XK_Tcedilla)
- *lower += (XK_racute - XK_Racute);
- else if (sym >= XK_racute && sym <= XK_tcedilla)
- *upper -= (XK_racute - XK_Racute);
- break;
- case 2: /* Latin 3 */
- /* Assume the KeySym is a legal value (ignore discontinuities) */
- if (sym >= XK_Hstroke && sym <= XK_Hcircumflex)
- *lower += (XK_hstroke - XK_Hstroke);
- else if (sym >= XK_Gbreve && sym <= XK_Jcircumflex)
- *lower += (XK_gbreve - XK_Gbreve);
- else if (sym >= XK_hstroke && sym <= XK_hcircumflex)
- *upper -= (XK_hstroke - XK_Hstroke);
- else if (sym >= XK_gbreve && sym <= XK_jcircumflex)
- *upper -= (XK_gbreve - XK_Gbreve);
- else if (sym >= XK_Cabovedot && sym <= XK_Scircumflex)
- *lower += (XK_cabovedot - XK_Cabovedot);
- else if (sym >= XK_cabovedot && sym <= XK_scircumflex)
- *upper -= (XK_cabovedot - XK_Cabovedot);
- break;
- case 3: /* Latin 4 */
- /* Assume the KeySym is a legal value (ignore discontinuities) */
- if (sym >= XK_Rcedilla && sym <= XK_Tslash)
- *lower += (XK_rcedilla - XK_Rcedilla);
- else if (sym >= XK_rcedilla && sym <= XK_tslash)
- *upper -= (XK_rcedilla - XK_Rcedilla);
- else if (sym == XK_ENG)
- *lower = XK_eng;
- else if (sym == XK_eng)
- *upper = XK_ENG;
- else if (sym >= XK_Amacron && sym <= XK_Umacron)
- *lower += (XK_amacron - XK_Amacron);
- else if (sym >= XK_amacron && sym <= XK_umacron)
- *upper -= (XK_amacron - XK_Amacron);
- break;
- case 6: /* Cyrillic */
- /* Assume the KeySym is a legal value (ignore discontinuities) */
- if (sym >= XK_Serbian_DJE && sym <= XK_Serbian_DZE)
- *lower -= (XK_Serbian_DJE - XK_Serbian_dje);
- else if (sym >= XK_Serbian_dje && sym <= XK_Serbian_dze)
- *upper += (XK_Serbian_DJE - XK_Serbian_dje);
- else if (sym >= XK_Cyrillic_YU && sym <= XK_Cyrillic_HARDSIGN)
- *lower -= (XK_Cyrillic_YU - XK_Cyrillic_yu);
- else if (sym >= XK_Cyrillic_yu && sym <= XK_Cyrillic_hardsign)
- *upper += (XK_Cyrillic_YU - XK_Cyrillic_yu);
- break;
- case 7: /* Greek */
- /* Assume the KeySym is a legal value (ignore discontinuities) */
- if (sym >= XK_Greek_ALPHAaccent && sym <= XK_Greek_OMEGAaccent)
- *lower += (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
- else if (sym >= XK_Greek_alphaaccent && sym <= XK_Greek_omegaaccent &&
- sym != XK_Greek_iotaaccentdieresis &&
- sym != XK_Greek_upsilonaccentdieresis)
- *upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
- else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
- *lower += (XK_Greek_alpha - XK_Greek_ALPHA);
- else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega &&
- sym != XK_Greek_finalsmallsigma)
- *upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
- break;
- case 0x13: /* Latin 9 */
- if (sym == XK_OE)
- *lower = XK_oe;
- else if (sym == XK_oe)
- *upper = XK_OE;
- else if (sym == XK_Ydiaeresis)
- *lower = XK_ydiaeresis;
- break;
- }
-}
-
-int
-_XTranslateKey( register Display *dpy,
- KeyCode keycode,
- register unsigned int modifiers,
- unsigned int *modifiers_return,
- KeySym *keysym_return)
-{
- int per;
- register KeySym *syms;
- KeySym sym, lsym, usym;
-
- if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
- return 0;
- *modifiers_return = ((ShiftMask|LockMask)
- | dpy->mode_switch | dpy->num_lock);
- if (((int)keycode < dpy->min_keycode) || ((int)keycode > dpy->max_keycode))
- {
- *keysym_return = NoSymbol;
- return 1;
- }
- per = dpy->keysyms_per_keycode;
- syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
- while ((per > 2) && (syms[per - 1] == NoSymbol))
- per--;
- if ((per > 2) && (modifiers & dpy->mode_switch)) {
- syms += 2;
- per -= 2;
- }
- if ((modifiers & dpy->num_lock) &&
- (per > 1 && (IsKeypadKey(syms[1]) || IsPrivateKeypadKey(syms[1])))) {
- if ((modifiers & ShiftMask) ||
- ((modifiers & LockMask) && (dpy->lock_meaning == XK_Shift_Lock)))
- *keysym_return = syms[0];
- else
- *keysym_return = syms[1];
- } else if (!(modifiers & ShiftMask) &&
- (!(modifiers & LockMask) || (dpy->lock_meaning == NoSymbol))) {
- if ((per == 1) || (syms[1] == NoSymbol))
- XConvertCase(syms[0], keysym_return, &usym);
- else
- *keysym_return = syms[0];
- } else if (!(modifiers & LockMask) ||
- (dpy->lock_meaning != XK_Caps_Lock)) {
- if ((per == 1) || ((usym = syms[1]) == NoSymbol))
- XConvertCase(syms[0], &lsym, &usym);
- *keysym_return = usym;
- } else {
- if ((per == 1) || ((sym = syms[1]) == NoSymbol))
- sym = syms[0];
- XConvertCase(sym, &lsym, &usym);
- if (!(modifiers & ShiftMask) && (sym != syms[0]) &&
- ((sym != usym) || (lsym == usym)))
- XConvertCase(syms[0], &lsym, &usym);
- *keysym_return = usym;
- }
- if (*keysym_return == XK_VoidSymbol)
- *keysym_return = NoSymbol;
- return 1;
-}
-
-int
-_XTranslateKeySym(
- Display *dpy,
- register KeySym symbol,
- unsigned int modifiers,
- char *buffer,
- int nbytes)
-{
- register struct _XKeytrans *p;
- int length;
- unsigned long hiBytes;
- register unsigned char c;
-
- if (!symbol)
- return 0;
- /* see if symbol rebound, if so, return that string. */
- for (p = dpy->key_bindings; p; p = p->next) {
- if (((modifiers & AllMods) == p->state) && (symbol == p->key)) {
- length = p->len;
- if (length > nbytes) length = nbytes;
- memcpy (buffer, p->string, length);
- return length;
- }
- }
- /* try to convert to Latin-1, handling control */
- hiBytes = symbol >> 8;
- if (!(nbytes &&
- ((hiBytes == 0) ||
- ((hiBytes == 0xFF) &&
- (((symbol >= XK_BackSpace) && (symbol <= XK_Clear)) ||
- (symbol == XK_Return) ||
- (symbol == XK_Escape) ||
- (symbol == XK_KP_Space) ||
- (symbol == XK_KP_Tab) ||
- (symbol == XK_KP_Enter) ||
- ((symbol >= XK_KP_Multiply) && (symbol <= XK_KP_9)) ||
- (symbol == XK_KP_Equal) ||
- (symbol == XK_Delete))))))
- return 0;
-
- /* if X keysym, convert to ascii by grabbing low 7 bits */
- if (symbol == XK_KP_Space)
- c = XK_space & 0x7F; /* patch encoding botch */
- else if (hiBytes == 0xFF)
- c = symbol & 0x7F;
- else
- c = symbol & 0xFF;
- /* only apply Control key if it makes sense, else ignore it */
- if (modifiers & ControlMask) {
- if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
- else if (c == '2') c = '\000';
- else if (c >= '3' && c <= '7') c -= ('3' - '\033');
- else if (c == '8') c = '\177';
- else if (c == '/') c = '_' & 0x1F;
- }
- buffer[0] = c;
- return 1;
-}
-
-/*ARGSUSED*/
-int
-XLookupString (
- register XKeyEvent *event,
- char *buffer, /* buffer */
- int nbytes, /* space in buffer for characters */
- KeySym *keysym,
- XComposeStatus *status) /* not implemented */
-{
- unsigned int modifiers;
- KeySym symbol;
-
- if (! _XTranslateKey(event->display, event->keycode, event->state,
- &modifiers, &symbol))
- return 0;
-
-#ifdef USE_OWN_COMPOSE
- if ( status ) {
- static int been_here= 0;
- if ( !been_here ) {
- XimCompInitTables();
- been_here = 1;
- }
- if ( !XimCompLegalStatus(status) ) {
- status->compose_ptr = NULL;
- status->chars_matched = 0;
- }
- if ( ((status->chars_matched>0)&&(status->compose_ptr!=NULL)) ||
- XimCompIsComposeKey(symbol,event->keycode,status) ) {
- XimCompRtrn rtrn;
- switch (XimCompProcessSym(status,symbol,&rtrn)) {
- case XIM_COMP_IGNORE:
- break;
- case XIM_COMP_IN_PROGRESS:
- if ( keysym!=NULL )
- *keysym = NoSymbol;
- return 0;
- case XIM_COMP_FAIL:
- {
- int n = 0, len= 0;
- for (n=len=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
- if ( nbytes-len > 0 ) {
- len+= _XTranslateKeySym(event->display,rtrn.sym[n],
- event->state,
- buffer+len,nbytes-len);
- }
- }
- if ( keysym!=NULL ) {
- if ( n==1 ) *keysym = rtrn.sym[0];
- else *keysym = NoSymbol;
- }
- return len;
- }
- case XIM_COMP_SUCCEED:
- {
- int len,n = 0;
-
- symbol = rtrn.matchSym;
- if ( keysym!=NULL ) *keysym = symbol;
- if ( rtrn.str[0]!='\0' ) {
- strncpy(buffer,rtrn.str,nbytes-1);
- buffer[nbytes-1]= '\0';
- len = strlen(buffer);
- }
- else {
- len = _XTranslateKeySym(event->display,symbol,
- event->state,
- buffer,nbytes);
- }
- for (n=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
- if ( nbytes-len > 0 ) {
- len+= _XTranslateKeySym(event->display,rtrn.sym[n],
- event->state,
- buffer+len,nbytes-len);
- }
- }
- return len;
- }
- }
- }
- }
-#endif
-
- if (keysym)
- *keysym = symbol;
- /* arguable whether to use (event->state & ~modifiers) here */
- return _XTranslateKeySym(event->display, symbol, event->state,
- buffer, nbytes);
-}
-
-static void
-_XFreeKeyBindings(
- Display *dpy)
-{
- register struct _XKeytrans *p, *np;
-
- for (p = dpy->key_bindings; p; p = np) {
- np = p->next;
- Xfree(p->string);
- Xfree((char *)p->modifiers);
- Xfree((char *)p);
- }
-}
-
-int
-XRebindKeysym (
- Display *dpy,
- KeySym keysym,
- KeySym *mlist,
- int nm, /* number of modifiers in mlist */
- _Xconst unsigned char *str,
- int nbytes)
-{
- register struct _XKeytrans *tmp, *p;
- int nb;
-
- if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
- return 0;
- LockDisplay(dpy);
- tmp = dpy->key_bindings;
- nb = sizeof(KeySym) * nm;
-
- if ((! (p = (struct _XKeytrans *) Xmalloc( sizeof(struct _XKeytrans)))) ||
- ((! (p->string = (char *) Xmalloc( (unsigned) nbytes))) &&
- (nbytes > 0)) ||
- ((! (p->modifiers = (KeySym *) Xmalloc( (unsigned) nb))) &&
- (nb > 0))) {
- if (p) {
- if (p->string) Xfree(p->string);
- if (p->modifiers) Xfree((char *) p->modifiers);
- Xfree((char *) p);
- }
- UnlockDisplay(dpy);
- return 0;
- }
-
- dpy->key_bindings = p;
- dpy->free_funcs->key_bindings = _XFreeKeyBindings;
- p->next = tmp; /* chain onto list */
- memcpy (p->string, (char *) str, nbytes);
- p->len = nbytes;
- memcpy ((char *) p->modifiers, (char *) mlist, nb);
- p->key = keysym;
- p->mlen = nm;
- ComputeMaskFromKeytrans(dpy, p);
- UnlockDisplay(dpy);
- return 0;
-}
-
-unsigned
-_XKeysymToModifiers(
- Display *dpy,
- KeySym ks)
-{
- CARD8 code,mods;
- register KeySym *kmax;
- register KeySym *k;
- register XModifierKeymap *m;
-
- if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
- return 0;
- kmax = dpy->keysyms +
- (dpy->max_keycode - dpy->min_keycode + 1) * dpy->keysyms_per_keycode;
- k = dpy->keysyms;
- m = dpy->modifiermap;
- mods= 0;
- while (k<kmax) {
- if (*k == ks ) {
- register int j = m->max_keypermod<<3;
-
- code=(((k-dpy->keysyms)/dpy->keysyms_per_keycode)+dpy->min_keycode);
-
- while (--j >= 0) {
- if (code == m->modifiermap[j])
- mods|= (1<<(j/m->max_keypermod));
- }
- }
- k++;
- }
- return mods;
-}
-
-/*
- * given a list of modifiers, computes the mask necessary for later matching.
- * This routine must lookup the key in the Keymap and then search to see
- * what modifier it is bound to, if any. Sets the AnyModifier bit if it
- * can't map some keysym to a modifier.
- */
-static void
-ComputeMaskFromKeytrans(
- Display *dpy,
- register struct _XKeytrans *p)
-{
- register int i;
-
- p->state = AnyModifier;
- for (i = 0; i < p->mlen; i++) {
- p->state|= XkbKeysymToModifiers(dpy,p->modifiers[i]);
- }
- p->state &= AllMods;
-}
+/*
+
+Copyright 1985, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+/* Beware, here be monsters (still under construction... - JG */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/Xutil.h>
+#define XK_MISCELLANY
+#define XK_LATIN1
+#define XK_LATIN2
+#define XK_LATIN3
+#define XK_LATIN4
+#define XK_LATIN8
+#define XK_LATIN9
+#define XK_CYRILLIC
+#define XK_GREEK
+#define XK_ARMENIAN
+#define XK_CAUCASUS
+#define XK_VIETNAMESE
+#define XK_XKB_KEYS
+#include <X11/keysymdef.h>
+#include <stdio.h>
+
+#ifdef USE_OWN_COMPOSE
+#include "imComp.h"
+
+#endif
+
+#include "Xresource.h"
+#include "Key.h"
+
+#ifdef XKB
+#include "XKBlib.h"
+#include "XKBlibint.h"
+#define XKeycodeToKeysym _XKeycodeToKeysym
+#define XKeysymToKeycode _XKeysymToKeycode
+#define XLookupKeysym _XLookupKeysym
+#define XRefreshKeyboardMapping _XRefreshKeyboardMapping
+#define XLookupString _XLookupString
+/* XKBBind.c */
+#else
+#define XkbKeysymToModifiers _XKeysymToModifiers
+#endif
+
+#define AllMods (ShiftMask|LockMask|ControlMask| \
+ Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)
+
+static void
+ComputeMaskFromKeytrans(
+ Display *dpy,
+ register struct _XKeytrans *p);
+
+struct _XKeytrans {
+ struct _XKeytrans *next;/* next on list */
+ char *string; /* string to return when the time comes */
+ int len; /* length of string (since NULL is legit)*/
+ KeySym key; /* keysym rebound */
+ unsigned int state; /* modifier state */
+ KeySym *modifiers; /* modifier keysyms you want */
+ int mlen; /* length of modifier list */
+};
+
+static KeySym
+KeyCodetoKeySym(register Display *dpy, KeyCode keycode, int col)
+{
+ register int per = dpy->keysyms_per_keycode;
+ register KeySym *syms;
+ KeySym lsym, usym;
+
+ if ((col < 0) || ((col >= per) && (col > 3)) ||
+ ((int)keycode < dpy->min_keycode) || ((int)keycode > dpy->max_keycode))
+ return NoSymbol;
+
+ syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
+ if (col < 4) {
+ if (col > 1) {
+ while ((per > 2) && (syms[per - 1] == NoSymbol))
+ per--;
+ if (per < 3)
+ col -= 2;
+ }
+ if ((per <= (col|1)) || (syms[col|1] == NoSymbol)) {
+ XConvertCase(syms[col&~1], &lsym, &usym);
+ if (!(col & 1))
+ return lsym;
+ else if (usym == lsym)
+ return NoSymbol;
+ else
+ return usym;
+ }
+ }
+ return syms[col];
+}
+
+KeySym
+XKeycodeToKeysym(Display *dpy,
+#if NeedWidePrototypes
+ unsigned int kc,
+#else
+ KeyCode kc,
+#endif
+ int col)
+{
+ if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
+ return NoSymbol;
+ return KeyCodetoKeySym(dpy, kc, col);
+}
+
+KeyCode
+XKeysymToKeycode(
+ Display *dpy,
+ KeySym ks)
+{
+ register int i, j;
+
+ if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
+ return (KeyCode) 0;
+ for (j = 0; j < dpy->keysyms_per_keycode; j++) {
+ for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) {
+ if (KeyCodetoKeySym(dpy, (KeyCode) i, j) == ks)
+ return i;
+ }
+ }
+ return 0;
+}
+
+KeySym
+XLookupKeysym(
+ register XKeyEvent *event,
+ int col)
+{
+ if ((! event->display->keysyms) && (! _XKeyInitialize(event->display)))
+ return NoSymbol;
+ return KeyCodetoKeySym(event->display, event->keycode, col);
+}
+
+static void
+ResetModMap(
+ Display *dpy)
+{
+ register XModifierKeymap *map;
+ register int i, j, n;
+ KeySym sym;
+ register struct _XKeytrans *p;
+
+ map = dpy->modifiermap;
+ /* If any Lock key contains Caps_Lock, then interpret as Caps_Lock,
+ * else if any contains Shift_Lock, then interpret as Shift_Lock,
+ * else ignore Lock altogether.
+ */
+ dpy->lock_meaning = NoSymbol;
+ /* Lock modifiers are in the second row of the matrix */
+ n = 2 * map->max_keypermod;
+ for (i = map->max_keypermod; i < n; i++) {
+ for (j = 0; j < dpy->keysyms_per_keycode; j++) {
+ sym = KeyCodetoKeySym(dpy, map->modifiermap[i], j);
+ if (sym == XK_Caps_Lock) {
+ dpy->lock_meaning = XK_Caps_Lock;
+ break;
+ } else if (sym == XK_Shift_Lock) {
+ dpy->lock_meaning = XK_Shift_Lock;
+ }
+ else if (sym == XK_ISO_Lock) {
+ dpy->lock_meaning = XK_Caps_Lock;
+ break;
+ }
+ }
+ }
+ /* Now find any Mod<n> modifier acting as the Group or Numlock modifier */
+ dpy->mode_switch = 0;
+ dpy->num_lock = 0;
+ n *= 4;
+ for (i = 3*map->max_keypermod; i < n; i++) {
+ for (j = 0; j < dpy->keysyms_per_keycode; j++) {
+ sym = KeyCodetoKeySym(dpy, map->modifiermap[i], j);
+ if (sym == XK_Mode_switch)
+ dpy->mode_switch |= 1 << (i / map->max_keypermod);
+ if (sym == XK_Num_Lock)
+ dpy->num_lock |= 1 << (i / map->max_keypermod);
+ }
+ }
+ for (p = dpy->key_bindings; p; p = p->next)
+ ComputeMaskFromKeytrans(dpy, p);
+}
+
+static int
+InitModMap(
+ Display *dpy)
+{
+ register XModifierKeymap *map;
+
+ if (! (map = XGetModifierMapping(dpy)))
+ return 0;
+ LockDisplay(dpy);
+ if (dpy->modifiermap)
+ XFreeModifiermap(dpy->modifiermap);
+ dpy->modifiermap = map;
+ dpy->free_funcs->modifiermap = XFreeModifiermap;
+ if (dpy->keysyms)
+ ResetModMap(dpy);
+ UnlockDisplay(dpy);
+ return 1;
+}
+
+int
+XRefreshKeyboardMapping(register XMappingEvent *event)
+{
+
+ if(event->request == MappingKeyboard) {
+ /* XXX should really only refresh what is necessary
+ * for now, make initialize test fail
+ */
+ LockDisplay(event->display);
+ if (event->display->keysyms) {
+ Xfree ((char *)event->display->keysyms);
+ event->display->keysyms = NULL;
+ }
+ UnlockDisplay(event->display);
+ }
+ if(event->request == MappingModifier) {
+ LockDisplay(event->display);
+ if (event->display->modifiermap) {
+ XFreeModifiermap(event->display->modifiermap);
+ event->display->modifiermap = NULL;
+ }
+ UnlockDisplay(event->display);
+ /* go ahead and get it now, since initialize test may not fail */
+ if (event->display->keysyms)
+ (void) InitModMap(event->display);
+ }
+ return 1;
+}
+
+int
+_XKeyInitialize(
+ Display *dpy)
+{
+ int per, n;
+ KeySym *keysyms;
+
+ /*
+ * lets go get the keysyms from the server.
+ */
+ if (!dpy->keysyms) {
+ n = dpy->max_keycode - dpy->min_keycode + 1;
+ keysyms = XGetKeyboardMapping (dpy, (KeyCode) dpy->min_keycode,
+ n, &per);
+ /* keysyms may be NULL */
+ if (! keysyms) return 0;
+
+ LockDisplay(dpy);
+ if (dpy->keysyms)
+ Xfree ((char *)dpy->keysyms);
+ dpy->keysyms = keysyms;
+ dpy->keysyms_per_keycode = per;
+ if (dpy->modifiermap)
+ ResetModMap(dpy);
+ UnlockDisplay(dpy);
+ }
+ if (!dpy->modifiermap)
+ return InitModMap(dpy);
+ return 1;
+}
+
+static void
+UCSConvertCase( register unsigned code,
+ KeySym *lower,
+ KeySym *upper )
+{
+ /* Case conversion for UCS, as in Unicode Data version 4.0.0 */
+ /* NB: Only converts simple one-to-one mappings. */
+
+ /* Tables are used where they take less space than */
+ /* the code to work out the mappings. Zero values mean */
+ /* undefined code points. */
+
+ static unsigned short const IPAExt_upper_mapping[] = { /* part only */
+ 0x0181, 0x0186, 0x0255, 0x0189, 0x018A,
+ 0x0258, 0x018F, 0x025A, 0x0190, 0x025C, 0x025D, 0x025E, 0x025F,
+ 0x0193, 0x0261, 0x0262, 0x0194, 0x0264, 0x0265, 0x0266, 0x0267,
+ 0x0197, 0x0196, 0x026A, 0x026B, 0x026C, 0x026D, 0x026E, 0x019C,
+ 0x0270, 0x0271, 0x019D, 0x0273, 0x0274, 0x019F, 0x0276, 0x0277,
+ 0x0278, 0x0279, 0x027A, 0x027B, 0x027C, 0x027D, 0x027E, 0x027F,
+ 0x01A6, 0x0281, 0x0282, 0x01A9, 0x0284, 0x0285, 0x0286, 0x0287,
+ 0x01AE, 0x0289, 0x01B1, 0x01B2, 0x028C, 0x028D, 0x028E, 0x028F,
+ 0x0290, 0x0291, 0x01B7
+ };
+
+ static unsigned short const LatinExtB_upper_mapping[] = { /* first part only */
+ 0x0180, 0x0181, 0x0182, 0x0182, 0x0184, 0x0184, 0x0186, 0x0187,
+ 0x0187, 0x0189, 0x018A, 0x018B, 0x018B, 0x018D, 0x018E, 0x018F,
+ 0x0190, 0x0191, 0x0191, 0x0193, 0x0194, 0x01F6, 0x0196, 0x0197,
+ 0x0198, 0x0198, 0x019A, 0x019B, 0x019C, 0x019D, 0x0220, 0x019F,
+ 0x01A0, 0x01A0, 0x01A2, 0x01A2, 0x01A4, 0x01A4, 0x01A6, 0x01A7,
+ 0x01A7, 0x01A9, 0x01AA, 0x01AB, 0x01AC, 0x01AC, 0x01AE, 0x01AF,
+ 0x01AF, 0x01B1, 0x01B2, 0x01B3, 0x01B3, 0x01B5, 0x01B5, 0x01B7,
+ 0x01B8, 0x01B8, 0x01BA, 0x01BB, 0x01BC, 0x01BC, 0x01BE, 0x01F7,
+ 0x01C0, 0x01C1, 0x01C2, 0x01C3, 0x01C4, 0x01C4, 0x01C4, 0x01C7,
+ 0x01C7, 0x01C7, 0x01CA, 0x01CA, 0x01CA
+ };
+
+ static unsigned short const LatinExtB_lower_mapping[] = { /* first part only */
+ 0x0180, 0x0253, 0x0183, 0x0183, 0x0185, 0x0185, 0x0254, 0x0188,
+ 0x0188, 0x0256, 0x0257, 0x018C, 0x018C, 0x018D, 0x01DD, 0x0259,
+ 0x025B, 0x0192, 0x0192, 0x0260, 0x0263, 0x0195, 0x0269, 0x0268,
+ 0x0199, 0x0199, 0x019A, 0x019B, 0x026F, 0x0272, 0x019E, 0x0275,
+ 0x01A1, 0x01A1, 0x01A3, 0x01A3, 0x01A5, 0x01A5, 0x0280, 0x01A8,
+ 0x01A8, 0x0283, 0x01AA, 0x01AB, 0x01AD, 0x01AD, 0x0288, 0x01B0,
+ 0x01B0, 0x028A, 0x028B, 0x01B4, 0x01B4, 0x01B6, 0x01B6, 0x0292,
+ 0x01B9, 0x01B9, 0x01BA, 0x01BB, 0x01BD, 0x01BD, 0x01BE, 0x01BF,
+ 0x01C0, 0x01C1, 0x01C2, 0x01C3, 0x01C6, 0x01C6, 0x01C6, 0x01C9,
+ 0x01C9, 0x01C9, 0x01CC, 0x01CC, 0x01CC
+ };
+
+ static unsigned short const Greek_upper_mapping[] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0374, 0x0375, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x037A, 0x0000, 0x0000, 0x0000, 0x037E, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0384, 0x0385, 0x0386, 0x0387,
+ 0x0388, 0x0389, 0x038A, 0x0000, 0x038C, 0x0000, 0x038E, 0x038F,
+ 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
+ 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
+ 0x03A0, 0x03A1, 0x0000, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
+ 0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x0386, 0x0388, 0x0389, 0x038A,
+ 0x03B0, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
+ 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
+ 0x03A0, 0x03A1, 0x03A3, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
+ 0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x038C, 0x038E, 0x038F, 0x0000,
+ 0x0392, 0x0398, 0x03D2, 0x03D3, 0x03D4, 0x03A6, 0x03A0, 0x03D7,
+ 0x03D8, 0x03D8, 0x03DA, 0x03DA, 0x03DC, 0x03DC, 0x03DE, 0x03DE,
+ 0x03E0, 0x03E0, 0x03E2, 0x03E2, 0x03E4, 0x03E4, 0x03E6, 0x03E6,
+ 0x03E8, 0x03E8, 0x03EA, 0x03EA, 0x03EC, 0x03EC, 0x03EE, 0x03EE,
+ 0x039A, 0x03A1, 0x03F9, 0x03F3, 0x03F4, 0x0395, 0x03F6, 0x03F7,
+ 0x03F7, 0x03F9, 0x03FA, 0x03FA, 0x0000, 0x0000, 0x0000, 0x0000
+ };
+
+ static unsigned short const Greek_lower_mapping[] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0374, 0x0375, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x037A, 0x0000, 0x0000, 0x0000, 0x037E, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0384, 0x0385, 0x03AC, 0x0387,
+ 0x03AD, 0x03AE, 0x03AF, 0x0000, 0x03CC, 0x0000, 0x03CD, 0x03CE,
+ 0x0390, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
+ 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
+ 0x03C0, 0x03C1, 0x0000, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
+ 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
+ 0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
+ 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
+ 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
+ 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0000,
+ 0x03D0, 0x03D1, 0x03D2, 0x03D3, 0x03D4, 0x03D5, 0x03D6, 0x03D7,
+ 0x03D9, 0x03D9, 0x03DB, 0x03DB, 0x03DD, 0x03DD, 0x03DF, 0x03DF,
+ 0x03E1, 0x03E1, 0x03E3, 0x03E3, 0x03E5, 0x03E5, 0x03E7, 0x03E7,
+ 0x03E9, 0x03E9, 0x03EB, 0x03EB, 0x03ED, 0x03ED, 0x03EF, 0x03EF,
+ 0x03F0, 0x03F1, 0x03F2, 0x03F3, 0x03B8, 0x03F5, 0x03F6, 0x03F8,
+ 0x03F8, 0x03F2, 0x03FB, 0x03FB, 0x0000, 0x0000, 0x0000, 0x0000
+ };
+
+ static unsigned short const GreekExt_lower_mapping[] = {
+ 0x1F00, 0x1F01, 0x1F02, 0x1F03, 0x1F04, 0x1F05, 0x1F06, 0x1F07,
+ 0x1F00, 0x1F01, 0x1F02, 0x1F03, 0x1F04, 0x1F05, 0x1F06, 0x1F07,
+ 0x1F10, 0x1F11, 0x1F12, 0x1F13, 0x1F14, 0x1F15, 0x0000, 0x0000,
+ 0x1F10, 0x1F11, 0x1F12, 0x1F13, 0x1F14, 0x1F15, 0x0000, 0x0000,
+ 0x1F20, 0x1F21, 0x1F22, 0x1F23, 0x1F24, 0x1F25, 0x1F26, 0x1F27,
+ 0x1F20, 0x1F21, 0x1F22, 0x1F23, 0x1F24, 0x1F25, 0x1F26, 0x1F27,
+ 0x1F30, 0x1F31, 0x1F32, 0x1F33, 0x1F34, 0x1F35, 0x1F36, 0x1F37,
+ 0x1F30, 0x1F31, 0x1F32, 0x1F33, 0x1F34, 0x1F35, 0x1F36, 0x1F37,
+ 0x1F40, 0x1F41, 0x1F42, 0x1F43, 0x1F44, 0x1F45, 0x0000, 0x0000,
+ 0x1F40, 0x1F41, 0x1F42, 0x1F43, 0x1F44, 0x1F45, 0x0000, 0x0000,
+ 0x1F50, 0x1F51, 0x1F52, 0x1F53, 0x1F54, 0x1F55, 0x1F56, 0x1F57,
+ 0x0000, 0x1F51, 0x0000, 0x1F53, 0x0000, 0x1F55, 0x0000, 0x1F57,
+ 0x1F60, 0x1F61, 0x1F62, 0x1F63, 0x1F64, 0x1F65, 0x1F66, 0x1F67,
+ 0x1F60, 0x1F61, 0x1F62, 0x1F63, 0x1F64, 0x1F65, 0x1F66, 0x1F67,
+ 0x1F70, 0x1F71, 0x1F72, 0x1F73, 0x1F74, 0x1F75, 0x1F76, 0x1F77,
+ 0x1F78, 0x1F79, 0x1F7A, 0x1F7B, 0x1F7C, 0x1F7D, 0x0000, 0x0000,
+ 0x1F80, 0x1F81, 0x1F82, 0x1F83, 0x1F84, 0x1F85, 0x1F86, 0x1F87,
+ 0x1F80, 0x1F81, 0x1F82, 0x1F83, 0x1F84, 0x1F85, 0x1F86, 0x1F87,
+ 0x1F90, 0x1F91, 0x1F92, 0x1F93, 0x1F94, 0x1F95, 0x1F96, 0x1F97,
+ 0x1F90, 0x1F91, 0x1F92, 0x1F93, 0x1F94, 0x1F95, 0x1F96, 0x1F97,
+ 0x1FA0, 0x1FA1, 0x1FA2, 0x1FA3, 0x1FA4, 0x1FA5, 0x1FA6, 0x1FA7,
+ 0x1FA0, 0x1FA1, 0x1FA2, 0x1FA3, 0x1FA4, 0x1FA5, 0x1FA6, 0x1FA7,
+ 0x1FB0, 0x1FB1, 0x1FB2, 0x1FB3, 0x1FB4, 0x0000, 0x1FB6, 0x1FB7,
+ 0x1FB0, 0x1FB1, 0x1F70, 0x1F71, 0x1FB3, 0x1FBD, 0x1FBE, 0x1FBF,
+ 0x1FC0, 0x1FC1, 0x1FC2, 0x1FC3, 0x1FC4, 0x0000, 0x1FC6, 0x1FC7,
+ 0x1F72, 0x1F73, 0x1F74, 0x1F75, 0x1FC3, 0x1FCD, 0x1FCE, 0x1FCF,
+ 0x1FD0, 0x1FD1, 0x1FD2, 0x1FD3, 0x0000, 0x0000, 0x1FD6, 0x1FD7,
+ 0x1FD0, 0x1FD1, 0x1F76, 0x1F77, 0x0000, 0x1FDD, 0x1FDE, 0x1FDF,
+ 0x1FE0, 0x1FE1, 0x1FE2, 0x1FE3, 0x1FE4, 0x1FE5, 0x1FE6, 0x1FE7,
+ 0x1FE0, 0x1FE1, 0x1F7A, 0x1F7B, 0x1FE5, 0x1FED, 0x1FEE, 0x1FEF,
+ 0x0000, 0x0000, 0x1FF2, 0x1FF3, 0x1FF4, 0x0000, 0x1FF6, 0x1FF7,
+ 0x1F78, 0x1F79, 0x1F7C, 0x1F7D, 0x1FF3, 0x1FFD, 0x1FFE, 0x0000
+ };
+
+ static unsigned short const GreekExt_upper_mapping[] = {
+ 0x1F08, 0x1F09, 0x1F0A, 0x1F0B, 0x1F0C, 0x1F0D, 0x1F0E, 0x1F0F,
+ 0x1F08, 0x1F09, 0x1F0A, 0x1F0B, 0x1F0C, 0x1F0D, 0x1F0E, 0x1F0F,
+ 0x1F18, 0x1F19, 0x1F1A, 0x1F1B, 0x1F1C, 0x1F1D, 0x0000, 0x0000,
+ 0x1F18, 0x1F19, 0x1F1A, 0x1F1B, 0x1F1C, 0x1F1D, 0x0000, 0x0000,
+ 0x1F28, 0x1F29, 0x1F2A, 0x1F2B, 0x1F2C, 0x1F2D, 0x1F2E, 0x1F2F,
+ 0x1F28, 0x1F29, 0x1F2A, 0x1F2B, 0x1F2C, 0x1F2D, 0x1F2E, 0x1F2F,
+ 0x1F38, 0x1F39, 0x1F3A, 0x1F3B, 0x1F3C, 0x1F3D, 0x1F3E, 0x1F3F,
+ 0x1F38, 0x1F39, 0x1F3A, 0x1F3B, 0x1F3C, 0x1F3D, 0x1F3E, 0x1F3F,
+ 0x1F48, 0x1F49, 0x1F4A, 0x1F4B, 0x1F4C, 0x1F4D, 0x0000, 0x0000,
+ 0x1F48, 0x1F49, 0x1F4A, 0x1F4B, 0x1F4C, 0x1F4D, 0x0000, 0x0000,
+ 0x1F50, 0x1F59, 0x1F52, 0x1F5B, 0x1F54, 0x1F5D, 0x1F56, 0x1F5F,
+ 0x0000, 0x1F59, 0x0000, 0x1F5B, 0x0000, 0x1F5D, 0x0000, 0x1F5F,
+ 0x1F68, 0x1F69, 0x1F6A, 0x1F6B, 0x1F6C, 0x1F6D, 0x1F6E, 0x1F6F,
+ 0x1F68, 0x1F69, 0x1F6A, 0x1F6B, 0x1F6C, 0x1F6D, 0x1F6E, 0x1F6F,
+ 0x1FBA, 0x1FBB, 0x1FC8, 0x1FC9, 0x1FCA, 0x1FCB, 0x1FDA, 0x1FDB,
+ 0x1FF8, 0x1FF9, 0x1FEA, 0x1FEB, 0x1FFA, 0x1FFB, 0x0000, 0x0000,
+ 0x1F88, 0x1F89, 0x1F8A, 0x1F8B, 0x1F8C, 0x1F8D, 0x1F8E, 0x1F8F,
+ 0x1F88, 0x1F89, 0x1F8A, 0x1F8B, 0x1F8C, 0x1F8D, 0x1F8E, 0x1F8F,
+ 0x1F98, 0x1F99, 0x1F9A, 0x1F9B, 0x1F9C, 0x1F9D, 0x1F9E, 0x1F9F,
+ 0x1F98, 0x1F99, 0x1F9A, 0x1F9B, 0x1F9C, 0x1F9D, 0x1F9E, 0x1F9F,
+ 0x1FA8, 0x1FA9, 0x1FAA, 0x1FAB, 0x1FAC, 0x1FAD, 0x1FAE, 0x1FAF,
+ 0x1FA8, 0x1FA9, 0x1FAA, 0x1FAB, 0x1FAC, 0x1FAD, 0x1FAE, 0x1FAF,
+ 0x1FB8, 0x1FB9, 0x1FB2, 0x1FBC, 0x1FB4, 0x0000, 0x1FB6, 0x1FB7,
+ 0x1FB8, 0x1FB9, 0x1FBA, 0x1FBB, 0x1FBC, 0x1FBD, 0x0399, 0x1FBF,
+ 0x1FC0, 0x1FC1, 0x1FC2, 0x1FCC, 0x1FC4, 0x0000, 0x1FC6, 0x1FC7,
+ 0x1FC8, 0x1FC9, 0x1FCA, 0x1FCB, 0x1FCC, 0x1FCD, 0x1FCE, 0x1FCF,
+ 0x1FD8, 0x1FD9, 0x1FD2, 0x1FD3, 0x0000, 0x0000, 0x1FD6, 0x1FD7,
+ 0x1FD8, 0x1FD9, 0x1FDA, 0x1FDB, 0x0000, 0x1FDD, 0x1FDE, 0x1FDF,
+ 0x1FE8, 0x1FE9, 0x1FE2, 0x1FE3, 0x1FE4, 0x1FEC, 0x1FE6, 0x1FE7,
+ 0x1FE8, 0x1FE9, 0x1FEA, 0x1FEB, 0x1FEC, 0x1FED, 0x1FEE, 0x1FEF,
+ 0x0000, 0x0000, 0x1FF2, 0x1FFC, 0x1FF4, 0x0000, 0x1FF6, 0x1FF7,
+ 0x1FF8, 0x1FF9, 0x1FFA, 0x1FFB, 0x1FFC, 0x1FFD, 0x1FFE, 0x0000
+ };
+
+ *lower = code;
+ *upper = code;
+
+ /* Basic Latin and Latin-1 Supplement, U+0000 to U+00FF */
+ if (code <= 0x00ff) {
+ if (code >= 0x0041 && code <= 0x005a) /* A-Z */
+ *lower += 0x20;
+ else if (code >= 0x0061 && code <= 0x007a) /* a-z */
+ *upper -= 0x20;
+ else if ( (code >= 0x00c0 && code <= 0x00d6) ||
+ (code >= 0x00d8 && code <= 0x00de) )
+ *lower += 0x20;
+ else if ( (code >= 0x00e0 && code <= 0x00f6) ||
+ (code >= 0x00f8 && code <= 0x00fe) )
+ *upper -= 0x20;
+ else if (code == 0x00ff) /* y with diaeresis */
+ *upper = 0x0178;
+ else if (code == 0x00b5) /* micro sign */
+ *upper = 0x039c;
+ return;
+ }
+
+ /* Latin Extended-A, U+0100 to U+017F */
+ if (code >= 0x0100 && code <= 0x017f) {
+ if ( (code >= 0x0100 && code <= 0x012f) ||
+ (code >= 0x0132 && code <= 0x0137) ||
+ (code >= 0x014a && code <= 0x0177) ) {
+ *upper = code & ~1;
+ *lower = code | 1;
+ }
+ else if ( (code >= 0x0139 && code <= 0x0148) ||
+ (code >= 0x0179 && code <= 0x017e) ) {
+ if (code & 1)
+ *lower += 1;
+ else
+ *upper -= 1;
+ }
+ else if (code == 0x0130)
+ *lower = 0x0069;
+ else if (code == 0x0131)
+ *upper = 0x0049;
+ else if (code == 0x0178)
+ *lower = 0x00ff;
+ else if (code == 0x017f)
+ *upper = 0x0053;
+ return;
+ }
+
+ /* Latin Extended-B, U+0180 to U+024F */
+ if (code >= 0x0180 && code <= 0x024f) {
+ if (code >= 0x01cd && code <= 0x01dc) {
+ if (code & 1)
+ *lower += 1;
+ else
+ *upper -= 1;
+ }
+ else if ( (code >= 0x01de && code <= 0x01ef) ||
+ (code >= 0x01f4 && code <= 0x01f5) ||
+ (code >= 0x01f8 && code <= 0x021f) ||
+ (code >= 0x0222 && code <= 0x0233) ) {
+ *lower |= 1;
+ *upper &= ~1;
+ }
+ else if (code >= 0x0180 && code <= 0x01cc) {
+ *lower = LatinExtB_lower_mapping[code - 0x0180];
+ *upper = LatinExtB_upper_mapping[code - 0x0180];
+ }
+ else if (code == 0x01dd)
+ *upper = 0x018e;
+ else if (code == 0x01f1 || code == 0x01f2) {
+ *lower = 0x01f3;
+ *upper = 0x01f1;
+ }
+ else if (code == 0x01f3)
+ *upper = 0x01f1;
+ else if (code == 0x01f6)
+ *lower = 0x0195;
+ else if (code == 0x01f7)
+ *lower = 0x01bf;
+ else if (code == 0x0220)
+ *lower = 0x019e;
+ return;
+ }
+
+ /* IPA Extensions, U+0250 to U+02AF */
+ if (code >= 0x0253 && code <= 0x0292) {
+ *upper = IPAExt_upper_mapping[code - 0x0253];
+ }
+
+ /* Combining Diacritical Marks, U+0300 to U+036F */
+ if (code == 0x0345) {
+ *upper = 0x0399;
+ }
+
+ /* Greek and Coptic, U+0370 to U+03FF */
+ if (code >= 0x0370 && code <= 0x03ff) {
+ *lower = Greek_lower_mapping[code - 0x0370];
+ *upper = Greek_upper_mapping[code - 0x0370];
+ if (*upper == 0)
+ *upper = code;
+ if (*lower == 0)
+ *lower = code;
+ }
+
+ /* Cyrillic and Cyrillic Supplementary, U+0400 to U+052F */
+ if ( (code >= 0x0400 && code <= 0x04ff) ||
+ (code >= 0x0500 && code <= 0x052f) ) {
+ if (code >= 0x0400 && code <= 0x040f)
+ *lower += 0x50;
+ else if (code >= 0x0410 && code <= 0x042f)
+ *lower += 0x20;
+ else if (code >= 0x0430 && code <= 0x044f)
+ *upper -= 0x20;
+ else if (code >= 0x0450 && code <= 0x045f)
+ *upper -= 0x50;
+ else if ( (code >= 0x0460 && code <= 0x0481) ||
+ (code >= 0x048a && code <= 0x04bf) ||
+ (code >= 0x04d0 && code <= 0x04f5) ||
+ (code >= 0x04f8 && code <= 0x04f9) ||
+ (code >= 0x0500 && code <= 0x050f) ) {
+ *upper &= ~1;
+ *lower |= 1;
+ }
+ else if (code >= 0x04c1 && code <= 0x04ce) {
+ if (code & 1)
+ *lower += 1;
+ else
+ *upper -= 1;
+ }
+ }
+
+ /* Armenian, U+0530 to U+058F */
+ if (code >= 0x0530 && code <= 0x058f) {
+ if (code >= 0x0531 && code <= 0x0556)
+ *lower += 0x30;
+ else if (code >=0x0561 && code <= 0x0586)
+ *upper -= 0x30;
+ }
+
+ /* Latin Extended Additional, U+1E00 to U+1EFF */
+ if (code >= 0x1e00 && code <= 0x1eff) {
+ if ( (code >= 0x1e00 && code <= 0x1e95) ||
+ (code >= 0x1ea0 && code <= 0x1ef9) ) {
+ *upper &= ~1;
+ *lower |= 1;
+ }
+ else if (code == 0x1e9b)
+ *upper = 0x1e60;
+ }
+
+ /* Greek Extended, U+1F00 to U+1FFF */
+ if (code >= 0x1f00 && code <= 0x1fff) {
+ *lower = GreekExt_lower_mapping[code - 0x1f00];
+ *upper = GreekExt_upper_mapping[code - 0x1f00];
+ if (*upper == 0)
+ *upper = code;
+ if (*lower == 0)
+ *lower = code;
+ }
+
+ /* Letterlike Symbols, U+2100 to U+214F */
+ if (code >= 0x2100 && code <= 0x214f) {
+ switch (code) {
+ case 0x2126: *lower = 0x03c9; break;
+ case 0x212a: *lower = 0x006b; break;
+ case 0x212b: *lower = 0x00e5; break;
+ }
+ }
+ /* Number Forms, U+2150 to U+218F */
+ else if (code >= 0x2160 && code <= 0x216f)
+ *lower += 0x10;
+ else if (code >= 0x2170 && code <= 0x217f)
+ *upper -= 0x10;
+ /* Enclosed Alphanumerics, U+2460 to U+24FF */
+ else if (code >= 0x24b6 && code <= 0x24cf)
+ *lower += 0x1a;
+ else if (code >= 0x24d0 && code <= 0x24e9)
+ *upper -= 0x1a;
+ /* Halfwidth and Fullwidth Forms, U+FF00 to U+FFEF */
+ else if (code >= 0xff21 && code <= 0xff3a)
+ *lower += 0x20;
+ else if (code >= 0xff41 && code <= 0xff5a)
+ *upper -= 0x20;
+ /* Deseret, U+10400 to U+104FF */
+ else if (code >= 0x10400 && code <= 0x10427)
+ *lower += 0x28;
+ else if (code >= 0x10428 && code <= 0x1044f)
+ *upper -= 0x28;
+}
+
+void
+XConvertCase(
+ register KeySym sym,
+ KeySym *lower,
+ KeySym *upper)
+{
+ /* Latin 1 keysym */
+ if (sym < 0x100) {
+ UCSConvertCase(sym, lower, upper);
+ return;
+ }
+
+ /* Unicode keysym */
+ if ((sym & 0xff000000) == 0x01000000) {
+ UCSConvertCase((sym & 0x00ffffff), lower, upper);
+ *upper |= 0x01000000;
+ *lower |= 0x01000000;
+ return;
+ }
+
+ /* Legacy keysym */
+
+ *lower = sym;
+ *upper = sym;
+
+ switch(sym >> 8) {
+ case 1: /* Latin 2 */
+ /* Assume the KeySym is a legal value (ignore discontinuities) */
+ if (sym == XK_Aogonek)
+ *lower = XK_aogonek;
+ else if (sym >= XK_Lstroke && sym <= XK_Sacute)
+ *lower += (XK_lstroke - XK_Lstroke);
+ else if (sym >= XK_Scaron && sym <= XK_Zacute)
+ *lower += (XK_scaron - XK_Scaron);
+ else if (sym >= XK_Zcaron && sym <= XK_Zabovedot)
+ *lower += (XK_zcaron - XK_Zcaron);
+ else if (sym == XK_aogonek)
+ *upper = XK_Aogonek;
+ else if (sym >= XK_lstroke && sym <= XK_sacute)
+ *upper -= (XK_lstroke - XK_Lstroke);
+ else if (sym >= XK_scaron && sym <= XK_zacute)
+ *upper -= (XK_scaron - XK_Scaron);
+ else if (sym >= XK_zcaron && sym <= XK_zabovedot)
+ *upper -= (XK_zcaron - XK_Zcaron);
+ else if (sym >= XK_Racute && sym <= XK_Tcedilla)
+ *lower += (XK_racute - XK_Racute);
+ else if (sym >= XK_racute && sym <= XK_tcedilla)
+ *upper -= (XK_racute - XK_Racute);
+ break;
+ case 2: /* Latin 3 */
+ /* Assume the KeySym is a legal value (ignore discontinuities) */
+ if (sym >= XK_Hstroke && sym <= XK_Hcircumflex)
+ *lower += (XK_hstroke - XK_Hstroke);
+ else if (sym >= XK_Gbreve && sym <= XK_Jcircumflex)
+ *lower += (XK_gbreve - XK_Gbreve);
+ else if (sym >= XK_hstroke && sym <= XK_hcircumflex)
+ *upper -= (XK_hstroke - XK_Hstroke);
+ else if (sym >= XK_gbreve && sym <= XK_jcircumflex)
+ *upper -= (XK_gbreve - XK_Gbreve);
+ else if (sym >= XK_Cabovedot && sym <= XK_Scircumflex)
+ *lower += (XK_cabovedot - XK_Cabovedot);
+ else if (sym >= XK_cabovedot && sym <= XK_scircumflex)
+ *upper -= (XK_cabovedot - XK_Cabovedot);
+ break;
+ case 3: /* Latin 4 */
+ /* Assume the KeySym is a legal value (ignore discontinuities) */
+ if (sym >= XK_Rcedilla && sym <= XK_Tslash)
+ *lower += (XK_rcedilla - XK_Rcedilla);
+ else if (sym >= XK_rcedilla && sym <= XK_tslash)
+ *upper -= (XK_rcedilla - XK_Rcedilla);
+ else if (sym == XK_ENG)
+ *lower = XK_eng;
+ else if (sym == XK_eng)
+ *upper = XK_ENG;
+ else if (sym >= XK_Amacron && sym <= XK_Umacron)
+ *lower += (XK_amacron - XK_Amacron);
+ else if (sym >= XK_amacron && sym <= XK_umacron)
+ *upper -= (XK_amacron - XK_Amacron);
+ break;
+ case 6: /* Cyrillic */
+ /* Assume the KeySym is a legal value (ignore discontinuities) */
+ if (sym >= XK_Serbian_DJE && sym <= XK_Serbian_DZE)
+ *lower -= (XK_Serbian_DJE - XK_Serbian_dje);
+ else if (sym >= XK_Serbian_dje && sym <= XK_Serbian_dze)
+ *upper += (XK_Serbian_DJE - XK_Serbian_dje);
+ else if (sym >= XK_Cyrillic_YU && sym <= XK_Cyrillic_HARDSIGN)
+ *lower -= (XK_Cyrillic_YU - XK_Cyrillic_yu);
+ else if (sym >= XK_Cyrillic_yu && sym <= XK_Cyrillic_hardsign)
+ *upper += (XK_Cyrillic_YU - XK_Cyrillic_yu);
+ break;
+ case 7: /* Greek */
+ /* Assume the KeySym is a legal value (ignore discontinuities) */
+ if (sym >= XK_Greek_ALPHAaccent && sym <= XK_Greek_OMEGAaccent)
+ *lower += (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
+ else if (sym >= XK_Greek_alphaaccent && sym <= XK_Greek_omegaaccent &&
+ sym != XK_Greek_iotaaccentdieresis &&
+ sym != XK_Greek_upsilonaccentdieresis)
+ *upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
+ else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
+ *lower += (XK_Greek_alpha - XK_Greek_ALPHA);
+ else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega &&
+ sym != XK_Greek_finalsmallsigma)
+ *upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
+ break;
+ case 0x13: /* Latin 9 */
+ if (sym == XK_OE)
+ *lower = XK_oe;
+ else if (sym == XK_oe)
+ *upper = XK_OE;
+ else if (sym == XK_Ydiaeresis)
+ *lower = XK_ydiaeresis;
+ break;
+ }
+}
+
+int
+_XTranslateKey( register Display *dpy,
+ KeyCode keycode,
+ register unsigned int modifiers,
+ unsigned int *modifiers_return,
+ KeySym *keysym_return)
+{
+ int per;
+ register KeySym *syms;
+ KeySym sym, lsym, usym;
+
+ if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
+ return 0;
+ *modifiers_return = ((ShiftMask|LockMask)
+ | dpy->mode_switch | dpy->num_lock);
+ if (((int)keycode < dpy->min_keycode) || ((int)keycode > dpy->max_keycode))
+ {
+ *keysym_return = NoSymbol;
+ return 1;
+ }
+ per = dpy->keysyms_per_keycode;
+ syms = &dpy->keysyms[(keycode - dpy->min_keycode) * per];
+ while ((per > 2) && (syms[per - 1] == NoSymbol))
+ per--;
+ if ((per > 2) && (modifiers & dpy->mode_switch)) {
+ syms += 2;
+ per -= 2;
+ }
+ if ((modifiers & dpy->num_lock) &&
+ (per > 1 && (IsKeypadKey(syms[1]) || IsPrivateKeypadKey(syms[1])))) {
+ if ((modifiers & ShiftMask) ||
+ ((modifiers & LockMask) && (dpy->lock_meaning == XK_Shift_Lock)))
+ *keysym_return = syms[0];
+ else
+ *keysym_return = syms[1];
+ } else if (!(modifiers & ShiftMask) &&
+ (!(modifiers & LockMask) || (dpy->lock_meaning == NoSymbol))) {
+ if ((per == 1) || (syms[1] == NoSymbol))
+ XConvertCase(syms[0], keysym_return, &usym);
+ else
+ *keysym_return = syms[0];
+ } else if (!(modifiers & LockMask) ||
+ (dpy->lock_meaning != XK_Caps_Lock)) {
+ if ((per == 1) || ((usym = syms[1]) == NoSymbol))
+ XConvertCase(syms[0], &lsym, &usym);
+ *keysym_return = usym;
+ } else {
+ if ((per == 1) || ((sym = syms[1]) == NoSymbol))
+ sym = syms[0];
+ XConvertCase(sym, &lsym, &usym);
+ if (!(modifiers & ShiftMask) && (sym != syms[0]) &&
+ ((sym != usym) || (lsym == usym)))
+ XConvertCase(syms[0], &lsym, &usym);
+ *keysym_return = usym;
+ }
+ if (*keysym_return == XK_VoidSymbol)
+ *keysym_return = NoSymbol;
+ return 1;
+}
+
+int
+_XTranslateKeySym(
+ Display *dpy,
+ register KeySym symbol,
+ unsigned int modifiers,
+ char *buffer,
+ int nbytes)
+{
+ register struct _XKeytrans *p;
+ int length;
+ unsigned long hiBytes;
+ register unsigned char c;
+
+ if (!symbol)
+ return 0;
+ /* see if symbol rebound, if so, return that string. */
+ for (p = dpy->key_bindings; p; p = p->next) {
+ if (((modifiers & AllMods) == p->state) && (symbol == p->key)) {
+ length = p->len;
+ if (length > nbytes) length = nbytes;
+ memcpy (buffer, p->string, length);
+ return length;
+ }
+ }
+ /* try to convert to Latin-1, handling control */
+ hiBytes = symbol >> 8;
+ if (!(nbytes &&
+ ((hiBytes == 0) ||
+ ((hiBytes == 0xFF) &&
+ (((symbol >= XK_BackSpace) && (symbol <= XK_Clear)) ||
+ (symbol == XK_Return) ||
+ (symbol == XK_Escape) ||
+ (symbol == XK_KP_Space) ||
+ (symbol == XK_KP_Tab) ||
+ (symbol == XK_KP_Enter) ||
+ ((symbol >= XK_KP_Multiply) && (symbol <= XK_KP_9)) ||
+ (symbol == XK_KP_Equal) ||
+ (symbol == XK_Delete))))))
+ return 0;
+
+ /* if X keysym, convert to ascii by grabbing low 7 bits */
+ if (symbol == XK_KP_Space)
+ c = XK_space & 0x7F; /* patch encoding botch */
+ else if (hiBytes == 0xFF)
+ c = symbol & 0x7F;
+ else
+ c = symbol & 0xFF;
+ /* only apply Control key if it makes sense, else ignore it */
+ if (modifiers & ControlMask) {
+ if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
+ else if (c == '2') c = '\000';
+ else if (c >= '3' && c <= '7') c -= ('3' - '\033');
+ else if (c == '8') c = '\177';
+ else if (c == '/') c = '_' & 0x1F;
+ }
+ buffer[0] = c;
+ return 1;
+}
+
+/*ARGSUSED*/
+int
+XLookupString (
+ register XKeyEvent *event,
+ char *buffer, /* buffer */
+ int nbytes, /* space in buffer for characters */
+ KeySym *keysym,
+ XComposeStatus *status) /* not implemented */
+{
+ unsigned int modifiers;
+ KeySym symbol;
+
+ if (! _XTranslateKey(event->display, event->keycode, event->state,
+ &modifiers, &symbol))
+ return 0;
+
+#ifdef USE_OWN_COMPOSE
+ if ( status ) {
+ static int been_here= 0;
+ if ( !been_here ) {
+ XimCompInitTables();
+ been_here = 1;
+ }
+ if ( !XimCompLegalStatus(status) ) {
+ status->compose_ptr = NULL;
+ status->chars_matched = 0;
+ }
+ if ( ((status->chars_matched>0)&&(status->compose_ptr!=NULL)) ||
+ XimCompIsComposeKey(symbol,event->keycode,status) ) {
+ XimCompRtrn rtrn;
+ switch (XimCompProcessSym(status,symbol,&rtrn)) {
+ case XIM_COMP_IGNORE:
+ break;
+ case XIM_COMP_IN_PROGRESS:
+ if ( keysym!=NULL )
+ *keysym = NoSymbol;
+ return 0;
+ case XIM_COMP_FAIL:
+ {
+ int n = 0, len= 0;
+ for (n=len=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
+ if ( nbytes-len > 0 ) {
+ len+= _XTranslateKeySym(event->display,rtrn.sym[n],
+ event->state,
+ buffer+len,nbytes-len);
+ }
+ }
+ if ( keysym!=NULL ) {
+ if ( n==1 ) *keysym = rtrn.sym[0];
+ else *keysym = NoSymbol;
+ }
+ return len;
+ }
+ case XIM_COMP_SUCCEED:
+ {
+ int len,n = 0;
+
+ symbol = rtrn.matchSym;
+ if ( keysym!=NULL ) *keysym = symbol;
+ if ( rtrn.str[0]!='\0' ) {
+ strncpy(buffer,rtrn.str,nbytes-1);
+ buffer[nbytes-1]= '\0';
+ len = strlen(buffer);
+ }
+ else {
+ len = _XTranslateKeySym(event->display,symbol,
+ event->state,
+ buffer,nbytes);
+ }
+ for (n=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
+ if ( nbytes-len > 0 ) {
+ len+= _XTranslateKeySym(event->display,rtrn.sym[n],
+ event->state,
+ buffer+len,nbytes-len);
+ }
+ }
+ return len;
+ }
+ }
+ }
+ }
+#endif
+
+ if (keysym)
+ *keysym = symbol;
+ /* arguable whether to use (event->state & ~modifiers) here */
+ return _XTranslateKeySym(event->display, symbol, event->state,
+ buffer, nbytes);
+}
+
+static void
+_XFreeKeyBindings(
+ Display *dpy)
+{
+ register struct _XKeytrans *p, *np;
+
+ for (p = dpy->key_bindings; p; p = np) {
+ np = p->next;
+ Xfree(p->string);
+ Xfree((char *)p->modifiers);
+ Xfree((char *)p);
+ }
+}
+
+int
+XRebindKeysym (
+ Display *dpy,
+ KeySym keysym,
+ KeySym *mlist,
+ int nm, /* number of modifiers in mlist */
+ _Xconst unsigned char *str,
+ int nbytes)
+{
+ register struct _XKeytrans *tmp, *p;
+ int nb;
+
+ if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
+ return 0;
+ LockDisplay(dpy);
+ tmp = dpy->key_bindings;
+ nb = sizeof(KeySym) * nm;
+
+ if ((! (p = (struct _XKeytrans *) Xmalloc( sizeof(struct _XKeytrans)))) ||
+ ((! (p->string = (char *) Xmalloc( (unsigned) nbytes))) &&
+ (nbytes > 0)) ||
+ ((! (p->modifiers = (KeySym *) Xmalloc( (unsigned) nb))) &&
+ (nb > 0))) {
+ if (p) {
+ if (p->string) Xfree(p->string);
+ if (p->modifiers) Xfree((char *) p->modifiers);
+ Xfree((char *) p);
+ }
+ UnlockDisplay(dpy);
+ return 0;
+ }
+
+ dpy->key_bindings = p;
+ dpy->free_funcs->key_bindings = _XFreeKeyBindings;
+ p->next = tmp; /* chain onto list */
+ memcpy (p->string, (char *) str, nbytes);
+ p->len = nbytes;
+ memcpy ((char *) p->modifiers, (char *) mlist, nb);
+ p->key = keysym;
+ p->mlen = nm;
+ ComputeMaskFromKeytrans(dpy, p);
+ UnlockDisplay(dpy);
+ return 0;
+}
+
+unsigned
+_XKeysymToModifiers(
+ Display *dpy,
+ KeySym ks)
+{
+ CARD8 code,mods;
+ register KeySym *kmax;
+ register KeySym *k;
+ register XModifierKeymap *m;
+
+ if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
+ return 0;
+ kmax = dpy->keysyms +
+ (dpy->max_keycode - dpy->min_keycode + 1) * dpy->keysyms_per_keycode;
+ k = dpy->keysyms;
+ m = dpy->modifiermap;
+ mods= 0;
+ while (k<kmax) {
+ if (*k == ks ) {
+ register int j = m->max_keypermod<<3;
+
+ code=(((k-dpy->keysyms)/dpy->keysyms_per_keycode)+dpy->min_keycode);
+
+ while (--j >= 0) {
+ if (code == m->modifiermap[j])
+ mods|= (1<<(j/m->max_keypermod));
+ }
+ }
+ k++;
+ }
+ return mods;
+}
+
+/*
+ * given a list of modifiers, computes the mask necessary for later matching.
+ * This routine must lookup the key in the Keymap and then search to see
+ * what modifier it is bound to, if any. Sets the AnyModifier bit if it
+ * can't map some keysym to a modifier.
+ */
+static void
+ComputeMaskFromKeytrans(
+ Display *dpy,
+ register struct _XKeytrans *p)
+{
+ register int i;
+
+ p->state = AnyModifier;
+ for (i = 0; i < p->mlen; i++) {
+ p->state|= XkbKeysymToModifiers(dpy,p->modifiers[i]);
+ }
+ p->state &= AllMods;
+}
diff --git a/libX11/src/LiHosts.c b/libX11/src/LiHosts.c
index ae9fa16cf..4e52b740f 100644
--- a/libX11/src/LiHosts.c
+++ b/libX11/src/LiHosts.c
@@ -1,157 +1,156 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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, and/or sell copies of the Software, and to permit persons
-to whom the Software is furnished to do so, provided that the above
-copyright notice(s) and this permission notice appear in all copies of
-the Software and that both the above copyright notice(s) and this
-permission notice appear in supporting documentation.
-
-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
-OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
-
-Except as contained in this notice, the name of a copyright holder
-shall not be used in advertising or otherwise to promote the sale, use
-or other dealings in this Software without prior written authorization
-of the copyright holder.
-
-X Window System is a trademark of The Open Group.
-
-*/
-
-/*
- * Copyright 2004 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.
- */
-
-/* This can really be considered an os dependent routine */
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-/*
- * can be freed using XFree.
- */
-
-XHostAddress *XListHosts (
- register Display *dpy,
- int *nhosts, /* RETURN */
- Bool *enabled) /* RETURN */
-{
- register XHostAddress *outbuf = NULL, *op;
- xListHostsReply reply;
- long nbytes;
- unsigned char *buf, *bp;
- register unsigned i;
- register xListHostsReq *req;
- XServerInterpretedAddress *sip;
-
- *nhosts = 0;
- LockDisplay(dpy);
- GetReq (ListHosts, req);
-
- if (!_XReply (dpy, (xReply *) &reply, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (XHostAddress *) NULL;
- }
-
- if (reply.nHosts) {
- nbytes = reply.length << 2; /* compute number of bytes in reply */
-
- op = outbuf = (XHostAddress *)
- Xmalloc((unsigned) (nbytes +
- (reply.nHosts * sizeof(XHostAddress)) +
- (reply.nHosts * sizeof(XServerInterpretedAddress))));
-
- if (! outbuf) {
- _XEatData(dpy, (unsigned long) nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return (XHostAddress *) NULL;
- }
- sip = (XServerInterpretedAddress *)
- (((unsigned char *) outbuf) + (reply.nHosts * sizeof(XHostAddress)));
- bp = buf = ((unsigned char *) sip)
- + (reply.nHosts * sizeof(XServerInterpretedAddress));
-
- _XRead (dpy, (char *) buf, nbytes);
-
- for (i = 0; i < reply.nHosts; i++) {
-#ifdef WORD64
- xHostEntry xhe;
- memcpy((char *)&xhe, bp, SIZEOF(xHostEntry));
- op->family = xhe.family;
- op->length = xhe.length;
-#else
- op->family = ((xHostEntry *) bp)->family;
- op->length =((xHostEntry *) bp)->length;
-#endif
- if (op->family == FamilyServerInterpreted) {
- char *tp = (char *) (bp + SIZEOF(xHostEntry));
- char *vp = memchr(tp, 0, op->length);
-
- if (vp != NULL) {
- sip->type = tp;
- sip->typelength = vp - tp;
- sip->value = vp + 1;
- sip->valuelength = op->length - (sip->typelength + 1);
- } else {
- sip->type = sip->value = NULL;
- sip->typelength = sip->valuelength = 0;
- }
- op->address = (char *) sip;
- sip++;
- } else {
- op->address = (char *) (bp + SIZEOF(xHostEntry));
- }
- bp += SIZEOF(xHostEntry) + (((op->length + 3) >> 2) << 2);
- op++;
- }
- }
-
- *enabled = reply.enabled;
- *nhosts = reply.nHosts;
- UnlockDisplay(dpy);
- SyncHandle();
- return (outbuf);
-}
-
-
-
-
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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, and/or sell copies of the Software, and to permit persons
+to whom the Software is furnished to do so, provided that the above
+copyright notice(s) and this permission notice appear in all copies of
+the Software and that both the above copyright notice(s) and this
+permission notice appear in supporting documentation.
+
+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
+OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+
+Except as contained in this notice, the name of a copyright holder
+shall not be used in advertising or otherwise to promote the sale, use
+or other dealings in this Software without prior written authorization
+of the copyright holder.
+
+X Window System is a trademark of The Open Group.
+
+*/
+
+/*
+ * Copyright 2004 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.
+ */
+
+/* This can really be considered an os dependent routine */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+/*
+ * can be freed using XFree.
+ */
+
+XHostAddress *XListHosts (
+ register Display *dpy,
+ int *nhosts, /* RETURN */
+ Bool *enabled) /* RETURN */
+{
+ register XHostAddress *outbuf = NULL, *op;
+ xListHostsReply reply;
+ long nbytes;
+ unsigned char *buf, *bp;
+ register unsigned i;
+ register xListHostsReq *req;
+ XServerInterpretedAddress *sip;
+
+ *nhosts = 0;
+ LockDisplay(dpy);
+ GetReq (ListHosts, req);
+
+ if (!_XReply (dpy, (xReply *) &reply, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (XHostAddress *) NULL;
+ }
+
+ if (reply.nHosts) {
+ nbytes = reply.length << 2; /* compute number of bytes in reply */
+
+ op = outbuf = (XHostAddress *)
+ Xmalloc((unsigned) (nbytes +
+ (reply.nHosts * sizeof(XHostAddress)) +
+ (reply.nHosts * sizeof(XServerInterpretedAddress))));
+
+ if (! outbuf) {
+ _XEatData(dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (XHostAddress *) NULL;
+ }
+ sip = (XServerInterpretedAddress *)
+ (((unsigned char *) outbuf) + (reply.nHosts * sizeof(XHostAddress)));
+ bp = buf = ((unsigned char *) sip)
+ + (reply.nHosts * sizeof(XServerInterpretedAddress));
+
+ _XRead (dpy, (char *) buf, nbytes);
+
+ for (i = 0; i < reply.nHosts; i++) {
+#ifdef WORD64
+ xHostEntry xhe;
+ memcpy((char *)&xhe, bp, SIZEOF(xHostEntry));
+ op->family = xhe.family;
+ op->length = xhe.length;
+#else
+ op->family = ((xHostEntry *) bp)->family;
+ op->length =((xHostEntry *) bp)->length;
+#endif
+ if (op->family == FamilyServerInterpreted) {
+ char *tp = (char *) (bp + SIZEOF(xHostEntry));
+ char *vp = memchr(tp, 0, op->length);
+
+ if (vp != NULL) {
+ sip->type = tp;
+ sip->typelength = vp - tp;
+ sip->value = vp + 1;
+ sip->valuelength = op->length - (sip->typelength + 1);
+ } else {
+ sip->type = sip->value = NULL;
+ sip->typelength = sip->valuelength = 0;
+ }
+ op->address = (char *) sip;
+ sip++;
+ } else {
+ op->address = (char *) (bp + SIZEOF(xHostEntry));
+ }
+ bp += SIZEOF(xHostEntry) + (((op->length + 3) >> 2) << 2);
+ op++;
+ }
+ }
+
+ *enabled = reply.enabled;
+ *nhosts = reply.nHosts;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (outbuf);
+}
+
+
+
+
+
diff --git a/libX11/src/LiICmaps.c b/libX11/src/LiICmaps.c
index d2cb221d8..841d90653 100644
--- a/libX11/src/LiICmaps.c
+++ b/libX11/src/LiICmaps.c
@@ -1,72 +1,71 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Colormap *XListInstalledColormaps(
- register Display *dpy,
- Window win,
- int *n) /* RETURN */
-{
- long nbytes;
- Colormap *cmaps;
- xListInstalledColormapsReply rep;
- register xResourceReq *req;
-
- LockDisplay(dpy);
- GetResReq(ListInstalledColormaps, win, req);
-
- if(_XReply(dpy, (xReply *) &rep, 0, xFalse) == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- *n = 0;
- return((Colormap *) NULL);
- }
-
- if (rep.nColormaps) {
- nbytes = rep.nColormaps * sizeof(Colormap);
- cmaps = (Colormap *) Xmalloc((unsigned) nbytes);
- nbytes = rep.nColormaps << 2;
- if (! cmaps) {
- _XEatData(dpy, (unsigned long) nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return((Colormap *) NULL);
- }
- _XRead32 (dpy, (long *) cmaps, nbytes);
- }
- else cmaps = (Colormap *) NULL;
-
- *n = rep.nColormaps;
- UnlockDisplay(dpy);
- SyncHandle();
- return(cmaps);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Colormap *XListInstalledColormaps(
+ register Display *dpy,
+ Window win,
+ int *n) /* RETURN */
+{
+ long nbytes;
+ Colormap *cmaps;
+ xListInstalledColormapsReply rep;
+ register xResourceReq *req;
+
+ LockDisplay(dpy);
+ GetResReq(ListInstalledColormaps, win, req);
+
+ if(_XReply(dpy, (xReply *) &rep, 0, xFalse) == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ *n = 0;
+ return((Colormap *) NULL);
+ }
+
+ if (rep.nColormaps) {
+ nbytes = rep.nColormaps * sizeof(Colormap);
+ cmaps = (Colormap *) Xmalloc((unsigned) nbytes);
+ nbytes = rep.nColormaps << 2;
+ if (! cmaps) {
+ _XEatData(dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return((Colormap *) NULL);
+ }
+ _XRead32 (dpy, (long *) cmaps, nbytes);
+ }
+ else cmaps = (Colormap *) NULL;
+
+ *n = rep.nColormaps;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(cmaps);
+}
+
diff --git a/libX11/src/LiProps.c b/libX11/src/LiProps.c
index 344f990d3..52fcb20c6 100644
--- a/libX11/src/LiProps.c
+++ b/libX11/src/LiProps.c
@@ -1,70 +1,69 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Atom *XListProperties(
- register Display *dpy,
- Window window,
- int *n_props) /* RETURN */
-{
- long nbytes;
- xListPropertiesReply rep;
- Atom *properties;
- register xResourceReq *req;
-
- LockDisplay(dpy);
- GetResReq(ListProperties, window, req);
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- *n_props = 0;
- UnlockDisplay(dpy);
- SyncHandle();
- return ((Atom *) NULL);
- }
-
- if (rep.nProperties) {
- nbytes = rep.nProperties * sizeof(Atom);
- properties = (Atom *) Xmalloc ((unsigned) nbytes);
- nbytes = rep.nProperties << 2;
- if (! properties) {
- _XEatData(dpy, (unsigned long) nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return (Atom *) NULL;
- }
- _XRead32 (dpy, (long *) properties, nbytes);
- }
- else properties = (Atom *) NULL;
-
- *n_props = rep.nProperties;
- UnlockDisplay(dpy);
- SyncHandle();
- return (properties);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Atom *XListProperties(
+ register Display *dpy,
+ Window window,
+ int *n_props) /* RETURN */
+{
+ long nbytes;
+ xListPropertiesReply rep;
+ Atom *properties;
+ register xResourceReq *req;
+
+ LockDisplay(dpy);
+ GetResReq(ListProperties, window, req);
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ *n_props = 0;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return ((Atom *) NULL);
+ }
+
+ if (rep.nProperties) {
+ nbytes = rep.nProperties * sizeof(Atom);
+ properties = (Atom *) Xmalloc ((unsigned) nbytes);
+ nbytes = rep.nProperties << 2;
+ if (! properties) {
+ _XEatData(dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (Atom *) NULL;
+ }
+ _XRead32 (dpy, (long *) properties, nbytes);
+ }
+ else properties = (Atom *) NULL;
+
+ *n_props = rep.nProperties;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (properties);
+}
diff --git a/libX11/src/ListExt.c b/libX11/src/ListExt.c
index 5a41ec35a..76d19c4b0 100644
--- a/libX11/src/ListExt.c
+++ b/libX11/src/ListExt.c
@@ -1,98 +1,97 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-char **XListExtensions(
- register Display *dpy,
- int *nextensions) /* RETURN */
-{
- xListExtensionsReply rep;
- char **list;
- char *ch;
- register unsigned i;
- register int length;
- register xReq *req;
- register long rlen;
-
- LockDisplay(dpy);
- GetEmptyReq (ListExtensions, req);
-
- if (! _XReply (dpy, (xReply *) &rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (char **) NULL;
- }
-
- if (rep.nExtensions) {
- list = (char **) Xmalloc (
- (unsigned)(rep.nExtensions * sizeof (char *)));
- rlen = rep.length << 2;
- ch = (char *) Xmalloc ((unsigned) rlen + 1);
- /* +1 to leave room for last null-terminator */
-
- if ((!list) || (!ch)) {
- if (list) Xfree((char *) list);
- if (ch) Xfree((char *) ch);
- _XEatData(dpy, (unsigned long) rlen);
- UnlockDisplay(dpy);
- SyncHandle();
- return (char **) NULL;
- }
-
- _XReadPad (dpy, ch, rlen);
- /*
- * unpack into null terminated strings.
- */
- length = *ch;
- for (i = 0; i < rep.nExtensions; i++) {
- list[i] = ch+1; /* skip over length */
- ch += length + 1; /* find next length ... */
- length = *ch;
- *ch = '\0'; /* and replace with null-termination */
- }
- }
- else list = (char **) NULL;
-
- *nextensions = rep.nExtensions;
- UnlockDisplay(dpy);
- SyncHandle();
- return (list);
-}
-
-int
-XFreeExtensionList (char **list)
-{
- if (list != NULL) {
- Xfree (list[0]-1);
- Xfree ((char *)list);
- }
- return 1;
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+char **XListExtensions(
+ register Display *dpy,
+ int *nextensions) /* RETURN */
+{
+ xListExtensionsReply rep;
+ char **list;
+ char *ch;
+ register unsigned i;
+ register int length;
+ register xReq *req;
+ register long rlen;
+
+ LockDisplay(dpy);
+ GetEmptyReq (ListExtensions, req);
+
+ if (! _XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (char **) NULL;
+ }
+
+ if (rep.nExtensions) {
+ list = (char **) Xmalloc (
+ (unsigned)(rep.nExtensions * sizeof (char *)));
+ rlen = rep.length << 2;
+ ch = (char *) Xmalloc ((unsigned) rlen + 1);
+ /* +1 to leave room for last null-terminator */
+
+ if ((!list) || (!ch)) {
+ if (list) Xfree((char *) list);
+ if (ch) Xfree((char *) ch);
+ _XEatData(dpy, (unsigned long) rlen);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (char **) NULL;
+ }
+
+ _XReadPad (dpy, ch, rlen);
+ /*
+ * unpack into null terminated strings.
+ */
+ length = *ch;
+ for (i = 0; i < rep.nExtensions; i++) {
+ list[i] = ch+1; /* skip over length */
+ ch += length + 1; /* find next length ... */
+ length = *ch;
+ *ch = '\0'; /* and replace with null-termination */
+ }
+ }
+ else list = (char **) NULL;
+
+ *nextensions = rep.nExtensions;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (list);
+}
+
+int
+XFreeExtensionList (char **list)
+{
+ if (list != NULL) {
+ Xfree (list[0]-1);
+ Xfree ((char *)list);
+ }
+ return 1;
+}
diff --git a/libX11/src/LookupCol.c b/libX11/src/LookupCol.c
index 04c700e44..8569343a2 100644
--- a/libX11/src/LookupCol.c
+++ b/libX11/src/LookupCol.c
@@ -1,105 +1,104 @@
-/*
-
-Copyright 1985, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "Xcmsint.h"
-
-
-Status
-XLookupColor (
- register Display *dpy,
- Colormap cmap,
- _Xconst char *spec,
- XColor *def,
- XColor *scr)
-{
- register int n;
- xLookupColorReply reply;
- register xLookupColorReq *req;
- XcmsCCC ccc;
- XcmsColor cmsColor_exact;
-
-#ifdef XCMS
- /*
- * Let's Attempt to use Xcms and i18n approach to Parse Color
- */
- if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
- const char *tmpName = spec;
-
- switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact,
- XcmsRGBFormat)) {
- case XcmsSuccess:
- case XcmsSuccessWithCompression:
- _XcmsRGB_to_XColor(&cmsColor_exact, def, 1);
- memcpy((char *)scr, (char *)def, sizeof(XColor));
- _XUnresolveColor(ccc, scr);
- return(1);
- case XcmsFailure:
- case _XCMS_NEWNAME:
- /*
- * if the result was _XCMS_NEWNAME tmpName points to
- * a string in cmsColNm.c:pairs table, for example,
- * gray70 would become tekhvc:0.0/70.0/0.0
- */
- break;
- }
- }
-#endif
-
- /*
- * Xcms and i18n methods failed, so lets pass it to the server
- * for parsing.
- */
-
- n = strlen (spec);
- LockDisplay(dpy);
- GetReq (LookupColor, req);
- req->cmap = cmap;
- req->nbytes = n;
- req->length += (n + 3) >> 2;
- Data (dpy, spec, (long)n);
- if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (0);
- }
- def->red = reply.exactRed;
- def->green = reply.exactGreen;
- def->blue = reply.exactBlue;
-
- scr->red = reply.screenRed;
- scr->green = reply.screenGreen;
- scr->blue = reply.screenBlue;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return (1);
-}
+/*
+
+Copyright 1985, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+
+
+Status
+XLookupColor (
+ register Display *dpy,
+ Colormap cmap,
+ _Xconst char *spec,
+ XColor *def,
+ XColor *scr)
+{
+ register int n;
+ xLookupColorReply reply;
+ register xLookupColorReq *req;
+ XcmsCCC ccc;
+ XcmsColor cmsColor_exact;
+
+#ifdef XCMS
+ /*
+ * Let's Attempt to use Xcms and i18n approach to Parse Color
+ */
+ if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
+ const char *tmpName = spec;
+
+ switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact,
+ XcmsRGBFormat)) {
+ case XcmsSuccess:
+ case XcmsSuccessWithCompression:
+ _XcmsRGB_to_XColor(&cmsColor_exact, def, 1);
+ memcpy((char *)scr, (char *)def, sizeof(XColor));
+ _XUnresolveColor(ccc, scr);
+ return(1);
+ case XcmsFailure:
+ case _XCMS_NEWNAME:
+ /*
+ * if the result was _XCMS_NEWNAME tmpName points to
+ * a string in cmsColNm.c:pairs table, for example,
+ * gray70 would become tekhvc:0.0/70.0/0.0
+ */
+ break;
+ }
+ }
+#endif
+
+ /*
+ * Xcms and i18n methods failed, so lets pass it to the server
+ * for parsing.
+ */
+
+ n = strlen (spec);
+ LockDisplay(dpy);
+ GetReq (LookupColor, req);
+ req->cmap = cmap;
+ req->nbytes = n;
+ req->length += (n + 3) >> 2;
+ Data (dpy, spec, (long)n);
+ if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (0);
+ }
+ def->red = reply.exactRed;
+ def->green = reply.exactGreen;
+ def->blue = reply.exactBlue;
+
+ scr->red = reply.screenRed;
+ scr->green = reply.screenGreen;
+ scr->blue = reply.screenBlue;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (1);
+}
diff --git a/libX11/src/MaskEvent.c b/libX11/src/MaskEvent.c
index ec1672b22..dca019037 100644
--- a/libX11/src/MaskEvent.c
+++ b/libX11/src/MaskEvent.c
@@ -1,81 +1,80 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-extern long const _Xevent_to_mask[];
-#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
-#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
- Button4MotionMask|Button5MotionMask)
-
-/*
- * return the next event in the queue matching one of the events in the mask.
- * If no event, flush output, and wait until match succeeds.
- * Events earlier in the queue are not discarded.
- */
-
-int
-XMaskEvent (
- register Display *dpy,
- long mask, /* Selected event mask. */
- register XEvent *event) /* XEvent to be filled in. */
-{
- register _XQEvent *prev, *qelt;
- unsigned long qe_serial = 0;
-
- LockDisplay(dpy);
-
- /* Delete unclaimed cookies */
- _XFreeEventCookies(dpy);
-
- prev = NULL;
- while (1) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if ((qelt->event.type < GenericEvent) &&
- (_Xevent_to_mask[qelt->event.type] & mask) &&
- ((qelt->event.type != MotionNotify) ||
- (mask & AllPointers) ||
- (mask & AllButtons & qelt->event.xmotion.state))) {
- *event = qelt->event;
- _XDeq(dpy, prev, qelt);
- UnlockDisplay(dpy);
- return 0;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- _XReadEvents(dpy);
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+extern long const _Xevent_to_mask[];
+#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
+#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
+ Button4MotionMask|Button5MotionMask)
+
+/*
+ * return the next event in the queue matching one of the events in the mask.
+ * If no event, flush output, and wait until match succeeds.
+ * Events earlier in the queue are not discarded.
+ */
+
+int
+XMaskEvent (
+ register Display *dpy,
+ long mask, /* Selected event mask. */
+ register XEvent *event) /* XEvent to be filled in. */
+{
+ register _XQEvent *prev, *qelt;
+ unsigned long qe_serial = 0;
+
+ LockDisplay(dpy);
+
+ /* Delete unclaimed cookies */
+ _XFreeEventCookies(dpy);
+
+ prev = NULL;
+ while (1) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if ((qelt->event.type < GenericEvent) &&
+ (_Xevent_to_mask[qelt->event.type] & mask) &&
+ ((qelt->event.type != MotionNotify) ||
+ (mask & AllPointers) ||
+ (mask & AllButtons & qelt->event.xmotion.state))) {
+ *event = qelt->event;
+ _XDeq(dpy, prev, qelt);
+ UnlockDisplay(dpy);
+ return 0;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ _XReadEvents(dpy);
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+}
diff --git a/libX11/src/ModMap.c b/libX11/src/ModMap.c
index 28c2da5a4..149bcbd20 100644
--- a/libX11/src/ModMap.c
+++ b/libX11/src/ModMap.c
@@ -1,182 +1,181 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-XModifierKeymap *
-XGetModifierMapping(register Display *dpy)
-{
- xGetModifierMappingReply rep;
- register xReq *req;
- unsigned long nbytes;
- XModifierKeymap *res;
-
- LockDisplay(dpy);
- GetEmptyReq(GetModifierMapping, req);
- (void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
-
- nbytes = (unsigned long)rep.length << 2;
- res = (XModifierKeymap *) Xmalloc(sizeof (XModifierKeymap));
- if (res) res->modifiermap = (KeyCode *) Xmalloc ((unsigned) nbytes);
- if ((! res) || (! res->modifiermap)) {
- if (res) Xfree((char *) res);
- res = (XModifierKeymap *) NULL;
- _XEatData(dpy, nbytes);
- } else {
- _XReadPad(dpy, (char *) res->modifiermap, (long) nbytes);
- res->max_keypermod = rep.numKeyPerModifier;
- }
-
- UnlockDisplay(dpy);
- SyncHandle();
- return (res);
-}
-
-/*
- * Returns:
- * 0 Success
- * 1 Busy - one or more old or new modifiers are down
- * 2 Failed - one or more new modifiers unacceptable
- */
-int
-XSetModifierMapping(
- register Display *dpy,
- register XModifierKeymap *modifier_map)
-{
- register xSetModifierMappingReq *req;
- xSetModifierMappingReply rep;
- int mapSize = modifier_map->max_keypermod << 3; /* 8 modifiers */
-
- LockDisplay(dpy);
- GetReqExtra(SetModifierMapping, mapSize, req);
-
- req->numKeyPerModifier = modifier_map->max_keypermod;
-
- memcpy((char *) NEXTPTR(req,xSetModifierMappingReq),
- (char *) modifier_map->modifiermap,
- mapSize);
-
- (void) _XReply(dpy, (xReply *) & rep,
- (SIZEOF(xSetModifierMappingReply) - SIZEOF(xReply)) >> 2, xTrue);
- UnlockDisplay(dpy);
- SyncHandle();
- return (rep.success);
-}
-
-XModifierKeymap *
-XNewModifiermap(int keyspermodifier)
-{
- XModifierKeymap *res = (XModifierKeymap *) Xmalloc((sizeof (XModifierKeymap)));
- if (res) {
- res->max_keypermod = keyspermodifier;
- res->modifiermap = (keyspermodifier > 0 ?
- (KeyCode *) Xmalloc((unsigned) (8 * keyspermodifier))
- : (KeyCode *) NULL);
- if (keyspermodifier && (res->modifiermap == NULL)) {
- Xfree((char *) res);
- return (XModifierKeymap *) NULL;
- }
- }
- return (res);
-}
-
-
-int
-XFreeModifiermap(XModifierKeymap *map)
-{
- if (map) {
- if (map->modifiermap)
- Xfree((char *) map->modifiermap);
- Xfree((char *) map);
- }
- return 1;
-}
-
-XModifierKeymap *
-XInsertModifiermapEntry(XModifierKeymap *map,
-#if NeedWidePrototypes
- unsigned int keycode,
-#else
- KeyCode keycode,
-#endif
- int modifier)
-{
- XModifierKeymap *newmap;
- int i,
- row = modifier * map->max_keypermod,
- newrow,
- lastrow;
-
- for (i=0; i<map->max_keypermod; i++) {
- if (map->modifiermap[ row+i ] == keycode)
- return(map); /* already in the map */
- if (map->modifiermap[ row+i ] == 0) {
- map->modifiermap[ row+i ] = keycode;
- return(map); /* we added it without stretching the map */
- }
- }
-
- /* stretch the map */
- if ((newmap = XNewModifiermap(map->max_keypermod+1)) == NULL)
- return (XModifierKeymap *) NULL;
- newrow = row = 0;
- lastrow = newmap->max_keypermod * 8;
- while (newrow < lastrow) {
- for (i=0; i<map->max_keypermod; i++)
- newmap->modifiermap[ newrow+i ] = map->modifiermap[ row+i ];
- newmap->modifiermap[ newrow+i ] = 0;
- row += map->max_keypermod;
- newrow += newmap->max_keypermod;
- }
- (void) XFreeModifiermap(map);
- newrow = newmap->max_keypermod * modifier + newmap->max_keypermod - 1;
- newmap->modifiermap[ newrow ] = keycode;
- return(newmap);
-}
-
-XModifierKeymap *
-XDeleteModifiermapEntry(XModifierKeymap *map,
-#if NeedWidePrototypes
- unsigned int keycode,
-#else
- KeyCode keycode,
-#endif
- int modifier)
-{
- int i,
- row = modifier * map->max_keypermod;
-
- for (i=0; i<map->max_keypermod; i++) {
- if (map->modifiermap[ row+i ] == keycode)
- map->modifiermap[ row+i ] = 0;
- }
- /* should we shrink the map?? */
- return (map);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+XModifierKeymap *
+XGetModifierMapping(register Display *dpy)
+{
+ xGetModifierMappingReply rep;
+ register xReq *req;
+ unsigned long nbytes;
+ XModifierKeymap *res;
+
+ LockDisplay(dpy);
+ GetEmptyReq(GetModifierMapping, req);
+ (void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
+
+ nbytes = (unsigned long)rep.length << 2;
+ res = (XModifierKeymap *) Xmalloc(sizeof (XModifierKeymap));
+ if (res) res->modifiermap = (KeyCode *) Xmalloc ((unsigned) nbytes);
+ if ((! res) || (! res->modifiermap)) {
+ if (res) Xfree((char *) res);
+ res = (XModifierKeymap *) NULL;
+ _XEatData(dpy, nbytes);
+ } else {
+ _XReadPad(dpy, (char *) res->modifiermap, (long) nbytes);
+ res->max_keypermod = rep.numKeyPerModifier;
+ }
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (res);
+}
+
+/*
+ * Returns:
+ * 0 Success
+ * 1 Busy - one or more old or new modifiers are down
+ * 2 Failed - one or more new modifiers unacceptable
+ */
+int
+XSetModifierMapping(
+ register Display *dpy,
+ register XModifierKeymap *modifier_map)
+{
+ register xSetModifierMappingReq *req;
+ xSetModifierMappingReply rep;
+ int mapSize = modifier_map->max_keypermod << 3; /* 8 modifiers */
+
+ LockDisplay(dpy);
+ GetReqExtra(SetModifierMapping, mapSize, req);
+
+ req->numKeyPerModifier = modifier_map->max_keypermod;
+
+ memcpy((char *) NEXTPTR(req,xSetModifierMappingReq),
+ (char *) modifier_map->modifiermap,
+ mapSize);
+
+ (void) _XReply(dpy, (xReply *) & rep,
+ (SIZEOF(xSetModifierMappingReply) - SIZEOF(xReply)) >> 2, xTrue);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (rep.success);
+}
+
+XModifierKeymap *
+XNewModifiermap(int keyspermodifier)
+{
+ XModifierKeymap *res = (XModifierKeymap *) Xmalloc((sizeof (XModifierKeymap)));
+ if (res) {
+ res->max_keypermod = keyspermodifier;
+ res->modifiermap = (keyspermodifier > 0 ?
+ (KeyCode *) Xmalloc((unsigned) (8 * keyspermodifier))
+ : (KeyCode *) NULL);
+ if (keyspermodifier && (res->modifiermap == NULL)) {
+ Xfree((char *) res);
+ return (XModifierKeymap *) NULL;
+ }
+ }
+ return (res);
+}
+
+
+int
+XFreeModifiermap(XModifierKeymap *map)
+{
+ if (map) {
+ if (map->modifiermap)
+ Xfree((char *) map->modifiermap);
+ Xfree((char *) map);
+ }
+ return 1;
+}
+
+XModifierKeymap *
+XInsertModifiermapEntry(XModifierKeymap *map,
+#if NeedWidePrototypes
+ unsigned int keycode,
+#else
+ KeyCode keycode,
+#endif
+ int modifier)
+{
+ XModifierKeymap *newmap;
+ int i,
+ row = modifier * map->max_keypermod,
+ newrow,
+ lastrow;
+
+ for (i=0; i<map->max_keypermod; i++) {
+ if (map->modifiermap[ row+i ] == keycode)
+ return(map); /* already in the map */
+ if (map->modifiermap[ row+i ] == 0) {
+ map->modifiermap[ row+i ] = keycode;
+ return(map); /* we added it without stretching the map */
+ }
+ }
+
+ /* stretch the map */
+ if ((newmap = XNewModifiermap(map->max_keypermod+1)) == NULL)
+ return (XModifierKeymap *) NULL;
+ newrow = row = 0;
+ lastrow = newmap->max_keypermod * 8;
+ while (newrow < lastrow) {
+ for (i=0; i<map->max_keypermod; i++)
+ newmap->modifiermap[ newrow+i ] = map->modifiermap[ row+i ];
+ newmap->modifiermap[ newrow+i ] = 0;
+ row += map->max_keypermod;
+ newrow += newmap->max_keypermod;
+ }
+ (void) XFreeModifiermap(map);
+ newrow = newmap->max_keypermod * modifier + newmap->max_keypermod - 1;
+ newmap->modifiermap[ newrow ] = keycode;
+ return(newmap);
+}
+
+XModifierKeymap *
+XDeleteModifiermapEntry(XModifierKeymap *map,
+#if NeedWidePrototypes
+ unsigned int keycode,
+#else
+ KeyCode keycode,
+#endif
+ int modifier)
+{
+ int i,
+ row = modifier * map->max_keypermod;
+
+ for (i=0; i<map->max_keypermod; i++) {
+ if (map->modifiermap[ row+i ] == keycode)
+ map->modifiermap[ row+i ] = 0;
+ }
+ /* should we shrink the map?? */
+ return (map);
+}
diff --git a/libX11/src/NextEvent.c b/libX11/src/NextEvent.c
index 286579170..71f63b6ac 100644
--- a/libX11/src/NextEvent.c
+++ b/libX11/src/NextEvent.c
@@ -1,59 +1,58 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * Return next event in queue, or if none, flush output and wait for
- * events.
- */
-
-int
-XNextEvent (
- register Display *dpy,
- register XEvent *event)
-{
- register _XQEvent *qelt;
-
- LockDisplay(dpy);
-
- /* Delete unclaimed cookies */
- _XFreeEventCookies(dpy);
-
- if (dpy->head == NULL)
- _XReadEvents(dpy);
- qelt = dpy->head;
- *event = qelt->event;
- _XDeq(dpy, NULL, qelt);
- _XStoreEventCookie(dpy, event);
- UnlockDisplay(dpy);
- return 0;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * Return next event in queue, or if none, flush output and wait for
+ * events.
+ */
+
+int
+XNextEvent (
+ register Display *dpy,
+ register XEvent *event)
+{
+ register _XQEvent *qelt;
+
+ LockDisplay(dpy);
+
+ /* Delete unclaimed cookies */
+ _XFreeEventCookies(dpy);
+
+ if (dpy->head == NULL)
+ _XReadEvents(dpy);
+ qelt = dpy->head;
+ *event = qelt->event;
+ _XDeq(dpy, NULL, qelt);
+ _XStoreEventCookie(dpy, event);
+ UnlockDisplay(dpy);
+ return 0;
+}
+
diff --git a/libX11/src/OpenDis.c b/libX11/src/OpenDis.c
index a225bb437..b1992a9a2 100644
--- a/libX11/src/OpenDis.c
+++ b/libX11/src/OpenDis.c
@@ -24,8 +24,6 @@ in this Software without prior written authorization from The Open Group.
*/
-#define NEED_REPLIES
-#define NEED_EVENTS
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
diff --git a/libX11/src/ParseCol.c b/libX11/src/ParseCol.c
index 5f9b09f25..913f04ee0 100644
--- a/libX11/src/ParseCol.c
+++ b/libX11/src/ParseCol.c
@@ -1,139 +1,138 @@
-/*
-
-Copyright 1985, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "Xcmsint.h"
-
-
-Status
-XParseColor (
- register Display *dpy,
- Colormap cmap,
- _Xconst char *spec,
- XColor *def)
-{
- register int n, i;
- int r, g, b;
- char c;
- XcmsCCC ccc;
- XcmsColor cmsColor;
-
- if (!spec) return(0);
- n = strlen (spec);
- if (*spec == '#') {
- /*
- * RGB
- */
- spec++;
- n--;
- if (n != 3 && n != 6 && n != 9 && n != 12)
- return (0);
- n /= 3;
- g = b = 0;
- do {
- r = g;
- g = b;
- b = 0;
- for (i = n; --i >= 0; ) {
- c = *spec++;
- b <<= 4;
- if (c >= '0' && c <= '9')
- b |= c - '0';
- else if (c >= 'A' && c <= 'F')
- b |= c - ('A' - 10);
- else if (c >= 'a' && c <= 'f')
- b |= c - ('a' - 10);
- else return (0);
- }
- } while (*spec != '\0');
- n <<= 2;
- n = 16 - n;
- def->red = r << n;
- def->green = g << n;
- def->blue = b << n;
- def->flags = DoRed | DoGreen | DoBlue;
- return (1);
- }
-
-
-#ifdef XCMS
- /*
- * Let's Attempt to use Xcms and i18n approach to Parse Color
- */
- if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
- const char *tmpName = spec;
-
- switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor,
- XcmsRGBFormat)) {
- case XcmsSuccess:
- case XcmsSuccessWithCompression:
- cmsColor.pixel = def->pixel;
- _XcmsRGB_to_XColor(&cmsColor, def, 1);
- return(1);
- case XcmsFailure:
- case _XCMS_NEWNAME:
- /*
- * if the result was _XCMS_NEWNAME tmpName points to
- * a string in cmsColNm.c:pairs table, for example,
- * gray70 would become tekhvc:0.0/70.0/0.0
- */
- break;
- }
- }
-#endif
-
- /*
- * Xcms and i18n methods failed, so lets pass it to the server
- * for parsing.
- */
- {
- xLookupColorReply reply;
- register xLookupColorReq *req;
- LockDisplay(dpy);
- GetReq (LookupColor, req);
- req->cmap = cmap;
- req->nbytes = n = strlen(spec);
- req->length += (n + 3) >> 2;
- Data (dpy, spec, (long)n);
- if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (0);
- }
- def->red = reply.exactRed;
- def->green = reply.exactGreen;
- def->blue = reply.exactBlue;
- def->flags = DoRed | DoGreen | DoBlue;
- UnlockDisplay(dpy);
- SyncHandle();
- return (1);
- }
-}
+/*
+
+Copyright 1985, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+
+
+Status
+XParseColor (
+ register Display *dpy,
+ Colormap cmap,
+ _Xconst char *spec,
+ XColor *def)
+{
+ register int n, i;
+ int r, g, b;
+ char c;
+ XcmsCCC ccc;
+ XcmsColor cmsColor;
+
+ if (!spec) return(0);
+ n = strlen (spec);
+ if (*spec == '#') {
+ /*
+ * RGB
+ */
+ spec++;
+ n--;
+ if (n != 3 && n != 6 && n != 9 && n != 12)
+ return (0);
+ n /= 3;
+ g = b = 0;
+ do {
+ r = g;
+ g = b;
+ b = 0;
+ for (i = n; --i >= 0; ) {
+ c = *spec++;
+ b <<= 4;
+ if (c >= '0' && c <= '9')
+ b |= c - '0';
+ else if (c >= 'A' && c <= 'F')
+ b |= c - ('A' - 10);
+ else if (c >= 'a' && c <= 'f')
+ b |= c - ('a' - 10);
+ else return (0);
+ }
+ } while (*spec != '\0');
+ n <<= 2;
+ n = 16 - n;
+ def->red = r << n;
+ def->green = g << n;
+ def->blue = b << n;
+ def->flags = DoRed | DoGreen | DoBlue;
+ return (1);
+ }
+
+
+#ifdef XCMS
+ /*
+ * Let's Attempt to use Xcms and i18n approach to Parse Color
+ */
+ if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
+ const char *tmpName = spec;
+
+ switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor,
+ XcmsRGBFormat)) {
+ case XcmsSuccess:
+ case XcmsSuccessWithCompression:
+ cmsColor.pixel = def->pixel;
+ _XcmsRGB_to_XColor(&cmsColor, def, 1);
+ return(1);
+ case XcmsFailure:
+ case _XCMS_NEWNAME:
+ /*
+ * if the result was _XCMS_NEWNAME tmpName points to
+ * a string in cmsColNm.c:pairs table, for example,
+ * gray70 would become tekhvc:0.0/70.0/0.0
+ */
+ break;
+ }
+ }
+#endif
+
+ /*
+ * Xcms and i18n methods failed, so lets pass it to the server
+ * for parsing.
+ */
+ {
+ xLookupColorReply reply;
+ register xLookupColorReq *req;
+ LockDisplay(dpy);
+ GetReq (LookupColor, req);
+ req->cmap = cmap;
+ req->nbytes = n = strlen(spec);
+ req->length += (n + 3) >> 2;
+ Data (dpy, spec, (long)n);
+ if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (0);
+ }
+ def->red = reply.exactRed;
+ def->green = reply.exactGreen;
+ def->blue = reply.exactBlue;
+ def->flags = DoRed | DoGreen | DoBlue;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (1);
+ }
+}
diff --git a/libX11/src/PeekEvent.c b/libX11/src/PeekEvent.c
index 3a7aebe28..f7d4e7006 100644
--- a/libX11/src/PeekEvent.c
+++ b/libX11/src/PeekEvent.c
@@ -1,56 +1,55 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * Return the next event in the queue,
- * BUT do not remove it from the queue.
- * If none found, flush and wait until there is an event to peek.
- */
-
-int
-XPeekEvent (
- register Display *dpy,
- register XEvent *event)
-{
- XEvent copy;
- LockDisplay(dpy);
- if (dpy->head == NULL)
- _XReadEvents(dpy);
- *event = (dpy->head)->event;
- if (_XCopyEventCookie(dpy, &event->xcookie, &copy.xcookie)) {
- _XStoreEventCookie(dpy, &copy);
- *event = copy;
- }
- UnlockDisplay(dpy);
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * Return the next event in the queue,
+ * BUT do not remove it from the queue.
+ * If none found, flush and wait until there is an event to peek.
+ */
+
+int
+XPeekEvent (
+ register Display *dpy,
+ register XEvent *event)
+{
+ XEvent copy;
+ LockDisplay(dpy);
+ if (dpy->head == NULL)
+ _XReadEvents(dpy);
+ *event = (dpy->head)->event;
+ if (_XCopyEventCookie(dpy, &event->xcookie, &copy.xcookie)) {
+ _XStoreEventCookie(dpy, &copy);
+ *event = copy;
+ }
+ UnlockDisplay(dpy);
+ return 1;
+}
+
diff --git a/libX11/src/PeekIfEv.c b/libX11/src/PeekIfEv.c
index 3421dd521..c60995824 100644
--- a/libX11/src/PeekIfEv.c
+++ b/libX11/src/PeekIfEv.c
@@ -1,79 +1,78 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * return the next event in the queue that satisfies the predicate.
- * BUT do not remove it from the queue.
- * If none found, flush, and then wait until one satisfies the predicate.
- */
-
-int
-XPeekIfEvent (
- register Display *dpy,
- register XEvent *event,
- Bool (*predicate)(
- Display* /* display */,
- XEvent* /* event */,
- char* /* arg */
- ),
- char *arg)
-{
- register _XQEvent *prev, *qelt;
- unsigned long qe_serial = 0;
-
- LockDisplay(dpy);
- prev = NULL;
- while (1) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if(qelt->qserial_num > qe_serial
- && (*predicate)(dpy, &qelt->event, arg)) {
- XEvent copy;
- *event = qelt->event;
- if (_XCopyEventCookie(dpy, &event->xcookie, &copy.xcookie)) {
- _XStoreEventCookie(dpy, &copy);
- *event = copy;
- }
- UnlockDisplay(dpy);
- return 0;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- _XReadEvents(dpy);
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * return the next event in the queue that satisfies the predicate.
+ * BUT do not remove it from the queue.
+ * If none found, flush, and then wait until one satisfies the predicate.
+ */
+
+int
+XPeekIfEvent (
+ register Display *dpy,
+ register XEvent *event,
+ Bool (*predicate)(
+ Display* /* display */,
+ XEvent* /* event */,
+ char* /* arg */
+ ),
+ char *arg)
+{
+ register _XQEvent *prev, *qelt;
+ unsigned long qe_serial = 0;
+
+ LockDisplay(dpy);
+ prev = NULL;
+ while (1) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if(qelt->qserial_num > qe_serial
+ && (*predicate)(dpy, &qelt->event, arg)) {
+ XEvent copy;
+ *event = qelt->event;
+ if (_XCopyEventCookie(dpy, &event->xcookie, &copy.xcookie)) {
+ _XStoreEventCookie(dpy, &copy);
+ *event = copy;
+ }
+ UnlockDisplay(dpy);
+ return 0;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ _XReadEvents(dpy);
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+}
+
diff --git a/libX11/src/PutBEvent.c b/libX11/src/PutBEvent.c
index 521df407c..9193cc3b4 100644
--- a/libX11/src/PutBEvent.c
+++ b/libX11/src/PutBEvent.c
@@ -1,88 +1,87 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-/* XPutBackEvent puts an event back at the head of the queue. */
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-_XPutBackEvent (
- register Display *dpy,
- register XEvent *event)
- {
- register _XQEvent *qelt;
- XEvent store = *event;
-
- if (!dpy->qfree) {
- if ((dpy->qfree = (_XQEvent *) Xmalloc (sizeof (_XQEvent))) == NULL) {
- return 0;
- }
- dpy->qfree->next = NULL;
- }
-
- /* unclaimed cookie? */
- if (_XIsEventCookie(dpy, event))
- {
- XEvent copy = {0};
- /* if not claimed, then just fetch and store again */
- if (!event->xcookie.data) {
- _XFetchEventCookie(dpy, &event->xcookie);
- store = *event;
- } else { /* if claimed, copy, client must free */
- _XCopyEventCookie(dpy, &event->xcookie, &copy.xcookie);
- store = copy;
- }
- }
-
- qelt = dpy->qfree;
- dpy->qfree = qelt->next;
- qelt->qserial_num = dpy->next_event_serial_num++;
- qelt->next = dpy->head;
- qelt->event = store;
- dpy->head = qelt;
- if (dpy->tail == NULL)
- dpy->tail = qelt;
- dpy->qlen++;
- return 0;
- }
-
-int
-XPutBackEvent (
- register Display * dpy,
- register XEvent *event)
- {
- int ret;
-
- LockDisplay(dpy);
- ret = _XPutBackEvent(dpy, event);
- UnlockDisplay(dpy);
- return ret;
- }
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+/* XPutBackEvent puts an event back at the head of the queue. */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+_XPutBackEvent (
+ register Display *dpy,
+ register XEvent *event)
+ {
+ register _XQEvent *qelt;
+ XEvent store = *event;
+
+ if (!dpy->qfree) {
+ if ((dpy->qfree = (_XQEvent *) Xmalloc (sizeof (_XQEvent))) == NULL) {
+ return 0;
+ }
+ dpy->qfree->next = NULL;
+ }
+
+ /* unclaimed cookie? */
+ if (_XIsEventCookie(dpy, event))
+ {
+ XEvent copy = {0};
+ /* if not claimed, then just fetch and store again */
+ if (!event->xcookie.data) {
+ _XFetchEventCookie(dpy, &event->xcookie);
+ store = *event;
+ } else { /* if claimed, copy, client must free */
+ _XCopyEventCookie(dpy, &event->xcookie, &copy.xcookie);
+ store = copy;
+ }
+ }
+
+ qelt = dpy->qfree;
+ dpy->qfree = qelt->next;
+ qelt->qserial_num = dpy->next_event_serial_num++;
+ qelt->next = dpy->head;
+ qelt->event = store;
+ dpy->head = qelt;
+ if (dpy->tail == NULL)
+ dpy->tail = qelt;
+ dpy->qlen++;
+ return 0;
+ }
+
+int
+XPutBackEvent (
+ register Display * dpy,
+ register XEvent *event)
+ {
+ int ret;
+
+ LockDisplay(dpy);
+ ret = _XPutBackEvent(dpy, event);
+ UnlockDisplay(dpy);
+ return ret;
+ }
diff --git a/libX11/src/QuBest.c b/libX11/src/QuBest.c
index 56b510d67..15e4c0b23 100644
--- a/libX11/src/QuBest.c
+++ b/libX11/src/QuBest.c
@@ -1,62 +1,61 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XQueryBestSize(
- register Display *dpy,
- int class,
- Drawable drawable,
- unsigned int width,
- unsigned int height,
- unsigned int *ret_width,
- unsigned int *ret_height)
-{
- xQueryBestSizeReply rep;
- register xQueryBestSizeReq *req;
-
- LockDisplay(dpy);
- GetReq(QueryBestSize, req);
- req->class = class;
- req->drawable = drawable;
- req->width = width;
- req->height = height;
- if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- return 0;
- }
- *ret_width = rep.width;
- *ret_height = rep.height;
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XQueryBestSize(
+ register Display *dpy,
+ int class,
+ Drawable drawable,
+ unsigned int width,
+ unsigned int height,
+ unsigned int *ret_width,
+ unsigned int *ret_height)
+{
+ xQueryBestSizeReply rep;
+ register xQueryBestSizeReq *req;
+
+ LockDisplay(dpy);
+ GetReq(QueryBestSize, req);
+ req->class = class;
+ req->drawable = drawable;
+ req->width = width;
+ req->height = height;
+ if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+ *ret_width = rep.width;
+ *ret_height = rep.height;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/QuColor.c b/libX11/src/QuColor.c
index 7aca7d7b8..a056ba4cc 100644
--- a/libX11/src/QuColor.c
+++ b/libX11/src/QuColor.c
@@ -1,62 +1,61 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XQueryColor(
- register Display *dpy,
- Colormap cmap,
- XColor *def) /* RETURN */
-{
- xrgb color;
- xQueryColorsReply rep;
- register xQueryColorsReq *req;
- unsigned long val = def->pixel; /* needed for macro below */
-
- LockDisplay(dpy);
- GetReqExtra(QueryColors, 4, req); /* a pixel (CARD32) is 4 bytes */
- req->cmap = cmap;
-
- OneDataCard32 (dpy, NEXTPTR(req,xQueryColorsReq), val);
-
- if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) {
-
- _XRead(dpy, (char *)&color, (long) SIZEOF(xrgb));
-
- def->red = color.red;
- def->blue = color.blue;
- def->green = color.green;
- def->flags = DoRed | DoGreen | DoBlue;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XQueryColor(
+ register Display *dpy,
+ Colormap cmap,
+ XColor *def) /* RETURN */
+{
+ xrgb color;
+ xQueryColorsReply rep;
+ register xQueryColorsReq *req;
+ unsigned long val = def->pixel; /* needed for macro below */
+
+ LockDisplay(dpy);
+ GetReqExtra(QueryColors, 4, req); /* a pixel (CARD32) is 4 bytes */
+ req->cmap = cmap;
+
+ OneDataCard32 (dpy, NEXTPTR(req,xQueryColorsReq), val);
+
+ if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) {
+
+ _XRead(dpy, (char *)&color, (long) SIZEOF(xrgb));
+
+ def->red = color.red;
+ def->blue = color.blue;
+ def->green = color.green;
+ def->flags = DoRed | DoGreen | DoBlue;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
diff --git a/libX11/src/QuColors.c b/libX11/src/QuColors.c
index 0df6f028f..3aa2838ac 100644
--- a/libX11/src/QuColors.c
+++ b/libX11/src/QuColors.c
@@ -1,78 +1,77 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XQueryColors(
- register Display *dpy,
- Colormap cmap,
- XColor *defs, /* RETURN */
- int ncolors)
-{
- register int i;
- xrgb *color;
- xQueryColorsReply rep;
- long nbytes;
- register xQueryColorsReq *req;
-
- LockDisplay(dpy);
- GetReq(QueryColors, req);
-
- req->cmap = cmap;
- req->length += ncolors; /* each pixel is a CARD32 */
-
- for (i = 0; i < ncolors; i++)
- Data32 (dpy, (long *)&defs[i].pixel, 4L);
- /* XXX this isn't very efficient */
-
- if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) {
- if ((color = (xrgb *)
- Xmalloc((unsigned) (nbytes = (long) ncolors * SIZEOF(xrgb))))) {
-
- _XRead(dpy, (char *) color, nbytes);
-
- for (i = 0; i < ncolors; i++) {
- register XColor *def = &defs[i];
- register xrgb *rgb = &color[i];
- def->red = rgb->red;
- def->green = rgb->green;
- def->blue = rgb->blue;
- def->flags = DoRed | DoGreen | DoBlue;
- }
- Xfree((char *)color);
- }
- else _XEatData(dpy, (unsigned long) nbytes);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XQueryColors(
+ register Display *dpy,
+ Colormap cmap,
+ XColor *defs, /* RETURN */
+ int ncolors)
+{
+ register int i;
+ xrgb *color;
+ xQueryColorsReply rep;
+ long nbytes;
+ register xQueryColorsReq *req;
+
+ LockDisplay(dpy);
+ GetReq(QueryColors, req);
+
+ req->cmap = cmap;
+ req->length += ncolors; /* each pixel is a CARD32 */
+
+ for (i = 0; i < ncolors; i++)
+ Data32 (dpy, (long *)&defs[i].pixel, 4L);
+ /* XXX this isn't very efficient */
+
+ if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) {
+ if ((color = (xrgb *)
+ Xmalloc((unsigned) (nbytes = (long) ncolors * SIZEOF(xrgb))))) {
+
+ _XRead(dpy, (char *) color, nbytes);
+
+ for (i = 0; i < ncolors; i++) {
+ register XColor *def = &defs[i];
+ register xrgb *rgb = &color[i];
+ def->red = rgb->red;
+ def->green = rgb->green;
+ def->blue = rgb->blue;
+ def->flags = DoRed | DoGreen | DoBlue;
+ }
+ Xfree((char *)color);
+ }
+ else _XEatData(dpy, (unsigned long) nbytes);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/QuCurShp.c b/libX11/src/QuCurShp.c
index 266e9bec2..8b5cbfaed 100644
--- a/libX11/src/QuCurShp.c
+++ b/libX11/src/QuCurShp.c
@@ -1,61 +1,60 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XQueryBestCursor(
- register Display *dpy,
- Drawable drawable,
- unsigned int width,
- unsigned int height,
- unsigned int *ret_width,
- unsigned int *ret_height)
-{
- xQueryBestSizeReply rep;
- register xQueryBestSizeReq *req;
-
- LockDisplay(dpy);
- GetReq(QueryBestSize, req);
- req->class = CursorShape;
- req->drawable = drawable;
- req->width = width;
- req->height = height;
- if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- return 0;
- }
- *ret_width = rep.width;
- *ret_height = rep.height;
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XQueryBestCursor(
+ register Display *dpy,
+ Drawable drawable,
+ unsigned int width,
+ unsigned int height,
+ unsigned int *ret_width,
+ unsigned int *ret_height)
+{
+ xQueryBestSizeReply rep;
+ register xQueryBestSizeReq *req;
+
+ LockDisplay(dpy);
+ GetReq(QueryBestSize, req);
+ req->class = CursorShape;
+ req->drawable = drawable;
+ req->width = width;
+ req->height = height;
+ if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+ *ret_width = rep.width;
+ *ret_height = rep.height;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/QuExt.c b/libX11/src/QuExt.c
index ca94f0486..190e8b1f5 100644
--- a/libX11/src/QuExt.c
+++ b/libX11/src/QuExt.c
@@ -1,57 +1,56 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Bool
-XQueryExtension(
- register Display *dpy,
- _Xconst char *name,
- int *major_opcode, /* RETURN */
- int *first_event, /* RETURN */
- int *first_error) /* RETURN */
-{
- xQueryExtensionReply rep;
- register xQueryExtensionReq *req;
-
- LockDisplay(dpy);
- GetReq(QueryExtension, req);
- req->nbytes = name ? strlen(name) : 0;
- req->length += (req->nbytes+(unsigned)3)>>2;
- _XSend(dpy, name, (long)req->nbytes);
- (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
- *major_opcode = rep.major_opcode;
- *first_event = rep.first_event;
- *first_error = rep.first_error;
- UnlockDisplay(dpy);
- SyncHandle();
- return (rep.present);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Bool
+XQueryExtension(
+ register Display *dpy,
+ _Xconst char *name,
+ int *major_opcode, /* RETURN */
+ int *first_event, /* RETURN */
+ int *first_error) /* RETURN */
+{
+ xQueryExtensionReply rep;
+ register xQueryExtensionReq *req;
+
+ LockDisplay(dpy);
+ GetReq(QueryExtension, req);
+ req->nbytes = name ? strlen(name) : 0;
+ req->length += (req->nbytes+(unsigned)3)>>2;
+ _XSend(dpy, name, (long)req->nbytes);
+ (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
+ *major_opcode = rep.major_opcode;
+ *first_event = rep.first_event;
+ *first_error = rep.first_error;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (rep.present);
+}
+
diff --git a/libX11/src/QuKeybd.c b/libX11/src/QuKeybd.c
index a7446a2f2..8f296c285 100644
--- a/libX11/src/QuKeybd.c
+++ b/libX11/src/QuKeybd.c
@@ -1,54 +1,53 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-struct kmap {
- char map[32];
-};
-
-int
-XQueryKeymap(
- register Display *dpy,
- char keys[32])
-{
- xQueryKeymapReply rep;
- register xReq *req;
-
- LockDisplay(dpy);
- GetEmptyReq(QueryKeymap, req);
- (void) _XReply(dpy, (xReply *)&rep,
- (SIZEOF(xQueryKeymapReply) - SIZEOF(xReply)) >> 2, xTrue);
- *(struct kmap *) keys = *(struct kmap *)rep.map; /* faster than memcpy */
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+struct kmap {
+ char map[32];
+};
+
+int
+XQueryKeymap(
+ register Display *dpy,
+ char keys[32])
+{
+ xQueryKeymapReply rep;
+ register xReq *req;
+
+ LockDisplay(dpy);
+ GetEmptyReq(QueryKeymap, req);
+ (void) _XReply(dpy, (xReply *)&rep,
+ (SIZEOF(xQueryKeymapReply) - SIZEOF(xReply)) >> 2, xTrue);
+ *(struct kmap *) keys = *(struct kmap *)rep.map; /* faster than memcpy */
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/QuPntr.c b/libX11/src/QuPntr.c
index d2968dc89..17412fc8e 100644
--- a/libX11/src/QuPntr.c
+++ b/libX11/src/QuPntr.c
@@ -1,66 +1,65 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Bool XQueryPointer(
- register Display *dpy,
- Window w,
- Window *root,
- Window *child,
- int *root_x,
- int *root_y,
- int *win_x,
- int *win_y,
- unsigned int *mask)
-{
- xQueryPointerReply rep;
- xResourceReq *req;
-
- LockDisplay(dpy);
- GetResReq(QueryPointer, w, req);
- if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- return(False);
- }
-
- *root = rep.root;
- *child = rep.child;
- *root_x = cvtINT16toInt (rep.rootX);
- *root_y = cvtINT16toInt (rep.rootY);
- *win_x = cvtINT16toInt (rep.winX);
- *win_y = cvtINT16toInt (rep.winY);
- *mask = rep.mask;
- UnlockDisplay(dpy);
- SyncHandle();
- return (rep.sameScreen);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Bool XQueryPointer(
+ register Display *dpy,
+ Window w,
+ Window *root,
+ Window *child,
+ int *root_x,
+ int *root_y,
+ int *win_x,
+ int *win_y,
+ unsigned int *mask)
+{
+ xQueryPointerReply rep;
+ xResourceReq *req;
+
+ LockDisplay(dpy);
+ GetResReq(QueryPointer, w, req);
+ if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(False);
+ }
+
+ *root = rep.root;
+ *child = rep.child;
+ *root_x = cvtINT16toInt (rep.rootX);
+ *root_y = cvtINT16toInt (rep.rootY);
+ *win_x = cvtINT16toInt (rep.winX);
+ *win_y = cvtINT16toInt (rep.winY);
+ *mask = rep.mask;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (rep.sameScreen);
+}
+
diff --git a/libX11/src/QuStipShp.c b/libX11/src/QuStipShp.c
index 5a8d310e9..11357e5e1 100644
--- a/libX11/src/QuStipShp.c
+++ b/libX11/src/QuStipShp.c
@@ -1,61 +1,60 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XQueryBestStipple(
- register Display *dpy,
- Drawable drawable,
- unsigned int width,
- unsigned int height,
- unsigned int *ret_width,
- unsigned int *ret_height)
-{
- xQueryBestSizeReply rep;
- register xQueryBestSizeReq *req;
-
- LockDisplay(dpy);
- GetReq(QueryBestSize, req);
- req->class = StippleShape;
- req->drawable = drawable;
- req->width = width;
- req->height = height;
- if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- return 0;
- }
- *ret_width = rep.width;
- *ret_height = rep.height;
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XQueryBestStipple(
+ register Display *dpy,
+ Drawable drawable,
+ unsigned int width,
+ unsigned int height,
+ unsigned int *ret_width,
+ unsigned int *ret_height)
+{
+ xQueryBestSizeReply rep;
+ register xQueryBestSizeReq *req;
+
+ LockDisplay(dpy);
+ GetReq(QueryBestSize, req);
+ req->class = StippleShape;
+ req->drawable = drawable;
+ req->width = width;
+ req->height = height;
+ if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+ *ret_width = rep.width;
+ *ret_height = rep.height;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/QuTextE16.c b/libX11/src/QuTextE16.c
index 67facd1e1..e88d246fa 100644
--- a/libX11/src/QuTextE16.c
+++ b/libX11/src/QuTextE16.c
@@ -1,82 +1,81 @@
-/*
-
-Copyright 1986, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XQueryTextExtents16 (
- register Display *dpy,
- Font fid,
- _Xconst XChar2b *string,
- register int nchars,
- int *dir,
- int *font_ascent,
- int *font_descent,
- register XCharStruct *overall)
-{
- register long i;
- register unsigned char *ptr;
- char *buf;
- xQueryTextExtentsReply rep;
- long nbytes;
- register xQueryTextExtentsReq *req;
-
- LockDisplay(dpy);
- nbytes = nchars << 1;
- GetReq(QueryTextExtents, req);
- req->fid = fid;
- if ((buf = _XAllocScratch (dpy, (unsigned long) nbytes))) {
- req->length += (nbytes + 3)>>2;
- req->oddLength = nchars & 1;
- for (ptr = (unsigned char *)buf, i = nchars; --i >= 0; string++) {
- *ptr++ = string->byte1;
- *ptr++ = string->byte2;
- }
- Data (dpy, buf, nbytes);
- }
- if (!_XReply (dpy, (xReply *)&rep, 0, xTrue) || !buf) {
- UnlockDisplay(dpy);
- SyncHandle();
- return 0;
- }
- *dir = rep.drawDirection;
- *font_ascent = cvtINT16toInt (rep.fontAscent);
- *font_descent = cvtINT16toInt (rep.fontDescent);
- overall->ascent = (short) cvtINT16toShort (rep.overallAscent);
- overall->descent = (short) cvtINT16toShort (rep.overallDescent);
- /* XXX bogus - we're throwing away information!!! */
- overall->width = (short) cvtINT32toInt (rep.overallWidth);
- overall->lbearing = (short) cvtINT32toInt (rep.overallLeft);
- overall->rbearing = (short) cvtINT32toInt (rep.overallRight);
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XQueryTextExtents16 (
+ register Display *dpy,
+ Font fid,
+ _Xconst XChar2b *string,
+ register int nchars,
+ int *dir,
+ int *font_ascent,
+ int *font_descent,
+ register XCharStruct *overall)
+{
+ register long i;
+ register unsigned char *ptr;
+ char *buf;
+ xQueryTextExtentsReply rep;
+ long nbytes;
+ register xQueryTextExtentsReq *req;
+
+ LockDisplay(dpy);
+ nbytes = nchars << 1;
+ GetReq(QueryTextExtents, req);
+ req->fid = fid;
+ if ((buf = _XAllocScratch (dpy, (unsigned long) nbytes))) {
+ req->length += (nbytes + 3)>>2;
+ req->oddLength = nchars & 1;
+ for (ptr = (unsigned char *)buf, i = nchars; --i >= 0; string++) {
+ *ptr++ = string->byte1;
+ *ptr++ = string->byte2;
+ }
+ Data (dpy, buf, nbytes);
+ }
+ if (!_XReply (dpy, (xReply *)&rep, 0, xTrue) || !buf) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+ *dir = rep.drawDirection;
+ *font_ascent = cvtINT16toInt (rep.fontAscent);
+ *font_descent = cvtINT16toInt (rep.fontDescent);
+ overall->ascent = (short) cvtINT16toShort (rep.overallAscent);
+ overall->descent = (short) cvtINT16toShort (rep.overallDescent);
+ /* XXX bogus - we're throwing away information!!! */
+ overall->width = (short) cvtINT32toInt (rep.overallWidth);
+ overall->lbearing = (short) cvtINT32toInt (rep.overallLeft);
+ overall->rbearing = (short) cvtINT32toInt (rep.overallRight);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/QuTextExt.c b/libX11/src/QuTextExt.c
index c94c11a82..f5f715f04 100644
--- a/libX11/src/QuTextExt.c
+++ b/libX11/src/QuTextExt.c
@@ -1,81 +1,80 @@
-/*
-
-Copyright 1986, 1987, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-int
-XQueryTextExtents (
- register Display *dpy,
- Font fid,
- register _Xconst char *string,
- register int nchars,
- int *dir,
- int *font_ascent,
- int *font_descent,
- register XCharStruct *overall)
-{
- register int i;
- register char *ptr;
- char *buf;
- xQueryTextExtentsReply rep;
- long nbytes;
- register xQueryTextExtentsReq *req;
-
- LockDisplay(dpy);
- nbytes = nchars << 1;
- GetReq(QueryTextExtents, req);
- req->fid = fid;
- if ((buf = _XAllocScratch (dpy, (unsigned long) nbytes))) {
- req->length += (nbytes + 3)>>2;
- req->oddLength = nchars & 1;
- for (ptr = buf, i = nchars; --i >= 0;) {
- *ptr++ = 0;
- *ptr++ = *string++;
- }
- Data (dpy, buf, nbytes);
- }
- if (!_XReply (dpy, (xReply *)&rep, 0, xTrue) || !buf) {
- UnlockDisplay(dpy);
- SyncHandle();
- return 0;
- }
- *dir = rep.drawDirection;
- *font_ascent = cvtINT16toInt (rep.fontAscent);
- *font_descent = cvtINT16toInt (rep.fontDescent);
- overall->ascent = (short) cvtINT16toShort (rep.overallAscent);
- overall->descent = (short) cvtINT16toShort (rep.overallDescent);
- /* XXX bogus - we're throwing away information!!! */
- overall->width = (short) cvtINT32toInt (rep.overallWidth);
- overall->lbearing = (short) cvtINT32toInt (rep.overallLeft);
- overall->rbearing = (short) cvtINT32toInt (rep.overallRight);
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
+/*
+
+Copyright 1986, 1987, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+int
+XQueryTextExtents (
+ register Display *dpy,
+ Font fid,
+ register _Xconst char *string,
+ register int nchars,
+ int *dir,
+ int *font_ascent,
+ int *font_descent,
+ register XCharStruct *overall)
+{
+ register int i;
+ register char *ptr;
+ char *buf;
+ xQueryTextExtentsReply rep;
+ long nbytes;
+ register xQueryTextExtentsReq *req;
+
+ LockDisplay(dpy);
+ nbytes = nchars << 1;
+ GetReq(QueryTextExtents, req);
+ req->fid = fid;
+ if ((buf = _XAllocScratch (dpy, (unsigned long) nbytes))) {
+ req->length += (nbytes + 3)>>2;
+ req->oddLength = nchars & 1;
+ for (ptr = buf, i = nchars; --i >= 0;) {
+ *ptr++ = 0;
+ *ptr++ = *string++;
+ }
+ Data (dpy, buf, nbytes);
+ }
+ if (!_XReply (dpy, (xReply *)&rep, 0, xTrue) || !buf) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+ *dir = rep.drawDirection;
+ *font_ascent = cvtINT16toInt (rep.fontAscent);
+ *font_descent = cvtINT16toInt (rep.fontDescent);
+ overall->ascent = (short) cvtINT16toShort (rep.overallAscent);
+ overall->descent = (short) cvtINT16toShort (rep.overallDescent);
+ /* XXX bogus - we're throwing away information!!! */
+ overall->width = (short) cvtINT32toInt (rep.overallWidth);
+ overall->lbearing = (short) cvtINT32toInt (rep.overallLeft);
+ overall->rbearing = (short) cvtINT32toInt (rep.overallRight);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
diff --git a/libX11/src/QuTileShp.c b/libX11/src/QuTileShp.c
index 55360e7d3..39ccb42fa 100644
--- a/libX11/src/QuTileShp.c
+++ b/libX11/src/QuTileShp.c
@@ -1,62 +1,61 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XQueryBestTile(
- register Display *dpy,
- Drawable drawable,
- unsigned int width,
- unsigned int height,
- unsigned int *ret_width,
- unsigned int *ret_height)
-{
- xQueryBestSizeReply rep;
- register xQueryBestSizeReq *req;
-
- LockDisplay(dpy);
- GetReq(QueryBestSize, req);
- req->class = TileShape;
- req->drawable = drawable;
- req->width = width;
- req->height = height;
- if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- return(0);
- }
-
- *ret_width = rep.width;
- *ret_height = rep.height;
- UnlockDisplay(dpy);
- SyncHandle();
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XQueryBestTile(
+ register Display *dpy,
+ Drawable drawable,
+ unsigned int width,
+ unsigned int height,
+ unsigned int *ret_width,
+ unsigned int *ret_height)
+{
+ xQueryBestSizeReply rep;
+ register xQueryBestSizeReq *req;
+
+ LockDisplay(dpy);
+ GetReq(QueryBestSize, req);
+ req->class = TileShape;
+ req->drawable = drawable;
+ req->width = width;
+ req->height = height;
+ if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(0);
+ }
+
+ *ret_width = rep.width;
+ *ret_height = rep.height;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
diff --git a/libX11/src/QuTree.c b/libX11/src/QuTree.c
index c40d08111..e95b57bd3 100644
--- a/libX11/src/QuTree.c
+++ b/libX11/src/QuTree.c
@@ -1,73 +1,72 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Status XQueryTree (
- register Display *dpy,
- Window w,
- Window *root, /* RETURN */
- Window *parent, /* RETURN */
- Window **children, /* RETURN */
- unsigned int *nchildren) /* RETURN */
-{
- long nbytes;
- xQueryTreeReply rep;
- register xResourceReq *req;
-
- LockDisplay(dpy);
- GetResReq(QueryTree, w, req);
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (0);
- }
-
- *children = (Window *) NULL;
- if (rep.nChildren != 0) {
- nbytes = rep.nChildren * sizeof(Window);
- *children = (Window *) Xmalloc((unsigned) nbytes);
- nbytes = rep.nChildren << 2;
- if (! *children) {
- _XEatData(dpy, (unsigned long) nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return (0);
- }
- _XRead32 (dpy, (long *) *children, nbytes);
- }
- *parent = rep.parent;
- *root = rep.root;
- *nchildren = rep.nChildren;
- UnlockDisplay(dpy);
- SyncHandle();
- return (1);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Status XQueryTree (
+ register Display *dpy,
+ Window w,
+ Window *root, /* RETURN */
+ Window *parent, /* RETURN */
+ Window **children, /* RETURN */
+ unsigned int *nchildren) /* RETURN */
+{
+ long nbytes;
+ xQueryTreeReply rep;
+ register xResourceReq *req;
+
+ LockDisplay(dpy);
+ GetResReq(QueryTree, w, req);
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (0);
+ }
+
+ *children = (Window *) NULL;
+ if (rep.nChildren != 0) {
+ nbytes = rep.nChildren * sizeof(Window);
+ *children = (Window *) Xmalloc((unsigned) nbytes);
+ nbytes = rep.nChildren << 2;
+ if (! *children) {
+ _XEatData(dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (0);
+ }
+ _XRead32 (dpy, (long *) *children, nbytes);
+ }
+ *parent = rep.parent;
+ *root = rep.root;
+ *nchildren = rep.nChildren;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (1);
+}
+
diff --git a/libX11/src/ReconfWM.c b/libX11/src/ReconfWM.c
index 3f68c34fc..63c10da86 100644
--- a/libX11/src/ReconfWM.c
+++ b/libX11/src/ReconfWM.c
@@ -1,141 +1,139 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-#define AllMaskBits (CWX|CWY|CWWidth|CWHeight|\
- CWBorderWidth|CWSibling|CWStackMode)
-
-Status XReconfigureWMWindow (
- register Display *dpy,
- Window w,
- int screen,
- unsigned int mask,
- XWindowChanges *changes)
-{
- XConfigureRequestEvent ev;
- Window root = RootWindow (dpy, screen);
- _XAsyncHandler async;
- _XAsyncErrorState async_state;
-
- /*
- * Only need to go through the trouble if we are actually changing the
- * stacking mode.
- */
- if (!(mask & CWStackMode)) {
- XConfigureWindow (dpy, w, mask, changes);
- return True;
- }
-
-
- /*
- * We need to inline XConfigureWindow and XSync so that everything is done
- * while the display is locked.
- */
-
- LockDisplay(dpy);
-
- /*
- * XConfigureWindow (dpy, w, mask, changes);
- */
- {
- unsigned long values[7];
- register unsigned long *value = values;
- long nvalues;
- register xConfigureWindowReq *req;
-
- GetReq(ConfigureWindow, req);
-
- async_state.min_sequence_number = dpy->request;
- async_state.max_sequence_number = dpy->request;
- async_state.error_code = BadMatch;
- async_state.major_opcode = X_ConfigureWindow;
- async_state.minor_opcode = 0;
- async_state.error_count = 0;
- async.next = dpy->async_handlers;
- async.handler = _XAsyncErrorHandler;
- async.data = (XPointer)&async_state;
- dpy->async_handlers = &async;
-
- req->window = w;
- mask &= AllMaskBits;
- req->mask = mask;
-
- if (mask & CWX) *value++ = changes->x;
- if (mask & CWY) *value++ = changes->y;
- if (mask & CWWidth) *value++ = changes->width;
- if (mask & CWHeight) *value++ = changes->height;
- if (mask & CWBorderWidth) *value++ = changes->border_width;
- if (mask & CWSibling) *value++ = changes->sibling;
- if (mask & CWStackMode) *value++ = changes->stack_mode;
- req->length += (nvalues = value - values);
- nvalues <<= 2; /* watch out for macros... */
- Data32 (dpy, (long *) values, nvalues);
- }
-
- /*
- * XSync (dpy, 0)
- */
- {
- xGetInputFocusReply rep;
- register xReq *req;
-
- GetEmptyReq(GetInputFocus, req);
- (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
- }
-
- DeqAsyncHandler(dpy, &async);
- UnlockDisplay(dpy);
- SyncHandle();
-
-
- /*
- * If the request succeeded, then everything is okay; otherwise, send event
- */
- if (!async_state.error_count) return True;
-
- ev.type = ConfigureRequest;
- ev.window = w;
- ev.parent = root;
- ev.value_mask = (mask & AllMaskBits);
- ev.x = changes->x;
- ev.y = changes->y;
- ev.width = changes->width;
- ev.height = changes->height;
- ev.border_width = changes->border_width;
- ev.above = changes->sibling;
- ev.detail = changes->stack_mode;
- return (XSendEvent (dpy, root, False,
- SubstructureRedirectMask|SubstructureNotifyMask,
- (XEvent *)&ev));
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+#define AllMaskBits (CWX|CWY|CWWidth|CWHeight|\
+ CWBorderWidth|CWSibling|CWStackMode)
+
+Status XReconfigureWMWindow (
+ register Display *dpy,
+ Window w,
+ int screen,
+ unsigned int mask,
+ XWindowChanges *changes)
+{
+ XConfigureRequestEvent ev;
+ Window root = RootWindow (dpy, screen);
+ _XAsyncHandler async;
+ _XAsyncErrorState async_state;
+
+ /*
+ * Only need to go through the trouble if we are actually changing the
+ * stacking mode.
+ */
+ if (!(mask & CWStackMode)) {
+ XConfigureWindow (dpy, w, mask, changes);
+ return True;
+ }
+
+
+ /*
+ * We need to inline XConfigureWindow and XSync so that everything is done
+ * while the display is locked.
+ */
+
+ LockDisplay(dpy);
+
+ /*
+ * XConfigureWindow (dpy, w, mask, changes);
+ */
+ {
+ unsigned long values[7];
+ register unsigned long *value = values;
+ long nvalues;
+ register xConfigureWindowReq *req;
+
+ GetReq(ConfigureWindow, req);
+
+ async_state.min_sequence_number = dpy->request;
+ async_state.max_sequence_number = dpy->request;
+ async_state.error_code = BadMatch;
+ async_state.major_opcode = X_ConfigureWindow;
+ async_state.minor_opcode = 0;
+ async_state.error_count = 0;
+ async.next = dpy->async_handlers;
+ async.handler = _XAsyncErrorHandler;
+ async.data = (XPointer)&async_state;
+ dpy->async_handlers = &async;
+
+ req->window = w;
+ mask &= AllMaskBits;
+ req->mask = mask;
+
+ if (mask & CWX) *value++ = changes->x;
+ if (mask & CWY) *value++ = changes->y;
+ if (mask & CWWidth) *value++ = changes->width;
+ if (mask & CWHeight) *value++ = changes->height;
+ if (mask & CWBorderWidth) *value++ = changes->border_width;
+ if (mask & CWSibling) *value++ = changes->sibling;
+ if (mask & CWStackMode) *value++ = changes->stack_mode;
+ req->length += (nvalues = value - values);
+ nvalues <<= 2; /* watch out for macros... */
+ Data32 (dpy, (long *) values, nvalues);
+ }
+
+ /*
+ * XSync (dpy, 0)
+ */
+ {
+ xGetInputFocusReply rep;
+ register xReq *req;
+
+ GetEmptyReq(GetInputFocus, req);
+ (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
+ }
+
+ DeqAsyncHandler(dpy, &async);
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+
+ /*
+ * If the request succeeded, then everything is okay; otherwise, send event
+ */
+ if (!async_state.error_count) return True;
+
+ ev.type = ConfigureRequest;
+ ev.window = w;
+ ev.parent = root;
+ ev.value_mask = (mask & AllMaskBits);
+ ev.x = changes->x;
+ ev.y = changes->y;
+ ev.width = changes->width;
+ ev.height = changes->height;
+ ev.border_width = changes->border_width;
+ ev.above = changes->sibling;
+ ev.detail = changes->stack_mode;
+ return (XSendEvent (dpy, root, False,
+ SubstructureRedirectMask|SubstructureNotifyMask,
+ (XEvent *)&ev));
+}
diff --git a/libX11/src/SendEvent.c b/libX11/src/SendEvent.c
index 27e75caad..137163930 100644
--- a/libX11/src/SendEvent.c
+++ b/libX11/src/SendEvent.c
@@ -1,82 +1,81 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/*
- * In order to avoid all images requiring _XEventToWire, we install the
- * event converter here if it has never been installed.
- */
-Status
-XSendEvent(
- register Display *dpy,
- Window w,
- Bool propagate,
- long event_mask,
- XEvent *event)
-{
- register xSendEventReq *req;
- xEvent ev;
- register Status (**fp)(
- Display * /* dpy */,
- XEvent * /* re */,
- xEvent * /* event */);
- Status status;
-
- /* initialize all of the event's fields first, before setting
- * the meaningful ones later.
- */
- memset (&ev, 0, sizeof (ev));
-
- LockDisplay (dpy);
-
- /* call through display to find proper conversion routine */
-
- fp = &dpy->wire_vec[event->type & 0177];
- if (*fp == NULL) *fp = _XEventToWire;
- status = (**fp)(dpy, event, &ev);
-
- if (status) {
- GetReq(SendEvent, req);
- req->destination = w;
- req->propagate = propagate;
- req->eventMask = event_mask;
-#ifdef WORD64
- /* avoid quad-alignment problems */
- memcpy ((char *) req->eventdata, (char *) &ev, SIZEOF(xEvent));
-#else
- req->event = ev;
-#endif /* WORD64 */
- }
-
- UnlockDisplay(dpy);
- SyncHandle();
- return(status);
-}
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/*
+ * In order to avoid all images requiring _XEventToWire, we install the
+ * event converter here if it has never been installed.
+ */
+Status
+XSendEvent(
+ register Display *dpy,
+ Window w,
+ Bool propagate,
+ long event_mask,
+ XEvent *event)
+{
+ register xSendEventReq *req;
+ xEvent ev;
+ register Status (**fp)(
+ Display * /* dpy */,
+ XEvent * /* re */,
+ xEvent * /* event */);
+ Status status;
+
+ /* initialize all of the event's fields first, before setting
+ * the meaningful ones later.
+ */
+ memset (&ev, 0, sizeof (ev));
+
+ LockDisplay (dpy);
+
+ /* call through display to find proper conversion routine */
+
+ fp = &dpy->wire_vec[event->type & 0177];
+ if (*fp == NULL) *fp = _XEventToWire;
+ status = (**fp)(dpy, event, &ev);
+
+ if (status) {
+ GetReq(SendEvent, req);
+ req->destination = w;
+ req->propagate = propagate;
+ req->eventMask = event_mask;
+#ifdef WORD64
+ /* avoid quad-alignment problems */
+ memcpy ((char *) req->eventdata, (char *) &ev, SIZEOF(xEvent));
+#else
+ req->event = ev;
+#endif /* WORD64 */
+ }
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(status);
+}
diff --git a/libX11/src/SetPntMap.c b/libX11/src/SetPntMap.c
index 78f965e32..5b278ff2b 100644
--- a/libX11/src/SetPntMap.c
+++ b/libX11/src/SetPntMap.c
@@ -24,8 +24,6 @@ in this Software without prior written authorization from The Open Group.
*/
-#define NEED_REPLIES
-
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
diff --git a/libX11/src/Sync.c b/libX11/src/Sync.c
index 014cb1cf7..fdc455961 100644
--- a/libX11/src/Sync.c
+++ b/libX11/src/Sync.c
@@ -1,62 +1,60 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-/* Synchronize with errors and events, optionally discarding pending events */
-
-int
-XSync (
- register Display *dpy,
- Bool discard)
-{
- xGetInputFocusReply rep;
- register xReq *req;
-
- LockDisplay(dpy);
- GetEmptyReq(GetInputFocus, req);
- (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
-
- if (discard && dpy->head) {
- _XQEvent *qelt;
-
- for (qelt=dpy->head; qelt; qelt=qelt->next)
- qelt->qserial_num = 0;
-
- ((_XQEvent *)dpy->tail)->next = dpy->qfree;
- dpy->qfree = (_XQEvent *)dpy->head;
- dpy->head = dpy->tail = NULL;
- dpy->qlen = 0;
- }
- UnlockDisplay(dpy);
- return 1;
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+/* Synchronize with errors and events, optionally discarding pending events */
+
+int
+XSync (
+ register Display *dpy,
+ Bool discard)
+{
+ xGetInputFocusReply rep;
+ register xReq *req;
+
+ LockDisplay(dpy);
+ GetEmptyReq(GetInputFocus, req);
+ (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
+
+ if (discard && dpy->head) {
+ _XQEvent *qelt;
+
+ for (qelt=dpy->head; qelt; qelt=qelt->next)
+ qelt->qserial_num = 0;
+
+ ((_XQEvent *)dpy->tail)->next = dpy->qfree;
+ dpy->qfree = (_XQEvent *)dpy->head;
+ dpy->head = dpy->tail = NULL;
+ dpy->qlen = 0;
+ }
+ UnlockDisplay(dpy);
+ return 1;
+}
+
diff --git a/libX11/src/TrCoords.c b/libX11/src/TrCoords.c
index 26d33b7a1..0e231614c 100644
--- a/libX11/src/TrCoords.c
+++ b/libX11/src/TrCoords.c
@@ -1,65 +1,64 @@
-/*
-
-Copyright 1986, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-Bool XTranslateCoordinates(
- register Display *dpy,
- Window src_win,
- Window dest_win,
- int src_x,
- int src_y,
- int *dst_x,
- int *dst_y,
- Window *child)
-{
- register xTranslateCoordsReq *req;
- xTranslateCoordsReply rep;
-
- LockDisplay(dpy);
- GetReq(TranslateCoords, req);
- req->srcWid = src_win;
- req->dstWid = dest_win;
- req->srcX = src_x;
- req->srcY = src_y;
- if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
- UnlockDisplay(dpy);
- SyncHandle();
- return(False);
- }
-
- *child = rep.child;
- *dst_x = cvtINT16toInt (rep.dstX);
- *dst_y = cvtINT16toInt (rep.dstY);
- UnlockDisplay(dpy);
- SyncHandle();
- return ((int)rep.sameScreen);
-}
-
+/*
+
+Copyright 1986, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+Bool XTranslateCoordinates(
+ register Display *dpy,
+ Window src_win,
+ Window dest_win,
+ int src_x,
+ int src_y,
+ int *dst_x,
+ int *dst_y,
+ Window *child)
+{
+ register xTranslateCoordsReq *req;
+ xTranslateCoordsReply rep;
+
+ LockDisplay(dpy);
+ GetReq(TranslateCoords, req);
+ req->srcWid = src_win;
+ req->dstWid = dest_win;
+ req->srcX = src_x;
+ req->srcY = src_y;
+ if (_XReply (dpy, (xReply *)&rep, 0, xTrue) == 0) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(False);
+ }
+
+ *child = rep.child;
+ *dst_x = cvtINT16toInt (rep.dstX);
+ *dst_y = cvtINT16toInt (rep.dstY);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return ((int)rep.sameScreen);
+}
+
diff --git a/libX11/src/WinEvent.c b/libX11/src/WinEvent.c
index 511cc18c2..d1afc38de 100644
--- a/libX11/src/WinEvent.c
+++ b/libX11/src/WinEvent.c
@@ -1,85 +1,84 @@
-/*
-
-Copyright 1985, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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
-OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-
-extern long const _Xevent_to_mask[];
-#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
-#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
- Button4MotionMask|Button5MotionMask)
-
-/*
- * Return the next event in the queue
- * for the given window matching one of the events in the mask.
- * Events earlier in the queue are not discarded.
- * If none found, flush, and then wait until an event arrives which
- * matches.
- */
-
-int
-XWindowEvent (
- register Display *dpy,
- Window w, /* Selected window. */
- long mask, /* Selected event mask. */
- register XEvent *event) /* XEvent to be filled in. */
-{
- register _XQEvent *prev, *qelt;
- unsigned long qe_serial = 0;
-
- LockDisplay(dpy);
-
- /* Delete unclaimed cookies */
- _XFreeEventCookies(dpy);
-
- prev = NULL;
- while (1) {
- for (qelt = prev ? prev->next : dpy->head;
- qelt;
- prev = qelt, qelt = qelt->next) {
- if ((qelt->event.xany.window == w) &&
- (qelt->event.type < GenericEvent) &&
- (_Xevent_to_mask[qelt->event.type] & mask) &&
- ((qelt->event.type != MotionNotify) ||
- (mask & AllPointers) ||
- (mask & AllButtons & qelt->event.xmotion.state))) {
- *event = qelt->event;
- _XDeq(dpy, prev, qelt);
- UnlockDisplay(dpy);
- return 0;
- }
- }
- if (prev)
- qe_serial = prev->qserial_num;
- _XReadEvents(dpy);
- if (prev && prev->qserial_num != qe_serial)
- /* another thread has snatched this event */
- prev = NULL;
- }
-}
+/*
+
+Copyright 1985, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+
+extern long const _Xevent_to_mask[];
+#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
+#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
+ Button4MotionMask|Button5MotionMask)
+
+/*
+ * Return the next event in the queue
+ * for the given window matching one of the events in the mask.
+ * Events earlier in the queue are not discarded.
+ * If none found, flush, and then wait until an event arrives which
+ * matches.
+ */
+
+int
+XWindowEvent (
+ register Display *dpy,
+ Window w, /* Selected window. */
+ long mask, /* Selected event mask. */
+ register XEvent *event) /* XEvent to be filled in. */
+{
+ register _XQEvent *prev, *qelt;
+ unsigned long qe_serial = 0;
+
+ LockDisplay(dpy);
+
+ /* Delete unclaimed cookies */
+ _XFreeEventCookies(dpy);
+
+ prev = NULL;
+ while (1) {
+ for (qelt = prev ? prev->next : dpy->head;
+ qelt;
+ prev = qelt, qelt = qelt->next) {
+ if ((qelt->event.xany.window == w) &&
+ (qelt->event.type < GenericEvent) &&
+ (_Xevent_to_mask[qelt->event.type] & mask) &&
+ ((qelt->event.type != MotionNotify) ||
+ (mask & AllPointers) ||
+ (mask & AllButtons & qelt->event.xmotion.state))) {
+ *event = qelt->event;
+ _XDeq(dpy, prev, qelt);
+ UnlockDisplay(dpy);
+ return 0;
+ }
+ }
+ if (prev)
+ qe_serial = prev->qserial_num;
+ _XReadEvents(dpy);
+ if (prev && prev->qserial_num != qe_serial)
+ /* another thread has snatched this event */
+ prev = NULL;
+ }
+}
diff --git a/libX11/src/Withdraw.c b/libX11/src/Withdraw.c
index 9e284e49f..e691a6730 100644
--- a/libX11/src/Withdraw.c
+++ b/libX11/src/Withdraw.c
@@ -1,83 +1,82 @@
-
-/***********************************************************
-Copyright 1988 by Wyse Technology, Inc., San Jose, Ca.,
-
- 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 Wyse not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-WYSE 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.
-
-******************************************************************/
-/*
-
-Copyright 1988, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-#include <X11/Xatom.h>
-#include <X11/Xos.h>
-#include <X11/Xutil.h>
-#include <stdio.h>
-
-/*
- * This function instructs the window manager to change this window from
- * NormalState or IconicState to Withdrawn.
- */
-Status XWithdrawWindow (
- Display *dpy,
- Window w,
- int screen)
-{
- XUnmapEvent ev;
- Window root = RootWindow (dpy, screen);
-
- XUnmapWindow (dpy, w);
-
- ev.type = UnmapNotify;
- ev.event = root;
- ev.window = w;
- ev.from_configure = False;
- return (XSendEvent (dpy, root, False,
- SubstructureRedirectMask|SubstructureNotifyMask,
- (XEvent *)&ev));
-}
+
+/***********************************************************
+Copyright 1988 by Wyse Technology, Inc., San Jose, Ca.,
+
+ 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 Wyse not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+WYSE 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.
+
+******************************************************************/
+/*
+
+Copyright 1988, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/Xatom.h>
+#include <X11/Xos.h>
+#include <X11/Xutil.h>
+#include <stdio.h>
+
+/*
+ * This function instructs the window manager to change this window from
+ * NormalState or IconicState to Withdrawn.
+ */
+Status XWithdrawWindow (
+ Display *dpy,
+ Window w,
+ int screen)
+{
+ XUnmapEvent ev;
+ Window root = RootWindow (dpy, screen);
+
+ XUnmapWindow (dpy, w);
+
+ ev.type = UnmapNotify;
+ ev.event = root;
+ ev.window = w;
+ ev.from_configure = False;
+ return (XSendEvent (dpy, root, False,
+ SubstructureRedirectMask|SubstructureNotifyMask,
+ (XEvent *)&ev));
+}
diff --git a/libX11/src/XlibAsync.c b/libX11/src/XlibAsync.c
index b4483ef6b..db8cba807 100644
--- a/libX11/src/XlibAsync.c
+++ b/libX11/src/XlibAsync.c
@@ -1,155 +1,154 @@
-/*
-
-Copyright 1992, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-#include <X11/Xos.h>
-
-/*ARGSUSED*/
-Bool
-_XAsyncErrorHandler(
- register Display *dpy,
- register xReply *rep,
- char *buf,
- int len,
- XPointer data)
-{
- register _XAsyncErrorState *state;
-
- state = (_XAsyncErrorState *)data;
- if (rep->generic.type == X_Error &&
- (!state->error_code ||
- rep->error.errorCode == state->error_code) &&
- (!state->major_opcode ||
- rep->error.majorCode == state->major_opcode) &&
- (!state->minor_opcode ||
- rep->error.minorCode == state->minor_opcode) &&
- (!state->min_sequence_number ||
- (state->min_sequence_number <= dpy->last_request_read)) &&
- (!state->max_sequence_number ||
- (state->max_sequence_number >= dpy->last_request_read))) {
- state->last_error_received = rep->error.errorCode;
- state->error_count++;
- return True;
- }
- return False;
-}
-
-void _XDeqAsyncHandler(
- Display *dpy,
- register _XAsyncHandler *handler)
-{
- register _XAsyncHandler **prev;
- register _XAsyncHandler *async;
-
- for (prev = &dpy->async_handlers;
- (async = *prev) && (async != handler);
- prev = &async->next)
- ;
- if (async)
- *prev = async->next;
-}
-
-char *
-_XGetAsyncReply(
- register Display *dpy,
- register char *replbuf, /* data is read into this buffer */
- register xReply *rep, /* value passed to calling handler */
- char *buf, /* value passed to calling handler */
- int len, /* value passed to calling handler */
- int extra, /* extra words to read, ala _XReply */
- Bool discard) /* discard after extra?, ala _XReply */
-{
- if (extra == 0) {
- if (discard && (rep->generic.length << 2) > len)
- _XEatData (dpy, (rep->generic.length << 2) - len);
- return (char *)rep;
- }
-
- if (extra <= rep->generic.length) {
- int size = SIZEOF(xReply) + (extra << 2);
- if (size > len) {
- memcpy(replbuf, buf, len);
- _XRead(dpy, replbuf + len, size - len);
- buf = replbuf;
- len = size;
-#ifdef MUSTCOPY
- } else {
- memcpy(replbuf, buf, size);
- buf = replbuf;
-#endif
- }
-
- if (discard && rep->generic.length > extra &&
- (rep->generic.length << 2) > len)
- _XEatData (dpy, (rep->generic.length << 2) - len);
-
- return buf;
- }
- /*
- *if we get here, then extra > rep->generic.length--meaning we
- * read a reply that's shorter than we expected. This is an
- * error, but we still need to figure out how to handle it...
- */
- if ((rep->generic.length << 2) > len)
- _XEatData (dpy, (rep->generic.length << 2) - len);
- _XIOError (dpy);
- return (char *)rep;
-}
-
-void
-_XGetAsyncData(
- Display *dpy,
- char *data, /* data is read into this buffer */
- char *buf, /* value passed to calling handler */
- int len, /* value passed to calling handler */
- int skip, /* number of bytes already read in previous
- _XGetAsyncReply or _XGetAsyncData calls */
- int datalen, /* size of data buffer in bytes */
- int discardtotal) /* min. bytes to consume (after skip) */
-{
- buf += skip;
- len -= skip;
- if (!data) {
- if (datalen > len)
- _XEatData(dpy, datalen - len);
- } else if (datalen <= len) {
- memcpy(data, buf, datalen);
- } else {
- memcpy(data, buf, len);
- _XRead(dpy, data + len, datalen - len);
- }
- if (discardtotal > len) {
- if (datalen > len)
- len = datalen;
- _XEatData(dpy, discardtotal - len);
- }
-}
+/*
+
+Copyright 1992, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/Xos.h>
+
+/*ARGSUSED*/
+Bool
+_XAsyncErrorHandler(
+ register Display *dpy,
+ register xReply *rep,
+ char *buf,
+ int len,
+ XPointer data)
+{
+ register _XAsyncErrorState *state;
+
+ state = (_XAsyncErrorState *)data;
+ if (rep->generic.type == X_Error &&
+ (!state->error_code ||
+ rep->error.errorCode == state->error_code) &&
+ (!state->major_opcode ||
+ rep->error.majorCode == state->major_opcode) &&
+ (!state->minor_opcode ||
+ rep->error.minorCode == state->minor_opcode) &&
+ (!state->min_sequence_number ||
+ (state->min_sequence_number <= dpy->last_request_read)) &&
+ (!state->max_sequence_number ||
+ (state->max_sequence_number >= dpy->last_request_read))) {
+ state->last_error_received = rep->error.errorCode;
+ state->error_count++;
+ return True;
+ }
+ return False;
+}
+
+void _XDeqAsyncHandler(
+ Display *dpy,
+ register _XAsyncHandler *handler)
+{
+ register _XAsyncHandler **prev;
+ register _XAsyncHandler *async;
+
+ for (prev = &dpy->async_handlers;
+ (async = *prev) && (async != handler);
+ prev = &async->next)
+ ;
+ if (async)
+ *prev = async->next;
+}
+
+char *
+_XGetAsyncReply(
+ register Display *dpy,
+ register char *replbuf, /* data is read into this buffer */
+ register xReply *rep, /* value passed to calling handler */
+ char *buf, /* value passed to calling handler */
+ int len, /* value passed to calling handler */
+ int extra, /* extra words to read, ala _XReply */
+ Bool discard) /* discard after extra?, ala _XReply */
+{
+ if (extra == 0) {
+ if (discard && (rep->generic.length << 2) > len)
+ _XEatData (dpy, (rep->generic.length << 2) - len);
+ return (char *)rep;
+ }
+
+ if (extra <= rep->generic.length) {
+ int size = SIZEOF(xReply) + (extra << 2);
+ if (size > len) {
+ memcpy(replbuf, buf, len);
+ _XRead(dpy, replbuf + len, size - len);
+ buf = replbuf;
+ len = size;
+#ifdef MUSTCOPY
+ } else {
+ memcpy(replbuf, buf, size);
+ buf = replbuf;
+#endif
+ }
+
+ if (discard && rep->generic.length > extra &&
+ (rep->generic.length << 2) > len)
+ _XEatData (dpy, (rep->generic.length << 2) - len);
+
+ return buf;
+ }
+ /*
+ *if we get here, then extra > rep->generic.length--meaning we
+ * read a reply that's shorter than we expected. This is an
+ * error, but we still need to figure out how to handle it...
+ */
+ if ((rep->generic.length << 2) > len)
+ _XEatData (dpy, (rep->generic.length << 2) - len);
+ _XIOError (dpy);
+ return (char *)rep;
+}
+
+void
+_XGetAsyncData(
+ Display *dpy,
+ char *data, /* data is read into this buffer */
+ char *buf, /* value passed to calling handler */
+ int len, /* value passed to calling handler */
+ int skip, /* number of bytes already read in previous
+ _XGetAsyncReply or _XGetAsyncData calls */
+ int datalen, /* size of data buffer in bytes */
+ int discardtotal) /* min. bytes to consume (after skip) */
+{
+ buf += skip;
+ len -= skip;
+ if (!data) {
+ if (datalen > len)
+ _XEatData(dpy, datalen - len);
+ } else if (datalen <= len) {
+ memcpy(data, buf, datalen);
+ } else {
+ memcpy(data, buf, len);
+ _XRead(dpy, data + len, datalen - len);
+ }
+ if (discardtotal > len) {
+ if (datalen > len)
+ len = datalen;
+ _XEatData(dpy, discardtotal - len);
+ }
+}
diff --git a/libX11/src/XlibInt.c b/libX11/src/XlibInt.c
index 6ac93005f..17a0bd0a4 100644
--- a/libX11/src/XlibInt.c
+++ b/libX11/src/XlibInt.c
@@ -30,8 +30,6 @@ from The Open Group.
* XlibInt.c - Internal support routines for the C subroutine
* interface library (Xlib) to the X Window System Protocol V11.0.
*/
-#define NEED_EVENTS
-#define NEED_REPLIES
#ifdef WIN32
#define _XLIBINT_
diff --git a/libX11/src/globals.c b/libX11/src/globals.c
index 415ee81f3..661c99979 100644
--- a/libX11/src/globals.c
+++ b/libX11/src/globals.c
@@ -1,236 +1,235 @@
-/*
-
-Copyright 1989, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-/*
- *
- * Global data
- *
- * This file should contain only those objects which must be predefined.
- */
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-
-
-/*
- * If possible, it is useful to have the global data default to a null value.
- * Some shared library implementations are *much* happier if there isn't any
- * global initialized data.
- */
-#ifdef NULL_NOT_ZERO /* then need to initialize */
-#define SetZero(t,var,z) t var = z
-#else
-#define SetZero(t,var,z) t var
-#endif
-
-#ifdef USL_SHAREDLIB /* then need extra variables */
-/*
- * If we need to define extra variables for each global
- */
-#if !defined(UNIXCPP) || defined(ANSICPP)
-#define ZEROINIT(t,var,val) SetZero(t,var,val); \
- SetZero (long, _libX_##var##Flag, 0); \
- SetZero (void *, _libX_##var##Ptr, NULL)
-#else /* else pcc concatenation */
-#define ZEROINIT(t,var,val) SetZero(t,var,val); \
- SetZero (long, _libX_/**/var/**/Flag, 0); \
- SetZero (void *, _libX_/**/var/**/Ptr, NULL)
-#endif /* concat ANSI C vs. pcc */
-
-#else /* else not USL_SHAREDLIB */
-/*
- * no extra crud
- */
-#define ZEROINIT(t,var,val) SetZero (t, var, val)
-
-#endif /* USL_SHAREDLIB */
-
-
-/*
- * Error handlers; used to be in XlibInt.c
- */
-ZEROINIT (XErrorHandler, _XErrorFunction, NULL);
-ZEROINIT (XIOErrorHandler, _XIOErrorFunction, NULL);
-ZEROINIT (_XQEvent *, _qfree, NULL);
-
-
-/*
- * Debugging information and display list; used to be in XOpenDis.c
- */
-ZEROINIT (int, _Xdebug, 0);
-ZEROINIT (Display *, _XHeadOfDisplayList, NULL);
-
-
-
-#if 0
-#ifdef STREAMSCONN
-
-
-/* The following are how the Xstream connections are used: */
-/* 1) Local connections over pseudo-tty ports. */
-/* 2) SVR4 local connections using named streams or SVR3.2 */
-/* local connections using streams. */
-/* 3) SVR4 stream pipe code. This code is proprietary and */
-/* the actual code is not included in the XC distribution. */
-/* 4) remote connections using tcp */
-/* 5) remote connections using StarLan */
-
-/*
- * descriptor block for streams connections
- */
-
-#include "Xstreams.h"
-
-char _XsTypeOfStream[100] = { 0 };
-
-extern int write();
-extern int close();
-#ifdef SVR4
-extern int _XsSetupSpStream();
-extern int _XsSetupNamedStream();
-#endif
-extern int _XsSetupLocalStream();
-extern int _XsConnectLocalClient();
-extern int _XsCallLocalServer();
-extern int _XsReadLocalStream();
-extern int _XsErrorCall();
-extern int _XsWriteLocalStream();
-extern int _XsCloseLocalStream();
-extern int _XsSetupTliStream();
-extern int _XsConnectTliClient();
-extern int _XsCallTliServer();
-extern int _XsReadTliStream();
-extern int _XsWriteTliStream();
-extern int _XsCloseTliStream();
-
-
-Xstream _XsStream[] = {
-
- {
- /* local connections using pseudo-ttys */
-
- _XsSetupLocalStream,
- _XsConnectLocalClient,
- _XsCallLocalServer,
- _XsReadLocalStream,
- _XsErrorCall,
- write,
- close,
- NULL
- },
- {
-#ifdef SVR4
- /* local connections using named streams */
-
- _XsSetupNamedStream,
-#else
- /* local connections using streams */
- _XsSetupLocalStream,
-#endif
- _XsConnectLocalClient,
- _XsCallLocalServer,
- _XsReadLocalStream,
- _XsErrorCall,
- write,
- close,
- NULL
- },
- /* Enhanced Application Compatibility Support */
- {
-#ifdef SVR4
- /* SVR4 stream pipe code */
- _XsSetupSpStream,
-#else
- _XsSetupLocalStream,
-#endif
- _XsConnectLocalClient,
- _XsCallLocalServer,
- _XsReadLocalStream,
- _XsErrorCall,
- write,
- close,
- NULL
- },
- /* End Enhanced Application Compatibility Support */
-
- {
- /* remote connections using tcp */
- _XsSetupTliStream,
- _XsConnectTliClient,
- _XsCallTliServer,
- _XsReadLocalStream,
- _XsErrorCall,
- write,
- close,
- NULL
- },
- {
- /* remote connections using StarLan */
- _XsSetupTliStream,
- _XsConnectTliClient,
- _XsCallTliServer,
- _XsReadLocalStream,
- _XsErrorCall,
- write,
- close,
- NULL
- }
-};
-
-
-#endif /* STREAMSCONN */
-#endif
-
-
-#ifdef XTEST1
-/*
- * Stuff for input synthesis extension:
- */
-/*
- * Holds the two event type codes for this extension. The event type codes
- * for this extension may vary depending on how many extensions are installed
- * already, so the initial values given below will be added to the base event
- * code that is aquired when this extension is installed.
- *
- * These two variables must be available to programs that use this extension.
- */
-int XTestInputActionType = 0;
-int XTestFakeAckType = 1;
-#endif
-
-/*
- * NOTE: any additional external definition NEED
- * to be inserted BELOW this point!!!
- */
-
-/*
- * NOTE: any additional external definition NEED
- * to be inserted ABOVE this point!!!
- */
+/*
+
+Copyright 1989, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+/*
+ *
+ * Global data
+ *
+ * This file should contain only those objects which must be predefined.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+
+
+/*
+ * If possible, it is useful to have the global data default to a null value.
+ * Some shared library implementations are *much* happier if there isn't any
+ * global initialized data.
+ */
+#ifdef NULL_NOT_ZERO /* then need to initialize */
+#define SetZero(t,var,z) t var = z
+#else
+#define SetZero(t,var,z) t var
+#endif
+
+#ifdef USL_SHAREDLIB /* then need extra variables */
+/*
+ * If we need to define extra variables for each global
+ */
+#if !defined(UNIXCPP) || defined(ANSICPP)
+#define ZEROINIT(t,var,val) SetZero(t,var,val); \
+ SetZero (long, _libX_##var##Flag, 0); \
+ SetZero (void *, _libX_##var##Ptr, NULL)
+#else /* else pcc concatenation */
+#define ZEROINIT(t,var,val) SetZero(t,var,val); \
+ SetZero (long, _libX_/**/var/**/Flag, 0); \
+ SetZero (void *, _libX_/**/var/**/Ptr, NULL)
+#endif /* concat ANSI C vs. pcc */
+
+#else /* else not USL_SHAREDLIB */
+/*
+ * no extra crud
+ */
+#define ZEROINIT(t,var,val) SetZero (t, var, val)
+
+#endif /* USL_SHAREDLIB */
+
+
+/*
+ * Error handlers; used to be in XlibInt.c
+ */
+ZEROINIT (XErrorHandler, _XErrorFunction, NULL);
+ZEROINIT (XIOErrorHandler, _XIOErrorFunction, NULL);
+ZEROINIT (_XQEvent *, _qfree, NULL);
+
+
+/*
+ * Debugging information and display list; used to be in XOpenDis.c
+ */
+ZEROINIT (int, _Xdebug, 0);
+ZEROINIT (Display *, _XHeadOfDisplayList, NULL);
+
+
+
+#if 0
+#ifdef STREAMSCONN
+
+
+/* The following are how the Xstream connections are used: */
+/* 1) Local connections over pseudo-tty ports. */
+/* 2) SVR4 local connections using named streams or SVR3.2 */
+/* local connections using streams. */
+/* 3) SVR4 stream pipe code. This code is proprietary and */
+/* the actual code is not included in the XC distribution. */
+/* 4) remote connections using tcp */
+/* 5) remote connections using StarLan */
+
+/*
+ * descriptor block for streams connections
+ */
+
+#include "Xstreams.h"
+
+char _XsTypeOfStream[100] = { 0 };
+
+extern int write();
+extern int close();
+#ifdef SVR4
+extern int _XsSetupSpStream();
+extern int _XsSetupNamedStream();
+#endif
+extern int _XsSetupLocalStream();
+extern int _XsConnectLocalClient();
+extern int _XsCallLocalServer();
+extern int _XsReadLocalStream();
+extern int _XsErrorCall();
+extern int _XsWriteLocalStream();
+extern int _XsCloseLocalStream();
+extern int _XsSetupTliStream();
+extern int _XsConnectTliClient();
+extern int _XsCallTliServer();
+extern int _XsReadTliStream();
+extern int _XsWriteTliStream();
+extern int _XsCloseTliStream();
+
+
+Xstream _XsStream[] = {
+
+ {
+ /* local connections using pseudo-ttys */
+
+ _XsSetupLocalStream,
+ _XsConnectLocalClient,
+ _XsCallLocalServer,
+ _XsReadLocalStream,
+ _XsErrorCall,
+ write,
+ close,
+ NULL
+ },
+ {
+#ifdef SVR4
+ /* local connections using named streams */
+
+ _XsSetupNamedStream,
+#else
+ /* local connections using streams */
+ _XsSetupLocalStream,
+#endif
+ _XsConnectLocalClient,
+ _XsCallLocalServer,
+ _XsReadLocalStream,
+ _XsErrorCall,
+ write,
+ close,
+ NULL
+ },
+ /* Enhanced Application Compatibility Support */
+ {
+#ifdef SVR4
+ /* SVR4 stream pipe code */
+ _XsSetupSpStream,
+#else
+ _XsSetupLocalStream,
+#endif
+ _XsConnectLocalClient,
+ _XsCallLocalServer,
+ _XsReadLocalStream,
+ _XsErrorCall,
+ write,
+ close,
+ NULL
+ },
+ /* End Enhanced Application Compatibility Support */
+
+ {
+ /* remote connections using tcp */
+ _XsSetupTliStream,
+ _XsConnectTliClient,
+ _XsCallTliServer,
+ _XsReadLocalStream,
+ _XsErrorCall,
+ write,
+ close,
+ NULL
+ },
+ {
+ /* remote connections using StarLan */
+ _XsSetupTliStream,
+ _XsConnectTliClient,
+ _XsCallTliServer,
+ _XsReadLocalStream,
+ _XsErrorCall,
+ write,
+ close,
+ NULL
+ }
+};
+
+
+#endif /* STREAMSCONN */
+#endif
+
+
+#ifdef XTEST1
+/*
+ * Stuff for input synthesis extension:
+ */
+/*
+ * Holds the two event type codes for this extension. The event type codes
+ * for this extension may vary depending on how many extensions are installed
+ * already, so the initial values given below will be added to the base event
+ * code that is aquired when this extension is installed.
+ *
+ * These two variables must be available to programs that use this extension.
+ */
+int XTestInputActionType = 0;
+int XTestFakeAckType = 1;
+#endif
+
+/*
+ * NOTE: any additional external definition NEED
+ * to be inserted BELOW this point!!!
+ */
+
+/*
+ * NOTE: any additional external definition NEED
+ * to be inserted ABOVE this point!!!
+ */
diff --git a/libX11/src/imConv.c b/libX11/src/imConv.c
index 4068b59ba..7c1ed89cf 100644
--- a/libX11/src/imConv.c
+++ b/libX11/src/imConv.c
@@ -1,357 +1,356 @@
-/******************************************************************
-
- Copyright 1991, 1992 by Fuji Xerox Co.,Ltd.
- Copyright 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 Fuji Xerox Co.,Ltd.
-, 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.
-Fuji Xerox Co.,Ltd. , and FUJITSU LIMITED makes no representations about
-the suitability of this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJI XEROX CO.,LTD. AND FUJITSU LIMITED DISCLAIMS ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX CO.,LTD.
-AND 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.
-
- Auther: Kazunori Nishihara, Fuji Xerox Co.,Ltd.
- kaz@ssdev.ksp.fujixerox.co.jp
- Modifier: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-/* 2000 Modifier: Ivan Pascal The XFree86 Project.
- */
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "XlcPubI.h"
-
-#ifdef XKB
-/*
- * rather than just call _XLookupString (i.e. the pre-XKB XLookupString)
- * do this because with XKB the event may have some funky modifiers that
- * _XLookupString doesn't grok.
- */
-#include "XKBlib.h"
-#define XLOOKUPSTRING lookup_string
-#else
-#define XLOOKUPSTRING XLookupString
-#endif
-
-typedef unsigned int ucs4_t;
-
-typedef int (*ucstocsConvProc)(
- XPointer,
- unsigned char *,
- ucs4_t,
- int
-);
-
-struct SubstRec {
- const char encoding_name[8];
- const char charset_name[12];
-};
-
-static const struct SubstRec SubstTable[] = {
- {"STRING", "ISO8859-1"},
- {"TIS620", "TIS620-0"},
- {"UTF-8", "ISO10646-1"}
-};
-#define num_substitute (sizeof SubstTable / sizeof SubstTable[0])
-
-/*
- * Given the name of a charset, returns the pointer to convertors
- * from UCS char to specified charset char.
- * This converter is needed for _XimGetCharCode subroutine.
- */
-XPointer
-_XimGetLocaleCode (
- _Xconst char* encoding_name)
-{
- XPointer cvt = _Utf8GetConvByName(encoding_name);
- if (!cvt && encoding_name) {
- int i;
- for (i = 0; i < num_substitute; i++)
- if (!strcmp(encoding_name, SubstTable[i].encoding_name))
- return _Utf8GetConvByName(SubstTable[i].charset_name);
- }
- return cvt;
-}
-
-/*
- * Returns the locale dependent representation of a keysym.
- * The locale's encoding is passed in form of pointer to UCS convertor.
- * The resulting multi-byte sequence is placed starting at buf (a buffer
- * with nbytes bytes, nbytes should be >= 8) and is NUL terminated.
- * Returns the length of the resulting multi-byte sequence, excluding the
- * terminating NUL byte. Return 0 if the keysym is not representable in the
- * locale
- */
-/*ARGSUSED*/
-int
-_XimGetCharCode (
- XPointer ucs_conv,
- KeySym keysym,
- unsigned char* buf,
- int nbytes)
-{
- int count = 0;
- ucstocsConvProc cvt = (ucstocsConvProc) ucs_conv;
- ucs4_t ucs4;
-
- if (keysym < 0x80) {
- buf[0] = (char) keysym;
- count = 1;
- } else if (cvt) {
- ucs4 = KeySymToUcs4(keysym);
- if (ucs4)
- count = (*cvt)((XPointer)NULL, buf, ucs4, nbytes);
- }
-
- if (count < 0)
- count = 0;
- if (count>nbytes)
- return nbytes;
- if (count<nbytes)
- buf[count]= '\0';
- return count;
-}
-
-#ifdef XKB
-static int lookup_string(
- XKeyEvent* event,
- char* buffer,
- int nbytes,
- KeySym* keysym,
- XComposeStatus* status)
-{
- int ret;
- unsigned ctrls = XkbGetXlibControls (event->display);
- XkbSetXlibControls (event->display,
- XkbLC_ForceLatin1Lookup, XkbLC_ForceLatin1Lookup);
- ret = XLookupString(event, (char *)buffer, nbytes, keysym, status);
- XkbSetXlibControls (event->display,
- XkbLC_ForceLatin1Lookup, ctrls);
- return ret;
-}
-#endif
-
-#define BUF_SIZE (20)
-
-int
-_XimLookupMBText(
- Xic ic,
- XKeyEvent* event,
- char* buffer,
- int nbytes,
- KeySym* keysym,
- XComposeStatus* status)
-{
- int count;
- KeySym symbol;
- Status dummy;
- Xim im = (Xim)ic->core.im;
- XimCommonPrivateRec* private = &im->private.common;
- unsigned char look[BUF_SIZE];
- ucs4_t ucs4;
-
- /* force a latin-1 lookup for compatibility */
- count = XLOOKUPSTRING(event, (char *)buffer, nbytes, &symbol, status);
- if (keysym != NULL) *keysym = symbol;
- if ((nbytes == 0) || (symbol == NoSymbol)) return count;
-
- if (count > 1) {
- memcpy(look, (char *)buffer,count);
- look[count] = '\0';
- if ((count = im->methods->ctstombs(ic->core.im,
- (char*) look, count,
- buffer, nbytes, &dummy)) < 0) {
- count = 0;
- }
- } else if ((count == 0) ||
- (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
-
- XPointer from = (XPointer) &ucs4;
- XPointer to = (XPointer) look;
- int from_len = 1;
- int to_len = BUF_SIZE;
- XPointer args[1];
- XlcCharSet charset;
- args[0] = (XPointer) &charset;
- ucs4 = (ucs4_t) KeySymToUcs4(symbol);
- if (!ucs4)
- return 0;
-
- if (_XlcConvert(private->ucstoc_conv,
- &from, &from_len, &to, &to_len,
- args, 1 ) != 0) {
- count = 0;
- } else {
- from = (XPointer) look;
- to = (XPointer) buffer;
- from_len = BUF_SIZE - to_len;
- to_len = nbytes;
- args[0] = (XPointer) charset;
- if (_XlcConvert(private->cstomb_conv,
- &from, &from_len, &to, &to_len,
- args, 1 ) != 0) {
- count = 0;
- } else {
- count = nbytes - to_len;
- }
- }
- }
- /* FIXME:
- * we should make sure that if the character is a Latin1 character
- * and it's on the right side, and we're in a non-Latin1 locale
- * that this is a valid Latin1 character for this locale.
- */
- return count;
-}
-
-int
-_XimLookupWCText(
- Xic ic,
- XKeyEvent* event,
- wchar_t* buffer,
- int nbytes,
- KeySym* keysym,
- XComposeStatus* status)
-{
- int count;
- KeySym symbol;
- Status dummy;
- Xim im = (Xim)ic->core.im;
- XimCommonPrivateRec* private = &im->private.common;
- unsigned char look[BUF_SIZE];
- ucs4_t ucs4;
-
- /* force a latin-1 lookup for compatibility */
- count = XLOOKUPSTRING(event, (char *)look, nbytes, &symbol, status);
- if (keysym != NULL) *keysym = symbol;
- if ((nbytes == 0) || (symbol == NoSymbol)) return count;
-
- if (count > 1) {
- if ((count = im->methods->ctstowcs(ic->core.im,
- (char*) look, count,
- buffer, nbytes, &dummy)) < 0) {
- count = 0;
- }
- } else if ((count == 0) ||
- (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
-
- XPointer from = (XPointer) &ucs4;
- XPointer to = (XPointer) look;
- int from_len = 1;
- int to_len = BUF_SIZE;
- XPointer args[1];
- XlcCharSet charset;
- args[0] = (XPointer) &charset;
- ucs4 = (ucs4_t) KeySymToUcs4(symbol);
- if (!ucs4)
- return 0;
-
- if (_XlcConvert(private->ucstoc_conv,
- &from, &from_len, &to, &to_len,
- args, 1 ) != 0) {
- count = 0;
- } else {
- from = (XPointer) look;
- to = (XPointer) buffer;
- from_len = BUF_SIZE - to_len;
- to_len = nbytes;
- args[0] = (XPointer) charset;
-
- if (_XlcConvert(private->cstowc_conv,
- &from, &from_len, &to, &to_len,
- args, 1 ) != 0) {
- count = 0;
- } else {
- count = nbytes - to_len;
- }
- }
- } else
- /* FIXME:
- * we should make sure that if the character is a Latin1 character
- * and it's on the right side, and we're in a non-Latin1 locale
- * that this is a valid Latin1 character for this locale.
- */
- buffer[0] = look[0];
-
- return count;
-}
-
-int
-_XimLookupUTF8Text(
- Xic ic,
- XKeyEvent* event,
- char* buffer,
- int nbytes,
- KeySym* keysym,
- XComposeStatus* status)
-{
- int count;
- KeySym symbol;
- Status dummy;
- Xim im = (Xim)ic->core.im;
- XimCommonPrivateRec* private = &im->private.common;
- unsigned char look[BUF_SIZE];
- ucs4_t ucs4;
-
- /* force a latin-1 lookup for compatibility */
- count = XLOOKUPSTRING(event, (char *)buffer, nbytes, &symbol, status);
- if (keysym != NULL) *keysym = symbol;
- if ((nbytes == 0) || (symbol == NoSymbol)) return count;
-
- if (count > 1) {
- memcpy(look, (char *)buffer,count);
- look[count] = '\0';
- if ((count = im->methods->ctstoutf8(ic->core.im,
- (char*) look, count,
- buffer, nbytes, &dummy)) < 0) {
- count = 0;
- }
- } else if ((count == 0) ||
- (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
-
- XPointer from = (XPointer) &ucs4;
- int from_len = 1;
- XPointer to = (XPointer) buffer;
- int to_len = nbytes;
-
- ucs4 = (ucs4_t) KeySymToUcs4(symbol);
- if (!ucs4)
- return 0;
-
- if (_XlcConvert(private->ucstoutf8_conv,
- &from, &from_len, &to, &to_len,
- NULL, 0) != 0) {
- count = 0;
- } else {
- count = nbytes - to_len;
- }
- }
- /* FIXME:
- * we should make sure that if the character is a Latin1 character
- * and it's on the right side, and we're in a non-Latin1 locale
- * that this is a valid Latin1 character for this locale.
- */
- return count;
-}
+/******************************************************************
+
+ Copyright 1991, 1992 by Fuji Xerox Co.,Ltd.
+ Copyright 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 Fuji Xerox Co.,Ltd.
+, 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.
+Fuji Xerox Co.,Ltd. , and FUJITSU LIMITED makes no representations about
+the suitability of this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJI XEROX CO.,LTD. AND FUJITSU LIMITED DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX CO.,LTD.
+AND 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.
+
+ Auther: Kazunori Nishihara, Fuji Xerox Co.,Ltd.
+ kaz@ssdev.ksp.fujixerox.co.jp
+ Modifier: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+/* 2000 Modifier: Ivan Pascal The XFree86 Project.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "XlcPubI.h"
+
+#ifdef XKB
+/*
+ * rather than just call _XLookupString (i.e. the pre-XKB XLookupString)
+ * do this because with XKB the event may have some funky modifiers that
+ * _XLookupString doesn't grok.
+ */
+#include "XKBlib.h"
+#define XLOOKUPSTRING lookup_string
+#else
+#define XLOOKUPSTRING XLookupString
+#endif
+
+typedef unsigned int ucs4_t;
+
+typedef int (*ucstocsConvProc)(
+ XPointer,
+ unsigned char *,
+ ucs4_t,
+ int
+);
+
+struct SubstRec {
+ const char encoding_name[8];
+ const char charset_name[12];
+};
+
+static const struct SubstRec SubstTable[] = {
+ {"STRING", "ISO8859-1"},
+ {"TIS620", "TIS620-0"},
+ {"UTF-8", "ISO10646-1"}
+};
+#define num_substitute (sizeof SubstTable / sizeof SubstTable[0])
+
+/*
+ * Given the name of a charset, returns the pointer to convertors
+ * from UCS char to specified charset char.
+ * This converter is needed for _XimGetCharCode subroutine.
+ */
+XPointer
+_XimGetLocaleCode (
+ _Xconst char* encoding_name)
+{
+ XPointer cvt = _Utf8GetConvByName(encoding_name);
+ if (!cvt && encoding_name) {
+ int i;
+ for (i = 0; i < num_substitute; i++)
+ if (!strcmp(encoding_name, SubstTable[i].encoding_name))
+ return _Utf8GetConvByName(SubstTable[i].charset_name);
+ }
+ return cvt;
+}
+
+/*
+ * Returns the locale dependent representation of a keysym.
+ * The locale's encoding is passed in form of pointer to UCS convertor.
+ * The resulting multi-byte sequence is placed starting at buf (a buffer
+ * with nbytes bytes, nbytes should be >= 8) and is NUL terminated.
+ * Returns the length of the resulting multi-byte sequence, excluding the
+ * terminating NUL byte. Return 0 if the keysym is not representable in the
+ * locale
+ */
+/*ARGSUSED*/
+int
+_XimGetCharCode (
+ XPointer ucs_conv,
+ KeySym keysym,
+ unsigned char* buf,
+ int nbytes)
+{
+ int count = 0;
+ ucstocsConvProc cvt = (ucstocsConvProc) ucs_conv;
+ ucs4_t ucs4;
+
+ if (keysym < 0x80) {
+ buf[0] = (char) keysym;
+ count = 1;
+ } else if (cvt) {
+ ucs4 = KeySymToUcs4(keysym);
+ if (ucs4)
+ count = (*cvt)((XPointer)NULL, buf, ucs4, nbytes);
+ }
+
+ if (count < 0)
+ count = 0;
+ if (count>nbytes)
+ return nbytes;
+ if (count<nbytes)
+ buf[count]= '\0';
+ return count;
+}
+
+#ifdef XKB
+static int lookup_string(
+ XKeyEvent* event,
+ char* buffer,
+ int nbytes,
+ KeySym* keysym,
+ XComposeStatus* status)
+{
+ int ret;
+ unsigned ctrls = XkbGetXlibControls (event->display);
+ XkbSetXlibControls (event->display,
+ XkbLC_ForceLatin1Lookup, XkbLC_ForceLatin1Lookup);
+ ret = XLookupString(event, (char *)buffer, nbytes, keysym, status);
+ XkbSetXlibControls (event->display,
+ XkbLC_ForceLatin1Lookup, ctrls);
+ return ret;
+}
+#endif
+
+#define BUF_SIZE (20)
+
+int
+_XimLookupMBText(
+ Xic ic,
+ XKeyEvent* event,
+ char* buffer,
+ int nbytes,
+ KeySym* keysym,
+ XComposeStatus* status)
+{
+ int count;
+ KeySym symbol;
+ Status dummy;
+ Xim im = (Xim)ic->core.im;
+ XimCommonPrivateRec* private = &im->private.common;
+ unsigned char look[BUF_SIZE];
+ ucs4_t ucs4;
+
+ /* force a latin-1 lookup for compatibility */
+ count = XLOOKUPSTRING(event, (char *)buffer, nbytes, &symbol, status);
+ if (keysym != NULL) *keysym = symbol;
+ if ((nbytes == 0) || (symbol == NoSymbol)) return count;
+
+ if (count > 1) {
+ memcpy(look, (char *)buffer,count);
+ look[count] = '\0';
+ if ((count = im->methods->ctstombs(ic->core.im,
+ (char*) look, count,
+ buffer, nbytes, &dummy)) < 0) {
+ count = 0;
+ }
+ } else if ((count == 0) ||
+ (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
+
+ XPointer from = (XPointer) &ucs4;
+ XPointer to = (XPointer) look;
+ int from_len = 1;
+ int to_len = BUF_SIZE;
+ XPointer args[1];
+ XlcCharSet charset;
+ args[0] = (XPointer) &charset;
+ ucs4 = (ucs4_t) KeySymToUcs4(symbol);
+ if (!ucs4)
+ return 0;
+
+ if (_XlcConvert(private->ucstoc_conv,
+ &from, &from_len, &to, &to_len,
+ args, 1 ) != 0) {
+ count = 0;
+ } else {
+ from = (XPointer) look;
+ to = (XPointer) buffer;
+ from_len = BUF_SIZE - to_len;
+ to_len = nbytes;
+ args[0] = (XPointer) charset;
+ if (_XlcConvert(private->cstomb_conv,
+ &from, &from_len, &to, &to_len,
+ args, 1 ) != 0) {
+ count = 0;
+ } else {
+ count = nbytes - to_len;
+ }
+ }
+ }
+ /* FIXME:
+ * we should make sure that if the character is a Latin1 character
+ * and it's on the right side, and we're in a non-Latin1 locale
+ * that this is a valid Latin1 character for this locale.
+ */
+ return count;
+}
+
+int
+_XimLookupWCText(
+ Xic ic,
+ XKeyEvent* event,
+ wchar_t* buffer,
+ int nbytes,
+ KeySym* keysym,
+ XComposeStatus* status)
+{
+ int count;
+ KeySym symbol;
+ Status dummy;
+ Xim im = (Xim)ic->core.im;
+ XimCommonPrivateRec* private = &im->private.common;
+ unsigned char look[BUF_SIZE];
+ ucs4_t ucs4;
+
+ /* force a latin-1 lookup for compatibility */
+ count = XLOOKUPSTRING(event, (char *)look, nbytes, &symbol, status);
+ if (keysym != NULL) *keysym = symbol;
+ if ((nbytes == 0) || (symbol == NoSymbol)) return count;
+
+ if (count > 1) {
+ if ((count = im->methods->ctstowcs(ic->core.im,
+ (char*) look, count,
+ buffer, nbytes, &dummy)) < 0) {
+ count = 0;
+ }
+ } else if ((count == 0) ||
+ (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
+
+ XPointer from = (XPointer) &ucs4;
+ XPointer to = (XPointer) look;
+ int from_len = 1;
+ int to_len = BUF_SIZE;
+ XPointer args[1];
+ XlcCharSet charset;
+ args[0] = (XPointer) &charset;
+ ucs4 = (ucs4_t) KeySymToUcs4(symbol);
+ if (!ucs4)
+ return 0;
+
+ if (_XlcConvert(private->ucstoc_conv,
+ &from, &from_len, &to, &to_len,
+ args, 1 ) != 0) {
+ count = 0;
+ } else {
+ from = (XPointer) look;
+ to = (XPointer) buffer;
+ from_len = BUF_SIZE - to_len;
+ to_len = nbytes;
+ args[0] = (XPointer) charset;
+
+ if (_XlcConvert(private->cstowc_conv,
+ &from, &from_len, &to, &to_len,
+ args, 1 ) != 0) {
+ count = 0;
+ } else {
+ count = nbytes - to_len;
+ }
+ }
+ } else
+ /* FIXME:
+ * we should make sure that if the character is a Latin1 character
+ * and it's on the right side, and we're in a non-Latin1 locale
+ * that this is a valid Latin1 character for this locale.
+ */
+ buffer[0] = look[0];
+
+ return count;
+}
+
+int
+_XimLookupUTF8Text(
+ Xic ic,
+ XKeyEvent* event,
+ char* buffer,
+ int nbytes,
+ KeySym* keysym,
+ XComposeStatus* status)
+{
+ int count;
+ KeySym symbol;
+ Status dummy;
+ Xim im = (Xim)ic->core.im;
+ XimCommonPrivateRec* private = &im->private.common;
+ unsigned char look[BUF_SIZE];
+ ucs4_t ucs4;
+
+ /* force a latin-1 lookup for compatibility */
+ count = XLOOKUPSTRING(event, (char *)buffer, nbytes, &symbol, status);
+ if (keysym != NULL) *keysym = symbol;
+ if ((nbytes == 0) || (symbol == NoSymbol)) return count;
+
+ if (count > 1) {
+ memcpy(look, (char *)buffer,count);
+ look[count] = '\0';
+ if ((count = im->methods->ctstoutf8(ic->core.im,
+ (char*) look, count,
+ buffer, nbytes, &dummy)) < 0) {
+ count = 0;
+ }
+ } else if ((count == 0) ||
+ (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
+
+ XPointer from = (XPointer) &ucs4;
+ int from_len = 1;
+ XPointer to = (XPointer) buffer;
+ int to_len = nbytes;
+
+ ucs4 = (ucs4_t) KeySymToUcs4(symbol);
+ if (!ucs4)
+ return 0;
+
+ if (_XlcConvert(private->ucstoutf8_conv,
+ &from, &from_len, &to, &to_len,
+ NULL, 0) != 0) {
+ count = 0;
+ } else {
+ count = nbytes - to_len;
+ }
+ }
+ /* FIXME:
+ * we should make sure that if the character is a Latin1 character
+ * and it's on the right side, and we're in a non-Latin1 locale
+ * that this is a valid Latin1 character for this locale.
+ */
+ return count;
+}
diff --git a/libX11/src/xcms/cmsAllNCol.c b/libX11/src/xcms/cmsAllNCol.c
index 105e8bd98..79e1bfe7f 100644
--- a/libX11/src/xcms/cmsAllNCol.c
+++ b/libX11/src/xcms/cmsAllNCol.c
@@ -1,199 +1,198 @@
-
-/*
- * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
- * All Rights Reserved
- *
- * This file is a component of an X Window System-specific implementation
- * of Xcms based on the TekColor Color Management System. Permission is
- * hereby granted to use, copy, modify, sell, and otherwise distribute this
- * software and its documentation for any purpose and without fee, provided
- * that this copyright, permission, and disclaimer notice is reproduced in
- * all copies of this software and in supporting documentation. TekColor
- * is a trademark of Tektronix, Inc.
- *
- * Tektronix makes no representation about the suitability of this software
- * for any purpose. It is provided "as is" and with all faults.
- *
- * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
- * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX 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 THE PERFORMANCE OF THIS SOFTWARE.
- *
- *
- * NAME
- * XcmsAlNCol.c
- *
- * DESCRIPTION
- * Source for XcmsAllocNamedColor
- *
- *
- */
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "Xcmsint.h"
-#include "Cv.h"
-
-
-/*
- * NAME
- * XcmsAllocNamedColor -
- *
- * SYNOPSIS
- */
-Status
-XcmsAllocNamedColor (
- Display *dpy,
- Colormap cmap,
- _Xconst char *colorname,
- XcmsColor *pColor_scrn_return,
- XcmsColor *pColor_exact_return,
- XcmsColorFormat result_format)
-/*
- * DESCRIPTION
- * Finds the color specification associated with the color
- * name in the Device-Independent Color Name Database, then
- * converts that color specification to an RGB format. This
- * RGB value is then used in a call to XAllocColor to allocate
- * a read-only color cell.
- *
- * RETURNS
- * 0 if failed to parse string or find any entry in the database.
- * 1 if succeeded in converting color name to XcmsColor.
- * 2 if succeeded in converting color name to another color name.
- *
- */
-{
- long nbytes;
- xAllocNamedColorReply rep;
- xAllocNamedColorReq *req;
- XColor hard_def;
- XColor exact_def;
- Status retval1 = 1;
- Status retval2 = XcmsSuccess;
- XcmsColor tmpColor;
- XColor XColor_in_out;
- XcmsCCC ccc;
-
- /*
- * 0. Check for invalid arguments.
- */
- if (dpy == NULL || colorname[0] == '\0' || pColor_scrn_return == 0
- || pColor_exact_return == NULL) {
- return(XcmsFailure);
- }
-
- if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) {
- return(XcmsFailure);
- }
-
- /*
- * 1. Convert string to a XcmsColor using Xcms and i18n mechanism
- */
- if ((retval1 = _XcmsResolveColorString(ccc, &colorname,
- &tmpColor, result_format)) == XcmsFailure) {
- return(XcmsFailure);
- }
- if (retval1 == _XCMS_NEWNAME) {
- goto PassToServer;
- }
- memcpy((char *)pColor_exact_return, (char *)&tmpColor, sizeof(XcmsColor));
-
- /*
- * 2. Convert tmpColor to RGB
- * Assume pColor_exact_return is now adjusted to Client White Point
- */
- if ((retval2 = XcmsConvertColors(ccc, &tmpColor,
- 1, XcmsRGBFormat, (Bool *) NULL)) == XcmsFailure) {
- return(XcmsFailure);
- }
-
- /*
- * 3. Convert to XColor and call XAllocColor
- */
- _XcmsRGB_to_XColor(&tmpColor, &XColor_in_out, 1);
- if (XAllocColor(ccc->dpy, cmap, &XColor_in_out) == 0) {
- return(XcmsFailure);
- }
-
- /*
- * 4. pColor_scrn_return
- *
- * Now convert to the target format.
- * We can ignore the return value because we're already in a
- * device-dependent format.
- */
- _XColor_to_XcmsRGB(ccc, &XColor_in_out, pColor_scrn_return, 1);
- if (result_format != XcmsRGBFormat) {
- if (result_format == XcmsUndefinedFormat) {
- result_format = pColor_exact_return->format;
- }
- if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
- (Bool *) NULL) == XcmsFailure) {
- return(XcmsFailure);
- }
- }
-
- return(retval1 > retval2 ? retval1 : retval2);
-
-PassToServer:
- /*
- * All previous methods failed, so lets pass it to the server
- * for parsing.
- */
- dpy = ccc->dpy;
- LockDisplay(dpy);
- GetReq(AllocNamedColor, req);
-
- req->cmap = cmap;
- nbytes = req->nbytes = strlen(colorname);
- req->length += (nbytes + 3) >> 2; /* round up to mult of 4 */
-
- _XSend(dpy, colorname, nbytes);
- /* _XSend is more efficient that Data, since _XReply follows */
-
- if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (0);
- }
-
- exact_def.red = rep.exactRed;
- exact_def.green = rep.exactGreen;
- exact_def.blue = rep.exactBlue;
-
- hard_def.red = rep.screenRed;
- hard_def.green = rep.screenGreen;
- hard_def.blue = rep.screenBlue;
-
- exact_def.pixel = hard_def.pixel = rep.pixel;
-
- UnlockDisplay(dpy);
- SyncHandle();
-
- /*
- * Now convert to the target format.
- */
- _XColor_to_XcmsRGB(ccc, &exact_def, pColor_exact_return, 1);
- _XColor_to_XcmsRGB(ccc, &hard_def, pColor_scrn_return, 1);
- if (result_format != XcmsRGBFormat
- && result_format != XcmsUndefinedFormat) {
- if (XcmsConvertColors(ccc, pColor_exact_return, 1, result_format,
- (Bool *) NULL) == XcmsFailure) {
- return(XcmsFailure);
- }
- if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
- (Bool *) NULL) == XcmsFailure) {
- return(XcmsFailure);
- }
- }
-
- return(XcmsSuccess);
-}
+
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX 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 THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsAlNCol.c
+ *
+ * DESCRIPTION
+ * Source for XcmsAllocNamedColor
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/*
+ * NAME
+ * XcmsAllocNamedColor -
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsAllocNamedColor (
+ Display *dpy,
+ Colormap cmap,
+ _Xconst char *colorname,
+ XcmsColor *pColor_scrn_return,
+ XcmsColor *pColor_exact_return,
+ XcmsColorFormat result_format)
+/*
+ * DESCRIPTION
+ * Finds the color specification associated with the color
+ * name in the Device-Independent Color Name Database, then
+ * converts that color specification to an RGB format. This
+ * RGB value is then used in a call to XAllocColor to allocate
+ * a read-only color cell.
+ *
+ * RETURNS
+ * 0 if failed to parse string or find any entry in the database.
+ * 1 if succeeded in converting color name to XcmsColor.
+ * 2 if succeeded in converting color name to another color name.
+ *
+ */
+{
+ long nbytes;
+ xAllocNamedColorReply rep;
+ xAllocNamedColorReq *req;
+ XColor hard_def;
+ XColor exact_def;
+ Status retval1 = 1;
+ Status retval2 = XcmsSuccess;
+ XcmsColor tmpColor;
+ XColor XColor_in_out;
+ XcmsCCC ccc;
+
+ /*
+ * 0. Check for invalid arguments.
+ */
+ if (dpy == NULL || colorname[0] == '\0' || pColor_scrn_return == 0
+ || pColor_exact_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * 1. Convert string to a XcmsColor using Xcms and i18n mechanism
+ */
+ if ((retval1 = _XcmsResolveColorString(ccc, &colorname,
+ &tmpColor, result_format)) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ if (retval1 == _XCMS_NEWNAME) {
+ goto PassToServer;
+ }
+ memcpy((char *)pColor_exact_return, (char *)&tmpColor, sizeof(XcmsColor));
+
+ /*
+ * 2. Convert tmpColor to RGB
+ * Assume pColor_exact_return is now adjusted to Client White Point
+ */
+ if ((retval2 = XcmsConvertColors(ccc, &tmpColor,
+ 1, XcmsRGBFormat, (Bool *) NULL)) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * 3. Convert to XColor and call XAllocColor
+ */
+ _XcmsRGB_to_XColor(&tmpColor, &XColor_in_out, 1);
+ if (XAllocColor(ccc->dpy, cmap, &XColor_in_out) == 0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * 4. pColor_scrn_return
+ *
+ * Now convert to the target format.
+ * We can ignore the return value because we're already in a
+ * device-dependent format.
+ */
+ _XColor_to_XcmsRGB(ccc, &XColor_in_out, pColor_scrn_return, 1);
+ if (result_format != XcmsRGBFormat) {
+ if (result_format == XcmsUndefinedFormat) {
+ result_format = pColor_exact_return->format;
+ }
+ if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+
+ return(retval1 > retval2 ? retval1 : retval2);
+
+PassToServer:
+ /*
+ * All previous methods failed, so lets pass it to the server
+ * for parsing.
+ */
+ dpy = ccc->dpy;
+ LockDisplay(dpy);
+ GetReq(AllocNamedColor, req);
+
+ req->cmap = cmap;
+ nbytes = req->nbytes = strlen(colorname);
+ req->length += (nbytes + 3) >> 2; /* round up to mult of 4 */
+
+ _XSend(dpy, colorname, nbytes);
+ /* _XSend is more efficient that Data, since _XReply follows */
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (0);
+ }
+
+ exact_def.red = rep.exactRed;
+ exact_def.green = rep.exactGreen;
+ exact_def.blue = rep.exactBlue;
+
+ hard_def.red = rep.screenRed;
+ hard_def.green = rep.screenGreen;
+ hard_def.blue = rep.screenBlue;
+
+ exact_def.pixel = hard_def.pixel = rep.pixel;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ /*
+ * Now convert to the target format.
+ */
+ _XColor_to_XcmsRGB(ccc, &exact_def, pColor_exact_return, 1);
+ _XColor_to_XcmsRGB(ccc, &hard_def, pColor_scrn_return, 1);
+ if (result_format != XcmsRGBFormat
+ && result_format != XcmsUndefinedFormat) {
+ if (XcmsConvertColors(ccc, pColor_exact_return, 1, result_format,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/cmsCmap.c b/libX11/src/xcms/cmsCmap.c
index f93a25b1f..2f14cdb25 100644
--- a/libX11/src/xcms/cmsCmap.c
+++ b/libX11/src/xcms/cmsCmap.c
@@ -1,495 +1,493 @@
-
-/*
- * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
- * All Rights Reserved
- *
- * This file is a component of an X Window System-specific implementation
- * of Xcms based on the TekColor Color Management System. Permission is
- * hereby granted to use, copy, modify, sell, and otherwise distribute this
- * software and its documentation for any purpose and without fee, provided
- * that this copyright, permission, and disclaimer notice is reproduced in
- * all copies of this software and in supporting documentation. TekColor
- * is a trademark of Tektronix, Inc.
- *
- * Tektronix makes no representation about the suitability of this software
- * for any purpose. It is provided "as is" and with all faults.
- *
- * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
- * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX 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 THE PERFORMANCE OF THIS SOFTWARE.
- *
- *
- * NAME
- * XcmsCmap.c - Client Colormap Management Routines
- *
- * DESCRIPTION
- * Routines that store additional information about
- * colormaps being used by the X Client.
- *
- *
- */
-
-#define NEED_EVENTS
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xcmsint.h"
-#include "Xutil.h"
-#include "Cmap.h"
-#include "Cv.h"
-
-/*
- * FORWARD DECLARATIONS
- */
-static void _XcmsFreeClientCmaps(Display *dpy);
-
-
-/************************************************************************
- * *
- * PRIVATE INTERFACES *
- * *
- ************************************************************************/
-
-/*
- * NAME
- * CmapRecForColormap
- *
- * SYNOPSIS
- */
-static XcmsCmapRec *
-CmapRecForColormap(
- Display *dpy,
- Colormap cmap)
-/*
- * DESCRIPTION
- * Find the corresponding XcmsCmapRec for cmap. In not found
- * this routines attempts to create one.
- *
- * RETURNS
- * Returns NULL if failed; otherwise the address to
- * the corresponding XcmsCmapRec.
- *
- */
-{
- XcmsCmapRec *pRec;
- int nScrn;
- int i, j;
- XVisualInfo visualTemplate; /* Template of the visual we want */
- XVisualInfo *visualList; /* List for visuals that match */
- int nVisualsMatched; /* Number of visuals that match */
- Window tmpWindow;
- Visual *vp;
- unsigned long border = 0;
- _XAsyncHandler async;
- _XAsyncErrorState async_state;
-
- for (pRec = (XcmsCmapRec *)dpy->cms.clientCmaps; pRec != NULL;
- pRec = pRec->pNext) {
- if (pRec->cmapID == cmap) {
- return(pRec);
- }
- }
-
- /*
- * Can't find an XcmsCmapRec associated with cmap in our records.
- * Let's try to see if its a default colormap
- */
- nScrn = ScreenCount(dpy);
- for (i = 0; i < nScrn; i++) {
- if (cmap == DefaultColormap(dpy, i)) {
- /* It is ... lets go ahead and store that info */
- if ((pRec = _XcmsAddCmapRec(dpy, cmap, RootWindow(dpy, i),
- DefaultVisual(dpy, i))) == NULL) {
- return((XcmsCmapRec *)NULL);
- }
- pRec->ccc = XcmsCreateCCC(
- dpy,
- i, /* screenNumber */
- DefaultVisual(dpy, i),
- (XcmsColor *)NULL, /* clientWhitePt */
- (XcmsCompressionProc)NULL, /* gamutCompProc */
- (XPointer)NULL, /* gamutCompClientData */
- (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */
- (XPointer)NULL /* whitePtAdjClientData */
- );
- return(pRec);
- }
- }
-
- /*
- * Nope, its not a default colormap, so it's probably a foreign color map
- * of which we have no specific details. Let's go through the
- * rigorous process of finding this colormap:
- * for each screen
- * for each screen's visual types
- * create a window with cmap specified as the colormap
- * if successful
- * Add a CmapRec
- * Create an XcmsCCC
- * return the CmapRec
- * else
- * continue
- */
-
- async_state.error_code = 0; /* don't care */
- async_state.major_opcode = X_CreateWindow;
- async_state.minor_opcode = 0;
- for (i = 0; i < nScrn; i++) {
- visualTemplate.screen = i;
- visualList = XGetVisualInfo(dpy, VisualScreenMask, &visualTemplate,
- &nVisualsMatched);
- if (visualList == NULL) {
- continue;
- }
-
- /*
- * Attempt to create a window with cmap
- */
- j = 0;
- do {
- vp = (visualList+j)->visual;
- LockDisplay(dpy);
- {
- register xCreateWindowReq *req;
-
- GetReq(CreateWindow, req);
- async_state.min_sequence_number = dpy->request;
- async_state.max_sequence_number = dpy->request;
- async_state.error_count = 0;
- async.next = dpy->async_handlers;
- async.handler = _XAsyncErrorHandler;
- async.data = (XPointer)&async_state;
- dpy->async_handlers = &async;
- req->parent = RootWindow(dpy, i);
- req->x = 0;
- req->y = 0;
- req->width = 1;
- req->height = 1;
- req->borderWidth = 0;
- req->depth = (visualList+j)->depth;
- req->class = CopyFromParent;
- req->visual = vp->visualid;
- tmpWindow = req->wid = XAllocID(dpy);
- req->mask = CWBorderPixel | CWColormap;
- req->length += 2;
- Data32 (dpy, (long *) &border, 4);
- Data32 (dpy, (long *) &cmap, 4);
- }
- {
- xGetInputFocusReply rep;
- register xReq *req;
-
- GetEmptyReq(GetInputFocus, req);
- (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
- }
- DeqAsyncHandler(dpy, &async);
- UnlockDisplay(dpy);
- SyncHandle();
- } while (async_state.error_count > 0 && ++j < nVisualsMatched);
-
- Xfree((char *)visualList);
-
- /*
- * if successful
- */
- if (j < nVisualsMatched) {
- if ((pRec = _XcmsAddCmapRec(dpy, cmap, tmpWindow, vp)) == NULL)
- return((XcmsCmapRec *)NULL);
- pRec->ccc = XcmsCreateCCC(
- dpy,
- i, /* screenNumber */
- vp,
- (XcmsColor *)NULL, /* clientWhitePt */
- (XcmsCompressionProc)NULL, /* gamutCompProc */
- (XPointer)NULL, /* gamutCompClientData */
- (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */
- (XPointer)NULL /* whitePtAdjClientData */
- );
- XDestroyWindow(dpy, tmpWindow);
- return(pRec);
- }
- }
-
- return(NULL);
-}
-
-
-
-/************************************************************************
- * *
- * API PRIVATE INTERFACES *
- * *
- ************************************************************************/
-
-/*
- * NAME
- * _XcmsAddCmapRec
- *
- * SYNOPSIS
- */
-XcmsCmapRec *
-_XcmsAddCmapRec(
- Display *dpy,
- Colormap cmap,
- Window windowID,
- Visual *visual)
-/*
- * DESCRIPTION
- * Create an XcmsCmapRec for the specified cmap, windowID,
- * and visual, then adds it to its list of CmapRec's.
- *
- * RETURNS
- * Returns NULL if failed; otherwise the address to
- * the added XcmsCmapRec.
- *
- */
-{
- XcmsCmapRec *pNew;
-
- if ((pNew = (XcmsCmapRec *) Xcalloc(1, (unsigned) sizeof(XcmsCmapRec)))
- == NULL) {
- return((XcmsCmapRec *)NULL);
- }
-
- pNew->cmapID = cmap;
- pNew->dpy = dpy;
- pNew->windowID = windowID;
- pNew->visual = visual;
- pNew->pNext = (XcmsCmapRec *)dpy->cms.clientCmaps;
- dpy->cms.clientCmaps = (XPointer)pNew;
- dpy->free_funcs->clientCmaps = _XcmsFreeClientCmaps;
-
- /*
- * Note, we don't create the XcmsCCC for pNew->ccc here because
- * it may require the use of XGetWindowAttributes (a round trip request)
- * to determine the screen.
- */
- return(pNew);
-}
-
-
-/*
- * NAME
- * _XcmsCopyCmapRecAndFree
- *
- * SYNOPSIS
- */
-XcmsCmapRec *
-_XcmsCopyCmapRecAndFree(
- Display *dpy,
- Colormap src_cmap,
- Colormap copy_cmap)
-/*
- * DESCRIPTION
- * Augments Xlib's XCopyColormapAndFree() to copy
- * XcmsCmapRecs.
- *
- * RETURNS
- * Returns NULL if failed; otherwise the address to
- * the copy XcmsCmapRec.
- *
- */
-{
- XcmsCmapRec *pRec_src;
- XcmsCmapRec *pRec_copy;
-
- if ((pRec_src = CmapRecForColormap(dpy, src_cmap)) != NULL) {
- pRec_copy =_XcmsAddCmapRec(dpy, copy_cmap, pRec_src->windowID,
- pRec_src->visual);
- if (pRec_copy != NULL && pRec_src->ccc) {
- pRec_copy->ccc = (XcmsCCC)Xcalloc(1, (unsigned) sizeof(XcmsCCCRec));
- memcpy((char *)pRec_copy->ccc, (char *)pRec_src->ccc,
- sizeof(XcmsCCCRec));
- }
- return(pRec_copy);
- }
- return((XcmsCmapRec *)NULL);
-}
-
-
-/*
- * NAME
- * _XcmsDeleteCmapRec
- *
- * SYNOPSIS
- */
-void
-_XcmsDeleteCmapRec(
- Display *dpy,
- Colormap cmap)
-/*
- * DESCRIPTION
- * Removes and frees the specified XcmsCmapRec structure
- * from the linked list of structures.
- *
- * RETURNS
- * void
- *
- */
-{
- XcmsCmapRec **pPrevPtr;
- XcmsCmapRec *pRec;
- int scr;
-
- /* If it is the default cmap for a screen, do not delete it,
- * because the server will not actually free it */
- for (scr = ScreenCount(dpy); --scr >= 0; ) {
- if (cmap == DefaultColormap(dpy, scr))
- return;
- }
-
- /* search for it in the list */
- pPrevPtr = (XcmsCmapRec **)&dpy->cms.clientCmaps;
- while ((pRec = *pPrevPtr) && (pRec->cmapID != cmap)) {
- pPrevPtr = &pRec->pNext;
- }
-
- if (pRec) {
- if (pRec->ccc) {
- XcmsFreeCCC(pRec->ccc);
- }
- *pPrevPtr = pRec->pNext;
- Xfree((char *)pRec);
- }
-}
-
-
-/*
- * NAME
- * _XcmsFreeClientCmaps
- *
- * SYNOPSIS
- */
-static void
-_XcmsFreeClientCmaps(
- Display *dpy)
-/*
- * DESCRIPTION
- * Frees all XcmsCmapRec structures in the linked list
- * and sets dpy->cms.clientCmaps to NULL.
- *
- * RETURNS
- * void
- *
- */
-{
- XcmsCmapRec *pRecNext, *pRecFree;
-
- pRecNext = (XcmsCmapRec *)dpy->cms.clientCmaps;
- while (pRecNext != NULL) {
- pRecFree = pRecNext;
- pRecNext = pRecNext->pNext;
- if (pRecFree->ccc) {
- /* Free the XcmsCCC structure */
- XcmsFreeCCC(pRecFree->ccc);
- }
- /* Now free the XcmsCmapRec structure */
- Xfree((char *)pRecFree);
- }
- dpy->cms.clientCmaps = (XPointer)NULL;
-}
-
-
-
-/************************************************************************
- * *
- * PUBLIC INTERFACES *
- * *
- ************************************************************************/
-
-/*
- * NAME
- * XcmsCCCOfColormap
- *
- * SYNOPSIS
- */
-XcmsCCC
-XcmsCCCOfColormap(
- Display *dpy,
- Colormap cmap)
-/*
- * DESCRIPTION
- * Finds the XcmsCCC associated with the specified colormap.
- *
- * RETURNS
- * Returns NULL if failed; otherwise the address to
- * the associated XcmsCCC structure.
- *
- */
-{
- XWindowAttributes windowAttr;
- XcmsCmapRec *pRec;
- int nScrn = ScreenCount(dpy);
- int i;
-
- if ((pRec = CmapRecForColormap(dpy, cmap)) != NULL) {
- if (pRec->ccc) {
- /* XcmsCmapRec already has a XcmsCCC */
- return(pRec->ccc);
- }
-
- /*
- * The XcmsCmapRec does not have a XcmsCCC yet, so let's create
- * one. But first, we need to know the screen associated with
- * cmap, so use XGetWindowAttributes() to extract that
- * information. Unless, of course there is only one screen!!
- */
- if (nScrn == 1) {
- /* Assume screenNumber == 0 */
- return(pRec->ccc = XcmsCreateCCC(
- dpy,
- 0, /* screenNumber */
- pRec->visual,
- (XcmsColor *)NULL, /* clientWhitePt */
- (XcmsCompressionProc)NULL, /* gamutCompProc */
- (XPointer)NULL, /* gamutCompClientData */
- (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */
- (XPointer)NULL /* whitePtAdjClientData */
- ));
- } else {
- if (XGetWindowAttributes(dpy, pRec->windowID, &windowAttr)) {
- for (i = 0; i < nScrn; i++) {
- if (ScreenOfDisplay(dpy, i) == windowAttr.screen) {
- return(pRec->ccc = XcmsCreateCCC(
- dpy,
- i, /* screenNumber */
- pRec->visual,
- (XcmsColor *)NULL, /* clientWhitePt */
- (XcmsCompressionProc)NULL, /* gamutCompProc */
- (XPointer)NULL, /* gamutCompClientData */
- (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */
- (XPointer)NULL /* whitePtAdjClientData */
- ));
- }
- }
- }
- }
- }
-
- /*
- * No such cmap
- */
- return(NULL);
-}
-
-XcmsCCC XcmsSetCCCOfColormap(
- Display *dpy,
- Colormap cmap,
- XcmsCCC ccc)
-{
- XcmsCCC prev_ccc = NULL;
- XcmsCmapRec *pRec;
-
- pRec = CmapRecForColormap(dpy, cmap);
- if (pRec) {
- prev_ccc = pRec->ccc;
- pRec->ccc = ccc;
- }
- return prev_ccc;
-}
+
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX 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 THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsCmap.c - Client Colormap Management Routines
+ *
+ * DESCRIPTION
+ * Routines that store additional information about
+ * colormaps being used by the X Client.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Xutil.h"
+#include "Cmap.h"
+#include "Cv.h"
+
+/*
+ * FORWARD DECLARATIONS
+ */
+static void _XcmsFreeClientCmaps(Display *dpy);
+
+
+/************************************************************************
+ * *
+ * PRIVATE INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * CmapRecForColormap
+ *
+ * SYNOPSIS
+ */
+static XcmsCmapRec *
+CmapRecForColormap(
+ Display *dpy,
+ Colormap cmap)
+/*
+ * DESCRIPTION
+ * Find the corresponding XcmsCmapRec for cmap. In not found
+ * this routines attempts to create one.
+ *
+ * RETURNS
+ * Returns NULL if failed; otherwise the address to
+ * the corresponding XcmsCmapRec.
+ *
+ */
+{
+ XcmsCmapRec *pRec;
+ int nScrn;
+ int i, j;
+ XVisualInfo visualTemplate; /* Template of the visual we want */
+ XVisualInfo *visualList; /* List for visuals that match */
+ int nVisualsMatched; /* Number of visuals that match */
+ Window tmpWindow;
+ Visual *vp;
+ unsigned long border = 0;
+ _XAsyncHandler async;
+ _XAsyncErrorState async_state;
+
+ for (pRec = (XcmsCmapRec *)dpy->cms.clientCmaps; pRec != NULL;
+ pRec = pRec->pNext) {
+ if (pRec->cmapID == cmap) {
+ return(pRec);
+ }
+ }
+
+ /*
+ * Can't find an XcmsCmapRec associated with cmap in our records.
+ * Let's try to see if its a default colormap
+ */
+ nScrn = ScreenCount(dpy);
+ for (i = 0; i < nScrn; i++) {
+ if (cmap == DefaultColormap(dpy, i)) {
+ /* It is ... lets go ahead and store that info */
+ if ((pRec = _XcmsAddCmapRec(dpy, cmap, RootWindow(dpy, i),
+ DefaultVisual(dpy, i))) == NULL) {
+ return((XcmsCmapRec *)NULL);
+ }
+ pRec->ccc = XcmsCreateCCC(
+ dpy,
+ i, /* screenNumber */
+ DefaultVisual(dpy, i),
+ (XcmsColor *)NULL, /* clientWhitePt */
+ (XcmsCompressionProc)NULL, /* gamutCompProc */
+ (XPointer)NULL, /* gamutCompClientData */
+ (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */
+ (XPointer)NULL /* whitePtAdjClientData */
+ );
+ return(pRec);
+ }
+ }
+
+ /*
+ * Nope, its not a default colormap, so it's probably a foreign color map
+ * of which we have no specific details. Let's go through the
+ * rigorous process of finding this colormap:
+ * for each screen
+ * for each screen's visual types
+ * create a window with cmap specified as the colormap
+ * if successful
+ * Add a CmapRec
+ * Create an XcmsCCC
+ * return the CmapRec
+ * else
+ * continue
+ */
+
+ async_state.error_code = 0; /* don't care */
+ async_state.major_opcode = X_CreateWindow;
+ async_state.minor_opcode = 0;
+ for (i = 0; i < nScrn; i++) {
+ visualTemplate.screen = i;
+ visualList = XGetVisualInfo(dpy, VisualScreenMask, &visualTemplate,
+ &nVisualsMatched);
+ if (visualList == NULL) {
+ continue;
+ }
+
+ /*
+ * Attempt to create a window with cmap
+ */
+ j = 0;
+ do {
+ vp = (visualList+j)->visual;
+ LockDisplay(dpy);
+ {
+ register xCreateWindowReq *req;
+
+ GetReq(CreateWindow, req);
+ async_state.min_sequence_number = dpy->request;
+ async_state.max_sequence_number = dpy->request;
+ async_state.error_count = 0;
+ async.next = dpy->async_handlers;
+ async.handler = _XAsyncErrorHandler;
+ async.data = (XPointer)&async_state;
+ dpy->async_handlers = &async;
+ req->parent = RootWindow(dpy, i);
+ req->x = 0;
+ req->y = 0;
+ req->width = 1;
+ req->height = 1;
+ req->borderWidth = 0;
+ req->depth = (visualList+j)->depth;
+ req->class = CopyFromParent;
+ req->visual = vp->visualid;
+ tmpWindow = req->wid = XAllocID(dpy);
+ req->mask = CWBorderPixel | CWColormap;
+ req->length += 2;
+ Data32 (dpy, (long *) &border, 4);
+ Data32 (dpy, (long *) &cmap, 4);
+ }
+ {
+ xGetInputFocusReply rep;
+ register xReq *req;
+
+ GetEmptyReq(GetInputFocus, req);
+ (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
+ }
+ DeqAsyncHandler(dpy, &async);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ } while (async_state.error_count > 0 && ++j < nVisualsMatched);
+
+ Xfree((char *)visualList);
+
+ /*
+ * if successful
+ */
+ if (j < nVisualsMatched) {
+ if ((pRec = _XcmsAddCmapRec(dpy, cmap, tmpWindow, vp)) == NULL)
+ return((XcmsCmapRec *)NULL);
+ pRec->ccc = XcmsCreateCCC(
+ dpy,
+ i, /* screenNumber */
+ vp,
+ (XcmsColor *)NULL, /* clientWhitePt */
+ (XcmsCompressionProc)NULL, /* gamutCompProc */
+ (XPointer)NULL, /* gamutCompClientData */
+ (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */
+ (XPointer)NULL /* whitePtAdjClientData */
+ );
+ XDestroyWindow(dpy, tmpWindow);
+ return(pRec);
+ }
+ }
+
+ return(NULL);
+}
+
+
+
+/************************************************************************
+ * *
+ * API PRIVATE INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * _XcmsAddCmapRec
+ *
+ * SYNOPSIS
+ */
+XcmsCmapRec *
+_XcmsAddCmapRec(
+ Display *dpy,
+ Colormap cmap,
+ Window windowID,
+ Visual *visual)
+/*
+ * DESCRIPTION
+ * Create an XcmsCmapRec for the specified cmap, windowID,
+ * and visual, then adds it to its list of CmapRec's.
+ *
+ * RETURNS
+ * Returns NULL if failed; otherwise the address to
+ * the added XcmsCmapRec.
+ *
+ */
+{
+ XcmsCmapRec *pNew;
+
+ if ((pNew = (XcmsCmapRec *) Xcalloc(1, (unsigned) sizeof(XcmsCmapRec)))
+ == NULL) {
+ return((XcmsCmapRec *)NULL);
+ }
+
+ pNew->cmapID = cmap;
+ pNew->dpy = dpy;
+ pNew->windowID = windowID;
+ pNew->visual = visual;
+ pNew->pNext = (XcmsCmapRec *)dpy->cms.clientCmaps;
+ dpy->cms.clientCmaps = (XPointer)pNew;
+ dpy->free_funcs->clientCmaps = _XcmsFreeClientCmaps;
+
+ /*
+ * Note, we don't create the XcmsCCC for pNew->ccc here because
+ * it may require the use of XGetWindowAttributes (a round trip request)
+ * to determine the screen.
+ */
+ return(pNew);
+}
+
+
+/*
+ * NAME
+ * _XcmsCopyCmapRecAndFree
+ *
+ * SYNOPSIS
+ */
+XcmsCmapRec *
+_XcmsCopyCmapRecAndFree(
+ Display *dpy,
+ Colormap src_cmap,
+ Colormap copy_cmap)
+/*
+ * DESCRIPTION
+ * Augments Xlib's XCopyColormapAndFree() to copy
+ * XcmsCmapRecs.
+ *
+ * RETURNS
+ * Returns NULL if failed; otherwise the address to
+ * the copy XcmsCmapRec.
+ *
+ */
+{
+ XcmsCmapRec *pRec_src;
+ XcmsCmapRec *pRec_copy;
+
+ if ((pRec_src = CmapRecForColormap(dpy, src_cmap)) != NULL) {
+ pRec_copy =_XcmsAddCmapRec(dpy, copy_cmap, pRec_src->windowID,
+ pRec_src->visual);
+ if (pRec_copy != NULL && pRec_src->ccc) {
+ pRec_copy->ccc = (XcmsCCC)Xcalloc(1, (unsigned) sizeof(XcmsCCCRec));
+ memcpy((char *)pRec_copy->ccc, (char *)pRec_src->ccc,
+ sizeof(XcmsCCCRec));
+ }
+ return(pRec_copy);
+ }
+ return((XcmsCmapRec *)NULL);
+}
+
+
+/*
+ * NAME
+ * _XcmsDeleteCmapRec
+ *
+ * SYNOPSIS
+ */
+void
+_XcmsDeleteCmapRec(
+ Display *dpy,
+ Colormap cmap)
+/*
+ * DESCRIPTION
+ * Removes and frees the specified XcmsCmapRec structure
+ * from the linked list of structures.
+ *
+ * RETURNS
+ * void
+ *
+ */
+{
+ XcmsCmapRec **pPrevPtr;
+ XcmsCmapRec *pRec;
+ int scr;
+
+ /* If it is the default cmap for a screen, do not delete it,
+ * because the server will not actually free it */
+ for (scr = ScreenCount(dpy); --scr >= 0; ) {
+ if (cmap == DefaultColormap(dpy, scr))
+ return;
+ }
+
+ /* search for it in the list */
+ pPrevPtr = (XcmsCmapRec **)&dpy->cms.clientCmaps;
+ while ((pRec = *pPrevPtr) && (pRec->cmapID != cmap)) {
+ pPrevPtr = &pRec->pNext;
+ }
+
+ if (pRec) {
+ if (pRec->ccc) {
+ XcmsFreeCCC(pRec->ccc);
+ }
+ *pPrevPtr = pRec->pNext;
+ Xfree((char *)pRec);
+ }
+}
+
+
+/*
+ * NAME
+ * _XcmsFreeClientCmaps
+ *
+ * SYNOPSIS
+ */
+static void
+_XcmsFreeClientCmaps(
+ Display *dpy)
+/*
+ * DESCRIPTION
+ * Frees all XcmsCmapRec structures in the linked list
+ * and sets dpy->cms.clientCmaps to NULL.
+ *
+ * RETURNS
+ * void
+ *
+ */
+{
+ XcmsCmapRec *pRecNext, *pRecFree;
+
+ pRecNext = (XcmsCmapRec *)dpy->cms.clientCmaps;
+ while (pRecNext != NULL) {
+ pRecFree = pRecNext;
+ pRecNext = pRecNext->pNext;
+ if (pRecFree->ccc) {
+ /* Free the XcmsCCC structure */
+ XcmsFreeCCC(pRecFree->ccc);
+ }
+ /* Now free the XcmsCmapRec structure */
+ Xfree((char *)pRecFree);
+ }
+ dpy->cms.clientCmaps = (XPointer)NULL;
+}
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCCCOfColormap
+ *
+ * SYNOPSIS
+ */
+XcmsCCC
+XcmsCCCOfColormap(
+ Display *dpy,
+ Colormap cmap)
+/*
+ * DESCRIPTION
+ * Finds the XcmsCCC associated with the specified colormap.
+ *
+ * RETURNS
+ * Returns NULL if failed; otherwise the address to
+ * the associated XcmsCCC structure.
+ *
+ */
+{
+ XWindowAttributes windowAttr;
+ XcmsCmapRec *pRec;
+ int nScrn = ScreenCount(dpy);
+ int i;
+
+ if ((pRec = CmapRecForColormap(dpy, cmap)) != NULL) {
+ if (pRec->ccc) {
+ /* XcmsCmapRec already has a XcmsCCC */
+ return(pRec->ccc);
+ }
+
+ /*
+ * The XcmsCmapRec does not have a XcmsCCC yet, so let's create
+ * one. But first, we need to know the screen associated with
+ * cmap, so use XGetWindowAttributes() to extract that
+ * information. Unless, of course there is only one screen!!
+ */
+ if (nScrn == 1) {
+ /* Assume screenNumber == 0 */
+ return(pRec->ccc = XcmsCreateCCC(
+ dpy,
+ 0, /* screenNumber */
+ pRec->visual,
+ (XcmsColor *)NULL, /* clientWhitePt */
+ (XcmsCompressionProc)NULL, /* gamutCompProc */
+ (XPointer)NULL, /* gamutCompClientData */
+ (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */
+ (XPointer)NULL /* whitePtAdjClientData */
+ ));
+ } else {
+ if (XGetWindowAttributes(dpy, pRec->windowID, &windowAttr)) {
+ for (i = 0; i < nScrn; i++) {
+ if (ScreenOfDisplay(dpy, i) == windowAttr.screen) {
+ return(pRec->ccc = XcmsCreateCCC(
+ dpy,
+ i, /* screenNumber */
+ pRec->visual,
+ (XcmsColor *)NULL, /* clientWhitePt */
+ (XcmsCompressionProc)NULL, /* gamutCompProc */
+ (XPointer)NULL, /* gamutCompClientData */
+ (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */
+ (XPointer)NULL /* whitePtAdjClientData */
+ ));
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * No such cmap
+ */
+ return(NULL);
+}
+
+XcmsCCC XcmsSetCCCOfColormap(
+ Display *dpy,
+ Colormap cmap,
+ XcmsCCC ccc)
+{
+ XcmsCCC prev_ccc = NULL;
+ XcmsCmapRec *pRec;
+
+ pRec = CmapRecForColormap(dpy, cmap);
+ if (pRec) {
+ prev_ccc = pRec->ccc;
+ pRec->ccc = ccc;
+ }
+ return prev_ccc;
+}
diff --git a/libX11/src/xcms/cmsInt.c b/libX11/src/xcms/cmsInt.c
index b48036522..47c54a701 100644
--- a/libX11/src/xcms/cmsInt.c
+++ b/libX11/src/xcms/cmsInt.c
@@ -1,413 +1,412 @@
-
-/*
- * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
- * All Rights Reserved
- *
- * This file is a component of an X Window System-specific implementation
- * of Xcms based on the TekColor Color Management System. Permission is
- * hereby granted to use, copy, modify, sell, and otherwise distribute this
- * software and its documentation for any purpose and without fee, provided
- * that this copyright, permission, and disclaimer notice is reproduced in
- * all copies of this software and in supporting documentation. TekColor
- * is a trademark of Tektronix, Inc.
- *
- * Tektronix makes no representation about the suitability of this software
- * for any purpose. It is provided "as is" and with all faults.
- *
- * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
- * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX 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 THE PERFORMANCE OF THIS SOFTWARE.
- *
- *
- * NAME
- * XcmsInt.c - Xcms API utility routines
- *
- * DESCRIPTION
- * Xcms Application Program Interface (API) utility
- * routines for hanging information directly onto
- * the Display structure.
- *
- *
- */
-
-/* #define NEED_EVENTS */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "Xcmsint.h"
-#include "Cv.h"
-
-#ifndef XCMSCOMPPROC
-# define XCMSCOMPPROC XcmsTekHVCClipC
-#endif
-
-/* forward/static */
-static void _XcmsFreeDefaultCCCs(Display *dpy);
-
-
-/************************************************************************
- * *
- * API PRIVATE ROUTINES *
- * *
- ************************************************************************/
-
-/*
- * NAME
- * _XcmsCopyPointerArray
- *
- * SYNOPSIS
- */
-XPointer *
-_XcmsCopyPointerArray(
- XPointer *pap)
-/*
- * DESCRIPTION
- * Copies an array of NULL terminated pointers.
- *
- * RETURNS
- * Returns NULL if failed; otherwise the address to
- * the copy.
- *
- */
-{
- XPointer *newArray;
- char **tmp;
- int n;
-
- for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
- n++; /* add 1 to include the NULL pointer */
-
- if ((newArray = (XPointer *)Xmalloc(n * sizeof(XPointer)))) {
- memcpy((char *)newArray, (char *)pap,
- (unsigned)(n * sizeof(XPointer)));
- }
- return((XPointer *)newArray);
-}
-
-/*
- * NAME
- * _XcmsFreePointerArray
- *
- * SYNOPSIS
- */
-void
-_XcmsFreePointerArray(
- XPointer *pap)
-/*
- * DESCRIPTION
- * Frees an array of NULL terminated pointers.
- *
- * RETURNS
- * void
- *
- */
-{
- Xfree(pap);
-}
-
-/*
- * NAME
- * _XcmsPushPointerArray
- *
- * SYNOPSIS
- */
-XPointer *
-_XcmsPushPointerArray(
- XPointer *pap,
- XPointer p,
- XPointer *papNoFree)
-/*
- * DESCRIPTION
- * Places the specified pointer at the head of an array of NULL
- * terminated pointers.
- *
- * RETURNS
- * Returns NULL if failed; otherwise the address to
- * the head of the array.
- *
- */
-{
- XPointer *newArray;
- char **tmp;
- int n;
-
- for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
-
- /* add 2: 1 for the new pointer and another for the NULL pointer */
- n += 2;
-
- if ((newArray = (XPointer *)Xmalloc(n * sizeof(XPointer)))) {
- memcpy((char *)(newArray+1),(char *)pap,
- (unsigned)((n-1) * sizeof(XPointer)));
- *newArray = p;
- }
- if (pap != papNoFree) {
- _XcmsFreePointerArray(pap);
- }
- return((XPointer *)newArray);
-}
-
-/*
- * NAME
- * _XcmsInitDefaultCCCs
- *
- * SYNOPSIS
- */
-int
-_XcmsInitDefaultCCCs(
- Display *dpy)
-/*
- * DESCRIPTION
- * Initializes the Xcms per Display Info structure
- * (XcmsPerDpyInfo).
- *
- * RETURNS
- * Returns 0 if failed; otherwise non-zero.
- *
- */
-{
- int nScrn = ScreenCount(dpy);
- int i;
- XcmsCCC ccc;
-
- if (nScrn <= 0) {
- return(0);
- }
-
- /*
- * Create an array of XcmsCCC structures, one for each screen.
- * They serve as the screen's default CCC.
- */
- if (!(ccc = (XcmsCCC)
- Xcalloc((unsigned)nScrn, (unsigned) sizeof(XcmsCCCRec)))) {
- return(0);
- }
- dpy->cms.defaultCCCs = (XPointer)ccc;
- dpy->free_funcs->defaultCCCs = _XcmsFreeDefaultCCCs;
-
- for (i = 0; i < nScrn; i++, ccc++) {
- ccc->dpy = dpy;
- ccc->screenNumber = i;
- ccc->visual = DefaultVisual(dpy, i);
- /*
- * Used calloc to allocate memory so:
- * ccc->clientWhitePt->format == XcmsUndefinedFormat
- * ccc->gamutCompProc == NULL
- * ccc->whitePtAdjProc == NULL
- * ccc->pPerScrnInfo = NULL
- *
- * Don't need to create XcmsPerScrnInfo and its functionSet and
- * pScreenData components until the default CCC is accessed.
- * Note that the XcmsDefaultCCC routine calls _XcmsInitScrnInto
- * to do this.
- */
- ccc->gamutCompProc = XCMSCOMPPROC;
- }
-
- return(1);
-}
-
-
-/*
- * NAME
- * _XcmsFreeDefaultCCCs - Free Default CCCs and its PerScrnInfo
- *
- * SYNOPSIS
- */
-static void
-_XcmsFreeDefaultCCCs(
- Display *dpy)
-/*
- * DESCRIPTION
- * This routine frees the default XcmsCCC's associated with
- * each screen and its associated substructures as neccessary.
- *
- * RETURNS
- * void
- *
- *
- */
-{
- int nScrn = ScreenCount(dpy);
- XcmsCCC ccc;
- int i;
-
- /*
- * Free Screen data in each DefaultCCC
- * Do not use XcmsFreeCCC here because it will not free
- * DefaultCCC's.
- */
- ccc = (XcmsCCC)dpy->cms.defaultCCCs;
- for (i = nScrn; i--; ccc++) {
- /*
- * Check if XcmsPerScrnInfo exists.
- *
- * This is the only place where XcmsPerScrnInfo structures
- * are freed since there is only one allocated per Screen.
- * It just so happens that we place its reference in the
- * default CCC.
- */
- if (ccc->pPerScrnInfo) {
- /* Check if SCCData exists */
- if (ccc->pPerScrnInfo->state != XcmsInitNone
- && ccc->pPerScrnInfo->screenData) {
- (*((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->screenFreeProc)
- (ccc->pPerScrnInfo->screenData);
- }
- Xfree(ccc->pPerScrnInfo);
- }
- }
-
- /*
- * Free the array of XcmsCCC structures
- */
- Xfree(dpy->cms.defaultCCCs);
- dpy->cms.defaultCCCs = (XPointer)NULL;
-}
-
-
-
-/*
- * NAME
- * _XcmsInitScrnInfo
- *
- * SYNOPSIS
- */
-int
-_XcmsInitScrnInfo(
- register Display *dpy,
- int screenNumber)
-/*
- * DESCRIPTION
- * Given a display and screen number, this routine attempts
- * to initialize the Xcms per Screen Info structure
- * (XcmsPerScrnInfo).
- *
- * RETURNS
- * Returns zero if initialization failed; non-zero otherwise.
- */
-{
- XcmsFunctionSet **papSCCFuncSet = _XcmsSCCFuncSets;
- XcmsCCC defaultccc;
-
- /*
- * Check if the XcmsCCC's for each screen has been created.
- * Really dont need to be created until some routine uses the Xcms
- * API routines.
- */
- if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) {
- if (!_XcmsInitDefaultCCCs(dpy)) {
- return(0);
- }
- }
-
- defaultccc = (XcmsCCC)dpy->cms.defaultCCCs + screenNumber;
-
- /*
- * For each SCCFuncSet, try its pInitScrnFunc.
- * If the function succeeds, then we got it!
- */
-
- if (!defaultccc->pPerScrnInfo) {
- /*
- * This is one of two places where XcmsPerScrnInfo structures
- * are allocated. There is one allocated per Screen that is
- * shared among visuals that do not have specific intensity
- * tables. Other XcmsPerScrnInfo structures are created
- * for the latter (see XcmsCreateCCC). The ones created
- * here are referenced by the default CCC.
- */
- if (!(defaultccc->pPerScrnInfo = (XcmsPerScrnInfo *)
- Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) {
- return(0);
- }
- defaultccc->pPerScrnInfo->state = XcmsInitNone;
- }
-
- while (*papSCCFuncSet != NULL) {
- if ((*(*papSCCFuncSet)->screenInitProc)(dpy, screenNumber,
- defaultccc->pPerScrnInfo)) {
- defaultccc->pPerScrnInfo->state = XcmsInitSuccess;
- return(1);
- }
- papSCCFuncSet++;
- }
-
- /*
- * Use Default SCCData
- */
- return(_XcmsLRGB_InitScrnDefault(dpy, screenNumber, defaultccc->pPerScrnInfo));
-}
-
-
-/*
- * NAME
- * _XcmsFreeIntensityMaps
- *
- * SYNOPSIS
- */
-void
-_XcmsFreeIntensityMaps(
- Display *dpy)
-/*
- * DESCRIPTION
- * Frees all XcmsIntensityMap structures in the linked list
- * and sets dpy->cms.perVisualIntensityMaps to NULL.
- *
- * RETURNS
- * void
- *
- */
-{
- XcmsIntensityMap *pNext, *pFree;
-
- pNext = (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps;
- while (pNext != NULL) {
- pFree = pNext;
- pNext = pNext->pNext;
- (*pFree->pFreeScreenData)(pFree->screenData);
- /* Now free the XcmsIntensityMap structure */
- Xfree(pFree);
- }
- dpy->cms.perVisualIntensityMaps = (XPointer)NULL;
-}
-
-
-/*
- * NAME
- * _XcmsGetIntensityMap
- *
- * SYNOPSIS
- */
-XcmsIntensityMap *
-_XcmsGetIntensityMap(
- Display *dpy,
- Visual *visual)
-/*
- * DESCRIPTION
- * Attempts to return a per-Visual intensity map.
- *
- * RETURNS
- * Pointer to the XcmsIntensityMap structure if found;
- * otherwise NULL
- *
- */
-{
- VisualID targetID = visual->visualid;
- XcmsIntensityMap *pNext;
-
- pNext = (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps;
- while (pNext != NULL) {
- if (targetID == pNext->visualID) {
- return(pNext);
- }
- pNext = pNext->pNext;
- }
- return((XcmsIntensityMap *)NULL);
-}
+
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX 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 THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsInt.c - Xcms API utility routines
+ *
+ * DESCRIPTION
+ * Xcms Application Program Interface (API) utility
+ * routines for hanging information directly onto
+ * the Display structure.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+#ifndef XCMSCOMPPROC
+# define XCMSCOMPPROC XcmsTekHVCClipC
+#endif
+
+/* forward/static */
+static void _XcmsFreeDefaultCCCs(Display *dpy);
+
+
+/************************************************************************
+ * *
+ * API PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * _XcmsCopyPointerArray
+ *
+ * SYNOPSIS
+ */
+XPointer *
+_XcmsCopyPointerArray(
+ XPointer *pap)
+/*
+ * DESCRIPTION
+ * Copies an array of NULL terminated pointers.
+ *
+ * RETURNS
+ * Returns NULL if failed; otherwise the address to
+ * the copy.
+ *
+ */
+{
+ XPointer *newArray;
+ char **tmp;
+ int n;
+
+ for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
+ n++; /* add 1 to include the NULL pointer */
+
+ if ((newArray = (XPointer *)Xmalloc(n * sizeof(XPointer)))) {
+ memcpy((char *)newArray, (char *)pap,
+ (unsigned)(n * sizeof(XPointer)));
+ }
+ return((XPointer *)newArray);
+}
+
+/*
+ * NAME
+ * _XcmsFreePointerArray
+ *
+ * SYNOPSIS
+ */
+void
+_XcmsFreePointerArray(
+ XPointer *pap)
+/*
+ * DESCRIPTION
+ * Frees an array of NULL terminated pointers.
+ *
+ * RETURNS
+ * void
+ *
+ */
+{
+ Xfree(pap);
+}
+
+/*
+ * NAME
+ * _XcmsPushPointerArray
+ *
+ * SYNOPSIS
+ */
+XPointer *
+_XcmsPushPointerArray(
+ XPointer *pap,
+ XPointer p,
+ XPointer *papNoFree)
+/*
+ * DESCRIPTION
+ * Places the specified pointer at the head of an array of NULL
+ * terminated pointers.
+ *
+ * RETURNS
+ * Returns NULL if failed; otherwise the address to
+ * the head of the array.
+ *
+ */
+{
+ XPointer *newArray;
+ char **tmp;
+ int n;
+
+ for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
+
+ /* add 2: 1 for the new pointer and another for the NULL pointer */
+ n += 2;
+
+ if ((newArray = (XPointer *)Xmalloc(n * sizeof(XPointer)))) {
+ memcpy((char *)(newArray+1),(char *)pap,
+ (unsigned)((n-1) * sizeof(XPointer)));
+ *newArray = p;
+ }
+ if (pap != papNoFree) {
+ _XcmsFreePointerArray(pap);
+ }
+ return((XPointer *)newArray);
+}
+
+/*
+ * NAME
+ * _XcmsInitDefaultCCCs
+ *
+ * SYNOPSIS
+ */
+int
+_XcmsInitDefaultCCCs(
+ Display *dpy)
+/*
+ * DESCRIPTION
+ * Initializes the Xcms per Display Info structure
+ * (XcmsPerDpyInfo).
+ *
+ * RETURNS
+ * Returns 0 if failed; otherwise non-zero.
+ *
+ */
+{
+ int nScrn = ScreenCount(dpy);
+ int i;
+ XcmsCCC ccc;
+
+ if (nScrn <= 0) {
+ return(0);
+ }
+
+ /*
+ * Create an array of XcmsCCC structures, one for each screen.
+ * They serve as the screen's default CCC.
+ */
+ if (!(ccc = (XcmsCCC)
+ Xcalloc((unsigned)nScrn, (unsigned) sizeof(XcmsCCCRec)))) {
+ return(0);
+ }
+ dpy->cms.defaultCCCs = (XPointer)ccc;
+ dpy->free_funcs->defaultCCCs = _XcmsFreeDefaultCCCs;
+
+ for (i = 0; i < nScrn; i++, ccc++) {
+ ccc->dpy = dpy;
+ ccc->screenNumber = i;
+ ccc->visual = DefaultVisual(dpy, i);
+ /*
+ * Used calloc to allocate memory so:
+ * ccc->clientWhitePt->format == XcmsUndefinedFormat
+ * ccc->gamutCompProc == NULL
+ * ccc->whitePtAdjProc == NULL
+ * ccc->pPerScrnInfo = NULL
+ *
+ * Don't need to create XcmsPerScrnInfo and its functionSet and
+ * pScreenData components until the default CCC is accessed.
+ * Note that the XcmsDefaultCCC routine calls _XcmsInitScrnInto
+ * to do this.
+ */
+ ccc->gamutCompProc = XCMSCOMPPROC;
+ }
+
+ return(1);
+}
+
+
+/*
+ * NAME
+ * _XcmsFreeDefaultCCCs - Free Default CCCs and its PerScrnInfo
+ *
+ * SYNOPSIS
+ */
+static void
+_XcmsFreeDefaultCCCs(
+ Display *dpy)
+/*
+ * DESCRIPTION
+ * This routine frees the default XcmsCCC's associated with
+ * each screen and its associated substructures as neccessary.
+ *
+ * RETURNS
+ * void
+ *
+ *
+ */
+{
+ int nScrn = ScreenCount(dpy);
+ XcmsCCC ccc;
+ int i;
+
+ /*
+ * Free Screen data in each DefaultCCC
+ * Do not use XcmsFreeCCC here because it will not free
+ * DefaultCCC's.
+ */
+ ccc = (XcmsCCC)dpy->cms.defaultCCCs;
+ for (i = nScrn; i--; ccc++) {
+ /*
+ * Check if XcmsPerScrnInfo exists.
+ *
+ * This is the only place where XcmsPerScrnInfo structures
+ * are freed since there is only one allocated per Screen.
+ * It just so happens that we place its reference in the
+ * default CCC.
+ */
+ if (ccc->pPerScrnInfo) {
+ /* Check if SCCData exists */
+ if (ccc->pPerScrnInfo->state != XcmsInitNone
+ && ccc->pPerScrnInfo->screenData) {
+ (*((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->screenFreeProc)
+ (ccc->pPerScrnInfo->screenData);
+ }
+ Xfree(ccc->pPerScrnInfo);
+ }
+ }
+
+ /*
+ * Free the array of XcmsCCC structures
+ */
+ Xfree(dpy->cms.defaultCCCs);
+ dpy->cms.defaultCCCs = (XPointer)NULL;
+}
+
+
+
+/*
+ * NAME
+ * _XcmsInitScrnInfo
+ *
+ * SYNOPSIS
+ */
+int
+_XcmsInitScrnInfo(
+ register Display *dpy,
+ int screenNumber)
+/*
+ * DESCRIPTION
+ * Given a display and screen number, this routine attempts
+ * to initialize the Xcms per Screen Info structure
+ * (XcmsPerScrnInfo).
+ *
+ * RETURNS
+ * Returns zero if initialization failed; non-zero otherwise.
+ */
+{
+ XcmsFunctionSet **papSCCFuncSet = _XcmsSCCFuncSets;
+ XcmsCCC defaultccc;
+
+ /*
+ * Check if the XcmsCCC's for each screen has been created.
+ * Really dont need to be created until some routine uses the Xcms
+ * API routines.
+ */
+ if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) {
+ if (!_XcmsInitDefaultCCCs(dpy)) {
+ return(0);
+ }
+ }
+
+ defaultccc = (XcmsCCC)dpy->cms.defaultCCCs + screenNumber;
+
+ /*
+ * For each SCCFuncSet, try its pInitScrnFunc.
+ * If the function succeeds, then we got it!
+ */
+
+ if (!defaultccc->pPerScrnInfo) {
+ /*
+ * This is one of two places where XcmsPerScrnInfo structures
+ * are allocated. There is one allocated per Screen that is
+ * shared among visuals that do not have specific intensity
+ * tables. Other XcmsPerScrnInfo structures are created
+ * for the latter (see XcmsCreateCCC). The ones created
+ * here are referenced by the default CCC.
+ */
+ if (!(defaultccc->pPerScrnInfo = (XcmsPerScrnInfo *)
+ Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) {
+ return(0);
+ }
+ defaultccc->pPerScrnInfo->state = XcmsInitNone;
+ }
+
+ while (*papSCCFuncSet != NULL) {
+ if ((*(*papSCCFuncSet)->screenInitProc)(dpy, screenNumber,
+ defaultccc->pPerScrnInfo)) {
+ defaultccc->pPerScrnInfo->state = XcmsInitSuccess;
+ return(1);
+ }
+ papSCCFuncSet++;
+ }
+
+ /*
+ * Use Default SCCData
+ */
+ return(_XcmsLRGB_InitScrnDefault(dpy, screenNumber, defaultccc->pPerScrnInfo));
+}
+
+
+/*
+ * NAME
+ * _XcmsFreeIntensityMaps
+ *
+ * SYNOPSIS
+ */
+void
+_XcmsFreeIntensityMaps(
+ Display *dpy)
+/*
+ * DESCRIPTION
+ * Frees all XcmsIntensityMap structures in the linked list
+ * and sets dpy->cms.perVisualIntensityMaps to NULL.
+ *
+ * RETURNS
+ * void
+ *
+ */
+{
+ XcmsIntensityMap *pNext, *pFree;
+
+ pNext = (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps;
+ while (pNext != NULL) {
+ pFree = pNext;
+ pNext = pNext->pNext;
+ (*pFree->pFreeScreenData)(pFree->screenData);
+ /* Now free the XcmsIntensityMap structure */
+ Xfree(pFree);
+ }
+ dpy->cms.perVisualIntensityMaps = (XPointer)NULL;
+}
+
+
+/*
+ * NAME
+ * _XcmsGetIntensityMap
+ *
+ * SYNOPSIS
+ */
+XcmsIntensityMap *
+_XcmsGetIntensityMap(
+ Display *dpy,
+ Visual *visual)
+/*
+ * DESCRIPTION
+ * Attempts to return a per-Visual intensity map.
+ *
+ * RETURNS
+ * Pointer to the XcmsIntensityMap structure if found;
+ * otherwise NULL
+ *
+ */
+{
+ VisualID targetID = visual->visualid;
+ XcmsIntensityMap *pNext;
+
+ pNext = (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps;
+ while (pNext != NULL) {
+ if (targetID == pNext->visualID) {
+ return(pNext);
+ }
+ pNext = pNext->pNext;
+ }
+ return((XcmsIntensityMap *)NULL);
+}
diff --git a/libX11/src/xcms/cmsLkCol.c b/libX11/src/xcms/cmsLkCol.c
index 776fffd75..02e48462e 100644
--- a/libX11/src/xcms/cmsLkCol.c
+++ b/libX11/src/xcms/cmsLkCol.c
@@ -1,194 +1,193 @@
-
-/*
- * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
- * All Rights Reserved
- *
- * This file is a component of an X Window System-specific implementation
- * of Xcms based on the TekColor Color Management System. Permission is
- * hereby granted to use, copy, modify, sell, and otherwise distribute this
- * software and its documentation for any purpose and without fee, provided
- * that this copyright, permission, and disclaimer notice is reproduced in
- * all copies of this software and in supporting documentation. TekColor
- * is a trademark of Tektronix, Inc.
- *
- * Tektronix makes no representation about the suitability of this software
- * for any purpose. It is provided "as is" and with all faults.
- *
- * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
- * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX 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 THE PERFORMANCE OF THIS SOFTWARE.
- *
- *
- * NAME
- * XcmsLkCol.c
- *
- * DESCRIPTION
- * Source for XcmsLookupColor
- *
- *
- */
-
-#define NEED_REPLIES
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "Xcmsint.h"
-#include "Cv.h"
-
-
-/*
- * NAME
- * XcmsLookupColor -
- *
- * SYNOPSIS
- */
-Status
-XcmsLookupColor (
- Display *dpy,
- Colormap cmap,
- _Xconst char *colorname,
- XcmsColor *pColor_exact_return,
- XcmsColor *pColor_scrn_return,
- XcmsColorFormat result_format)
-/*
- * DESCRIPTION
- * The XcmsLookupColor function finds the color specification
- * associated with a color name in the Device-Independent Color
- * Name Database.
- * RETURNS
- * This function returns both the color specification found in the
- * database (db specification) and the color specification for the
- * color displayable by the specified screen (screen
- * specification). The calling routine sets the format for these
- * returned specifications in the XcmsColor format component.
- * If XcmsUndefinedFormat, the specification is returned in the
- * format used to store the color in the database.
- */
-{
- Status retval1 = XcmsSuccess;
- Status retval2 = XcmsSuccess;
- XcmsCCC ccc;
- register int n;
- xLookupColorReply reply;
- register xLookupColorReq *req;
- XColor def, scr;
-
-/*
- * 0. Check for invalid arguments.
- */
- if (dpy == NULL || colorname[0] == '\0' || pColor_scrn_return == 0
- || pColor_exact_return == NULL) {
- return(XcmsFailure);
- }
-
- if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) {
- return(XcmsFailure);
- }
-
-/*
- * 1. Convert string to a XcmsColor
- */
- if ((retval1 = _XcmsResolveColorString(ccc, &colorname,
- pColor_exact_return, result_format)) == XcmsFailure) {
- return(XcmsFailure);
- }
- if (retval1 == _XCMS_NEWNAME) {
- goto PassToServer;
- }
-
-/*
- * 2. pColor_scrn_return
- * Assume the pColor_exact_return has already been adjusted to
- * the Client White Point.
- *
- */
- /*
- * Convert to RGB, adjusting for white point differences if necessary.
- */
- memcpy((char *)pColor_scrn_return, (char *)pColor_exact_return,
- sizeof(XcmsColor));
- if (pColor_scrn_return->format == XcmsRGBFormat) {
- retval2 = XcmsSuccess;
- } else if ((retval2 = XcmsConvertColors(ccc, pColor_scrn_return, 1,
- XcmsRGBFormat, (Bool *)NULL)) == XcmsFailure) {
- return(XcmsFailure);
- }
-
- /*
- * Then, convert XcmsColor structure to the target specification
- * format. Note that we must use NULL instead of passing
- * pCompressed.
- */
-
- if (result_format == XcmsUndefinedFormat) {
- result_format = pColor_exact_return->format;
- }
- if (result_format == XcmsRGBFormat) {
- _XcmsUnresolveColor(ccc, pColor_scrn_return);
- } else {
- _XcmsResolveColor(ccc, pColor_scrn_return);
- if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
- (Bool *) NULL) == XcmsFailure) {
- return(XcmsFailure);
- }
- }
-
- return(retval1 > retval2 ? retval1 : retval2);
-
-PassToServer:
- /*
- * Xcms and i18n methods failed, so lets pass it to the server
- * for parsing.
- */
-
- LockDisplay(dpy);
- GetReq (LookupColor, req);
- req->cmap = cmap;
- req->nbytes = n = strlen(colorname);
- req->length += (n + 3) >> 2;
- Data (dpy, colorname, (long)n);
- if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (XcmsFailure);
- }
- def.red = reply.exactRed;
- def.green = reply.exactGreen;
- def.blue = reply.exactBlue;
-
- scr.red = reply.screenRed;
- scr.green = reply.screenGreen;
- scr.blue = reply.screenBlue;
-
- UnlockDisplay(dpy);
- SyncHandle();
-
- _XColor_to_XcmsRGB(ccc, &def, pColor_exact_return, 1);
- _XColor_to_XcmsRGB(ccc, &scr, pColor_scrn_return, 1);
-
- /*
- * Then, convert XcmsColor structure to the target specification
- * format. Note that we must use NULL instead of passing
- * pCompressed.
- */
-
- if (result_format != XcmsRGBFormat
- && result_format != XcmsUndefinedFormat) {
- if (XcmsConvertColors(ccc, pColor_exact_return, 1, result_format,
- (Bool *) NULL) == XcmsFailure) {
- return(XcmsFailure);
- }
- if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
- (Bool *) NULL) == XcmsFailure) {
- return(XcmsFailure);
- }
- }
-
- return(XcmsSuccess);
-}
+
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX 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 THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsLkCol.c
+ *
+ * DESCRIPTION
+ * Source for XcmsLookupColor
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/*
+ * NAME
+ * XcmsLookupColor -
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsLookupColor (
+ Display *dpy,
+ Colormap cmap,
+ _Xconst char *colorname,
+ XcmsColor *pColor_exact_return,
+ XcmsColor *pColor_scrn_return,
+ XcmsColorFormat result_format)
+/*
+ * DESCRIPTION
+ * The XcmsLookupColor function finds the color specification
+ * associated with a color name in the Device-Independent Color
+ * Name Database.
+ * RETURNS
+ * This function returns both the color specification found in the
+ * database (db specification) and the color specification for the
+ * color displayable by the specified screen (screen
+ * specification). The calling routine sets the format for these
+ * returned specifications in the XcmsColor format component.
+ * If XcmsUndefinedFormat, the specification is returned in the
+ * format used to store the color in the database.
+ */
+{
+ Status retval1 = XcmsSuccess;
+ Status retval2 = XcmsSuccess;
+ XcmsCCC ccc;
+ register int n;
+ xLookupColorReply reply;
+ register xLookupColorReq *req;
+ XColor def, scr;
+
+/*
+ * 0. Check for invalid arguments.
+ */
+ if (dpy == NULL || colorname[0] == '\0' || pColor_scrn_return == 0
+ || pColor_exact_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) {
+ return(XcmsFailure);
+ }
+
+/*
+ * 1. Convert string to a XcmsColor
+ */
+ if ((retval1 = _XcmsResolveColorString(ccc, &colorname,
+ pColor_exact_return, result_format)) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ if (retval1 == _XCMS_NEWNAME) {
+ goto PassToServer;
+ }
+
+/*
+ * 2. pColor_scrn_return
+ * Assume the pColor_exact_return has already been adjusted to
+ * the Client White Point.
+ *
+ */
+ /*
+ * Convert to RGB, adjusting for white point differences if necessary.
+ */
+ memcpy((char *)pColor_scrn_return, (char *)pColor_exact_return,
+ sizeof(XcmsColor));
+ if (pColor_scrn_return->format == XcmsRGBFormat) {
+ retval2 = XcmsSuccess;
+ } else if ((retval2 = XcmsConvertColors(ccc, pColor_scrn_return, 1,
+ XcmsRGBFormat, (Bool *)NULL)) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Then, convert XcmsColor structure to the target specification
+ * format. Note that we must use NULL instead of passing
+ * pCompressed.
+ */
+
+ if (result_format == XcmsUndefinedFormat) {
+ result_format = pColor_exact_return->format;
+ }
+ if (result_format == XcmsRGBFormat) {
+ _XcmsUnresolveColor(ccc, pColor_scrn_return);
+ } else {
+ _XcmsResolveColor(ccc, pColor_scrn_return);
+ if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+
+ return(retval1 > retval2 ? retval1 : retval2);
+
+PassToServer:
+ /*
+ * Xcms and i18n methods failed, so lets pass it to the server
+ * for parsing.
+ */
+
+ LockDisplay(dpy);
+ GetReq (LookupColor, req);
+ req->cmap = cmap;
+ req->nbytes = n = strlen(colorname);
+ req->length += (n + 3) >> 2;
+ Data (dpy, colorname, (long)n);
+ if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (XcmsFailure);
+ }
+ def.red = reply.exactRed;
+ def.green = reply.exactGreen;
+ def.blue = reply.exactBlue;
+
+ scr.red = reply.screenRed;
+ scr.green = reply.screenGreen;
+ scr.blue = reply.screenBlue;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ _XColor_to_XcmsRGB(ccc, &def, pColor_exact_return, 1);
+ _XColor_to_XcmsRGB(ccc, &scr, pColor_scrn_return, 1);
+
+ /*
+ * Then, convert XcmsColor structure to the target specification
+ * format. Note that we must use NULL instead of passing
+ * pCompressed.
+ */
+
+ if (result_format != XcmsRGBFormat
+ && result_format != XcmsUndefinedFormat) {
+ if (XcmsConvertColors(ccc, pColor_exact_return, 1, result_format,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xkb/XKB.c b/libX11/src/xkb/XKB.c
index b9338e0d1..fea57870b 100644
--- a/libX11/src/xkb/XKB.c
+++ b/libX11/src/xkb/XKB.c
@@ -1,774 +1,772 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-
-#ifdef XKB_IN_SERVER
-#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
-#endif
-
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-XkbInternAtomFunc _XkbInternAtomFunc= XInternAtom;
-XkbGetAtomNameFunc _XkbGetAtomNameFunc= XGetAtomName;
-
-Bool
-XkbQueryExtension( Display *dpy,
- int * opcodeReturn,
- int * eventBaseReturn,
- int * errorBaseReturn,
- int * majorReturn,
- int * minorReturn)
-{
- if (!XkbUseExtension(dpy,majorReturn,minorReturn))
- return False;
- if (opcodeReturn)
- *opcodeReturn = dpy->xkb_info->codes->major_opcode;
- if (eventBaseReturn)
- *eventBaseReturn = dpy->xkb_info->codes->first_event;
- if (errorBaseReturn)
- *errorBaseReturn = dpy->xkb_info->codes->first_error;
- if (majorReturn)
- *majorReturn = dpy->xkb_info->srv_major;
- if (minorReturn)
- *minorReturn = dpy->xkb_info->srv_minor;
- return True;
-}
-
-Bool
-XkbLibraryVersion(int *libMajorRtrn,int *libMinorRtrn)
-{
-int supported;
-
- if (*libMajorRtrn != XkbMajorVersion) {
- /* version 0.65 is (almost) compatible with 1.00 */
- if ((XkbMajorVersion==1)&&(((*libMajorRtrn)==0)&&((*libMinorRtrn)==65)))
- supported= True;
- else supported= False;
- }
- else {
- supported = True;
- }
-
- *libMajorRtrn = XkbMajorVersion;
- *libMinorRtrn = XkbMinorVersion;
- return supported;
-}
-
-Bool
-XkbSelectEvents( Display * dpy,
- unsigned int deviceSpec,
- unsigned int affect,
- unsigned int selectAll)
-{
- register xkbSelectEventsReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- xkbi->selected_events&= ~affect;
- xkbi->selected_events|= (affect&selectAll);
- GetReq(kbSelectEvents, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSelectEvents;
- req->deviceSpec = deviceSpec;
- req->affectWhich = (CARD16)affect;
- req->clear = affect&(~selectAll);
- req->selectAll = affect&selectAll;
- if (affect&XkbMapNotifyMask) {
- req->affectMap= XkbAllMapComponentsMask;
- /* the implicit support needs the client info */
- /* even if the client itself doesn't want it */
- if (selectAll&XkbMapNotifyMask)
- req->map= XkbAllMapEventsMask;
- else req->map= XkbAllClientInfoMask;
- if (selectAll&XkbMapNotifyMask)
- xkbi->selected_map_details= XkbAllMapEventsMask;
- else xkbi->selected_map_details= 0;
- }
- if (affect&XkbNewKeyboardNotifyMask) {
- if (selectAll&XkbNewKeyboardNotifyMask)
- xkbi->selected_nkn_details= XkbAllNewKeyboardEventsMask;
- else xkbi->selected_nkn_details= 0;
- if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) {
- /* we want it, even if the client doesn't. Don't mess */
- /* around with details -- ask for all of them and throw */
- /* away the ones we don't need */
- req->selectAll|= XkbNewKeyboardNotifyMask;
- }
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbSelectEventDetails( Display * dpy,
- unsigned deviceSpec,
- unsigned eventType,
- unsigned long int affect,
- unsigned long int details)
-{
- register xkbSelectEventsReq *req;
- XkbInfoPtr xkbi;
- int size = 0;
- char *out;
- union {
- CARD8 *c8;
- CARD16 *c16;
- CARD32 *c32;
- } u;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- if (affect&details) xkbi->selected_events|= (1<<eventType);
- else xkbi->selected_events&= ~(1<<eventType);
- GetReq(kbSelectEvents, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSelectEvents;
- req->deviceSpec = deviceSpec;
- req->clear= req->selectAll= 0;
- if (eventType==XkbMapNotify) {
- /* we need all of the client info, even if the application */
- /* doesn't. Make sure that we always request the stuff */
- /* that the implicit support needs, and just filter out anything */
- /* the client doesn't want later */
- req->affectWhich = 0;
- req->selectAll = 0;
- req->clear = 0;
- req->affectMap = (CARD16)affect;
- req->map = (CARD16)details|(XkbAllClientInfoMask&affect);
- req->affectWhich = XkbMapNotifyMask;
- xkbi->selected_map_details&= ~affect;
- xkbi->selected_map_details|= (details&affect);
- }
- else {
- req->affectMap = req->map = 0;
- req->affectWhich= (1<<eventType);
- switch (eventType) {
- case XkbNewKeyboardNotify:
- xkbi->selected_nkn_details&= ~affect;
- xkbi->selected_nkn_details|= (details&affect);
- if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards))
- details= (affect&XkbAllNewKeyboardEventsMask);
- case XkbStateNotify:
- case XkbNamesNotify:
- case XkbAccessXNotify:
- case XkbExtensionDeviceNotify:
- size= 2;
- req->length+= 1;
- break;
- case XkbControlsNotify:
- case XkbIndicatorStateNotify:
- case XkbIndicatorMapNotify:
- size= 4;
- req->length+= 2;
- break;
- case XkbBellNotify:
- case XkbActionMessage:
- case XkbCompatMapNotify:
- size= 1;
- req->length+= 1;
- break;
- }
- BufAlloc(char *,out,(((size*2)+(unsigned)3)/4)*4);
- u.c8= (CARD8 *)out;
- if (size==2) {
- u.c16[0]= (CARD16)affect;
- u.c16[1]= (CARD16)details;
- }
- else if (size==4) {
- u.c32[0]= (CARD32)affect;
- u.c32[1]= (CARD32)details;
- }
- else {
- u.c8[0]= (CARD8)affect;
- u.c8[1]= (CARD8)details;
- }
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbLockModifiers( Display * dpy,
- unsigned int deviceSpec,
- unsigned int affect,
- unsigned int values)
-{
- register xkbLatchLockStateReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbLatchLockState, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbLatchLockState;
- req->deviceSpec = deviceSpec;
- req->affectModLocks= affect;
- req->modLocks = values;
- req->lockGroup = False;
- req->groupLock = 0;
-
- req->affectModLatches = req->modLatches = 0;
- req->latchGroup = False;
- req->groupLatch = 0;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbLatchModifiers( Display * dpy,
- unsigned int deviceSpec,
- unsigned int affect,
- unsigned int values)
-{
- register xkbLatchLockStateReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbLatchLockState, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbLatchLockState;
- req->deviceSpec = deviceSpec;
-
- req->affectModLatches= affect;
- req->modLatches = values;
- req->latchGroup = False;
- req->groupLatch = 0;
-
- req->affectModLocks = req->modLocks = 0;
- req->lockGroup = False;
- req->groupLock = 0;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbLockGroup(Display *dpy,unsigned int deviceSpec,unsigned int group)
-{
- register xkbLatchLockStateReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbLatchLockState, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbLatchLockState;
- req->deviceSpec = deviceSpec;
- req->affectModLocks= 0;
- req->modLocks = 0;
- req->lockGroup = True;
- req->groupLock = group;
-
- req->affectModLatches = req->modLatches = 0;
- req->latchGroup = False;
- req->groupLatch = 0;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group)
-{
- register xkbLatchLockStateReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbLatchLockState, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbLatchLockState;
- req->deviceSpec = deviceSpec;
-
- req->affectModLatches= 0;
- req->modLatches = 0;
- req->latchGroup = True;
- req->groupLatch = group;
-
- req->affectModLocks = req->modLocks = 0;
- req->lockGroup = False;
- req->groupLock = 0;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-unsigned
-XkbSetXlibControls(Display *dpy,unsigned affect,unsigned values)
-{
- if (!dpy->xkb_info)
- XkbUseExtension(dpy,NULL,NULL);
- if (!dpy->xkb_info)
- return 0;
- affect&= XkbLC_AllControls;
- dpy->xkb_info->xlib_ctrls&= ~affect;
- dpy->xkb_info->xlib_ctrls|= (affect&values);
- return dpy->xkb_info->xlib_ctrls;
-}
-
-unsigned
-XkbGetXlibControls(Display *dpy)
-{
- if (!dpy->xkb_info)
- XkbUseExtension(dpy,NULL,NULL);
- if (!dpy->xkb_info)
- return 0;
- return dpy->xkb_info->xlib_ctrls;
-}
-
-unsigned int
-XkbXlibControlsImplemented(void)
-{
-#ifdef __sgi
- return XkbLC_AllControls;
-#else
- return XkbLC_AllControls&~XkbLC_AllComposeControls;
-#endif
-}
-
-Bool
-XkbSetDebuggingFlags( Display * dpy,
- unsigned int mask,
- unsigned int flags,
- char * msg,
- unsigned int ctrls_mask,
- unsigned int ctrls,
- unsigned int * rtrn_flags,
- unsigned int * rtrn_ctrls)
-{
- register xkbSetDebuggingFlagsReq *req;
- xkbSetDebuggingFlagsReply rep;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetDebuggingFlags, req);
- req->reqType= xkbi->codes->major_opcode;
- req->xkbReqType= X_kbSetDebuggingFlags;
- req->affectFlags= mask;
- req->flags= flags;
- req->affectCtrls= ctrls_mask;
- req->ctrls= ctrls;
-
- if (msg) {
- char *out;
- req->msgLength= (unsigned short)strlen(msg)+1;
- req->length+= (req->msgLength+(unsigned)3)>>2;
- BufAlloc(char *,out,((req->msgLength+(unsigned)3)/4)*4);
- memcpy(out,msg,req->msgLength);
- }
- else req->msgLength= 0;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- if (rtrn_flags)
- *rtrn_flags= rep.currentFlags;
- if (rtrn_ctrls)
- *rtrn_ctrls= rep.currentCtrls;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbComputeEffectiveMap( XkbDescPtr xkb,
- XkbKeyTypePtr type,
- unsigned char * map_rtrn)
-{
-register int i;
-unsigned tmp;
-XkbKTMapEntryPtr entry = NULL;
-
- if ((!xkb)||(!type)||(!xkb->server))
- return False;
-
- if (type->mods.vmods!=0) {
- if (!XkbVirtualModsToReal(xkb,type->mods.vmods,&tmp))
- return False;
-
- type->mods.mask= tmp|type->mods.real_mods;
- entry= type->map;
- for (i=0;i<type->map_count;i++,entry++) {
- tmp= 0;
- if (entry->mods.vmods!=0) {
- if (!XkbVirtualModsToReal(xkb,entry->mods.vmods,&tmp))
- return False;
- if (tmp==0) {
- entry->active= False;
- continue;
- }
- }
- entry->active= True;
- entry->mods.mask= (entry->mods.real_mods|tmp)&type->mods.mask;
- }
- }
- else {
- type->mods.mask= type->mods.real_mods;
- }
- if (map_rtrn!=NULL) {
- bzero(map_rtrn,type->mods.mask+1);
- for (i=0;i<type->map_count;i++) {
- if (entry->active) {
- map_rtrn[type->map[i].mods.mask]= type->map[i].level;
- }
- }
- }
- return True;
-}
-
-Status
-XkbGetState(Display *dpy,unsigned deviceSpec,XkbStatePtr rtrn)
-{
- register xkbGetStateReq *req;
- xkbGetStateReply rep;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbGetState, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetState;
- req->deviceSpec = deviceSpec;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadImplementation;
- }
- rtrn->mods= rep.mods;
- rtrn->base_mods= rep.baseMods;
- rtrn->latched_mods= rep.latchedMods;
- rtrn->locked_mods= rep.lockedMods;
- rtrn->group= rep.group;
- rtrn->base_group= rep.baseGroup;
- rtrn->latched_group= rep.latchedGroup;
- rtrn->locked_group= rep.lockedGroup;
- rtrn->compat_state= rep.compatState;
- rtrn->grab_mods= rep.grabMods;
- rtrn->compat_grab_mods= rep.compatGrabMods;
- rtrn->lookup_mods= rep.lookupMods;
- rtrn->compat_lookup_mods= rep.compatLookupMods;
- rtrn->ptr_buttons= rep.ptrBtnState;
- UnlockDisplay(dpy);
- SyncHandle();
- return Success;
-}
-
-Bool
-XkbSetDetectableAutoRepeat(Display *dpy,Bool detectable,Bool *supported)
-{
-register xkbPerClientFlagsReq * req;
-xkbPerClientFlagsReply rep;
-XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbPerClientFlags, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbPerClientFlags;
- req->deviceSpec = XkbUseCoreKbd;
- req->change = XkbPCF_DetectableAutoRepeatMask;
- if (detectable)
- req->value = XkbPCF_DetectableAutoRepeatMask;
- else req->value = 0;
- req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- if (supported!=NULL)
- *supported= ((rep.supported&XkbPCF_DetectableAutoRepeatMask)!=0);
- return ((rep.value&XkbPCF_DetectableAutoRepeatMask)!=0);
-}
-
-Bool
-XkbGetDetectableAutoRepeat(Display *dpy,Bool *supported)
-{
-register xkbPerClientFlagsReq * req;
-xkbPerClientFlagsReply rep;
-XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbPerClientFlags, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbPerClientFlags;
- req->deviceSpec = XkbUseCoreKbd;
- req->change = 0;
- req->value = 0;
- req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- if (supported!=NULL)
- *supported= ((rep.supported&XkbPCF_DetectableAutoRepeatMask)!=0);
- return ((rep.value&XkbPCF_DetectableAutoRepeatMask)!=0);
-}
-
-Bool
-XkbSetAutoResetControls( Display * dpy,
- unsigned changes,
- unsigned * auto_ctrls,
- unsigned * auto_values)
-{
-register xkbPerClientFlagsReq * req;
-xkbPerClientFlagsReply rep;
-XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbPerClientFlags, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbPerClientFlags;
- req->change = XkbPCF_AutoResetControlsMask;
- req->deviceSpec = XkbUseCoreKbd;
- req->value = XkbPCF_AutoResetControlsMask;
- req->ctrlsToChange= changes;
- req->autoCtrls= *auto_ctrls;
- req->autoCtrlValues= *auto_values;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- *auto_ctrls= rep.autoCtrls;
- *auto_values= rep.autoCtrlValues;
- return ((rep.value&XkbPCF_AutoResetControlsMask)!=0);
-}
-
-Bool
-XkbGetAutoResetControls( Display * dpy,
- unsigned * auto_ctrls,
- unsigned * auto_ctrl_values)
-{
-register xkbPerClientFlagsReq * req;
-xkbPerClientFlagsReply rep;
-XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbPerClientFlags, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbPerClientFlags;
- req->deviceSpec = XkbUseCoreKbd;
- req->change = 0;
- req->value = 0;
- req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- if (auto_ctrls)
- *auto_ctrls= rep.autoCtrls;
- if (auto_ctrl_values)
- *auto_ctrl_values= rep.autoCtrlValues;
- return ((rep.value&XkbPCF_AutoResetControlsMask)!=0);
-}
-
-Bool
-XkbSetPerClientControls( Display * dpy,
- unsigned change,
- unsigned * values)
-{
-register xkbPerClientFlagsReq * req;
-xkbPerClientFlagsReply rep;
-XkbInfoPtr xkbi;
-unsigned value_hold = *values;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ||
- (change & ~(XkbPCF_GrabsUseXKBStateMask|XkbPCF_LookupStateWhenGrabbed|XkbPCF_SendEventUsesXKBState)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbPerClientFlags, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbPerClientFlags;
- req->change = change;
- req->deviceSpec = XkbUseCoreKbd;
- req->value = *values;
- req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues= 0;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- *values = rep.value;
- return ((rep.value&value_hold)!=0);
-}
-
-Bool
-XkbGetPerClientControls( Display * dpy,
- unsigned * ctrls)
-{
-register xkbPerClientFlagsReq * req;
-xkbPerClientFlagsReply rep;
-XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ||
- (*ctrls & ~(XkbPCF_GrabsUseXKBStateMask|XkbPCF_LookupStateWhenGrabbed|XkbPCF_SendEventUsesXKBState)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbPerClientFlags, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbPerClientFlags;
- req->deviceSpec = XkbUseCoreKbd;
- req->change = 0;
- req->value = 0;
- req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- if (ctrls)
- *ctrls= (rep.value & (XkbPCF_GrabsUseXKBStateMask |
- XkbPCF_LookupStateWhenGrabbed |
- XkbPCF_SendEventUsesXKBState));
- return (True);
-}
-
-Display *
-XkbOpenDisplay( char * name,
- int * ev_rtrn,
- int * err_rtrn,
- int * major_rtrn,
- int * minor_rtrn,
- int * reason)
-{
- Display* dpy;
- int major_num,minor_num;
-
- if ((major_rtrn!=NULL) && (minor_rtrn!=NULL)) {
- if (!XkbLibraryVersion(major_rtrn,minor_rtrn)) {
- if (reason!=NULL)
- *reason= XkbOD_BadLibraryVersion;
- return NULL;
- }
- }
- else {
- major_num= XkbMajorVersion;
- minor_num= XkbMinorVersion;
- major_rtrn= &major_num;
- minor_rtrn= &minor_num;
- }
- dpy= XOpenDisplay(name);
- if (dpy==NULL) {
- if (reason!=NULL)
- *reason= XkbOD_ConnectionRefused;
- return NULL;
- }
- if (!XkbQueryExtension(dpy,NULL,ev_rtrn,err_rtrn,major_rtrn,minor_rtrn)) {
- if (reason!=NULL) {
- if ((*major_rtrn!=0)||(*minor_rtrn!=0))
- *reason= XkbOD_BadServerVersion;
- else *reason= XkbOD_NonXkbServer;
- }
- XCloseDisplay(dpy);
- return NULL;
- }
- if (reason!=NULL)
- *reason= XkbOD_Success;
- return dpy;
-}
-
-void
-XkbSetAtomFuncs(XkbInternAtomFunc getAtom,XkbGetAtomNameFunc getName)
-{
- _XkbInternAtomFunc= (getAtom?getAtom:XInternAtom);
- _XkbGetAtomNameFunc= (getName?getName:XGetAtomName);
- return;
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 <stdio.h>
+
+#ifdef XKB_IN_SERVER
+#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
+#endif
+
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+XkbInternAtomFunc _XkbInternAtomFunc= XInternAtom;
+XkbGetAtomNameFunc _XkbGetAtomNameFunc= XGetAtomName;
+
+Bool
+XkbQueryExtension( Display *dpy,
+ int * opcodeReturn,
+ int * eventBaseReturn,
+ int * errorBaseReturn,
+ int * majorReturn,
+ int * minorReturn)
+{
+ if (!XkbUseExtension(dpy,majorReturn,minorReturn))
+ return False;
+ if (opcodeReturn)
+ *opcodeReturn = dpy->xkb_info->codes->major_opcode;
+ if (eventBaseReturn)
+ *eventBaseReturn = dpy->xkb_info->codes->first_event;
+ if (errorBaseReturn)
+ *errorBaseReturn = dpy->xkb_info->codes->first_error;
+ if (majorReturn)
+ *majorReturn = dpy->xkb_info->srv_major;
+ if (minorReturn)
+ *minorReturn = dpy->xkb_info->srv_minor;
+ return True;
+}
+
+Bool
+XkbLibraryVersion(int *libMajorRtrn,int *libMinorRtrn)
+{
+int supported;
+
+ if (*libMajorRtrn != XkbMajorVersion) {
+ /* version 0.65 is (almost) compatible with 1.00 */
+ if ((XkbMajorVersion==1)&&(((*libMajorRtrn)==0)&&((*libMinorRtrn)==65)))
+ supported= True;
+ else supported= False;
+ }
+ else {
+ supported = True;
+ }
+
+ *libMajorRtrn = XkbMajorVersion;
+ *libMinorRtrn = XkbMinorVersion;
+ return supported;
+}
+
+Bool
+XkbSelectEvents( Display * dpy,
+ unsigned int deviceSpec,
+ unsigned int affect,
+ unsigned int selectAll)
+{
+ register xkbSelectEventsReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ xkbi->selected_events&= ~affect;
+ xkbi->selected_events|= (affect&selectAll);
+ GetReq(kbSelectEvents, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSelectEvents;
+ req->deviceSpec = deviceSpec;
+ req->affectWhich = (CARD16)affect;
+ req->clear = affect&(~selectAll);
+ req->selectAll = affect&selectAll;
+ if (affect&XkbMapNotifyMask) {
+ req->affectMap= XkbAllMapComponentsMask;
+ /* the implicit support needs the client info */
+ /* even if the client itself doesn't want it */
+ if (selectAll&XkbMapNotifyMask)
+ req->map= XkbAllMapEventsMask;
+ else req->map= XkbAllClientInfoMask;
+ if (selectAll&XkbMapNotifyMask)
+ xkbi->selected_map_details= XkbAllMapEventsMask;
+ else xkbi->selected_map_details= 0;
+ }
+ if (affect&XkbNewKeyboardNotifyMask) {
+ if (selectAll&XkbNewKeyboardNotifyMask)
+ xkbi->selected_nkn_details= XkbAllNewKeyboardEventsMask;
+ else xkbi->selected_nkn_details= 0;
+ if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) {
+ /* we want it, even if the client doesn't. Don't mess */
+ /* around with details -- ask for all of them and throw */
+ /* away the ones we don't need */
+ req->selectAll|= XkbNewKeyboardNotifyMask;
+ }
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbSelectEventDetails( Display * dpy,
+ unsigned deviceSpec,
+ unsigned eventType,
+ unsigned long int affect,
+ unsigned long int details)
+{
+ register xkbSelectEventsReq *req;
+ XkbInfoPtr xkbi;
+ int size = 0;
+ char *out;
+ union {
+ CARD8 *c8;
+ CARD16 *c16;
+ CARD32 *c32;
+ } u;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ if (affect&details) xkbi->selected_events|= (1<<eventType);
+ else xkbi->selected_events&= ~(1<<eventType);
+ GetReq(kbSelectEvents, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSelectEvents;
+ req->deviceSpec = deviceSpec;
+ req->clear= req->selectAll= 0;
+ if (eventType==XkbMapNotify) {
+ /* we need all of the client info, even if the application */
+ /* doesn't. Make sure that we always request the stuff */
+ /* that the implicit support needs, and just filter out anything */
+ /* the client doesn't want later */
+ req->affectWhich = 0;
+ req->selectAll = 0;
+ req->clear = 0;
+ req->affectMap = (CARD16)affect;
+ req->map = (CARD16)details|(XkbAllClientInfoMask&affect);
+ req->affectWhich = XkbMapNotifyMask;
+ xkbi->selected_map_details&= ~affect;
+ xkbi->selected_map_details|= (details&affect);
+ }
+ else {
+ req->affectMap = req->map = 0;
+ req->affectWhich= (1<<eventType);
+ switch (eventType) {
+ case XkbNewKeyboardNotify:
+ xkbi->selected_nkn_details&= ~affect;
+ xkbi->selected_nkn_details|= (details&affect);
+ if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards))
+ details= (affect&XkbAllNewKeyboardEventsMask);
+ case XkbStateNotify:
+ case XkbNamesNotify:
+ case XkbAccessXNotify:
+ case XkbExtensionDeviceNotify:
+ size= 2;
+ req->length+= 1;
+ break;
+ case XkbControlsNotify:
+ case XkbIndicatorStateNotify:
+ case XkbIndicatorMapNotify:
+ size= 4;
+ req->length+= 2;
+ break;
+ case XkbBellNotify:
+ case XkbActionMessage:
+ case XkbCompatMapNotify:
+ size= 1;
+ req->length+= 1;
+ break;
+ }
+ BufAlloc(char *,out,(((size*2)+(unsigned)3)/4)*4);
+ u.c8= (CARD8 *)out;
+ if (size==2) {
+ u.c16[0]= (CARD16)affect;
+ u.c16[1]= (CARD16)details;
+ }
+ else if (size==4) {
+ u.c32[0]= (CARD32)affect;
+ u.c32[1]= (CARD32)details;
+ }
+ else {
+ u.c8[0]= (CARD8)affect;
+ u.c8[1]= (CARD8)details;
+ }
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbLockModifiers( Display * dpy,
+ unsigned int deviceSpec,
+ unsigned int affect,
+ unsigned int values)
+{
+ register xkbLatchLockStateReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbLatchLockState, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbLatchLockState;
+ req->deviceSpec = deviceSpec;
+ req->affectModLocks= affect;
+ req->modLocks = values;
+ req->lockGroup = False;
+ req->groupLock = 0;
+
+ req->affectModLatches = req->modLatches = 0;
+ req->latchGroup = False;
+ req->groupLatch = 0;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbLatchModifiers( Display * dpy,
+ unsigned int deviceSpec,
+ unsigned int affect,
+ unsigned int values)
+{
+ register xkbLatchLockStateReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbLatchLockState, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbLatchLockState;
+ req->deviceSpec = deviceSpec;
+
+ req->affectModLatches= affect;
+ req->modLatches = values;
+ req->latchGroup = False;
+ req->groupLatch = 0;
+
+ req->affectModLocks = req->modLocks = 0;
+ req->lockGroup = False;
+ req->groupLock = 0;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbLockGroup(Display *dpy,unsigned int deviceSpec,unsigned int group)
+{
+ register xkbLatchLockStateReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbLatchLockState, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbLatchLockState;
+ req->deviceSpec = deviceSpec;
+ req->affectModLocks= 0;
+ req->modLocks = 0;
+ req->lockGroup = True;
+ req->groupLock = group;
+
+ req->affectModLatches = req->modLatches = 0;
+ req->latchGroup = False;
+ req->groupLatch = 0;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group)
+{
+ register xkbLatchLockStateReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbLatchLockState, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbLatchLockState;
+ req->deviceSpec = deviceSpec;
+
+ req->affectModLatches= 0;
+ req->modLatches = 0;
+ req->latchGroup = True;
+ req->groupLatch = group;
+
+ req->affectModLocks = req->modLocks = 0;
+ req->lockGroup = False;
+ req->groupLock = 0;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+unsigned
+XkbSetXlibControls(Display *dpy,unsigned affect,unsigned values)
+{
+ if (!dpy->xkb_info)
+ XkbUseExtension(dpy,NULL,NULL);
+ if (!dpy->xkb_info)
+ return 0;
+ affect&= XkbLC_AllControls;
+ dpy->xkb_info->xlib_ctrls&= ~affect;
+ dpy->xkb_info->xlib_ctrls|= (affect&values);
+ return dpy->xkb_info->xlib_ctrls;
+}
+
+unsigned
+XkbGetXlibControls(Display *dpy)
+{
+ if (!dpy->xkb_info)
+ XkbUseExtension(dpy,NULL,NULL);
+ if (!dpy->xkb_info)
+ return 0;
+ return dpy->xkb_info->xlib_ctrls;
+}
+
+unsigned int
+XkbXlibControlsImplemented(void)
+{
+#ifdef __sgi
+ return XkbLC_AllControls;
+#else
+ return XkbLC_AllControls&~XkbLC_AllComposeControls;
+#endif
+}
+
+Bool
+XkbSetDebuggingFlags( Display * dpy,
+ unsigned int mask,
+ unsigned int flags,
+ char * msg,
+ unsigned int ctrls_mask,
+ unsigned int ctrls,
+ unsigned int * rtrn_flags,
+ unsigned int * rtrn_ctrls)
+{
+ register xkbSetDebuggingFlagsReq *req;
+ xkbSetDebuggingFlagsReply rep;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetDebuggingFlags, req);
+ req->reqType= xkbi->codes->major_opcode;
+ req->xkbReqType= X_kbSetDebuggingFlags;
+ req->affectFlags= mask;
+ req->flags= flags;
+ req->affectCtrls= ctrls_mask;
+ req->ctrls= ctrls;
+
+ if (msg) {
+ char *out;
+ req->msgLength= (unsigned short)strlen(msg)+1;
+ req->length+= (req->msgLength+(unsigned)3)>>2;
+ BufAlloc(char *,out,((req->msgLength+(unsigned)3)/4)*4);
+ memcpy(out,msg,req->msgLength);
+ }
+ else req->msgLength= 0;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ if (rtrn_flags)
+ *rtrn_flags= rep.currentFlags;
+ if (rtrn_ctrls)
+ *rtrn_ctrls= rep.currentCtrls;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbComputeEffectiveMap( XkbDescPtr xkb,
+ XkbKeyTypePtr type,
+ unsigned char * map_rtrn)
+{
+register int i;
+unsigned tmp;
+XkbKTMapEntryPtr entry = NULL;
+
+ if ((!xkb)||(!type)||(!xkb->server))
+ return False;
+
+ if (type->mods.vmods!=0) {
+ if (!XkbVirtualModsToReal(xkb,type->mods.vmods,&tmp))
+ return False;
+
+ type->mods.mask= tmp|type->mods.real_mods;
+ entry= type->map;
+ for (i=0;i<type->map_count;i++,entry++) {
+ tmp= 0;
+ if (entry->mods.vmods!=0) {
+ if (!XkbVirtualModsToReal(xkb,entry->mods.vmods,&tmp))
+ return False;
+ if (tmp==0) {
+ entry->active= False;
+ continue;
+ }
+ }
+ entry->active= True;
+ entry->mods.mask= (entry->mods.real_mods|tmp)&type->mods.mask;
+ }
+ }
+ else {
+ type->mods.mask= type->mods.real_mods;
+ }
+ if (map_rtrn!=NULL) {
+ bzero(map_rtrn,type->mods.mask+1);
+ for (i=0;i<type->map_count;i++) {
+ if (entry->active) {
+ map_rtrn[type->map[i].mods.mask]= type->map[i].level;
+ }
+ }
+ }
+ return True;
+}
+
+Status
+XkbGetState(Display *dpy,unsigned deviceSpec,XkbStatePtr rtrn)
+{
+ register xkbGetStateReq *req;
+ xkbGetStateReply rep;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbGetState, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetState;
+ req->deviceSpec = deviceSpec;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadImplementation;
+ }
+ rtrn->mods= rep.mods;
+ rtrn->base_mods= rep.baseMods;
+ rtrn->latched_mods= rep.latchedMods;
+ rtrn->locked_mods= rep.lockedMods;
+ rtrn->group= rep.group;
+ rtrn->base_group= rep.baseGroup;
+ rtrn->latched_group= rep.latchedGroup;
+ rtrn->locked_group= rep.lockedGroup;
+ rtrn->compat_state= rep.compatState;
+ rtrn->grab_mods= rep.grabMods;
+ rtrn->compat_grab_mods= rep.compatGrabMods;
+ rtrn->lookup_mods= rep.lookupMods;
+ rtrn->compat_lookup_mods= rep.compatLookupMods;
+ rtrn->ptr_buttons= rep.ptrBtnState;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return Success;
+}
+
+Bool
+XkbSetDetectableAutoRepeat(Display *dpy,Bool detectable,Bool *supported)
+{
+register xkbPerClientFlagsReq * req;
+xkbPerClientFlagsReply rep;
+XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbPerClientFlags, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbPerClientFlags;
+ req->deviceSpec = XkbUseCoreKbd;
+ req->change = XkbPCF_DetectableAutoRepeatMask;
+ if (detectable)
+ req->value = XkbPCF_DetectableAutoRepeatMask;
+ else req->value = 0;
+ req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if (supported!=NULL)
+ *supported= ((rep.supported&XkbPCF_DetectableAutoRepeatMask)!=0);
+ return ((rep.value&XkbPCF_DetectableAutoRepeatMask)!=0);
+}
+
+Bool
+XkbGetDetectableAutoRepeat(Display *dpy,Bool *supported)
+{
+register xkbPerClientFlagsReq * req;
+xkbPerClientFlagsReply rep;
+XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbPerClientFlags, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbPerClientFlags;
+ req->deviceSpec = XkbUseCoreKbd;
+ req->change = 0;
+ req->value = 0;
+ req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if (supported!=NULL)
+ *supported= ((rep.supported&XkbPCF_DetectableAutoRepeatMask)!=0);
+ return ((rep.value&XkbPCF_DetectableAutoRepeatMask)!=0);
+}
+
+Bool
+XkbSetAutoResetControls( Display * dpy,
+ unsigned changes,
+ unsigned * auto_ctrls,
+ unsigned * auto_values)
+{
+register xkbPerClientFlagsReq * req;
+xkbPerClientFlagsReply rep;
+XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbPerClientFlags, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbPerClientFlags;
+ req->change = XkbPCF_AutoResetControlsMask;
+ req->deviceSpec = XkbUseCoreKbd;
+ req->value = XkbPCF_AutoResetControlsMask;
+ req->ctrlsToChange= changes;
+ req->autoCtrls= *auto_ctrls;
+ req->autoCtrlValues= *auto_values;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ *auto_ctrls= rep.autoCtrls;
+ *auto_values= rep.autoCtrlValues;
+ return ((rep.value&XkbPCF_AutoResetControlsMask)!=0);
+}
+
+Bool
+XkbGetAutoResetControls( Display * dpy,
+ unsigned * auto_ctrls,
+ unsigned * auto_ctrl_values)
+{
+register xkbPerClientFlagsReq * req;
+xkbPerClientFlagsReply rep;
+XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbPerClientFlags, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbPerClientFlags;
+ req->deviceSpec = XkbUseCoreKbd;
+ req->change = 0;
+ req->value = 0;
+ req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if (auto_ctrls)
+ *auto_ctrls= rep.autoCtrls;
+ if (auto_ctrl_values)
+ *auto_ctrl_values= rep.autoCtrlValues;
+ return ((rep.value&XkbPCF_AutoResetControlsMask)!=0);
+}
+
+Bool
+XkbSetPerClientControls( Display * dpy,
+ unsigned change,
+ unsigned * values)
+{
+register xkbPerClientFlagsReq * req;
+xkbPerClientFlagsReply rep;
+XkbInfoPtr xkbi;
+unsigned value_hold = *values;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ||
+ (change & ~(XkbPCF_GrabsUseXKBStateMask|XkbPCF_LookupStateWhenGrabbed|XkbPCF_SendEventUsesXKBState)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbPerClientFlags, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbPerClientFlags;
+ req->change = change;
+ req->deviceSpec = XkbUseCoreKbd;
+ req->value = *values;
+ req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues= 0;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ *values = rep.value;
+ return ((rep.value&value_hold)!=0);
+}
+
+Bool
+XkbGetPerClientControls( Display * dpy,
+ unsigned * ctrls)
+{
+register xkbPerClientFlagsReq * req;
+xkbPerClientFlagsReply rep;
+XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ||
+ (*ctrls & ~(XkbPCF_GrabsUseXKBStateMask|XkbPCF_LookupStateWhenGrabbed|XkbPCF_SendEventUsesXKBState)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbPerClientFlags, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbPerClientFlags;
+ req->deviceSpec = XkbUseCoreKbd;
+ req->change = 0;
+ req->value = 0;
+ req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if (ctrls)
+ *ctrls= (rep.value & (XkbPCF_GrabsUseXKBStateMask |
+ XkbPCF_LookupStateWhenGrabbed |
+ XkbPCF_SendEventUsesXKBState));
+ return (True);
+}
+
+Display *
+XkbOpenDisplay( char * name,
+ int * ev_rtrn,
+ int * err_rtrn,
+ int * major_rtrn,
+ int * minor_rtrn,
+ int * reason)
+{
+ Display* dpy;
+ int major_num,minor_num;
+
+ if ((major_rtrn!=NULL) && (minor_rtrn!=NULL)) {
+ if (!XkbLibraryVersion(major_rtrn,minor_rtrn)) {
+ if (reason!=NULL)
+ *reason= XkbOD_BadLibraryVersion;
+ return NULL;
+ }
+ }
+ else {
+ major_num= XkbMajorVersion;
+ minor_num= XkbMinorVersion;
+ major_rtrn= &major_num;
+ minor_rtrn= &minor_num;
+ }
+ dpy= XOpenDisplay(name);
+ if (dpy==NULL) {
+ if (reason!=NULL)
+ *reason= XkbOD_ConnectionRefused;
+ return NULL;
+ }
+ if (!XkbQueryExtension(dpy,NULL,ev_rtrn,err_rtrn,major_rtrn,minor_rtrn)) {
+ if (reason!=NULL) {
+ if ((*major_rtrn!=0)||(*minor_rtrn!=0))
+ *reason= XkbOD_BadServerVersion;
+ else *reason= XkbOD_NonXkbServer;
+ }
+ XCloseDisplay(dpy);
+ return NULL;
+ }
+ if (reason!=NULL)
+ *reason= XkbOD_Success;
+ return dpy;
+}
+
+void
+XkbSetAtomFuncs(XkbInternAtomFunc getAtom,XkbGetAtomNameFunc getName)
+{
+ _XkbInternAtomFunc= (getAtom?getAtom:XInternAtom);
+ _XkbGetAtomNameFunc= (getName?getName:XGetAtomName);
+ return;
+}
diff --git a/libX11/src/xkb/XKBAlloc.c b/libX11/src/xkb/XKBAlloc.c
index bd615eaae..7a46ef2b9 100644
--- a/libX11/src/xkb/XKBAlloc.c
+++ b/libX11/src/xkb/XKBAlloc.c
@@ -1,502 +1,498 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_DIX_CONFIG_H
-#include <dix-config.h>
-#elif defined(HAVE_CONFIG_H)
-#include <config.h>
-#endif
-
-#ifndef XKB_IN_SERVER
-
-#include <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include "XKBlibint.h"
-#include <X11/extensions/XKBgeom.h>
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-#else
-
-#include <stdio.h>
-#include <X11/X.h>
-#define NEED_EVENTS
-#define NEED_REPLIES
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
-#include <X11/extensions/XKBgeom.h>
-
-#endif /* XKB_IN_SERVER */
-
-/***===================================================================***/
-
-/*ARGSUSED*/
-Status
-XkbAllocCompatMap(XkbDescPtr xkb,unsigned which,unsigned nSI)
-{
-XkbCompatMapPtr compat;
-XkbSymInterpretRec *prev_interpret;
-
- if (!xkb)
- return BadMatch;
- if (xkb->compat) {
- if (xkb->compat->size_si>=nSI)
- return Success;
- compat= xkb->compat;
- compat->size_si= nSI;
- if (compat->sym_interpret==NULL)
- compat->num_si= 0;
- prev_interpret = compat->sym_interpret;
- compat->sym_interpret= _XkbTypedRealloc(compat->sym_interpret,
- nSI,XkbSymInterpretRec);
- if (compat->sym_interpret==NULL) {
- _XkbFree(prev_interpret);
- compat->size_si= compat->num_si= 0;
- return BadAlloc;
- }
- if (compat->num_si!=0) {
- _XkbClearElems(compat->sym_interpret,compat->num_si,
- compat->size_si-1,XkbSymInterpretRec);
- }
- return Success;
- }
- compat= _XkbTypedCalloc(1,XkbCompatMapRec);
- if (compat==NULL)
- return BadAlloc;
- if (nSI>0) {
- compat->sym_interpret= _XkbTypedCalloc(nSI,XkbSymInterpretRec);
- if (!compat->sym_interpret) {
- _XkbFree(compat);
- return BadAlloc;
- }
- }
- compat->size_si= nSI;
- compat->num_si= 0;
- bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
- xkb->compat= compat;
- return Success;
-}
-
-
-void
-XkbFreeCompatMap(XkbDescPtr xkb,unsigned which,Bool freeMap)
-{
-register XkbCompatMapPtr compat;
-
- if ((xkb==NULL)||(xkb->compat==NULL))
- return;
- compat= xkb->compat;
- if (freeMap)
- which= XkbAllCompatMask;
- if (which&XkbGroupCompatMask)
- bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
- if (which&XkbSymInterpMask) {
- if ((compat->sym_interpret)&&(compat->size_si>0))
- _XkbFree(compat->sym_interpret);
- compat->size_si= compat->num_si= 0;
- compat->sym_interpret= NULL;
- }
- if (freeMap) {
- _XkbFree(compat);
- xkb->compat= NULL;
- }
- return;
-}
-
-/***===================================================================***/
-
-Status
-XkbAllocNames(XkbDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases)
-{
-XkbNamesPtr names;
-
- if (xkb==NULL)
- return BadMatch;
- if (xkb->names==NULL) {
- xkb->names = _XkbTypedCalloc(1,XkbNamesRec);
- if (xkb->names==NULL)
- return BadAlloc;
- }
- names= xkb->names;
- if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){
- register int i;
- XkbKeyTypePtr type;
-
- type= xkb->map->types;
- for (i=0;i<xkb->map->num_types;i++,type++) {
- if (type->level_names==NULL) {
- type->level_names= _XkbTypedCalloc(type->num_levels,Atom);
- if (type->level_names==NULL)
- return BadAlloc;
- }
- }
- }
- if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code))||
- (!XkbIsLegalKeycode(xkb->max_key_code))||
- (xkb->max_key_code<xkb->min_key_code))
- return BadValue;
- names->keys= _XkbTypedCalloc((xkb->max_key_code+1),XkbKeyNameRec);
- if (names->keys==NULL)
- return BadAlloc;
- }
- if ((which&XkbKeyAliasesMask)&&(nTotalAliases>0)) {
- if (names->key_aliases==NULL) {
- names->key_aliases= _XkbTypedCalloc(nTotalAliases,XkbKeyAliasRec);
- }
- else if (nTotalAliases>names->num_key_aliases) {
- XkbKeyAliasRec *prev_aliases = names->key_aliases;
-
- names->key_aliases= _XkbTypedRealloc(names->key_aliases,
- nTotalAliases,XkbKeyAliasRec);
- if (names->key_aliases!=NULL) {
- _XkbClearElems(names->key_aliases,names->num_key_aliases,
- nTotalAliases-1,XkbKeyAliasRec);
- } else {
- _XkbFree(prev_aliases);
- }
- }
- if (names->key_aliases==NULL) {
- names->num_key_aliases= 0;
- return BadAlloc;
- }
- names->num_key_aliases= nTotalAliases;
- }
- if ((which&XkbRGNamesMask)&&(nTotalRG>0)) {
- if (names->radio_groups==NULL) {
- names->radio_groups= _XkbTypedCalloc(nTotalRG,Atom);
- }
- else if (nTotalRG>names->num_rg) {
- Atom *prev_radio_groups = names->radio_groups;
-
- names->radio_groups= _XkbTypedRealloc(names->radio_groups,nTotalRG,
- Atom);
- if (names->radio_groups!=NULL) {
- _XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1,
- Atom);
- } else {
- _XkbFree(prev_radio_groups);
- }
- }
- if (names->radio_groups==NULL)
- return BadAlloc;
- names->num_rg= nTotalRG;
- }
- return Success;
-}
-
-void
-XkbFreeNames(XkbDescPtr xkb,unsigned which,Bool freeMap)
-{
-XkbNamesPtr names;
-
- if ((xkb==NULL)||(xkb->names==NULL))
- return;
- names= xkb->names;
- if (freeMap)
- which= XkbAllNamesMask;
- if (which&XkbKTLevelNamesMask) {
- XkbClientMapPtr map= xkb->map;
- if ((map!=NULL)&&(map->types!=NULL)) {
- register int i;
- register XkbKeyTypePtr type;
- type= map->types;
- for (i=0;i<map->num_types;i++,type++) {
- if (type->level_names!=NULL) {
- _XkbFree(type->level_names);
- type->level_names= NULL;
- }
- }
- }
- }
- if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
- _XkbFree(names->keys);
- names->keys= NULL;
- names->num_keys= 0;
- }
- if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){
- _XkbFree(names->key_aliases);
- names->key_aliases=NULL;
- names->num_key_aliases=0;
- }
- if ((which&XkbRGNamesMask)&&(names->radio_groups)) {
- _XkbFree(names->radio_groups);
- names->radio_groups= NULL;
- names->num_rg= 0;
- }
- if (freeMap) {
- _XkbFree(names);
- xkb->names= NULL;
- }
- return;
-}
-
-/***===================================================================***/
-
-/*ARGSUSED*/
-Status
-XkbAllocControls(XkbDescPtr xkb,unsigned which)
-{
- if (xkb==NULL)
- return BadMatch;
-
- if (xkb->ctrls==NULL) {
- xkb->ctrls= _XkbTypedCalloc(1,XkbControlsRec);
- if (!xkb->ctrls)
- return BadAlloc;
- }
- return Success;
-}
-
-/*ARGSUSED*/
-void
-XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap)
-{
- if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) {
- _XkbFree(xkb->ctrls);
- xkb->ctrls= NULL;
- }
- return;
-}
-
-/***===================================================================***/
-
-Status
-XkbAllocIndicatorMaps(XkbDescPtr xkb)
-{
- if (xkb==NULL)
- return BadMatch;
- if (xkb->indicators==NULL) {
- xkb->indicators= _XkbTypedCalloc(1,XkbIndicatorRec);
- if (!xkb->indicators)
- return BadAlloc;
- }
- return Success;
-}
-
-void
-XkbFreeIndicatorMaps(XkbDescPtr xkb)
-{
- if ((xkb!=NULL)&&(xkb->indicators!=NULL)) {
- _XkbFree(xkb->indicators);
- xkb->indicators= NULL;
- }
- return;
-}
-
-/***====================================================================***/
-
-XkbDescRec *
-XkbAllocKeyboard(void)
-{
-XkbDescRec *xkb;
-
- xkb = _XkbTypedCalloc(1,XkbDescRec);
- if (xkb)
- xkb->device_spec= XkbUseCoreKbd;
- return xkb;
-}
-
-void
-XkbFreeKeyboard(XkbDescPtr xkb,unsigned which,Bool freeAll)
-{
- if (xkb==NULL)
- return;
- if (freeAll)
- which= XkbAllComponentsMask;
- if (which&XkbClientMapMask)
- XkbFreeClientMap(xkb,XkbAllClientInfoMask,True);
- if (which&XkbServerMapMask)
- XkbFreeServerMap(xkb,XkbAllServerInfoMask,True);
- if (which&XkbCompatMapMask)
- XkbFreeCompatMap(xkb,XkbAllCompatMask,True);
- if (which&XkbIndicatorMapMask)
- XkbFreeIndicatorMaps(xkb);
- if (which&XkbNamesMask)
- XkbFreeNames(xkb,XkbAllNamesMask,True);
- if ((which&XkbGeometryMask) && (xkb->geom!=NULL))
- XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True);
- if (which&XkbControlsMask)
- XkbFreeControls(xkb,XkbAllControlsMask,True);
- if (freeAll)
- _XkbFree(xkb);
- return;
-}
-
-/***====================================================================***/
-
-XkbDeviceLedInfoPtr
-XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi,unsigned ledClass,unsigned ledId)
-{
-XkbDeviceLedInfoPtr devli;
-register int i;
-
- if ((!devi)||(!XkbSingleXIClass(ledClass))||(!XkbSingleXIId(ledId)))
- return NULL;
- for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) {
- if ((devli->led_class==ledClass)&&(devli->led_id==ledId))
- return devli;
- }
- if (devi->num_leds>=devi->sz_leds) {
- XkbDeviceLedInfoRec *prev_leds = devi->leds;
-
- if (devi->sz_leds>0) devi->sz_leds*= 2;
- else devi->sz_leds= 1;
- devi->leds= _XkbTypedRealloc(devi->leds,devi->sz_leds,
- XkbDeviceLedInfoRec);
- if (!devi->leds) {
- _XkbFree(prev_leds);
- devi->sz_leds= devi->num_leds= 0;
- return NULL;
- }
- i= devi->num_leds;
- for (devli=&devi->leds[i];i<devi->sz_leds;i++,devli++) {
- bzero(devli,sizeof(XkbDeviceLedInfoRec));
- devli->led_class= XkbXINone;
- devli->led_id= XkbXINone;
- }
- }
- devli= &devi->leds[devi->num_leds++];
- bzero(devli,sizeof(XkbDeviceLedInfoRec));
- devli->led_class= ledClass;
- devli->led_id= ledId;
- return devli;
-}
-
-Status
-XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi,unsigned newTotal)
-{
- XkbAction *prev_btn_acts;
-
- if ((!devi)||(newTotal>255))
- return BadValue;
- if ((devi->btn_acts!=NULL)&&(newTotal==devi->num_btns))
- return Success;
- if (newTotal==0) {
- if (devi->btn_acts!=NULL) {
- _XkbFree(devi->btn_acts);
- devi->btn_acts= NULL;
- }
- devi->num_btns= 0;
- return Success;
- }
- prev_btn_acts = devi->btn_acts;
- devi->btn_acts= _XkbTypedRealloc(devi->btn_acts,newTotal,XkbAction);
- if (devi->btn_acts==NULL) {
- _XkbFree(prev_btn_acts);
- devi->num_btns= 0;
- return BadAlloc;
- }
- if (newTotal>devi->num_btns) {
- XkbAction *act;
- act= &devi->btn_acts[devi->num_btns];
- bzero((char *)act,(newTotal-devi->num_btns)*sizeof(XkbAction));
- }
- devi->num_btns= newTotal;
- return Success;
-}
-
-/*ARGSUSED*/
-XkbDeviceInfoPtr
-XkbAllocDeviceInfo(unsigned deviceSpec,unsigned nButtons,unsigned szLeds)
-{
-XkbDeviceInfoPtr devi;
-
- devi= _XkbTypedCalloc(1,XkbDeviceInfoRec);
- if (devi!=NULL) {
- devi->device_spec= deviceSpec;
- devi->has_own_state= False;
- devi->num_btns= 0;
- devi->btn_acts= NULL;
- if (nButtons>0) {
- devi->num_btns= nButtons;
- devi->btn_acts= _XkbTypedCalloc(nButtons,XkbAction);
- if (!devi->btn_acts) {
- _XkbFree(devi);
- return NULL;
- }
- }
- devi->dflt_kbd_fb= XkbXINone;
- devi->dflt_led_fb= XkbXINone;
- devi->num_leds= 0;
- devi->sz_leds= 0;
- devi->leds= NULL;
- if (szLeds>0) {
- devi->sz_leds= szLeds;
- devi->leds= _XkbTypedCalloc(szLeds,XkbDeviceLedInfoRec);
- if (!devi->leds) {
- if (devi->btn_acts)
- _XkbFree(devi->btn_acts);
- _XkbFree(devi);
- return NULL;
- }
- }
- }
- return devi;
-}
-
-
-void
-XkbFreeDeviceInfo(XkbDeviceInfoPtr devi,unsigned which,Bool freeDevI)
-{
- if (devi) {
- if (freeDevI) {
- which= XkbXI_AllDeviceFeaturesMask;
- if (devi->name) {
- _XkbFree(devi->name);
- devi->name= NULL;
- }
- }
- if ((which&XkbXI_ButtonActionsMask)&&(devi->btn_acts)) {
- _XkbFree(devi->btn_acts);
- devi->num_btns= 0;
- devi->btn_acts= NULL;
- }
- if ((which&XkbXI_IndicatorsMask)&&(devi->leds)) {
- register int i;
- if ((which&XkbXI_IndicatorsMask)==XkbXI_IndicatorsMask) {
- _XkbFree(devi->leds);
- devi->sz_leds= devi->num_leds= 0;
- devi->leds= NULL;
- }
- else {
- XkbDeviceLedInfoPtr devli;
- for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) {
- if (which&XkbXI_IndicatorMapsMask)
- bzero((char *)&devli->maps[0],sizeof(devli->maps));
- else bzero((char *)&devli->names[0],sizeof(devli->names));
- }
- }
- }
- if (freeDevI)
- _XkbFree(devi);
- }
- return;
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_DIX_CONFIG_H
+#include <dix-config.h>
+#elif defined(HAVE_CONFIG_H)
+#include <config.h>
+#endif
+
+#ifndef XKB_IN_SERVER
+
+#include <stdio.h>
+#include "Xlibint.h"
+#include "XKBlibint.h"
+#include <X11/extensions/XKBgeom.h>
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+#else
+
+#include <stdio.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "inputstr.h"
+#include <X11/extensions/XKBsrv.h>
+#include <X11/extensions/XKBgeom.h>
+
+#endif /* XKB_IN_SERVER */
+
+/***===================================================================***/
+
+/*ARGSUSED*/
+Status
+XkbAllocCompatMap(XkbDescPtr xkb,unsigned which,unsigned nSI)
+{
+XkbCompatMapPtr compat;
+XkbSymInterpretRec *prev_interpret;
+
+ if (!xkb)
+ return BadMatch;
+ if (xkb->compat) {
+ if (xkb->compat->size_si>=nSI)
+ return Success;
+ compat= xkb->compat;
+ compat->size_si= nSI;
+ if (compat->sym_interpret==NULL)
+ compat->num_si= 0;
+ prev_interpret = compat->sym_interpret;
+ compat->sym_interpret= _XkbTypedRealloc(compat->sym_interpret,
+ nSI,XkbSymInterpretRec);
+ if (compat->sym_interpret==NULL) {
+ _XkbFree(prev_interpret);
+ compat->size_si= compat->num_si= 0;
+ return BadAlloc;
+ }
+ if (compat->num_si!=0) {
+ _XkbClearElems(compat->sym_interpret,compat->num_si,
+ compat->size_si-1,XkbSymInterpretRec);
+ }
+ return Success;
+ }
+ compat= _XkbTypedCalloc(1,XkbCompatMapRec);
+ if (compat==NULL)
+ return BadAlloc;
+ if (nSI>0) {
+ compat->sym_interpret= _XkbTypedCalloc(nSI,XkbSymInterpretRec);
+ if (!compat->sym_interpret) {
+ _XkbFree(compat);
+ return BadAlloc;
+ }
+ }
+ compat->size_si= nSI;
+ compat->num_si= 0;
+ bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
+ xkb->compat= compat;
+ return Success;
+}
+
+
+void
+XkbFreeCompatMap(XkbDescPtr xkb,unsigned which,Bool freeMap)
+{
+register XkbCompatMapPtr compat;
+
+ if ((xkb==NULL)||(xkb->compat==NULL))
+ return;
+ compat= xkb->compat;
+ if (freeMap)
+ which= XkbAllCompatMask;
+ if (which&XkbGroupCompatMask)
+ bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
+ if (which&XkbSymInterpMask) {
+ if ((compat->sym_interpret)&&(compat->size_si>0))
+ _XkbFree(compat->sym_interpret);
+ compat->size_si= compat->num_si= 0;
+ compat->sym_interpret= NULL;
+ }
+ if (freeMap) {
+ _XkbFree(compat);
+ xkb->compat= NULL;
+ }
+ return;
+}
+
+/***===================================================================***/
+
+Status
+XkbAllocNames(XkbDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases)
+{
+XkbNamesPtr names;
+
+ if (xkb==NULL)
+ return BadMatch;
+ if (xkb->names==NULL) {
+ xkb->names = _XkbTypedCalloc(1,XkbNamesRec);
+ if (xkb->names==NULL)
+ return BadAlloc;
+ }
+ names= xkb->names;
+ if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){
+ register int i;
+ XkbKeyTypePtr type;
+
+ type= xkb->map->types;
+ for (i=0;i<xkb->map->num_types;i++,type++) {
+ if (type->level_names==NULL) {
+ type->level_names= _XkbTypedCalloc(type->num_levels,Atom);
+ if (type->level_names==NULL)
+ return BadAlloc;
+ }
+ }
+ }
+ if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) {
+ if ((!XkbIsLegalKeycode(xkb->min_key_code))||
+ (!XkbIsLegalKeycode(xkb->max_key_code))||
+ (xkb->max_key_code<xkb->min_key_code))
+ return BadValue;
+ names->keys= _XkbTypedCalloc((xkb->max_key_code+1),XkbKeyNameRec);
+ if (names->keys==NULL)
+ return BadAlloc;
+ }
+ if ((which&XkbKeyAliasesMask)&&(nTotalAliases>0)) {
+ if (names->key_aliases==NULL) {
+ names->key_aliases= _XkbTypedCalloc(nTotalAliases,XkbKeyAliasRec);
+ }
+ else if (nTotalAliases>names->num_key_aliases) {
+ XkbKeyAliasRec *prev_aliases = names->key_aliases;
+
+ names->key_aliases= _XkbTypedRealloc(names->key_aliases,
+ nTotalAliases,XkbKeyAliasRec);
+ if (names->key_aliases!=NULL) {
+ _XkbClearElems(names->key_aliases,names->num_key_aliases,
+ nTotalAliases-1,XkbKeyAliasRec);
+ } else {
+ _XkbFree(prev_aliases);
+ }
+ }
+ if (names->key_aliases==NULL) {
+ names->num_key_aliases= 0;
+ return BadAlloc;
+ }
+ names->num_key_aliases= nTotalAliases;
+ }
+ if ((which&XkbRGNamesMask)&&(nTotalRG>0)) {
+ if (names->radio_groups==NULL) {
+ names->radio_groups= _XkbTypedCalloc(nTotalRG,Atom);
+ }
+ else if (nTotalRG>names->num_rg) {
+ Atom *prev_radio_groups = names->radio_groups;
+
+ names->radio_groups= _XkbTypedRealloc(names->radio_groups,nTotalRG,
+ Atom);
+ if (names->radio_groups!=NULL) {
+ _XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1,
+ Atom);
+ } else {
+ _XkbFree(prev_radio_groups);
+ }
+ }
+ if (names->radio_groups==NULL)
+ return BadAlloc;
+ names->num_rg= nTotalRG;
+ }
+ return Success;
+}
+
+void
+XkbFreeNames(XkbDescPtr xkb,unsigned which,Bool freeMap)
+{
+XkbNamesPtr names;
+
+ if ((xkb==NULL)||(xkb->names==NULL))
+ return;
+ names= xkb->names;
+ if (freeMap)
+ which= XkbAllNamesMask;
+ if (which&XkbKTLevelNamesMask) {
+ XkbClientMapPtr map= xkb->map;
+ if ((map!=NULL)&&(map->types!=NULL)) {
+ register int i;
+ register XkbKeyTypePtr type;
+ type= map->types;
+ for (i=0;i<map->num_types;i++,type++) {
+ if (type->level_names!=NULL) {
+ _XkbFree(type->level_names);
+ type->level_names= NULL;
+ }
+ }
+ }
+ }
+ if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
+ _XkbFree(names->keys);
+ names->keys= NULL;
+ names->num_keys= 0;
+ }
+ if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){
+ _XkbFree(names->key_aliases);
+ names->key_aliases=NULL;
+ names->num_key_aliases=0;
+ }
+ if ((which&XkbRGNamesMask)&&(names->radio_groups)) {
+ _XkbFree(names->radio_groups);
+ names->radio_groups= NULL;
+ names->num_rg= 0;
+ }
+ if (freeMap) {
+ _XkbFree(names);
+ xkb->names= NULL;
+ }
+ return;
+}
+
+/***===================================================================***/
+
+/*ARGSUSED*/
+Status
+XkbAllocControls(XkbDescPtr xkb,unsigned which)
+{
+ if (xkb==NULL)
+ return BadMatch;
+
+ if (xkb->ctrls==NULL) {
+ xkb->ctrls= _XkbTypedCalloc(1,XkbControlsRec);
+ if (!xkb->ctrls)
+ return BadAlloc;
+ }
+ return Success;
+}
+
+/*ARGSUSED*/
+void
+XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap)
+{
+ if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) {
+ _XkbFree(xkb->ctrls);
+ xkb->ctrls= NULL;
+ }
+ return;
+}
+
+/***===================================================================***/
+
+Status
+XkbAllocIndicatorMaps(XkbDescPtr xkb)
+{
+ if (xkb==NULL)
+ return BadMatch;
+ if (xkb->indicators==NULL) {
+ xkb->indicators= _XkbTypedCalloc(1,XkbIndicatorRec);
+ if (!xkb->indicators)
+ return BadAlloc;
+ }
+ return Success;
+}
+
+void
+XkbFreeIndicatorMaps(XkbDescPtr xkb)
+{
+ if ((xkb!=NULL)&&(xkb->indicators!=NULL)) {
+ _XkbFree(xkb->indicators);
+ xkb->indicators= NULL;
+ }
+ return;
+}
+
+/***====================================================================***/
+
+XkbDescRec *
+XkbAllocKeyboard(void)
+{
+XkbDescRec *xkb;
+
+ xkb = _XkbTypedCalloc(1,XkbDescRec);
+ if (xkb)
+ xkb->device_spec= XkbUseCoreKbd;
+ return xkb;
+}
+
+void
+XkbFreeKeyboard(XkbDescPtr xkb,unsigned which,Bool freeAll)
+{
+ if (xkb==NULL)
+ return;
+ if (freeAll)
+ which= XkbAllComponentsMask;
+ if (which&XkbClientMapMask)
+ XkbFreeClientMap(xkb,XkbAllClientInfoMask,True);
+ if (which&XkbServerMapMask)
+ XkbFreeServerMap(xkb,XkbAllServerInfoMask,True);
+ if (which&XkbCompatMapMask)
+ XkbFreeCompatMap(xkb,XkbAllCompatMask,True);
+ if (which&XkbIndicatorMapMask)
+ XkbFreeIndicatorMaps(xkb);
+ if (which&XkbNamesMask)
+ XkbFreeNames(xkb,XkbAllNamesMask,True);
+ if ((which&XkbGeometryMask) && (xkb->geom!=NULL))
+ XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True);
+ if (which&XkbControlsMask)
+ XkbFreeControls(xkb,XkbAllControlsMask,True);
+ if (freeAll)
+ _XkbFree(xkb);
+ return;
+}
+
+/***====================================================================***/
+
+XkbDeviceLedInfoPtr
+XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi,unsigned ledClass,unsigned ledId)
+{
+XkbDeviceLedInfoPtr devli;
+register int i;
+
+ if ((!devi)||(!XkbSingleXIClass(ledClass))||(!XkbSingleXIId(ledId)))
+ return NULL;
+ for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) {
+ if ((devli->led_class==ledClass)&&(devli->led_id==ledId))
+ return devli;
+ }
+ if (devi->num_leds>=devi->sz_leds) {
+ XkbDeviceLedInfoRec *prev_leds = devi->leds;
+
+ if (devi->sz_leds>0) devi->sz_leds*= 2;
+ else devi->sz_leds= 1;
+ devi->leds= _XkbTypedRealloc(devi->leds,devi->sz_leds,
+ XkbDeviceLedInfoRec);
+ if (!devi->leds) {
+ _XkbFree(prev_leds);
+ devi->sz_leds= devi->num_leds= 0;
+ return NULL;
+ }
+ i= devi->num_leds;
+ for (devli=&devi->leds[i];i<devi->sz_leds;i++,devli++) {
+ bzero(devli,sizeof(XkbDeviceLedInfoRec));
+ devli->led_class= XkbXINone;
+ devli->led_id= XkbXINone;
+ }
+ }
+ devli= &devi->leds[devi->num_leds++];
+ bzero(devli,sizeof(XkbDeviceLedInfoRec));
+ devli->led_class= ledClass;
+ devli->led_id= ledId;
+ return devli;
+}
+
+Status
+XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi,unsigned newTotal)
+{
+ XkbAction *prev_btn_acts;
+
+ if ((!devi)||(newTotal>255))
+ return BadValue;
+ if ((devi->btn_acts!=NULL)&&(newTotal==devi->num_btns))
+ return Success;
+ if (newTotal==0) {
+ if (devi->btn_acts!=NULL) {
+ _XkbFree(devi->btn_acts);
+ devi->btn_acts= NULL;
+ }
+ devi->num_btns= 0;
+ return Success;
+ }
+ prev_btn_acts = devi->btn_acts;
+ devi->btn_acts= _XkbTypedRealloc(devi->btn_acts,newTotal,XkbAction);
+ if (devi->btn_acts==NULL) {
+ _XkbFree(prev_btn_acts);
+ devi->num_btns= 0;
+ return BadAlloc;
+ }
+ if (newTotal>devi->num_btns) {
+ XkbAction *act;
+ act= &devi->btn_acts[devi->num_btns];
+ bzero((char *)act,(newTotal-devi->num_btns)*sizeof(XkbAction));
+ }
+ devi->num_btns= newTotal;
+ return Success;
+}
+
+/*ARGSUSED*/
+XkbDeviceInfoPtr
+XkbAllocDeviceInfo(unsigned deviceSpec,unsigned nButtons,unsigned szLeds)
+{
+XkbDeviceInfoPtr devi;
+
+ devi= _XkbTypedCalloc(1,XkbDeviceInfoRec);
+ if (devi!=NULL) {
+ devi->device_spec= deviceSpec;
+ devi->has_own_state= False;
+ devi->num_btns= 0;
+ devi->btn_acts= NULL;
+ if (nButtons>0) {
+ devi->num_btns= nButtons;
+ devi->btn_acts= _XkbTypedCalloc(nButtons,XkbAction);
+ if (!devi->btn_acts) {
+ _XkbFree(devi);
+ return NULL;
+ }
+ }
+ devi->dflt_kbd_fb= XkbXINone;
+ devi->dflt_led_fb= XkbXINone;
+ devi->num_leds= 0;
+ devi->sz_leds= 0;
+ devi->leds= NULL;
+ if (szLeds>0) {
+ devi->sz_leds= szLeds;
+ devi->leds= _XkbTypedCalloc(szLeds,XkbDeviceLedInfoRec);
+ if (!devi->leds) {
+ if (devi->btn_acts)
+ _XkbFree(devi->btn_acts);
+ _XkbFree(devi);
+ return NULL;
+ }
+ }
+ }
+ return devi;
+}
+
+
+void
+XkbFreeDeviceInfo(XkbDeviceInfoPtr devi,unsigned which,Bool freeDevI)
+{
+ if (devi) {
+ if (freeDevI) {
+ which= XkbXI_AllDeviceFeaturesMask;
+ if (devi->name) {
+ _XkbFree(devi->name);
+ devi->name= NULL;
+ }
+ }
+ if ((which&XkbXI_ButtonActionsMask)&&(devi->btn_acts)) {
+ _XkbFree(devi->btn_acts);
+ devi->num_btns= 0;
+ devi->btn_acts= NULL;
+ }
+ if ((which&XkbXI_IndicatorsMask)&&(devi->leds)) {
+ register int i;
+ if ((which&XkbXI_IndicatorsMask)==XkbXI_IndicatorsMask) {
+ _XkbFree(devi->leds);
+ devi->sz_leds= devi->num_leds= 0;
+ devi->leds= NULL;
+ }
+ else {
+ XkbDeviceLedInfoPtr devli;
+ for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) {
+ if (which&XkbXI_IndicatorMapsMask)
+ bzero((char *)&devli->maps[0],sizeof(devli->maps));
+ else bzero((char *)&devli->names[0],sizeof(devli->names));
+ }
+ }
+ }
+ if (freeDevI)
+ _XkbFree(devi);
+ }
+ return;
+}
diff --git a/libX11/src/xkb/XKBBell.c b/libX11/src/xkb/XKBBell.c
index 0054a5c28..13937c9cd 100644
--- a/libX11/src/xkb/XKBBell.c
+++ b/libX11/src/xkb/XKBBell.c
@@ -1,180 +1,178 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-
-Bool
-XkbDeviceBell( Display * dpy,
- Window window,
- int deviceID,
- int bellClass,
- int bellID,
- int percent,
- Atom name)
-{
- register xkbBellReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbBell,req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbBell;
- req->deviceSpec = deviceID;
- req->window = (CARD32)window;
- req->bellClass = (CARD16)bellClass;
- req->bellID = (CARD16)bellID;
- req->percent = percent;
- req->forceSound = False;
- req->eventOnly = False;
- req->pitch = 0;
- req->duration = 0;
- req->name = (CARD32)name;
- req->pad1= 0; req->pad2= 0;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbForceDeviceBell( Display * dpy,
- int deviceID,
- int bellClass,
- int bellID,
- int percent)
-{
- register xkbBellReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbBell,req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbBell;
- req->deviceSpec = deviceID;
- req->window = (CARD32)None;
- req->bellClass = (CARD16)bellClass;
- req->bellID = (CARD16)bellID;
- req->percent = percent;
- req->forceSound = True;
- req->eventOnly = False;
- req->pitch = 0;
- req->duration = 0;
- req->name = None;
- req->pad1= 0; req->pad2= 0;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbDeviceBellEvent( Display * dpy,
- Window window,
- int deviceID,
- int bellClass,
- int bellID,
- int percent,
- Atom name)
-{
- register xkbBellReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbBell,req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbBell;
- req->deviceSpec = deviceID;
- req->window = (CARD32)window;
- req->bellClass = (CARD16)bellClass;
- req->bellID = (CARD16)bellID;
- req->percent = percent;
- req->forceSound = False;
- req->eventOnly = True;
- req->pitch = 0;
- req->duration = 0;
- req->name = (CARD32)name;
- req->pad1= 0; req->pad2= 0;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbBell(Display *dpy,Window window,int percent,Atom name)
-{
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
- XBell(dpy,percent);
- return False;
- }
- return XkbDeviceBell(dpy,window,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId,
- percent,name);
-}
-
-Bool
-XkbForceBell(Display *dpy,int percent)
-{
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
- XBell(dpy,percent);
- return False;
- }
- return XkbForceDeviceBell(dpy,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId,
- percent);
-}
-
-Bool
-XkbBellEvent(Display *dpy,Window window,int percent,Atom name)
-{
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
- return False;
- }
- /* class 0 = KbdFeedbackClass (X Input Extension) */
- return XkbDeviceBellEvent(dpy,window,XkbUseCoreKbd,
- XkbDfltXIClass,XkbDfltXIId,
- percent,name);
-}
-
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 <stdio.h>
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+
+Bool
+XkbDeviceBell( Display * dpy,
+ Window window,
+ int deviceID,
+ int bellClass,
+ int bellID,
+ int percent,
+ Atom name)
+{
+ register xkbBellReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbBell,req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbBell;
+ req->deviceSpec = deviceID;
+ req->window = (CARD32)window;
+ req->bellClass = (CARD16)bellClass;
+ req->bellID = (CARD16)bellID;
+ req->percent = percent;
+ req->forceSound = False;
+ req->eventOnly = False;
+ req->pitch = 0;
+ req->duration = 0;
+ req->name = (CARD32)name;
+ req->pad1= 0; req->pad2= 0;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbForceDeviceBell( Display * dpy,
+ int deviceID,
+ int bellClass,
+ int bellID,
+ int percent)
+{
+ register xkbBellReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbBell,req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbBell;
+ req->deviceSpec = deviceID;
+ req->window = (CARD32)None;
+ req->bellClass = (CARD16)bellClass;
+ req->bellID = (CARD16)bellID;
+ req->percent = percent;
+ req->forceSound = True;
+ req->eventOnly = False;
+ req->pitch = 0;
+ req->duration = 0;
+ req->name = None;
+ req->pad1= 0; req->pad2= 0;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbDeviceBellEvent( Display * dpy,
+ Window window,
+ int deviceID,
+ int bellClass,
+ int bellID,
+ int percent,
+ Atom name)
+{
+ register xkbBellReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbBell,req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbBell;
+ req->deviceSpec = deviceID;
+ req->window = (CARD32)window;
+ req->bellClass = (CARD16)bellClass;
+ req->bellID = (CARD16)bellID;
+ req->percent = percent;
+ req->forceSound = False;
+ req->eventOnly = True;
+ req->pitch = 0;
+ req->duration = 0;
+ req->name = (CARD32)name;
+ req->pad1= 0; req->pad2= 0;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbBell(Display *dpy,Window window,int percent,Atom name)
+{
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
+ XBell(dpy,percent);
+ return False;
+ }
+ return XkbDeviceBell(dpy,window,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId,
+ percent,name);
+}
+
+Bool
+XkbForceBell(Display *dpy,int percent)
+{
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
+ XBell(dpy,percent);
+ return False;
+ }
+ return XkbForceDeviceBell(dpy,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId,
+ percent);
+}
+
+Bool
+XkbBellEvent(Display *dpy,Window window,int percent,Atom name)
+{
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
+ return False;
+ }
+ /* class 0 = KbdFeedbackClass (X Input Extension) */
+ return XkbDeviceBellEvent(dpy,window,XkbUseCoreKbd,
+ XkbDfltXIClass,XkbDfltXIId,
+ percent,name);
+}
+
diff --git a/libX11/src/xkb/XKBBind.c b/libX11/src/xkb/XKBBind.c
index c07c40697..4904b461f 100644
--- a/libX11/src/xkb/XKBBind.c
+++ b/libX11/src/xkb/XKBBind.c
@@ -1,877 +1,876 @@
-/*
-
-Copyright 1985, 1987, 1994, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
- /* the new monsters ate the old ones */
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef XKB_IN_SERVER
-#define XkbAllocClientMap SrvXkbAllocClientMap
-#define XkbAllocServerMap SrvXkbAllocServerMap
-#define XkbChangeTypesOfKey SrvXkbChangeTypesOfKey
-#define XkbCopyKeyTypes SrvXkbCopyKeyTypes
-#define XkbFreeClientMap SrvXkbFreeClientMap
-#define XkbFreeServerMap SrvXkbFreeServerMap
-#define XkbKeyTypesForCoreSymbols SrvXkbKeyTypesForCoreSymbols
-#define XkbApplyCompatMapToKey SrvXkbApplyCompatMapToKey
-#define XkbResizeKeyActions SrvXkbResizeKeyActions
-#define XkbResizeKeySyms SrvXkbResizeKeySyms
-#define XkbResizeKeyType SrvXkbResizeKeyType
-#define XkbAllocCompatMap SrvXkbAllocCompatMap
-#define XkbAllocControls SrvXkbAllocControls
-#define XkbAllocIndicatorMaps SrvXkbAllocIndicatorMaps
-#define XkbAllocKeyboard SrvXkbAllocKeyboard
-#define XkbAllocNames SrvXkbAllocNames
-#define XkbFreeCompatMap SrvXkbFreeCompatMap
-#define XkbFreeKeyboard SrvXkbFreeKeyboard
-#define XkbFreeNames SrvXkbFreeNames
-#define XkbLatchModifiers SrvXkbLatchModifiers
-#define XkbLatchGroup SrvXkbLatchGroup
-#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
-#define XkbChangeKeycodeRange SrvXkbChangeKeycodeRange
-#define XkbApplyVirtualModChanges SrvXkbApplyVirtualModChanges
-#endif
-
-#include "XKBlib.h"
-#include <X11/Xlibint.h>
-#include <X11/Xutil.h>
-#include <X11/keysym.h>
-#include <stdio.h>
-#include <ctype.h>
-
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-#ifdef USE_OWN_COMPOSE
-#define COMPOSE_NO_CONST_MEMBERS
-#include "imComp.h"
-#endif
-
-#define AllMods (ShiftMask|LockMask|ControlMask| \
- Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)
-
-static int _XkbLoadDpy(
- Display *dpy
-);
-
-struct _XKeytrans {
- struct _XKeytrans *next;/* next on list */
- char *string; /* string to return when the time comes */
- int len; /* length of string (since NULL is legit)*/
- KeySym key; /* keysym rebound */
- unsigned int state; /* modifier state */
- KeySym *modifiers; /* modifier keysyms you want */
- int mlen; /* length of modifier list */
-};
-
-KeySym
-XkbKeycodeToKeysym(Display *dpy,
-#if NeedWidePrototypes
- unsigned int kc,
-#else
- KeyCode kc,
-#endif
- int group,
- int level)
-{
- XkbDescRec *xkb;
-
- if (_XkbUnavailable(dpy))
- return NoSymbol;
-
- _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
-
- xkb = dpy->xkb_info->desc;
- if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code))
- return NoSymbol;
-
- if ((group<0)||(level<0)||(group>=XkbKeyNumGroups(xkb,kc)))
- return NoSymbol;
- if (level>=XkbKeyGroupWidth(xkb,kc,group)) {
- /* for compatibility with the core protocol, _always_ allow */
- /* two symbols in the first two groups. If either of the */
- /* two is of type ONE_LEVEL, just replicate the first symbol */
- if ((group>XkbGroup2Index)||(XkbKeyGroupWidth(xkb,kc,group)!=1)||
- (level!=1)) {
- return NoSymbol;
- }
- level= 0;
- }
- return XkbKeySymEntry(xkb,kc,level,group);
-}
-
-KeySym
-XKeycodeToKeysym(Display *dpy,
-#if NeedWidePrototypes
- unsigned int kc,
-#else
- KeyCode kc,
-#endif
- int col)
-{
- XkbDescRec *xkb;
-
- if (_XkbUnavailable(dpy))
- return _XKeycodeToKeysym(dpy, kc, col);
-
- _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
-
- xkb = dpy->xkb_info->desc;
- if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code))
- return NoSymbol;
-
- if (col>3) {
- int lastSym,tmp,nGrp;
-
- lastSym= 3;
- nGrp= XkbKeyNumGroups(xkb,kc);
- if ((nGrp>0)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup1Index))>2)) {
- if (col<=(lastSym+tmp-2))
- return XkbKeycodeToKeysym(dpy,kc,XkbGroup1Index,col-lastSym+2);
- lastSym+= tmp-2;
- }
- if ((nGrp>1)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup2Index))>2)) {
- if (col<=(lastSym+tmp-2))
- return XkbKeycodeToKeysym(dpy,kc,XkbGroup2Index,col-lastSym+2);
- lastSym+= tmp-2;
- }
- if (nGrp>2) {
- tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup3Index);
- if (col<=lastSym+tmp)
- return XkbKeycodeToKeysym(dpy,kc,XkbGroup3Index,col-lastSym);
- lastSym+= tmp;
- }
- if (nGrp>3) {
- tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup4Index);
- if (col<=lastSym+tmp)
- return XkbKeycodeToKeysym(dpy,kc,XkbGroup4Index,col-lastSym);
- }
- return NoSymbol;
- }
- return XkbKeycodeToKeysym(dpy,kc,(col>>1),(col&1));
-}
-
-KeyCode
-XKeysymToKeycode(Display *dpy, KeySym ks)
-{
- register int i, j, gotOne;
-
- if (_XkbUnavailable(dpy))
- return _XKeysymToKeycode(dpy,ks);
- _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
-
- j= 0;
- do {
- register XkbDescRec *xkb = dpy->xkb_info->desc;
- gotOne= 0;
- for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) {
- if ( j<(int)XkbKeyNumSyms(xkb,i) ) {
- gotOne = 1;
- if ((XkbKeySym(xkb,i,j)==ks))
- return i;
- }
- }
- j++;
- } while (gotOne);
- return 0;
-}
-
-static int
-_XkbComputeModmap(Display *dpy)
-{
-register XkbDescPtr xkb;
-
- xkb= dpy->xkb_info->desc;
- if (XkbGetUpdatedMap(dpy,XkbModifierMapMask,xkb)==Success)
- return 1;
- return 0;
-}
-
-unsigned
-XkbKeysymToModifiers(Display *dpy,KeySym ks)
-{
- XkbDescRec *xkb;
- register int i,j;
- register KeySym *pSyms;
- CARD8 mods;
-
- if (_XkbUnavailable(dpy))
- return _XKeysymToModifiers(dpy,ks);
- _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
-
- if (_XkbNeedModmap(dpy->xkb_info)&&(!_XkbComputeModmap(dpy)))
- return _XKeysymToModifiers(dpy,ks);
-
- xkb= dpy->xkb_info->desc;
- mods= 0;
- for (i = xkb->min_key_code; i <= (int)xkb->max_key_code; i++) {
- pSyms= XkbKeySymsPtr(xkb,i);
- for (j=XkbKeyNumSyms(xkb,i)-1;j>=0;j--) {
- if (pSyms[j]==ks) {
- mods|= xkb->map->modmap[i];
- break;
- }
- }
- }
- return mods;
-}
-
-KeySym
-XLookupKeysym(register XKeyEvent *event, int col)
-{
- Display *dpy = event->display;
- if (_XkbUnavailable(dpy))
- return _XLookupKeysym(event, col);
- _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
- return XKeycodeToKeysym(dpy, event->keycode, col);
-}
-
- /*
- * Not a public entry point -- XkbTranslateKey is an obsolete name
- * that is preserved here so that functions linked against the old
- * version will continue to work in a shared library environment.
- */
-int
-XkbTranslateKey( register Display * dpy,
- KeyCode key,
- register unsigned int mods,
- unsigned int * mods_rtrn,
- KeySym * keysym_rtrn);
-int
-XkbTranslateKey( register Display * dpy,
- KeyCode key,
- register unsigned int mods,
- unsigned int * mods_rtrn,
- KeySym * keysym_rtrn)
-{
- return XkbLookupKeySym(dpy,key,mods,mods_rtrn,keysym_rtrn);
-}
-
-Bool
-XkbLookupKeySym( register Display * dpy,
- KeyCode key,
- register unsigned int mods,
- unsigned int * mods_rtrn,
- KeySym * keysym_rtrn)
-{
- if (_XkbUnavailable(dpy))
- return _XTranslateKey(dpy, key, mods, mods_rtrn, keysym_rtrn);
- _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
- return XkbTranslateKeyCode(dpy->xkb_info->desc,key,mods,mods_rtrn,
- keysym_rtrn);
-}
-
-Bool
-XkbTranslateKeyCode( register XkbDescPtr xkb,
- KeyCode key,
- register unsigned int mods,
- unsigned int * mods_rtrn,
- KeySym * keysym_rtrn)
-{
- XkbKeyTypeRec *type;
- int col,nKeyGroups;
- unsigned preserve,effectiveGroup;
- KeySym *syms;
-
- if (mods_rtrn!=NULL)
- *mods_rtrn = 0;
-
- nKeyGroups= XkbKeyNumGroups(xkb,key);
- if ((!XkbKeycodeInRange(xkb,key))||(nKeyGroups==0)) {
- if (keysym_rtrn!=NULL)
- *keysym_rtrn = NoSymbol;
- return False;
- }
-
- syms = XkbKeySymsPtr(xkb,key);
-
- /* find the offset of the effective group */
- col = 0;
- effectiveGroup= XkbGroupForCoreState(mods);
- if ( effectiveGroup>=nKeyGroups ) {
- unsigned groupInfo= XkbKeyGroupInfo(xkb,key);
- switch (XkbOutOfRangeGroupAction(groupInfo)) {
- default:
- effectiveGroup %= nKeyGroups;
- break;
- case XkbClampIntoRange:
- effectiveGroup = nKeyGroups-1;
- break;
- case XkbRedirectIntoRange:
- effectiveGroup = XkbOutOfRangeGroupNumber(groupInfo);
- if (effectiveGroup>=nKeyGroups)
- effectiveGroup= 0;
- break;
- }
- }
- col= effectiveGroup*XkbKeyGroupsWidth(xkb,key);
- type = XkbKeyKeyType(xkb,key,effectiveGroup);
-
- preserve= 0;
- if (type->map) { /* find the column (shift level) within the group */
- register int i;
- register XkbKTMapEntryPtr entry;
- for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
- if ((entry->active)&&((mods&type->mods.mask)==entry->mods.mask)) {
- col+= entry->level;
- if (type->preserve)
- preserve= type->preserve[i].mask;
- break;
- }
- }
- }
-
- if (keysym_rtrn!=NULL)
- *keysym_rtrn= syms[col];
- if (mods_rtrn) {
- *mods_rtrn= type->mods.mask&(~preserve);
- /* The Motif VTS doesn't get the help callback called if help
- * is bound to Shift+<whatever>, and it appears as though it
- * is XkbTranslateKeyCode that is causing the problem. The
- * core X version of XTranslateKey always OR's in ShiftMask
- * and LockMask for mods_rtrn, so this "fix" keeps this behavior
- * and solves the VTS problem.
- */
- if ((xkb->dpy)&&(xkb->dpy->xkb_info)&&
- (xkb->dpy->xkb_info->xlib_ctrls&XkbLC_AlwaysConsumeShiftAndLock)) {
- *mods_rtrn|= (ShiftMask|LockMask);
- }
- }
- return (syms[col]!=NoSymbol);
-}
-
-Status
-XkbRefreshKeyboardMapping(register XkbMapNotifyEvent *event)
-{
- Display *dpy = event->display;
- XkbInfoPtr xkbi;
-
- if (_XkbUnavailable(dpy)) {
- _XRefreshKeyboardMapping((XMappingEvent *)event);
- return Success;
- }
- xkbi= dpy->xkb_info;
-
- if (((event->type&0x7f)-xkbi->codes->first_event)!=XkbEventCode)
- return BadMatch;
- if (event->xkb_type==XkbNewKeyboardNotify) {
- _XkbReloadDpy(dpy);
- return Success;
- }
- if (event->xkb_type==XkbMapNotify) {
- XkbMapChangesRec changes;
- Status rtrn;
-
- if (xkbi->flags&XkbMapPending)
- changes= xkbi->changes;
- else bzero(&changes,sizeof(changes));
- XkbNoteMapChanges(&changes,event,XKB_XLIB_MAP_MASK);
- if ((rtrn=XkbGetMapChanges(dpy,xkbi->desc,&changes))!=Success) {
-#ifdef DEBUG
- fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n");
-#endif
- xkbi->changes= changes;
- }
- else if (xkbi->flags&XkbMapPending) {
- xkbi->flags&= ~XkbMapPending;
- bzero(&xkbi->changes,sizeof(XkbMapChangesRec));
- }
- return rtrn;
- }
- return BadMatch;
-}
-
-int
-XRefreshKeyboardMapping(register XMappingEvent *event)
-{
- XkbEvent *xkbevent = (XkbEvent *)event;
- Display *dpy = event->display;
- XkbMapChangesRec changes;
- XkbInfoPtr xkbi;
-
- /* always do this for input methods, which still use the old keymap */
- (void) _XRefreshKeyboardMapping(event);
-
- if (_XkbUnavailable(dpy))
- return 1;
-
- xkbi = dpy->xkb_info;
-
- if (((event->type&0x7f)-xkbi->codes->first_event)==XkbEventCode)
- return XkbRefreshKeyboardMapping(&xkbevent->map);
-
- if (xkbi->flags&XkbXlibNewKeyboard) {
- _XkbReloadDpy(dpy);
- return 1;
- }
-
- if ((xkbi->flags&XkbMapPending)||(event->request==MappingKeyboard)) {
- if (xkbi->flags&XkbMapPending) {
- changes= xkbi->changes;
- _XkbNoteCoreMapChanges(&changes,event,XKB_XLIB_MAP_MASK);
- }
- else {
- bzero(&changes,sizeof(changes));
- changes.changed= XkbKeySymsMask;
- if (xkbi->desc->min_key_code<xkbi->desc->max_key_code) {
- changes.first_key_sym= xkbi->desc->min_key_code;
- changes.num_key_syms= xkbi->desc->max_key_code-
- xkbi->desc->min_key_code+1;
- }
- else {
- changes.first_key_sym= event->first_keycode;
- changes.num_key_syms= event->count;
- }
- }
-
- if (XkbGetMapChanges(dpy,xkbi->desc, &changes)!=Success) {
-#ifdef DEBUG
- fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n");
- if (changes.changed&XkbKeyTypesMask) {
- int first= changes.first_type;
- int last= changes.first_type+changes.num_types-1;
- fprintf(stderr," types: %d..%d\n",first,last);
- }
- if (changes.changed&XkbKeySymsMask) {
- int first= changes.first_key_sym;
- int last= changes.first_key_sym+changes.num_key_syms-1;
- fprintf(stderr," symbols: %d..%d\n",first,last);
- }
- if (changes.changed&XkbKeyActionsMask) {
- int last,first= changes.first_key_act;
- last= changes.first_key_act+changes.num_key_acts-1;
- fprintf(stderr," acts: %d..%d\n",first,last);
- }
- if (changes.changed&XkbKeyBehaviorsMask) {
- int last,first= changes.first_key_behavior;
- last= first+changes.num_key_behaviors-1;
- fprintf(stderr," behaviors: %d..%d\n",first,last);
- }
- if (changes.changed&XkbVirtualModsMask) {
- fprintf(stderr,"virtual mods: 0x%04x\n",
- changes.vmods);
- }
- if (changes.changed&XkbExplicitComponentsMask) {
- int last,first= changes.first_key_explicit;
- last= first+changes.num_key_explicit-1;
- fprintf(stderr," explicit: %d..%d\n",first,last);
- }
-#endif
- }
- LockDisplay(dpy);
- if (xkbi->flags&XkbMapPending) {
- xkbi->flags&= ~XkbMapPending;
- bzero(&xkbi->changes,sizeof(XkbMapChangesRec));
- }
- UnlockDisplay(dpy);
- }
- if (event->request==MappingModifier) {
- LockDisplay(dpy);
- if (xkbi->desc->map->modmap) {
- _XkbFree(xkbi->desc->map->modmap);
- xkbi->desc->map->modmap= NULL;
- }
- if (dpy->key_bindings) {
- register struct _XKeytrans *p;
- for (p = dpy->key_bindings; p; p = p->next) {
- register int i;
- p->state= 0;
- if (p->mlen>0) {
- for (i = 0; i < p->mlen; i++) {
- p->state|= XkbKeysymToModifiers(dpy,p->modifiers[i]);
- }
- if (p->state) p->state &= AllMods;
- else p->state = AnyModifier;
- }
- }
- }
- UnlockDisplay(dpy);
- }
- return 1;
-}
-
-static int
-_XkbLoadDpy(Display *dpy)
-{
- XkbInfoPtr xkbi;
- unsigned query,oldEvents;
- XkbDescRec *desc;
-
- if (!XkbUseExtension(dpy,NULL,NULL))
- return 0;
-
- xkbi = dpy->xkb_info;
- query = XkbAllClientInfoMask;
- desc = XkbGetMap(dpy,query,XkbUseCoreKbd);
- if (!desc) {
-#ifdef DEBUG
- fprintf(stderr,"Warning! XkbGetMap failed!\n");
-#endif
- return 0;
- }
- LockDisplay(dpy);
- xkbi->desc = desc;
-
- UnlockDisplay(dpy);
- oldEvents= xkbi->selected_events;
- if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) {
- XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbNewKeyboardNotify,
- XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask,
- XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask);
- }
- XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify,
- XkbAllClientInfoMask,XkbAllClientInfoMask);
- LockDisplay(dpy);
- xkbi->selected_events= oldEvents;
- UnlockDisplay(dpy);
- return 1;
-}
-
-void
-_XkbReloadDpy(Display *dpy)
-{
- XkbInfoPtr xkbi;
- XkbDescRec *desc;
- unsigned oldDeviceID;
-
- if (_XkbUnavailable(dpy))
- return;
-
- xkbi = dpy->xkb_info;
- LockDisplay(dpy);
- if (xkbi->desc) {
- oldDeviceID= xkbi->desc->device_spec;
- XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True);
- xkbi->desc= NULL;
- xkbi->flags&= ~(XkbMapPending|XkbXlibNewKeyboard);
- xkbi->changes.changed= 0;
- }
- else oldDeviceID= XkbUseCoreKbd;
- UnlockDisplay(dpy);
- desc = XkbGetMap(dpy,XkbAllClientInfoMask,XkbUseCoreKbd);
- if (!desc)
- return;
- LockDisplay(dpy);
- xkbi->desc = desc;
- UnlockDisplay(dpy);
-
- if (desc->device_spec!=oldDeviceID) {
- /* transfer(?) event masks here */
-#ifdef NOTYET
- unsigned oldEvents;
- oldEvents= xkbi->selected_events;
- XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify,
- XkbAllMapComponentsMask,XkbAllClientInfoMask);
- LockDisplay(dpy);
- xkbi->selected_events= oldEvents;
- UnlockDisplay(dpy);
-#endif
- }
- return;
-}
-
-int
-XkbTranslateKeySym( register Display * dpy,
- register KeySym * sym_rtrn,
- unsigned int mods,
- char * buffer,
- int nbytes,
- int * extra_rtrn)
-{
- register XkbInfoPtr xkb;
- XkbKSToMBFunc cvtr;
- XPointer priv;
- char tmp[4];
- int n;
-
- xkb= dpy->xkb_info;
- if (!xkb->cvt.KSToMB) {
- _XkbGetConverters(_XkbGetCharset(),&xkb->cvt);
- _XkbGetConverters("ISO8859-1",&xkb->latin1cvt);
- }
-
- if (extra_rtrn)
- *extra_rtrn= 0;
-
- if ((buffer==NULL)||(nbytes==0)) {
- buffer= tmp;
- nbytes= 4;
- }
-
- /* see if symbol rebound, if so, return that string. */
- n = XkbLookupKeyBinding(dpy,*sym_rtrn,mods,buffer,nbytes,extra_rtrn);
- if (n)
- return n;
-
- if ( nbytes>0 )
- buffer[0]= '\0';
-
- if ( xkb->cvt.KSToUpper && (mods&LockMask) ) {
- *sym_rtrn = (*xkb->cvt.KSToUpper)(*sym_rtrn);
- }
- if (xkb->xlib_ctrls & XkbLC_ForceLatin1Lookup) {
- cvtr = xkb->latin1cvt.KSToMB;
- priv = xkb->latin1cvt.KSToMBPriv;
- } else {
- cvtr = xkb->cvt.KSToMB;
- priv = xkb->cvt.KSToMBPriv;
- }
-
- n = (*cvtr)(priv,*sym_rtrn,buffer,nbytes,extra_rtrn);
-
- if ((!xkb->cvt.KSToUpper)&&( mods&LockMask )) {
- register int i;
- int change;
- char ch;
- for (i=change=0;i<n;i++) {
- ch= toupper(buffer[i]);
- change= (change||(buffer[i]!=ch));
- buffer[i] = ch;
- }
- if (change) {
- if (n==1)
- *sym_rtrn=(*xkb->cvt.MBToKS)(xkb->cvt.MBToKSPriv,buffer,n,NULL);
- else *sym_rtrn= NoSymbol;
- }
- }
-
- if ( mods&ControlMask ) {
- if ( n==1 ) {
- buffer[0]= XkbToControl(buffer[0]);
- if ( nbytes>1 )
- buffer[1]= '\0';
- return 1;
- }
- if ( nbytes > 0 )
- buffer[0]= '\0';
- return 0;
- }
- return n;
-}
-
-int
-XLookupString ( register XKeyEvent * event,
- char * buffer,
- int nbytes,
- KeySym * keysym,
- XComposeStatus * status)
-{
- KeySym dummy;
- int rtrnLen;
- unsigned int new_mods;
- Display *dpy = event->display;
-
- if (keysym==NULL)
- keysym= &dummy;
- if (!XkbLookupKeySym(dpy,event->keycode,event->state, &new_mods,keysym))
- return 0;
- new_mods= (event->state&(~new_mods));
-
- /* find the group where a symbol can be converted to control one */
- if (new_mods&ControlMask && *keysym > 0x7F &&
- (dpy->xkb_info->xlib_ctrls & XkbLC_ControlFallback)) {
- XKeyEvent tmp_ev = *event;
- KeySym tmp_keysym;
- unsigned int tmp_new_mods;
- if (_XkbUnavailable(dpy)) {
- tmp_ev.state= event->state ^ dpy->mode_switch;
- if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state,
- &tmp_new_mods, &tmp_keysym) &&
- tmp_keysym != NoSymbol && tmp_keysym < 0x80 ) {
- *keysym = tmp_keysym;
- }
- } else {
- int n = XkbKeyNumGroups(dpy->xkb_info->desc, tmp_ev.keycode);
- int i;
- for (i = 0; i < n; i++) {
- if (XkbGroupForCoreState(event->state) == i)
- continue;
- tmp_ev.state= XkbBuildCoreState(tmp_ev.state, i);
- if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state,
- &tmp_new_mods, &tmp_keysym) &&
- tmp_keysym != NoSymbol && tmp_keysym < 0x80 ) {
- *keysym = tmp_keysym;
- new_mods= (event->state&(~tmp_new_mods));
- break;
- }
- }
- }
- }
-
-#ifdef USE_OWN_COMPOSE
- if ( status ) {
- static int been_here= 0;
- if ( !been_here ) {
- XimCompInitTables();
- been_here = 1;
- }
- if ( !XimCompLegalStatus(status) ) {
- status->compose_ptr = NULL;
- status->chars_matched = 0;
- }
- if ( ((status->chars_matched>0)&&(status->compose_ptr!=NULL)) ||
- XimCompIsComposeKey(*keysym,event->keycode,status) ) {
- XimCompRtrn rtrn;
-
- switch (XimCompProcessSym(status,*keysym,&rtrn)) {
- case XIM_COMP_IGNORE:
- break;
- case XIM_COMP_IN_PROGRESS:
- if ( keysym!=NULL )
- *keysym = NoSymbol;
-#ifndef NO_COMPOSE_LED
- if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) {
- XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED,
- True,True,False,NULL);
- }
-#endif
- return 0;
- case XIM_COMP_FAIL:
- {
- static Atom _ComposeFail= None;
- int n = 0, len= 0;
-#ifndef NO_COMPOSE_LED
- if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) {
- XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED,
- True,False,False,NULL);
- }
-#endif
-#ifndef NO_BELL_ON_COMPOSE_FAIL
- if (dpy->xkb_info->xlib_ctrls&XkbLC_BeepOnComposeFail) {
- if (_ComposeFail==None)
- _ComposeFail= XInternAtom(dpy,"ComposeFail",0);
- XkbBell(dpy,event->window,0,_ComposeFail);
- }
-#endif
- for (n=len=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
- if ( nbytes-len > 0 ) {
- len+= XkbTranslateKeySym(dpy,&rtrn.sym[n],new_mods,
- buffer+len,nbytes-len,
- NULL);
- }
- }
- if ( keysym!=NULL ) {
- if ( n==1 ) *keysym = rtrn.sym[0];
- else *keysym = NoSymbol;
- }
- return len;
- }
- case XIM_COMP_SUCCEED:
- {
- int len,n = 0;
-
-#ifndef NO_COMPOSE_LED
- if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) {
- XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED,
- True,False,False,NULL);
- }
-#endif
- *keysym = rtrn.matchSym;
- if ( rtrn.str[0]!='\0' ) {
- strncpy(buffer,rtrn.str,nbytes-1);
- buffer[nbytes-1]= '\0';
- len = (int)strlen(buffer);
- }
- else {
- len = XkbTranslateKeySym(dpy,keysym,new_mods,
- buffer,nbytes,
- NULL);
- }
- for (n=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
- if ( nbytes-len > 0 ) {
- len+= XkbTranslateKeySym(dpy,&rtrn.sym[n],
- event->state,
- buffer+len,nbytes-len,
- NULL);
- }
- }
- return len;
- }
- }
- }
- }
-#endif
-
- /* We *should* use the new_mods (which does not contain any modifiers */
- /* that were used to compute the symbol here, but pre-XKB XLookupString */
- /* did not and we have to remain compatible. Sigh. */
- if (_XkbUnavailable(dpy) ||
- (dpy->xkb_info->xlib_ctrls&XkbLC_ConsumeLookupMods)==0)
- new_mods= event->state;
-
- rtrnLen= XkbLookupKeyBinding(dpy,*keysym,new_mods,buffer,nbytes,NULL);
- if (rtrnLen>0)
- return rtrnLen;
-
- return XkbTranslateKeySym(dpy,keysym,new_mods,buffer,nbytes,NULL);
-}
-
-
-int
-XkbLookupKeyBinding( Display * dpy,
- register KeySym sym,
- unsigned int mods,
- char * buffer,
- int nbytes,
- int * extra_rtrn)
-{
- register struct _XKeytrans *p;
-
- if (extra_rtrn)
- *extra_rtrn= 0;
- for (p = dpy->key_bindings; p; p = p->next) {
- if (((mods & AllMods) == p->state) && (sym == p->key)) {
- int tmp = p->len;
- if (tmp > nbytes) {
- if (extra_rtrn)
- *extra_rtrn= (tmp-nbytes);
- tmp = nbytes;
- }
- memcpy (buffer, p->string, tmp);
- if (tmp < nbytes) buffer[tmp]= '\0';
- return tmp;
- }
- }
- return 0;
-}
-
-char
-XkbToControl( char ch )
-{
- register char c = ch;
-
- if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
- else if (c == '2') c = '\000';
- else if (c >= '3' && c <= '7') c -= ('3' - '\033');
- else if (c == '8') c = '\177';
- else if (c == '/') c = '_' & 0x1F;
- return c;
-}
+/*
+
+Copyright 1985, 1987, 1994, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+ /* the new monsters ate the old ones */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef XKB_IN_SERVER
+#define XkbAllocClientMap SrvXkbAllocClientMap
+#define XkbAllocServerMap SrvXkbAllocServerMap
+#define XkbChangeTypesOfKey SrvXkbChangeTypesOfKey
+#define XkbCopyKeyTypes SrvXkbCopyKeyTypes
+#define XkbFreeClientMap SrvXkbFreeClientMap
+#define XkbFreeServerMap SrvXkbFreeServerMap
+#define XkbKeyTypesForCoreSymbols SrvXkbKeyTypesForCoreSymbols
+#define XkbApplyCompatMapToKey SrvXkbApplyCompatMapToKey
+#define XkbResizeKeyActions SrvXkbResizeKeyActions
+#define XkbResizeKeySyms SrvXkbResizeKeySyms
+#define XkbResizeKeyType SrvXkbResizeKeyType
+#define XkbAllocCompatMap SrvXkbAllocCompatMap
+#define XkbAllocControls SrvXkbAllocControls
+#define XkbAllocIndicatorMaps SrvXkbAllocIndicatorMaps
+#define XkbAllocKeyboard SrvXkbAllocKeyboard
+#define XkbAllocNames SrvXkbAllocNames
+#define XkbFreeCompatMap SrvXkbFreeCompatMap
+#define XkbFreeKeyboard SrvXkbFreeKeyboard
+#define XkbFreeNames SrvXkbFreeNames
+#define XkbLatchModifiers SrvXkbLatchModifiers
+#define XkbLatchGroup SrvXkbLatchGroup
+#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
+#define XkbChangeKeycodeRange SrvXkbChangeKeycodeRange
+#define XkbApplyVirtualModChanges SrvXkbApplyVirtualModChanges
+#endif
+
+#include "XKBlib.h"
+#include <X11/Xlibint.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+#ifdef USE_OWN_COMPOSE
+#define COMPOSE_NO_CONST_MEMBERS
+#include "imComp.h"
+#endif
+
+#define AllMods (ShiftMask|LockMask|ControlMask| \
+ Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)
+
+static int _XkbLoadDpy(
+ Display *dpy
+);
+
+struct _XKeytrans {
+ struct _XKeytrans *next;/* next on list */
+ char *string; /* string to return when the time comes */
+ int len; /* length of string (since NULL is legit)*/
+ KeySym key; /* keysym rebound */
+ unsigned int state; /* modifier state */
+ KeySym *modifiers; /* modifier keysyms you want */
+ int mlen; /* length of modifier list */
+};
+
+KeySym
+XkbKeycodeToKeysym(Display *dpy,
+#if NeedWidePrototypes
+ unsigned int kc,
+#else
+ KeyCode kc,
+#endif
+ int group,
+ int level)
+{
+ XkbDescRec *xkb;
+
+ if (_XkbUnavailable(dpy))
+ return NoSymbol;
+
+ _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
+
+ xkb = dpy->xkb_info->desc;
+ if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code))
+ return NoSymbol;
+
+ if ((group<0)||(level<0)||(group>=XkbKeyNumGroups(xkb,kc)))
+ return NoSymbol;
+ if (level>=XkbKeyGroupWidth(xkb,kc,group)) {
+ /* for compatibility with the core protocol, _always_ allow */
+ /* two symbols in the first two groups. If either of the */
+ /* two is of type ONE_LEVEL, just replicate the first symbol */
+ if ((group>XkbGroup2Index)||(XkbKeyGroupWidth(xkb,kc,group)!=1)||
+ (level!=1)) {
+ return NoSymbol;
+ }
+ level= 0;
+ }
+ return XkbKeySymEntry(xkb,kc,level,group);
+}
+
+KeySym
+XKeycodeToKeysym(Display *dpy,
+#if NeedWidePrototypes
+ unsigned int kc,
+#else
+ KeyCode kc,
+#endif
+ int col)
+{
+ XkbDescRec *xkb;
+
+ if (_XkbUnavailable(dpy))
+ return _XKeycodeToKeysym(dpy, kc, col);
+
+ _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
+
+ xkb = dpy->xkb_info->desc;
+ if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code))
+ return NoSymbol;
+
+ if (col>3) {
+ int lastSym,tmp,nGrp;
+
+ lastSym= 3;
+ nGrp= XkbKeyNumGroups(xkb,kc);
+ if ((nGrp>0)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup1Index))>2)) {
+ if (col<=(lastSym+tmp-2))
+ return XkbKeycodeToKeysym(dpy,kc,XkbGroup1Index,col-lastSym+2);
+ lastSym+= tmp-2;
+ }
+ if ((nGrp>1)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup2Index))>2)) {
+ if (col<=(lastSym+tmp-2))
+ return XkbKeycodeToKeysym(dpy,kc,XkbGroup2Index,col-lastSym+2);
+ lastSym+= tmp-2;
+ }
+ if (nGrp>2) {
+ tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup3Index);
+ if (col<=lastSym+tmp)
+ return XkbKeycodeToKeysym(dpy,kc,XkbGroup3Index,col-lastSym);
+ lastSym+= tmp;
+ }
+ if (nGrp>3) {
+ tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup4Index);
+ if (col<=lastSym+tmp)
+ return XkbKeycodeToKeysym(dpy,kc,XkbGroup4Index,col-lastSym);
+ }
+ return NoSymbol;
+ }
+ return XkbKeycodeToKeysym(dpy,kc,(col>>1),(col&1));
+}
+
+KeyCode
+XKeysymToKeycode(Display *dpy, KeySym ks)
+{
+ register int i, j, gotOne;
+
+ if (_XkbUnavailable(dpy))
+ return _XKeysymToKeycode(dpy,ks);
+ _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
+
+ j= 0;
+ do {
+ register XkbDescRec *xkb = dpy->xkb_info->desc;
+ gotOne= 0;
+ for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) {
+ if ( j<(int)XkbKeyNumSyms(xkb,i) ) {
+ gotOne = 1;
+ if ((XkbKeySym(xkb,i,j)==ks))
+ return i;
+ }
+ }
+ j++;
+ } while (gotOne);
+ return 0;
+}
+
+static int
+_XkbComputeModmap(Display *dpy)
+{
+register XkbDescPtr xkb;
+
+ xkb= dpy->xkb_info->desc;
+ if (XkbGetUpdatedMap(dpy,XkbModifierMapMask,xkb)==Success)
+ return 1;
+ return 0;
+}
+
+unsigned
+XkbKeysymToModifiers(Display *dpy,KeySym ks)
+{
+ XkbDescRec *xkb;
+ register int i,j;
+ register KeySym *pSyms;
+ CARD8 mods;
+
+ if (_XkbUnavailable(dpy))
+ return _XKeysymToModifiers(dpy,ks);
+ _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
+
+ if (_XkbNeedModmap(dpy->xkb_info)&&(!_XkbComputeModmap(dpy)))
+ return _XKeysymToModifiers(dpy,ks);
+
+ xkb= dpy->xkb_info->desc;
+ mods= 0;
+ for (i = xkb->min_key_code; i <= (int)xkb->max_key_code; i++) {
+ pSyms= XkbKeySymsPtr(xkb,i);
+ for (j=XkbKeyNumSyms(xkb,i)-1;j>=0;j--) {
+ if (pSyms[j]==ks) {
+ mods|= xkb->map->modmap[i];
+ break;
+ }
+ }
+ }
+ return mods;
+}
+
+KeySym
+XLookupKeysym(register XKeyEvent *event, int col)
+{
+ Display *dpy = event->display;
+ if (_XkbUnavailable(dpy))
+ return _XLookupKeysym(event, col);
+ _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
+ return XKeycodeToKeysym(dpy, event->keycode, col);
+}
+
+ /*
+ * Not a public entry point -- XkbTranslateKey is an obsolete name
+ * that is preserved here so that functions linked against the old
+ * version will continue to work in a shared library environment.
+ */
+int
+XkbTranslateKey( register Display * dpy,
+ KeyCode key,
+ register unsigned int mods,
+ unsigned int * mods_rtrn,
+ KeySym * keysym_rtrn);
+int
+XkbTranslateKey( register Display * dpy,
+ KeyCode key,
+ register unsigned int mods,
+ unsigned int * mods_rtrn,
+ KeySym * keysym_rtrn)
+{
+ return XkbLookupKeySym(dpy,key,mods,mods_rtrn,keysym_rtrn);
+}
+
+Bool
+XkbLookupKeySym( register Display * dpy,
+ KeyCode key,
+ register unsigned int mods,
+ unsigned int * mods_rtrn,
+ KeySym * keysym_rtrn)
+{
+ if (_XkbUnavailable(dpy))
+ return _XTranslateKey(dpy, key, mods, mods_rtrn, keysym_rtrn);
+ _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
+ return XkbTranslateKeyCode(dpy->xkb_info->desc,key,mods,mods_rtrn,
+ keysym_rtrn);
+}
+
+Bool
+XkbTranslateKeyCode( register XkbDescPtr xkb,
+ KeyCode key,
+ register unsigned int mods,
+ unsigned int * mods_rtrn,
+ KeySym * keysym_rtrn)
+{
+ XkbKeyTypeRec *type;
+ int col,nKeyGroups;
+ unsigned preserve,effectiveGroup;
+ KeySym *syms;
+
+ if (mods_rtrn!=NULL)
+ *mods_rtrn = 0;
+
+ nKeyGroups= XkbKeyNumGroups(xkb,key);
+ if ((!XkbKeycodeInRange(xkb,key))||(nKeyGroups==0)) {
+ if (keysym_rtrn!=NULL)
+ *keysym_rtrn = NoSymbol;
+ return False;
+ }
+
+ syms = XkbKeySymsPtr(xkb,key);
+
+ /* find the offset of the effective group */
+ col = 0;
+ effectiveGroup= XkbGroupForCoreState(mods);
+ if ( effectiveGroup>=nKeyGroups ) {
+ unsigned groupInfo= XkbKeyGroupInfo(xkb,key);
+ switch (XkbOutOfRangeGroupAction(groupInfo)) {
+ default:
+ effectiveGroup %= nKeyGroups;
+ break;
+ case XkbClampIntoRange:
+ effectiveGroup = nKeyGroups-1;
+ break;
+ case XkbRedirectIntoRange:
+ effectiveGroup = XkbOutOfRangeGroupNumber(groupInfo);
+ if (effectiveGroup>=nKeyGroups)
+ effectiveGroup= 0;
+ break;
+ }
+ }
+ col= effectiveGroup*XkbKeyGroupsWidth(xkb,key);
+ type = XkbKeyKeyType(xkb,key,effectiveGroup);
+
+ preserve= 0;
+ if (type->map) { /* find the column (shift level) within the group */
+ register int i;
+ register XkbKTMapEntryPtr entry;
+ for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
+ if ((entry->active)&&((mods&type->mods.mask)==entry->mods.mask)) {
+ col+= entry->level;
+ if (type->preserve)
+ preserve= type->preserve[i].mask;
+ break;
+ }
+ }
+ }
+
+ if (keysym_rtrn!=NULL)
+ *keysym_rtrn= syms[col];
+ if (mods_rtrn) {
+ *mods_rtrn= type->mods.mask&(~preserve);
+ /* The Motif VTS doesn't get the help callback called if help
+ * is bound to Shift+<whatever>, and it appears as though it
+ * is XkbTranslateKeyCode that is causing the problem. The
+ * core X version of XTranslateKey always OR's in ShiftMask
+ * and LockMask for mods_rtrn, so this "fix" keeps this behavior
+ * and solves the VTS problem.
+ */
+ if ((xkb->dpy)&&(xkb->dpy->xkb_info)&&
+ (xkb->dpy->xkb_info->xlib_ctrls&XkbLC_AlwaysConsumeShiftAndLock)) {
+ *mods_rtrn|= (ShiftMask|LockMask);
+ }
+ }
+ return (syms[col]!=NoSymbol);
+}
+
+Status
+XkbRefreshKeyboardMapping(register XkbMapNotifyEvent *event)
+{
+ Display *dpy = event->display;
+ XkbInfoPtr xkbi;
+
+ if (_XkbUnavailable(dpy)) {
+ _XRefreshKeyboardMapping((XMappingEvent *)event);
+ return Success;
+ }
+ xkbi= dpy->xkb_info;
+
+ if (((event->type&0x7f)-xkbi->codes->first_event)!=XkbEventCode)
+ return BadMatch;
+ if (event->xkb_type==XkbNewKeyboardNotify) {
+ _XkbReloadDpy(dpy);
+ return Success;
+ }
+ if (event->xkb_type==XkbMapNotify) {
+ XkbMapChangesRec changes;
+ Status rtrn;
+
+ if (xkbi->flags&XkbMapPending)
+ changes= xkbi->changes;
+ else bzero(&changes,sizeof(changes));
+ XkbNoteMapChanges(&changes,event,XKB_XLIB_MAP_MASK);
+ if ((rtrn=XkbGetMapChanges(dpy,xkbi->desc,&changes))!=Success) {
+#ifdef DEBUG
+ fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n");
+#endif
+ xkbi->changes= changes;
+ }
+ else if (xkbi->flags&XkbMapPending) {
+ xkbi->flags&= ~XkbMapPending;
+ bzero(&xkbi->changes,sizeof(XkbMapChangesRec));
+ }
+ return rtrn;
+ }
+ return BadMatch;
+}
+
+int
+XRefreshKeyboardMapping(register XMappingEvent *event)
+{
+ XkbEvent *xkbevent = (XkbEvent *)event;
+ Display *dpy = event->display;
+ XkbMapChangesRec changes;
+ XkbInfoPtr xkbi;
+
+ /* always do this for input methods, which still use the old keymap */
+ (void) _XRefreshKeyboardMapping(event);
+
+ if (_XkbUnavailable(dpy))
+ return 1;
+
+ xkbi = dpy->xkb_info;
+
+ if (((event->type&0x7f)-xkbi->codes->first_event)==XkbEventCode)
+ return XkbRefreshKeyboardMapping(&xkbevent->map);
+
+ if (xkbi->flags&XkbXlibNewKeyboard) {
+ _XkbReloadDpy(dpy);
+ return 1;
+ }
+
+ if ((xkbi->flags&XkbMapPending)||(event->request==MappingKeyboard)) {
+ if (xkbi->flags&XkbMapPending) {
+ changes= xkbi->changes;
+ _XkbNoteCoreMapChanges(&changes,event,XKB_XLIB_MAP_MASK);
+ }
+ else {
+ bzero(&changes,sizeof(changes));
+ changes.changed= XkbKeySymsMask;
+ if (xkbi->desc->min_key_code<xkbi->desc->max_key_code) {
+ changes.first_key_sym= xkbi->desc->min_key_code;
+ changes.num_key_syms= xkbi->desc->max_key_code-
+ xkbi->desc->min_key_code+1;
+ }
+ else {
+ changes.first_key_sym= event->first_keycode;
+ changes.num_key_syms= event->count;
+ }
+ }
+
+ if (XkbGetMapChanges(dpy,xkbi->desc, &changes)!=Success) {
+#ifdef DEBUG
+ fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n");
+ if (changes.changed&XkbKeyTypesMask) {
+ int first= changes.first_type;
+ int last= changes.first_type+changes.num_types-1;
+ fprintf(stderr," types: %d..%d\n",first,last);
+ }
+ if (changes.changed&XkbKeySymsMask) {
+ int first= changes.first_key_sym;
+ int last= changes.first_key_sym+changes.num_key_syms-1;
+ fprintf(stderr," symbols: %d..%d\n",first,last);
+ }
+ if (changes.changed&XkbKeyActionsMask) {
+ int last,first= changes.first_key_act;
+ last= changes.first_key_act+changes.num_key_acts-1;
+ fprintf(stderr," acts: %d..%d\n",first,last);
+ }
+ if (changes.changed&XkbKeyBehaviorsMask) {
+ int last,first= changes.first_key_behavior;
+ last= first+changes.num_key_behaviors-1;
+ fprintf(stderr," behaviors: %d..%d\n",first,last);
+ }
+ if (changes.changed&XkbVirtualModsMask) {
+ fprintf(stderr,"virtual mods: 0x%04x\n",
+ changes.vmods);
+ }
+ if (changes.changed&XkbExplicitComponentsMask) {
+ int last,first= changes.first_key_explicit;
+ last= first+changes.num_key_explicit-1;
+ fprintf(stderr," explicit: %d..%d\n",first,last);
+ }
+#endif
+ }
+ LockDisplay(dpy);
+ if (xkbi->flags&XkbMapPending) {
+ xkbi->flags&= ~XkbMapPending;
+ bzero(&xkbi->changes,sizeof(XkbMapChangesRec));
+ }
+ UnlockDisplay(dpy);
+ }
+ if (event->request==MappingModifier) {
+ LockDisplay(dpy);
+ if (xkbi->desc->map->modmap) {
+ _XkbFree(xkbi->desc->map->modmap);
+ xkbi->desc->map->modmap= NULL;
+ }
+ if (dpy->key_bindings) {
+ register struct _XKeytrans *p;
+ for (p = dpy->key_bindings; p; p = p->next) {
+ register int i;
+ p->state= 0;
+ if (p->mlen>0) {
+ for (i = 0; i < p->mlen; i++) {
+ p->state|= XkbKeysymToModifiers(dpy,p->modifiers[i]);
+ }
+ if (p->state) p->state &= AllMods;
+ else p->state = AnyModifier;
+ }
+ }
+ }
+ UnlockDisplay(dpy);
+ }
+ return 1;
+}
+
+static int
+_XkbLoadDpy(Display *dpy)
+{
+ XkbInfoPtr xkbi;
+ unsigned query,oldEvents;
+ XkbDescRec *desc;
+
+ if (!XkbUseExtension(dpy,NULL,NULL))
+ return 0;
+
+ xkbi = dpy->xkb_info;
+ query = XkbAllClientInfoMask;
+ desc = XkbGetMap(dpy,query,XkbUseCoreKbd);
+ if (!desc) {
+#ifdef DEBUG
+ fprintf(stderr,"Warning! XkbGetMap failed!\n");
+#endif
+ return 0;
+ }
+ LockDisplay(dpy);
+ xkbi->desc = desc;
+
+ UnlockDisplay(dpy);
+ oldEvents= xkbi->selected_events;
+ if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) {
+ XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbNewKeyboardNotify,
+ XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask,
+ XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask);
+ }
+ XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify,
+ XkbAllClientInfoMask,XkbAllClientInfoMask);
+ LockDisplay(dpy);
+ xkbi->selected_events= oldEvents;
+ UnlockDisplay(dpy);
+ return 1;
+}
+
+void
+_XkbReloadDpy(Display *dpy)
+{
+ XkbInfoPtr xkbi;
+ XkbDescRec *desc;
+ unsigned oldDeviceID;
+
+ if (_XkbUnavailable(dpy))
+ return;
+
+ xkbi = dpy->xkb_info;
+ LockDisplay(dpy);
+ if (xkbi->desc) {
+ oldDeviceID= xkbi->desc->device_spec;
+ XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True);
+ xkbi->desc= NULL;
+ xkbi->flags&= ~(XkbMapPending|XkbXlibNewKeyboard);
+ xkbi->changes.changed= 0;
+ }
+ else oldDeviceID= XkbUseCoreKbd;
+ UnlockDisplay(dpy);
+ desc = XkbGetMap(dpy,XkbAllClientInfoMask,XkbUseCoreKbd);
+ if (!desc)
+ return;
+ LockDisplay(dpy);
+ xkbi->desc = desc;
+ UnlockDisplay(dpy);
+
+ if (desc->device_spec!=oldDeviceID) {
+ /* transfer(?) event masks here */
+#ifdef NOTYET
+ unsigned oldEvents;
+ oldEvents= xkbi->selected_events;
+ XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify,
+ XkbAllMapComponentsMask,XkbAllClientInfoMask);
+ LockDisplay(dpy);
+ xkbi->selected_events= oldEvents;
+ UnlockDisplay(dpy);
+#endif
+ }
+ return;
+}
+
+int
+XkbTranslateKeySym( register Display * dpy,
+ register KeySym * sym_rtrn,
+ unsigned int mods,
+ char * buffer,
+ int nbytes,
+ int * extra_rtrn)
+{
+ register XkbInfoPtr xkb;
+ XkbKSToMBFunc cvtr;
+ XPointer priv;
+ char tmp[4];
+ int n;
+
+ xkb= dpy->xkb_info;
+ if (!xkb->cvt.KSToMB) {
+ _XkbGetConverters(_XkbGetCharset(),&xkb->cvt);
+ _XkbGetConverters("ISO8859-1",&xkb->latin1cvt);
+ }
+
+ if (extra_rtrn)
+ *extra_rtrn= 0;
+
+ if ((buffer==NULL)||(nbytes==0)) {
+ buffer= tmp;
+ nbytes= 4;
+ }
+
+ /* see if symbol rebound, if so, return that string. */
+ n = XkbLookupKeyBinding(dpy,*sym_rtrn,mods,buffer,nbytes,extra_rtrn);
+ if (n)
+ return n;
+
+ if ( nbytes>0 )
+ buffer[0]= '\0';
+
+ if ( xkb->cvt.KSToUpper && (mods&LockMask) ) {
+ *sym_rtrn = (*xkb->cvt.KSToUpper)(*sym_rtrn);
+ }
+ if (xkb->xlib_ctrls & XkbLC_ForceLatin1Lookup) {
+ cvtr = xkb->latin1cvt.KSToMB;
+ priv = xkb->latin1cvt.KSToMBPriv;
+ } else {
+ cvtr = xkb->cvt.KSToMB;
+ priv = xkb->cvt.KSToMBPriv;
+ }
+
+ n = (*cvtr)(priv,*sym_rtrn,buffer,nbytes,extra_rtrn);
+
+ if ((!xkb->cvt.KSToUpper)&&( mods&LockMask )) {
+ register int i;
+ int change;
+ char ch;
+ for (i=change=0;i<n;i++) {
+ ch= toupper(buffer[i]);
+ change= (change||(buffer[i]!=ch));
+ buffer[i] = ch;
+ }
+ if (change) {
+ if (n==1)
+ *sym_rtrn=(*xkb->cvt.MBToKS)(xkb->cvt.MBToKSPriv,buffer,n,NULL);
+ else *sym_rtrn= NoSymbol;
+ }
+ }
+
+ if ( mods&ControlMask ) {
+ if ( n==1 ) {
+ buffer[0]= XkbToControl(buffer[0]);
+ if ( nbytes>1 )
+ buffer[1]= '\0';
+ return 1;
+ }
+ if ( nbytes > 0 )
+ buffer[0]= '\0';
+ return 0;
+ }
+ return n;
+}
+
+int
+XLookupString ( register XKeyEvent * event,
+ char * buffer,
+ int nbytes,
+ KeySym * keysym,
+ XComposeStatus * status)
+{
+ KeySym dummy;
+ int rtrnLen;
+ unsigned int new_mods;
+ Display *dpy = event->display;
+
+ if (keysym==NULL)
+ keysym= &dummy;
+ if (!XkbLookupKeySym(dpy,event->keycode,event->state, &new_mods,keysym))
+ return 0;
+ new_mods= (event->state&(~new_mods));
+
+ /* find the group where a symbol can be converted to control one */
+ if (new_mods&ControlMask && *keysym > 0x7F &&
+ (dpy->xkb_info->xlib_ctrls & XkbLC_ControlFallback)) {
+ XKeyEvent tmp_ev = *event;
+ KeySym tmp_keysym;
+ unsigned int tmp_new_mods;
+ if (_XkbUnavailable(dpy)) {
+ tmp_ev.state= event->state ^ dpy->mode_switch;
+ if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state,
+ &tmp_new_mods, &tmp_keysym) &&
+ tmp_keysym != NoSymbol && tmp_keysym < 0x80 ) {
+ *keysym = tmp_keysym;
+ }
+ } else {
+ int n = XkbKeyNumGroups(dpy->xkb_info->desc, tmp_ev.keycode);
+ int i;
+ for (i = 0; i < n; i++) {
+ if (XkbGroupForCoreState(event->state) == i)
+ continue;
+ tmp_ev.state= XkbBuildCoreState(tmp_ev.state, i);
+ if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state,
+ &tmp_new_mods, &tmp_keysym) &&
+ tmp_keysym != NoSymbol && tmp_keysym < 0x80 ) {
+ *keysym = tmp_keysym;
+ new_mods= (event->state&(~tmp_new_mods));
+ break;
+ }
+ }
+ }
+ }
+
+#ifdef USE_OWN_COMPOSE
+ if ( status ) {
+ static int been_here= 0;
+ if ( !been_here ) {
+ XimCompInitTables();
+ been_here = 1;
+ }
+ if ( !XimCompLegalStatus(status) ) {
+ status->compose_ptr = NULL;
+ status->chars_matched = 0;
+ }
+ if ( ((status->chars_matched>0)&&(status->compose_ptr!=NULL)) ||
+ XimCompIsComposeKey(*keysym,event->keycode,status) ) {
+ XimCompRtrn rtrn;
+
+ switch (XimCompProcessSym(status,*keysym,&rtrn)) {
+ case XIM_COMP_IGNORE:
+ break;
+ case XIM_COMP_IN_PROGRESS:
+ if ( keysym!=NULL )
+ *keysym = NoSymbol;
+#ifndef NO_COMPOSE_LED
+ if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) {
+ XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED,
+ True,True,False,NULL);
+ }
+#endif
+ return 0;
+ case XIM_COMP_FAIL:
+ {
+ static Atom _ComposeFail= None;
+ int n = 0, len= 0;
+#ifndef NO_COMPOSE_LED
+ if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) {
+ XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED,
+ True,False,False,NULL);
+ }
+#endif
+#ifndef NO_BELL_ON_COMPOSE_FAIL
+ if (dpy->xkb_info->xlib_ctrls&XkbLC_BeepOnComposeFail) {
+ if (_ComposeFail==None)
+ _ComposeFail= XInternAtom(dpy,"ComposeFail",0);
+ XkbBell(dpy,event->window,0,_ComposeFail);
+ }
+#endif
+ for (n=len=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
+ if ( nbytes-len > 0 ) {
+ len+= XkbTranslateKeySym(dpy,&rtrn.sym[n],new_mods,
+ buffer+len,nbytes-len,
+ NULL);
+ }
+ }
+ if ( keysym!=NULL ) {
+ if ( n==1 ) *keysym = rtrn.sym[0];
+ else *keysym = NoSymbol;
+ }
+ return len;
+ }
+ case XIM_COMP_SUCCEED:
+ {
+ int len,n = 0;
+
+#ifndef NO_COMPOSE_LED
+ if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) {
+ XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED,
+ True,False,False,NULL);
+ }
+#endif
+ *keysym = rtrn.matchSym;
+ if ( rtrn.str[0]!='\0' ) {
+ strncpy(buffer,rtrn.str,nbytes-1);
+ buffer[nbytes-1]= '\0';
+ len = (int)strlen(buffer);
+ }
+ else {
+ len = XkbTranslateKeySym(dpy,keysym,new_mods,
+ buffer,nbytes,
+ NULL);
+ }
+ for (n=0;rtrn.sym[n]!=XK_VoidSymbol;n++) {
+ if ( nbytes-len > 0 ) {
+ len+= XkbTranslateKeySym(dpy,&rtrn.sym[n],
+ event->state,
+ buffer+len,nbytes-len,
+ NULL);
+ }
+ }
+ return len;
+ }
+ }
+ }
+ }
+#endif
+
+ /* We *should* use the new_mods (which does not contain any modifiers */
+ /* that were used to compute the symbol here, but pre-XKB XLookupString */
+ /* did not and we have to remain compatible. Sigh. */
+ if (_XkbUnavailable(dpy) ||
+ (dpy->xkb_info->xlib_ctrls&XkbLC_ConsumeLookupMods)==0)
+ new_mods= event->state;
+
+ rtrnLen= XkbLookupKeyBinding(dpy,*keysym,new_mods,buffer,nbytes,NULL);
+ if (rtrnLen>0)
+ return rtrnLen;
+
+ return XkbTranslateKeySym(dpy,keysym,new_mods,buffer,nbytes,NULL);
+}
+
+
+int
+XkbLookupKeyBinding( Display * dpy,
+ register KeySym sym,
+ unsigned int mods,
+ char * buffer,
+ int nbytes,
+ int * extra_rtrn)
+{
+ register struct _XKeytrans *p;
+
+ if (extra_rtrn)
+ *extra_rtrn= 0;
+ for (p = dpy->key_bindings; p; p = p->next) {
+ if (((mods & AllMods) == p->state) && (sym == p->key)) {
+ int tmp = p->len;
+ if (tmp > nbytes) {
+ if (extra_rtrn)
+ *extra_rtrn= (tmp-nbytes);
+ tmp = nbytes;
+ }
+ memcpy (buffer, p->string, tmp);
+ if (tmp < nbytes) buffer[tmp]= '\0';
+ return tmp;
+ }
+ }
+ return 0;
+}
+
+char
+XkbToControl( char ch )
+{
+ register char c = ch;
+
+ if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
+ else if (c == '2') c = '\000';
+ else if (c >= '3' && c <= '7') c -= ('3' - '\033');
+ else if (c == '8') c = '\177';
+ else if (c == '/') c = '_' & 0x1F;
+ return c;
+}
diff --git a/libX11/src/xkb/XKBCompat.c b/libX11/src/xkb/XKBCompat.c
index ba7f6864f..6d110b167 100644
--- a/libX11/src/xkb/XKBCompat.c
+++ b/libX11/src/xkb/XKBCompat.c
@@ -1,249 +1,247 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#define NEED_MAP_READERS
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-Status
-_XkbReadGetCompatMapReply( Display * dpy,
- xkbGetCompatMapReply * rep,
- XkbDescPtr xkb,
- int * nread_rtrn)
-{
-register int i;
-XkbReadBufferRec buf;
-
- if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
- return BadAlloc;
-
- if (nread_rtrn)
- *nread_rtrn= (int)rep->length*4;
-
- i= rep->firstSI+rep->nSI;
- if ((!xkb->compat)&&
- (XkbAllocCompatMap(xkb,XkbAllCompatMask,i)!=Success))
- return BadAlloc;
-
- if (rep->nSI!=0) {
- XkbSymInterpretRec *syms;
- xkbSymInterpretWireDesc *wire;
-
- wire= (xkbSymInterpretWireDesc *)_XkbGetReadBufferPtr(&buf,
- rep->nSI*SIZEOF(xkbSymInterpretWireDesc));
- if (wire==NULL)
- goto BAILOUT;
- syms= &xkb->compat->sym_interpret[rep->firstSI];
-
- for (i=0;i<rep->nSI;i++,syms++,wire++) {
- syms->sym= wire->sym;
- syms->mods= wire->mods;
- syms->match= wire->match;
- syms->virtual_mod= wire->virtualMod;
- syms->flags= wire->flags;
- syms->act= *((XkbAnyAction *)&wire->act);
- }
- xkb->compat->num_si+= rep->nSI;
- }
-
- if (rep->groups&XkbAllGroupsMask) {
- register unsigned bit,nGroups;
- xkbModsWireDesc * wire;
- for (i=0,nGroups=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
- if (rep->groups&bit)
- nGroups++;
- }
- wire= (xkbModsWireDesc *)_XkbGetReadBufferPtr(&buf,
- nGroups*SIZEOF(xkbModsWireDesc));
- if (wire==NULL)
- goto BAILOUT;
- for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
- if ((rep->groups&bit)==0)
- continue;
- xkb->compat->groups[i].mask= wire->mask;
- xkb->compat->groups[i].real_mods= wire->realMods;
- xkb->compat->groups[i].vmods= wire->virtualMods;
- wire++;
- }
- }
- i= _XkbFreeReadBuffer(&buf);
- if (i)
- fprintf(stderr,"CompatMapReply! Bad length (%d extra bytes)\n",i);
- if (i || buf.error)
- return BadLength;
- return Success;
-BAILOUT:
- _XkbFreeReadBuffer(&buf);
- return BadLength;
-}
-
-Status
-XkbGetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb)
-{
- register xkbGetCompatMapReq *req;
- xkbGetCompatMapReply rep;
- Status status;
- XkbInfoPtr xkbi;
-
- if ( (!dpy) || (!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
- ((xkb->dpy!=NULL)&&(xkb->dpy!=dpy)) ||
- (!dpy->xkb_info && (!XkbUseExtension(dpy,NULL,NULL))))
- return BadAccess;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbGetCompatMap, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetCompatMap;
- req->deviceSpec = xkb->device_spec;
- if (which&XkbSymInterpMask)
- req->getAllSI= True;
- else req->getAllSI= False;
- req->firstSI= req->nSI= 0;
-
- if (which&XkbGroupCompatMask)
- req->groups= XkbAllGroupsMask;
- else req->groups= 0;
-
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadLength;
- }
- if (xkb->dpy==NULL)
- xkb->dpy= dpy;
- if (xkb->device_spec==XkbUseCoreKbd)
- xkb->device_spec= rep.deviceID;
-
- status = _XkbReadGetCompatMapReply(dpy,&rep,xkb,NULL);
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-static Bool
-_XkbWriteSetCompatMap(Display *dpy,xkbSetCompatMapReq *req,XkbDescPtr xkb)
-{
-CARD16 firstSI;
-CARD16 nSI;
-int size;
-register int i,nGroups;
-register unsigned bit;
-unsigned groups;
-char * buf;
-
- firstSI = req->firstSI;
- nSI = req->nSI;
- size= nSI*SIZEOF(xkbSymInterpretWireDesc);
- nGroups= 0;
- groups= req->groups;
- if (groups&XkbAllGroupsMask) {
- for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
- if (groups&bit)
- nGroups++;
- }
- size+= SIZEOF(xkbModsWireDesc)*nGroups;
- }
- req->length+= size/4;
- BufAlloc(char *,buf,size);
- if (!buf)
- return False;
-
- if (nSI) {
- XkbSymInterpretPtr sym= &xkb->compat->sym_interpret[firstSI];
- xkbSymInterpretWireDesc *wire= (xkbSymInterpretWireDesc *)buf;
- for (i=0;i<nSI;i++,wire++,sym++) {
- wire->sym= (CARD32)sym->sym;
- wire->mods= sym->mods;
- wire->match= sym->match;
- wire->flags= sym->flags;
- wire->virtualMod= sym->virtual_mod;
- memcpy(&wire->act,&sym->act,sz_xkbActionWireDesc);
- }
- buf+= nSI*SIZEOF(xkbSymInterpretWireDesc);
- }
- if (groups&XkbAllGroupsMask) {
- xkbModsWireDesc * out;
-
- out= (xkbModsWireDesc *)buf;
- for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
- if ((groups&bit)!=0) {
- out->mask= xkb->compat->groups[i].mask;
- out->realMods= xkb->compat->groups[i].real_mods;
- out->virtualMods= xkb->compat->groups[i].vmods;
- out++;
- }
- }
- buf+= nGroups*SIZEOF(xkbModsWireDesc);
- }
- return True;
-}
-
-Bool
-XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions)
-{
- register xkbSetCompatMapReq *req;
- Status ok;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) || (dpy!=xkb->dpy) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- if ((!xkb->compat) ||
- ((which&XkbSymInterpMask)&&(!xkb->compat->sym_interpret)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetCompatMap, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSetCompatMap;
- req->deviceSpec = xkb->device_spec;
- req->recomputeActions = updateActions;
- if (which&XkbSymInterpMask) {
- req->truncateSI = True;
- req->firstSI= 0;
- req->nSI= xkb->compat->num_si;
- }
- else {
- req->truncateSI = False;
- req->firstSI= 0;
- req->nSI= 0;
- }
- if (which&XkbGroupCompatMask)
- req->groups= XkbAllGroupsMask;
- else req->groups= 0;
- ok= _XkbWriteSetCompatMap(dpy,req,xkb);
- UnlockDisplay(dpy);
- SyncHandle();
- return ok;
-}
-
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 <stdio.h>
+#define NEED_MAP_READERS
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+Status
+_XkbReadGetCompatMapReply( Display * dpy,
+ xkbGetCompatMapReply * rep,
+ XkbDescPtr xkb,
+ int * nread_rtrn)
+{
+register int i;
+XkbReadBufferRec buf;
+
+ if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
+ return BadAlloc;
+
+ if (nread_rtrn)
+ *nread_rtrn= (int)rep->length*4;
+
+ i= rep->firstSI+rep->nSI;
+ if ((!xkb->compat)&&
+ (XkbAllocCompatMap(xkb,XkbAllCompatMask,i)!=Success))
+ return BadAlloc;
+
+ if (rep->nSI!=0) {
+ XkbSymInterpretRec *syms;
+ xkbSymInterpretWireDesc *wire;
+
+ wire= (xkbSymInterpretWireDesc *)_XkbGetReadBufferPtr(&buf,
+ rep->nSI*SIZEOF(xkbSymInterpretWireDesc));
+ if (wire==NULL)
+ goto BAILOUT;
+ syms= &xkb->compat->sym_interpret[rep->firstSI];
+
+ for (i=0;i<rep->nSI;i++,syms++,wire++) {
+ syms->sym= wire->sym;
+ syms->mods= wire->mods;
+ syms->match= wire->match;
+ syms->virtual_mod= wire->virtualMod;
+ syms->flags= wire->flags;
+ syms->act= *((XkbAnyAction *)&wire->act);
+ }
+ xkb->compat->num_si+= rep->nSI;
+ }
+
+ if (rep->groups&XkbAllGroupsMask) {
+ register unsigned bit,nGroups;
+ xkbModsWireDesc * wire;
+ for (i=0,nGroups=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
+ if (rep->groups&bit)
+ nGroups++;
+ }
+ wire= (xkbModsWireDesc *)_XkbGetReadBufferPtr(&buf,
+ nGroups*SIZEOF(xkbModsWireDesc));
+ if (wire==NULL)
+ goto BAILOUT;
+ for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
+ if ((rep->groups&bit)==0)
+ continue;
+ xkb->compat->groups[i].mask= wire->mask;
+ xkb->compat->groups[i].real_mods= wire->realMods;
+ xkb->compat->groups[i].vmods= wire->virtualMods;
+ wire++;
+ }
+ }
+ i= _XkbFreeReadBuffer(&buf);
+ if (i)
+ fprintf(stderr,"CompatMapReply! Bad length (%d extra bytes)\n",i);
+ if (i || buf.error)
+ return BadLength;
+ return Success;
+BAILOUT:
+ _XkbFreeReadBuffer(&buf);
+ return BadLength;
+}
+
+Status
+XkbGetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb)
+{
+ register xkbGetCompatMapReq *req;
+ xkbGetCompatMapReply rep;
+ Status status;
+ XkbInfoPtr xkbi;
+
+ if ( (!dpy) || (!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
+ ((xkb->dpy!=NULL)&&(xkb->dpy!=dpy)) ||
+ (!dpy->xkb_info && (!XkbUseExtension(dpy,NULL,NULL))))
+ return BadAccess;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbGetCompatMap, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetCompatMap;
+ req->deviceSpec = xkb->device_spec;
+ if (which&XkbSymInterpMask)
+ req->getAllSI= True;
+ else req->getAllSI= False;
+ req->firstSI= req->nSI= 0;
+
+ if (which&XkbGroupCompatMask)
+ req->groups= XkbAllGroupsMask;
+ else req->groups= 0;
+
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadLength;
+ }
+ if (xkb->dpy==NULL)
+ xkb->dpy= dpy;
+ if (xkb->device_spec==XkbUseCoreKbd)
+ xkb->device_spec= rep.deviceID;
+
+ status = _XkbReadGetCompatMapReply(dpy,&rep,xkb,NULL);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+static Bool
+_XkbWriteSetCompatMap(Display *dpy,xkbSetCompatMapReq *req,XkbDescPtr xkb)
+{
+CARD16 firstSI;
+CARD16 nSI;
+int size;
+register int i,nGroups;
+register unsigned bit;
+unsigned groups;
+char * buf;
+
+ firstSI = req->firstSI;
+ nSI = req->nSI;
+ size= nSI*SIZEOF(xkbSymInterpretWireDesc);
+ nGroups= 0;
+ groups= req->groups;
+ if (groups&XkbAllGroupsMask) {
+ for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
+ if (groups&bit)
+ nGroups++;
+ }
+ size+= SIZEOF(xkbModsWireDesc)*nGroups;
+ }
+ req->length+= size/4;
+ BufAlloc(char *,buf,size);
+ if (!buf)
+ return False;
+
+ if (nSI) {
+ XkbSymInterpretPtr sym= &xkb->compat->sym_interpret[firstSI];
+ xkbSymInterpretWireDesc *wire= (xkbSymInterpretWireDesc *)buf;
+ for (i=0;i<nSI;i++,wire++,sym++) {
+ wire->sym= (CARD32)sym->sym;
+ wire->mods= sym->mods;
+ wire->match= sym->match;
+ wire->flags= sym->flags;
+ wire->virtualMod= sym->virtual_mod;
+ memcpy(&wire->act,&sym->act,sz_xkbActionWireDesc);
+ }
+ buf+= nSI*SIZEOF(xkbSymInterpretWireDesc);
+ }
+ if (groups&XkbAllGroupsMask) {
+ xkbModsWireDesc * out;
+
+ out= (xkbModsWireDesc *)buf;
+ for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
+ if ((groups&bit)!=0) {
+ out->mask= xkb->compat->groups[i].mask;
+ out->realMods= xkb->compat->groups[i].real_mods;
+ out->virtualMods= xkb->compat->groups[i].vmods;
+ out++;
+ }
+ }
+ buf+= nGroups*SIZEOF(xkbModsWireDesc);
+ }
+ return True;
+}
+
+Bool
+XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions)
+{
+ register xkbSetCompatMapReq *req;
+ Status ok;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) || (dpy!=xkb->dpy) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ if ((!xkb->compat) ||
+ ((which&XkbSymInterpMask)&&(!xkb->compat->sym_interpret)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetCompatMap, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSetCompatMap;
+ req->deviceSpec = xkb->device_spec;
+ req->recomputeActions = updateActions;
+ if (which&XkbSymInterpMask) {
+ req->truncateSI = True;
+ req->firstSI= 0;
+ req->nSI= xkb->compat->num_si;
+ }
+ else {
+ req->truncateSI = False;
+ req->firstSI= 0;
+ req->nSI= 0;
+ }
+ if (which&XkbGroupCompatMask)
+ req->groups= XkbAllGroupsMask;
+ else req->groups= 0;
+ ok= _XkbWriteSetCompatMap(dpy,req,xkb);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return ok;
+}
+
diff --git a/libX11/src/xkb/XKBCtrls.c b/libX11/src/xkb/XKBCtrls.c
index 3742c94eb..abb470be9 100644
--- a/libX11/src/xkb/XKBCtrls.c
+++ b/libX11/src/xkb/XKBCtrls.c
@@ -1,354 +1,352 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-
-static xkbSetControlsReq *
-_XkbGetSetControlsReq(Display *dpy,XkbInfoPtr xkbi,unsigned int deviceSpec)
-{
-xkbSetControlsReq *req;
-
- GetReq(kbSetControls,req);
- bzero(req,SIZEOF(xkbSetControlsReq));
- req->reqType = xkbi->codes->major_opcode;
- req->length = (SIZEOF(xkbSetControlsReq)>>2);
- req->xkbReqType = X_kbSetControls;
- req->deviceSpec = deviceSpec;
- return req;
-}
-
-Bool
-XkbSetAutoRepeatRate( Display *dpy,
- unsigned int deviceSpec,
- unsigned int timeout,
- unsigned int interval)
-{
- register xkbSetControlsReq *req;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
- req->changeCtrls = XkbRepeatKeysMask;
- req->repeatDelay = timeout;
- req->repeatInterval = interval;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbGetAutoRepeatRate( Display * dpy,
- unsigned int deviceSpec,
- unsigned int * timeoutp,
- unsigned int * intervalp)
-{
- register xkbGetControlsReq *req;
- xkbGetControlsReply rep;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbGetControls, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetControls;
- req->deviceSpec = deviceSpec;
- if (!_XReply(dpy, (xReply *)&rep,
- (SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- *timeoutp = rep.repeatDelay;
- *intervalp = rep.repeatInterval;
- return True;
-}
-
-Bool
-XkbSetServerInternalMods( Display * dpy,
- unsigned deviceSpec,
- unsigned affectReal,
- unsigned realValues,
- unsigned affectVirtual,
- unsigned virtualValues)
-{
- register xkbSetControlsReq *req;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
- req->affectInternalMods = affectReal;
- req->internalMods = realValues;
- req->affectInternalVMods= affectVirtual;
- req->internalVMods= virtualValues;
- req->changeCtrls = XkbInternalModsMask;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbSetIgnoreLockMods( Display * dpy,
- unsigned int deviceSpec,
- unsigned affectReal,
- unsigned realValues,
- unsigned affectVirtual,
- unsigned virtualValues)
-{
- register xkbSetControlsReq *req;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
- req->affectIgnoreLockMods= affectReal;
- req->ignoreLockMods = realValues;
- req->affectIgnoreLockVMods= affectVirtual;
- req->ignoreLockVMods= virtualValues;
- req->changeCtrls = XkbIgnoreLockModsMask;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbChangeEnabledControls( Display * dpy,
- unsigned deviceSpec,
- unsigned affect,
- unsigned values)
-{
- register xkbSetControlsReq *req;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
- req->affectEnabledCtrls= affect;
- req->enabledCtrls= (affect&values);
- req->changeCtrls = XkbControlsEnabledMask;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Status
-XkbGetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
-{
- register xkbGetControlsReq *req;
- xkbGetControlsReply rep;
- XkbControlsPtr ctrls;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
- if ((!xkb) || (!which))
- return BadMatch;
-
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbGetControls, req);
- if (!xkb->ctrls) {
- xkb->ctrls = _XkbTypedCalloc(1,XkbControlsRec);
- if (!xkb->ctrls) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadAlloc;
- }
- }
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetControls;
- req->deviceSpec = xkb->device_spec;
- if (!_XReply(dpy, (xReply *)&rep,
- (SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadImplementation;
- }
- if (xkb->device_spec==XkbUseCoreKbd)
- xkb->device_spec= rep.deviceID;
- ctrls= xkb->ctrls;
- if (which&XkbControlsEnabledMask)
- ctrls->enabled_ctrls = rep.enabledCtrls;
- ctrls->num_groups= rep.numGroups;
- if (which&XkbGroupsWrapMask)
- ctrls->groups_wrap= rep.groupsWrap;
- if (which&XkbInternalModsMask) {
- ctrls->internal.mask = rep.internalMods;
- ctrls->internal.real_mods = rep.internalRealMods;
- ctrls->internal.vmods = rep.internalVMods;
- }
- if (which&XkbIgnoreLockModsMask) {
- ctrls->ignore_lock.mask = rep.ignoreLockMods;
- ctrls->ignore_lock.real_mods = rep.ignoreLockRealMods;
- ctrls->ignore_lock.vmods = rep.ignoreLockVMods;
- }
- if (which&XkbRepeatKeysMask) {
- ctrls->repeat_delay = rep.repeatDelay;
- ctrls->repeat_interval = rep.repeatInterval;
- }
- if (which&XkbSlowKeysMask)
- ctrls->slow_keys_delay = rep.slowKeysDelay;
- if (which&XkbBounceKeysMask)
- ctrls->debounce_delay = rep.debounceDelay;
- if (which&XkbMouseKeysMask) {
- ctrls->mk_dflt_btn = rep.mkDfltBtn;
- }
- if (which&XkbMouseKeysAccelMask) {
- ctrls->mk_delay = rep.mkDelay;
- ctrls->mk_interval = rep.mkInterval;
- ctrls->mk_time_to_max = rep.mkTimeToMax;
- ctrls->mk_max_speed = rep.mkMaxSpeed;
- ctrls->mk_curve = rep.mkCurve;
- }
- if (which&XkbAccessXKeysMask)
- ctrls->ax_options= rep.axOptions;
- if (which&XkbStickyKeysMask) {
- ctrls->ax_options &= ~XkbAX_SKOptionsMask;
- ctrls->ax_options |= rep.axOptions & XkbAX_SKOptionsMask;
- }
- if (which&XkbAccessXFeedbackMask) {
- ctrls->ax_options &= ~XkbAX_FBOptionsMask;
- ctrls->ax_options |= rep.axOptions & XkbAX_FBOptionsMask;
- }
- if (which&XkbAccessXTimeoutMask) {
- ctrls->ax_timeout = rep.axTimeout;
- ctrls->axt_ctrls_mask = rep.axtCtrlsMask;
- ctrls->axt_ctrls_values = rep.axtCtrlsValues;
- ctrls->axt_opts_mask = rep.axtOptsMask;
- ctrls->axt_opts_values= rep.axtOptsValues;
- }
- if (which&XkbPerKeyRepeatMask) {
- memcpy(ctrls->per_key_repeat,rep.perKeyRepeat,
- XkbPerKeyBitArraySize);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return Success;
-}
-
-Bool
-XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
-{
- register xkbSetControlsReq *req;
- XkbControlsPtr ctrls;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- if ((!xkb)||(!xkb->ctrls))
- return False;
-
- ctrls= xkb->ctrls;
- LockDisplay(dpy);
- req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,xkb->device_spec);
- req->changeCtrls = (CARD32)which;
- if (which&XkbInternalModsMask) {
- req->affectInternalMods= ~0;
- req->internalMods= ctrls->internal.real_mods;
- req->affectInternalVMods = ~0;
- req->internalVMods= ctrls->internal.vmods;
- }
- if (which&XkbIgnoreLockModsMask) {
- req->affectIgnoreLockMods= ~0;
- req->ignoreLockMods= ctrls->ignore_lock.real_mods;
- req->affectIgnoreLockVMods= ~0;
- req->ignoreLockVMods= ctrls->ignore_lock.vmods;
- }
- if (which&XkbControlsEnabledMask) {
- req->affectEnabledCtrls= XkbAllBooleanCtrlsMask;
- req->enabledCtrls= ctrls->enabled_ctrls;
- }
- if (which&XkbRepeatKeysMask) {
- req->repeatDelay = ctrls->repeat_delay;
- req->repeatInterval = ctrls->repeat_interval;
- }
- if (which&XkbSlowKeysMask)
- req->slowKeysDelay = ctrls->slow_keys_delay;
- if (which&XkbBounceKeysMask)
- req->debounceDelay = ctrls->debounce_delay;
- if (which&XkbMouseKeysMask) {
- req->mkDfltBtn = ctrls->mk_dflt_btn;
- }
- if (which&XkbGroupsWrapMask)
- req->groupsWrap= ctrls->groups_wrap;
- if (which&(XkbAccessXKeysMask|XkbStickyKeysMask|XkbAccessXFeedbackMask))
- req->axOptions= ctrls->ax_options;
- if (which&XkbMouseKeysAccelMask) {
- req->mkDelay = ctrls->mk_delay;
- req->mkInterval = ctrls->mk_interval;
- req->mkTimeToMax = ctrls->mk_time_to_max;
- req->mkMaxSpeed = ctrls->mk_max_speed;
- req->mkCurve = ctrls->mk_curve;
- }
- if (which&XkbAccessXTimeoutMask) {
- req->axTimeout = ctrls->ax_timeout;
- req->axtCtrlsMask = ctrls->axt_ctrls_mask;
- req->axtCtrlsValues = ctrls->axt_ctrls_values;
- req->axtOptsMask = ctrls->axt_opts_mask;
- req->axtOptsValues=ctrls->axt_opts_values;
- }
- if (which&XkbPerKeyRepeatMask) {
- memcpy(req->perKeyRepeat,ctrls->per_key_repeat,
- XkbPerKeyBitArraySize);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-/***====================================================================***/
-
-void
-XkbNoteControlsChanges( XkbControlsChangesPtr old,
- XkbControlsNotifyEvent * new,
- unsigned int wanted)
-{
- old->changed_ctrls|= (new->changed_ctrls&wanted);
- if (new->changed_ctrls&XkbControlsEnabledMask&wanted)
- old->enabled_ctrls_changes^= new->enabled_ctrl_changes;
- /* num_groups_changed?? */
- return;
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 <stdio.h>
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+
+static xkbSetControlsReq *
+_XkbGetSetControlsReq(Display *dpy,XkbInfoPtr xkbi,unsigned int deviceSpec)
+{
+xkbSetControlsReq *req;
+
+ GetReq(kbSetControls,req);
+ bzero(req,SIZEOF(xkbSetControlsReq));
+ req->reqType = xkbi->codes->major_opcode;
+ req->length = (SIZEOF(xkbSetControlsReq)>>2);
+ req->xkbReqType = X_kbSetControls;
+ req->deviceSpec = deviceSpec;
+ return req;
+}
+
+Bool
+XkbSetAutoRepeatRate( Display *dpy,
+ unsigned int deviceSpec,
+ unsigned int timeout,
+ unsigned int interval)
+{
+ register xkbSetControlsReq *req;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
+ req->changeCtrls = XkbRepeatKeysMask;
+ req->repeatDelay = timeout;
+ req->repeatInterval = interval;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbGetAutoRepeatRate( Display * dpy,
+ unsigned int deviceSpec,
+ unsigned int * timeoutp,
+ unsigned int * intervalp)
+{
+ register xkbGetControlsReq *req;
+ xkbGetControlsReply rep;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbGetControls, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetControls;
+ req->deviceSpec = deviceSpec;
+ if (!_XReply(dpy, (xReply *)&rep,
+ (SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ *timeoutp = rep.repeatDelay;
+ *intervalp = rep.repeatInterval;
+ return True;
+}
+
+Bool
+XkbSetServerInternalMods( Display * dpy,
+ unsigned deviceSpec,
+ unsigned affectReal,
+ unsigned realValues,
+ unsigned affectVirtual,
+ unsigned virtualValues)
+{
+ register xkbSetControlsReq *req;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
+ req->affectInternalMods = affectReal;
+ req->internalMods = realValues;
+ req->affectInternalVMods= affectVirtual;
+ req->internalVMods= virtualValues;
+ req->changeCtrls = XkbInternalModsMask;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbSetIgnoreLockMods( Display * dpy,
+ unsigned int deviceSpec,
+ unsigned affectReal,
+ unsigned realValues,
+ unsigned affectVirtual,
+ unsigned virtualValues)
+{
+ register xkbSetControlsReq *req;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
+ req->affectIgnoreLockMods= affectReal;
+ req->ignoreLockMods = realValues;
+ req->affectIgnoreLockVMods= affectVirtual;
+ req->ignoreLockVMods= virtualValues;
+ req->changeCtrls = XkbIgnoreLockModsMask;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbChangeEnabledControls( Display * dpy,
+ unsigned deviceSpec,
+ unsigned affect,
+ unsigned values)
+{
+ register xkbSetControlsReq *req;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
+ req->affectEnabledCtrls= affect;
+ req->enabledCtrls= (affect&values);
+ req->changeCtrls = XkbControlsEnabledMask;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Status
+XkbGetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
+{
+ register xkbGetControlsReq *req;
+ xkbGetControlsReply rep;
+ XkbControlsPtr ctrls;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+ if ((!xkb) || (!which))
+ return BadMatch;
+
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbGetControls, req);
+ if (!xkb->ctrls) {
+ xkb->ctrls = _XkbTypedCalloc(1,XkbControlsRec);
+ if (!xkb->ctrls) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadAlloc;
+ }
+ }
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetControls;
+ req->deviceSpec = xkb->device_spec;
+ if (!_XReply(dpy, (xReply *)&rep,
+ (SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadImplementation;
+ }
+ if (xkb->device_spec==XkbUseCoreKbd)
+ xkb->device_spec= rep.deviceID;
+ ctrls= xkb->ctrls;
+ if (which&XkbControlsEnabledMask)
+ ctrls->enabled_ctrls = rep.enabledCtrls;
+ ctrls->num_groups= rep.numGroups;
+ if (which&XkbGroupsWrapMask)
+ ctrls->groups_wrap= rep.groupsWrap;
+ if (which&XkbInternalModsMask) {
+ ctrls->internal.mask = rep.internalMods;
+ ctrls->internal.real_mods = rep.internalRealMods;
+ ctrls->internal.vmods = rep.internalVMods;
+ }
+ if (which&XkbIgnoreLockModsMask) {
+ ctrls->ignore_lock.mask = rep.ignoreLockMods;
+ ctrls->ignore_lock.real_mods = rep.ignoreLockRealMods;
+ ctrls->ignore_lock.vmods = rep.ignoreLockVMods;
+ }
+ if (which&XkbRepeatKeysMask) {
+ ctrls->repeat_delay = rep.repeatDelay;
+ ctrls->repeat_interval = rep.repeatInterval;
+ }
+ if (which&XkbSlowKeysMask)
+ ctrls->slow_keys_delay = rep.slowKeysDelay;
+ if (which&XkbBounceKeysMask)
+ ctrls->debounce_delay = rep.debounceDelay;
+ if (which&XkbMouseKeysMask) {
+ ctrls->mk_dflt_btn = rep.mkDfltBtn;
+ }
+ if (which&XkbMouseKeysAccelMask) {
+ ctrls->mk_delay = rep.mkDelay;
+ ctrls->mk_interval = rep.mkInterval;
+ ctrls->mk_time_to_max = rep.mkTimeToMax;
+ ctrls->mk_max_speed = rep.mkMaxSpeed;
+ ctrls->mk_curve = rep.mkCurve;
+ }
+ if (which&XkbAccessXKeysMask)
+ ctrls->ax_options= rep.axOptions;
+ if (which&XkbStickyKeysMask) {
+ ctrls->ax_options &= ~XkbAX_SKOptionsMask;
+ ctrls->ax_options |= rep.axOptions & XkbAX_SKOptionsMask;
+ }
+ if (which&XkbAccessXFeedbackMask) {
+ ctrls->ax_options &= ~XkbAX_FBOptionsMask;
+ ctrls->ax_options |= rep.axOptions & XkbAX_FBOptionsMask;
+ }
+ if (which&XkbAccessXTimeoutMask) {
+ ctrls->ax_timeout = rep.axTimeout;
+ ctrls->axt_ctrls_mask = rep.axtCtrlsMask;
+ ctrls->axt_ctrls_values = rep.axtCtrlsValues;
+ ctrls->axt_opts_mask = rep.axtOptsMask;
+ ctrls->axt_opts_values= rep.axtOptsValues;
+ }
+ if (which&XkbPerKeyRepeatMask) {
+ memcpy(ctrls->per_key_repeat,rep.perKeyRepeat,
+ XkbPerKeyBitArraySize);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return Success;
+}
+
+Bool
+XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
+{
+ register xkbSetControlsReq *req;
+ XkbControlsPtr ctrls;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ if ((!xkb)||(!xkb->ctrls))
+ return False;
+
+ ctrls= xkb->ctrls;
+ LockDisplay(dpy);
+ req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,xkb->device_spec);
+ req->changeCtrls = (CARD32)which;
+ if (which&XkbInternalModsMask) {
+ req->affectInternalMods= ~0;
+ req->internalMods= ctrls->internal.real_mods;
+ req->affectInternalVMods = ~0;
+ req->internalVMods= ctrls->internal.vmods;
+ }
+ if (which&XkbIgnoreLockModsMask) {
+ req->affectIgnoreLockMods= ~0;
+ req->ignoreLockMods= ctrls->ignore_lock.real_mods;
+ req->affectIgnoreLockVMods= ~0;
+ req->ignoreLockVMods= ctrls->ignore_lock.vmods;
+ }
+ if (which&XkbControlsEnabledMask) {
+ req->affectEnabledCtrls= XkbAllBooleanCtrlsMask;
+ req->enabledCtrls= ctrls->enabled_ctrls;
+ }
+ if (which&XkbRepeatKeysMask) {
+ req->repeatDelay = ctrls->repeat_delay;
+ req->repeatInterval = ctrls->repeat_interval;
+ }
+ if (which&XkbSlowKeysMask)
+ req->slowKeysDelay = ctrls->slow_keys_delay;
+ if (which&XkbBounceKeysMask)
+ req->debounceDelay = ctrls->debounce_delay;
+ if (which&XkbMouseKeysMask) {
+ req->mkDfltBtn = ctrls->mk_dflt_btn;
+ }
+ if (which&XkbGroupsWrapMask)
+ req->groupsWrap= ctrls->groups_wrap;
+ if (which&(XkbAccessXKeysMask|XkbStickyKeysMask|XkbAccessXFeedbackMask))
+ req->axOptions= ctrls->ax_options;
+ if (which&XkbMouseKeysAccelMask) {
+ req->mkDelay = ctrls->mk_delay;
+ req->mkInterval = ctrls->mk_interval;
+ req->mkTimeToMax = ctrls->mk_time_to_max;
+ req->mkMaxSpeed = ctrls->mk_max_speed;
+ req->mkCurve = ctrls->mk_curve;
+ }
+ if (which&XkbAccessXTimeoutMask) {
+ req->axTimeout = ctrls->ax_timeout;
+ req->axtCtrlsMask = ctrls->axt_ctrls_mask;
+ req->axtCtrlsValues = ctrls->axt_ctrls_values;
+ req->axtOptsMask = ctrls->axt_opts_mask;
+ req->axtOptsValues=ctrls->axt_opts_values;
+ }
+ if (which&XkbPerKeyRepeatMask) {
+ memcpy(req->perKeyRepeat,ctrls->per_key_repeat,
+ XkbPerKeyBitArraySize);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+/***====================================================================***/
+
+void
+XkbNoteControlsChanges( XkbControlsChangesPtr old,
+ XkbControlsNotifyEvent * new,
+ unsigned int wanted)
+{
+ old->changed_ctrls|= (new->changed_ctrls&wanted);
+ if (new->changed_ctrls&XkbControlsEnabledMask&wanted)
+ old->enabled_ctrls_changes^= new->enabled_ctrl_changes;
+ /* num_groups_changed?? */
+ return;
+}
diff --git a/libX11/src/xkb/XKBCvt.c b/libX11/src/xkb/XKBCvt.c
index b2621a9b1..a68778223 100644
--- a/libX11/src/xkb/XKBCvt.c
+++ b/libX11/src/xkb/XKBCvt.c
@@ -1,338 +1,337 @@
-/*
-
-Copyright 1988, 1989, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <X11/X.h>
-#include <X11/Xlib.h>
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcPubI.h"
-#include "Ximint.h"
-#include <X11/Xutil.h>
-#include <X11/Xmd.h>
-#define XK_LATIN1
-#define XK_PUBLISHING
-#include <X11/keysym.h>
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-#include <X11/Xlocale.h>
-#include <ctype.h>
-#include <X11/Xos.h>
-
-#ifdef __sgi_not_xconsortium
-#define XKB_EXTEND_LOOKUP_STRING
-#endif
-
-static int
-_XkbHandleSpecialSym(KeySym keysym, char *buffer, int nbytes, int *extra_rtrn)
-{
-
- /* try to convert to Latin-1, handling ctrl */
- if (!(((keysym >= XK_BackSpace) && (keysym <= XK_Clear)) ||
- (keysym == XK_Return) || (keysym == XK_Escape) ||
- (keysym == XK_KP_Space) || (keysym == XK_KP_Tab) ||
- (keysym == XK_KP_Enter) ||
- ((keysym >= XK_KP_Multiply) && (keysym <= XK_KP_9)) ||
- (keysym == XK_KP_Equal) ||
- (keysym == XK_Delete)))
- return 0;
-
- if (nbytes<1) {
- if (extra_rtrn)
- *extra_rtrn= 1;
- return 0;
- }
- /* if X keysym, convert to ascii by grabbing low 7 bits */
- if (keysym == XK_KP_Space)
- buffer[0] = XK_space & 0x7F; /* patch encoding botch */
- else if (keysym == XK_hyphen)
- buffer[0] = (char)(XK_minus & 0xFF); /* map to equiv character */
- else buffer[0] = (char)(keysym & 0x7F);
- return 1;
-}
-
-/*ARGSUSED*/
-static int
-_XkbKSToKnownSet ( XPointer priv,
- KeySym keysym,
- char * buffer,
- int nbytes,
- int * extra_rtrn)
-{
- char tbuf[8],*buf;
-
- if (extra_rtrn)
- *extra_rtrn= 0;
-
- /* convert "dead" diacriticals for dumb applications */
- if ( (keysym&0xffffff00)== 0xfe00 ) {
- switch ( keysym ) {
- case XK_dead_grave: keysym = XK_grave; break;
- case XK_dead_acute: keysym = XK_acute; break;
- case XK_dead_circumflex: keysym = XK_asciicircum; break;
- case XK_dead_tilde: keysym = XK_asciitilde; break;
- case XK_dead_macron: keysym = XK_macron; break;
- case XK_dead_breve: keysym = XK_breve; break;
- case XK_dead_abovedot: keysym = XK_abovedot; break;
- case XK_dead_diaeresis: keysym = XK_diaeresis; break;
- case XK_dead_abovering: keysym = XK_degree; break;
- case XK_dead_doubleacute: keysym = XK_doubleacute; break;
- case XK_dead_caron: keysym = XK_caron; break;
- case XK_dead_cedilla: keysym = XK_cedilla; break;
- case XK_dead_ogonek : keysym = XK_ogonek; break;
- case XK_dead_iota: keysym = XK_Greek_iota; break;
-#ifdef XK_KATAKANA
- case XK_dead_voiced_sound: keysym = XK_voicedsound; break;
- case XK_dead_semivoiced_sound:keysym = XK_semivoicedsound; break;
-#endif
- }
- }
-
- if (nbytes<1) buf= tbuf;
- else buf= buffer;
-
- if ((keysym&0xffffff00)==0xff00) {
- return _XkbHandleSpecialSym(keysym, buf, nbytes, extra_rtrn);
- }
- return _XimGetCharCode (priv, keysym, (unsigned char *)buf, nbytes);
-}
-
-typedef struct _XkbToKS {
- unsigned prefix;
- char *map;
-} XkbToKS;
-
-/*ARGSUSED*/
-static KeySym
-_XkbKnownSetToKS(XPointer priv,char *buffer,int nbytes,Status *status)
-{
- if (nbytes!=1)
- return NoSymbol;
- if (((buffer[0]&0x80)==0)&&(buffer[0]>=32))
- return buffer[0];
- else if ((buffer[0]&0x7f)>=32) {
- XkbToKS *map= (XkbToKS *)priv;
- if ( map ) {
- if ( map->map ) return map->prefix|map->map[buffer[0]&0x7f];
- else return map->prefix|buffer[0];
- }
- return buffer[0];
- }
- return NoSymbol;
-}
-
-static KeySym
-__XkbDefaultToUpper(KeySym sym)
-{
- KeySym lower,upper;
-
- XConvertCase(sym, &lower, &upper);
- return upper;
-}
-
-#ifdef XKB_EXTEND_LOOKUP_STRING
-static int
-Strcmp(char *str1, char *str2)
-{
- char str[256];
- char c, *s;
-
- /*
- * unchecked strings from the environment can end up here, so check
- * the length before copying.
- */
- if (strlen(str1) >= sizeof(str)) /* almost certain it's a mismatch */
- return 1;
-
- for (s = str; (c = *str1++); ) {
- if (isupper(c))
- c = tolower(c);
- *s++ = c;
- }
- *s = '\0';
- return (strcmp(str, str2));
-}
-#endif
-
-int
-_XkbGetConverters(const char *encoding_name, XkbConverters *cvt_rtrn)
-{
- if ( !cvt_rtrn ) return 0;
-
- cvt_rtrn->KSToMB = _XkbKSToKnownSet;
- cvt_rtrn->KSToMBPriv = _XimGetLocaleCode(encoding_name);
- cvt_rtrn->MBToKS = _XkbKnownSetToKS;
- cvt_rtrn->MBToKSPriv = NULL;
- cvt_rtrn->KSToUpper = __XkbDefaultToUpper;
- return 1;
-}
-
-/***====================================================================***/
-
-/*
- * The function _XkbGetCharset seems to be missnamed as what it seems to
- * be used for is to determine the encoding-name for the locale. ???
- */
-
-#ifdef XKB_EXTEND_LOOKUP_STRING
-
-/*
- * XKB_EXTEND_LOOKUP_STRING is not used by the SI. It is used by various
- * X Consortium/X Project Team members, so we leave it in the source as
- * an simplify integration by these companies.
- */
-
-#define CHARSET_FILE "/usr/lib/X11/input/charsets"
-static char *_XkbKnownLanguages = "c=ascii:da,de,en,es,fr,is,it,nl,no,pt,sv=iso8859-1:hu,pl,cs=iso8859-2:eo=iso8859-3:sp=iso8859-5:ar,ara=iso8859-6:el=iso8859-7:he=iso8859-8:tr=iso8859-9:lt,lv=iso8859-13:et,fi=iso8859-15:ru=koi8-r:uk=koi8-u:th,th_TH,th_TH.iso8859-11=iso8859-11:th_TH.TIS620=tis620:hy=armscii-8:vi=tcvn-5712:ka=georgian-academy:be,bg=microsoft-cp1251";
-
-char *
-_XkbGetCharset(void)
-{
- /*
- * PAGE USAGE TUNING: explicitly initialize to move these to data
- * instead of bss
- */
- static char buf[100] = { 0 };
- char lang[256];
- char *start,*tmp,*end,*next,*set;
- char *country,*charset;
- char *locale;
-
- tmp = getenv( "_XKB_CHARSET" );
- if ( tmp )
- return tmp;
- locale = setlocale(LC_CTYPE,NULL);
-
- if ( locale == NULL )
- return NULL;
-
- if (strlen(locale) >= sizeof(lang))
- return NULL;
-
- for (tmp = lang; *tmp = *locale++; tmp++) {
- if (isupper(*tmp))
- *tmp = tolower(*tmp);
- }
- country = strchr( lang, '_');
- if ( country ) {
- *country++ = '\0';
- charset = strchr( country, '.' );
- if ( charset ) *charset++ = '\0';
- if ( charset ) {
- strncpy(buf,charset,99);
- buf[99] = '\0';
- return buf;
- }
- }
- else {
- charset = NULL;
- }
-
- if ((tmp = getenv("_XKB_LOCALE_CHARSETS"))!=NULL) {
- start = _XkbAlloc(strlen(tmp) + 1);
- strcpy(start, tmp);
- tmp = start;
- } else {
- struct stat sbuf;
- FILE *file;
-#ifndef __UNIXOS2__
- char *cf = CHARSET_FILE;
-#else
- char *cf = __XOS2RedirRoot(CHARSET_FILE);
-#endif
-
-#ifndef S_ISREG
-# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
-#endif
-
- if ( (stat(cf,&sbuf)==0) && S_ISREG(sbuf.st_mode) &&
- (file = fopen(cf,"r")) ) {
- tmp = _XkbAlloc(sbuf.st_size+1);
- if (tmp!=NULL) {
- sbuf.st_size = (long)fread(tmp,1,sbuf.st_size,file);
- tmp[sbuf.st_size] = '\0';
- }
- fclose(file);
- }
- }
-
- if ( tmp == NULL ) {
- tmp = _XkbAlloc(strlen(_XkbKnownLanguages) + 1);
- if (!tmp)
- return NULL;
- strcpy(tmp, _XkbKnownLanguages);
- }
- start = tmp;
- do {
- if ( (set=strchr(tmp,'=')) == NULL )
- break;
- *set++ = '\0';
- if ( (next=strchr(set,':')) != NULL )
- *next++ = '\0';
- while ( tmp && *tmp ) {
- if ( (end=strchr(tmp,',')) != NULL )
- *end++ = '\0';
- if ( Strcmp( tmp, lang ) == 0 ) {
- strncpy(buf,set,100);
- buf[99] = '\0';
- Xfree(start);
- return buf;
- }
- tmp = end;
- }
- tmp = next;
- } while ( tmp && *tmp );
- Xfree(start);
- return NULL;
-}
-#else
-char *
-_XkbGetCharset(void)
-{
- char *tmp;
- XLCd lcd;
-
- tmp = getenv( "_XKB_CHARSET" );
- if ( tmp )
- return tmp;
-
- lcd = _XlcCurrentLC();
- if ( lcd )
- return XLC_PUBLIC(lcd,encoding_name);
-
- return NULL;
-}
-#endif
-
+/*
+
+Copyright 1988, 1989, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcPubI.h"
+#include "Ximint.h"
+#include <X11/Xutil.h>
+#include <X11/Xmd.h>
+#define XK_LATIN1
+#define XK_PUBLISHING
+#include <X11/keysym.h>
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+#include <X11/Xlocale.h>
+#include <ctype.h>
+#include <X11/Xos.h>
+
+#ifdef __sgi_not_xconsortium
+#define XKB_EXTEND_LOOKUP_STRING
+#endif
+
+static int
+_XkbHandleSpecialSym(KeySym keysym, char *buffer, int nbytes, int *extra_rtrn)
+{
+
+ /* try to convert to Latin-1, handling ctrl */
+ if (!(((keysym >= XK_BackSpace) && (keysym <= XK_Clear)) ||
+ (keysym == XK_Return) || (keysym == XK_Escape) ||
+ (keysym == XK_KP_Space) || (keysym == XK_KP_Tab) ||
+ (keysym == XK_KP_Enter) ||
+ ((keysym >= XK_KP_Multiply) && (keysym <= XK_KP_9)) ||
+ (keysym == XK_KP_Equal) ||
+ (keysym == XK_Delete)))
+ return 0;
+
+ if (nbytes<1) {
+ if (extra_rtrn)
+ *extra_rtrn= 1;
+ return 0;
+ }
+ /* if X keysym, convert to ascii by grabbing low 7 bits */
+ if (keysym == XK_KP_Space)
+ buffer[0] = XK_space & 0x7F; /* patch encoding botch */
+ else if (keysym == XK_hyphen)
+ buffer[0] = (char)(XK_minus & 0xFF); /* map to equiv character */
+ else buffer[0] = (char)(keysym & 0x7F);
+ return 1;
+}
+
+/*ARGSUSED*/
+static int
+_XkbKSToKnownSet ( XPointer priv,
+ KeySym keysym,
+ char * buffer,
+ int nbytes,
+ int * extra_rtrn)
+{
+ char tbuf[8],*buf;
+
+ if (extra_rtrn)
+ *extra_rtrn= 0;
+
+ /* convert "dead" diacriticals for dumb applications */
+ if ( (keysym&0xffffff00)== 0xfe00 ) {
+ switch ( keysym ) {
+ case XK_dead_grave: keysym = XK_grave; break;
+ case XK_dead_acute: keysym = XK_acute; break;
+ case XK_dead_circumflex: keysym = XK_asciicircum; break;
+ case XK_dead_tilde: keysym = XK_asciitilde; break;
+ case XK_dead_macron: keysym = XK_macron; break;
+ case XK_dead_breve: keysym = XK_breve; break;
+ case XK_dead_abovedot: keysym = XK_abovedot; break;
+ case XK_dead_diaeresis: keysym = XK_diaeresis; break;
+ case XK_dead_abovering: keysym = XK_degree; break;
+ case XK_dead_doubleacute: keysym = XK_doubleacute; break;
+ case XK_dead_caron: keysym = XK_caron; break;
+ case XK_dead_cedilla: keysym = XK_cedilla; break;
+ case XK_dead_ogonek : keysym = XK_ogonek; break;
+ case XK_dead_iota: keysym = XK_Greek_iota; break;
+#ifdef XK_KATAKANA
+ case XK_dead_voiced_sound: keysym = XK_voicedsound; break;
+ case XK_dead_semivoiced_sound:keysym = XK_semivoicedsound; break;
+#endif
+ }
+ }
+
+ if (nbytes<1) buf= tbuf;
+ else buf= buffer;
+
+ if ((keysym&0xffffff00)==0xff00) {
+ return _XkbHandleSpecialSym(keysym, buf, nbytes, extra_rtrn);
+ }
+ return _XimGetCharCode (priv, keysym, (unsigned char *)buf, nbytes);
+}
+
+typedef struct _XkbToKS {
+ unsigned prefix;
+ char *map;
+} XkbToKS;
+
+/*ARGSUSED*/
+static KeySym
+_XkbKnownSetToKS(XPointer priv,char *buffer,int nbytes,Status *status)
+{
+ if (nbytes!=1)
+ return NoSymbol;
+ if (((buffer[0]&0x80)==0)&&(buffer[0]>=32))
+ return buffer[0];
+ else if ((buffer[0]&0x7f)>=32) {
+ XkbToKS *map= (XkbToKS *)priv;
+ if ( map ) {
+ if ( map->map ) return map->prefix|map->map[buffer[0]&0x7f];
+ else return map->prefix|buffer[0];
+ }
+ return buffer[0];
+ }
+ return NoSymbol;
+}
+
+static KeySym
+__XkbDefaultToUpper(KeySym sym)
+{
+ KeySym lower,upper;
+
+ XConvertCase(sym, &lower, &upper);
+ return upper;
+}
+
+#ifdef XKB_EXTEND_LOOKUP_STRING
+static int
+Strcmp(char *str1, char *str2)
+{
+ char str[256];
+ char c, *s;
+
+ /*
+ * unchecked strings from the environment can end up here, so check
+ * the length before copying.
+ */
+ if (strlen(str1) >= sizeof(str)) /* almost certain it's a mismatch */
+ return 1;
+
+ for (s = str; (c = *str1++); ) {
+ if (isupper(c))
+ c = tolower(c);
+ *s++ = c;
+ }
+ *s = '\0';
+ return (strcmp(str, str2));
+}
+#endif
+
+int
+_XkbGetConverters(const char *encoding_name, XkbConverters *cvt_rtrn)
+{
+ if ( !cvt_rtrn ) return 0;
+
+ cvt_rtrn->KSToMB = _XkbKSToKnownSet;
+ cvt_rtrn->KSToMBPriv = _XimGetLocaleCode(encoding_name);
+ cvt_rtrn->MBToKS = _XkbKnownSetToKS;
+ cvt_rtrn->MBToKSPriv = NULL;
+ cvt_rtrn->KSToUpper = __XkbDefaultToUpper;
+ return 1;
+}
+
+/***====================================================================***/
+
+/*
+ * The function _XkbGetCharset seems to be missnamed as what it seems to
+ * be used for is to determine the encoding-name for the locale. ???
+ */
+
+#ifdef XKB_EXTEND_LOOKUP_STRING
+
+/*
+ * XKB_EXTEND_LOOKUP_STRING is not used by the SI. It is used by various
+ * X Consortium/X Project Team members, so we leave it in the source as
+ * an simplify integration by these companies.
+ */
+
+#define CHARSET_FILE "/usr/lib/X11/input/charsets"
+static char *_XkbKnownLanguages = "c=ascii:da,de,en,es,fr,is,it,nl,no,pt,sv=iso8859-1:hu,pl,cs=iso8859-2:eo=iso8859-3:sp=iso8859-5:ar,ara=iso8859-6:el=iso8859-7:he=iso8859-8:tr=iso8859-9:lt,lv=iso8859-13:et,fi=iso8859-15:ru=koi8-r:uk=koi8-u:th,th_TH,th_TH.iso8859-11=iso8859-11:th_TH.TIS620=tis620:hy=armscii-8:vi=tcvn-5712:ka=georgian-academy:be,bg=microsoft-cp1251";
+
+char *
+_XkbGetCharset(void)
+{
+ /*
+ * PAGE USAGE TUNING: explicitly initialize to move these to data
+ * instead of bss
+ */
+ static char buf[100] = { 0 };
+ char lang[256];
+ char *start,*tmp,*end,*next,*set;
+ char *country,*charset;
+ char *locale;
+
+ tmp = getenv( "_XKB_CHARSET" );
+ if ( tmp )
+ return tmp;
+ locale = setlocale(LC_CTYPE,NULL);
+
+ if ( locale == NULL )
+ return NULL;
+
+ if (strlen(locale) >= sizeof(lang))
+ return NULL;
+
+ for (tmp = lang; *tmp = *locale++; tmp++) {
+ if (isupper(*tmp))
+ *tmp = tolower(*tmp);
+ }
+ country = strchr( lang, '_');
+ if ( country ) {
+ *country++ = '\0';
+ charset = strchr( country, '.' );
+ if ( charset ) *charset++ = '\0';
+ if ( charset ) {
+ strncpy(buf,charset,99);
+ buf[99] = '\0';
+ return buf;
+ }
+ }
+ else {
+ charset = NULL;
+ }
+
+ if ((tmp = getenv("_XKB_LOCALE_CHARSETS"))!=NULL) {
+ start = _XkbAlloc(strlen(tmp) + 1);
+ strcpy(start, tmp);
+ tmp = start;
+ } else {
+ struct stat sbuf;
+ FILE *file;
+#ifndef __UNIXOS2__
+ char *cf = CHARSET_FILE;
+#else
+ char *cf = __XOS2RedirRoot(CHARSET_FILE);
+#endif
+
+#ifndef S_ISREG
+# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
+ if ( (stat(cf,&sbuf)==0) && S_ISREG(sbuf.st_mode) &&
+ (file = fopen(cf,"r")) ) {
+ tmp = _XkbAlloc(sbuf.st_size+1);
+ if (tmp!=NULL) {
+ sbuf.st_size = (long)fread(tmp,1,sbuf.st_size,file);
+ tmp[sbuf.st_size] = '\0';
+ }
+ fclose(file);
+ }
+ }
+
+ if ( tmp == NULL ) {
+ tmp = _XkbAlloc(strlen(_XkbKnownLanguages) + 1);
+ if (!tmp)
+ return NULL;
+ strcpy(tmp, _XkbKnownLanguages);
+ }
+ start = tmp;
+ do {
+ if ( (set=strchr(tmp,'=')) == NULL )
+ break;
+ *set++ = '\0';
+ if ( (next=strchr(set,':')) != NULL )
+ *next++ = '\0';
+ while ( tmp && *tmp ) {
+ if ( (end=strchr(tmp,',')) != NULL )
+ *end++ = '\0';
+ if ( Strcmp( tmp, lang ) == 0 ) {
+ strncpy(buf,set,100);
+ buf[99] = '\0';
+ Xfree(start);
+ return buf;
+ }
+ tmp = end;
+ }
+ tmp = next;
+ } while ( tmp && *tmp );
+ Xfree(start);
+ return NULL;
+}
+#else
+char *
+_XkbGetCharset(void)
+{
+ char *tmp;
+ XLCd lcd;
+
+ tmp = getenv( "_XKB_CHARSET" );
+ if ( tmp )
+ return tmp;
+
+ lcd = _XlcCurrentLC();
+ if ( lcd )
+ return XLC_PUBLIC(lcd,encoding_name);
+
+ return NULL;
+}
+#endif
+
diff --git a/libX11/src/xkb/XKBExtDev.c b/libX11/src/xkb/XKBExtDev.c
index e8157b95b..b762747e6 100644
--- a/libX11/src/xkb/XKBExtDev.c
+++ b/libX11/src/xkb/XKBExtDev.c
@@ -1,821 +1,819 @@
-/************************************************************
-Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#define NEED_MAP_READERS
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-#include <X11/extensions/XI.h>
-
-/***====================================================================***/
-
-extern void
-XkbNoteDeviceChanges( XkbDeviceChangesPtr old,
- XkbExtensionDeviceNotifyEvent * new,
- unsigned int wanted)
-{
- if ((!old)||(!new)||(!wanted)||((new->reason&wanted)==0))
- return;
- if ((wanted&new->reason)&XkbXI_ButtonActionsMask) {
- if (old->changed&XkbXI_ButtonActionsMask) {
- int first,last,newLast;
- if (new->first_btn<old->first_btn)
- first= new->first_btn;
- else first= old->first_btn;
- last= old->first_btn+old->num_btns-1;
- newLast= new->first_btn+new->num_btns-1;
- if (newLast>last)
- last= newLast;
- old->first_btn= first;
- old->num_btns= (last-first)+1;
- }
- else {
- old->changed|= XkbXI_ButtonActionsMask;
- old->first_btn= new->first_btn;
- old->num_btns= new->num_btns;
- }
- }
- if ((wanted&new->reason)&XkbXI_IndicatorsMask) {
- XkbDeviceLedChangesPtr this;
- if (old->changed&XkbXI_IndicatorsMask) {
- XkbDeviceLedChangesPtr found;
- found= NULL;
- for (this= &old->leds;this&&(!found);this=this->next) {
- if ((this->led_class==new->led_class)&&
- (this->led_id==new->led_id)) {
- found= this;
- }
- }
- if (!found) {
- found= _XkbTypedCalloc(1,XkbDeviceLedChangesRec);
- if (!found)
- return;
- found->next= old->leds.next;
- found->led_class= new->led_class;
- found->led_id= new->led_id;
- old->leds.next= found;
- }
- if ((wanted&new->reason)&XkbXI_IndicatorNamesMask)
- found->defined= new->leds_defined;
- }
- else {
- old->changed|= ((wanted&new->reason)&XkbXI_IndicatorsMask);
- old->leds.led_class= new->led_class;
- old->leds.led_id= new->led_id;
- old->leds.defined= new->leds_defined;
- if (old->leds.next) {
- XkbDeviceLedChangesPtr next;
- for (this=old->leds.next;this;this=next) {
- next= this->next;
- _XkbFree(this);
- }
- old->leds.next= NULL;
- }
- }
- }
- return;
-}
-
-/***====================================================================***/
-
-static Status
-_XkbReadDeviceLedInfo( XkbReadBufferPtr buf,
- unsigned present,
- XkbDeviceInfoPtr devi)
-{
-register unsigned i,bit;
-XkbDeviceLedInfoPtr devli;
-xkbDeviceLedsWireDesc * wireli;
-
- wireli= _XkbGetTypedRdBufPtr(buf,1,xkbDeviceLedsWireDesc);
- if (!wireli)
- return BadLength;
- devli= XkbAddDeviceLedInfo(devi,wireli->ledClass,wireli->ledID);
- if (!devli)
- return BadAlloc;
- devli->phys_indicators= wireli->physIndicators;
-
- if (present&XkbXI_IndicatorStateMask)
- devli->state= wireli->state;
-
- if (present&XkbXI_IndicatorNamesMask) {
- devli->names_present= wireli->namesPresent;
- if (devli->names_present) {
- for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
- if (wireli->namesPresent&bit) {
- if (!_XkbCopyFromReadBuffer(buf,(char *)&devli->names[i],4))
- return BadLength;
- }
- }
- }
- }
-
- if (present&XkbXI_IndicatorMapsMask) {
- devli->maps_present= wireli->mapsPresent;
- if (devli->maps_present) {
- XkbIndicatorMapPtr im;
- xkbIndicatorMapWireDesc * wireim;
- for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
- if (wireli->mapsPresent&bit) {
- wireim= _XkbGetTypedRdBufPtr(buf,1,xkbIndicatorMapWireDesc);
- if (!wireim)
- return BadAlloc;
- im= &devli->maps[i];
- im->flags= wireim->flags;
- im->which_groups= wireim->whichGroups;
- im->groups= wireim->groups;
- im->which_mods= wireim->whichMods;
- im->mods.mask= wireim->mods;
- im->mods.real_mods= wireim->realMods;
- im->mods.vmods= wireim->virtualMods;
- im->ctrls= wireim->ctrls;
- }
- }
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadGetDeviceInfoReply( Display * dpy,
- xkbGetDeviceInfoReply * rep,
- XkbDeviceInfoPtr devi)
-{
-XkbReadBufferRec buf;
-XkbAction * act;
-int tmp;
-
- if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
- return BadAlloc;
-
- if ((rep->totalBtns>0)&&(rep->totalBtns!=devi->num_btns)) {
- tmp= XkbResizeDeviceButtonActions(devi,rep->totalBtns);
- if (tmp!=Success)
- return tmp;
- }
- if (rep->nBtnsWanted>0) {
- act= &devi->btn_acts[rep->firstBtnWanted];
- bzero((char *)act,(rep->nBtnsWanted*sizeof(XkbAction)));
- }
- if (devi->name!=NULL)
- _XkbFree(devi->name);
- if (!_XkbGetReadBufferCountedString(&buf,&devi->name))
- goto BAILOUT;
- if (rep->nBtnsRtrn>0) {
- int size;
- act= &devi->btn_acts[rep->firstBtnRtrn];
- size= rep->nBtnsRtrn*SIZEOF(xkbActionWireDesc);
- if (!_XkbCopyFromReadBuffer(&buf,(char *)act,size))
- goto BAILOUT;
- }
- if (rep->nDeviceLedFBs>0) {
- register int i;
- for (i=0;i<rep->nDeviceLedFBs;i++) {
- if ((tmp= _XkbReadDeviceLedInfo(&buf,rep->present,devi))!=Success)
- return tmp;
- }
- }
- tmp= _XkbFreeReadBuffer(&buf);
- if (tmp)
- fprintf(stderr,"GetDeviceInfo! Bad length (%d extra bytes)\n",tmp);
- if (tmp || buf.error)
- return BadLength;
- return Success;
-BAILOUT:
- _XkbFreeReadBuffer(&buf);
- return BadLength;
-}
-
-XkbDeviceInfoPtr
-XkbGetDeviceInfo( Display * dpy,
- unsigned which,
- unsigned deviceSpec,
- unsigned class,
- unsigned id)
-{
- register xkbGetDeviceInfoReq * req;
- xkbGetDeviceInfoReply rep;
- Status status;
- XkbDeviceInfoPtr devi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return NULL;
- LockDisplay(dpy);
- GetReq(kbGetDeviceInfo, req);
- req->reqType = dpy->xkb_info->codes->major_opcode;
- req->xkbReqType = X_kbGetDeviceInfo;
- req->deviceSpec = deviceSpec;
- req->wanted= which;
- req->allBtns= ((which&XkbXI_ButtonActionsMask)!=0);
- req->firstBtn= req->nBtns= 0;
- req->ledClass= class;
- req->ledID= id;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return NULL;
- }
- devi= XkbAllocDeviceInfo(rep.deviceID,rep.totalBtns,rep.nDeviceLedFBs);
- if (devi) {
- devi->supported= rep.supported;
- devi->unsupported= rep.unsupported;
- devi->type= rep.devType;
- devi->has_own_state= rep.hasOwnState;
- devi->dflt_kbd_fb = rep.dfltKbdFB;
- devi->dflt_led_fb = rep.dfltLedFB;
- status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
- if (status!=Success) {
- XkbFreeDeviceInfo(devi,XkbXI_AllDeviceFeaturesMask,True);
- devi= NULL;
- }
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return devi;
-}
-
-Status
-XkbGetDeviceInfoChanges( Display * dpy,
- XkbDeviceInfoPtr devi,
- XkbDeviceChangesPtr changes)
-{
- register xkbGetDeviceInfoReq * req;
- xkbGetDeviceInfoReply rep;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadMatch;
- if ((changes->changed&XkbXI_AllDeviceFeaturesMask)==0)
- return Success;
- changes->changed&= ~XkbXI_AllDeviceFeaturesMask;
- status= Success;
- LockDisplay(dpy);
- while ((changes->changed)&&(status==Success)) {
- GetReq(kbGetDeviceInfo, req);
- req->reqType = dpy->xkb_info->codes->major_opcode;
- req->xkbReqType = X_kbGetDeviceInfo;
- req->deviceSpec = devi->device_spec;
- req->wanted= changes->changed;
- req->allBtns= False;
- if (changes->changed&XkbXI_ButtonActionsMask) {
- req->firstBtn= changes->first_btn;
- req->nBtns= changes->num_btns;
- changes->changed&= ~XkbXI_ButtonActionsMask;
- }
- else req->firstBtn= req->nBtns= 0;
- if (changes->changed&XkbXI_IndicatorsMask) {
- req->ledClass= changes->leds.led_class;
- req->ledID= changes->leds.led_id;
- if (changes->leds.next==NULL)
- changes->changed&= ~XkbXI_IndicatorsMask;
- else {
- XkbDeviceLedChangesPtr next;
- next= changes->leds.next;
- changes->leds= *next;
- _XkbFree(next);
- }
- }
- else {
- req->ledClass= XkbDfltXIClass;
- req->ledID= XkbDfltXIId;
- }
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- status= BadLength;
- break;
- }
- devi->supported|= rep.supported;
- devi->unsupported|= rep.unsupported;
- devi->type= rep.devType;
- status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetDeviceButtonActions( Display * dpy,
- XkbDeviceInfoPtr devi,
- Bool all,
- unsigned int first,
- unsigned int num)
-{
- register xkbGetDeviceInfoReq * req;
- xkbGetDeviceInfoReply rep;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadMatch;
- if (!devi)
- return BadValue;
- LockDisplay(dpy);
- GetReq(kbGetDeviceInfo, req);
- req->reqType = dpy->xkb_info->codes->major_opcode;
- req->xkbReqType = X_kbGetDeviceInfo;
- req->deviceSpec = devi->device_spec;
- req->wanted= XkbXI_ButtonActionsMask;
- req->allBtns= all;
- req->firstBtn= first;
- req->nBtns= num;
- req->ledClass= XkbDfltXIClass;
- req->ledID= XkbDfltXIId;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadLength;
- }
- devi->type= rep.devType;
- devi->supported= rep.supported;
- devi->unsupported= rep.unsupported;
- status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetDeviceLedInfo( Display * dpy,
- XkbDeviceInfoPtr devi,
- unsigned int ledClass,
- unsigned int ledId,
- unsigned int which)
-{
- register xkbGetDeviceInfoReq * req;
- xkbGetDeviceInfoReply rep;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadMatch;
- if (((which&XkbXI_IndicatorsMask)==0)||(which&(~XkbXI_IndicatorsMask)))
- return BadMatch;
- if (!devi)
- return BadValue;
- LockDisplay(dpy);
- GetReq(kbGetDeviceInfo, req);
- req->reqType = dpy->xkb_info->codes->major_opcode;
- req->xkbReqType = X_kbGetDeviceInfo;
- req->deviceSpec = devi->device_spec;
- req->wanted= which;
- req->allBtns= False;
- req->firstBtn= req->nBtns= 0;
- req->ledClass= ledClass;
- req->ledID= ledId;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadLength;
- }
- devi->type= rep.devType;
- devi->supported= rep.supported;
- devi->unsupported= rep.unsupported;
- status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-/***====================================================================***/
-
-typedef struct _LedInfoStuff {
- Bool used;
- XkbDeviceLedInfoPtr devli;
-} LedInfoStuff;
-
-typedef struct _SetLedStuff {
- unsigned wanted;
- int num_info;
- int dflt_class;
- LedInfoStuff * dflt_kbd_fb;
- LedInfoStuff * dflt_led_fb;
- LedInfoStuff * info;
-} SetLedStuff;
-
-static void
-_InitLedStuff(SetLedStuff *stuff,unsigned wanted,XkbDeviceInfoPtr devi)
-{
-int i;
-register XkbDeviceLedInfoPtr devli;
-
- bzero(stuff,sizeof(SetLedStuff));
- stuff->wanted= wanted;
- stuff->dflt_class= XkbXINone;
- if ((devi->num_leds<1)||((wanted&XkbXI_IndicatorsMask)==0))
- return;
- stuff->info= _XkbTypedCalloc(devi->num_leds,LedInfoStuff);
- if (!stuff->info)
- return;
- stuff->num_info= devi->num_leds;
- for (devli=&devi->leds[0],i=0;i<devi->num_leds;i++,devli++) {
- stuff->info[i].devli= devli;
- if (devli->led_class==KbdFeedbackClass) {
- stuff->dflt_class= KbdFeedbackClass;
- if (stuff->dflt_kbd_fb==NULL)
- stuff->dflt_kbd_fb= &stuff->info[i];
- }
- else if (devli->led_class==LedFeedbackClass) {
- if (stuff->dflt_class==XkbXINone)
- stuff->dflt_class= LedFeedbackClass;
- if (stuff->dflt_led_fb==NULL)
- stuff->dflt_led_fb= &stuff->info[i];
- }
- }
- return;
-}
-
-static void
-_FreeLedStuff(SetLedStuff *stuff)
-{
- if ((stuff->num_info>0)&&(stuff->info!=NULL))
- _XkbFree(stuff->info);
- bzero(stuff,sizeof(SetLedStuff));
- return;
-}
-
-static int
-_XkbSizeLedInfo(unsigned changed,XkbDeviceLedInfoPtr devli)
-{
-register int i,size;
-register unsigned bit,namesNeeded,mapsNeeded;
-
- size= SIZEOF(xkbDeviceLedsWireDesc);
- namesNeeded= mapsNeeded= 0;
- if (changed&XkbXI_IndicatorNamesMask)
- namesNeeded= devli->names_present;
- if (changed&XkbXI_IndicatorMapsMask)
- mapsNeeded= devli->maps_present;
- if ((namesNeeded)||(mapsNeeded)) {
- for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
- if (namesNeeded&bit)
- size+= 4; /* atoms are 4 bytes on the wire */
- if (mapsNeeded&bit)
- size+= SIZEOF(xkbIndicatorMapWireDesc);
- }
- }
- return size;
-}
-
-static Bool
-_SizeMatches( SetLedStuff * stuff,
- XkbDeviceLedChangesPtr changes,
- int * sz_rtrn,
- int * nleds_rtrn)
-{
-int i,nMatch,class,id;
-LedInfoStuff * linfo;
-Bool match;
-
- nMatch= 0;
- class= changes->led_class;
- id= changes->led_id;
- if (class==XkbDfltXIClass)
- class= stuff->dflt_class;
- for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) {
- XkbDeviceLedInfoPtr devli;
- LedInfoStuff * dflt;
-
- devli= linfo->devli;
- match= ((class==devli->led_class)||(class==XkbAllXIClasses));
- if (devli->led_class==KbdFeedbackClass) dflt= stuff->dflt_kbd_fb;
- else dflt= stuff->dflt_led_fb;
- match = (match && (id == devli->led_id)) ||
- (id == XkbAllXIIds) ||
- ((id == XkbDfltXIId) &&
- (linfo == dflt));
- if (match) {
- if (!linfo->used) {
- *sz_rtrn+= _XkbSizeLedInfo(stuff->wanted,devli);
- *nleds_rtrn+= 1;
- linfo->used= True;
- if ((class!=XkbAllXIClasses)&&(id!=XkbAllXIIds))
- return True;
- }
- nMatch++;
- linfo->used= True;
- }
- }
- return (nMatch>0);
-}
-
-/***====================================================================***/
-
-
-static Status
-_XkbSetDeviceInfoSize( XkbDeviceInfoPtr devi,
- XkbDeviceChangesPtr changes,
- SetLedStuff * stuff,
- int * sz_rtrn,
- int * num_leds_rtrn)
-{
- *sz_rtrn= 0;
- if ((changes->changed&XkbXI_ButtonActionsMask)&&(changes->num_btns>0)) {
- if (!XkbXI_LegalDevBtn(devi,(changes->first_btn+changes->num_btns-1)))
- return BadMatch;
- *sz_rtrn+= changes->num_btns*SIZEOF(xkbActionWireDesc);
- }
- else {
- changes->changed&= ~XkbXI_ButtonActionsMask;
- changes->first_btn= changes->num_btns= 0;
- }
- if ((changes->changed&XkbXI_IndicatorsMask)&&
- XkbLegalXILedClass(changes->leds.led_class)) {
- XkbDeviceLedChangesPtr leds;
-
- for (leds=&changes->leds;leds!=NULL;leds= leds->next) {
- if (!_SizeMatches(stuff,leds,sz_rtrn,num_leds_rtrn))
- return BadMatch;
- }
- }
- else {
- changes->changed&= ~XkbXI_IndicatorsMask;
- *num_leds_rtrn= 0;
- }
- return Success;
-}
-
-static char *
-_XkbWriteLedInfo(char *wire,unsigned changed,XkbDeviceLedInfoPtr devli)
-{
-register int i;
-register unsigned bit,namesNeeded,mapsNeeded;
-xkbDeviceLedsWireDesc * lwire;
-
- namesNeeded= mapsNeeded= 0;
- if (changed&XkbXI_IndicatorNamesMask)
- namesNeeded= devli->names_present;
- if (changed&XkbXI_IndicatorMapsMask)
- mapsNeeded= devli->maps_present;
-
- lwire= (xkbDeviceLedsWireDesc *)wire;
- lwire->ledClass= devli->led_class;
- lwire->ledID= devli->led_id;
- lwire->namesPresent= namesNeeded;
- lwire->mapsPresent= mapsNeeded;
- lwire->physIndicators= devli->phys_indicators;
- lwire->state= devli->state;
- wire= (char *)&lwire[1];
- if (namesNeeded) {
- CARD32 *awire;
- awire= (CARD32 *)wire;
- for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
- if (namesNeeded&bit) {
- *awire= (CARD32)devli->names[i];
- awire++;
- }
- }
- wire= (char *)awire;
- }
- if (mapsNeeded) {
- xkbIndicatorMapWireDesc *mwire;
-
- mwire= (xkbIndicatorMapWireDesc *)wire;
- for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
- if (mapsNeeded&bit) {
- XkbIndicatorMapPtr map;
- map= &devli->maps[i];
- mwire->flags= map->flags;
- mwire->whichGroups= map->which_groups;
- mwire->groups= map->groups;
- mwire->whichMods= map->which_mods;
- mwire->mods= map->mods.mask;
- mwire->realMods= map->mods.real_mods;
- mwire->virtualMods= map->mods.vmods;
- mwire->ctrls= map->ctrls;
- mwire++;
- }
- }
- wire= (char *)mwire;
- }
- return wire;
-}
-
-
-static int
-_XkbWriteSetDeviceInfo( char * wire,
- XkbDeviceChangesPtr changes,
- SetLedStuff * stuff,
- XkbDeviceInfoPtr devi)
-{
-char *start;
-
- start= wire;
- if (changes->changed&XkbXI_ButtonActionsMask) {
- int size;
- size= changes->num_btns*SIZEOF(xkbActionWireDesc);
- memcpy(wire,(char *)&devi->btn_acts[changes->first_btn],size);
- wire+= size;
- }
- if (changes->changed&XkbXI_IndicatorsMask) {
- register int i;
- register LedInfoStuff *linfo;
-
- for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) {
- if (linfo->used) {
- register char *new_wire;
- new_wire= _XkbWriteLedInfo(wire,stuff->wanted,linfo->devli);
- if (!new_wire)
- return wire-start;
- wire= new_wire;
- }
- }
- }
- return wire-start;
-}
-
-Bool
-XkbSetDeviceInfo( Display * dpy,
- unsigned which,
- XkbDeviceInfoPtr devi)
-{
- register xkbSetDeviceInfoReq *req;
- Status ok = 0;
- int size,nLeds;
- XkbInfoPtr xkbi;
- XkbDeviceChangesRec changes;
- SetLedStuff lstuff;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- if ((!devi) || (which&(~XkbXI_AllDeviceFeaturesMask)) ||
- ((which&XkbXI_ButtonActionsMask)&&(!XkbXI_DevHasBtnActs(devi)))||
- ((which&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi))))
- return False;
-
- bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
- changes.changed= which;
- changes.first_btn= 0;
- changes.num_btns= devi->num_btns;
- changes.leds.led_class= XkbAllXIClasses;
- changes.leds.led_id= XkbAllXIIds;
- changes.leds.defined= 0;
- size= nLeds= 0;
- _InitLedStuff(&lstuff,changes.changed,devi);
- if (_XkbSetDeviceInfoSize(devi,&changes,&lstuff,&size,&nLeds)!=Success)
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetDeviceInfo, req);
- req->length+= size/4;
- req->reqType= xkbi->codes->major_opcode;
- req->xkbReqType= X_kbSetDeviceInfo;
- req->deviceSpec= devi->device_spec;
- req->firstBtn= changes.first_btn;
- req->nBtns= changes.num_btns;
- req->change= changes.changed;
- req->nDeviceLedFBs= nLeds;
- if (size>0) {
- char * wire;
- BufAlloc(char *,wire,size);
- ok= (wire!=NULL)&&
- (_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- _FreeLedStuff(&lstuff);
- /* 12/11/95 (ef) -- XXX!! should clear changes here */
- return ok;
-}
-
-Bool
-XkbChangeDeviceInfo( Display * dpy,
- XkbDeviceInfoPtr devi,
- XkbDeviceChangesPtr changes)
-{
- register xkbSetDeviceInfoReq *req;
- Status ok = 0;
- int size,nLeds;
- XkbInfoPtr xkbi;
- SetLedStuff lstuff;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- if ((!devi) || (changes->changed&(~XkbXI_AllDeviceFeaturesMask)) ||
- ((changes->changed&XkbXI_ButtonActionsMask)&&
- (!XkbXI_DevHasBtnActs(devi)))||
- ((changes->changed&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi))))
- return False;
-
- size= nLeds= 0;
- _InitLedStuff(&lstuff,changes->changed,devi);
- if (_XkbSetDeviceInfoSize(devi,changes,&lstuff,&size,&nLeds)!=Success)
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetDeviceInfo, req);
- req->length+= size/4;
- req->reqType= xkbi->codes->major_opcode;
- req->xkbReqType= X_kbSetDeviceInfo;
- req->deviceSpec= devi->device_spec;
- req->firstBtn= changes->first_btn;
- req->nBtns= changes->num_btns;
- req->change= changes->changed;
- req->nDeviceLedFBs= nLeds;
- if (size>0) {
- char * wire;
- BufAlloc(char *,wire,size);
- ok= (wire!=NULL)&&
- (_XkbWriteSetDeviceInfo(wire,changes,&lstuff,devi)==size);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- _FreeLedStuff(&lstuff);
- /* 12/11/95 (ef) -- XXX!! should clear changes here */
- return ok;
-}
-
-Bool
-XkbSetDeviceLedInfo( Display * dpy,
- XkbDeviceInfoPtr devi,
- unsigned ledClass,
- unsigned ledID,
- unsigned which)
-{
- return False;
-}
-
-Bool
-XkbSetDeviceButtonActions( Display * dpy,
- XkbDeviceInfoPtr devi,
- unsigned int first,
- unsigned int nBtns)
-{
- register xkbSetDeviceInfoReq *req;
- Status ok = 0;
- int size,nLeds;
- XkbInfoPtr xkbi;
- XkbDeviceChangesRec changes;
- SetLedStuff lstuff;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- if ((!devi)||(!XkbXI_DevHasBtnActs(devi))||(first+nBtns>devi->num_btns))
- return False;
- if (nBtns==0)
- return True;
-
- bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
- changes.changed= XkbXI_ButtonActionsMask;
- changes.first_btn= first;
- changes.num_btns= nBtns;
- changes.leds.led_class= XkbXINone;
- changes.leds.led_id= XkbXINone;
- changes.leds.defined= 0;
- size= nLeds= 0;
- if (_XkbSetDeviceInfoSize(devi,&changes,NULL,&size,&nLeds)!=Success)
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetDeviceInfo, req);
- req->length+= size/4;
- req->reqType= xkbi->codes->major_opcode;
- req->xkbReqType= X_kbSetDeviceInfo;
- req->deviceSpec= devi->device_spec;
- req->firstBtn= changes.first_btn;
- req->nBtns= changes.num_btns;
- req->change= changes.changed;
- req->nDeviceLedFBs= nLeds;
- if (size>0) {
- char * wire;
- BufAlloc(char *,wire,size);
- ok= (wire!=NULL)&&
- (_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return ok;
-}
+/************************************************************
+Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 <stdio.h>
+#define NEED_MAP_READERS
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+#include <X11/extensions/XI.h>
+
+/***====================================================================***/
+
+extern void
+XkbNoteDeviceChanges( XkbDeviceChangesPtr old,
+ XkbExtensionDeviceNotifyEvent * new,
+ unsigned int wanted)
+{
+ if ((!old)||(!new)||(!wanted)||((new->reason&wanted)==0))
+ return;
+ if ((wanted&new->reason)&XkbXI_ButtonActionsMask) {
+ if (old->changed&XkbXI_ButtonActionsMask) {
+ int first,last,newLast;
+ if (new->first_btn<old->first_btn)
+ first= new->first_btn;
+ else first= old->first_btn;
+ last= old->first_btn+old->num_btns-1;
+ newLast= new->first_btn+new->num_btns-1;
+ if (newLast>last)
+ last= newLast;
+ old->first_btn= first;
+ old->num_btns= (last-first)+1;
+ }
+ else {
+ old->changed|= XkbXI_ButtonActionsMask;
+ old->first_btn= new->first_btn;
+ old->num_btns= new->num_btns;
+ }
+ }
+ if ((wanted&new->reason)&XkbXI_IndicatorsMask) {
+ XkbDeviceLedChangesPtr this;
+ if (old->changed&XkbXI_IndicatorsMask) {
+ XkbDeviceLedChangesPtr found;
+ found= NULL;
+ for (this= &old->leds;this&&(!found);this=this->next) {
+ if ((this->led_class==new->led_class)&&
+ (this->led_id==new->led_id)) {
+ found= this;
+ }
+ }
+ if (!found) {
+ found= _XkbTypedCalloc(1,XkbDeviceLedChangesRec);
+ if (!found)
+ return;
+ found->next= old->leds.next;
+ found->led_class= new->led_class;
+ found->led_id= new->led_id;
+ old->leds.next= found;
+ }
+ if ((wanted&new->reason)&XkbXI_IndicatorNamesMask)
+ found->defined= new->leds_defined;
+ }
+ else {
+ old->changed|= ((wanted&new->reason)&XkbXI_IndicatorsMask);
+ old->leds.led_class= new->led_class;
+ old->leds.led_id= new->led_id;
+ old->leds.defined= new->leds_defined;
+ if (old->leds.next) {
+ XkbDeviceLedChangesPtr next;
+ for (this=old->leds.next;this;this=next) {
+ next= this->next;
+ _XkbFree(this);
+ }
+ old->leds.next= NULL;
+ }
+ }
+ }
+ return;
+}
+
+/***====================================================================***/
+
+static Status
+_XkbReadDeviceLedInfo( XkbReadBufferPtr buf,
+ unsigned present,
+ XkbDeviceInfoPtr devi)
+{
+register unsigned i,bit;
+XkbDeviceLedInfoPtr devli;
+xkbDeviceLedsWireDesc * wireli;
+
+ wireli= _XkbGetTypedRdBufPtr(buf,1,xkbDeviceLedsWireDesc);
+ if (!wireli)
+ return BadLength;
+ devli= XkbAddDeviceLedInfo(devi,wireli->ledClass,wireli->ledID);
+ if (!devli)
+ return BadAlloc;
+ devli->phys_indicators= wireli->physIndicators;
+
+ if (present&XkbXI_IndicatorStateMask)
+ devli->state= wireli->state;
+
+ if (present&XkbXI_IndicatorNamesMask) {
+ devli->names_present= wireli->namesPresent;
+ if (devli->names_present) {
+ for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
+ if (wireli->namesPresent&bit) {
+ if (!_XkbCopyFromReadBuffer(buf,(char *)&devli->names[i],4))
+ return BadLength;
+ }
+ }
+ }
+ }
+
+ if (present&XkbXI_IndicatorMapsMask) {
+ devli->maps_present= wireli->mapsPresent;
+ if (devli->maps_present) {
+ XkbIndicatorMapPtr im;
+ xkbIndicatorMapWireDesc * wireim;
+ for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
+ if (wireli->mapsPresent&bit) {
+ wireim= _XkbGetTypedRdBufPtr(buf,1,xkbIndicatorMapWireDesc);
+ if (!wireim)
+ return BadAlloc;
+ im= &devli->maps[i];
+ im->flags= wireim->flags;
+ im->which_groups= wireim->whichGroups;
+ im->groups= wireim->groups;
+ im->which_mods= wireim->whichMods;
+ im->mods.mask= wireim->mods;
+ im->mods.real_mods= wireim->realMods;
+ im->mods.vmods= wireim->virtualMods;
+ im->ctrls= wireim->ctrls;
+ }
+ }
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadGetDeviceInfoReply( Display * dpy,
+ xkbGetDeviceInfoReply * rep,
+ XkbDeviceInfoPtr devi)
+{
+XkbReadBufferRec buf;
+XkbAction * act;
+int tmp;
+
+ if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
+ return BadAlloc;
+
+ if ((rep->totalBtns>0)&&(rep->totalBtns!=devi->num_btns)) {
+ tmp= XkbResizeDeviceButtonActions(devi,rep->totalBtns);
+ if (tmp!=Success)
+ return tmp;
+ }
+ if (rep->nBtnsWanted>0) {
+ act= &devi->btn_acts[rep->firstBtnWanted];
+ bzero((char *)act,(rep->nBtnsWanted*sizeof(XkbAction)));
+ }
+ if (devi->name!=NULL)
+ _XkbFree(devi->name);
+ if (!_XkbGetReadBufferCountedString(&buf,&devi->name))
+ goto BAILOUT;
+ if (rep->nBtnsRtrn>0) {
+ int size;
+ act= &devi->btn_acts[rep->firstBtnRtrn];
+ size= rep->nBtnsRtrn*SIZEOF(xkbActionWireDesc);
+ if (!_XkbCopyFromReadBuffer(&buf,(char *)act,size))
+ goto BAILOUT;
+ }
+ if (rep->nDeviceLedFBs>0) {
+ register int i;
+ for (i=0;i<rep->nDeviceLedFBs;i++) {
+ if ((tmp= _XkbReadDeviceLedInfo(&buf,rep->present,devi))!=Success)
+ return tmp;
+ }
+ }
+ tmp= _XkbFreeReadBuffer(&buf);
+ if (tmp)
+ fprintf(stderr,"GetDeviceInfo! Bad length (%d extra bytes)\n",tmp);
+ if (tmp || buf.error)
+ return BadLength;
+ return Success;
+BAILOUT:
+ _XkbFreeReadBuffer(&buf);
+ return BadLength;
+}
+
+XkbDeviceInfoPtr
+XkbGetDeviceInfo( Display * dpy,
+ unsigned which,
+ unsigned deviceSpec,
+ unsigned class,
+ unsigned id)
+{
+ register xkbGetDeviceInfoReq * req;
+ xkbGetDeviceInfoReply rep;
+ Status status;
+ XkbDeviceInfoPtr devi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return NULL;
+ LockDisplay(dpy);
+ GetReq(kbGetDeviceInfo, req);
+ req->reqType = dpy->xkb_info->codes->major_opcode;
+ req->xkbReqType = X_kbGetDeviceInfo;
+ req->deviceSpec = deviceSpec;
+ req->wanted= which;
+ req->allBtns= ((which&XkbXI_ButtonActionsMask)!=0);
+ req->firstBtn= req->nBtns= 0;
+ req->ledClass= class;
+ req->ledID= id;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return NULL;
+ }
+ devi= XkbAllocDeviceInfo(rep.deviceID,rep.totalBtns,rep.nDeviceLedFBs);
+ if (devi) {
+ devi->supported= rep.supported;
+ devi->unsupported= rep.unsupported;
+ devi->type= rep.devType;
+ devi->has_own_state= rep.hasOwnState;
+ devi->dflt_kbd_fb = rep.dfltKbdFB;
+ devi->dflt_led_fb = rep.dfltLedFB;
+ status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
+ if (status!=Success) {
+ XkbFreeDeviceInfo(devi,XkbXI_AllDeviceFeaturesMask,True);
+ devi= NULL;
+ }
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return devi;
+}
+
+Status
+XkbGetDeviceInfoChanges( Display * dpy,
+ XkbDeviceInfoPtr devi,
+ XkbDeviceChangesPtr changes)
+{
+ register xkbGetDeviceInfoReq * req;
+ xkbGetDeviceInfoReply rep;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadMatch;
+ if ((changes->changed&XkbXI_AllDeviceFeaturesMask)==0)
+ return Success;
+ changes->changed&= ~XkbXI_AllDeviceFeaturesMask;
+ status= Success;
+ LockDisplay(dpy);
+ while ((changes->changed)&&(status==Success)) {
+ GetReq(kbGetDeviceInfo, req);
+ req->reqType = dpy->xkb_info->codes->major_opcode;
+ req->xkbReqType = X_kbGetDeviceInfo;
+ req->deviceSpec = devi->device_spec;
+ req->wanted= changes->changed;
+ req->allBtns= False;
+ if (changes->changed&XkbXI_ButtonActionsMask) {
+ req->firstBtn= changes->first_btn;
+ req->nBtns= changes->num_btns;
+ changes->changed&= ~XkbXI_ButtonActionsMask;
+ }
+ else req->firstBtn= req->nBtns= 0;
+ if (changes->changed&XkbXI_IndicatorsMask) {
+ req->ledClass= changes->leds.led_class;
+ req->ledID= changes->leds.led_id;
+ if (changes->leds.next==NULL)
+ changes->changed&= ~XkbXI_IndicatorsMask;
+ else {
+ XkbDeviceLedChangesPtr next;
+ next= changes->leds.next;
+ changes->leds= *next;
+ _XkbFree(next);
+ }
+ }
+ else {
+ req->ledClass= XkbDfltXIClass;
+ req->ledID= XkbDfltXIId;
+ }
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ status= BadLength;
+ break;
+ }
+ devi->supported|= rep.supported;
+ devi->unsupported|= rep.unsupported;
+ devi->type= rep.devType;
+ status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetDeviceButtonActions( Display * dpy,
+ XkbDeviceInfoPtr devi,
+ Bool all,
+ unsigned int first,
+ unsigned int num)
+{
+ register xkbGetDeviceInfoReq * req;
+ xkbGetDeviceInfoReply rep;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadMatch;
+ if (!devi)
+ return BadValue;
+ LockDisplay(dpy);
+ GetReq(kbGetDeviceInfo, req);
+ req->reqType = dpy->xkb_info->codes->major_opcode;
+ req->xkbReqType = X_kbGetDeviceInfo;
+ req->deviceSpec = devi->device_spec;
+ req->wanted= XkbXI_ButtonActionsMask;
+ req->allBtns= all;
+ req->firstBtn= first;
+ req->nBtns= num;
+ req->ledClass= XkbDfltXIClass;
+ req->ledID= XkbDfltXIId;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadLength;
+ }
+ devi->type= rep.devType;
+ devi->supported= rep.supported;
+ devi->unsupported= rep.unsupported;
+ status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetDeviceLedInfo( Display * dpy,
+ XkbDeviceInfoPtr devi,
+ unsigned int ledClass,
+ unsigned int ledId,
+ unsigned int which)
+{
+ register xkbGetDeviceInfoReq * req;
+ xkbGetDeviceInfoReply rep;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadMatch;
+ if (((which&XkbXI_IndicatorsMask)==0)||(which&(~XkbXI_IndicatorsMask)))
+ return BadMatch;
+ if (!devi)
+ return BadValue;
+ LockDisplay(dpy);
+ GetReq(kbGetDeviceInfo, req);
+ req->reqType = dpy->xkb_info->codes->major_opcode;
+ req->xkbReqType = X_kbGetDeviceInfo;
+ req->deviceSpec = devi->device_spec;
+ req->wanted= which;
+ req->allBtns= False;
+ req->firstBtn= req->nBtns= 0;
+ req->ledClass= ledClass;
+ req->ledID= ledId;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadLength;
+ }
+ devi->type= rep.devType;
+ devi->supported= rep.supported;
+ devi->unsupported= rep.unsupported;
+ status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+/***====================================================================***/
+
+typedef struct _LedInfoStuff {
+ Bool used;
+ XkbDeviceLedInfoPtr devli;
+} LedInfoStuff;
+
+typedef struct _SetLedStuff {
+ unsigned wanted;
+ int num_info;
+ int dflt_class;
+ LedInfoStuff * dflt_kbd_fb;
+ LedInfoStuff * dflt_led_fb;
+ LedInfoStuff * info;
+} SetLedStuff;
+
+static void
+_InitLedStuff(SetLedStuff *stuff,unsigned wanted,XkbDeviceInfoPtr devi)
+{
+int i;
+register XkbDeviceLedInfoPtr devli;
+
+ bzero(stuff,sizeof(SetLedStuff));
+ stuff->wanted= wanted;
+ stuff->dflt_class= XkbXINone;
+ if ((devi->num_leds<1)||((wanted&XkbXI_IndicatorsMask)==0))
+ return;
+ stuff->info= _XkbTypedCalloc(devi->num_leds,LedInfoStuff);
+ if (!stuff->info)
+ return;
+ stuff->num_info= devi->num_leds;
+ for (devli=&devi->leds[0],i=0;i<devi->num_leds;i++,devli++) {
+ stuff->info[i].devli= devli;
+ if (devli->led_class==KbdFeedbackClass) {
+ stuff->dflt_class= KbdFeedbackClass;
+ if (stuff->dflt_kbd_fb==NULL)
+ stuff->dflt_kbd_fb= &stuff->info[i];
+ }
+ else if (devli->led_class==LedFeedbackClass) {
+ if (stuff->dflt_class==XkbXINone)
+ stuff->dflt_class= LedFeedbackClass;
+ if (stuff->dflt_led_fb==NULL)
+ stuff->dflt_led_fb= &stuff->info[i];
+ }
+ }
+ return;
+}
+
+static void
+_FreeLedStuff(SetLedStuff *stuff)
+{
+ if ((stuff->num_info>0)&&(stuff->info!=NULL))
+ _XkbFree(stuff->info);
+ bzero(stuff,sizeof(SetLedStuff));
+ return;
+}
+
+static int
+_XkbSizeLedInfo(unsigned changed,XkbDeviceLedInfoPtr devli)
+{
+register int i,size;
+register unsigned bit,namesNeeded,mapsNeeded;
+
+ size= SIZEOF(xkbDeviceLedsWireDesc);
+ namesNeeded= mapsNeeded= 0;
+ if (changed&XkbXI_IndicatorNamesMask)
+ namesNeeded= devli->names_present;
+ if (changed&XkbXI_IndicatorMapsMask)
+ mapsNeeded= devli->maps_present;
+ if ((namesNeeded)||(mapsNeeded)) {
+ for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
+ if (namesNeeded&bit)
+ size+= 4; /* atoms are 4 bytes on the wire */
+ if (mapsNeeded&bit)
+ size+= SIZEOF(xkbIndicatorMapWireDesc);
+ }
+ }
+ return size;
+}
+
+static Bool
+_SizeMatches( SetLedStuff * stuff,
+ XkbDeviceLedChangesPtr changes,
+ int * sz_rtrn,
+ int * nleds_rtrn)
+{
+int i,nMatch,class,id;
+LedInfoStuff * linfo;
+Bool match;
+
+ nMatch= 0;
+ class= changes->led_class;
+ id= changes->led_id;
+ if (class==XkbDfltXIClass)
+ class= stuff->dflt_class;
+ for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) {
+ XkbDeviceLedInfoPtr devli;
+ LedInfoStuff * dflt;
+
+ devli= linfo->devli;
+ match= ((class==devli->led_class)||(class==XkbAllXIClasses));
+ if (devli->led_class==KbdFeedbackClass) dflt= stuff->dflt_kbd_fb;
+ else dflt= stuff->dflt_led_fb;
+ match = (match && (id == devli->led_id)) ||
+ (id == XkbAllXIIds) ||
+ ((id == XkbDfltXIId) &&
+ (linfo == dflt));
+ if (match) {
+ if (!linfo->used) {
+ *sz_rtrn+= _XkbSizeLedInfo(stuff->wanted,devli);
+ *nleds_rtrn+= 1;
+ linfo->used= True;
+ if ((class!=XkbAllXIClasses)&&(id!=XkbAllXIIds))
+ return True;
+ }
+ nMatch++;
+ linfo->used= True;
+ }
+ }
+ return (nMatch>0);
+}
+
+/***====================================================================***/
+
+
+static Status
+_XkbSetDeviceInfoSize( XkbDeviceInfoPtr devi,
+ XkbDeviceChangesPtr changes,
+ SetLedStuff * stuff,
+ int * sz_rtrn,
+ int * num_leds_rtrn)
+{
+ *sz_rtrn= 0;
+ if ((changes->changed&XkbXI_ButtonActionsMask)&&(changes->num_btns>0)) {
+ if (!XkbXI_LegalDevBtn(devi,(changes->first_btn+changes->num_btns-1)))
+ return BadMatch;
+ *sz_rtrn+= changes->num_btns*SIZEOF(xkbActionWireDesc);
+ }
+ else {
+ changes->changed&= ~XkbXI_ButtonActionsMask;
+ changes->first_btn= changes->num_btns= 0;
+ }
+ if ((changes->changed&XkbXI_IndicatorsMask)&&
+ XkbLegalXILedClass(changes->leds.led_class)) {
+ XkbDeviceLedChangesPtr leds;
+
+ for (leds=&changes->leds;leds!=NULL;leds= leds->next) {
+ if (!_SizeMatches(stuff,leds,sz_rtrn,num_leds_rtrn))
+ return BadMatch;
+ }
+ }
+ else {
+ changes->changed&= ~XkbXI_IndicatorsMask;
+ *num_leds_rtrn= 0;
+ }
+ return Success;
+}
+
+static char *
+_XkbWriteLedInfo(char *wire,unsigned changed,XkbDeviceLedInfoPtr devli)
+{
+register int i;
+register unsigned bit,namesNeeded,mapsNeeded;
+xkbDeviceLedsWireDesc * lwire;
+
+ namesNeeded= mapsNeeded= 0;
+ if (changed&XkbXI_IndicatorNamesMask)
+ namesNeeded= devli->names_present;
+ if (changed&XkbXI_IndicatorMapsMask)
+ mapsNeeded= devli->maps_present;
+
+ lwire= (xkbDeviceLedsWireDesc *)wire;
+ lwire->ledClass= devli->led_class;
+ lwire->ledID= devli->led_id;
+ lwire->namesPresent= namesNeeded;
+ lwire->mapsPresent= mapsNeeded;
+ lwire->physIndicators= devli->phys_indicators;
+ lwire->state= devli->state;
+ wire= (char *)&lwire[1];
+ if (namesNeeded) {
+ CARD32 *awire;
+ awire= (CARD32 *)wire;
+ for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
+ if (namesNeeded&bit) {
+ *awire= (CARD32)devli->names[i];
+ awire++;
+ }
+ }
+ wire= (char *)awire;
+ }
+ if (mapsNeeded) {
+ xkbIndicatorMapWireDesc *mwire;
+
+ mwire= (xkbIndicatorMapWireDesc *)wire;
+ for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
+ if (mapsNeeded&bit) {
+ XkbIndicatorMapPtr map;
+ map= &devli->maps[i];
+ mwire->flags= map->flags;
+ mwire->whichGroups= map->which_groups;
+ mwire->groups= map->groups;
+ mwire->whichMods= map->which_mods;
+ mwire->mods= map->mods.mask;
+ mwire->realMods= map->mods.real_mods;
+ mwire->virtualMods= map->mods.vmods;
+ mwire->ctrls= map->ctrls;
+ mwire++;
+ }
+ }
+ wire= (char *)mwire;
+ }
+ return wire;
+}
+
+
+static int
+_XkbWriteSetDeviceInfo( char * wire,
+ XkbDeviceChangesPtr changes,
+ SetLedStuff * stuff,
+ XkbDeviceInfoPtr devi)
+{
+char *start;
+
+ start= wire;
+ if (changes->changed&XkbXI_ButtonActionsMask) {
+ int size;
+ size= changes->num_btns*SIZEOF(xkbActionWireDesc);
+ memcpy(wire,(char *)&devi->btn_acts[changes->first_btn],size);
+ wire+= size;
+ }
+ if (changes->changed&XkbXI_IndicatorsMask) {
+ register int i;
+ register LedInfoStuff *linfo;
+
+ for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) {
+ if (linfo->used) {
+ register char *new_wire;
+ new_wire= _XkbWriteLedInfo(wire,stuff->wanted,linfo->devli);
+ if (!new_wire)
+ return wire-start;
+ wire= new_wire;
+ }
+ }
+ }
+ return wire-start;
+}
+
+Bool
+XkbSetDeviceInfo( Display * dpy,
+ unsigned which,
+ XkbDeviceInfoPtr devi)
+{
+ register xkbSetDeviceInfoReq *req;
+ Status ok = 0;
+ int size,nLeds;
+ XkbInfoPtr xkbi;
+ XkbDeviceChangesRec changes;
+ SetLedStuff lstuff;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ if ((!devi) || (which&(~XkbXI_AllDeviceFeaturesMask)) ||
+ ((which&XkbXI_ButtonActionsMask)&&(!XkbXI_DevHasBtnActs(devi)))||
+ ((which&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi))))
+ return False;
+
+ bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
+ changes.changed= which;
+ changes.first_btn= 0;
+ changes.num_btns= devi->num_btns;
+ changes.leds.led_class= XkbAllXIClasses;
+ changes.leds.led_id= XkbAllXIIds;
+ changes.leds.defined= 0;
+ size= nLeds= 0;
+ _InitLedStuff(&lstuff,changes.changed,devi);
+ if (_XkbSetDeviceInfoSize(devi,&changes,&lstuff,&size,&nLeds)!=Success)
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetDeviceInfo, req);
+ req->length+= size/4;
+ req->reqType= xkbi->codes->major_opcode;
+ req->xkbReqType= X_kbSetDeviceInfo;
+ req->deviceSpec= devi->device_spec;
+ req->firstBtn= changes.first_btn;
+ req->nBtns= changes.num_btns;
+ req->change= changes.changed;
+ req->nDeviceLedFBs= nLeds;
+ if (size>0) {
+ char * wire;
+ BufAlloc(char *,wire,size);
+ ok= (wire!=NULL)&&
+ (_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ _FreeLedStuff(&lstuff);
+ /* 12/11/95 (ef) -- XXX!! should clear changes here */
+ return ok;
+}
+
+Bool
+XkbChangeDeviceInfo( Display * dpy,
+ XkbDeviceInfoPtr devi,
+ XkbDeviceChangesPtr changes)
+{
+ register xkbSetDeviceInfoReq *req;
+ Status ok = 0;
+ int size,nLeds;
+ XkbInfoPtr xkbi;
+ SetLedStuff lstuff;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ if ((!devi) || (changes->changed&(~XkbXI_AllDeviceFeaturesMask)) ||
+ ((changes->changed&XkbXI_ButtonActionsMask)&&
+ (!XkbXI_DevHasBtnActs(devi)))||
+ ((changes->changed&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi))))
+ return False;
+
+ size= nLeds= 0;
+ _InitLedStuff(&lstuff,changes->changed,devi);
+ if (_XkbSetDeviceInfoSize(devi,changes,&lstuff,&size,&nLeds)!=Success)
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetDeviceInfo, req);
+ req->length+= size/4;
+ req->reqType= xkbi->codes->major_opcode;
+ req->xkbReqType= X_kbSetDeviceInfo;
+ req->deviceSpec= devi->device_spec;
+ req->firstBtn= changes->first_btn;
+ req->nBtns= changes->num_btns;
+ req->change= changes->changed;
+ req->nDeviceLedFBs= nLeds;
+ if (size>0) {
+ char * wire;
+ BufAlloc(char *,wire,size);
+ ok= (wire!=NULL)&&
+ (_XkbWriteSetDeviceInfo(wire,changes,&lstuff,devi)==size);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ _FreeLedStuff(&lstuff);
+ /* 12/11/95 (ef) -- XXX!! should clear changes here */
+ return ok;
+}
+
+Bool
+XkbSetDeviceLedInfo( Display * dpy,
+ XkbDeviceInfoPtr devi,
+ unsigned ledClass,
+ unsigned ledID,
+ unsigned which)
+{
+ return False;
+}
+
+Bool
+XkbSetDeviceButtonActions( Display * dpy,
+ XkbDeviceInfoPtr devi,
+ unsigned int first,
+ unsigned int nBtns)
+{
+ register xkbSetDeviceInfoReq *req;
+ Status ok = 0;
+ int size,nLeds;
+ XkbInfoPtr xkbi;
+ XkbDeviceChangesRec changes;
+ SetLedStuff lstuff;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ if ((!devi)||(!XkbXI_DevHasBtnActs(devi))||(first+nBtns>devi->num_btns))
+ return False;
+ if (nBtns==0)
+ return True;
+
+ bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
+ changes.changed= XkbXI_ButtonActionsMask;
+ changes.first_btn= first;
+ changes.num_btns= nBtns;
+ changes.leds.led_class= XkbXINone;
+ changes.leds.led_id= XkbXINone;
+ changes.leds.defined= 0;
+ size= nLeds= 0;
+ if (_XkbSetDeviceInfoSize(devi,&changes,NULL,&size,&nLeds)!=Success)
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetDeviceInfo, req);
+ req->length+= size/4;
+ req->reqType= xkbi->codes->major_opcode;
+ req->xkbReqType= X_kbSetDeviceInfo;
+ req->deviceSpec= devi->device_spec;
+ req->firstBtn= changes.first_btn;
+ req->nBtns= changes.num_btns;
+ req->change= changes.changed;
+ req->nDeviceLedFBs= nLeds;
+ if (size>0) {
+ char * wire;
+ BufAlloc(char *,wire,size);
+ ok= (wire!=NULL)&&
+ (_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return ok;
+}
diff --git a/libX11/src/xkb/XKBGAlloc.c b/libX11/src/xkb/XKBGAlloc.c
index 8f163c340..4cd40016b 100644
--- a/libX11/src/xkb/XKBGAlloc.c
+++ b/libX11/src/xkb/XKBGAlloc.c
@@ -1,1019 +1,1016 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_DIX_CONFIG_H
-#include <dix-config.h>
-#elif defined(HAVE_CONFIG_H)
-#include <config.h>
-#endif
-
-#define NEED_EVENTS
-#define NEED_REPLIES
-
-#ifndef XKB_IN_SERVER
-
-#include <stdio.h>
-#include "Xlibint.h"
-#include "XKBlibint.h"
-#include <X11/extensions/XKBgeom.h>
-#include <X11/extensions/XKBproto.h>
-
-#else
-
-#include <stdio.h>
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
-#include <X11/extensions/XKBgeom.h>
-
-#endif /* XKB_IN_SERVER */
-
-#ifdef X_NOT_POSIX
-#define Size_t unsigned int
-#else
-#define Size_t size_t
-#endif
-
-/***====================================================================***/
-
-static void
-_XkbFreeGeomLeafElems( Bool freeAll,
- int first,
- int count,
- unsigned short * num_inout,
- unsigned short * sz_inout,
- char ** elems,
- unsigned int elem_sz)
-{
- if ((freeAll)||(*elems==NULL)) {
- *num_inout= *sz_inout= 0;
- if (*elems!=NULL) {
- _XkbFree(*elems);
- *elems= NULL;
- }
- return;
- }
-
- if ((first>=(*num_inout))||(first<0)||(count<1))
- return;
-
- if (first+count>=(*num_inout)) {
- /* truncating the array is easy */
- (*num_inout)= first;
- }
- else {
- char * ptr;
- int extra;
- ptr= *elems;
- extra= ((*num_inout)-(first+count))*elem_sz;
- if (extra>0)
- memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],extra);
- (*num_inout)-= count;
- }
- return;
-}
-
-typedef void (*ContentsClearFunc)(
- char * /* priv */
-);
-
-static void
-_XkbFreeGeomNonLeafElems( Bool freeAll,
- int first,
- int count,
- unsigned short * num_inout,
- unsigned short * sz_inout,
- char ** elems,
- unsigned int elem_sz,
- ContentsClearFunc freeFunc)
-{
-register int i;
-register char *ptr;
-
- if (freeAll) {
- first= 0;
- count= (*num_inout);
- }
- else if ((first>=(*num_inout))||(first<0)||(count<1))
- return;
- else if (first+count>(*num_inout))
- count= (*num_inout)-first;
- if (*elems==NULL)
- return;
-
- if (freeFunc) {
- ptr= *elems;
- ptr+= first*elem_sz;
- for (i=0;i<count;i++) {
- (*freeFunc)(ptr);
- ptr+= elem_sz;
- }
- }
- if (freeAll) {
- (*num_inout)= (*sz_inout)= 0;
- if (*elems) {
- _XkbFree(*elems);
- *elems= NULL;
- }
- }
- else if (first+count>=(*num_inout))
- *num_inout= first;
- else {
- i= ((*num_inout)-(first+count))*elem_sz;
- ptr= *elems;
- memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],i);
- (*num_inout)-= count;
- }
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearProperty(char *prop_in)
-{
-XkbPropertyPtr prop= (XkbPropertyPtr)prop_in;
-
- if (prop->name) {
- _XkbFree(prop->name);
- prop->name= NULL;
- }
- if (prop->value) {
- _XkbFree(prop->value);
- prop->value= NULL;
- }
- return;
-}
-
-void
-XkbFreeGeomProperties( XkbGeometryPtr geom,
- int first,
- int count,
- Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &geom->num_properties,&geom->sz_properties,
- (char **)&geom->properties,
- sizeof(XkbPropertyRec),_XkbClearProperty);
- return;
-}
-
-/***====================================================================***/
-
-void
-XkbFreeGeomKeyAliases( XkbGeometryPtr geom,
- int first,
- int count,
- Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll,first,count,
- &geom->num_key_aliases,&geom->sz_key_aliases,
- (char **)&geom->key_aliases,
- sizeof(XkbKeyAliasRec));
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearColor(char *color_in)
-{
-XkbColorPtr color= (XkbColorPtr)color_in;
-
- if (color->spec)
- _XkbFree(color->spec);
- return;
-}
-
-void
-XkbFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &geom->num_colors,&geom->sz_colors,
- (char **)&geom->colors,
- sizeof(XkbColorRec),_XkbClearColor);
- return;
-}
-
-/***====================================================================***/
-
-void
-XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll,first,count,
- &outline->num_points,&outline->sz_points,
- (char **)&outline->points,
- sizeof(XkbPointRec));
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearOutline(char *outline_in)
-{
-XkbOutlinePtr outline= (XkbOutlinePtr)outline_in;
-
- if (outline->points!=NULL)
- XkbFreeGeomPoints(outline,0,outline->num_points,True);
- return;
-}
-
-void
-XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &shape->num_outlines,&shape->sz_outlines,
- (char **)&shape->outlines,
- sizeof(XkbOutlineRec),_XkbClearOutline);
-
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearShape(char *shape_in)
-{
-XkbShapePtr shape= (XkbShapePtr)shape_in;
-
- if (shape->outlines)
- XkbFreeGeomOutlines(shape,0,shape->num_outlines,True);
- return;
-}
-
-void
-XkbFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &geom->num_shapes,&geom->sz_shapes,
- (char **)&geom->shapes,
- sizeof(XkbShapeRec),_XkbClearShape);
- return;
-}
-
-/***====================================================================***/
-
-void
-XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll,first,count,
- &row->num_keys,&row->sz_keys,
- (char **)&row->keys,
- sizeof(XkbOverlayKeyRec));
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearOverlayRow(char *row_in)
-{
-XkbOverlayRowPtr row= (XkbOverlayRowPtr)row_in;
-
- if (row->keys!=NULL)
- XkbFreeGeomOverlayKeys(row,0,row->num_keys,True);
- return;
-}
-
-void
-XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &overlay->num_rows,&overlay->sz_rows,
- (char **)&overlay->rows,
- sizeof(XkbOverlayRowRec),_XkbClearOverlayRow);
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearOverlay(char *overlay_in)
-{
-XkbOverlayPtr overlay= (XkbOverlayPtr)overlay_in;
-
- if (overlay->rows!=NULL)
- XkbFreeGeomOverlayRows(overlay,0,overlay->num_rows,True);
- return;
-}
-
-void
-XkbFreeGeomOverlays(XkbSectionPtr section,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &section->num_overlays,&section->sz_overlays,
- (char **)&section->overlays,
- sizeof(XkbOverlayRec),_XkbClearOverlay);
- return;
-}
-
-/***====================================================================***/
-
-void
-XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll,first,count,
- &row->num_keys,&row->sz_keys,
- (char **)&row->keys,
- sizeof(XkbKeyRec));
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearRow(char *row_in)
-{
-XkbRowPtr row= (XkbRowPtr)row_in;
-
- if (row->keys!=NULL)
- XkbFreeGeomKeys(row,0,row->num_keys,True);
- return;
-}
-
-void
-XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &section->num_rows,&section->sz_rows,
- (char **)&section->rows,
- sizeof(XkbRowRec),_XkbClearRow);
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearSection(char *section_in)
-{
-XkbSectionPtr section= (XkbSectionPtr)section_in;
-
- if (section->rows!=NULL)
- XkbFreeGeomRows(section,0,section->num_rows,True);
- if (section->doodads!=NULL) {
- XkbFreeGeomDoodads(section->doodads,section->num_doodads,True);
- section->doodads= NULL;
- }
- return;
-}
-
-void
-XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &geom->num_sections,&geom->sz_sections,
- (char **)&geom->sections,
- sizeof(XkbSectionRec),_XkbClearSection);
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearDoodad(char *doodad_in)
-{
-XkbDoodadPtr doodad= (XkbDoodadPtr)doodad_in;
-
- switch (doodad->any.type) {
- case XkbTextDoodad:
- {
- if (doodad->text.text!=NULL) {
- _XkbFree(doodad->text.text);
- doodad->text.text= NULL;
- }
- if (doodad->text.font!=NULL) {
- _XkbFree(doodad->text.font);
- doodad->text.font= NULL;
- }
- }
- break;
- case XkbLogoDoodad:
- {
- if (doodad->logo.logo_name!=NULL) {
- _XkbFree(doodad->logo.logo_name);
- doodad->logo.logo_name= NULL;
- }
- }
- break;
- }
- return;
-}
-
-void
-XkbFreeGeomDoodads(XkbDoodadPtr doodads,int nDoodads,Bool freeAll)
-{
-register int i;
-register XkbDoodadPtr doodad;
-
- if (doodads) {
- for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) {
- _XkbClearDoodad((char *)doodad);
- }
- if (freeAll)
- _XkbFree(doodads);
- }
- return;
-}
-
-void
-XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap)
-{
- if (geom==NULL)
- return;
- if (freeMap)
- which= XkbGeomAllMask;
- if ((which&XkbGeomPropertiesMask)&&(geom->properties!=NULL))
- XkbFreeGeomProperties(geom,0,geom->num_properties,True);
- if ((which&XkbGeomColorsMask)&&(geom->colors!=NULL))
- XkbFreeGeomColors(geom,0,geom->num_colors,True);
- if ((which&XkbGeomShapesMask)&&(geom->shapes!=NULL))
- XkbFreeGeomShapes(geom,0,geom->num_shapes,True);
- if ((which&XkbGeomSectionsMask)&&(geom->sections!=NULL))
- XkbFreeGeomSections(geom,0,geom->num_sections,True);
- if ((which&XkbGeomDoodadsMask)&&(geom->doodads!= NULL)) {
- XkbFreeGeomDoodads(geom->doodads,geom->num_doodads,True);
- geom->doodads= NULL;
- geom->num_doodads= geom->sz_doodads= 0;
- }
- if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL))
- XkbFreeGeomKeyAliases(geom,0,geom->num_key_aliases,True);
- if (freeMap) {
- if (geom->label_font!=NULL) {
- _XkbFree(geom->label_font);
- geom->label_font= NULL;
- }
- _XkbFree(geom);
- }
- return;
-}
-
-/***====================================================================***/
-
-static Status
-_XkbGeomAlloc( XPointer * old,
- unsigned short * num,
- unsigned short * total,
- int num_new,
- Size_t sz_elem)
-{
- if (num_new<1)
- return Success;
- if ((*old)==NULL)
- *num= *total= 0;
-
- if ((*num)+num_new<=(*total))
- return Success;
-
- *total= (*num)+num_new;
- if ((*old)!=NULL)
- (*old)= (XPointer)_XkbRealloc((*old),(*total)*sz_elem);
- else (*old)= (XPointer)_XkbCalloc((*total),sz_elem);
- if ((*old)==NULL) {
- *total= *num= 0;
- return BadAlloc;
- }
-
- if (*num>0) {
- char *tmp= (char *)(*old);
- bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem));
- }
- return Success;
-}
-
-#define _XkbAllocProps(g,n) _XkbGeomAlloc((XPointer *)&(g)->properties,\
- &(g)->num_properties,&(g)->sz_properties,\
- (n),sizeof(XkbPropertyRec))
-#define _XkbAllocColors(g,n) _XkbGeomAlloc((XPointer *)&(g)->colors,\
- &(g)->num_colors,&(g)->sz_colors,\
- (n),sizeof(XkbColorRec))
-#define _XkbAllocShapes(g,n) _XkbGeomAlloc((XPointer *)&(g)->shapes,\
- &(g)->num_shapes,&(g)->sz_shapes,\
- (n),sizeof(XkbShapeRec))
-#define _XkbAllocSections(g,n) _XkbGeomAlloc((XPointer *)&(g)->sections,\
- &(g)->num_sections,&(g)->sz_sections,\
- (n),sizeof(XkbSectionRec))
-#define _XkbAllocDoodads(g,n) _XkbGeomAlloc((XPointer *)&(g)->doodads,\
- &(g)->num_doodads,&(g)->sz_doodads,\
- (n),sizeof(XkbDoodadRec))
-#define _XkbAllocKeyAliases(g,n) _XkbGeomAlloc((XPointer *)&(g)->key_aliases,\
- &(g)->num_key_aliases,&(g)->sz_key_aliases,\
- (n),sizeof(XkbKeyAliasRec))
-
-#define _XkbAllocOutlines(s,n) _XkbGeomAlloc((XPointer *)&(s)->outlines,\
- &(s)->num_outlines,&(s)->sz_outlines,\
- (n),sizeof(XkbOutlineRec))
-#define _XkbAllocRows(s,n) _XkbGeomAlloc((XPointer *)&(s)->rows,\
- &(s)->num_rows,&(s)->sz_rows,\
- (n),sizeof(XkbRowRec))
-#define _XkbAllocPoints(o,n) _XkbGeomAlloc((XPointer *)&(o)->points,\
- &(o)->num_points,&(o)->sz_points,\
- (n),sizeof(XkbPointRec))
-#define _XkbAllocKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
- &(r)->num_keys,&(r)->sz_keys,\
- (n),sizeof(XkbKeyRec))
-#define _XkbAllocOverlays(s,n) _XkbGeomAlloc((XPointer *)&(s)->overlays,\
- &(s)->num_overlays,&(s)->sz_overlays,\
- (n),sizeof(XkbOverlayRec))
-#define _XkbAllocOverlayRows(o,n) _XkbGeomAlloc((XPointer *)&(o)->rows,\
- &(o)->num_rows,&(o)->sz_rows,\
- (n),sizeof(XkbOverlayRowRec))
-#define _XkbAllocOverlayKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
- &(r)->num_keys,&(r)->sz_keys,\
- (n),sizeof(XkbOverlayKeyRec))
-
-Status
-XkbAllocGeomProps(XkbGeometryPtr geom,int nProps)
-{
- return _XkbAllocProps(geom,nProps);
-}
-
-Status
-XkbAllocGeomColors(XkbGeometryPtr geom,int nColors)
-{
- return _XkbAllocColors(geom,nColors);
-}
-
-Status
-XkbAllocGeomKeyAliases(XkbGeometryPtr geom,int nKeyAliases)
-{
- return _XkbAllocKeyAliases(geom,nKeyAliases);
-}
-
-Status
-XkbAllocGeomShapes(XkbGeometryPtr geom,int nShapes)
-{
- return _XkbAllocShapes(geom,nShapes);
-}
-
-Status
-XkbAllocGeomSections(XkbGeometryPtr geom,int nSections)
-{
- return _XkbAllocSections(geom,nSections);
-}
-
-Status
-XkbAllocGeomOverlays(XkbSectionPtr section,int nOverlays)
-{
- return _XkbAllocOverlays(section,nOverlays);
-}
-
-Status
-XkbAllocGeomOverlayRows(XkbOverlayPtr overlay,int nRows)
-{
- return _XkbAllocOverlayRows(overlay,nRows);
-}
-
-Status
-XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row,int nKeys)
-{
- return _XkbAllocOverlayKeys(row,nKeys);
-}
-
-Status
-XkbAllocGeomDoodads(XkbGeometryPtr geom,int nDoodads)
-{
- return _XkbAllocDoodads(geom,nDoodads);
-}
-
-Status
-XkbAllocGeomSectionDoodads(XkbSectionPtr section,int nDoodads)
-{
- return _XkbAllocDoodads(section,nDoodads);
-}
-
-Status
-XkbAllocGeomOutlines(XkbShapePtr shape,int nOL)
-{
- return _XkbAllocOutlines(shape,nOL);
-}
-
-Status
-XkbAllocGeomRows(XkbSectionPtr section,int nRows)
-{
- return _XkbAllocRows(section,nRows);
-}
-
-Status
-XkbAllocGeomPoints(XkbOutlinePtr ol,int nPts)
-{
- return _XkbAllocPoints(ol,nPts);
-}
-
-Status
-XkbAllocGeomKeys(XkbRowPtr row,int nKeys)
-{
- return _XkbAllocKeys(row,nKeys);
-}
-
-Status
-XkbAllocGeometry(XkbDescPtr xkb,XkbGeometrySizesPtr sizes)
-{
-XkbGeometryPtr geom;
-Status rtrn;
-
- if (xkb->geom==NULL) {
- xkb->geom= _XkbTypedCalloc(1,XkbGeometryRec);
- if (!xkb->geom)
- return BadAlloc;
- }
- geom= xkb->geom;
- if ((sizes->which&XkbGeomPropertiesMask)&&
- ((rtrn=_XkbAllocProps(geom,sizes->num_properties))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomColorsMask)&&
- ((rtrn=_XkbAllocColors(geom,sizes->num_colors))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomShapesMask)&&
- ((rtrn=_XkbAllocShapes(geom,sizes->num_shapes))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomSectionsMask)&&
- ((rtrn=_XkbAllocSections(geom,sizes->num_sections))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomDoodadsMask)&&
- ((rtrn=_XkbAllocDoodads(geom,sizes->num_doodads))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomKeyAliasesMask)&&
- ((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=Success)) {
- goto BAIL;
- }
- return Success;
-BAIL:
- XkbFreeGeometry(geom,XkbGeomAllMask,True);
- xkb->geom= NULL;
- return rtrn;
-}
-
-/***====================================================================***/
-
-XkbPropertyPtr
-XkbAddGeomProperty(XkbGeometryPtr geom,char *name,char *value)
-{
-register int i;
-register XkbPropertyPtr prop;
-
- if ((!geom)||(!name)||(!value))
- return NULL;
- for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
- if ((prop->name)&&(strcmp(name,prop->name)==0)) {
- if (prop->value)
- _XkbFree(prop->value);
- prop->value= (char *)_XkbAlloc(strlen(value)+1);
- if (prop->value)
- strcpy(prop->value,value);
- return prop;
- }
- }
- if ((geom->num_properties>=geom->sz_properties)&&
- (_XkbAllocProps(geom,1)!=Success)) {
- return NULL;
- }
- prop= &geom->properties[geom->num_properties];
- prop->name= (char *)_XkbAlloc(strlen(name)+1);
- if (!name)
- return NULL;
- strcpy(prop->name,name);
- prop->value= (char *)_XkbAlloc(strlen(value)+1);
- if (!value) {
- _XkbFree(prop->name);
- prop->name= NULL;
- return NULL;
- }
- strcpy(prop->value,value);
- geom->num_properties++;
- return prop;
-}
-
-XkbKeyAliasPtr
-XkbAddGeomKeyAlias(XkbGeometryPtr geom,char *aliasStr,char *realStr)
-{
-register int i;
-register XkbKeyAliasPtr alias;
-
- if ((!geom)||(!aliasStr)||(!realStr)||(!aliasStr[0])||(!realStr[0]))
- return NULL;
- for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) {
- if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) {
- bzero(alias->real,XkbKeyNameLength);
- strncpy(alias->real,realStr,XkbKeyNameLength);
- return alias;
- }
- }
- if ((geom->num_key_aliases>=geom->sz_key_aliases)&&
- (_XkbAllocKeyAliases(geom,1)!=Success)) {
- return NULL;
- }
- alias= &geom->key_aliases[geom->num_key_aliases];
- bzero(alias,sizeof(XkbKeyAliasRec));
- strncpy(alias->alias,aliasStr,XkbKeyNameLength);
- strncpy(alias->real,realStr,XkbKeyNameLength);
- geom->num_key_aliases++;
- return alias;
-}
-
-XkbColorPtr
-XkbAddGeomColor(XkbGeometryPtr geom,char *spec,unsigned int pixel)
-{
-register int i;
-register XkbColorPtr color;
-
- if ((!geom)||(!spec))
- return NULL;
- for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) {
- if ((color->spec)&&(strcmp(color->spec,spec)==0)) {
- color->pixel= pixel;
- return color;
- }
- }
- if ((geom->num_colors>=geom->sz_colors)&&
- (_XkbAllocColors(geom,1)!=Success)) {
- return NULL;
- }
- color= &geom->colors[geom->num_colors];
- color->pixel= pixel;
- color->spec= (char *)_XkbAlloc(strlen(spec)+1);
- if (!color->spec)
- return NULL;
- strcpy(color->spec,spec);
- geom->num_colors++;
- return color;
-}
-
-XkbOutlinePtr
-XkbAddGeomOutline(XkbShapePtr shape,int sz_points)
-{
-XkbOutlinePtr outline;
-
- if ((!shape)||(sz_points<0))
- return NULL;
- if ((shape->num_outlines>=shape->sz_outlines)&&
- (_XkbAllocOutlines(shape,1)!=Success)) {
- return NULL;
- }
- outline= &shape->outlines[shape->num_outlines];
- bzero(outline,sizeof(XkbOutlineRec));
- if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success))
- return NULL;
- shape->num_outlines++;
- return outline;
-}
-
-XkbShapePtr
-XkbAddGeomShape(XkbGeometryPtr geom,Atom name,int sz_outlines)
-{
-XkbShapePtr shape;
-register int i;
-
- if ((!geom)||(!name)||(sz_outlines<0))
- return NULL;
- if (geom->num_shapes>0) {
- for (shape=geom->shapes,i=0;i<geom->num_shapes;i++,shape++) {
- if (name==shape->name)
- return shape;
- }
- }
- if ((geom->num_shapes>=geom->sz_shapes)&&
- (_XkbAllocShapes(geom,1)!=Success))
- return NULL;
- shape= &geom->shapes[geom->num_shapes];
- bzero(shape,sizeof(XkbShapeRec));
- if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success))
- return NULL;
- shape->name= name;
- shape->primary= shape->approx= NULL;
- geom->num_shapes++;
- return shape;
-}
-
-XkbKeyPtr
-XkbAddGeomKey(XkbRowPtr row)
-{
-XkbKeyPtr key;
- if (!row)
- return NULL;
- if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success))
- return NULL;
- key= &row->keys[row->num_keys++];
- bzero(key,sizeof(XkbKeyRec));
- return key;
-}
-
-XkbRowPtr
-XkbAddGeomRow(XkbSectionPtr section,int sz_keys)
-{
-XkbRowPtr row;
-
- if ((!section)||(sz_keys<0))
- return NULL;
- if ((section->num_rows>=section->sz_rows)&&
- (_XkbAllocRows(section,1)!=Success))
- return NULL;
- row= &section->rows[section->num_rows];
- bzero(row,sizeof(XkbRowRec));
- if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success))
- return NULL;
- section->num_rows++;
- return row;
-}
-
-XkbSectionPtr
-XkbAddGeomSection( XkbGeometryPtr geom,
- Atom name,
- int sz_rows,
- int sz_doodads,
- int sz_over)
-{
-register int i;
-XkbSectionPtr section;
-
- if ((!geom)||(name==None)||(sz_rows<0))
- return NULL;
- for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) {
- if (section->name!=name)
- continue;
- if (((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))||
- ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success))||
- ((sz_over>0)&&(_XkbAllocOverlays(section,sz_over)!=Success)))
- return NULL;
- return section;
- }
- if ((geom->num_sections>=geom->sz_sections)&&
- (_XkbAllocSections(geom,1)!=Success))
- return NULL;
- section= &geom->sections[geom->num_sections];
- if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))
- return NULL;
- if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) {
- if (section->rows) {
- _XkbFree(section->rows);
- section->rows= NULL;
- section->sz_rows= section->num_rows= 0;
- }
- return NULL;
- }
- section->name= name;
- geom->num_sections++;
- return section;
-}
-
-XkbDoodadPtr
-XkbAddGeomDoodad(XkbGeometryPtr geom,XkbSectionPtr section,Atom name)
-{
-XkbDoodadPtr old,doodad;
-register int i,nDoodads;
-
- if ((!geom)||(name==None))
- return NULL;
- if ((section!=NULL)&&(section->num_doodads>0)) {
- old= section->doodads;
- nDoodads= section->num_doodads;
- }
- else {
- old= geom->doodads;
- nDoodads= geom->num_doodads;
- }
- for (i=0,doodad=old;i<nDoodads;i++,doodad++) {
- if (doodad->any.name==name)
- return doodad;
- }
- if (section) {
- if ((section->num_doodads>=geom->sz_doodads)&&
- (_XkbAllocDoodads(section,1)!=Success)) {
- return NULL;
- }
- doodad= &section->doodads[section->num_doodads++];
- }
- else {
- if ((geom->num_doodads>=geom->sz_doodads)&&
- (_XkbAllocDoodads(geom,1)!=Success))
- return NULL;
- doodad= &geom->doodads[geom->num_doodads++];
- }
- bzero(doodad,sizeof(XkbDoodadRec));
- doodad->any.name= name;
- return doodad;
-}
-
-XkbOverlayKeyPtr
-XkbAddGeomOverlayKey( XkbOverlayPtr overlay,
- XkbOverlayRowPtr row,
- char * over,
- char * under)
-{
-register int i;
-XkbOverlayKeyPtr key;
-XkbSectionPtr section;
-XkbRowPtr row_under;
-Bool found;
-
- if ((!overlay)||(!row)||(!over)||(!under))
- return NULL;
- section= overlay->section_under;
- if (row->row_under>=section->num_rows)
- return NULL;
- row_under= &section->rows[row->row_under];
- for (i=0,found=False;i<row_under->num_keys;i++) {
- if (strncmp(under,row_under->keys[i].name.name,XkbKeyNameLength)==0) {
- found= True;
- break;
- }
- }
- if (!found)
- return NULL;
- if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success))
- return NULL;
- key= &row->keys[row->num_keys];
- strncpy(key->under.name,under,XkbKeyNameLength);
- strncpy(key->over.name,over,XkbKeyNameLength);
- row->num_keys++;
- return key;
-}
-
-XkbOverlayRowPtr
-XkbAddGeomOverlayRow(XkbOverlayPtr overlay,int row_under,int sz_keys)
-{
-register int i;
-XkbOverlayRowPtr row;
-
- if ((!overlay)||(sz_keys<0))
- return NULL;
- if (row_under>=overlay->section_under->num_rows)
- return NULL;
- for (i=0;i<overlay->num_rows;i++) {
- if (overlay->rows[i].row_under==row_under) {
- row= &overlay->rows[i];
- if ((row->sz_keys<sz_keys)&&
- (_XkbAllocOverlayKeys(row,sz_keys)!=Success)) {
- return NULL;
- }
- return &overlay->rows[i];
- }
- }
- if ((overlay->num_rows>=overlay->sz_rows)&&
- (_XkbAllocOverlayRows(overlay,1)!=Success))
- return NULL;
- row= &overlay->rows[overlay->num_rows];
- bzero(row,sizeof(XkbOverlayRowRec));
- if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success))
- return NULL;
- row->row_under= row_under;
- overlay->num_rows++;
- return row;
-}
-
-XkbOverlayPtr
-XkbAddGeomOverlay(XkbSectionPtr section,Atom name,int sz_rows)
-{
-register int i;
-XkbOverlayPtr overlay;
-
- if ((!section)||(name==None)||(sz_rows==0))
- return NULL;
-
- for (i=0,overlay=section->overlays;i<section->num_overlays;i++,overlay++) {
- if (overlay->name==name) {
- if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
- return NULL;
- return overlay;
- }
- }
- if ((section->num_overlays>=section->sz_overlays)&&
- (_XkbAllocOverlays(section,1)!=Success))
- return NULL;
- overlay= &section->overlays[section->num_overlays];
- if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
- return NULL;
- overlay->name= name;
- overlay->section_under= section;
- section->num_overlays++;
- return overlay;
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_DIX_CONFIG_H
+#include <dix-config.h>
+#elif defined(HAVE_CONFIG_H)
+#include <config.h>
+#endif
+
+#ifndef XKB_IN_SERVER
+
+#include <stdio.h>
+#include "Xlibint.h"
+#include "XKBlibint.h"
+#include <X11/extensions/XKBgeom.h>
+#include <X11/extensions/XKBproto.h>
+
+#else
+
+#include <stdio.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "inputstr.h"
+#include <X11/extensions/XKBsrv.h>
+#include <X11/extensions/XKBgeom.h>
+
+#endif /* XKB_IN_SERVER */
+
+#ifdef X_NOT_POSIX
+#define Size_t unsigned int
+#else
+#define Size_t size_t
+#endif
+
+/***====================================================================***/
+
+static void
+_XkbFreeGeomLeafElems( Bool freeAll,
+ int first,
+ int count,
+ unsigned short * num_inout,
+ unsigned short * sz_inout,
+ char ** elems,
+ unsigned int elem_sz)
+{
+ if ((freeAll)||(*elems==NULL)) {
+ *num_inout= *sz_inout= 0;
+ if (*elems!=NULL) {
+ _XkbFree(*elems);
+ *elems= NULL;
+ }
+ return;
+ }
+
+ if ((first>=(*num_inout))||(first<0)||(count<1))
+ return;
+
+ if (first+count>=(*num_inout)) {
+ /* truncating the array is easy */
+ (*num_inout)= first;
+ }
+ else {
+ char * ptr;
+ int extra;
+ ptr= *elems;
+ extra= ((*num_inout)-(first+count))*elem_sz;
+ if (extra>0)
+ memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],extra);
+ (*num_inout)-= count;
+ }
+ return;
+}
+
+typedef void (*ContentsClearFunc)(
+ char * /* priv */
+);
+
+static void
+_XkbFreeGeomNonLeafElems( Bool freeAll,
+ int first,
+ int count,
+ unsigned short * num_inout,
+ unsigned short * sz_inout,
+ char ** elems,
+ unsigned int elem_sz,
+ ContentsClearFunc freeFunc)
+{
+register int i;
+register char *ptr;
+
+ if (freeAll) {
+ first= 0;
+ count= (*num_inout);
+ }
+ else if ((first>=(*num_inout))||(first<0)||(count<1))
+ return;
+ else if (first+count>(*num_inout))
+ count= (*num_inout)-first;
+ if (*elems==NULL)
+ return;
+
+ if (freeFunc) {
+ ptr= *elems;
+ ptr+= first*elem_sz;
+ for (i=0;i<count;i++) {
+ (*freeFunc)(ptr);
+ ptr+= elem_sz;
+ }
+ }
+ if (freeAll) {
+ (*num_inout)= (*sz_inout)= 0;
+ if (*elems) {
+ _XkbFree(*elems);
+ *elems= NULL;
+ }
+ }
+ else if (first+count>=(*num_inout))
+ *num_inout= first;
+ else {
+ i= ((*num_inout)-(first+count))*elem_sz;
+ ptr= *elems;
+ memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],i);
+ (*num_inout)-= count;
+ }
+ return;
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearProperty(char *prop_in)
+{
+XkbPropertyPtr prop= (XkbPropertyPtr)prop_in;
+
+ if (prop->name) {
+ _XkbFree(prop->name);
+ prop->name= NULL;
+ }
+ if (prop->value) {
+ _XkbFree(prop->value);
+ prop->value= NULL;
+ }
+ return;
+}
+
+void
+XkbFreeGeomProperties( XkbGeometryPtr geom,
+ int first,
+ int count,
+ Bool freeAll)
+{
+ _XkbFreeGeomNonLeafElems(freeAll,first,count,
+ &geom->num_properties,&geom->sz_properties,
+ (char **)&geom->properties,
+ sizeof(XkbPropertyRec),_XkbClearProperty);
+ return;
+}
+
+/***====================================================================***/
+
+void
+XkbFreeGeomKeyAliases( XkbGeometryPtr geom,
+ int first,
+ int count,
+ Bool freeAll)
+{
+ _XkbFreeGeomLeafElems(freeAll,first,count,
+ &geom->num_key_aliases,&geom->sz_key_aliases,
+ (char **)&geom->key_aliases,
+ sizeof(XkbKeyAliasRec));
+ return;
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearColor(char *color_in)
+{
+XkbColorPtr color= (XkbColorPtr)color_in;
+
+ if (color->spec)
+ _XkbFree(color->spec);
+ return;
+}
+
+void
+XkbFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomNonLeafElems(freeAll,first,count,
+ &geom->num_colors,&geom->sz_colors,
+ (char **)&geom->colors,
+ sizeof(XkbColorRec),_XkbClearColor);
+ return;
+}
+
+/***====================================================================***/
+
+void
+XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomLeafElems(freeAll,first,count,
+ &outline->num_points,&outline->sz_points,
+ (char **)&outline->points,
+ sizeof(XkbPointRec));
+ return;
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearOutline(char *outline_in)
+{
+XkbOutlinePtr outline= (XkbOutlinePtr)outline_in;
+
+ if (outline->points!=NULL)
+ XkbFreeGeomPoints(outline,0,outline->num_points,True);
+ return;
+}
+
+void
+XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomNonLeafElems(freeAll,first,count,
+ &shape->num_outlines,&shape->sz_outlines,
+ (char **)&shape->outlines,
+ sizeof(XkbOutlineRec),_XkbClearOutline);
+
+ return;
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearShape(char *shape_in)
+{
+XkbShapePtr shape= (XkbShapePtr)shape_in;
+
+ if (shape->outlines)
+ XkbFreeGeomOutlines(shape,0,shape->num_outlines,True);
+ return;
+}
+
+void
+XkbFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomNonLeafElems(freeAll,first,count,
+ &geom->num_shapes,&geom->sz_shapes,
+ (char **)&geom->shapes,
+ sizeof(XkbShapeRec),_XkbClearShape);
+ return;
+}
+
+/***====================================================================***/
+
+void
+XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomLeafElems(freeAll,first,count,
+ &row->num_keys,&row->sz_keys,
+ (char **)&row->keys,
+ sizeof(XkbOverlayKeyRec));
+ return;
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearOverlayRow(char *row_in)
+{
+XkbOverlayRowPtr row= (XkbOverlayRowPtr)row_in;
+
+ if (row->keys!=NULL)
+ XkbFreeGeomOverlayKeys(row,0,row->num_keys,True);
+ return;
+}
+
+void
+XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomNonLeafElems(freeAll,first,count,
+ &overlay->num_rows,&overlay->sz_rows,
+ (char **)&overlay->rows,
+ sizeof(XkbOverlayRowRec),_XkbClearOverlayRow);
+ return;
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearOverlay(char *overlay_in)
+{
+XkbOverlayPtr overlay= (XkbOverlayPtr)overlay_in;
+
+ if (overlay->rows!=NULL)
+ XkbFreeGeomOverlayRows(overlay,0,overlay->num_rows,True);
+ return;
+}
+
+void
+XkbFreeGeomOverlays(XkbSectionPtr section,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomNonLeafElems(freeAll,first,count,
+ &section->num_overlays,&section->sz_overlays,
+ (char **)&section->overlays,
+ sizeof(XkbOverlayRec),_XkbClearOverlay);
+ return;
+}
+
+/***====================================================================***/
+
+void
+XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomLeafElems(freeAll,first,count,
+ &row->num_keys,&row->sz_keys,
+ (char **)&row->keys,
+ sizeof(XkbKeyRec));
+ return;
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearRow(char *row_in)
+{
+XkbRowPtr row= (XkbRowPtr)row_in;
+
+ if (row->keys!=NULL)
+ XkbFreeGeomKeys(row,0,row->num_keys,True);
+ return;
+}
+
+void
+XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomNonLeafElems(freeAll,first,count,
+ &section->num_rows,&section->sz_rows,
+ (char **)&section->rows,
+ sizeof(XkbRowRec),_XkbClearRow);
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearSection(char *section_in)
+{
+XkbSectionPtr section= (XkbSectionPtr)section_in;
+
+ if (section->rows!=NULL)
+ XkbFreeGeomRows(section,0,section->num_rows,True);
+ if (section->doodads!=NULL) {
+ XkbFreeGeomDoodads(section->doodads,section->num_doodads,True);
+ section->doodads= NULL;
+ }
+ return;
+}
+
+void
+XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll)
+{
+ _XkbFreeGeomNonLeafElems(freeAll,first,count,
+ &geom->num_sections,&geom->sz_sections,
+ (char **)&geom->sections,
+ sizeof(XkbSectionRec),_XkbClearSection);
+ return;
+}
+
+/***====================================================================***/
+
+static void
+_XkbClearDoodad(char *doodad_in)
+{
+XkbDoodadPtr doodad= (XkbDoodadPtr)doodad_in;
+
+ switch (doodad->any.type) {
+ case XkbTextDoodad:
+ {
+ if (doodad->text.text!=NULL) {
+ _XkbFree(doodad->text.text);
+ doodad->text.text= NULL;
+ }
+ if (doodad->text.font!=NULL) {
+ _XkbFree(doodad->text.font);
+ doodad->text.font= NULL;
+ }
+ }
+ break;
+ case XkbLogoDoodad:
+ {
+ if (doodad->logo.logo_name!=NULL) {
+ _XkbFree(doodad->logo.logo_name);
+ doodad->logo.logo_name= NULL;
+ }
+ }
+ break;
+ }
+ return;
+}
+
+void
+XkbFreeGeomDoodads(XkbDoodadPtr doodads,int nDoodads,Bool freeAll)
+{
+register int i;
+register XkbDoodadPtr doodad;
+
+ if (doodads) {
+ for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) {
+ _XkbClearDoodad((char *)doodad);
+ }
+ if (freeAll)
+ _XkbFree(doodads);
+ }
+ return;
+}
+
+void
+XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap)
+{
+ if (geom==NULL)
+ return;
+ if (freeMap)
+ which= XkbGeomAllMask;
+ if ((which&XkbGeomPropertiesMask)&&(geom->properties!=NULL))
+ XkbFreeGeomProperties(geom,0,geom->num_properties,True);
+ if ((which&XkbGeomColorsMask)&&(geom->colors!=NULL))
+ XkbFreeGeomColors(geom,0,geom->num_colors,True);
+ if ((which&XkbGeomShapesMask)&&(geom->shapes!=NULL))
+ XkbFreeGeomShapes(geom,0,geom->num_shapes,True);
+ if ((which&XkbGeomSectionsMask)&&(geom->sections!=NULL))
+ XkbFreeGeomSections(geom,0,geom->num_sections,True);
+ if ((which&XkbGeomDoodadsMask)&&(geom->doodads!= NULL)) {
+ XkbFreeGeomDoodads(geom->doodads,geom->num_doodads,True);
+ geom->doodads= NULL;
+ geom->num_doodads= geom->sz_doodads= 0;
+ }
+ if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL))
+ XkbFreeGeomKeyAliases(geom,0,geom->num_key_aliases,True);
+ if (freeMap) {
+ if (geom->label_font!=NULL) {
+ _XkbFree(geom->label_font);
+ geom->label_font= NULL;
+ }
+ _XkbFree(geom);
+ }
+ return;
+}
+
+/***====================================================================***/
+
+static Status
+_XkbGeomAlloc( XPointer * old,
+ unsigned short * num,
+ unsigned short * total,
+ int num_new,
+ Size_t sz_elem)
+{
+ if (num_new<1)
+ return Success;
+ if ((*old)==NULL)
+ *num= *total= 0;
+
+ if ((*num)+num_new<=(*total))
+ return Success;
+
+ *total= (*num)+num_new;
+ if ((*old)!=NULL)
+ (*old)= (XPointer)_XkbRealloc((*old),(*total)*sz_elem);
+ else (*old)= (XPointer)_XkbCalloc((*total),sz_elem);
+ if ((*old)==NULL) {
+ *total= *num= 0;
+ return BadAlloc;
+ }
+
+ if (*num>0) {
+ char *tmp= (char *)(*old);
+ bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem));
+ }
+ return Success;
+}
+
+#define _XkbAllocProps(g,n) _XkbGeomAlloc((XPointer *)&(g)->properties,\
+ &(g)->num_properties,&(g)->sz_properties,\
+ (n),sizeof(XkbPropertyRec))
+#define _XkbAllocColors(g,n) _XkbGeomAlloc((XPointer *)&(g)->colors,\
+ &(g)->num_colors,&(g)->sz_colors,\
+ (n),sizeof(XkbColorRec))
+#define _XkbAllocShapes(g,n) _XkbGeomAlloc((XPointer *)&(g)->shapes,\
+ &(g)->num_shapes,&(g)->sz_shapes,\
+ (n),sizeof(XkbShapeRec))
+#define _XkbAllocSections(g,n) _XkbGeomAlloc((XPointer *)&(g)->sections,\
+ &(g)->num_sections,&(g)->sz_sections,\
+ (n),sizeof(XkbSectionRec))
+#define _XkbAllocDoodads(g,n) _XkbGeomAlloc((XPointer *)&(g)->doodads,\
+ &(g)->num_doodads,&(g)->sz_doodads,\
+ (n),sizeof(XkbDoodadRec))
+#define _XkbAllocKeyAliases(g,n) _XkbGeomAlloc((XPointer *)&(g)->key_aliases,\
+ &(g)->num_key_aliases,&(g)->sz_key_aliases,\
+ (n),sizeof(XkbKeyAliasRec))
+
+#define _XkbAllocOutlines(s,n) _XkbGeomAlloc((XPointer *)&(s)->outlines,\
+ &(s)->num_outlines,&(s)->sz_outlines,\
+ (n),sizeof(XkbOutlineRec))
+#define _XkbAllocRows(s,n) _XkbGeomAlloc((XPointer *)&(s)->rows,\
+ &(s)->num_rows,&(s)->sz_rows,\
+ (n),sizeof(XkbRowRec))
+#define _XkbAllocPoints(o,n) _XkbGeomAlloc((XPointer *)&(o)->points,\
+ &(o)->num_points,&(o)->sz_points,\
+ (n),sizeof(XkbPointRec))
+#define _XkbAllocKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
+ &(r)->num_keys,&(r)->sz_keys,\
+ (n),sizeof(XkbKeyRec))
+#define _XkbAllocOverlays(s,n) _XkbGeomAlloc((XPointer *)&(s)->overlays,\
+ &(s)->num_overlays,&(s)->sz_overlays,\
+ (n),sizeof(XkbOverlayRec))
+#define _XkbAllocOverlayRows(o,n) _XkbGeomAlloc((XPointer *)&(o)->rows,\
+ &(o)->num_rows,&(o)->sz_rows,\
+ (n),sizeof(XkbOverlayRowRec))
+#define _XkbAllocOverlayKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
+ &(r)->num_keys,&(r)->sz_keys,\
+ (n),sizeof(XkbOverlayKeyRec))
+
+Status
+XkbAllocGeomProps(XkbGeometryPtr geom,int nProps)
+{
+ return _XkbAllocProps(geom,nProps);
+}
+
+Status
+XkbAllocGeomColors(XkbGeometryPtr geom,int nColors)
+{
+ return _XkbAllocColors(geom,nColors);
+}
+
+Status
+XkbAllocGeomKeyAliases(XkbGeometryPtr geom,int nKeyAliases)
+{
+ return _XkbAllocKeyAliases(geom,nKeyAliases);
+}
+
+Status
+XkbAllocGeomShapes(XkbGeometryPtr geom,int nShapes)
+{
+ return _XkbAllocShapes(geom,nShapes);
+}
+
+Status
+XkbAllocGeomSections(XkbGeometryPtr geom,int nSections)
+{
+ return _XkbAllocSections(geom,nSections);
+}
+
+Status
+XkbAllocGeomOverlays(XkbSectionPtr section,int nOverlays)
+{
+ return _XkbAllocOverlays(section,nOverlays);
+}
+
+Status
+XkbAllocGeomOverlayRows(XkbOverlayPtr overlay,int nRows)
+{
+ return _XkbAllocOverlayRows(overlay,nRows);
+}
+
+Status
+XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row,int nKeys)
+{
+ return _XkbAllocOverlayKeys(row,nKeys);
+}
+
+Status
+XkbAllocGeomDoodads(XkbGeometryPtr geom,int nDoodads)
+{
+ return _XkbAllocDoodads(geom,nDoodads);
+}
+
+Status
+XkbAllocGeomSectionDoodads(XkbSectionPtr section,int nDoodads)
+{
+ return _XkbAllocDoodads(section,nDoodads);
+}
+
+Status
+XkbAllocGeomOutlines(XkbShapePtr shape,int nOL)
+{
+ return _XkbAllocOutlines(shape,nOL);
+}
+
+Status
+XkbAllocGeomRows(XkbSectionPtr section,int nRows)
+{
+ return _XkbAllocRows(section,nRows);
+}
+
+Status
+XkbAllocGeomPoints(XkbOutlinePtr ol,int nPts)
+{
+ return _XkbAllocPoints(ol,nPts);
+}
+
+Status
+XkbAllocGeomKeys(XkbRowPtr row,int nKeys)
+{
+ return _XkbAllocKeys(row,nKeys);
+}
+
+Status
+XkbAllocGeometry(XkbDescPtr xkb,XkbGeometrySizesPtr sizes)
+{
+XkbGeometryPtr geom;
+Status rtrn;
+
+ if (xkb->geom==NULL) {
+ xkb->geom= _XkbTypedCalloc(1,XkbGeometryRec);
+ if (!xkb->geom)
+ return BadAlloc;
+ }
+ geom= xkb->geom;
+ if ((sizes->which&XkbGeomPropertiesMask)&&
+ ((rtrn=_XkbAllocProps(geom,sizes->num_properties))!=Success)) {
+ goto BAIL;
+ }
+ if ((sizes->which&XkbGeomColorsMask)&&
+ ((rtrn=_XkbAllocColors(geom,sizes->num_colors))!=Success)) {
+ goto BAIL;
+ }
+ if ((sizes->which&XkbGeomShapesMask)&&
+ ((rtrn=_XkbAllocShapes(geom,sizes->num_shapes))!=Success)) {
+ goto BAIL;
+ }
+ if ((sizes->which&XkbGeomSectionsMask)&&
+ ((rtrn=_XkbAllocSections(geom,sizes->num_sections))!=Success)) {
+ goto BAIL;
+ }
+ if ((sizes->which&XkbGeomDoodadsMask)&&
+ ((rtrn=_XkbAllocDoodads(geom,sizes->num_doodads))!=Success)) {
+ goto BAIL;
+ }
+ if ((sizes->which&XkbGeomKeyAliasesMask)&&
+ ((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=Success)) {
+ goto BAIL;
+ }
+ return Success;
+BAIL:
+ XkbFreeGeometry(geom,XkbGeomAllMask,True);
+ xkb->geom= NULL;
+ return rtrn;
+}
+
+/***====================================================================***/
+
+XkbPropertyPtr
+XkbAddGeomProperty(XkbGeometryPtr geom,char *name,char *value)
+{
+register int i;
+register XkbPropertyPtr prop;
+
+ if ((!geom)||(!name)||(!value))
+ return NULL;
+ for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
+ if ((prop->name)&&(strcmp(name,prop->name)==0)) {
+ if (prop->value)
+ _XkbFree(prop->value);
+ prop->value= (char *)_XkbAlloc(strlen(value)+1);
+ if (prop->value)
+ strcpy(prop->value,value);
+ return prop;
+ }
+ }
+ if ((geom->num_properties>=geom->sz_properties)&&
+ (_XkbAllocProps(geom,1)!=Success)) {
+ return NULL;
+ }
+ prop= &geom->properties[geom->num_properties];
+ prop->name= (char *)_XkbAlloc(strlen(name)+1);
+ if (!name)
+ return NULL;
+ strcpy(prop->name,name);
+ prop->value= (char *)_XkbAlloc(strlen(value)+1);
+ if (!value) {
+ _XkbFree(prop->name);
+ prop->name= NULL;
+ return NULL;
+ }
+ strcpy(prop->value,value);
+ geom->num_properties++;
+ return prop;
+}
+
+XkbKeyAliasPtr
+XkbAddGeomKeyAlias(XkbGeometryPtr geom,char *aliasStr,char *realStr)
+{
+register int i;
+register XkbKeyAliasPtr alias;
+
+ if ((!geom)||(!aliasStr)||(!realStr)||(!aliasStr[0])||(!realStr[0]))
+ return NULL;
+ for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) {
+ if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) {
+ bzero(alias->real,XkbKeyNameLength);
+ strncpy(alias->real,realStr,XkbKeyNameLength);
+ return alias;
+ }
+ }
+ if ((geom->num_key_aliases>=geom->sz_key_aliases)&&
+ (_XkbAllocKeyAliases(geom,1)!=Success)) {
+ return NULL;
+ }
+ alias= &geom->key_aliases[geom->num_key_aliases];
+ bzero(alias,sizeof(XkbKeyAliasRec));
+ strncpy(alias->alias,aliasStr,XkbKeyNameLength);
+ strncpy(alias->real,realStr,XkbKeyNameLength);
+ geom->num_key_aliases++;
+ return alias;
+}
+
+XkbColorPtr
+XkbAddGeomColor(XkbGeometryPtr geom,char *spec,unsigned int pixel)
+{
+register int i;
+register XkbColorPtr color;
+
+ if ((!geom)||(!spec))
+ return NULL;
+ for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) {
+ if ((color->spec)&&(strcmp(color->spec,spec)==0)) {
+ color->pixel= pixel;
+ return color;
+ }
+ }
+ if ((geom->num_colors>=geom->sz_colors)&&
+ (_XkbAllocColors(geom,1)!=Success)) {
+ return NULL;
+ }
+ color= &geom->colors[geom->num_colors];
+ color->pixel= pixel;
+ color->spec= (char *)_XkbAlloc(strlen(spec)+1);
+ if (!color->spec)
+ return NULL;
+ strcpy(color->spec,spec);
+ geom->num_colors++;
+ return color;
+}
+
+XkbOutlinePtr
+XkbAddGeomOutline(XkbShapePtr shape,int sz_points)
+{
+XkbOutlinePtr outline;
+
+ if ((!shape)||(sz_points<0))
+ return NULL;
+ if ((shape->num_outlines>=shape->sz_outlines)&&
+ (_XkbAllocOutlines(shape,1)!=Success)) {
+ return NULL;
+ }
+ outline= &shape->outlines[shape->num_outlines];
+ bzero(outline,sizeof(XkbOutlineRec));
+ if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success))
+ return NULL;
+ shape->num_outlines++;
+ return outline;
+}
+
+XkbShapePtr
+XkbAddGeomShape(XkbGeometryPtr geom,Atom name,int sz_outlines)
+{
+XkbShapePtr shape;
+register int i;
+
+ if ((!geom)||(!name)||(sz_outlines<0))
+ return NULL;
+ if (geom->num_shapes>0) {
+ for (shape=geom->shapes,i=0;i<geom->num_shapes;i++,shape++) {
+ if (name==shape->name)
+ return shape;
+ }
+ }
+ if ((geom->num_shapes>=geom->sz_shapes)&&
+ (_XkbAllocShapes(geom,1)!=Success))
+ return NULL;
+ shape= &geom->shapes[geom->num_shapes];
+ bzero(shape,sizeof(XkbShapeRec));
+ if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success))
+ return NULL;
+ shape->name= name;
+ shape->primary= shape->approx= NULL;
+ geom->num_shapes++;
+ return shape;
+}
+
+XkbKeyPtr
+XkbAddGeomKey(XkbRowPtr row)
+{
+XkbKeyPtr key;
+ if (!row)
+ return NULL;
+ if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success))
+ return NULL;
+ key= &row->keys[row->num_keys++];
+ bzero(key,sizeof(XkbKeyRec));
+ return key;
+}
+
+XkbRowPtr
+XkbAddGeomRow(XkbSectionPtr section,int sz_keys)
+{
+XkbRowPtr row;
+
+ if ((!section)||(sz_keys<0))
+ return NULL;
+ if ((section->num_rows>=section->sz_rows)&&
+ (_XkbAllocRows(section,1)!=Success))
+ return NULL;
+ row= &section->rows[section->num_rows];
+ bzero(row,sizeof(XkbRowRec));
+ if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success))
+ return NULL;
+ section->num_rows++;
+ return row;
+}
+
+XkbSectionPtr
+XkbAddGeomSection( XkbGeometryPtr geom,
+ Atom name,
+ int sz_rows,
+ int sz_doodads,
+ int sz_over)
+{
+register int i;
+XkbSectionPtr section;
+
+ if ((!geom)||(name==None)||(sz_rows<0))
+ return NULL;
+ for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) {
+ if (section->name!=name)
+ continue;
+ if (((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))||
+ ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success))||
+ ((sz_over>0)&&(_XkbAllocOverlays(section,sz_over)!=Success)))
+ return NULL;
+ return section;
+ }
+ if ((geom->num_sections>=geom->sz_sections)&&
+ (_XkbAllocSections(geom,1)!=Success))
+ return NULL;
+ section= &geom->sections[geom->num_sections];
+ if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))
+ return NULL;
+ if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) {
+ if (section->rows) {
+ _XkbFree(section->rows);
+ section->rows= NULL;
+ section->sz_rows= section->num_rows= 0;
+ }
+ return NULL;
+ }
+ section->name= name;
+ geom->num_sections++;
+ return section;
+}
+
+XkbDoodadPtr
+XkbAddGeomDoodad(XkbGeometryPtr geom,XkbSectionPtr section,Atom name)
+{
+XkbDoodadPtr old,doodad;
+register int i,nDoodads;
+
+ if ((!geom)||(name==None))
+ return NULL;
+ if ((section!=NULL)&&(section->num_doodads>0)) {
+ old= section->doodads;
+ nDoodads= section->num_doodads;
+ }
+ else {
+ old= geom->doodads;
+ nDoodads= geom->num_doodads;
+ }
+ for (i=0,doodad=old;i<nDoodads;i++,doodad++) {
+ if (doodad->any.name==name)
+ return doodad;
+ }
+ if (section) {
+ if ((section->num_doodads>=geom->sz_doodads)&&
+ (_XkbAllocDoodads(section,1)!=Success)) {
+ return NULL;
+ }
+ doodad= &section->doodads[section->num_doodads++];
+ }
+ else {
+ if ((geom->num_doodads>=geom->sz_doodads)&&
+ (_XkbAllocDoodads(geom,1)!=Success))
+ return NULL;
+ doodad= &geom->doodads[geom->num_doodads++];
+ }
+ bzero(doodad,sizeof(XkbDoodadRec));
+ doodad->any.name= name;
+ return doodad;
+}
+
+XkbOverlayKeyPtr
+XkbAddGeomOverlayKey( XkbOverlayPtr overlay,
+ XkbOverlayRowPtr row,
+ char * over,
+ char * under)
+{
+register int i;
+XkbOverlayKeyPtr key;
+XkbSectionPtr section;
+XkbRowPtr row_under;
+Bool found;
+
+ if ((!overlay)||(!row)||(!over)||(!under))
+ return NULL;
+ section= overlay->section_under;
+ if (row->row_under>=section->num_rows)
+ return NULL;
+ row_under= &section->rows[row->row_under];
+ for (i=0,found=False;i<row_under->num_keys;i++) {
+ if (strncmp(under,row_under->keys[i].name.name,XkbKeyNameLength)==0) {
+ found= True;
+ break;
+ }
+ }
+ if (!found)
+ return NULL;
+ if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success))
+ return NULL;
+ key= &row->keys[row->num_keys];
+ strncpy(key->under.name,under,XkbKeyNameLength);
+ strncpy(key->over.name,over,XkbKeyNameLength);
+ row->num_keys++;
+ return key;
+}
+
+XkbOverlayRowPtr
+XkbAddGeomOverlayRow(XkbOverlayPtr overlay,int row_under,int sz_keys)
+{
+register int i;
+XkbOverlayRowPtr row;
+
+ if ((!overlay)||(sz_keys<0))
+ return NULL;
+ if (row_under>=overlay->section_under->num_rows)
+ return NULL;
+ for (i=0;i<overlay->num_rows;i++) {
+ if (overlay->rows[i].row_under==row_under) {
+ row= &overlay->rows[i];
+ if ((row->sz_keys<sz_keys)&&
+ (_XkbAllocOverlayKeys(row,sz_keys)!=Success)) {
+ return NULL;
+ }
+ return &overlay->rows[i];
+ }
+ }
+ if ((overlay->num_rows>=overlay->sz_rows)&&
+ (_XkbAllocOverlayRows(overlay,1)!=Success))
+ return NULL;
+ row= &overlay->rows[overlay->num_rows];
+ bzero(row,sizeof(XkbOverlayRowRec));
+ if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success))
+ return NULL;
+ row->row_under= row_under;
+ overlay->num_rows++;
+ return row;
+}
+
+XkbOverlayPtr
+XkbAddGeomOverlay(XkbSectionPtr section,Atom name,int sz_rows)
+{
+register int i;
+XkbOverlayPtr overlay;
+
+ if ((!section)||(name==None)||(sz_rows==0))
+ return NULL;
+
+ for (i=0,overlay=section->overlays;i<section->num_overlays;i++,overlay++) {
+ if (overlay->name==name) {
+ if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
+ return NULL;
+ return overlay;
+ }
+ }
+ if ((section->num_overlays>=section->sz_overlays)&&
+ (_XkbAllocOverlays(section,1)!=Success))
+ return NULL;
+ overlay= &section->overlays[section->num_overlays];
+ if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
+ return NULL;
+ overlay->name= name;
+ overlay->section_under= section;
+ section->num_overlays++;
+ return overlay;
+}
diff --git a/libX11/src/xkb/XKBGeom.c b/libX11/src/xkb/XKBGeom.c
index 0ff744952..065285fcb 100644
--- a/libX11/src/xkb/XKBGeom.c
+++ b/libX11/src/xkb/XKBGeom.c
@@ -1,690 +1,688 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 DEBUG
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#endif
-
-#define NEED_EVENTS
-#define NEED_REPLIES
-#define NEED_MAP_READERS
-#include "Xlibint.h"
-#include <X11/extensions/XKBgeom.h>
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-#define MINSHORT -32768
-#define MAXSHORT 32767
-
-/***====================================================================***/
-
-static void
-_XkbCheckBounds(XkbBoundsPtr bounds,int x,int y)
-{
- if (x<bounds->x1) bounds->x1= x;
- if (x>bounds->x2) bounds->x2= x;
- if (y<bounds->y1) bounds->y1= y;
- if (y>bounds->y2) bounds->y2= y;
- return;
-}
-
-Bool
-XkbComputeShapeBounds(XkbShapePtr shape)
-{
-register int o,p;
-XkbOutlinePtr outline;
-XkbPointPtr pt;
-
- if ((!shape)||(shape->num_outlines<1))
- return False;
- shape->bounds.x1= shape->bounds.y1= MAXSHORT;
- shape->bounds.x2= shape->bounds.y2= MINSHORT;
- for (outline=shape->outlines,o=0;o<shape->num_outlines;o++,outline++) {
- for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) {
- _XkbCheckBounds(&shape->bounds,pt->x,pt->y);
- }
- if (outline->num_points<2) {
- _XkbCheckBounds(&shape->bounds,0,0);
- }
- }
- return True;
-}
-
-Bool
-XkbComputeShapeTop(XkbShapePtr shape,XkbBoundsPtr bounds)
-{
-register int p;
-XkbOutlinePtr outline;
-XkbPointPtr pt;
-
- if ((!shape)||(shape->num_outlines<1))
- return False;
- if (shape->approx) outline= shape->approx;
- else outline= &shape->outlines[shape->num_outlines-1];
- if (outline->num_points<2) {
- bounds->x1= bounds->y1= 0;
- bounds->x2= bounds->y2= 0;
- }
- else {
- bounds->x1= bounds->y1= MAXSHORT;
- bounds->x2= bounds->y2= MINSHORT;
- }
- for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) {
- _XkbCheckBounds(bounds,pt->x,pt->y);
- }
- return True;
-}
-
-Bool
-XkbComputeRowBounds(XkbGeometryPtr geom,XkbSectionPtr section,XkbRowPtr row)
-{
-register int k,pos;
-XkbKeyPtr key;
-XkbBoundsPtr bounds,sbounds;
-
- if ((!geom)||(!section)||(!row))
- return False;
- pos= 0;
- bounds= &row->bounds;
- bzero(bounds,sizeof(XkbBoundsRec));
- for (key=row->keys,pos=k=0;k<row->num_keys;k++,key++) {
- sbounds= &XkbKeyShape(geom,key)->bounds;
- _XkbCheckBounds(bounds,pos,0);
- if (!row->vertical) {
- if (key->gap!=0) {
- pos+= key->gap;
- _XkbCheckBounds(bounds,pos,0);
- }
- _XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1);
- _XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2);
- pos+= sbounds->x2;
- }
- else {
- if (key->gap!=0) {
- pos+= key->gap;
- _XkbCheckBounds(bounds,0,pos);
- }
- _XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1);
- _XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2);
- pos+= sbounds->y2;
- }
- }
- return True;
-}
-
-Bool
-XkbComputeSectionBounds(XkbGeometryPtr geom,XkbSectionPtr section)
-{
-register int i;
-XkbShapePtr shape;
-XkbRowPtr row;
-XkbDoodadPtr doodad;
-XkbBoundsPtr bounds,rbounds=NULL;
-
- if ((!geom)||(!section))
- return False;
- bounds= &section->bounds;
- bzero(bounds,sizeof(XkbBoundsRec));
- for (i=0,row=section->rows;i<section->num_rows;i++,row++) {
- if (!XkbComputeRowBounds(geom,section,row))
- return False;
- rbounds= &row->bounds;
- _XkbCheckBounds(bounds,row->left+rbounds->x1,row->top+rbounds->y1);
- _XkbCheckBounds(bounds,row->left+rbounds->x2,row->top+rbounds->y2);
- }
- for (i=0,doodad=section->doodads;i<section->num_doodads;i++,doodad++) {
- static XkbBoundsRec tbounds;
- switch (doodad->any.type) {
- case XkbOutlineDoodad:
- case XkbSolidDoodad:
- shape= XkbShapeDoodadShape(geom,&doodad->shape);
- rbounds= &shape->bounds;
- break;
- case XkbTextDoodad:
- tbounds.x1= doodad->text.left;
- tbounds.y1= doodad->text.top;
- tbounds.x2= tbounds.x1+doodad->text.width;
- tbounds.y2= tbounds.y1+doodad->text.height;
- rbounds= &tbounds;
- break;
- case XkbIndicatorDoodad:
- shape= XkbIndicatorDoodadShape(geom,&doodad->indicator);
- rbounds= &shape->bounds;
- break;
- case XkbLogoDoodad:
- shape= XkbLogoDoodadShape(geom,&doodad->logo);
- rbounds= &shape->bounds;
- break;
- default:
- tbounds.x1= tbounds.x2= doodad->any.left;
- tbounds.y1= tbounds.y2= doodad->any.top;
- break;
- }
- _XkbCheckBounds(bounds,rbounds->x1,rbounds->y1);
- _XkbCheckBounds(bounds,rbounds->x2,rbounds->y2);
- }
- return True;
-}
-
-/***====================================================================***/
-
-char *
-XkbFindOverlayForKey(XkbGeometryPtr geom,XkbSectionPtr wanted,char *under)
-{
-int s;
-XkbSectionPtr section;
-
- if ((geom==NULL)||(under==NULL)||(geom->num_sections<1))
- return NULL;
-
- if (wanted)
- section= wanted;
- else section= geom->sections;
-
- for (s=0;s<geom->num_sections;s++,section++) {
- XkbOverlayPtr ol;
- int o;
-
- if (section->num_overlays<1)
- continue;
- for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) {
- XkbOverlayRowPtr row;
- int r;
-
- for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
- XkbOverlayKeyPtr key;
- int k;
- for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
- if (strncmp(under,key->under.name,XkbKeyNameLength)==0)
- return key->over.name;
- }
- }
- }
- if (wanted!=NULL)
- break;
- }
- return NULL;
-}
-
-/***====================================================================***/
-
-static Status
-_XkbReadGeomProperties( XkbReadBufferPtr buf,
- XkbGeometryPtr geom,
- xkbGetGeometryReply * rep)
-{
-Status rtrn;
-
- if (rep->nProperties<1)
- return Success;
- if ((rtrn=XkbAllocGeomProps(geom,rep->nProperties))==Success) {
- register int i;
- register Bool ok;
- char *name,*value;
- ok= True;
- for (i=0;(i<rep->nProperties)&&ok;i++) {
- name=NULL;
- value=NULL;
- ok= _XkbGetReadBufferCountedString(buf,&name)&&ok;
- ok= _XkbGetReadBufferCountedString(buf,&value)&&ok;
- ok= ok&&(XkbAddGeomProperty(geom,name,value)!=NULL);
- if (name)
- _XkbFree(name);
- if (value)
- _XkbFree(value);
- }
- if (ok) rtrn= Success;
- else rtrn= BadLength;
- }
- return rtrn;
-}
-
-static Status
-_XkbReadGeomKeyAliases( XkbReadBufferPtr buf,
- XkbGeometryPtr geom,
- xkbGetGeometryReply * rep)
-{
-Status rtrn;
-
- if (rep->nKeyAliases<1)
- return Success;
- if ((rtrn=XkbAllocGeomKeyAliases(geom,rep->nKeyAliases))==Success) {
- if (!_XkbCopyFromReadBuffer(buf,(char *)geom->key_aliases,
- (rep->nKeyAliases*XkbKeyNameLength*2)))
- return BadLength;
- geom->num_key_aliases= rep->nKeyAliases;
- return Success;
- }
- else { /* alloc failed, just skip the aliases */
- _XkbSkipReadBufferData(buf,(rep->nKeyAliases*XkbKeyNameLength*2));
- }
- return rtrn;
-}
-
-static Status
-_XkbReadGeomColors( XkbReadBufferPtr buf,
- XkbGeometryPtr geom,
- xkbGetGeometryReply * rep)
-{
-Status rtrn;
-
- if (rep->nColors<1)
- return Success;
- if ((rtrn=XkbAllocGeomColors(geom,rep->nColors))==Success) {
- register int i;
- char *spec;
- for (i=0;i<rep->nColors;i++) {
- spec = NULL;
- if (!_XkbGetReadBufferCountedString(buf,&spec))
- rtrn = BadLength;
- else if (XkbAddGeomColor(geom,spec,geom->num_colors)==NULL)
- rtrn = BadAlloc;
- if (spec)
- _XkbFree(spec);
- if (rtrn != Success)
- return rtrn;
- }
- return Success;
- }
- return rtrn;
-}
-
-static Status
-_XkbReadGeomShapes( XkbReadBufferPtr buf,
- XkbGeometryPtr geom,
- xkbGetGeometryReply * rep)
-{
-register int i;
-Status rtrn;
-
- if (rep->nShapes<1)
- return Success;
- if ((rtrn=XkbAllocGeomShapes(geom,rep->nShapes))!=Success)
- return rtrn;
- for (i=0;i<rep->nShapes;i++) {
- xkbShapeWireDesc *shapeWire;
- XkbShapePtr shape;
- register int o;
- shapeWire= (xkbShapeWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbShapeWireDesc));
- if (!shapeWire)
- return BadLength;
- shape= XkbAddGeomShape(geom,shapeWire->name,shapeWire->nOutlines);
- if (!shape)
- return BadAlloc;
- for (o=0;o<shapeWire->nOutlines;o++) {
- xkbOutlineWireDesc *olWire;
- XkbOutlinePtr ol;
- register int p;
- XkbPointPtr pt;
- olWire= (xkbOutlineWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbOutlineWireDesc));
- if (!olWire)
- return BadLength;
- ol= XkbAddGeomOutline(shape,olWire->nPoints);
- if (!ol)
- return BadAlloc;
- ol->corner_radius= olWire->cornerRadius;
- for (p=0,pt=ol->points;p<olWire->nPoints;p++,pt++) {
- xkbPointWireDesc * ptWire;
- ptWire= (xkbPointWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbPointWireDesc));
- if (!ptWire)
- return BadLength;
- pt->x= ptWire->x;
- pt->y= ptWire->y;
- }
- ol->num_points= olWire->nPoints;
- }
- if (shapeWire->primaryNdx!=XkbNoShape)
- shape->primary= &shape->outlines[shapeWire->primaryNdx];
- else shape->primary= NULL;
- if (shapeWire->approxNdx!=XkbNoShape)
- shape->approx= &shape->outlines[shapeWire->approxNdx];
- else shape->approx= NULL;
- XkbComputeShapeBounds(shape);
- }
- return Success;
-}
-
-static Status
-_XkbReadGeomDoodad( XkbReadBufferPtr buf,
- XkbGeometryPtr geom,
- XkbSectionPtr section)
-{
-XkbDoodadPtr doodad;
-xkbDoodadWireDesc * doodadWire;
-
- doodadWire= (xkbDoodadWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbDoodadWireDesc));
- if (!doodadWire)
- return BadLength;
- doodad= XkbAddGeomDoodad(geom,section,doodadWire->any.name);
- if (!doodad)
- return BadAlloc;
- doodad->any.type= doodadWire->any.type;
- doodad->any.priority= doodadWire->any.priority;
- doodad->any.top= doodadWire->any.top;
- doodad->any.left= doodadWire->any.left;
- doodad->any.angle= doodadWire->any.angle;
- switch (doodad->any.type) {
- case XkbOutlineDoodad:
- case XkbSolidDoodad:
- doodad->shape.color_ndx= doodadWire->shape.colorNdx;
- doodad->shape.shape_ndx= doodadWire->shape.shapeNdx;
- break;
- case XkbTextDoodad:
- doodad->text.width= doodadWire->text.width;
- doodad->text.height= doodadWire->text.height;
- doodad->text.color_ndx= doodadWire->text.colorNdx;
- if (!_XkbGetReadBufferCountedString(buf,&doodad->text.text))
- return BadLength;
- if (!_XkbGetReadBufferCountedString(buf,&doodad->text.font))
- return BadLength;
- break;
- case XkbIndicatorDoodad:
- doodad->indicator.shape_ndx= doodadWire->indicator.shapeNdx;
- doodad->indicator.on_color_ndx= doodadWire->indicator.onColorNdx;
- doodad->indicator.off_color_ndx= doodadWire->indicator.offColorNdx;
- break;
- case XkbLogoDoodad:
- doodad->logo.color_ndx= doodadWire->logo.colorNdx;
- doodad->logo.shape_ndx= doodadWire->logo.shapeNdx;
- if (!_XkbGetReadBufferCountedString(buf,&doodad->logo.logo_name))
- return BadLength;
- break;
- default:
- return BadValue;
- }
- return Success;
-}
-
-static Status
-_XkbReadGeomOverlay( XkbReadBufferPtr buf,
- XkbGeometryPtr geom,
- XkbSectionPtr section)
-{
-XkbOverlayPtr ol;
-xkbOverlayWireDesc * olWire;
-register int r;
-
- olWire= (xkbOverlayWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayWireDesc));
- if (olWire==NULL)
- return BadLength;
- ol= XkbAddGeomOverlay(section,olWire->name,olWire->nRows);
- if (ol==NULL)
- return BadLength;
- for (r=0;r<olWire->nRows;r++) {
- register int k;
- XkbOverlayRowPtr row;
- xkbOverlayRowWireDesc * rowWire;
- xkbOverlayKeyWireDesc * keyWire;
- rowWire= (xkbOverlayRowWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayRowWireDesc));
- if (rowWire==NULL)
- return BadLength;
- row= XkbAddGeomOverlayRow(ol,rowWire->rowUnder,rowWire->nKeys);
- row->row_under= rowWire->rowUnder;
- if (!row)
- return BadAlloc;
- if (rowWire->nKeys<1)
- continue;
- keyWire= (xkbOverlayKeyWireDesc *)
- _XkbGetReadBufferPtr(buf,
- SIZEOF(xkbOverlayKeyWireDesc)*rowWire->nKeys);
- if (keyWire==NULL)
- return BadLength;
- for (k=0;k<rowWire->nKeys;k++,keyWire++,row->num_keys++) {
- memcpy(row->keys[row->num_keys].over.name,keyWire->over,
- XkbKeyNameLength);
- memcpy(row->keys[row->num_keys].under.name,keyWire->under,
- XkbKeyNameLength);
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadGeomSections( XkbReadBufferPtr buf,
- XkbGeometryPtr geom,
- xkbGetGeometryReply * rep)
-{
-register int s;
-XkbSectionPtr section;
-xkbSectionWireDesc * sectionWire;
-Status rtrn;
-
- if (rep->nSections<1)
- return Success;
- if ((rtrn=XkbAllocGeomSections(geom,rep->nSections))!=Success)
- return rtrn;
- for (s=0;s<rep->nSections;s++) {
- sectionWire= (xkbSectionWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbSectionWireDesc));
- if (!sectionWire)
- return BadLength;
- section= XkbAddGeomSection(geom,sectionWire->name,sectionWire->nRows,
- sectionWire->nDoodads,
- sectionWire->nOverlays);
- if (!section)
- return BadAlloc;
- section->top= sectionWire->top;
- section->left= sectionWire->left;
- section->width= sectionWire->width;
- section->height= sectionWire->height;
- section->angle= sectionWire->angle;
- section->priority= sectionWire->priority;
- if (sectionWire->nRows>0) {
- register int r;
- XkbRowPtr row;
- xkbRowWireDesc * rowWire;
- for (r=0;r<sectionWire->nRows;r++) {
- rowWire= (xkbRowWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbRowWireDesc));
- if (!rowWire)
- return BadLength;
- row= XkbAddGeomRow(section,rowWire->nKeys);
- if (!row)
- return BadAlloc;
- row->top= rowWire->top;
- row->left= rowWire->left;
- row->vertical= rowWire->vertical;
- if (rowWire->nKeys>0) {
- register int k;
- XkbKeyPtr key;
- xkbKeyWireDesc * keyWire;
- for (k=0;k<rowWire->nKeys;k++) {
- keyWire= (xkbKeyWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbKeyWireDesc));
- if (!keyWire)
- return BadLength;
- key= XkbAddGeomKey(row);
- if (!key)
- return BadAlloc;
- memcpy(key->name.name,keyWire->name,XkbKeyNameLength);
- key->gap= keyWire->gap;
- key->shape_ndx= keyWire->shapeNdx;
- key->color_ndx= keyWire->colorNdx;
- }
- }
- }
- }
- if (sectionWire->nDoodads>0) {
- register int d;
- for (d=0;d<sectionWire->nDoodads;d++) {
- if ((rtrn=_XkbReadGeomDoodad(buf,geom,section))!=Success)
- return rtrn;
- }
- }
- if (sectionWire->nOverlays>0) {
- register int o;
- for (o=0;o<sectionWire->nOverlays;o++) {
- if ((rtrn=_XkbReadGeomOverlay(buf,geom,section))!=Success)
- return rtrn;
- }
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadGeomDoodads( XkbReadBufferPtr buf,
- XkbGeometryPtr geom,
- xkbGetGeometryReply * rep)
-{
-register int d;
-Status rtrn;
-
- if (rep->nDoodads<1)
- return Success;
- if ((rtrn=XkbAllocGeomDoodads(geom,rep->nDoodads))!=Success)
- return rtrn;
- for (d=0;d<rep->nDoodads;d++) {
- if ((rtrn=_XkbReadGeomDoodad(buf,geom,NULL))!=Success)
- return rtrn;
- }
- return Success;
-}
-
-Status
-_XkbReadGetGeometryReply( Display * dpy,
- xkbGetGeometryReply * rep,
- XkbDescPtr xkb,
- int * nread_rtrn)
-{
-XkbGeometryPtr geom;
-
- geom= _XkbTypedCalloc(1,XkbGeometryRec);
- if (!geom)
- return BadAlloc;
- if (xkb->geom)
- XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True);
- xkb->geom= geom;
-
- geom->name= rep->name;
- geom->width_mm= rep->widthMM;
- geom->height_mm= rep->heightMM;
- if (rep->length) {
- XkbReadBufferRec buf;
- int left;
- if (_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) {
- Status status= Success;
- if (nread_rtrn)
- *nread_rtrn= (int)rep->length*4;
- if (!_XkbGetReadBufferCountedString(&buf,&geom->label_font))
- status= BadLength;
- if (status==Success)
- status= _XkbReadGeomProperties(&buf,geom,rep);
- if (status==Success)
- status= _XkbReadGeomColors(&buf,geom,rep);
- if (status==Success)
- status= _XkbReadGeomShapes(&buf,geom,rep);
- if (status==Success)
- status= _XkbReadGeomSections(&buf,geom,rep);
- if (status==Success)
- status= _XkbReadGeomDoodads(&buf,geom,rep);
- if (status==Success)
- status= _XkbReadGeomKeyAliases(&buf,geom,rep);
- left= _XkbFreeReadBuffer(&buf);
- if ((status!=Success) || left || buf.error) {
- if (status==Success)
- status= BadLength;
- XkbFreeGeometry(geom,XkbGeomAllMask,True);
- xkb->geom= NULL;
- return status;
- }
- geom->base_color= &geom->colors[rep->baseColorNdx];
- geom->label_color= &geom->colors[rep->labelColorNdx];
- }
- else {
- XkbFreeGeometry(geom,XkbGeomAllMask,True);
- xkb->geom= NULL;
- return BadAlloc;
- }
- }
- return Success;
-}
-
-Status
-XkbGetGeometry(Display *dpy,XkbDescPtr xkb)
-{
-xkbGetGeometryReq *req;
-xkbGetGeometryReply rep;
-Status status;
-
- if ( (!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- LockDisplay(dpy);
- GetReq(kbGetGeometry, req);
- req->reqType = dpy->xkb_info->codes->major_opcode;
- req->xkbReqType = X_kbGetGeometry;
- req->deviceSpec = xkb->device_spec;
- req->name= None;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
- status = BadImplementation;
- else if (!rep.found)
- status = BadName;
- else
- status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL);
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetNamedGeometry(Display *dpy,XkbDescPtr xkb,Atom name)
-{
-xkbGetGeometryReq *req;
-xkbGetGeometryReply rep;
-Status status;
-
- if ( (name==None) || (dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) )
- return BadAccess;
-
- LockDisplay(dpy);
- GetReq(kbGetGeometry, req);
- req->reqType = dpy->xkb_info->codes->major_opcode;
- req->xkbReqType = X_kbGetGeometry;
- req->deviceSpec = xkb->device_spec;
- req->name= (CARD32)name;
- if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.found))
- status = BadImplementation;
- else if (!rep.found)
- status = BadName;
- else
- status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL);
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 DEBUG
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#endif
+
+#define NEED_MAP_READERS
+#include "Xlibint.h"
+#include <X11/extensions/XKBgeom.h>
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+#define MINSHORT -32768
+#define MAXSHORT 32767
+
+/***====================================================================***/
+
+static void
+_XkbCheckBounds(XkbBoundsPtr bounds,int x,int y)
+{
+ if (x<bounds->x1) bounds->x1= x;
+ if (x>bounds->x2) bounds->x2= x;
+ if (y<bounds->y1) bounds->y1= y;
+ if (y>bounds->y2) bounds->y2= y;
+ return;
+}
+
+Bool
+XkbComputeShapeBounds(XkbShapePtr shape)
+{
+register int o,p;
+XkbOutlinePtr outline;
+XkbPointPtr pt;
+
+ if ((!shape)||(shape->num_outlines<1))
+ return False;
+ shape->bounds.x1= shape->bounds.y1= MAXSHORT;
+ shape->bounds.x2= shape->bounds.y2= MINSHORT;
+ for (outline=shape->outlines,o=0;o<shape->num_outlines;o++,outline++) {
+ for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) {
+ _XkbCheckBounds(&shape->bounds,pt->x,pt->y);
+ }
+ if (outline->num_points<2) {
+ _XkbCheckBounds(&shape->bounds,0,0);
+ }
+ }
+ return True;
+}
+
+Bool
+XkbComputeShapeTop(XkbShapePtr shape,XkbBoundsPtr bounds)
+{
+register int p;
+XkbOutlinePtr outline;
+XkbPointPtr pt;
+
+ if ((!shape)||(shape->num_outlines<1))
+ return False;
+ if (shape->approx) outline= shape->approx;
+ else outline= &shape->outlines[shape->num_outlines-1];
+ if (outline->num_points<2) {
+ bounds->x1= bounds->y1= 0;
+ bounds->x2= bounds->y2= 0;
+ }
+ else {
+ bounds->x1= bounds->y1= MAXSHORT;
+ bounds->x2= bounds->y2= MINSHORT;
+ }
+ for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) {
+ _XkbCheckBounds(bounds,pt->x,pt->y);
+ }
+ return True;
+}
+
+Bool
+XkbComputeRowBounds(XkbGeometryPtr geom,XkbSectionPtr section,XkbRowPtr row)
+{
+register int k,pos;
+XkbKeyPtr key;
+XkbBoundsPtr bounds,sbounds;
+
+ if ((!geom)||(!section)||(!row))
+ return False;
+ pos= 0;
+ bounds= &row->bounds;
+ bzero(bounds,sizeof(XkbBoundsRec));
+ for (key=row->keys,pos=k=0;k<row->num_keys;k++,key++) {
+ sbounds= &XkbKeyShape(geom,key)->bounds;
+ _XkbCheckBounds(bounds,pos,0);
+ if (!row->vertical) {
+ if (key->gap!=0) {
+ pos+= key->gap;
+ _XkbCheckBounds(bounds,pos,0);
+ }
+ _XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1);
+ _XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2);
+ pos+= sbounds->x2;
+ }
+ else {
+ if (key->gap!=0) {
+ pos+= key->gap;
+ _XkbCheckBounds(bounds,0,pos);
+ }
+ _XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1);
+ _XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2);
+ pos+= sbounds->y2;
+ }
+ }
+ return True;
+}
+
+Bool
+XkbComputeSectionBounds(XkbGeometryPtr geom,XkbSectionPtr section)
+{
+register int i;
+XkbShapePtr shape;
+XkbRowPtr row;
+XkbDoodadPtr doodad;
+XkbBoundsPtr bounds,rbounds=NULL;
+
+ if ((!geom)||(!section))
+ return False;
+ bounds= &section->bounds;
+ bzero(bounds,sizeof(XkbBoundsRec));
+ for (i=0,row=section->rows;i<section->num_rows;i++,row++) {
+ if (!XkbComputeRowBounds(geom,section,row))
+ return False;
+ rbounds= &row->bounds;
+ _XkbCheckBounds(bounds,row->left+rbounds->x1,row->top+rbounds->y1);
+ _XkbCheckBounds(bounds,row->left+rbounds->x2,row->top+rbounds->y2);
+ }
+ for (i=0,doodad=section->doodads;i<section->num_doodads;i++,doodad++) {
+ static XkbBoundsRec tbounds;
+ switch (doodad->any.type) {
+ case XkbOutlineDoodad:
+ case XkbSolidDoodad:
+ shape= XkbShapeDoodadShape(geom,&doodad->shape);
+ rbounds= &shape->bounds;
+ break;
+ case XkbTextDoodad:
+ tbounds.x1= doodad->text.left;
+ tbounds.y1= doodad->text.top;
+ tbounds.x2= tbounds.x1+doodad->text.width;
+ tbounds.y2= tbounds.y1+doodad->text.height;
+ rbounds= &tbounds;
+ break;
+ case XkbIndicatorDoodad:
+ shape= XkbIndicatorDoodadShape(geom,&doodad->indicator);
+ rbounds= &shape->bounds;
+ break;
+ case XkbLogoDoodad:
+ shape= XkbLogoDoodadShape(geom,&doodad->logo);
+ rbounds= &shape->bounds;
+ break;
+ default:
+ tbounds.x1= tbounds.x2= doodad->any.left;
+ tbounds.y1= tbounds.y2= doodad->any.top;
+ break;
+ }
+ _XkbCheckBounds(bounds,rbounds->x1,rbounds->y1);
+ _XkbCheckBounds(bounds,rbounds->x2,rbounds->y2);
+ }
+ return True;
+}
+
+/***====================================================================***/
+
+char *
+XkbFindOverlayForKey(XkbGeometryPtr geom,XkbSectionPtr wanted,char *under)
+{
+int s;
+XkbSectionPtr section;
+
+ if ((geom==NULL)||(under==NULL)||(geom->num_sections<1))
+ return NULL;
+
+ if (wanted)
+ section= wanted;
+ else section= geom->sections;
+
+ for (s=0;s<geom->num_sections;s++,section++) {
+ XkbOverlayPtr ol;
+ int o;
+
+ if (section->num_overlays<1)
+ continue;
+ for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) {
+ XkbOverlayRowPtr row;
+ int r;
+
+ for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
+ XkbOverlayKeyPtr key;
+ int k;
+ for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
+ if (strncmp(under,key->under.name,XkbKeyNameLength)==0)
+ return key->over.name;
+ }
+ }
+ }
+ if (wanted!=NULL)
+ break;
+ }
+ return NULL;
+}
+
+/***====================================================================***/
+
+static Status
+_XkbReadGeomProperties( XkbReadBufferPtr buf,
+ XkbGeometryPtr geom,
+ xkbGetGeometryReply * rep)
+{
+Status rtrn;
+
+ if (rep->nProperties<1)
+ return Success;
+ if ((rtrn=XkbAllocGeomProps(geom,rep->nProperties))==Success) {
+ register int i;
+ register Bool ok;
+ char *name,*value;
+ ok= True;
+ for (i=0;(i<rep->nProperties)&&ok;i++) {
+ name=NULL;
+ value=NULL;
+ ok= _XkbGetReadBufferCountedString(buf,&name)&&ok;
+ ok= _XkbGetReadBufferCountedString(buf,&value)&&ok;
+ ok= ok&&(XkbAddGeomProperty(geom,name,value)!=NULL);
+ if (name)
+ _XkbFree(name);
+ if (value)
+ _XkbFree(value);
+ }
+ if (ok) rtrn= Success;
+ else rtrn= BadLength;
+ }
+ return rtrn;
+}
+
+static Status
+_XkbReadGeomKeyAliases( XkbReadBufferPtr buf,
+ XkbGeometryPtr geom,
+ xkbGetGeometryReply * rep)
+{
+Status rtrn;
+
+ if (rep->nKeyAliases<1)
+ return Success;
+ if ((rtrn=XkbAllocGeomKeyAliases(geom,rep->nKeyAliases))==Success) {
+ if (!_XkbCopyFromReadBuffer(buf,(char *)geom->key_aliases,
+ (rep->nKeyAliases*XkbKeyNameLength*2)))
+ return BadLength;
+ geom->num_key_aliases= rep->nKeyAliases;
+ return Success;
+ }
+ else { /* alloc failed, just skip the aliases */
+ _XkbSkipReadBufferData(buf,(rep->nKeyAliases*XkbKeyNameLength*2));
+ }
+ return rtrn;
+}
+
+static Status
+_XkbReadGeomColors( XkbReadBufferPtr buf,
+ XkbGeometryPtr geom,
+ xkbGetGeometryReply * rep)
+{
+Status rtrn;
+
+ if (rep->nColors<1)
+ return Success;
+ if ((rtrn=XkbAllocGeomColors(geom,rep->nColors))==Success) {
+ register int i;
+ char *spec;
+ for (i=0;i<rep->nColors;i++) {
+ spec = NULL;
+ if (!_XkbGetReadBufferCountedString(buf,&spec))
+ rtrn = BadLength;
+ else if (XkbAddGeomColor(geom,spec,geom->num_colors)==NULL)
+ rtrn = BadAlloc;
+ if (spec)
+ _XkbFree(spec);
+ if (rtrn != Success)
+ return rtrn;
+ }
+ return Success;
+ }
+ return rtrn;
+}
+
+static Status
+_XkbReadGeomShapes( XkbReadBufferPtr buf,
+ XkbGeometryPtr geom,
+ xkbGetGeometryReply * rep)
+{
+register int i;
+Status rtrn;
+
+ if (rep->nShapes<1)
+ return Success;
+ if ((rtrn=XkbAllocGeomShapes(geom,rep->nShapes))!=Success)
+ return rtrn;
+ for (i=0;i<rep->nShapes;i++) {
+ xkbShapeWireDesc *shapeWire;
+ XkbShapePtr shape;
+ register int o;
+ shapeWire= (xkbShapeWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbShapeWireDesc));
+ if (!shapeWire)
+ return BadLength;
+ shape= XkbAddGeomShape(geom,shapeWire->name,shapeWire->nOutlines);
+ if (!shape)
+ return BadAlloc;
+ for (o=0;o<shapeWire->nOutlines;o++) {
+ xkbOutlineWireDesc *olWire;
+ XkbOutlinePtr ol;
+ register int p;
+ XkbPointPtr pt;
+ olWire= (xkbOutlineWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbOutlineWireDesc));
+ if (!olWire)
+ return BadLength;
+ ol= XkbAddGeomOutline(shape,olWire->nPoints);
+ if (!ol)
+ return BadAlloc;
+ ol->corner_radius= olWire->cornerRadius;
+ for (p=0,pt=ol->points;p<olWire->nPoints;p++,pt++) {
+ xkbPointWireDesc * ptWire;
+ ptWire= (xkbPointWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbPointWireDesc));
+ if (!ptWire)
+ return BadLength;
+ pt->x= ptWire->x;
+ pt->y= ptWire->y;
+ }
+ ol->num_points= olWire->nPoints;
+ }
+ if (shapeWire->primaryNdx!=XkbNoShape)
+ shape->primary= &shape->outlines[shapeWire->primaryNdx];
+ else shape->primary= NULL;
+ if (shapeWire->approxNdx!=XkbNoShape)
+ shape->approx= &shape->outlines[shapeWire->approxNdx];
+ else shape->approx= NULL;
+ XkbComputeShapeBounds(shape);
+ }
+ return Success;
+}
+
+static Status
+_XkbReadGeomDoodad( XkbReadBufferPtr buf,
+ XkbGeometryPtr geom,
+ XkbSectionPtr section)
+{
+XkbDoodadPtr doodad;
+xkbDoodadWireDesc * doodadWire;
+
+ doodadWire= (xkbDoodadWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbDoodadWireDesc));
+ if (!doodadWire)
+ return BadLength;
+ doodad= XkbAddGeomDoodad(geom,section,doodadWire->any.name);
+ if (!doodad)
+ return BadAlloc;
+ doodad->any.type= doodadWire->any.type;
+ doodad->any.priority= doodadWire->any.priority;
+ doodad->any.top= doodadWire->any.top;
+ doodad->any.left= doodadWire->any.left;
+ doodad->any.angle= doodadWire->any.angle;
+ switch (doodad->any.type) {
+ case XkbOutlineDoodad:
+ case XkbSolidDoodad:
+ doodad->shape.color_ndx= doodadWire->shape.colorNdx;
+ doodad->shape.shape_ndx= doodadWire->shape.shapeNdx;
+ break;
+ case XkbTextDoodad:
+ doodad->text.width= doodadWire->text.width;
+ doodad->text.height= doodadWire->text.height;
+ doodad->text.color_ndx= doodadWire->text.colorNdx;
+ if (!_XkbGetReadBufferCountedString(buf,&doodad->text.text))
+ return BadLength;
+ if (!_XkbGetReadBufferCountedString(buf,&doodad->text.font))
+ return BadLength;
+ break;
+ case XkbIndicatorDoodad:
+ doodad->indicator.shape_ndx= doodadWire->indicator.shapeNdx;
+ doodad->indicator.on_color_ndx= doodadWire->indicator.onColorNdx;
+ doodad->indicator.off_color_ndx= doodadWire->indicator.offColorNdx;
+ break;
+ case XkbLogoDoodad:
+ doodad->logo.color_ndx= doodadWire->logo.colorNdx;
+ doodad->logo.shape_ndx= doodadWire->logo.shapeNdx;
+ if (!_XkbGetReadBufferCountedString(buf,&doodad->logo.logo_name))
+ return BadLength;
+ break;
+ default:
+ return BadValue;
+ }
+ return Success;
+}
+
+static Status
+_XkbReadGeomOverlay( XkbReadBufferPtr buf,
+ XkbGeometryPtr geom,
+ XkbSectionPtr section)
+{
+XkbOverlayPtr ol;
+xkbOverlayWireDesc * olWire;
+register int r;
+
+ olWire= (xkbOverlayWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayWireDesc));
+ if (olWire==NULL)
+ return BadLength;
+ ol= XkbAddGeomOverlay(section,olWire->name,olWire->nRows);
+ if (ol==NULL)
+ return BadLength;
+ for (r=0;r<olWire->nRows;r++) {
+ register int k;
+ XkbOverlayRowPtr row;
+ xkbOverlayRowWireDesc * rowWire;
+ xkbOverlayKeyWireDesc * keyWire;
+ rowWire= (xkbOverlayRowWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayRowWireDesc));
+ if (rowWire==NULL)
+ return BadLength;
+ row= XkbAddGeomOverlayRow(ol,rowWire->rowUnder,rowWire->nKeys);
+ row->row_under= rowWire->rowUnder;
+ if (!row)
+ return BadAlloc;
+ if (rowWire->nKeys<1)
+ continue;
+ keyWire= (xkbOverlayKeyWireDesc *)
+ _XkbGetReadBufferPtr(buf,
+ SIZEOF(xkbOverlayKeyWireDesc)*rowWire->nKeys);
+ if (keyWire==NULL)
+ return BadLength;
+ for (k=0;k<rowWire->nKeys;k++,keyWire++,row->num_keys++) {
+ memcpy(row->keys[row->num_keys].over.name,keyWire->over,
+ XkbKeyNameLength);
+ memcpy(row->keys[row->num_keys].under.name,keyWire->under,
+ XkbKeyNameLength);
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadGeomSections( XkbReadBufferPtr buf,
+ XkbGeometryPtr geom,
+ xkbGetGeometryReply * rep)
+{
+register int s;
+XkbSectionPtr section;
+xkbSectionWireDesc * sectionWire;
+Status rtrn;
+
+ if (rep->nSections<1)
+ return Success;
+ if ((rtrn=XkbAllocGeomSections(geom,rep->nSections))!=Success)
+ return rtrn;
+ for (s=0;s<rep->nSections;s++) {
+ sectionWire= (xkbSectionWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbSectionWireDesc));
+ if (!sectionWire)
+ return BadLength;
+ section= XkbAddGeomSection(geom,sectionWire->name,sectionWire->nRows,
+ sectionWire->nDoodads,
+ sectionWire->nOverlays);
+ if (!section)
+ return BadAlloc;
+ section->top= sectionWire->top;
+ section->left= sectionWire->left;
+ section->width= sectionWire->width;
+ section->height= sectionWire->height;
+ section->angle= sectionWire->angle;
+ section->priority= sectionWire->priority;
+ if (sectionWire->nRows>0) {
+ register int r;
+ XkbRowPtr row;
+ xkbRowWireDesc * rowWire;
+ for (r=0;r<sectionWire->nRows;r++) {
+ rowWire= (xkbRowWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbRowWireDesc));
+ if (!rowWire)
+ return BadLength;
+ row= XkbAddGeomRow(section,rowWire->nKeys);
+ if (!row)
+ return BadAlloc;
+ row->top= rowWire->top;
+ row->left= rowWire->left;
+ row->vertical= rowWire->vertical;
+ if (rowWire->nKeys>0) {
+ register int k;
+ XkbKeyPtr key;
+ xkbKeyWireDesc * keyWire;
+ for (k=0;k<rowWire->nKeys;k++) {
+ keyWire= (xkbKeyWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbKeyWireDesc));
+ if (!keyWire)
+ return BadLength;
+ key= XkbAddGeomKey(row);
+ if (!key)
+ return BadAlloc;
+ memcpy(key->name.name,keyWire->name,XkbKeyNameLength);
+ key->gap= keyWire->gap;
+ key->shape_ndx= keyWire->shapeNdx;
+ key->color_ndx= keyWire->colorNdx;
+ }
+ }
+ }
+ }
+ if (sectionWire->nDoodads>0) {
+ register int d;
+ for (d=0;d<sectionWire->nDoodads;d++) {
+ if ((rtrn=_XkbReadGeomDoodad(buf,geom,section))!=Success)
+ return rtrn;
+ }
+ }
+ if (sectionWire->nOverlays>0) {
+ register int o;
+ for (o=0;o<sectionWire->nOverlays;o++) {
+ if ((rtrn=_XkbReadGeomOverlay(buf,geom,section))!=Success)
+ return rtrn;
+ }
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadGeomDoodads( XkbReadBufferPtr buf,
+ XkbGeometryPtr geom,
+ xkbGetGeometryReply * rep)
+{
+register int d;
+Status rtrn;
+
+ if (rep->nDoodads<1)
+ return Success;
+ if ((rtrn=XkbAllocGeomDoodads(geom,rep->nDoodads))!=Success)
+ return rtrn;
+ for (d=0;d<rep->nDoodads;d++) {
+ if ((rtrn=_XkbReadGeomDoodad(buf,geom,NULL))!=Success)
+ return rtrn;
+ }
+ return Success;
+}
+
+Status
+_XkbReadGetGeometryReply( Display * dpy,
+ xkbGetGeometryReply * rep,
+ XkbDescPtr xkb,
+ int * nread_rtrn)
+{
+XkbGeometryPtr geom;
+
+ geom= _XkbTypedCalloc(1,XkbGeometryRec);
+ if (!geom)
+ return BadAlloc;
+ if (xkb->geom)
+ XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True);
+ xkb->geom= geom;
+
+ geom->name= rep->name;
+ geom->width_mm= rep->widthMM;
+ geom->height_mm= rep->heightMM;
+ if (rep->length) {
+ XkbReadBufferRec buf;
+ int left;
+ if (_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) {
+ Status status= Success;
+ if (nread_rtrn)
+ *nread_rtrn= (int)rep->length*4;
+ if (!_XkbGetReadBufferCountedString(&buf,&geom->label_font))
+ status= BadLength;
+ if (status==Success)
+ status= _XkbReadGeomProperties(&buf,geom,rep);
+ if (status==Success)
+ status= _XkbReadGeomColors(&buf,geom,rep);
+ if (status==Success)
+ status= _XkbReadGeomShapes(&buf,geom,rep);
+ if (status==Success)
+ status= _XkbReadGeomSections(&buf,geom,rep);
+ if (status==Success)
+ status= _XkbReadGeomDoodads(&buf,geom,rep);
+ if (status==Success)
+ status= _XkbReadGeomKeyAliases(&buf,geom,rep);
+ left= _XkbFreeReadBuffer(&buf);
+ if ((status!=Success) || left || buf.error) {
+ if (status==Success)
+ status= BadLength;
+ XkbFreeGeometry(geom,XkbGeomAllMask,True);
+ xkb->geom= NULL;
+ return status;
+ }
+ geom->base_color= &geom->colors[rep->baseColorNdx];
+ geom->label_color= &geom->colors[rep->labelColorNdx];
+ }
+ else {
+ XkbFreeGeometry(geom,XkbGeomAllMask,True);
+ xkb->geom= NULL;
+ return BadAlloc;
+ }
+ }
+ return Success;
+}
+
+Status
+XkbGetGeometry(Display *dpy,XkbDescPtr xkb)
+{
+xkbGetGeometryReq *req;
+xkbGetGeometryReply rep;
+Status status;
+
+ if ( (!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ LockDisplay(dpy);
+ GetReq(kbGetGeometry, req);
+ req->reqType = dpy->xkb_info->codes->major_opcode;
+ req->xkbReqType = X_kbGetGeometry;
+ req->deviceSpec = xkb->device_spec;
+ req->name= None;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
+ status = BadImplementation;
+ else if (!rep.found)
+ status = BadName;
+ else
+ status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetNamedGeometry(Display *dpy,XkbDescPtr xkb,Atom name)
+{
+xkbGetGeometryReq *req;
+xkbGetGeometryReply rep;
+Status status;
+
+ if ( (name==None) || (dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) )
+ return BadAccess;
+
+ LockDisplay(dpy);
+ GetReq(kbGetGeometry, req);
+ req->reqType = dpy->xkb_info->codes->major_opcode;
+ req->xkbReqType = X_kbGetGeometry;
+ req->deviceSpec = xkb->device_spec;
+ req->name= (CARD32)name;
+ if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.found))
+ status = BadImplementation;
+ else if (!rep.found)
+ status = BadName;
+ else
+ status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
diff --git a/libX11/src/xkb/XKBGetByName.c b/libX11/src/xkb/XKBGetByName.c
index 15d0338a5..9417238ce 100644
--- a/libX11/src/xkb/XKBGetByName.c
+++ b/libX11/src/xkb/XKBGetByName.c
@@ -1,216 +1,214 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_REPLIES
-#define NEED_EVENTS
-#define NEED_MAP_READERS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-/***====================================================================***/
-
-XkbDescPtr
-XkbGetKeyboardByName( Display * dpy,
- unsigned deviceSpec,
- XkbComponentNamesPtr names,
- unsigned want,
- unsigned need,
- Bool load)
-{
- register xkbGetKbdByNameReq * req;
- xkbGetKbdByNameReply rep;
- int len,extraLen;
- char * str;
- XkbDescPtr xkb;
- int mapLen,codesLen,typesLen,compatLen;
- int symsLen,geomLen;
- XkbInfoPtr xkbi;
-
- if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) )
- return NULL;
-
- xkbi= dpy->xkb_info;
- xkb = (XkbDescRec *)_XkbCalloc(1,sizeof(XkbDescRec));
- if (!xkb)
- return NULL;
- xkb->device_spec = deviceSpec;
- xkb->map = (XkbClientMapRec *)_XkbCalloc(1,sizeof(XkbClientMapRec));
- xkb->dpy = dpy;
-
- LockDisplay(dpy);
- GetReq(kbGetKbdByName, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetKbdByName;
- req->deviceSpec = xkb->device_spec;
- req->want= want;
- req->need= need;
- req->load= load;
-
- mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
- if (names) {
- if (names->keymap)
- mapLen= (int)strlen(names->keymap);
- if (names->keycodes)
- codesLen= (int)strlen(names->keycodes);
- if (names->types)
- typesLen= (int)strlen(names->types);
- if (names->compat)
- compatLen= (int)strlen(names->compat);
- if (names->symbols)
- symsLen= (int)strlen(names->symbols);
- if (names->geometry)
- geomLen= (int)strlen(names->geometry);
- if (mapLen>255) mapLen= 255;
- if (codesLen>255) codesLen= 255;
- if (typesLen>255) typesLen= 255;
- if (compatLen>255) compatLen= 255;
- if (symsLen>255) symsLen= 255;
- if (geomLen>255) geomLen= 255;
- }
- else mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
-
- len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6;
- len= XkbPaddedSize(len);
- req->length+= len/4;
- BufAlloc(char *,str,len);
- *str++= mapLen;
- if (mapLen>0) {
- memcpy(str,names->keymap,mapLen);
- str+= mapLen;
- }
- *str++= codesLen;
- if (codesLen>0) {
- memcpy(str,names->keycodes,codesLen);
- str+= codesLen;
- }
- *str++= typesLen;
- if (typesLen>0) {
- memcpy(str,names->types,typesLen);
- str+= typesLen;
- }
- *str++= compatLen;
- if (compatLen>0) {
- memcpy(str,names->compat,compatLen);
- str+= compatLen;
- }
- *str++= symsLen;
- if (symsLen>0) {
- memcpy(str,names->symbols,symsLen);
- str+= symsLen;
- }
- *str++= geomLen;
- if (geomLen>0) {
- memcpy(str,names->geometry,geomLen);
- str+= geomLen;
- }
- if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.reported))
- goto BAILOUT;
- extraLen= (int)rep.length*4;
-
- xkb->device_spec= rep.deviceID;
- xkb->min_key_code = rep.minKeyCode;
- xkb->max_key_code = rep.maxKeyCode;
- if (rep.reported&(XkbGBN_SymbolsMask|XkbGBN_TypesMask)) {
- xkbGetMapReply mrep;
- Status status;
- int nread= 0;
-
- _XRead(dpy, (char *)&mrep, SIZEOF(xkbGetMapReply));
- extraLen-= SIZEOF(xkbGetMapReply);
- status= _XkbReadGetMapReply(dpy,&mrep,xkb,&nread);
- extraLen-= nread;
- if (status!=Success)
- goto BAILOUT;
- }
- if (rep.reported&XkbGBN_CompatMapMask) {
- xkbGetCompatMapReply crep;
- Status status;
- int nread= 0;
-
- _XRead(dpy, (char *)&crep, SIZEOF(xkbGetCompatMapReply));
- extraLen-= SIZEOF(xkbGetCompatMapReply);
- status= _XkbReadGetCompatMapReply(dpy,&crep,xkb,&nread);
- extraLen-= nread;
- if (status!=Success)
- goto BAILOUT;
- }
- if (rep.reported&XkbGBN_IndicatorMapMask) {
- xkbGetIndicatorMapReply irep;
- Status status;
- int nread= 0;
-
- _XRead(dpy, (char *)&irep, SIZEOF(xkbGetIndicatorMapReply));
- extraLen-= SIZEOF(xkbGetIndicatorMapReply);
- status= _XkbReadGetIndicatorMapReply(dpy,&irep,xkb,&nread);
- extraLen-= nread;
- if (status!=Success)
- goto BAILOUT;
- }
- if (rep.reported&(XkbGBN_KeyNamesMask|XkbGBN_OtherNamesMask)) {
- xkbGetNamesReply nrep;
- Status status;
- int nread= 0;
-
- _XRead(dpy, (char *)&nrep, SIZEOF(xkbGetNamesReply));
- extraLen-= SIZEOF(xkbGetNamesReply);
- status= _XkbReadGetNamesReply(dpy,&nrep,xkb,&nread);
- extraLen-= nread;
- if (status!=Success)
- goto BAILOUT;
- }
- if (rep.reported&XkbGBN_GeometryMask) {
- xkbGetGeometryReply grep;
- Status status;
- int nread= 0;
-
- _XRead(dpy, (char *)&grep, SIZEOF(xkbGetGeometryReply));
- extraLen-= SIZEOF(xkbGetGeometryReply);
- status= _XkbReadGetGeometryReply(dpy,&grep,xkb,&nread);
- extraLen-= nread;
- if (status!=Success)
- goto BAILOUT;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return xkb;
-BAILOUT:
- if (xkb!=NULL)
- XkbFreeKeyboard(xkb,XkbAllComponentsMask,xTrue);
- UnlockDisplay(dpy);
- SyncHandle();
- return NULL;
-}
-
-XkbDescPtr
-XkbGetKeyboard(Display *dpy,unsigned which,unsigned deviceSpec)
-{
- return XkbGetKeyboardByName(dpy,deviceSpec,NULL,which,which,False);
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_MAP_READERS
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+/***====================================================================***/
+
+XkbDescPtr
+XkbGetKeyboardByName( Display * dpy,
+ unsigned deviceSpec,
+ XkbComponentNamesPtr names,
+ unsigned want,
+ unsigned need,
+ Bool load)
+{
+ register xkbGetKbdByNameReq * req;
+ xkbGetKbdByNameReply rep;
+ int len,extraLen;
+ char * str;
+ XkbDescPtr xkb;
+ int mapLen,codesLen,typesLen,compatLen;
+ int symsLen,geomLen;
+ XkbInfoPtr xkbi;
+
+ if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) )
+ return NULL;
+
+ xkbi= dpy->xkb_info;
+ xkb = (XkbDescRec *)_XkbCalloc(1,sizeof(XkbDescRec));
+ if (!xkb)
+ return NULL;
+ xkb->device_spec = deviceSpec;
+ xkb->map = (XkbClientMapRec *)_XkbCalloc(1,sizeof(XkbClientMapRec));
+ xkb->dpy = dpy;
+
+ LockDisplay(dpy);
+ GetReq(kbGetKbdByName, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetKbdByName;
+ req->deviceSpec = xkb->device_spec;
+ req->want= want;
+ req->need= need;
+ req->load= load;
+
+ mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
+ if (names) {
+ if (names->keymap)
+ mapLen= (int)strlen(names->keymap);
+ if (names->keycodes)
+ codesLen= (int)strlen(names->keycodes);
+ if (names->types)
+ typesLen= (int)strlen(names->types);
+ if (names->compat)
+ compatLen= (int)strlen(names->compat);
+ if (names->symbols)
+ symsLen= (int)strlen(names->symbols);
+ if (names->geometry)
+ geomLen= (int)strlen(names->geometry);
+ if (mapLen>255) mapLen= 255;
+ if (codesLen>255) codesLen= 255;
+ if (typesLen>255) typesLen= 255;
+ if (compatLen>255) compatLen= 255;
+ if (symsLen>255) symsLen= 255;
+ if (geomLen>255) geomLen= 255;
+ }
+ else mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
+
+ len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6;
+ len= XkbPaddedSize(len);
+ req->length+= len/4;
+ BufAlloc(char *,str,len);
+ *str++= mapLen;
+ if (mapLen>0) {
+ memcpy(str,names->keymap,mapLen);
+ str+= mapLen;
+ }
+ *str++= codesLen;
+ if (codesLen>0) {
+ memcpy(str,names->keycodes,codesLen);
+ str+= codesLen;
+ }
+ *str++= typesLen;
+ if (typesLen>0) {
+ memcpy(str,names->types,typesLen);
+ str+= typesLen;
+ }
+ *str++= compatLen;
+ if (compatLen>0) {
+ memcpy(str,names->compat,compatLen);
+ str+= compatLen;
+ }
+ *str++= symsLen;
+ if (symsLen>0) {
+ memcpy(str,names->symbols,symsLen);
+ str+= symsLen;
+ }
+ *str++= geomLen;
+ if (geomLen>0) {
+ memcpy(str,names->geometry,geomLen);
+ str+= geomLen;
+ }
+ if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.reported))
+ goto BAILOUT;
+ extraLen= (int)rep.length*4;
+
+ xkb->device_spec= rep.deviceID;
+ xkb->min_key_code = rep.minKeyCode;
+ xkb->max_key_code = rep.maxKeyCode;
+ if (rep.reported&(XkbGBN_SymbolsMask|XkbGBN_TypesMask)) {
+ xkbGetMapReply mrep;
+ Status status;
+ int nread= 0;
+
+ _XRead(dpy, (char *)&mrep, SIZEOF(xkbGetMapReply));
+ extraLen-= SIZEOF(xkbGetMapReply);
+ status= _XkbReadGetMapReply(dpy,&mrep,xkb,&nread);
+ extraLen-= nread;
+ if (status!=Success)
+ goto BAILOUT;
+ }
+ if (rep.reported&XkbGBN_CompatMapMask) {
+ xkbGetCompatMapReply crep;
+ Status status;
+ int nread= 0;
+
+ _XRead(dpy, (char *)&crep, SIZEOF(xkbGetCompatMapReply));
+ extraLen-= SIZEOF(xkbGetCompatMapReply);
+ status= _XkbReadGetCompatMapReply(dpy,&crep,xkb,&nread);
+ extraLen-= nread;
+ if (status!=Success)
+ goto BAILOUT;
+ }
+ if (rep.reported&XkbGBN_IndicatorMapMask) {
+ xkbGetIndicatorMapReply irep;
+ Status status;
+ int nread= 0;
+
+ _XRead(dpy, (char *)&irep, SIZEOF(xkbGetIndicatorMapReply));
+ extraLen-= SIZEOF(xkbGetIndicatorMapReply);
+ status= _XkbReadGetIndicatorMapReply(dpy,&irep,xkb,&nread);
+ extraLen-= nread;
+ if (status!=Success)
+ goto BAILOUT;
+ }
+ if (rep.reported&(XkbGBN_KeyNamesMask|XkbGBN_OtherNamesMask)) {
+ xkbGetNamesReply nrep;
+ Status status;
+ int nread= 0;
+
+ _XRead(dpy, (char *)&nrep, SIZEOF(xkbGetNamesReply));
+ extraLen-= SIZEOF(xkbGetNamesReply);
+ status= _XkbReadGetNamesReply(dpy,&nrep,xkb,&nread);
+ extraLen-= nread;
+ if (status!=Success)
+ goto BAILOUT;
+ }
+ if (rep.reported&XkbGBN_GeometryMask) {
+ xkbGetGeometryReply grep;
+ Status status;
+ int nread= 0;
+
+ _XRead(dpy, (char *)&grep, SIZEOF(xkbGetGeometryReply));
+ extraLen-= SIZEOF(xkbGetGeometryReply);
+ status= _XkbReadGetGeometryReply(dpy,&grep,xkb,&nread);
+ extraLen-= nread;
+ if (status!=Success)
+ goto BAILOUT;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return xkb;
+BAILOUT:
+ if (xkb!=NULL)
+ XkbFreeKeyboard(xkb,XkbAllComponentsMask,xTrue);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return NULL;
+}
+
+XkbDescPtr
+XkbGetKeyboard(Display *dpy,unsigned which,unsigned deviceSpec)
+{
+ return XkbGetKeyboardByName(dpy,deviceSpec,NULL,which,which,False);
+}
diff --git a/libX11/src/xkb/XKBGetMap.c b/libX11/src/xkb/XKBGetMap.c
index 53ebb2c15..96370c6d3 100644
--- a/libX11/src/xkb/XKBGetMap.c
+++ b/libX11/src/xkb/XKBGetMap.c
@@ -1,859 +1,856 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_REPLIES
-#define NEED_EVENTS
-#define NEED_MAP_READERS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef XKB_IN_SERVER
-#define XkbAllocClientMap SrvXkbAllocClientMap
-#define XkbAllocServerMap SrvXkbAllocServerMap
-#define XkbChangeTypesOfKey SrvXkbChangeTypesOfKey
-#define XkbCopyKeyTypes SrvXkbCopyKeyTypes
-#define XkbFreeClientMap SrvXkbFreeClientMap
-#define XkbFreeServerMap SrvXkbFreeServerMap
-#define XkbKeyTypesForCoreSymbols SrvXkbKeyTypesForCoreSymbols
-#define XkbApplyCompatMapToKey SrvXkbApplyCompatMapToKey
-#define XkbResizeKeyActions SrvXkbResizeKeyActions
-#define XkbResizeKeySyms SrvXkbResizeKeySyms
-#define XkbResizeKeyType SrvXkbResizeKeyType
-#define XkbAllocCompatMap SrvXkbAllocCompatMap
-#define XkbAllocControls SrvXkbAllocControls
-#define XkbAllocIndicatorMaps SrvXkbAllocIndicatorMaps
-#define XkbAllocKeyboard SrvXkbAllocKeyboard
-#define XkbAllocNames SrvXkbAllocNames
-#define XkbFreeCompatMap SrvXkbFreeCompatMap
-#define XkbFreeKeyboard SrvXkbFreeKeyboard
-#define XkbFreeNames SrvXkbFreeNames
-#define XkbLatchModifiers SrvXkbLatchModifiers
-#define XkbLatchGroup SrvXkbLatchGroup
-#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
-#define XkbChangeKeycodeRange SrvXkbChangeKeycodeRange
-#define XkbApplyVirtualModChanges SrvXkbApplyVirtualModChanges
-#endif
-
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-static Status
-_XkbReadKeyTypes(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
-{
-int i,n,lastMapCount;
-XkbKeyTypePtr type;
-
- if ( rep->nTypes>0 ) {
- n = rep->firstType+rep->nTypes;
- if (xkb->map->num_types>=n)
- n= xkb->map->num_types;
- else if (XkbAllocClientMap(xkb,XkbKeyTypesMask,n)!=Success)
- return BadAlloc;
-
- type = &xkb->map->types[rep->firstType];
- for (i=0;i<(int)rep->nTypes;i++,type++) {
- xkbKeyTypeWireDesc *desc;
- register int ndx;
-
- ndx= i+rep->firstType;
- if (ndx>=xkb->map->num_types)
- xkb->map->num_types= ndx+1;
-
- desc= (xkbKeyTypeWireDesc *)_XkbGetReadBufferPtr(buf,
- SIZEOF(xkbKeyTypeWireDesc));
- if (desc==NULL)
- return BadLength;
-
- lastMapCount= type->map_count;
- if ( desc->nMapEntries>0 ) {
- if ((type->map==NULL)||(desc->nMapEntries>type->map_count)) {
- XkbKTMapEntryRec *prev_map = type->map;
-
- type->map= _XkbTypedRealloc(type->map,desc->nMapEntries,
- XkbKTMapEntryRec);
- if (type->map==NULL) {
- _XkbFree(prev_map);
- return BadAlloc;
- }
- }
- }
- else if (type->map!=NULL) {
- Xfree(type->map);
- type->map_count= 0;
- type->map= NULL;
- }
-
- if ( desc->preserve && (desc->nMapEntries>0) ) {
- if ((!type->preserve)||
- (desc->nMapEntries>lastMapCount)) {
- XkbModsRec *prev_preserve = type->preserve;
-
- type->preserve= _XkbTypedRealloc(type->preserve,
- desc->nMapEntries,
- XkbModsRec);
- if (type->preserve==NULL) {
- _XkbFree(prev_preserve);
- return BadAlloc;
- }
- }
- }
- else if (type->preserve!=NULL) {
- Xfree(type->preserve);
- type->preserve= NULL;
- }
-
- type->mods.mask = desc->mask;
- type->mods.real_mods = desc->realMods;
- type->mods.vmods = desc->virtualMods;
- type->num_levels = desc->numLevels;
- type->map_count = desc->nMapEntries;
- if (desc->nMapEntries>0) {
- register xkbKTMapEntryWireDesc *wire;
- register XkbKTMapEntryPtr entry;
- register int size;
-
- size= type->map_count*SIZEOF(xkbKTMapEntryWireDesc);
- wire= (xkbKTMapEntryWireDesc *)_XkbGetReadBufferPtr(buf,size);
- if (wire==NULL)
- return BadLength;
- entry= type->map;
- for (n=0;n<type->map_count;n++,wire++,entry++) {
- entry->active= wire->active;
- entry->level= wire->level;
- entry->mods.mask= wire->mask;
- entry->mods.real_mods= wire->realMods;
- entry->mods.vmods= wire->virtualMods;
- }
-
- if (desc->preserve) {
- register xkbModsWireDesc * pwire;
- register XkbModsPtr preserve;
- register int sz;
-
- sz= desc->nMapEntries*SIZEOF(xkbModsWireDesc);
- pwire=(xkbModsWireDesc *)_XkbGetReadBufferPtr(buf,sz);
- if (pwire==NULL)
- return BadLength;
- preserve= type->preserve;
- for (n=0;n<desc->nMapEntries;n++,pwire++,preserve++) {
- preserve->mask= pwire->mask;
- preserve->vmods= pwire->virtualMods;
- preserve->real_mods= pwire->realMods;
- }
- }
- }
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadKeySyms(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
-{
-register int i;
-XkbClientMapPtr map;
-
- map= xkb->map;
- if (map->key_sym_map==NULL) {
- register int offset;
- XkbSymMapPtr oldMap;
- xkbSymMapWireDesc *newMap;
- map->key_sym_map= _XkbTypedCalloc((xkb->max_key_code+1),XkbSymMapRec);
- if (map->key_sym_map==NULL)
- return BadAlloc;
- if (map->syms==NULL) {
- int sz;
- sz= (rep->totalSyms*12)/10;
- sz= ((sz+(unsigned)128)/128)*128;
- map->syms = _XkbTypedCalloc(sz,KeySym);
- if (map->syms==NULL)
- return BadAlloc;
- map->size_syms = sz;
- }
- offset = 1;
- oldMap = &map->key_sym_map[rep->firstKeySym];
- for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) {
- newMap= (xkbSymMapWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc));
- if (newMap==NULL)
- return BadLength;
- oldMap->kt_index[0]= newMap->ktIndex[0];
- oldMap->kt_index[1]= newMap->ktIndex[1];
- oldMap->kt_index[2]= newMap->ktIndex[2];
- oldMap->kt_index[3]= newMap->ktIndex[3];
- oldMap->group_info= newMap->groupInfo;
- oldMap->width= newMap->width;
- oldMap->offset= offset;
- if (offset+newMap->nSyms>=map->size_syms) {
- register int sz;
- KeySym *prev_syms = map->syms;
-
- sz= map->size_syms+128;
- map->syms= _XkbTypedRealloc(map->syms,sz,KeySym);
- if (map->syms==NULL) {
- _XkbFree(prev_syms);
- map->size_syms= 0;
- return BadAlloc;
- }
- map->size_syms= sz;
- }
- if (newMap->nSyms>0) {
- _XkbReadBufferCopyKeySyms(buf,(KeySym *)&map->syms[offset],
- newMap->nSyms);
- offset+= newMap->nSyms;
- }
- else {
- map->syms[offset]= 0;
- }
- }
- map->num_syms= offset;
- }
- else {
- xkbSymMapWireDesc * newMap;
- XkbSymMapPtr oldMap;
- KeySym * newSyms;
- int tmp;
-
- oldMap = &map->key_sym_map[rep->firstKeySym];
- for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) {
- newMap= (xkbSymMapWireDesc *)
- _XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc));
- if (newMap==NULL)
- return BadLength;
-
- if (newMap->nSyms>0)
- tmp= newMap->nSyms;
- else tmp= 0;
-
- newSyms = XkbResizeKeySyms(xkb,i+rep->firstKeySym,tmp);
- if (newSyms==NULL)
- return BadAlloc;
- if (newMap->nSyms>0)
- _XkbReadBufferCopyKeySyms(buf,newSyms,newMap->nSyms);
- else newSyms[0]= NoSymbol;
- oldMap->kt_index[0] = newMap->ktIndex[0];
- oldMap->kt_index[1] = newMap->ktIndex[1];
- oldMap->kt_index[2] = newMap->ktIndex[2];
- oldMap->kt_index[3] = newMap->ktIndex[3];
- oldMap->group_info = newMap->groupInfo;
- oldMap->width = newMap->width;
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadKeyActions(XkbReadBufferPtr buf,XkbDescPtr info,xkbGetMapReply *rep)
-{
-int i;
-CARD8 numDescBuf[248];
-CARD8* numDesc = NULL;
-register int nKeyActs;
-Status ret = Success;
-
- if ( (nKeyActs=rep->nKeyActs)>0 ) {
- XkbSymMapPtr symMap;
-
- if (nKeyActs < sizeof numDescBuf) numDesc = numDescBuf;
- else numDesc = Xmalloc (nKeyActs * sizeof(CARD8));
-
- if (!_XkbCopyFromReadBuffer(buf, (char *)numDesc, nKeyActs)) {
- ret = BadLength;
- goto done;
- }
- i= XkbPaddedSize(nKeyActs)-nKeyActs;
- if ((i>0)&&(!_XkbSkipReadBufferData(buf,i))) {
- ret = BadLength;
- goto done;
- }
- symMap = &info->map->key_sym_map[rep->firstKeyAct];
- for (i=0;i<(int)rep->nKeyActs;i++,symMap++) {
- if (numDesc[i]==0) {
- info->server->key_acts[i+rep->firstKeyAct]= 0;
- }
- else {
- XkbAction *newActs;
- /* 8/16/93 (ef) -- XXX! Verify size here (numdesc must be */
- /* either zero or XkbKeyNumSyms(info,key) */
- newActs=XkbResizeKeyActions(info,i+rep->firstKeyAct,
- numDesc[i]);
- if (newActs==NULL) {
- ret = BadAlloc;
- goto done;
- }
- if (!_XkbCopyFromReadBuffer(buf,(char *)newActs,
- (int)(numDesc[i]*sizeof(XkbAction)))) {
- ret = BadLength;
- goto done;
- }
- }
- }
- }
-done:
- if (numDesc != NULL && numDesc != numDescBuf) Xfree (numDesc);
- return ret;
-}
-
-static Status
-_XkbReadKeyBehaviors(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
-{
-register int i;
-xkbBehaviorWireDesc *wire;
-
- if ( rep->totalKeyBehaviors>0 ) {
- if ( xkb->server->behaviors == NULL ) {
- int size = xkb->max_key_code+1;
- xkb->server->behaviors = _XkbTypedCalloc(size,XkbBehavior);
- if (xkb->server->behaviors==NULL)
- return BadAlloc;
- }
- else {
- bzero(&xkb->server->behaviors[rep->firstKeyBehavior],
- (rep->nKeyBehaviors*sizeof(XkbBehavior)));
- }
- for (i=0;i<rep->totalKeyBehaviors;i++) {
- wire= (xkbBehaviorWireDesc *)_XkbGetReadBufferPtr(buf,
- SIZEOF(xkbBehaviorWireDesc));
- if (wire==NULL)
- return BadLength;
- xkb->server->behaviors[wire->key].type= wire->type;
- xkb->server->behaviors[wire->key].data= wire->data;
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadVirtualMods(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
-{
- if ( rep->virtualMods ) {
- register int i,bit,nVMods;
- register char *data;
-
- for (i=nVMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
- if (rep->virtualMods&bit)
- nVMods++;
- }
- data= _XkbGetReadBufferPtr(buf,XkbPaddedSize(nVMods));
- if (data==NULL)
- return BadLength;
- for (i=0,bit=1;(i<XkbNumVirtualMods)&&(nVMods>0);i++,bit<<=1) {
- if (rep->virtualMods&bit) {
- xkb->server->vmods[i]= *data++;
- nVMods--;
- }
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadExplicitComponents( XkbReadBufferPtr buf,
- XkbDescPtr xkb,
- xkbGetMapReply * rep)
-{
-register int i;
-unsigned char *wire;
-
- if ( rep->totalKeyExplicit>0 ) {
- if ( xkb->server->explicit == NULL ) {
- int size = xkb->max_key_code+1;
- xkb->server->explicit = _XkbTypedCalloc(size,unsigned char);
- if (xkb->server->explicit==NULL)
- return BadAlloc;
- }
- else {
- bzero(&xkb->server->explicit[rep->firstKeyExplicit],
- rep->nKeyExplicit);
- }
- i= XkbPaddedSize(2*rep->totalKeyExplicit);
- wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i);
- if (!wire)
- return BadLength;
- for (i=0;i<rep->totalKeyExplicit;i++,wire+=2) {
- xkb->server->explicit[wire[0]]= wire[1];
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadModifierMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
-{
-register int i;
-unsigned char *wire;
-
- if ( rep->totalModMapKeys>0 ) {
- if ((xkb->map->modmap==NULL)&&
- (XkbAllocClientMap(xkb,XkbModifierMapMask,0)!=Success)) {
- return BadAlloc;
- }
- else {
- bzero(&xkb->map->modmap[rep->firstModMapKey],rep->nModMapKeys);
- }
- i= XkbPaddedSize(2*rep->totalModMapKeys);
- wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i);
- if (!wire)
- return BadLength;
- for (i=0;i<rep->totalModMapKeys;i++,wire+=2) {
- xkb->map->modmap[wire[0]]= wire[1];
- }
- }
- return Success;
-}
-
-static Status
-_XkbReadVirtualModMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
-{
-register int i;
-xkbVModMapWireDesc * wire;
-XkbServerMapPtr srv;
-
- if ( rep->totalVModMapKeys>0 ) {
- if (((xkb->server==NULL)||(xkb->server->vmodmap==NULL))&&
- (XkbAllocServerMap(xkb,XkbVirtualModMapMask,0)!=Success)) {
- return BadAlloc;
- }
- else {
- srv= xkb->server;
- if (rep->nVModMapKeys > rep->firstVModMapKey)
- bzero((char *)&srv->vmodmap[rep->firstVModMapKey],
- (rep->nVModMapKeys - rep->firstVModMapKey) *
- sizeof(unsigned short));
- }
- srv= xkb->server;
- i= rep->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc);
- wire=(xkbVModMapWireDesc *)_XkbGetReadBufferPtr(buf,i);
- if (!wire)
- return BadLength;
- for (i=0;i<rep->totalVModMapKeys;i++,wire++) {
- if ((wire->key>=xkb->min_key_code)&&(wire->key<=xkb->max_key_code))
- srv->vmodmap[wire->key]= wire->vmods;
- }
- }
- return Success;
-}
-
-static xkbGetMapReq *
-_XkbGetGetMapReq(Display *dpy,XkbDescPtr xkb)
-{
-xkbGetMapReq *req;
-
- GetReq(kbGetMap, req);
- req->reqType = dpy->xkb_info->codes->major_opcode;
- req->xkbReqType = X_kbGetMap;
- req->deviceSpec = xkb->device_spec;
- req->full = req->partial = 0;
- req->firstType = req->nTypes = 0;
- req->firstKeySym = req->nKeySyms = 0;
- req->firstKeyAct = req->nKeyActs = 0;
- req->firstKeyBehavior = req->nKeyBehaviors = 0;
- req->virtualMods = 0;
- req->firstKeyExplicit = req->nKeyExplicit = 0;
- req->firstModMapKey = req->nModMapKeys = 0;
- req->firstVModMapKey = req->nVModMapKeys = 0;
- return req;
-}
-
-Status
-_XkbReadGetMapReply( Display * dpy,
- xkbGetMapReply *rep,
- XkbDescPtr xkb,
- int * nread_rtrn)
-{
-int extraData;
-unsigned mask;
-
- if ( xkb->device_spec == XkbUseCoreKbd )
- xkb->device_spec= rep->deviceID;
- xkb->min_key_code = rep->minKeyCode;
- xkb->max_key_code = rep->maxKeyCode;
-
- if (!xkb->map) {
- mask= rep->present&XkbAllClientInfoMask;
- if (mask&&(XkbAllocClientMap(xkb,mask,rep->nTypes)!=Success))
- return BadAlloc;
- }
- if (!xkb->server) {
- mask= rep->present&XkbAllServerInfoMask;
- if (mask&&(XkbAllocServerMap(xkb,mask,rep->totalActs)!=Success))
- return BadAlloc;
- }
- extraData= (int)(rep->length*4);
- extraData-= (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply));
- if (rep->length) {
- XkbReadBufferRec buf;
- int left;
- if (_XkbInitReadBuffer(dpy,&buf,extraData)) {
- Status status= Success;
- if (nread_rtrn!=NULL)
- *nread_rtrn= extraData;
- if (status==Success)
- status= _XkbReadKeyTypes(&buf,xkb,rep);
- if (status==Success)
- status= _XkbReadKeySyms(&buf,xkb,rep);
- if (status==Success)
- status= _XkbReadKeyActions(&buf,xkb,rep);
- if (status==Success)
- status= _XkbReadKeyBehaviors(&buf,xkb,rep);
- if (status==Success)
- status= _XkbReadVirtualMods(&buf,xkb,rep);
- if (status==Success)
- status= _XkbReadExplicitComponents(&buf,xkb,rep);
- if (status==Success)
- status= _XkbReadModifierMap(&buf,xkb,rep);
- if (status==Success)
- status= _XkbReadVirtualModMap(&buf,xkb,rep);
- left= _XkbFreeReadBuffer(&buf);
- if (status!=Success) return status;
- else if ( left || buf.error ) return BadLength;
- }
- else return BadAlloc;
- }
- return Success;
-}
-
-static Status
-_XkbHandleGetMapReply(Display *dpy,XkbDescPtr xkb)
-{
-xkbGetMapReply rep;
-
- if (!_XReply(dpy, (xReply *)&rep,
- ( (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply)) >> 2 ),
- xFalse)) {
- return BadImplementation;
- }
- return _XkbReadGetMapReply(dpy,&rep,xkb,NULL);
-}
-
-Status
-XkbGetUpdatedMap(Display *dpy,unsigned which,XkbDescPtr xkb)
-{
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
- if (which) {
- register xkbGetMapReq *req;
- Status status;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->full = which;
- status= _XkbHandleGetMapReply(dpy, xkb);
-
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
- }
- return Success;
-}
-
-XkbDescPtr
-XkbGetMap(Display *dpy,unsigned which,unsigned deviceSpec)
-{
-XkbDescPtr xkb;
-
- xkb = _XkbTypedCalloc(1,XkbDescRec);
- if (xkb) {
- xkb->device_spec = deviceSpec;
- xkb->map = _XkbTypedCalloc(1,XkbClientMapRec);
- if ((xkb->map==NULL)||
- ((which)&&(XkbGetUpdatedMap(dpy,which,xkb)!=Success))) {
- if (xkb->map) {
- Xfree(xkb->map);
- xkb->map= NULL;
- }
- Xfree(xkb);
- return NULL;
- }
- xkb->dpy= dpy;
- }
- return xkb;
-}
-
-Status
-XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
-{
- register xkbGetMapReq *req;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
- if ((num<1)||(num>XkbMaxKeyTypes))
- return BadValue;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->firstType = first;
- req->nTypes = num;
- status= _XkbHandleGetMapReply(dpy, xkb);
-
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
-{
- register xkbGetMapReq *req;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- if ((num<1)||(num>XkbMaxKeyCount))
- return BadValue;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->firstKeyAct = first;
- req->nKeyActs = num;
- status= _XkbHandleGetMapReply(dpy, xkb);
-
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
-{
- register xkbGetMapReq *req;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- if ((num<1)||(num>XkbMaxKeyCount))
- return BadValue;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->firstKeySym = first;
- req->nKeySyms = num;
- status= _XkbHandleGetMapReply(dpy, xkb);
-
- UnlockDisplay(dpy);
- SyncHandle();
-
- return status;
-}
-
-Status
-XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
-{
- register xkbGetMapReq *req;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- if ((num<1)||(num>XkbMaxKeyCount))
- return BadValue;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->firstKeyBehavior = first;
- req->nKeyBehaviors = num;
- status= _XkbHandleGetMapReply(dpy, xkb);
-
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb)
-{
- register xkbGetMapReq *req;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->virtualMods = which;
- status= _XkbHandleGetMapReply(dpy, xkb);
-
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetKeyExplicitComponents( Display * dpy,
- unsigned first,
- unsigned num,
- XkbDescPtr xkb)
-{
- register xkbGetMapReq *req;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- if ((num<1)||(num>XkbMaxKeyCount))
- return BadValue;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->firstKeyExplicit = first;
- req->nKeyExplicit = num;
- if ((xkb!=NULL) && (xkb->server!=NULL) && (xkb->server->explicit!=NULL)) {
- if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
- bzero(&xkb->server->explicit[first],num);
- }
- if (xkb)
- status= _XkbHandleGetMapReply(dpy, xkb);
- else
- status = BadMatch;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
-{
- register xkbGetMapReq *req;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- if ((num<1)||(num>XkbMaxKeyCount))
- return BadValue;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->firstModMapKey = first;
- req->nModMapKeys = num;
- if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) {
- if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
- bzero(&xkb->map->modmap[first],num);
- }
- if (xkb)
- status= _XkbHandleGetMapReply(dpy, xkb);
- else
- status = BadMatch;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
-{
- register xkbGetMapReq *req;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- if ((num<1)||(num>XkbMaxKeyCount))
- return BadValue;
-
- LockDisplay(dpy);
-
- req = _XkbGetGetMapReq(dpy, xkb);
- req->firstVModMapKey = first;
- req->nVModMapKeys = num;
- if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) {
- if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
- bzero(&xkb->server->vmodmap[first],num*sizeof(unsigned short));
- }
-
- if (xkb)
- status= _XkbHandleGetMapReply(dpy, xkb);
- else
- status = BadMatch;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Status
-XkbGetMapChanges(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes)
-{
- xkbGetMapReq *req;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
- LockDisplay(dpy);
- if (changes->changed) {
- Status status= Success;
- req = _XkbGetGetMapReq(dpy, xkb);
- req->full = 0;
- req->partial = changes->changed;
- req->firstType = changes->first_type;
- req->nTypes = changes->num_types;
- req->firstKeySym = changes->first_key_sym;
- req->nKeySyms = changes->num_key_syms;
- req->firstKeyAct = changes->first_key_act;
- req->nKeyActs = changes->num_key_acts;
- req->firstKeyBehavior = changes->first_key_behavior;
- req->nKeyBehaviors = changes->num_key_behaviors;
- req->virtualMods = changes->vmods;
- req->firstKeyExplicit = changes->first_key_explicit;
- req->nKeyExplicit = changes->num_key_explicit;
- req->firstModMapKey = changes->first_modmap_key;
- req->nModMapKeys = changes->num_modmap_keys;
- req->firstVModMapKey = changes->first_vmodmap_key;
- req->nVModMapKeys = changes->num_vmodmap_keys;
- status= _XkbHandleGetMapReply(dpy, xkb);
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
- }
- UnlockDisplay(dpy);
- return Success;
-}
-
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_MAP_READERS
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef XKB_IN_SERVER
+#define XkbAllocClientMap SrvXkbAllocClientMap
+#define XkbAllocServerMap SrvXkbAllocServerMap
+#define XkbChangeTypesOfKey SrvXkbChangeTypesOfKey
+#define XkbCopyKeyTypes SrvXkbCopyKeyTypes
+#define XkbFreeClientMap SrvXkbFreeClientMap
+#define XkbFreeServerMap SrvXkbFreeServerMap
+#define XkbKeyTypesForCoreSymbols SrvXkbKeyTypesForCoreSymbols
+#define XkbApplyCompatMapToKey SrvXkbApplyCompatMapToKey
+#define XkbResizeKeyActions SrvXkbResizeKeyActions
+#define XkbResizeKeySyms SrvXkbResizeKeySyms
+#define XkbResizeKeyType SrvXkbResizeKeyType
+#define XkbAllocCompatMap SrvXkbAllocCompatMap
+#define XkbAllocControls SrvXkbAllocControls
+#define XkbAllocIndicatorMaps SrvXkbAllocIndicatorMaps
+#define XkbAllocKeyboard SrvXkbAllocKeyboard
+#define XkbAllocNames SrvXkbAllocNames
+#define XkbFreeCompatMap SrvXkbFreeCompatMap
+#define XkbFreeKeyboard SrvXkbFreeKeyboard
+#define XkbFreeNames SrvXkbFreeNames
+#define XkbLatchModifiers SrvXkbLatchModifiers
+#define XkbLatchGroup SrvXkbLatchGroup
+#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
+#define XkbChangeKeycodeRange SrvXkbChangeKeycodeRange
+#define XkbApplyVirtualModChanges SrvXkbApplyVirtualModChanges
+#endif
+
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+static Status
+_XkbReadKeyTypes(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
+{
+int i,n,lastMapCount;
+XkbKeyTypePtr type;
+
+ if ( rep->nTypes>0 ) {
+ n = rep->firstType+rep->nTypes;
+ if (xkb->map->num_types>=n)
+ n= xkb->map->num_types;
+ else if (XkbAllocClientMap(xkb,XkbKeyTypesMask,n)!=Success)
+ return BadAlloc;
+
+ type = &xkb->map->types[rep->firstType];
+ for (i=0;i<(int)rep->nTypes;i++,type++) {
+ xkbKeyTypeWireDesc *desc;
+ register int ndx;
+
+ ndx= i+rep->firstType;
+ if (ndx>=xkb->map->num_types)
+ xkb->map->num_types= ndx+1;
+
+ desc= (xkbKeyTypeWireDesc *)_XkbGetReadBufferPtr(buf,
+ SIZEOF(xkbKeyTypeWireDesc));
+ if (desc==NULL)
+ return BadLength;
+
+ lastMapCount= type->map_count;
+ if ( desc->nMapEntries>0 ) {
+ if ((type->map==NULL)||(desc->nMapEntries>type->map_count)) {
+ XkbKTMapEntryRec *prev_map = type->map;
+
+ type->map= _XkbTypedRealloc(type->map,desc->nMapEntries,
+ XkbKTMapEntryRec);
+ if (type->map==NULL) {
+ _XkbFree(prev_map);
+ return BadAlloc;
+ }
+ }
+ }
+ else if (type->map!=NULL) {
+ Xfree(type->map);
+ type->map_count= 0;
+ type->map= NULL;
+ }
+
+ if ( desc->preserve && (desc->nMapEntries>0) ) {
+ if ((!type->preserve)||
+ (desc->nMapEntries>lastMapCount)) {
+ XkbModsRec *prev_preserve = type->preserve;
+
+ type->preserve= _XkbTypedRealloc(type->preserve,
+ desc->nMapEntries,
+ XkbModsRec);
+ if (type->preserve==NULL) {
+ _XkbFree(prev_preserve);
+ return BadAlloc;
+ }
+ }
+ }
+ else if (type->preserve!=NULL) {
+ Xfree(type->preserve);
+ type->preserve= NULL;
+ }
+
+ type->mods.mask = desc->mask;
+ type->mods.real_mods = desc->realMods;
+ type->mods.vmods = desc->virtualMods;
+ type->num_levels = desc->numLevels;
+ type->map_count = desc->nMapEntries;
+ if (desc->nMapEntries>0) {
+ register xkbKTMapEntryWireDesc *wire;
+ register XkbKTMapEntryPtr entry;
+ register int size;
+
+ size= type->map_count*SIZEOF(xkbKTMapEntryWireDesc);
+ wire= (xkbKTMapEntryWireDesc *)_XkbGetReadBufferPtr(buf,size);
+ if (wire==NULL)
+ return BadLength;
+ entry= type->map;
+ for (n=0;n<type->map_count;n++,wire++,entry++) {
+ entry->active= wire->active;
+ entry->level= wire->level;
+ entry->mods.mask= wire->mask;
+ entry->mods.real_mods= wire->realMods;
+ entry->mods.vmods= wire->virtualMods;
+ }
+
+ if (desc->preserve) {
+ register xkbModsWireDesc * pwire;
+ register XkbModsPtr preserve;
+ register int sz;
+
+ sz= desc->nMapEntries*SIZEOF(xkbModsWireDesc);
+ pwire=(xkbModsWireDesc *)_XkbGetReadBufferPtr(buf,sz);
+ if (pwire==NULL)
+ return BadLength;
+ preserve= type->preserve;
+ for (n=0;n<desc->nMapEntries;n++,pwire++,preserve++) {
+ preserve->mask= pwire->mask;
+ preserve->vmods= pwire->virtualMods;
+ preserve->real_mods= pwire->realMods;
+ }
+ }
+ }
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadKeySyms(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
+{
+register int i;
+XkbClientMapPtr map;
+
+ map= xkb->map;
+ if (map->key_sym_map==NULL) {
+ register int offset;
+ XkbSymMapPtr oldMap;
+ xkbSymMapWireDesc *newMap;
+ map->key_sym_map= _XkbTypedCalloc((xkb->max_key_code+1),XkbSymMapRec);
+ if (map->key_sym_map==NULL)
+ return BadAlloc;
+ if (map->syms==NULL) {
+ int sz;
+ sz= (rep->totalSyms*12)/10;
+ sz= ((sz+(unsigned)128)/128)*128;
+ map->syms = _XkbTypedCalloc(sz,KeySym);
+ if (map->syms==NULL)
+ return BadAlloc;
+ map->size_syms = sz;
+ }
+ offset = 1;
+ oldMap = &map->key_sym_map[rep->firstKeySym];
+ for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) {
+ newMap= (xkbSymMapWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc));
+ if (newMap==NULL)
+ return BadLength;
+ oldMap->kt_index[0]= newMap->ktIndex[0];
+ oldMap->kt_index[1]= newMap->ktIndex[1];
+ oldMap->kt_index[2]= newMap->ktIndex[2];
+ oldMap->kt_index[3]= newMap->ktIndex[3];
+ oldMap->group_info= newMap->groupInfo;
+ oldMap->width= newMap->width;
+ oldMap->offset= offset;
+ if (offset+newMap->nSyms>=map->size_syms) {
+ register int sz;
+ KeySym *prev_syms = map->syms;
+
+ sz= map->size_syms+128;
+ map->syms= _XkbTypedRealloc(map->syms,sz,KeySym);
+ if (map->syms==NULL) {
+ _XkbFree(prev_syms);
+ map->size_syms= 0;
+ return BadAlloc;
+ }
+ map->size_syms= sz;
+ }
+ if (newMap->nSyms>0) {
+ _XkbReadBufferCopyKeySyms(buf,(KeySym *)&map->syms[offset],
+ newMap->nSyms);
+ offset+= newMap->nSyms;
+ }
+ else {
+ map->syms[offset]= 0;
+ }
+ }
+ map->num_syms= offset;
+ }
+ else {
+ xkbSymMapWireDesc * newMap;
+ XkbSymMapPtr oldMap;
+ KeySym * newSyms;
+ int tmp;
+
+ oldMap = &map->key_sym_map[rep->firstKeySym];
+ for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) {
+ newMap= (xkbSymMapWireDesc *)
+ _XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc));
+ if (newMap==NULL)
+ return BadLength;
+
+ if (newMap->nSyms>0)
+ tmp= newMap->nSyms;
+ else tmp= 0;
+
+ newSyms = XkbResizeKeySyms(xkb,i+rep->firstKeySym,tmp);
+ if (newSyms==NULL)
+ return BadAlloc;
+ if (newMap->nSyms>0)
+ _XkbReadBufferCopyKeySyms(buf,newSyms,newMap->nSyms);
+ else newSyms[0]= NoSymbol;
+ oldMap->kt_index[0] = newMap->ktIndex[0];
+ oldMap->kt_index[1] = newMap->ktIndex[1];
+ oldMap->kt_index[2] = newMap->ktIndex[2];
+ oldMap->kt_index[3] = newMap->ktIndex[3];
+ oldMap->group_info = newMap->groupInfo;
+ oldMap->width = newMap->width;
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadKeyActions(XkbReadBufferPtr buf,XkbDescPtr info,xkbGetMapReply *rep)
+{
+int i;
+CARD8 numDescBuf[248];
+CARD8* numDesc = NULL;
+register int nKeyActs;
+Status ret = Success;
+
+ if ( (nKeyActs=rep->nKeyActs)>0 ) {
+ XkbSymMapPtr symMap;
+
+ if (nKeyActs < sizeof numDescBuf) numDesc = numDescBuf;
+ else numDesc = Xmalloc (nKeyActs * sizeof(CARD8));
+
+ if (!_XkbCopyFromReadBuffer(buf, (char *)numDesc, nKeyActs)) {
+ ret = BadLength;
+ goto done;
+ }
+ i= XkbPaddedSize(nKeyActs)-nKeyActs;
+ if ((i>0)&&(!_XkbSkipReadBufferData(buf,i))) {
+ ret = BadLength;
+ goto done;
+ }
+ symMap = &info->map->key_sym_map[rep->firstKeyAct];
+ for (i=0;i<(int)rep->nKeyActs;i++,symMap++) {
+ if (numDesc[i]==0) {
+ info->server->key_acts[i+rep->firstKeyAct]= 0;
+ }
+ else {
+ XkbAction *newActs;
+ /* 8/16/93 (ef) -- XXX! Verify size here (numdesc must be */
+ /* either zero or XkbKeyNumSyms(info,key) */
+ newActs=XkbResizeKeyActions(info,i+rep->firstKeyAct,
+ numDesc[i]);
+ if (newActs==NULL) {
+ ret = BadAlloc;
+ goto done;
+ }
+ if (!_XkbCopyFromReadBuffer(buf,(char *)newActs,
+ (int)(numDesc[i]*sizeof(XkbAction)))) {
+ ret = BadLength;
+ goto done;
+ }
+ }
+ }
+ }
+done:
+ if (numDesc != NULL && numDesc != numDescBuf) Xfree (numDesc);
+ return ret;
+}
+
+static Status
+_XkbReadKeyBehaviors(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
+{
+register int i;
+xkbBehaviorWireDesc *wire;
+
+ if ( rep->totalKeyBehaviors>0 ) {
+ if ( xkb->server->behaviors == NULL ) {
+ int size = xkb->max_key_code+1;
+ xkb->server->behaviors = _XkbTypedCalloc(size,XkbBehavior);
+ if (xkb->server->behaviors==NULL)
+ return BadAlloc;
+ }
+ else {
+ bzero(&xkb->server->behaviors[rep->firstKeyBehavior],
+ (rep->nKeyBehaviors*sizeof(XkbBehavior)));
+ }
+ for (i=0;i<rep->totalKeyBehaviors;i++) {
+ wire= (xkbBehaviorWireDesc *)_XkbGetReadBufferPtr(buf,
+ SIZEOF(xkbBehaviorWireDesc));
+ if (wire==NULL)
+ return BadLength;
+ xkb->server->behaviors[wire->key].type= wire->type;
+ xkb->server->behaviors[wire->key].data= wire->data;
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadVirtualMods(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
+{
+ if ( rep->virtualMods ) {
+ register int i,bit,nVMods;
+ register char *data;
+
+ for (i=nVMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
+ if (rep->virtualMods&bit)
+ nVMods++;
+ }
+ data= _XkbGetReadBufferPtr(buf,XkbPaddedSize(nVMods));
+ if (data==NULL)
+ return BadLength;
+ for (i=0,bit=1;(i<XkbNumVirtualMods)&&(nVMods>0);i++,bit<<=1) {
+ if (rep->virtualMods&bit) {
+ xkb->server->vmods[i]= *data++;
+ nVMods--;
+ }
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadExplicitComponents( XkbReadBufferPtr buf,
+ XkbDescPtr xkb,
+ xkbGetMapReply * rep)
+{
+register int i;
+unsigned char *wire;
+
+ if ( rep->totalKeyExplicit>0 ) {
+ if ( xkb->server->explicit == NULL ) {
+ int size = xkb->max_key_code+1;
+ xkb->server->explicit = _XkbTypedCalloc(size,unsigned char);
+ if (xkb->server->explicit==NULL)
+ return BadAlloc;
+ }
+ else {
+ bzero(&xkb->server->explicit[rep->firstKeyExplicit],
+ rep->nKeyExplicit);
+ }
+ i= XkbPaddedSize(2*rep->totalKeyExplicit);
+ wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i);
+ if (!wire)
+ return BadLength;
+ for (i=0;i<rep->totalKeyExplicit;i++,wire+=2) {
+ xkb->server->explicit[wire[0]]= wire[1];
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadModifierMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
+{
+register int i;
+unsigned char *wire;
+
+ if ( rep->totalModMapKeys>0 ) {
+ if ((xkb->map->modmap==NULL)&&
+ (XkbAllocClientMap(xkb,XkbModifierMapMask,0)!=Success)) {
+ return BadAlloc;
+ }
+ else {
+ bzero(&xkb->map->modmap[rep->firstModMapKey],rep->nModMapKeys);
+ }
+ i= XkbPaddedSize(2*rep->totalModMapKeys);
+ wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i);
+ if (!wire)
+ return BadLength;
+ for (i=0;i<rep->totalModMapKeys;i++,wire+=2) {
+ xkb->map->modmap[wire[0]]= wire[1];
+ }
+ }
+ return Success;
+}
+
+static Status
+_XkbReadVirtualModMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
+{
+register int i;
+xkbVModMapWireDesc * wire;
+XkbServerMapPtr srv;
+
+ if ( rep->totalVModMapKeys>0 ) {
+ if (((xkb->server==NULL)||(xkb->server->vmodmap==NULL))&&
+ (XkbAllocServerMap(xkb,XkbVirtualModMapMask,0)!=Success)) {
+ return BadAlloc;
+ }
+ else {
+ srv= xkb->server;
+ if (rep->nVModMapKeys > rep->firstVModMapKey)
+ bzero((char *)&srv->vmodmap[rep->firstVModMapKey],
+ (rep->nVModMapKeys - rep->firstVModMapKey) *
+ sizeof(unsigned short));
+ }
+ srv= xkb->server;
+ i= rep->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc);
+ wire=(xkbVModMapWireDesc *)_XkbGetReadBufferPtr(buf,i);
+ if (!wire)
+ return BadLength;
+ for (i=0;i<rep->totalVModMapKeys;i++,wire++) {
+ if ((wire->key>=xkb->min_key_code)&&(wire->key<=xkb->max_key_code))
+ srv->vmodmap[wire->key]= wire->vmods;
+ }
+ }
+ return Success;
+}
+
+static xkbGetMapReq *
+_XkbGetGetMapReq(Display *dpy,XkbDescPtr xkb)
+{
+xkbGetMapReq *req;
+
+ GetReq(kbGetMap, req);
+ req->reqType = dpy->xkb_info->codes->major_opcode;
+ req->xkbReqType = X_kbGetMap;
+ req->deviceSpec = xkb->device_spec;
+ req->full = req->partial = 0;
+ req->firstType = req->nTypes = 0;
+ req->firstKeySym = req->nKeySyms = 0;
+ req->firstKeyAct = req->nKeyActs = 0;
+ req->firstKeyBehavior = req->nKeyBehaviors = 0;
+ req->virtualMods = 0;
+ req->firstKeyExplicit = req->nKeyExplicit = 0;
+ req->firstModMapKey = req->nModMapKeys = 0;
+ req->firstVModMapKey = req->nVModMapKeys = 0;
+ return req;
+}
+
+Status
+_XkbReadGetMapReply( Display * dpy,
+ xkbGetMapReply *rep,
+ XkbDescPtr xkb,
+ int * nread_rtrn)
+{
+int extraData;
+unsigned mask;
+
+ if ( xkb->device_spec == XkbUseCoreKbd )
+ xkb->device_spec= rep->deviceID;
+ xkb->min_key_code = rep->minKeyCode;
+ xkb->max_key_code = rep->maxKeyCode;
+
+ if (!xkb->map) {
+ mask= rep->present&XkbAllClientInfoMask;
+ if (mask&&(XkbAllocClientMap(xkb,mask,rep->nTypes)!=Success))
+ return BadAlloc;
+ }
+ if (!xkb->server) {
+ mask= rep->present&XkbAllServerInfoMask;
+ if (mask&&(XkbAllocServerMap(xkb,mask,rep->totalActs)!=Success))
+ return BadAlloc;
+ }
+ extraData= (int)(rep->length*4);
+ extraData-= (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply));
+ if (rep->length) {
+ XkbReadBufferRec buf;
+ int left;
+ if (_XkbInitReadBuffer(dpy,&buf,extraData)) {
+ Status status= Success;
+ if (nread_rtrn!=NULL)
+ *nread_rtrn= extraData;
+ if (status==Success)
+ status= _XkbReadKeyTypes(&buf,xkb,rep);
+ if (status==Success)
+ status= _XkbReadKeySyms(&buf,xkb,rep);
+ if (status==Success)
+ status= _XkbReadKeyActions(&buf,xkb,rep);
+ if (status==Success)
+ status= _XkbReadKeyBehaviors(&buf,xkb,rep);
+ if (status==Success)
+ status= _XkbReadVirtualMods(&buf,xkb,rep);
+ if (status==Success)
+ status= _XkbReadExplicitComponents(&buf,xkb,rep);
+ if (status==Success)
+ status= _XkbReadModifierMap(&buf,xkb,rep);
+ if (status==Success)
+ status= _XkbReadVirtualModMap(&buf,xkb,rep);
+ left= _XkbFreeReadBuffer(&buf);
+ if (status!=Success) return status;
+ else if ( left || buf.error ) return BadLength;
+ }
+ else return BadAlloc;
+ }
+ return Success;
+}
+
+static Status
+_XkbHandleGetMapReply(Display *dpy,XkbDescPtr xkb)
+{
+xkbGetMapReply rep;
+
+ if (!_XReply(dpy, (xReply *)&rep,
+ ( (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply)) >> 2 ),
+ xFalse)) {
+ return BadImplementation;
+ }
+ return _XkbReadGetMapReply(dpy,&rep,xkb,NULL);
+}
+
+Status
+XkbGetUpdatedMap(Display *dpy,unsigned which,XkbDescPtr xkb)
+{
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+ if (which) {
+ register xkbGetMapReq *req;
+ Status status;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->full = which;
+ status= _XkbHandleGetMapReply(dpy, xkb);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+ }
+ return Success;
+}
+
+XkbDescPtr
+XkbGetMap(Display *dpy,unsigned which,unsigned deviceSpec)
+{
+XkbDescPtr xkb;
+
+ xkb = _XkbTypedCalloc(1,XkbDescRec);
+ if (xkb) {
+ xkb->device_spec = deviceSpec;
+ xkb->map = _XkbTypedCalloc(1,XkbClientMapRec);
+ if ((xkb->map==NULL)||
+ ((which)&&(XkbGetUpdatedMap(dpy,which,xkb)!=Success))) {
+ if (xkb->map) {
+ Xfree(xkb->map);
+ xkb->map= NULL;
+ }
+ Xfree(xkb);
+ return NULL;
+ }
+ xkb->dpy= dpy;
+ }
+ return xkb;
+}
+
+Status
+XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
+{
+ register xkbGetMapReq *req;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+ if ((num<1)||(num>XkbMaxKeyTypes))
+ return BadValue;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->firstType = first;
+ req->nTypes = num;
+ status= _XkbHandleGetMapReply(dpy, xkb);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
+{
+ register xkbGetMapReq *req;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ if ((num<1)||(num>XkbMaxKeyCount))
+ return BadValue;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->firstKeyAct = first;
+ req->nKeyActs = num;
+ status= _XkbHandleGetMapReply(dpy, xkb);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
+{
+ register xkbGetMapReq *req;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ if ((num<1)||(num>XkbMaxKeyCount))
+ return BadValue;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->firstKeySym = first;
+ req->nKeySyms = num;
+ status= _XkbHandleGetMapReply(dpy, xkb);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ return status;
+}
+
+Status
+XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
+{
+ register xkbGetMapReq *req;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ if ((num<1)||(num>XkbMaxKeyCount))
+ return BadValue;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->firstKeyBehavior = first;
+ req->nKeyBehaviors = num;
+ status= _XkbHandleGetMapReply(dpy, xkb);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb)
+{
+ register xkbGetMapReq *req;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->virtualMods = which;
+ status= _XkbHandleGetMapReply(dpy, xkb);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetKeyExplicitComponents( Display * dpy,
+ unsigned first,
+ unsigned num,
+ XkbDescPtr xkb)
+{
+ register xkbGetMapReq *req;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ if ((num<1)||(num>XkbMaxKeyCount))
+ return BadValue;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->firstKeyExplicit = first;
+ req->nKeyExplicit = num;
+ if ((xkb!=NULL) && (xkb->server!=NULL) && (xkb->server->explicit!=NULL)) {
+ if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
+ bzero(&xkb->server->explicit[first],num);
+ }
+ if (xkb)
+ status= _XkbHandleGetMapReply(dpy, xkb);
+ else
+ status = BadMatch;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
+{
+ register xkbGetMapReq *req;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ if ((num<1)||(num>XkbMaxKeyCount))
+ return BadValue;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->firstModMapKey = first;
+ req->nModMapKeys = num;
+ if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) {
+ if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
+ bzero(&xkb->map->modmap[first],num);
+ }
+ if (xkb)
+ status= _XkbHandleGetMapReply(dpy, xkb);
+ else
+ status = BadMatch;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
+{
+ register xkbGetMapReq *req;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ if ((num<1)||(num>XkbMaxKeyCount))
+ return BadValue;
+
+ LockDisplay(dpy);
+
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->firstVModMapKey = first;
+ req->nVModMapKeys = num;
+ if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) {
+ if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
+ bzero(&xkb->server->vmodmap[first],num*sizeof(unsigned short));
+ }
+
+ if (xkb)
+ status= _XkbHandleGetMapReply(dpy, xkb);
+ else
+ status = BadMatch;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Status
+XkbGetMapChanges(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes)
+{
+ xkbGetMapReq *req;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+ LockDisplay(dpy);
+ if (changes->changed) {
+ Status status= Success;
+ req = _XkbGetGetMapReq(dpy, xkb);
+ req->full = 0;
+ req->partial = changes->changed;
+ req->firstType = changes->first_type;
+ req->nTypes = changes->num_types;
+ req->firstKeySym = changes->first_key_sym;
+ req->nKeySyms = changes->num_key_syms;
+ req->firstKeyAct = changes->first_key_act;
+ req->nKeyActs = changes->num_key_acts;
+ req->firstKeyBehavior = changes->first_key_behavior;
+ req->nKeyBehaviors = changes->num_key_behaviors;
+ req->virtualMods = changes->vmods;
+ req->firstKeyExplicit = changes->first_key_explicit;
+ req->nKeyExplicit = changes->num_key_explicit;
+ req->firstModMapKey = changes->first_modmap_key;
+ req->nModMapKeys = changes->num_modmap_keys;
+ req->firstVModMapKey = changes->first_vmodmap_key;
+ req->nVModMapKeys = changes->num_vmodmap_keys;
+ status= _XkbHandleGetMapReply(dpy, xkb);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+ }
+ UnlockDisplay(dpy);
+ return Success;
+}
+
diff --git a/libX11/src/xkb/XKBList.c b/libX11/src/xkb/XKBList.c
index f202d935d..1afe3685f 100644
--- a/libX11/src/xkb/XKBList.c
+++ b/libX11/src/xkb/XKBList.c
@@ -1,249 +1,247 @@
-/************************************************************
-Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_REPLIES
-#define NEED_EVENTS
-#define NEED_MAP_READERS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-/***====================================================================***/
-
-static void
-_FreeComponentNames(int num,XkbComponentNamePtr names)
-{
-int i;
-XkbComponentNamePtr tmp;
-
- if ((num<1)||(names==NULL))
- return;
- for (i=0,tmp=names;i<num;i++,tmp++) {
- if (tmp->name) {
- _XkbFree(tmp->name);
- tmp->name= NULL;
- }
- }
- _XkbFree(names);
- return;
-}
-
-/***====================================================================***/
-
-static XkbComponentNamePtr
-_ReadListing(XkbReadBufferPtr buf,int count,Status *status_rtrn)
-{
-XkbComponentNamePtr first,this;
-register int i;
-CARD16 * flags;
-int slen,wlen;
-char * str;
-
- if (count<1)
- return NULL;
- first= _XkbTypedCalloc(count,XkbComponentNameRec);
- if (!first)
- return NULL;
- for (this=first,i=0;i<count;i++,this++) {
- flags= (CARD16 *)_XkbGetReadBufferPtr(buf,2*sizeof(CARD16));
- if (!flags)
- goto BAILOUT;
- this->flags= flags[0];
- slen= flags[1];
- wlen= ((slen+1)/2)*2; /* pad to 2 byte boundary */
- this->name= _XkbTypedCalloc(slen+1,char);
- if (!this->name)
- goto BAILOUT;
- str= (char *)_XkbGetReadBufferPtr(buf,wlen);
- memcpy(this->name,str,slen);
- }
- return first;
-BAILOUT:
- *status_rtrn= BadAlloc;
- _FreeComponentNames(i,first);
- return NULL;
-}
-
-/***====================================================================***/
-
-XkbComponentListPtr
-XkbListComponents( Display * dpy,
- unsigned deviceSpec,
- XkbComponentNamesPtr ptrns,
- int * max_inout)
-{
-register xkbListComponentsReq* req;
-xkbListComponentsReply rep;
-XkbInfoPtr xkbi;
-XkbComponentListPtr list;
-XkbReadBufferRec buf;
-int left;
-char * str;
-int extraLen,len,mapLen,codesLen,typesLen,compatLen,symsLen,geomLen;
-
- if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ||
- (ptrns==NULL) || (max_inout==NULL))
- return NULL;
-
- xkbi= dpy->xkb_info;
- LockDisplay(dpy);
- GetReq(kbListComponents, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbListComponents;
- req->deviceSpec = deviceSpec;
- req->maxNames = *max_inout;
-
- mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
- if (ptrns->keymap)
- mapLen= (int)strlen(ptrns->keymap);
- if (ptrns->keycodes)
- codesLen= (int)strlen(ptrns->keycodes);
- if (ptrns->types)
- typesLen= (int)strlen(ptrns->types);
- if (ptrns->compat)
- compatLen= (int)strlen(ptrns->compat);
- if (ptrns->symbols)
- symsLen= (int)strlen(ptrns->symbols);
- if (ptrns->geometry)
- geomLen= (int)strlen(ptrns->geometry);
- if (mapLen>255) mapLen= 255;
- if (codesLen>255) codesLen= 255;
- if (typesLen>255) typesLen= 255;
- if (compatLen>255) compatLen= 255;
- if (symsLen>255) symsLen= 255;
- if (geomLen>255) geomLen= 255;
-
- len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6;
- len= XkbPaddedSize(len);
- req->length+= len/4;
- BufAlloc(char *,str,len);
- *str++= mapLen;
- if (mapLen>0) {
- memcpy(str,ptrns->keymap,mapLen);
- str+= mapLen;
- }
- *str++= codesLen;
- if (codesLen>0) {
- memcpy(str,ptrns->keycodes,codesLen);
- str+= codesLen;
- }
- *str++= typesLen;
- if (typesLen>0) {
- memcpy(str,ptrns->types,typesLen);
- str+= typesLen;
- }
- *str++= compatLen;
- if (compatLen>0) {
- memcpy(str,ptrns->compat,compatLen);
- str+= compatLen;
- }
- *str++= symsLen;
- if (symsLen>0) {
- memcpy(str,ptrns->symbols,symsLen);
- str+= symsLen;
- }
- *str++= geomLen;
- if (geomLen>0) {
- memcpy(str,ptrns->geometry,geomLen);
- str+= geomLen;
- }
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
- goto BAILOUT;
- extraLen= (int)rep.length*4;
- *max_inout= rep.extra;
- if (extraLen==0) { /* no matches, but we don't want to report a failure */
- list= _XkbTypedCalloc(1,XkbComponentListRec);
- UnlockDisplay(dpy);
- SyncHandle();
- return list;
- }
- if (_XkbInitReadBuffer(dpy,&buf,extraLen)) {
- Status status;
-
- status= Success;
- list= _XkbTypedCalloc(1,XkbComponentListRec);
- if (!list) {
- _XkbFreeReadBuffer(&buf);
- goto BAILOUT;
- }
- list->num_keymaps= rep.nKeymaps;
- list->num_keycodes= rep.nKeycodes;
- list->num_types= rep.nTypes;
- list->num_compat= rep.nCompatMaps;
- list->num_symbols= rep.nSymbols;
- list->num_geometry= rep.nGeometries;
- if ((status==Success)&&(list->num_keymaps>0))
- list->keymaps= _ReadListing(&buf,list->num_keymaps,&status);
- if ((status==Success)&&(list->num_keycodes>0))
- list->keycodes= _ReadListing(&buf,list->num_keycodes,&status);
- if ((status==Success)&&(list->num_types>0))
- list->types= _ReadListing(&buf,list->num_types,&status);
- if ((status==Success)&&(list->num_compat>0))
- list->compat= _ReadListing(&buf,list->num_compat,&status);
- if ((status==Success)&&(list->num_symbols>0))
- list->symbols= _ReadListing(&buf,list->num_symbols,&status);
- if ((status==Success)&&(list->num_geometry>0))
- list->geometry= _ReadListing(&buf,list->num_geometry,&status);
- left= _XkbFreeReadBuffer(&buf);
- if ((status!=Success)||(buf.error)||(left>2)) {
- XkbFreeComponentList(list);
- goto BAILOUT;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return list;
- }
-BAILOUT:
- UnlockDisplay(dpy);
- SyncHandle();
- return NULL;
-}
-
-void
-XkbFreeComponentList(XkbComponentListPtr list)
-{
- if (list) {
- if (list->keymaps)
- _FreeComponentNames(list->num_keymaps,list->keymaps);
- if (list->keycodes)
- _FreeComponentNames(list->num_keycodes,list->keycodes);
- if (list->types)
- _FreeComponentNames(list->num_types,list->types);
- if (list->compat)
- _FreeComponentNames(list->num_compat,list->compat);
- if (list->symbols)
- _FreeComponentNames(list->num_symbols,list->symbols);
- if (list->geometry)
- _FreeComponentNames(list->num_geometry,list->geometry);
- bzero((char *)list,sizeof(XkbComponentListRec));
- _XkbFree(list);
- }
- return;
-}
+/************************************************************
+Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_MAP_READERS
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+/***====================================================================***/
+
+static void
+_FreeComponentNames(int num,XkbComponentNamePtr names)
+{
+int i;
+XkbComponentNamePtr tmp;
+
+ if ((num<1)||(names==NULL))
+ return;
+ for (i=0,tmp=names;i<num;i++,tmp++) {
+ if (tmp->name) {
+ _XkbFree(tmp->name);
+ tmp->name= NULL;
+ }
+ }
+ _XkbFree(names);
+ return;
+}
+
+/***====================================================================***/
+
+static XkbComponentNamePtr
+_ReadListing(XkbReadBufferPtr buf,int count,Status *status_rtrn)
+{
+XkbComponentNamePtr first,this;
+register int i;
+CARD16 * flags;
+int slen,wlen;
+char * str;
+
+ if (count<1)
+ return NULL;
+ first= _XkbTypedCalloc(count,XkbComponentNameRec);
+ if (!first)
+ return NULL;
+ for (this=first,i=0;i<count;i++,this++) {
+ flags= (CARD16 *)_XkbGetReadBufferPtr(buf,2*sizeof(CARD16));
+ if (!flags)
+ goto BAILOUT;
+ this->flags= flags[0];
+ slen= flags[1];
+ wlen= ((slen+1)/2)*2; /* pad to 2 byte boundary */
+ this->name= _XkbTypedCalloc(slen+1,char);
+ if (!this->name)
+ goto BAILOUT;
+ str= (char *)_XkbGetReadBufferPtr(buf,wlen);
+ memcpy(this->name,str,slen);
+ }
+ return first;
+BAILOUT:
+ *status_rtrn= BadAlloc;
+ _FreeComponentNames(i,first);
+ return NULL;
+}
+
+/***====================================================================***/
+
+XkbComponentListPtr
+XkbListComponents( Display * dpy,
+ unsigned deviceSpec,
+ XkbComponentNamesPtr ptrns,
+ int * max_inout)
+{
+register xkbListComponentsReq* req;
+xkbListComponentsReply rep;
+XkbInfoPtr xkbi;
+XkbComponentListPtr list;
+XkbReadBufferRec buf;
+int left;
+char * str;
+int extraLen,len,mapLen,codesLen,typesLen,compatLen,symsLen,geomLen;
+
+ if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ||
+ (ptrns==NULL) || (max_inout==NULL))
+ return NULL;
+
+ xkbi= dpy->xkb_info;
+ LockDisplay(dpy);
+ GetReq(kbListComponents, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbListComponents;
+ req->deviceSpec = deviceSpec;
+ req->maxNames = *max_inout;
+
+ mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
+ if (ptrns->keymap)
+ mapLen= (int)strlen(ptrns->keymap);
+ if (ptrns->keycodes)
+ codesLen= (int)strlen(ptrns->keycodes);
+ if (ptrns->types)
+ typesLen= (int)strlen(ptrns->types);
+ if (ptrns->compat)
+ compatLen= (int)strlen(ptrns->compat);
+ if (ptrns->symbols)
+ symsLen= (int)strlen(ptrns->symbols);
+ if (ptrns->geometry)
+ geomLen= (int)strlen(ptrns->geometry);
+ if (mapLen>255) mapLen= 255;
+ if (codesLen>255) codesLen= 255;
+ if (typesLen>255) typesLen= 255;
+ if (compatLen>255) compatLen= 255;
+ if (symsLen>255) symsLen= 255;
+ if (geomLen>255) geomLen= 255;
+
+ len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6;
+ len= XkbPaddedSize(len);
+ req->length+= len/4;
+ BufAlloc(char *,str,len);
+ *str++= mapLen;
+ if (mapLen>0) {
+ memcpy(str,ptrns->keymap,mapLen);
+ str+= mapLen;
+ }
+ *str++= codesLen;
+ if (codesLen>0) {
+ memcpy(str,ptrns->keycodes,codesLen);
+ str+= codesLen;
+ }
+ *str++= typesLen;
+ if (typesLen>0) {
+ memcpy(str,ptrns->types,typesLen);
+ str+= typesLen;
+ }
+ *str++= compatLen;
+ if (compatLen>0) {
+ memcpy(str,ptrns->compat,compatLen);
+ str+= compatLen;
+ }
+ *str++= symsLen;
+ if (symsLen>0) {
+ memcpy(str,ptrns->symbols,symsLen);
+ str+= symsLen;
+ }
+ *str++= geomLen;
+ if (geomLen>0) {
+ memcpy(str,ptrns->geometry,geomLen);
+ str+= geomLen;
+ }
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
+ goto BAILOUT;
+ extraLen= (int)rep.length*4;
+ *max_inout= rep.extra;
+ if (extraLen==0) { /* no matches, but we don't want to report a failure */
+ list= _XkbTypedCalloc(1,XkbComponentListRec);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return list;
+ }
+ if (_XkbInitReadBuffer(dpy,&buf,extraLen)) {
+ Status status;
+
+ status= Success;
+ list= _XkbTypedCalloc(1,XkbComponentListRec);
+ if (!list) {
+ _XkbFreeReadBuffer(&buf);
+ goto BAILOUT;
+ }
+ list->num_keymaps= rep.nKeymaps;
+ list->num_keycodes= rep.nKeycodes;
+ list->num_types= rep.nTypes;
+ list->num_compat= rep.nCompatMaps;
+ list->num_symbols= rep.nSymbols;
+ list->num_geometry= rep.nGeometries;
+ if ((status==Success)&&(list->num_keymaps>0))
+ list->keymaps= _ReadListing(&buf,list->num_keymaps,&status);
+ if ((status==Success)&&(list->num_keycodes>0))
+ list->keycodes= _ReadListing(&buf,list->num_keycodes,&status);
+ if ((status==Success)&&(list->num_types>0))
+ list->types= _ReadListing(&buf,list->num_types,&status);
+ if ((status==Success)&&(list->num_compat>0))
+ list->compat= _ReadListing(&buf,list->num_compat,&status);
+ if ((status==Success)&&(list->num_symbols>0))
+ list->symbols= _ReadListing(&buf,list->num_symbols,&status);
+ if ((status==Success)&&(list->num_geometry>0))
+ list->geometry= _ReadListing(&buf,list->num_geometry,&status);
+ left= _XkbFreeReadBuffer(&buf);
+ if ((status!=Success)||(buf.error)||(left>2)) {
+ XkbFreeComponentList(list);
+ goto BAILOUT;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return list;
+ }
+BAILOUT:
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return NULL;
+}
+
+void
+XkbFreeComponentList(XkbComponentListPtr list)
+{
+ if (list) {
+ if (list->keymaps)
+ _FreeComponentNames(list->num_keymaps,list->keymaps);
+ if (list->keycodes)
+ _FreeComponentNames(list->num_keycodes,list->keycodes);
+ if (list->types)
+ _FreeComponentNames(list->num_types,list->types);
+ if (list->compat)
+ _FreeComponentNames(list->num_compat,list->compat);
+ if (list->symbols)
+ _FreeComponentNames(list->num_symbols,list->symbols);
+ if (list->geometry)
+ _FreeComponentNames(list->num_geometry,list->geometry);
+ bzero((char *)list,sizeof(XkbComponentListRec));
+ _XkbFree(list);
+ }
+ return;
+}
diff --git a/libX11/src/xkb/XKBMAlloc.c b/libX11/src/xkb/XKBMAlloc.c
index 3ed9c7bf2..f65e4e914 100644
--- a/libX11/src/xkb/XKBMAlloc.c
+++ b/libX11/src/xkb/XKBMAlloc.c
@@ -1,994 +1,990 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_DIX_CONFIG_H
-#include <dix-config.h>
-#elif defined(HAVE_CONFIG_H)
-#include <config.h>
-#endif
-
-#ifndef XKB_IN_SERVER
-
-#include <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include <X11/keysym.h>
-#include "XKBlibint.h"
-
-#else
-
-#include <stdio.h>
-#include <X11/X.h>
-#define NEED_EVENTS
-#define NEED_REPLIES
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "inputstr.h"
-#include <X11/keysym.h>
-#define XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
-
-#endif /* XKB_IN_SERVER */
-
-/***====================================================================***/
-
-Status
-XkbAllocClientMap(XkbDescPtr xkb,unsigned which,unsigned nTotalTypes)
-{
-register int i;
-XkbClientMapPtr map;
-
- if ((xkb==NULL)||((nTotalTypes>0)&&(nTotalTypes<XkbNumRequiredTypes)))
- return BadValue;
- if ((which&XkbKeySymsMask)&&
- ((!XkbIsLegalKeycode(xkb->min_key_code))||
- (!XkbIsLegalKeycode(xkb->max_key_code))||
- (xkb->max_key_code<xkb->min_key_code))) {
-#ifdef DEBUG
-fprintf(stderr,"bad keycode (%d,%d) in XkbAllocClientMap\n",
- xkb->min_key_code,xkb->max_key_code);
-#endif
- return BadValue;
- }
-
- if (xkb->map==NULL) {
- map= _XkbTypedCalloc(1,XkbClientMapRec);
- if (map==NULL)
- return BadAlloc;
- xkb->map= map;
- }
- else map= xkb->map;
-
- if ((which&XkbKeyTypesMask)&&(nTotalTypes>0)) {
- if (map->types==NULL) {
- map->types= _XkbTypedCalloc(nTotalTypes,XkbKeyTypeRec);
- if (map->types==NULL)
- return BadAlloc;
- map->num_types= 0;
- map->size_types= nTotalTypes;
- }
- else if (map->size_types<nTotalTypes) {
- XkbKeyTypeRec *prev_types = map->types;
-
- map->types= _XkbTypedRealloc(map->types,nTotalTypes,XkbKeyTypeRec);
- if (map->types==NULL) {
- _XkbFree(prev_types);
- map->num_types= map->size_types= 0;
- return BadAlloc;
- }
- map->size_types= nTotalTypes;
- bzero(&map->types[map->num_types],
- ((map->size_types-map->num_types)*sizeof(XkbKeyTypeRec)));
- }
- }
- if (which&XkbKeySymsMask) {
- int nKeys= XkbNumKeys(xkb);
- if (map->syms==NULL) {
- map->size_syms= (nKeys*15)/10;
- map->syms= _XkbTypedCalloc(map->size_syms,KeySym);
- if (!map->syms) {
- map->size_syms= 0;
- return BadAlloc;
- }
- map->num_syms= 1;
- map->syms[0]= NoSymbol;
- }
- if (map->key_sym_map==NULL) {
- i= xkb->max_key_code+1;
- map->key_sym_map= _XkbTypedCalloc(i,XkbSymMapRec);
- if (map->key_sym_map==NULL)
- return BadAlloc;
- }
- }
- if (which&XkbModifierMapMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code))||
- (!XkbIsLegalKeycode(xkb->max_key_code))||
- (xkb->max_key_code<xkb->min_key_code))
- return BadMatch;
- if (map->modmap==NULL) {
- i= xkb->max_key_code+1;
- map->modmap= _XkbTypedCalloc(i,unsigned char);
- if (map->modmap==NULL)
- return BadAlloc;
- }
- }
- return Success;
-}
-
-Status
-XkbAllocServerMap(XkbDescPtr xkb,unsigned which,unsigned nNewActions)
-{
-register int i;
-XkbServerMapPtr map;
-
- if (xkb==NULL)
- return BadMatch;
- if (xkb->server==NULL) {
- map= _XkbTypedCalloc(1,XkbServerMapRec);
- if (map==NULL)
- return BadAlloc;
- for (i=0;i<XkbNumVirtualMods;i++) {
- map->vmods[i]= XkbNoModifierMask;
- }
- xkb->server= map;
- }
- else map= xkb->server;
- if (which&XkbExplicitComponentsMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code))||
- (!XkbIsLegalKeycode(xkb->max_key_code))||
- (xkb->max_key_code<xkb->min_key_code))
- return BadMatch;
- if (map->explicit==NULL) {
- i= xkb->max_key_code+1;
- map->explicit= _XkbTypedCalloc(i,unsigned char);
- if (map->explicit==NULL)
- return BadAlloc;
- }
- }
- if (which&XkbKeyActionsMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code))||
- (!XkbIsLegalKeycode(xkb->max_key_code))||
- (xkb->max_key_code<xkb->min_key_code))
- return BadMatch;
- if (nNewActions<1)
- nNewActions= 1;
- if (map->acts==NULL) {
- map->acts= _XkbTypedCalloc((nNewActions+1),XkbAction);
- if (map->acts==NULL)
- return BadAlloc;
- map->num_acts= 1;
- map->size_acts= nNewActions+1;
- }
- else if ((map->size_acts-map->num_acts)<nNewActions) {
- unsigned need;
- XkbAction *prev_acts = map->acts;
- need= map->num_acts+nNewActions;
- map->acts= _XkbTypedRealloc(map->acts,need,XkbAction);
- if (map->acts==NULL) {
- _XkbFree(prev_acts);
- map->num_acts= map->size_acts= 0;
- return BadAlloc;
- }
- map->size_acts= need;
- bzero(&map->acts[map->num_acts],
- ((map->size_acts-map->num_acts)*sizeof(XkbAction)));
- }
- if (map->key_acts==NULL) {
- i= xkb->max_key_code+1;
- map->key_acts= _XkbTypedCalloc(i,unsigned short);
- if (map->key_acts==NULL)
- return BadAlloc;
- }
- }
- if (which&XkbKeyBehaviorsMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code))||
- (!XkbIsLegalKeycode(xkb->max_key_code))||
- (xkb->max_key_code<xkb->min_key_code))
- return BadMatch;
- if (map->behaviors==NULL) {
- i= xkb->max_key_code+1;
- map->behaviors= _XkbTypedCalloc(i,XkbBehavior);
- if (map->behaviors==NULL)
- return BadAlloc;
- }
- }
- if (which&XkbVirtualModMapMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code))||
- (!XkbIsLegalKeycode(xkb->max_key_code))||
- (xkb->max_key_code<xkb->min_key_code))
- return BadMatch;
- if (map->vmodmap==NULL) {
- i= xkb->max_key_code+1;
- map->vmodmap= _XkbTypedCalloc(i,unsigned short);
- if (map->vmodmap==NULL)
- return BadAlloc;
- }
- }
- return Success;
-}
-
-/***====================================================================***/
-
-Status
-XkbCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into)
-{
- if ((!from)||(!into))
- return BadMatch;
- if (into->map) {
- _XkbFree(into->map);
- into->map= NULL;
- }
- if (into->preserve) {
- _XkbFree(into->preserve);
- into->preserve= NULL;
- }
- if (into->level_names) {
- _XkbFree(into->level_names);
- into->level_names= NULL;
- }
- *into= *from;
- if ((from->map)&&(into->map_count>0)) {
- into->map= _XkbTypedCalloc(into->map_count,XkbKTMapEntryRec);
- if (!into->map)
- return BadAlloc;
- memcpy(into->map,from->map,into->map_count*sizeof(XkbKTMapEntryRec));
- }
- if ((from->preserve)&&(into->map_count>0)) {
- into->preserve= _XkbTypedCalloc(into->map_count,XkbModsRec);
- if (!into->preserve)
- return BadAlloc;
- memcpy(into->preserve,from->preserve,
- into->map_count*sizeof(XkbModsRec));
- }
- if ((from->level_names)&&(into->num_levels>0)) {
- into->level_names= _XkbTypedCalloc(into->num_levels,Atom);
- if (!into->level_names)
- return BadAlloc;
- memcpy(into->level_names,from->level_names,
- into->num_levels*sizeof(Atom));
- }
- return Success;
-}
-
-Status
-XkbCopyKeyTypes(XkbKeyTypePtr from,XkbKeyTypePtr into,int num_types)
-{
-register int i,rtrn;
-
- if ((!from)||(!into)||(num_types<0))
- return BadMatch;
- for (i=0;i<num_types;i++) {
- if ((rtrn= XkbCopyKeyType(from++,into++))!=Success)
- return rtrn;
- }
- return Success;
-}
-
-XkbKeyTypePtr
-XkbAddKeyType( XkbDescPtr xkb,
- Atom name,
- int map_count,
- Bool want_preserve,
- int num_lvls)
-{
-register int i;
-unsigned tmp;
-XkbKeyTypePtr type;
-XkbClientMapPtr map;
-
- if ((!xkb)||(num_lvls<1))
- return NULL;
- map= xkb->map;
- if ((map)&&(map->types)) {
- for (i=0;i<map->num_types;i++) {
- if (map->types[i].name==name) {
- Status status;
- status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
- return (status==Success?&map->types[i]:NULL);
- }
- }
- }
- if ((!map)||(!map->types)||(!map->num_types<XkbNumRequiredTypes)) {
- tmp= XkbNumRequiredTypes+1;
- if (XkbAllocClientMap(xkb,XkbKeyTypesMask,tmp)!=Success)
- return NULL;
- if (!map)
- map = xkb->map;
- tmp= 0;
- if (map->num_types<=XkbKeypadIndex)
- tmp|= XkbKeypadMask;
- if (map->num_types<=XkbAlphabeticIndex)
- tmp|= XkbAlphabeticMask;
- if (map->num_types<=XkbTwoLevelIndex)
- tmp|= XkbTwoLevelMask;
- if (map->num_types<=XkbOneLevelIndex)
- tmp|= XkbOneLevelMask;
- if (XkbInitCanonicalKeyTypes(xkb,tmp,XkbNoModifier)==Success) {
- for (i=0;i<map->num_types;i++) {
- Status status;
- if (map->types[i].name!=name)
- continue;
- status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
- return (status==Success?&map->types[i]:NULL);
- }
- }
- }
- if ((map->num_types<=map->size_types)&&
- (XkbAllocClientMap(xkb,XkbKeyTypesMask,map->num_types+1)!=Success)) {
- return NULL;
- }
- type= &map->types[map->num_types];
- map->num_types++;
- bzero((char *)type,sizeof(XkbKeyTypeRec));
- type->num_levels= num_lvls;
- type->map_count= map_count;
- type->name= name;
- if (map_count>0) {
- type->map= _XkbTypedCalloc(map_count,XkbKTMapEntryRec);
- if (!type->map) {
- map->num_types--;
- return NULL;
- }
- if (want_preserve) {
- type->preserve= _XkbTypedCalloc(map_count,XkbModsRec);
- if (!type->preserve) {
- _XkbFree(type->map);
- map->num_types--;
- return NULL;
- }
- }
- }
- return type;
-}
-
-Status
-XkbResizeKeyType( XkbDescPtr xkb,
- int type_ndx,
- int map_count,
- Bool want_preserve,
- int new_num_lvls)
-{
-XkbKeyTypePtr type;
-KeyCode matchingKeys[XkbMaxKeyCount],nMatchingKeys;
-
- if ((type_ndx<0)||(type_ndx>=xkb->map->num_types)||(map_count<0)||
- (new_num_lvls<1))
- return BadValue;
- switch (type_ndx) {
- case XkbOneLevelIndex:
- if (new_num_lvls!=1)
- return BadMatch;
- break;
- case XkbTwoLevelIndex:
- case XkbAlphabeticIndex:
- case XkbKeypadIndex:
- if (new_num_lvls!=2)
- return BadMatch;
- break;
- }
- type= &xkb->map->types[type_ndx];
- if (map_count==0) {
- if (type->map!=NULL)
- _XkbFree(type->map);
- type->map= NULL;
- if (type->preserve!=NULL)
- _XkbFree(type->preserve);
- type->preserve= NULL;
- type->map_count= 0;
- }
- else {
- XkbKTMapEntryRec *prev_map = type->map;
-
- if ((map_count>type->map_count)||(type->map==NULL))
- type->map=_XkbTypedRealloc(type->map,map_count,XkbKTMapEntryRec);
- if (!type->map) {
- if (prev_map)
- _XkbFree(prev_map);
- return BadAlloc;
- }
- if (want_preserve) {
- XkbModsRec *prev_preserve = type->preserve;
-
- if ((map_count>type->map_count)||(type->preserve==NULL)) {
- type->preserve= _XkbTypedRealloc(type->preserve,map_count,
- XkbModsRec);
- }
- if (!type->preserve) {
- if (prev_preserve)
- _XkbFree(prev_preserve);
- return BadAlloc;
- }
- }
- else if (type->preserve!=NULL) {
- _XkbFree(type->preserve);
- type->preserve= NULL;
- }
- type->map_count= map_count;
- }
-
- if ((new_num_lvls>type->num_levels)||(type->level_names==NULL)) {
- Atom * prev_level_names = type->level_names;
-
- type->level_names=_XkbTypedRealloc(type->level_names,new_num_lvls,Atom);
- if (!type->level_names) {
- if (prev_level_names)
- _XkbFree(prev_level_names);
- return BadAlloc;
- }
- }
- /*
- * Here's the theory:
- * If the width of the type changed, we might have to resize the symbol
- * maps for any keys that use the type for one or more groups. This is
- * expensive, so we'll try to cull out any keys that are obviously okay:
- * In any case:
- * - keys that have a group width <= the old width are okay (because
- * they could not possibly have been associated with the old type)
- * If the key type increased in size:
- * - keys that already have a group width >= to the new width are okay
- * + keys that have a group width >= the old width but < the new width
- * might have to be enlarged.
- * If the key type decreased in size:
- * - keys that have a group width > the old width don't have to be
- * resized (because they must have some other wider type associated
- * with some group).
- * + keys that have a group width == the old width might have to be
- * shrunk.
- * The possibilities marked with '+' require us to examine the key types
- * associated with each group for the key.
- */
- bzero(matchingKeys,XkbMaxKeyCount*sizeof(KeyCode));
- nMatchingKeys= 0;
- if (new_num_lvls>type->num_levels) {
- int nTotal;
- KeySym * newSyms;
- int width,match,nResize;
- register int i,g,nSyms;
-
- nResize= 0;
- for (nTotal=1,i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
- width= XkbKeyGroupsWidth(xkb,i);
- if (width<type->num_levels)
- continue;
- for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) {
- if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) {
- matchingKeys[nMatchingKeys++]= i;
- match= 1;
- }
- }
- if ((!match)||(width>=new_num_lvls))
- nTotal+= XkbKeyNumSyms(xkb,i);
- else {
- nTotal+= XkbKeyNumGroups(xkb,i)*new_num_lvls;
- nResize++;
- }
- }
- if (nResize>0) {
- int nextMatch;
- xkb->map->size_syms= (nTotal*12)/10;
- newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym);
- if (newSyms==NULL)
- return BadAlloc;
- nextMatch= 0;
- nSyms= 1;
- for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
- if (matchingKeys[nextMatch]==i) {
- KeySym *pOld;
- nextMatch++;
- width= XkbKeyGroupsWidth(xkb,i);
- pOld= XkbKeySymsPtr(xkb,i);
- for (g=XkbKeyNumGroups(xkb,i)-1;g>=0;g--) {
- memcpy(&newSyms[nSyms+(new_num_lvls*g)],&pOld[width*g],
- width*sizeof(KeySym));
- }
- xkb->map->key_sym_map[i].offset= nSyms;
- nSyms+= XkbKeyNumGroups(xkb,i)*new_num_lvls;
- }
- else {
- memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),
- XkbKeyNumSyms(xkb,i)*sizeof(KeySym));
- xkb->map->key_sym_map[i].offset= nSyms;
- nSyms+= XkbKeyNumSyms(xkb,i);
- }
- }
- type->num_levels= new_num_lvls;
- _XkbFree(xkb->map->syms);
- xkb->map->syms= newSyms;
- xkb->map->num_syms= nSyms;
- return Success;
- }
- }
- else if (new_num_lvls<type->num_levels) {
- int width,match;
- register int g,i;
- for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
- width= XkbKeyGroupsWidth(xkb,i);
- if (width<type->num_levels)
- continue;
- for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) {
- if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) {
- matchingKeys[nMatchingKeys++]= i;
- match= 1;
- }
- }
- }
- }
- if (nMatchingKeys>0) {
- int key,firstClear;
- register int i,g;
- if (new_num_lvls>type->num_levels)
- firstClear= type->num_levels;
- else firstClear= new_num_lvls;
- for (i=0;i<nMatchingKeys;i++) {
- KeySym * pSyms;
- int width,nClear;
-
- key= matchingKeys[i];
- width= XkbKeyGroupsWidth(xkb,key);
- nClear= width-firstClear;
- pSyms= XkbKeySymsPtr(xkb,key);
- for (g=XkbKeyNumGroups(xkb,key)-1;g>=0;g--) {
- if (XkbKeyKeyTypeIndex(xkb,key,g)==type_ndx) {
- if (nClear>0)
- bzero(&pSyms[g*width+firstClear],nClear*sizeof(KeySym));
- }
- }
- }
- }
- type->num_levels= new_num_lvls;
- return Success;
-}
-
-KeySym *
-XkbResizeKeySyms(XkbDescPtr xkb,int key,int needed)
-{
-register int i,nSyms,nKeySyms;
-unsigned nOldSyms;
-KeySym *newSyms;
-
- if (needed==0) {
- xkb->map->key_sym_map[key].offset= 0;
- return xkb->map->syms;
- }
- nOldSyms= XkbKeyNumSyms(xkb,key);
- if (nOldSyms>=(unsigned)needed) {
- return XkbKeySymsPtr(xkb,key);
- }
- if (xkb->map->size_syms-xkb->map->num_syms>=(unsigned)needed) {
- if (nOldSyms>0) {
- memcpy(&xkb->map->syms[xkb->map->num_syms],XkbKeySymsPtr(xkb,key),
- nOldSyms*sizeof(KeySym));
- }
- if ((needed-nOldSyms)>0) {
- bzero(&xkb->map->syms[xkb->map->num_syms+XkbKeyNumSyms(xkb,key)],
- (needed-nOldSyms)*sizeof(KeySym));
- }
- xkb->map->key_sym_map[key].offset = xkb->map->num_syms;
- xkb->map->num_syms+= needed;
- return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
- }
- xkb->map->size_syms+= (needed>32?needed:32);
- newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym);
- if (newSyms==NULL)
- return NULL;
- newSyms[0]= NoSymbol;
- nSyms = 1;
- for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) {
- int nCopy;
-
- nCopy= nKeySyms= XkbKeyNumSyms(xkb,i);
- if ((nKeySyms==0)&&(i!=key))
- continue;
- if (i==key)
- nKeySyms= needed;
- if (nCopy!=0)
- memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),nCopy*sizeof(KeySym));
- if (nKeySyms>nCopy)
- bzero(&newSyms[nSyms+nCopy],(nKeySyms-nCopy)*sizeof(KeySym));
- xkb->map->key_sym_map[i].offset = nSyms;
- nSyms+= nKeySyms;
- }
- _XkbFree(xkb->map->syms);
- xkb->map->syms = newSyms;
- xkb->map->num_syms = nSyms;
- return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
-}
-
-static unsigned
-_ExtendRange( unsigned int old_flags,
- unsigned int flag,
- KeyCode newKC,
- KeyCode * old_min,
- unsigned char * old_num)
-{
- if ((old_flags&flag)==0) {
- old_flags|= flag;
- *old_min= newKC;
- *old_num= 1;
- }
- else {
- int last= (*old_min)+(*old_num)-1;
- if (newKC<*old_min) {
- *old_min= newKC;
- *old_num= (last-newKC)+1;
- }
- else if (newKC>last) {
- *old_num= (newKC-(*old_min))+1;
- }
- }
- return old_flags;
-}
-
-Status
-XkbChangeKeycodeRange( XkbDescPtr xkb,
- int minKC,
- int maxKC,
- XkbChangesPtr changes)
-{
-int tmp;
-
- if ((!xkb)||(minKC<XkbMinLegalKeyCode)||(maxKC>XkbMaxLegalKeyCode))
- return BadValue;
- if (minKC>maxKC)
- return BadMatch;
- if (minKC<xkb->min_key_code) {
- if (changes)
- changes->map.min_key_code= minKC;
- tmp= xkb->min_key_code-minKC;
- if (xkb->map) {
- if (xkb->map->key_sym_map) {
- bzero((char *)&xkb->map->key_sym_map[minKC],
- tmp*sizeof(XkbSymMapRec));
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbKeySymsMask,minKC,
- &changes->map.first_key_sym,
- &changes->map.num_key_syms);
- }
- }
- if (xkb->map->modmap) {
- bzero((char *)&xkb->map->modmap[minKC],tmp);
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbModifierMapMask,minKC,
- &changes->map.first_modmap_key,
- &changes->map.num_modmap_keys);
- }
- }
- }
- if (xkb->server) {
- if (xkb->server->behaviors) {
- bzero((char *)&xkb->server->behaviors[minKC],
- tmp*sizeof(XkbBehavior));
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbKeyBehaviorsMask,minKC,
- &changes->map.first_key_behavior,
- &changes->map.num_key_behaviors);
- }
- }
- if (xkb->server->key_acts) {
- bzero((char *)&xkb->server->key_acts[minKC],
- tmp*sizeof(unsigned short));
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbKeyActionsMask,minKC,
- &changes->map.first_key_act,
- &changes->map.num_key_acts);
- }
- }
- if (xkb->server->vmodmap) {
- bzero((char *)&xkb->server->vmodmap[minKC],
- tmp*sizeof(unsigned short));
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbVirtualModMapMask,minKC,
- &changes->map.first_modmap_key,
- &changes->map.num_vmodmap_keys);
- }
- }
- }
- if ((xkb->names)&&(xkb->names->keys)) {
- bzero((char *)&xkb->names->keys[minKC],tmp*sizeof(XkbKeyNameRec));
- if (changes) {
- changes->names.changed= _ExtendRange(changes->names.changed,
- XkbKeyNamesMask,minKC,
- &changes->names.first_key,
- &changes->names.num_keys);
- }
- }
- xkb->min_key_code= minKC;
- }
- if (maxKC>xkb->max_key_code) {
- if (changes)
- changes->map.max_key_code= maxKC;
- tmp= maxKC-xkb->max_key_code;
- if (xkb->map) {
- if (xkb->map->key_sym_map) {
- XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map;
-
- xkb->map->key_sym_map= _XkbTypedRealloc(xkb->map->key_sym_map,
- (maxKC+1),XkbSymMapRec);
- if (!xkb->map->key_sym_map) {
- _XkbFree(prev_key_sym_map);
- return BadAlloc;
- }
- bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code],
- tmp*sizeof(XkbSymMapRec));
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbKeySymsMask,maxKC,
- &changes->map.first_key_sym,
- &changes->map.num_key_syms);
- }
- }
- if (xkb->map->modmap) {
- unsigned char *prev_modmap = xkb->map->modmap;
-
- xkb->map->modmap= _XkbTypedRealloc(xkb->map->modmap,
- (maxKC+1),unsigned char);
- if (!xkb->map->modmap) {
- _XkbFree(prev_modmap);
- return BadAlloc;
- }
- bzero((char *)&xkb->map->modmap[xkb->max_key_code],tmp);
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbModifierMapMask,maxKC,
- &changes->map.first_modmap_key,
- &changes->map.num_modmap_keys);
- }
- }
- }
- if (xkb->server) {
- if (xkb->server->behaviors) {
- XkbBehavior *prev_behaviors = xkb->server->behaviors;
-
- xkb->server->behaviors=_XkbTypedRealloc(xkb->server->behaviors,
- (maxKC+1),XkbBehavior);
- if (!xkb->server->behaviors) {
- _XkbFree(prev_behaviors);
- return BadAlloc;
- }
- bzero((char *)&xkb->server->behaviors[xkb->max_key_code],
- tmp*sizeof(XkbBehavior));
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbKeyBehaviorsMask,maxKC,
- &changes->map.first_key_behavior,
- &changes->map.num_key_behaviors);
- }
- }
- if (xkb->server->key_acts) {
- unsigned short *prev_key_acts = xkb->server->key_acts;
-
- xkb->server->key_acts= _XkbTypedRealloc(xkb->server->key_acts,
- (maxKC+1),unsigned short);
- if (!xkb->server->key_acts) {
- _XkbFree(prev_key_acts);
- return BadAlloc;
- }
- bzero((char *)&xkb->server->key_acts[xkb->max_key_code],
- tmp*sizeof(unsigned short));
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbKeyActionsMask,maxKC,
- &changes->map.first_key_act,
- &changes->map.num_key_acts);
- }
- }
- if (xkb->server->vmodmap) {
- unsigned short *prev_vmodmap = xkb->server->vmodmap;
-
- xkb->server->vmodmap= _XkbTypedRealloc(xkb->server->vmodmap,
- (maxKC+1),unsigned short);
- if (!xkb->server->vmodmap) {
- _XkbFree(prev_vmodmap);
- return BadAlloc;
- }
- bzero((char *)&xkb->server->vmodmap[xkb->max_key_code],
- tmp*sizeof(unsigned short));
- if (changes) {
- changes->map.changed= _ExtendRange(changes->map.changed,
- XkbVirtualModMapMask,maxKC,
- &changes->map.first_modmap_key,
- &changes->map.num_vmodmap_keys);
- }
- }
- }
- if ((xkb->names)&&(xkb->names->keys)) {
- XkbKeyNameRec *prev_keys = xkb->names->keys;
-
- xkb->names->keys= _XkbTypedRealloc(xkb->names->keys,
- (maxKC+1),XkbKeyNameRec);
- if (!xkb->names->keys) {
- _XkbFree(prev_keys);
- return BadAlloc;
- }
- bzero((char *)&xkb->names->keys[xkb->max_key_code],
- tmp*sizeof(XkbKeyNameRec));
- if (changes) {
- changes->names.changed= _ExtendRange(changes->names.changed,
- XkbKeyNamesMask,maxKC,
- &changes->names.first_key,
- &changes->names.num_keys);
- }
- }
- xkb->max_key_code= maxKC;
- }
- return Success;
-}
-
-XkbAction *
-XkbResizeKeyActions(XkbDescPtr xkb,int key,int needed)
-{
-register int i,nActs;
-XkbAction *newActs;
-
- if (needed==0) {
- xkb->server->key_acts[key]= 0;
- return NULL;
- }
- if (XkbKeyHasActions(xkb,key)&&(XkbKeyNumSyms(xkb,key)>=(unsigned)needed))
- return XkbKeyActionsPtr(xkb,key);
- if (xkb->server->size_acts-xkb->server->num_acts>=(unsigned)needed) {
- xkb->server->key_acts[key]= xkb->server->num_acts;
- xkb->server->num_acts+= needed;
- return &xkb->server->acts[xkb->server->key_acts[key]];
- }
- xkb->server->size_acts= xkb->server->num_acts+needed+8;
- newActs = _XkbTypedCalloc(xkb->server->size_acts,XkbAction);
- if (newActs==NULL)
- return NULL;
- newActs[0].type = XkbSA_NoAction;
- nActs = 1;
- for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) {
- int nKeyActs,nCopy;
-
- if ((xkb->server->key_acts[i]==0)&&(i!=key))
- continue;
-
- nCopy= nKeyActs= XkbKeyNumActions(xkb,i);
- if (i==key) {
- nKeyActs= needed;
- if (needed<nCopy)
- nCopy= needed;
- }
-
- if (nCopy>0)
- memcpy(&newActs[nActs],XkbKeyActionsPtr(xkb,i),
- nCopy*sizeof(XkbAction));
- if (nCopy<nKeyActs)
- bzero(&newActs[nActs+nCopy],(nKeyActs-nCopy)*sizeof(XkbAction));
- xkb->server->key_acts[i]= nActs;
- nActs+= nKeyActs;
- }
- _XkbFree(xkb->server->acts);
- xkb->server->acts = newActs;
- xkb->server->num_acts= nActs;
- return &xkb->server->acts[xkb->server->key_acts[key]];
-}
-
-void
-XkbFreeClientMap(XkbDescPtr xkb,unsigned what,Bool freeMap)
-{
-XkbClientMapPtr map;
-
- if ((xkb==NULL)||(xkb->map==NULL))
- return;
- if (freeMap)
- what= XkbAllClientInfoMask;
- map= xkb->map;
- if (what&XkbKeyTypesMask) {
- if (map->types!=NULL) {
- if (map->num_types>0) {
- register int i;
- XkbKeyTypePtr type;
- for (i=0,type=map->types;i<map->num_types;i++,type++) {
- if (type->map!=NULL) {
- _XkbFree(type->map);
- type->map= NULL;
- }
- if (type->preserve!=NULL) {
- _XkbFree(type->preserve);
- type->preserve= NULL;
- }
- type->map_count= 0;
- if (type->level_names!=NULL) {
- _XkbFree(type->level_names);
- type->level_names= NULL;
- }
- }
- }
- _XkbFree(map->types);
- map->num_types= map->size_types= 0;
- map->types= NULL;
- }
- }
- if (what&XkbKeySymsMask) {
- if (map->key_sym_map!=NULL) {
- _XkbFree(map->key_sym_map);
- map->key_sym_map= NULL;
- }
- if (map->syms!=NULL) {
- _XkbFree(map->syms);
- map->size_syms= map->num_syms= 0;
- map->syms= NULL;
- }
- }
- if ((what&XkbModifierMapMask)&&(map->modmap!=NULL)) {
- _XkbFree(map->modmap);
- map->modmap= NULL;
- }
- if (freeMap) {
- _XkbFree(xkb->map);
- xkb->map= NULL;
- }
- return;
-}
-
-void
-XkbFreeServerMap(XkbDescPtr xkb,unsigned what,Bool freeMap)
-{
-XkbServerMapPtr map;
-
- if ((xkb==NULL)||(xkb->server==NULL))
- return;
- if (freeMap)
- what= XkbAllServerInfoMask;
- map= xkb->server;
- if ((what&XkbExplicitComponentsMask)&&(map->explicit!=NULL)) {
- _XkbFree(map->explicit);
- map->explicit= NULL;
- }
- if (what&XkbKeyActionsMask) {
- if (map->key_acts!=NULL) {
- _XkbFree(map->key_acts);
- map->key_acts= NULL;
- }
- if (map->acts!=NULL) {
- _XkbFree(map->acts);
- map->num_acts= map->size_acts= 0;
- map->acts= NULL;
- }
- }
- if ((what&XkbKeyBehaviorsMask)&&(map->behaviors!=NULL)) {
- _XkbFree(map->behaviors);
- map->behaviors= NULL;
- }
- if ((what&XkbVirtualModMapMask)&&(map->vmodmap!=NULL)) {
- _XkbFree(map->vmodmap);
- map->vmodmap= NULL;
- }
-
- if (freeMap) {
- _XkbFree(xkb->server);
- xkb->server= NULL;
- }
- return;
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_DIX_CONFIG_H
+#include <dix-config.h>
+#elif defined(HAVE_CONFIG_H)
+#include <config.h>
+#endif
+
+#ifndef XKB_IN_SERVER
+
+#include <stdio.h>
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include <X11/keysym.h>
+#include "XKBlibint.h"
+
+#else
+
+#include <stdio.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "inputstr.h"
+#include <X11/keysym.h>
+#define XKBSRV_NEED_FILE_FUNCS
+#include <X11/extensions/XKBsrv.h>
+
+#endif /* XKB_IN_SERVER */
+
+/***====================================================================***/
+
+Status
+XkbAllocClientMap(XkbDescPtr xkb,unsigned which,unsigned nTotalTypes)
+{
+register int i;
+XkbClientMapPtr map;
+
+ if ((xkb==NULL)||((nTotalTypes>0)&&(nTotalTypes<XkbNumRequiredTypes)))
+ return BadValue;
+ if ((which&XkbKeySymsMask)&&
+ ((!XkbIsLegalKeycode(xkb->min_key_code))||
+ (!XkbIsLegalKeycode(xkb->max_key_code))||
+ (xkb->max_key_code<xkb->min_key_code))) {
+#ifdef DEBUG
+fprintf(stderr,"bad keycode (%d,%d) in XkbAllocClientMap\n",
+ xkb->min_key_code,xkb->max_key_code);
+#endif
+ return BadValue;
+ }
+
+ if (xkb->map==NULL) {
+ map= _XkbTypedCalloc(1,XkbClientMapRec);
+ if (map==NULL)
+ return BadAlloc;
+ xkb->map= map;
+ }
+ else map= xkb->map;
+
+ if ((which&XkbKeyTypesMask)&&(nTotalTypes>0)) {
+ if (map->types==NULL) {
+ map->types= _XkbTypedCalloc(nTotalTypes,XkbKeyTypeRec);
+ if (map->types==NULL)
+ return BadAlloc;
+ map->num_types= 0;
+ map->size_types= nTotalTypes;
+ }
+ else if (map->size_types<nTotalTypes) {
+ XkbKeyTypeRec *prev_types = map->types;
+
+ map->types= _XkbTypedRealloc(map->types,nTotalTypes,XkbKeyTypeRec);
+ if (map->types==NULL) {
+ _XkbFree(prev_types);
+ map->num_types= map->size_types= 0;
+ return BadAlloc;
+ }
+ map->size_types= nTotalTypes;
+ bzero(&map->types[map->num_types],
+ ((map->size_types-map->num_types)*sizeof(XkbKeyTypeRec)));
+ }
+ }
+ if (which&XkbKeySymsMask) {
+ int nKeys= XkbNumKeys(xkb);
+ if (map->syms==NULL) {
+ map->size_syms= (nKeys*15)/10;
+ map->syms= _XkbTypedCalloc(map->size_syms,KeySym);
+ if (!map->syms) {
+ map->size_syms= 0;
+ return BadAlloc;
+ }
+ map->num_syms= 1;
+ map->syms[0]= NoSymbol;
+ }
+ if (map->key_sym_map==NULL) {
+ i= xkb->max_key_code+1;
+ map->key_sym_map= _XkbTypedCalloc(i,XkbSymMapRec);
+ if (map->key_sym_map==NULL)
+ return BadAlloc;
+ }
+ }
+ if (which&XkbModifierMapMask) {
+ if ((!XkbIsLegalKeycode(xkb->min_key_code))||
+ (!XkbIsLegalKeycode(xkb->max_key_code))||
+ (xkb->max_key_code<xkb->min_key_code))
+ return BadMatch;
+ if (map->modmap==NULL) {
+ i= xkb->max_key_code+1;
+ map->modmap= _XkbTypedCalloc(i,unsigned char);
+ if (map->modmap==NULL)
+ return BadAlloc;
+ }
+ }
+ return Success;
+}
+
+Status
+XkbAllocServerMap(XkbDescPtr xkb,unsigned which,unsigned nNewActions)
+{
+register int i;
+XkbServerMapPtr map;
+
+ if (xkb==NULL)
+ return BadMatch;
+ if (xkb->server==NULL) {
+ map= _XkbTypedCalloc(1,XkbServerMapRec);
+ if (map==NULL)
+ return BadAlloc;
+ for (i=0;i<XkbNumVirtualMods;i++) {
+ map->vmods[i]= XkbNoModifierMask;
+ }
+ xkb->server= map;
+ }
+ else map= xkb->server;
+ if (which&XkbExplicitComponentsMask) {
+ if ((!XkbIsLegalKeycode(xkb->min_key_code))||
+ (!XkbIsLegalKeycode(xkb->max_key_code))||
+ (xkb->max_key_code<xkb->min_key_code))
+ return BadMatch;
+ if (map->explicit==NULL) {
+ i= xkb->max_key_code+1;
+ map->explicit= _XkbTypedCalloc(i,unsigned char);
+ if (map->explicit==NULL)
+ return BadAlloc;
+ }
+ }
+ if (which&XkbKeyActionsMask) {
+ if ((!XkbIsLegalKeycode(xkb->min_key_code))||
+ (!XkbIsLegalKeycode(xkb->max_key_code))||
+ (xkb->max_key_code<xkb->min_key_code))
+ return BadMatch;
+ if (nNewActions<1)
+ nNewActions= 1;
+ if (map->acts==NULL) {
+ map->acts= _XkbTypedCalloc((nNewActions+1),XkbAction);
+ if (map->acts==NULL)
+ return BadAlloc;
+ map->num_acts= 1;
+ map->size_acts= nNewActions+1;
+ }
+ else if ((map->size_acts-map->num_acts)<nNewActions) {
+ unsigned need;
+ XkbAction *prev_acts = map->acts;
+ need= map->num_acts+nNewActions;
+ map->acts= _XkbTypedRealloc(map->acts,need,XkbAction);
+ if (map->acts==NULL) {
+ _XkbFree(prev_acts);
+ map->num_acts= map->size_acts= 0;
+ return BadAlloc;
+ }
+ map->size_acts= need;
+ bzero(&map->acts[map->num_acts],
+ ((map->size_acts-map->num_acts)*sizeof(XkbAction)));
+ }
+ if (map->key_acts==NULL) {
+ i= xkb->max_key_code+1;
+ map->key_acts= _XkbTypedCalloc(i,unsigned short);
+ if (map->key_acts==NULL)
+ return BadAlloc;
+ }
+ }
+ if (which&XkbKeyBehaviorsMask) {
+ if ((!XkbIsLegalKeycode(xkb->min_key_code))||
+ (!XkbIsLegalKeycode(xkb->max_key_code))||
+ (xkb->max_key_code<xkb->min_key_code))
+ return BadMatch;
+ if (map->behaviors==NULL) {
+ i= xkb->max_key_code+1;
+ map->behaviors= _XkbTypedCalloc(i,XkbBehavior);
+ if (map->behaviors==NULL)
+ return BadAlloc;
+ }
+ }
+ if (which&XkbVirtualModMapMask) {
+ if ((!XkbIsLegalKeycode(xkb->min_key_code))||
+ (!XkbIsLegalKeycode(xkb->max_key_code))||
+ (xkb->max_key_code<xkb->min_key_code))
+ return BadMatch;
+ if (map->vmodmap==NULL) {
+ i= xkb->max_key_code+1;
+ map->vmodmap= _XkbTypedCalloc(i,unsigned short);
+ if (map->vmodmap==NULL)
+ return BadAlloc;
+ }
+ }
+ return Success;
+}
+
+/***====================================================================***/
+
+Status
+XkbCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into)
+{
+ if ((!from)||(!into))
+ return BadMatch;
+ if (into->map) {
+ _XkbFree(into->map);
+ into->map= NULL;
+ }
+ if (into->preserve) {
+ _XkbFree(into->preserve);
+ into->preserve= NULL;
+ }
+ if (into->level_names) {
+ _XkbFree(into->level_names);
+ into->level_names= NULL;
+ }
+ *into= *from;
+ if ((from->map)&&(into->map_count>0)) {
+ into->map= _XkbTypedCalloc(into->map_count,XkbKTMapEntryRec);
+ if (!into->map)
+ return BadAlloc;
+ memcpy(into->map,from->map,into->map_count*sizeof(XkbKTMapEntryRec));
+ }
+ if ((from->preserve)&&(into->map_count>0)) {
+ into->preserve= _XkbTypedCalloc(into->map_count,XkbModsRec);
+ if (!into->preserve)
+ return BadAlloc;
+ memcpy(into->preserve,from->preserve,
+ into->map_count*sizeof(XkbModsRec));
+ }
+ if ((from->level_names)&&(into->num_levels>0)) {
+ into->level_names= _XkbTypedCalloc(into->num_levels,Atom);
+ if (!into->level_names)
+ return BadAlloc;
+ memcpy(into->level_names,from->level_names,
+ into->num_levels*sizeof(Atom));
+ }
+ return Success;
+}
+
+Status
+XkbCopyKeyTypes(XkbKeyTypePtr from,XkbKeyTypePtr into,int num_types)
+{
+register int i,rtrn;
+
+ if ((!from)||(!into)||(num_types<0))
+ return BadMatch;
+ for (i=0;i<num_types;i++) {
+ if ((rtrn= XkbCopyKeyType(from++,into++))!=Success)
+ return rtrn;
+ }
+ return Success;
+}
+
+XkbKeyTypePtr
+XkbAddKeyType( XkbDescPtr xkb,
+ Atom name,
+ int map_count,
+ Bool want_preserve,
+ int num_lvls)
+{
+register int i;
+unsigned tmp;
+XkbKeyTypePtr type;
+XkbClientMapPtr map;
+
+ if ((!xkb)||(num_lvls<1))
+ return NULL;
+ map= xkb->map;
+ if ((map)&&(map->types)) {
+ for (i=0;i<map->num_types;i++) {
+ if (map->types[i].name==name) {
+ Status status;
+ status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
+ return (status==Success?&map->types[i]:NULL);
+ }
+ }
+ }
+ if ((!map)||(!map->types)||(!map->num_types<XkbNumRequiredTypes)) {
+ tmp= XkbNumRequiredTypes+1;
+ if (XkbAllocClientMap(xkb,XkbKeyTypesMask,tmp)!=Success)
+ return NULL;
+ if (!map)
+ map = xkb->map;
+ tmp= 0;
+ if (map->num_types<=XkbKeypadIndex)
+ tmp|= XkbKeypadMask;
+ if (map->num_types<=XkbAlphabeticIndex)
+ tmp|= XkbAlphabeticMask;
+ if (map->num_types<=XkbTwoLevelIndex)
+ tmp|= XkbTwoLevelMask;
+ if (map->num_types<=XkbOneLevelIndex)
+ tmp|= XkbOneLevelMask;
+ if (XkbInitCanonicalKeyTypes(xkb,tmp,XkbNoModifier)==Success) {
+ for (i=0;i<map->num_types;i++) {
+ Status status;
+ if (map->types[i].name!=name)
+ continue;
+ status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
+ return (status==Success?&map->types[i]:NULL);
+ }
+ }
+ }
+ if ((map->num_types<=map->size_types)&&
+ (XkbAllocClientMap(xkb,XkbKeyTypesMask,map->num_types+1)!=Success)) {
+ return NULL;
+ }
+ type= &map->types[map->num_types];
+ map->num_types++;
+ bzero((char *)type,sizeof(XkbKeyTypeRec));
+ type->num_levels= num_lvls;
+ type->map_count= map_count;
+ type->name= name;
+ if (map_count>0) {
+ type->map= _XkbTypedCalloc(map_count,XkbKTMapEntryRec);
+ if (!type->map) {
+ map->num_types--;
+ return NULL;
+ }
+ if (want_preserve) {
+ type->preserve= _XkbTypedCalloc(map_count,XkbModsRec);
+ if (!type->preserve) {
+ _XkbFree(type->map);
+ map->num_types--;
+ return NULL;
+ }
+ }
+ }
+ return type;
+}
+
+Status
+XkbResizeKeyType( XkbDescPtr xkb,
+ int type_ndx,
+ int map_count,
+ Bool want_preserve,
+ int new_num_lvls)
+{
+XkbKeyTypePtr type;
+KeyCode matchingKeys[XkbMaxKeyCount],nMatchingKeys;
+
+ if ((type_ndx<0)||(type_ndx>=xkb->map->num_types)||(map_count<0)||
+ (new_num_lvls<1))
+ return BadValue;
+ switch (type_ndx) {
+ case XkbOneLevelIndex:
+ if (new_num_lvls!=1)
+ return BadMatch;
+ break;
+ case XkbTwoLevelIndex:
+ case XkbAlphabeticIndex:
+ case XkbKeypadIndex:
+ if (new_num_lvls!=2)
+ return BadMatch;
+ break;
+ }
+ type= &xkb->map->types[type_ndx];
+ if (map_count==0) {
+ if (type->map!=NULL)
+ _XkbFree(type->map);
+ type->map= NULL;
+ if (type->preserve!=NULL)
+ _XkbFree(type->preserve);
+ type->preserve= NULL;
+ type->map_count= 0;
+ }
+ else {
+ XkbKTMapEntryRec *prev_map = type->map;
+
+ if ((map_count>type->map_count)||(type->map==NULL))
+ type->map=_XkbTypedRealloc(type->map,map_count,XkbKTMapEntryRec);
+ if (!type->map) {
+ if (prev_map)
+ _XkbFree(prev_map);
+ return BadAlloc;
+ }
+ if (want_preserve) {
+ XkbModsRec *prev_preserve = type->preserve;
+
+ if ((map_count>type->map_count)||(type->preserve==NULL)) {
+ type->preserve= _XkbTypedRealloc(type->preserve,map_count,
+ XkbModsRec);
+ }
+ if (!type->preserve) {
+ if (prev_preserve)
+ _XkbFree(prev_preserve);
+ return BadAlloc;
+ }
+ }
+ else if (type->preserve!=NULL) {
+ _XkbFree(type->preserve);
+ type->preserve= NULL;
+ }
+ type->map_count= map_count;
+ }
+
+ if ((new_num_lvls>type->num_levels)||(type->level_names==NULL)) {
+ Atom * prev_level_names = type->level_names;
+
+ type->level_names=_XkbTypedRealloc(type->level_names,new_num_lvls,Atom);
+ if (!type->level_names) {
+ if (prev_level_names)
+ _XkbFree(prev_level_names);
+ return BadAlloc;
+ }
+ }
+ /*
+ * Here's the theory:
+ * If the width of the type changed, we might have to resize the symbol
+ * maps for any keys that use the type for one or more groups. This is
+ * expensive, so we'll try to cull out any keys that are obviously okay:
+ * In any case:
+ * - keys that have a group width <= the old width are okay (because
+ * they could not possibly have been associated with the old type)
+ * If the key type increased in size:
+ * - keys that already have a group width >= to the new width are okay
+ * + keys that have a group width >= the old width but < the new width
+ * might have to be enlarged.
+ * If the key type decreased in size:
+ * - keys that have a group width > the old width don't have to be
+ * resized (because they must have some other wider type associated
+ * with some group).
+ * + keys that have a group width == the old width might have to be
+ * shrunk.
+ * The possibilities marked with '+' require us to examine the key types
+ * associated with each group for the key.
+ */
+ bzero(matchingKeys,XkbMaxKeyCount*sizeof(KeyCode));
+ nMatchingKeys= 0;
+ if (new_num_lvls>type->num_levels) {
+ int nTotal;
+ KeySym * newSyms;
+ int width,match,nResize;
+ register int i,g,nSyms;
+
+ nResize= 0;
+ for (nTotal=1,i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
+ width= XkbKeyGroupsWidth(xkb,i);
+ if (width<type->num_levels)
+ continue;
+ for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) {
+ if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) {
+ matchingKeys[nMatchingKeys++]= i;
+ match= 1;
+ }
+ }
+ if ((!match)||(width>=new_num_lvls))
+ nTotal+= XkbKeyNumSyms(xkb,i);
+ else {
+ nTotal+= XkbKeyNumGroups(xkb,i)*new_num_lvls;
+ nResize++;
+ }
+ }
+ if (nResize>0) {
+ int nextMatch;
+ xkb->map->size_syms= (nTotal*12)/10;
+ newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym);
+ if (newSyms==NULL)
+ return BadAlloc;
+ nextMatch= 0;
+ nSyms= 1;
+ for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
+ if (matchingKeys[nextMatch]==i) {
+ KeySym *pOld;
+ nextMatch++;
+ width= XkbKeyGroupsWidth(xkb,i);
+ pOld= XkbKeySymsPtr(xkb,i);
+ for (g=XkbKeyNumGroups(xkb,i)-1;g>=0;g--) {
+ memcpy(&newSyms[nSyms+(new_num_lvls*g)],&pOld[width*g],
+ width*sizeof(KeySym));
+ }
+ xkb->map->key_sym_map[i].offset= nSyms;
+ nSyms+= XkbKeyNumGroups(xkb,i)*new_num_lvls;
+ }
+ else {
+ memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),
+ XkbKeyNumSyms(xkb,i)*sizeof(KeySym));
+ xkb->map->key_sym_map[i].offset= nSyms;
+ nSyms+= XkbKeyNumSyms(xkb,i);
+ }
+ }
+ type->num_levels= new_num_lvls;
+ _XkbFree(xkb->map->syms);
+ xkb->map->syms= newSyms;
+ xkb->map->num_syms= nSyms;
+ return Success;
+ }
+ }
+ else if (new_num_lvls<type->num_levels) {
+ int width,match;
+ register int g,i;
+ for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
+ width= XkbKeyGroupsWidth(xkb,i);
+ if (width<type->num_levels)
+ continue;
+ for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) {
+ if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) {
+ matchingKeys[nMatchingKeys++]= i;
+ match= 1;
+ }
+ }
+ }
+ }
+ if (nMatchingKeys>0) {
+ int key,firstClear;
+ register int i,g;
+ if (new_num_lvls>type->num_levels)
+ firstClear= type->num_levels;
+ else firstClear= new_num_lvls;
+ for (i=0;i<nMatchingKeys;i++) {
+ KeySym * pSyms;
+ int width,nClear;
+
+ key= matchingKeys[i];
+ width= XkbKeyGroupsWidth(xkb,key);
+ nClear= width-firstClear;
+ pSyms= XkbKeySymsPtr(xkb,key);
+ for (g=XkbKeyNumGroups(xkb,key)-1;g>=0;g--) {
+ if (XkbKeyKeyTypeIndex(xkb,key,g)==type_ndx) {
+ if (nClear>0)
+ bzero(&pSyms[g*width+firstClear],nClear*sizeof(KeySym));
+ }
+ }
+ }
+ }
+ type->num_levels= new_num_lvls;
+ return Success;
+}
+
+KeySym *
+XkbResizeKeySyms(XkbDescPtr xkb,int key,int needed)
+{
+register int i,nSyms,nKeySyms;
+unsigned nOldSyms;
+KeySym *newSyms;
+
+ if (needed==0) {
+ xkb->map->key_sym_map[key].offset= 0;
+ return xkb->map->syms;
+ }
+ nOldSyms= XkbKeyNumSyms(xkb,key);
+ if (nOldSyms>=(unsigned)needed) {
+ return XkbKeySymsPtr(xkb,key);
+ }
+ if (xkb->map->size_syms-xkb->map->num_syms>=(unsigned)needed) {
+ if (nOldSyms>0) {
+ memcpy(&xkb->map->syms[xkb->map->num_syms],XkbKeySymsPtr(xkb,key),
+ nOldSyms*sizeof(KeySym));
+ }
+ if ((needed-nOldSyms)>0) {
+ bzero(&xkb->map->syms[xkb->map->num_syms+XkbKeyNumSyms(xkb,key)],
+ (needed-nOldSyms)*sizeof(KeySym));
+ }
+ xkb->map->key_sym_map[key].offset = xkb->map->num_syms;
+ xkb->map->num_syms+= needed;
+ return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
+ }
+ xkb->map->size_syms+= (needed>32?needed:32);
+ newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym);
+ if (newSyms==NULL)
+ return NULL;
+ newSyms[0]= NoSymbol;
+ nSyms = 1;
+ for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) {
+ int nCopy;
+
+ nCopy= nKeySyms= XkbKeyNumSyms(xkb,i);
+ if ((nKeySyms==0)&&(i!=key))
+ continue;
+ if (i==key)
+ nKeySyms= needed;
+ if (nCopy!=0)
+ memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),nCopy*sizeof(KeySym));
+ if (nKeySyms>nCopy)
+ bzero(&newSyms[nSyms+nCopy],(nKeySyms-nCopy)*sizeof(KeySym));
+ xkb->map->key_sym_map[i].offset = nSyms;
+ nSyms+= nKeySyms;
+ }
+ _XkbFree(xkb->map->syms);
+ xkb->map->syms = newSyms;
+ xkb->map->num_syms = nSyms;
+ return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
+}
+
+static unsigned
+_ExtendRange( unsigned int old_flags,
+ unsigned int flag,
+ KeyCode newKC,
+ KeyCode * old_min,
+ unsigned char * old_num)
+{
+ if ((old_flags&flag)==0) {
+ old_flags|= flag;
+ *old_min= newKC;
+ *old_num= 1;
+ }
+ else {
+ int last= (*old_min)+(*old_num)-1;
+ if (newKC<*old_min) {
+ *old_min= newKC;
+ *old_num= (last-newKC)+1;
+ }
+ else if (newKC>last) {
+ *old_num= (newKC-(*old_min))+1;
+ }
+ }
+ return old_flags;
+}
+
+Status
+XkbChangeKeycodeRange( XkbDescPtr xkb,
+ int minKC,
+ int maxKC,
+ XkbChangesPtr changes)
+{
+int tmp;
+
+ if ((!xkb)||(minKC<XkbMinLegalKeyCode)||(maxKC>XkbMaxLegalKeyCode))
+ return BadValue;
+ if (minKC>maxKC)
+ return BadMatch;
+ if (minKC<xkb->min_key_code) {
+ if (changes)
+ changes->map.min_key_code= minKC;
+ tmp= xkb->min_key_code-minKC;
+ if (xkb->map) {
+ if (xkb->map->key_sym_map) {
+ bzero((char *)&xkb->map->key_sym_map[minKC],
+ tmp*sizeof(XkbSymMapRec));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbKeySymsMask,minKC,
+ &changes->map.first_key_sym,
+ &changes->map.num_key_syms);
+ }
+ }
+ if (xkb->map->modmap) {
+ bzero((char *)&xkb->map->modmap[minKC],tmp);
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbModifierMapMask,minKC,
+ &changes->map.first_modmap_key,
+ &changes->map.num_modmap_keys);
+ }
+ }
+ }
+ if (xkb->server) {
+ if (xkb->server->behaviors) {
+ bzero((char *)&xkb->server->behaviors[minKC],
+ tmp*sizeof(XkbBehavior));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbKeyBehaviorsMask,minKC,
+ &changes->map.first_key_behavior,
+ &changes->map.num_key_behaviors);
+ }
+ }
+ if (xkb->server->key_acts) {
+ bzero((char *)&xkb->server->key_acts[minKC],
+ tmp*sizeof(unsigned short));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbKeyActionsMask,minKC,
+ &changes->map.first_key_act,
+ &changes->map.num_key_acts);
+ }
+ }
+ if (xkb->server->vmodmap) {
+ bzero((char *)&xkb->server->vmodmap[minKC],
+ tmp*sizeof(unsigned short));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbVirtualModMapMask,minKC,
+ &changes->map.first_modmap_key,
+ &changes->map.num_vmodmap_keys);
+ }
+ }
+ }
+ if ((xkb->names)&&(xkb->names->keys)) {
+ bzero((char *)&xkb->names->keys[minKC],tmp*sizeof(XkbKeyNameRec));
+ if (changes) {
+ changes->names.changed= _ExtendRange(changes->names.changed,
+ XkbKeyNamesMask,minKC,
+ &changes->names.first_key,
+ &changes->names.num_keys);
+ }
+ }
+ xkb->min_key_code= minKC;
+ }
+ if (maxKC>xkb->max_key_code) {
+ if (changes)
+ changes->map.max_key_code= maxKC;
+ tmp= maxKC-xkb->max_key_code;
+ if (xkb->map) {
+ if (xkb->map->key_sym_map) {
+ XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map;
+
+ xkb->map->key_sym_map= _XkbTypedRealloc(xkb->map->key_sym_map,
+ (maxKC+1),XkbSymMapRec);
+ if (!xkb->map->key_sym_map) {
+ _XkbFree(prev_key_sym_map);
+ return BadAlloc;
+ }
+ bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code],
+ tmp*sizeof(XkbSymMapRec));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbKeySymsMask,maxKC,
+ &changes->map.first_key_sym,
+ &changes->map.num_key_syms);
+ }
+ }
+ if (xkb->map->modmap) {
+ unsigned char *prev_modmap = xkb->map->modmap;
+
+ xkb->map->modmap= _XkbTypedRealloc(xkb->map->modmap,
+ (maxKC+1),unsigned char);
+ if (!xkb->map->modmap) {
+ _XkbFree(prev_modmap);
+ return BadAlloc;
+ }
+ bzero((char *)&xkb->map->modmap[xkb->max_key_code],tmp);
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbModifierMapMask,maxKC,
+ &changes->map.first_modmap_key,
+ &changes->map.num_modmap_keys);
+ }
+ }
+ }
+ if (xkb->server) {
+ if (xkb->server->behaviors) {
+ XkbBehavior *prev_behaviors = xkb->server->behaviors;
+
+ xkb->server->behaviors=_XkbTypedRealloc(xkb->server->behaviors,
+ (maxKC+1),XkbBehavior);
+ if (!xkb->server->behaviors) {
+ _XkbFree(prev_behaviors);
+ return BadAlloc;
+ }
+ bzero((char *)&xkb->server->behaviors[xkb->max_key_code],
+ tmp*sizeof(XkbBehavior));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbKeyBehaviorsMask,maxKC,
+ &changes->map.first_key_behavior,
+ &changes->map.num_key_behaviors);
+ }
+ }
+ if (xkb->server->key_acts) {
+ unsigned short *prev_key_acts = xkb->server->key_acts;
+
+ xkb->server->key_acts= _XkbTypedRealloc(xkb->server->key_acts,
+ (maxKC+1),unsigned short);
+ if (!xkb->server->key_acts) {
+ _XkbFree(prev_key_acts);
+ return BadAlloc;
+ }
+ bzero((char *)&xkb->server->key_acts[xkb->max_key_code],
+ tmp*sizeof(unsigned short));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbKeyActionsMask,maxKC,
+ &changes->map.first_key_act,
+ &changes->map.num_key_acts);
+ }
+ }
+ if (xkb->server->vmodmap) {
+ unsigned short *prev_vmodmap = xkb->server->vmodmap;
+
+ xkb->server->vmodmap= _XkbTypedRealloc(xkb->server->vmodmap,
+ (maxKC+1),unsigned short);
+ if (!xkb->server->vmodmap) {
+ _XkbFree(prev_vmodmap);
+ return BadAlloc;
+ }
+ bzero((char *)&xkb->server->vmodmap[xkb->max_key_code],
+ tmp*sizeof(unsigned short));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbVirtualModMapMask,maxKC,
+ &changes->map.first_modmap_key,
+ &changes->map.num_vmodmap_keys);
+ }
+ }
+ }
+ if ((xkb->names)&&(xkb->names->keys)) {
+ XkbKeyNameRec *prev_keys = xkb->names->keys;
+
+ xkb->names->keys= _XkbTypedRealloc(xkb->names->keys,
+ (maxKC+1),XkbKeyNameRec);
+ if (!xkb->names->keys) {
+ _XkbFree(prev_keys);
+ return BadAlloc;
+ }
+ bzero((char *)&xkb->names->keys[xkb->max_key_code],
+ tmp*sizeof(XkbKeyNameRec));
+ if (changes) {
+ changes->names.changed= _ExtendRange(changes->names.changed,
+ XkbKeyNamesMask,maxKC,
+ &changes->names.first_key,
+ &changes->names.num_keys);
+ }
+ }
+ xkb->max_key_code= maxKC;
+ }
+ return Success;
+}
+
+XkbAction *
+XkbResizeKeyActions(XkbDescPtr xkb,int key,int needed)
+{
+register int i,nActs;
+XkbAction *newActs;
+
+ if (needed==0) {
+ xkb->server->key_acts[key]= 0;
+ return NULL;
+ }
+ if (XkbKeyHasActions(xkb,key)&&(XkbKeyNumSyms(xkb,key)>=(unsigned)needed))
+ return XkbKeyActionsPtr(xkb,key);
+ if (xkb->server->size_acts-xkb->server->num_acts>=(unsigned)needed) {
+ xkb->server->key_acts[key]= xkb->server->num_acts;
+ xkb->server->num_acts+= needed;
+ return &xkb->server->acts[xkb->server->key_acts[key]];
+ }
+ xkb->server->size_acts= xkb->server->num_acts+needed+8;
+ newActs = _XkbTypedCalloc(xkb->server->size_acts,XkbAction);
+ if (newActs==NULL)
+ return NULL;
+ newActs[0].type = XkbSA_NoAction;
+ nActs = 1;
+ for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) {
+ int nKeyActs,nCopy;
+
+ if ((xkb->server->key_acts[i]==0)&&(i!=key))
+ continue;
+
+ nCopy= nKeyActs= XkbKeyNumActions(xkb,i);
+ if (i==key) {
+ nKeyActs= needed;
+ if (needed<nCopy)
+ nCopy= needed;
+ }
+
+ if (nCopy>0)
+ memcpy(&newActs[nActs],XkbKeyActionsPtr(xkb,i),
+ nCopy*sizeof(XkbAction));
+ if (nCopy<nKeyActs)
+ bzero(&newActs[nActs+nCopy],(nKeyActs-nCopy)*sizeof(XkbAction));
+ xkb->server->key_acts[i]= nActs;
+ nActs+= nKeyActs;
+ }
+ _XkbFree(xkb->server->acts);
+ xkb->server->acts = newActs;
+ xkb->server->num_acts= nActs;
+ return &xkb->server->acts[xkb->server->key_acts[key]];
+}
+
+void
+XkbFreeClientMap(XkbDescPtr xkb,unsigned what,Bool freeMap)
+{
+XkbClientMapPtr map;
+
+ if ((xkb==NULL)||(xkb->map==NULL))
+ return;
+ if (freeMap)
+ what= XkbAllClientInfoMask;
+ map= xkb->map;
+ if (what&XkbKeyTypesMask) {
+ if (map->types!=NULL) {
+ if (map->num_types>0) {
+ register int i;
+ XkbKeyTypePtr type;
+ for (i=0,type=map->types;i<map->num_types;i++,type++) {
+ if (type->map!=NULL) {
+ _XkbFree(type->map);
+ type->map= NULL;
+ }
+ if (type->preserve!=NULL) {
+ _XkbFree(type->preserve);
+ type->preserve= NULL;
+ }
+ type->map_count= 0;
+ if (type->level_names!=NULL) {
+ _XkbFree(type->level_names);
+ type->level_names= NULL;
+ }
+ }
+ }
+ _XkbFree(map->types);
+ map->num_types= map->size_types= 0;
+ map->types= NULL;
+ }
+ }
+ if (what&XkbKeySymsMask) {
+ if (map->key_sym_map!=NULL) {
+ _XkbFree(map->key_sym_map);
+ map->key_sym_map= NULL;
+ }
+ if (map->syms!=NULL) {
+ _XkbFree(map->syms);
+ map->size_syms= map->num_syms= 0;
+ map->syms= NULL;
+ }
+ }
+ if ((what&XkbModifierMapMask)&&(map->modmap!=NULL)) {
+ _XkbFree(map->modmap);
+ map->modmap= NULL;
+ }
+ if (freeMap) {
+ _XkbFree(xkb->map);
+ xkb->map= NULL;
+ }
+ return;
+}
+
+void
+XkbFreeServerMap(XkbDescPtr xkb,unsigned what,Bool freeMap)
+{
+XkbServerMapPtr map;
+
+ if ((xkb==NULL)||(xkb->server==NULL))
+ return;
+ if (freeMap)
+ what= XkbAllServerInfoMask;
+ map= xkb->server;
+ if ((what&XkbExplicitComponentsMask)&&(map->explicit!=NULL)) {
+ _XkbFree(map->explicit);
+ map->explicit= NULL;
+ }
+ if (what&XkbKeyActionsMask) {
+ if (map->key_acts!=NULL) {
+ _XkbFree(map->key_acts);
+ map->key_acts= NULL;
+ }
+ if (map->acts!=NULL) {
+ _XkbFree(map->acts);
+ map->num_acts= map->size_acts= 0;
+ map->acts= NULL;
+ }
+ }
+ if ((what&XkbKeyBehaviorsMask)&&(map->behaviors!=NULL)) {
+ _XkbFree(map->behaviors);
+ map->behaviors= NULL;
+ }
+ if ((what&XkbVirtualModMapMask)&&(map->vmodmap!=NULL)) {
+ _XkbFree(map->vmodmap);
+ map->vmodmap= NULL;
+ }
+
+ if (freeMap) {
+ _XkbFree(xkb->server);
+ xkb->server= NULL;
+ }
+ return;
+}
diff --git a/libX11/src/xkb/XKBMisc.c b/libX11/src/xkb/XKBMisc.c
index 33bc2ccb7..f736d1851 100644
--- a/libX11/src/xkb/XKBMisc.c
+++ b/libX11/src/xkb/XKBMisc.c
@@ -1,983 +1,979 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_DIX_CONFIG_H
-#include <dix-config.h>
-#elif defined(HAVE_CONFIG_H)
-#include <config.h>
-#endif
-
-#ifndef XKB_IN_SERVER
-
-#include <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include <X11/keysym.h>
-#include "XKBlibint.h"
-
-#else
-
-#include <stdio.h>
-#include <X11/X.h>
-#define NEED_EVENTS
-#define NEED_REPLIES
-#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "inputstr.h"
-#include <X11/keysym.h>
-#define XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
-
-#endif /* XKB_IN_SERVER */
-
-/***====================================================================***/
-
-#define mapSize(m) (sizeof(m)/sizeof(XkbKTMapEntryRec))
-static XkbKTMapEntryRec map2Level[]= {
- { True, ShiftMask, {1, ShiftMask, 0} }
-};
-
-static XkbKTMapEntryRec mapAlpha[]= {
- { True, ShiftMask, { 1, ShiftMask, 0 } },
- { True, LockMask, { 0, LockMask, 0 } }
-};
-
-static XkbModsRec preAlpha[]= {
- { 0, 0, 0 },
- { LockMask, LockMask, 0 }
-};
-
-#define NL_VMOD_MASK 0
-static XkbKTMapEntryRec mapKeypad[]= {
- { True, ShiftMask, { 1, ShiftMask, 0 } },
- { False, 0, { 1, 0, NL_VMOD_MASK } }
-};
-
-static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = {
- { { 0, 0, 0 },
- 1, /* num_levels */
- 0, /* map_count */
- NULL, NULL,
- None, NULL
- },
- { { ShiftMask, ShiftMask, 0 },
- 2, /* num_levels */
- mapSize(map2Level), /* map_count */
- map2Level, NULL,
- None, NULL
- },
- { { ShiftMask|LockMask, ShiftMask|LockMask, 0 },
- 2, /* num_levels */
- mapSize(mapAlpha), /* map_count */
- mapAlpha, preAlpha,
- None, NULL
- },
- { { ShiftMask, ShiftMask, NL_VMOD_MASK },
- 2, /* num_levels */
- mapSize(mapKeypad), /* map_count */
- mapKeypad, NULL,
- None, NULL
- }
-};
-
-Status
-XkbInitCanonicalKeyTypes(XkbDescPtr xkb,unsigned which,int keypadVMod)
-{
-XkbClientMapPtr map;
-XkbKeyTypePtr from,to;
-Status rtrn;
-
- if (!xkb)
- return BadMatch;
- rtrn= XkbAllocClientMap(xkb,XkbKeyTypesMask,XkbNumRequiredTypes);
- if (rtrn!=Success)
- return rtrn;
- map= xkb->map;
- if ((which&XkbAllRequiredTypes)==0)
- return Success;
- rtrn= Success;
- from= canonicalTypes;
- to= map->types;
- if (which&XkbOneLevelMask)
- rtrn= XkbCopyKeyType(&from[XkbOneLevelIndex],&to[XkbOneLevelIndex]);
- if ((which&XkbTwoLevelMask)&&(rtrn==Success))
- rtrn= XkbCopyKeyType(&from[XkbTwoLevelIndex],&to[XkbTwoLevelIndex]);
- if ((which&XkbAlphabeticMask)&&(rtrn==Success))
- rtrn= XkbCopyKeyType(&from[XkbAlphabeticIndex],&to[XkbAlphabeticIndex]);
- if ((which&XkbKeypadMask)&&(rtrn==Success)) {
- XkbKeyTypePtr type;
- rtrn= XkbCopyKeyType(&from[XkbKeypadIndex],&to[XkbKeypadIndex]);
- type= &to[XkbKeypadIndex];
- if ((keypadVMod>=0)&&(keypadVMod<XkbNumVirtualMods)&&(rtrn==Success)) {
- type->mods.vmods= (1<<keypadVMod);
- type->map[0].active= True;
- type->map[0].mods.mask= ShiftMask;
- type->map[0].mods.real_mods= ShiftMask;
- type->map[0].mods.vmods= 0;
- type->map[0].level= 1;
- type->map[1].active= False;
- type->map[1].mods.mask= 0;
- type->map[1].mods.real_mods= 0;
- type->map[1].mods.vmods= (1<<keypadVMod);
- type->map[1].level= 1;
- }
- }
- return Success;
-}
-
-/***====================================================================***/
-
-#define CORE_SYM(i) (i<map_width?core_syms[i]:NoSymbol)
-#define XKB_OFFSET(g,l) (((g)*groupsWidth)+(l))
-
-int
-XkbKeyTypesForCoreSymbols( XkbDescPtr xkb,
- int map_width,
- KeySym * core_syms,
- unsigned int protected,
- int * types_inout,
- KeySym * xkb_syms_rtrn)
-{
-register int i;
-unsigned int empty;
-int nSyms[XkbNumKbdGroups];
-int nGroups,tmp,groupsWidth;
-
- /* Section 12.2 of the protocol describes this process in more detail */
- /* Step 1: find the # of symbols in the core mapping per group */
- groupsWidth= 2;
- for (i=0;i<XkbNumKbdGroups;i++) {
- if ((protected&(1<<i))&&(types_inout[i]<xkb->map->num_types)) {
- nSyms[i]= xkb->map->types[types_inout[i]].num_levels;
- if (nSyms[i]>groupsWidth)
- groupsWidth= nSyms[i];
- }
- else {
- types_inout[i]= XkbTwoLevelIndex; /* don't really know, yet */
- nSyms[i]= 2;
- }
- }
- if (nSyms[XkbGroup1Index]<2)
- nSyms[XkbGroup1Index]= 2;
- if (nSyms[XkbGroup2Index]<2)
- nSyms[XkbGroup2Index]= 2;
- /* Step 2: Copy the symbols from the core ordering to XKB ordering */
- /* symbols in the core are in the order: */
- /* G1L1 G1L2 G2L1 G2L2 [G1L[3-n]] [G2L[3-n]] [G3L*] [G3L*] */
- xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,0)]= CORE_SYM(0);
- xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,1)]= CORE_SYM(1);
- for (i=2;i<nSyms[XkbGroup1Index];i++) {
- xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,i)]= CORE_SYM(2+i);
- }
- xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,0)]= CORE_SYM(2);
- xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,1)]= CORE_SYM(3);
- tmp= 2+(nSyms[XkbGroup1Index]-2); /* offset to extra group2 syms */
- for (i=2;i<nSyms[XkbGroup2Index];i++) {
- xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,i)]= CORE_SYM(tmp+i);
- }
- tmp= nSyms[XkbGroup1Index]+nSyms[XkbGroup2Index];
- if ((tmp>=map_width)&&
- ((protected&(XkbExplicitKeyType3Mask|XkbExplicitKeyType4Mask))==0)) {
- nSyms[XkbGroup3Index]= 0;
- nSyms[XkbGroup4Index]= 0;
- nGroups= 2;
- }
- else {
- nGroups= 3;
- for (i=0;i<nSyms[XkbGroup3Index];i++,tmp++) {
- xkb_syms_rtrn[XKB_OFFSET(XkbGroup3Index,i)]= CORE_SYM(tmp);
- }
- if ((tmp<map_width)||(protected&XkbExplicitKeyType4Mask)) {
- nGroups= 4;
- for (i=0;i<nSyms[XkbGroup4Index];i++,tmp++) {
- xkb_syms_rtrn[XKB_OFFSET(XkbGroup4Index,i)]= CORE_SYM(tmp);
- }
- }
- else {
- nSyms[XkbGroup4Index]= 0;
- }
- }
- /* steps 3&4: alphanumeric expansion, assign canonical types */
- empty= 0;
- for (i=0;i<nGroups;i++) {
- KeySym *syms;
- syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)];
- if ((nSyms[i]>1)&&(syms[1]==NoSymbol)&&(syms[0]!=NoSymbol)) {
- KeySym upper,lower;
- XConvertCase(syms[0],&lower,&upper);
- if (upper!=lower) {
- xkb_syms_rtrn[XKB_OFFSET(i,0)]= lower;
- xkb_syms_rtrn[XKB_OFFSET(i,1)]= upper;
- if ((protected&(1<<i))==0)
- types_inout[i]= XkbAlphabeticIndex;
- }
- else if ((protected&(1<<i))==0) {
- types_inout[i]= XkbOneLevelIndex;
- /* nSyms[i]= 1;*/
- }
- }
- if (((protected&(1<<i))==0)&&(types_inout[i]==XkbTwoLevelIndex)) {
- if (IsKeypadKey(syms[0])||IsKeypadKey(syms[1]))
- types_inout[i]= XkbKeypadIndex;
- else {
- KeySym upper,lower;
- XConvertCase(syms[0],&lower,&upper);
- if ((syms[0]==lower)&&(syms[1]==upper))
- types_inout[i]= XkbAlphabeticIndex;
- }
- }
- if (syms[0]==NoSymbol) {
- register int n;
- Bool found;
- for (n=1,found=False;(!found)&&(n<nSyms[i]);n++) {
- found= (syms[n]!=NoSymbol);
- }
- if (!found)
- empty|= (1<<i);
- }
- }
- /* step 5: squoosh out empty groups */
- if (empty) {
- for (i=nGroups-1;i>=0;i--) {
- if (((empty&(1<<i))==0)||(protected&(1<<i)))
- break;
- nGroups--;
- }
- }
- if (nGroups<1)
- return 0;
-
- /* step 6: replicate group 1 into group two, if necessary */
- if ((nGroups>1)&&((empty&(XkbGroup1Mask|XkbGroup2Mask))==XkbGroup2Mask)) {
- if ((protected&(XkbExplicitKeyType1Mask|XkbExplicitKeyType2Mask))==0) {
- nSyms[XkbGroup2Index]= nSyms[XkbGroup1Index];
- types_inout[XkbGroup2Index]= types_inout[XkbGroup1Index];
- memcpy((char *)&xkb_syms_rtrn[2],(char *)xkb_syms_rtrn,
- 2*sizeof(KeySym));
- }
- else if (types_inout[XkbGroup1Index]==types_inout[XkbGroup2Index]) {
- memcpy((char *)&xkb_syms_rtrn[nSyms[XkbGroup1Index]],
- (char *)xkb_syms_rtrn,
- nSyms[XkbGroup1Index]*sizeof(KeySym));
- }
- }
-
- /* step 7: check for all groups identical or all width 1 */
- if (nGroups>1) {
- Bool sameType,allOneLevel;
- allOneLevel= (xkb->map->types[types_inout[0]].num_levels==1);
- for (i=1,sameType=True;(allOneLevel||sameType)&&(i<nGroups);i++) {
- sameType=(sameType&&(types_inout[i]==types_inout[XkbGroup1Index]));
- if (allOneLevel)
- allOneLevel= (xkb->map->types[types_inout[i]].num_levels==1);
- }
- if ((sameType)&&
- (!(protected&(XkbExplicitKeyTypesMask&~XkbExplicitKeyType1Mask)))){
- register int s;
- Bool identical;
- for (i=1,identical=True;identical&&(i<nGroups);i++) {
- KeySym *syms;
- syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)];
- for (s=0;identical&&(s<nSyms[i]);s++) {
- if (syms[s]!=xkb_syms_rtrn[s])
- identical= False;
- }
- }
- if (identical)
- nGroups= 1;
- }
- if (allOneLevel && (nGroups>1)) {
- KeySym *syms;
- syms= &xkb_syms_rtrn[nSyms[XkbGroup1Index]];
- nSyms[XkbGroup1Index]= 1;
- for (i=1;i<nGroups;i++) {
- xkb_syms_rtrn[i]= syms[0];
- syms+= nSyms[i];
- nSyms[i]= 1;
- }
- }
- }
- return nGroups;
-}
-
-static XkbSymInterpretPtr
-_XkbFindMatchingInterp( XkbDescPtr xkb,
- KeySym sym,
- unsigned int real_mods,
- unsigned int level)
-{
-register unsigned i;
-XkbSymInterpretPtr interp,rtrn;
-CARD8 mods;
-
- rtrn= NULL;
- interp= xkb->compat->sym_interpret;
- for (i=0;i<xkb->compat->num_si;i++,interp++) {
- if ((interp->sym==NoSymbol)||(sym==interp->sym)) {
- int match;
- if ((level==0)||((interp->match&XkbSI_LevelOneOnly)==0))
- mods= real_mods;
- else mods= 0;
- switch (interp->match&XkbSI_OpMask) {
- case XkbSI_NoneOf:
- match= ((interp->mods&mods)==0);
- break;
- case XkbSI_AnyOfOrNone:
- match= ((mods==0)||((interp->mods&mods)!=0));
- break;
- case XkbSI_AnyOf:
- match= ((interp->mods&mods)!=0);
- break;
- case XkbSI_AllOf:
- match= ((interp->mods&mods)==interp->mods);
- break;
- case XkbSI_Exactly:
- match= (interp->mods==mods);
- break;
- default:
- match= 0;
- break;
- }
- if (match) {
- if (interp->sym!=NoSymbol) {
- return interp;
- }
- else if (rtrn==NULL) {
- rtrn= interp;
- }
- }
- }
- }
- return rtrn;
-}
-
-static void
-_XkbAddKeyChange(KeyCode *pFirst,unsigned char *pNum,KeyCode newKey)
-{
-KeyCode last;
-
- last= (*pFirst)+(*pNum);
- if (newKey<*pFirst) {
- *pFirst= newKey;
- *pNum= (last-newKey)+1;
- }
- else if (newKey>last) {
- *pNum= (last-*pFirst)+1;
- }
- return;
-}
-
-static void
-_XkbSetActionKeyMods(XkbDescPtr xkb,XkbAction *act,unsigned mods)
-{
-unsigned tmp;
-
- switch (act->type) {
- case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods:
- if (act->mods.flags&XkbSA_UseModMapMods)
- act->mods.real_mods= act->mods.mask= mods;
- if ((tmp= XkbModActionVMods(&act->mods))!=0) {
- XkbVirtualModsToReal(xkb,tmp,&tmp);
- act->mods.mask|= tmp;
- }
- break;
- case XkbSA_ISOLock:
- if (act->iso.flags&XkbSA_UseModMapMods)
- act->iso.real_mods= act->iso.mask= mods;
- if ((tmp= XkbModActionVMods(&act->iso))!=0) {
- XkbVirtualModsToReal(xkb,tmp,&tmp);
- act->iso.mask|= tmp;
- }
- break;
- }
- return;
-}
-
-#define IBUF_SIZE 8
-
-Bool
-XkbApplyCompatMapToKey(XkbDescPtr xkb,KeyCode key,XkbChangesPtr changes)
-{
-KeySym * syms;
-unsigned char explicit,mods;
-XkbSymInterpretPtr *interps,ibuf[IBUF_SIZE];
-int n,nSyms,found;
-unsigned changed,tmp;
-
- if ((!xkb)||(!xkb->map)||(!xkb->map->key_sym_map)||
- (!xkb->compat)||(!xkb->compat->sym_interpret)||
- (key<xkb->min_key_code)||(key>xkb->max_key_code)) {
- return False;
- }
- if (((!xkb->server)||(!xkb->server->key_acts))&&
- (XkbAllocServerMap(xkb,XkbAllServerInfoMask,0)!=Success)) {
- return False;
- }
- changed= 0; /* keeps track of what has changed in _this_ call */
- explicit= xkb->server->explicit[key];
- if (explicit&XkbExplicitInterpretMask) /* nothing to do */
- return True;
- mods= (xkb->map->modmap?xkb->map->modmap[key]:0);
- nSyms= XkbKeyNumSyms(xkb,key);
- syms= XkbKeySymsPtr(xkb,key);
- if (nSyms>IBUF_SIZE) {
- interps= _XkbTypedCalloc(nSyms,XkbSymInterpretPtr);
- if (interps==NULL) {
- interps= ibuf;
- nSyms= IBUF_SIZE;
- }
- }
- else {
- interps= ibuf;
- }
- found= 0;
- for (n=0;n<nSyms;n++) {
- unsigned level= (n%XkbKeyGroupsWidth(xkb,key));
- interps[n]= NULL;
- if (syms[n]!=NoSymbol) {
- interps[n]= _XkbFindMatchingInterp(xkb,syms[n],mods,level);
- if (interps[n]&&interps[n]->act.type!=XkbSA_NoAction)
- found++;
- else interps[n]= NULL;
- }
- }
- /* 1/28/96 (ef) -- XXX! WORKING HERE */
- if (!found) {
- if (xkb->server->key_acts[key]!=0) {
- xkb->server->key_acts[key]= 0;
- changed|= XkbKeyActionsMask;
- }
- }
- else {
- XkbAction *pActs;
- unsigned int new_vmodmask;
- changed|= XkbKeyActionsMask;
- pActs= XkbResizeKeyActions(xkb,key,nSyms);
- if (!pActs) {
- if (nSyms > IBUF_SIZE)
- Xfree(interps);
- return False;
- }
- new_vmodmask= 0;
- for (n=0;n<nSyms;n++) {
- if (interps[n]) {
- unsigned effMods;
-
- pActs[n]= *((XkbAction *)&interps[n]->act);
- if ((n==0)||((interps[n]->match&XkbSI_LevelOneOnly)==0)) {
- effMods= mods;
- if (interps[n]->virtual_mod!=XkbNoModifier)
- new_vmodmask|= (1<<interps[n]->virtual_mod);
- }
- else effMods= 0;
- _XkbSetActionKeyMods(xkb,&pActs[n],effMods);
- }
- else pActs[n].type= XkbSA_NoAction;
- }
- if (((explicit&XkbExplicitVModMapMask)==0)&&
- (xkb->server->vmodmap[key]!=new_vmodmask)) {
- changed|= XkbVirtualModMapMask;
- xkb->server->vmodmap[key]= new_vmodmask;
- }
- if (interps[0]) {
- if ((interps[0]->flags&XkbSI_LockingKey)&&
- ((explicit&XkbExplicitBehaviorMask)==0)) {
- xkb->server->behaviors[key].type= XkbKB_Lock;
- changed|= XkbKeyBehaviorsMask;
- }
- if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) {
- CARD8 old;
- old= xkb->ctrls->per_key_repeat[key/8];
- if (interps[0]->flags&XkbSI_AutoRepeat)
- xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8));
- else xkb->ctrls->per_key_repeat[key/8]&= ~(1<<(key%8));
- if (changes && (old!=xkb->ctrls->per_key_repeat[key/8]))
- changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask;
- }
- }
- }
- if ((!found)||(interps[0]==NULL)) {
- if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) {
- CARD8 old;
- old= xkb->ctrls->per_key_repeat[key/8];
-#ifdef RETURN_SHOULD_REPEAT
- if (*XkbKeySymsPtr(xkb,key) != XK_Return)
-#endif
- xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8));
- if (changes && (old!=xkb->ctrls->per_key_repeat[key/8]))
- changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask;
- }
- if (((explicit&XkbExplicitBehaviorMask)==0)&&
- (xkb->server->behaviors[key].type==XkbKB_Lock)) {
- xkb->server->behaviors[key].type= XkbKB_Default;
- changed|= XkbKeyBehaviorsMask;
- }
- }
- if (changes) {
- XkbMapChangesPtr mc;
- mc= &changes->map;
- tmp= (changed&mc->changed);
- if (tmp&XkbKeyActionsMask)
- _XkbAddKeyChange(&mc->first_key_act,&mc->num_key_acts,key);
- else if (changed&XkbKeyActionsMask) {
- mc->changed|= XkbKeyActionsMask;
- mc->first_key_act= key;
- mc->num_key_acts= 1;
- }
- if (tmp&XkbKeyBehaviorsMask) {
- _XkbAddKeyChange(&mc->first_key_behavior,&mc->num_key_behaviors,
- key);
- }
- else if (changed&XkbKeyBehaviorsMask) {
- mc->changed|= XkbKeyBehaviorsMask;
- mc->first_key_behavior= key;
- mc->num_key_behaviors= 1;
- }
- if (tmp&XkbVirtualModMapMask)
- _XkbAddKeyChange(&mc->first_vmodmap_key,&mc->num_vmodmap_keys,key);
- else if (changed&XkbVirtualModMapMask) {
- mc->changed|= XkbVirtualModMapMask;
- mc->first_vmodmap_key= key;
- mc->num_vmodmap_keys= 1;
- }
- mc->changed|= changed;
- }
- if (interps!=ibuf)
- _XkbFree(interps);
- return True;
-}
-
-Bool
-XkbUpdateMapFromCore( XkbDescPtr xkb,
- KeyCode first_key,
- int num_keys,
- int map_width,
- KeySym * core_keysyms,
- XkbChangesPtr changes)
-{
-register int key,last_key;
-KeySym * syms;
-
- syms= &core_keysyms[(first_key-xkb->min_key_code)*map_width];
- if (changes) {
- if (changes->map.changed&XkbKeySymsMask) {
- _XkbAddKeyChange(&changes->map.first_key_sym,
- &changes->map.num_key_syms,first_key);
- if (num_keys>1) {
- _XkbAddKeyChange(&changes->map.first_key_sym,
- &changes->map.num_key_syms,
- first_key+num_keys-1);
- }
- }
- else {
- changes->map.changed|= XkbKeySymsMask;
- changes->map.first_key_sym= first_key;
- changes->map.num_key_syms= num_keys;
- }
- }
- last_key= first_key+num_keys-1;
- for (key=first_key;key<=last_key;key++,syms+= map_width) {
- XkbMapChangesPtr mc;
- unsigned explicit;
- KeySym tsyms[XkbMaxSymsPerKey];
- int types[XkbNumKbdGroups];
- int nG;
-
- explicit= xkb->server->explicit[key]&XkbExplicitKeyTypesMask;
- types[XkbGroup1Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index);
- types[XkbGroup2Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup2Index);
- types[XkbGroup3Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup3Index);
- types[XkbGroup4Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup4Index);
- nG= XkbKeyTypesForCoreSymbols(xkb,map_width,syms,explicit,types,tsyms);
- if (changes)
- mc= &changes->map;
- else mc= NULL;
- XkbChangeTypesOfKey(xkb,key,nG,XkbAllGroupsMask,types,mc);
- memcpy((char *)XkbKeySymsPtr(xkb,key),(char *)tsyms,
- XkbKeyNumSyms(xkb,key)*sizeof(KeySym));
- XkbApplyCompatMapToKey(xkb,key,changes);
- }
-
- if ((xkb->server->vmods!=NULL)&&(xkb->map->modmap!=NULL)&&(changes)&&
- (changes->map.changed&(XkbVirtualModMapMask|XkbModifierMapMask))) {
- unsigned char newVMods[XkbNumVirtualMods];
- register unsigned bit,i;
- unsigned present;
-
- bzero(newVMods,XkbNumVirtualMods);
- present= 0;
- for (key=xkb->min_key_code;key<=xkb->max_key_code;key++) {
- if (xkb->server->vmodmap[key]==0)
- continue;
- for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
- if (bit&xkb->server->vmodmap[key]) {
- present|= bit;
- newVMods[i]|= xkb->map->modmap[key];
- }
- }
- }
- for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
- if ((bit&present)&&(newVMods[i]!=xkb->server->vmods[i])) {
- changes->map.changed|= XkbVirtualModsMask;
- changes->map.vmods|= bit;
- xkb->server->vmods[i]= newVMods[i];
- }
- }
- }
- if (changes && (changes->map.changed&XkbVirtualModsMask))
- XkbApplyVirtualModChanges(xkb,changes->map.vmods,changes);
- return True;
-}
-
-Status
-XkbChangeTypesOfKey( XkbDescPtr xkb,
- int key,
- int nGroups,
- unsigned groups,
- int * newTypesIn,
- XkbMapChangesPtr changes)
-{
-XkbKeyTypePtr pOldType,pNewType;
-register int i;
-int width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups];
-
- if ((!xkb) || (!XkbKeycodeInRange(xkb,key)) || (!xkb->map) ||
- (!xkb->map->types)||((groups&XkbAllGroupsMask)==0)||
- (nGroups>XkbNumKbdGroups)) {
- return BadMatch;
- }
- if (nGroups==0) {
- for (i=0;i<XkbNumKbdGroups;i++) {
- xkb->map->key_sym_map[key].kt_index[i]= XkbOneLevelIndex;
- }
- i= xkb->map->key_sym_map[key].group_info;
- i= XkbSetNumGroups(i,0);
- xkb->map->key_sym_map[key].group_info= i;
- XkbResizeKeySyms(xkb,key,0);
- return Success;
- }
-
- nOldGroups= XkbKeyNumGroups(xkb,key);
- oldWidth= XkbKeyGroupsWidth(xkb,key);
- for (width=i=0;i<nGroups;i++) {
- if (groups&(1<<i))
- newTypes[i]= newTypesIn[i];
- else if (i<nOldGroups)
- newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,i);
- else if (nOldGroups>0)
- newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index);
- else newTypes[i]= XkbTwoLevelIndex;
- if (newTypes[i]>xkb->map->num_types)
- return BadMatch;
- pNewType= &xkb->map->types[newTypes[i]];
- if (pNewType->num_levels>width)
- width= pNewType->num_levels;
- }
- if ((xkb->ctrls)&&(nGroups>xkb->ctrls->num_groups))
- xkb->ctrls->num_groups= nGroups;
- if ((width!=oldWidth)||(nGroups!=nOldGroups)) {
- KeySym oldSyms[XkbMaxSymsPerKey],*pSyms;
- int nCopy;
-
- if (nOldGroups==0) {
- pSyms= XkbResizeKeySyms(xkb,key,width*nGroups);
- if (pSyms!=NULL) {
- i= xkb->map->key_sym_map[key].group_info;
- i= XkbSetNumGroups(i,nGroups);
- xkb->map->key_sym_map[key].group_info= i;
- xkb->map->key_sym_map[key].width= width;
- for (i=0;i<nGroups;i++) {
- xkb->map->key_sym_map[key].kt_index[i]= newTypes[i];
- }
- return Success;
- }
- return BadAlloc;
- }
- pSyms= XkbKeySymsPtr(xkb,key);
- memcpy(oldSyms,pSyms,XkbKeyNumSyms(xkb,key)*sizeof(KeySym));
- pSyms= XkbResizeKeySyms(xkb,key,width*nGroups);
- if (pSyms==NULL)
- return BadAlloc;
- bzero(pSyms,width*nGroups*sizeof(KeySym));
- for (i=0;(i<nGroups)&&(i<nOldGroups);i++) {
- pOldType= XkbKeyKeyType(xkb,key,i);
- pNewType= &xkb->map->types[newTypes[i]];
- if (pNewType->num_levels>pOldType->num_levels)
- nCopy= pOldType->num_levels;
- else nCopy= pNewType->num_levels;
- memcpy(&pSyms[i*width],&oldSyms[i*oldWidth],nCopy*sizeof(KeySym));
- }
- if (XkbKeyHasActions(xkb,key)) {
- XkbAction oldActs[XkbMaxSymsPerKey],*pActs;
- pActs= XkbKeyActionsPtr(xkb,key);
- memcpy(oldActs,pActs,XkbKeyNumSyms(xkb,key)*sizeof(XkbAction));
- pActs= XkbResizeKeyActions(xkb,key,width*nGroups);
- if (pActs==NULL)
- return BadAlloc;
- bzero(pActs,width*nGroups*sizeof(XkbAction));
- for (i=0;(i<nGroups)&&(i<nOldGroups);i++) {
- pOldType= XkbKeyKeyType(xkb,key,i);
- pNewType= &xkb->map->types[newTypes[i]];
- if (pNewType->num_levels>pOldType->num_levels)
- nCopy= pOldType->num_levels;
- else nCopy= pNewType->num_levels;
- memcpy(&pActs[i*width],&oldActs[i*oldWidth],
- nCopy*sizeof(XkbAction));
- }
- }
- i= xkb->map->key_sym_map[key].group_info;
- i= XkbSetNumGroups(i,nGroups);
- xkb->map->key_sym_map[key].group_info= i;
- xkb->map->key_sym_map[key].width= width;
- }
- width= 0;
- for (i=0;i<nGroups;i++) {
- xkb->map->key_sym_map[key].kt_index[i]= newTypes[i];
- if (xkb->map->types[newTypes[i]].num_levels>width)
- width= xkb->map->types[newTypes[i]].num_levels;
- }
- xkb->map->key_sym_map[key].width= width;
- if (changes!=NULL) {
- if (changes->changed&XkbKeySymsMask) {
- _XkbAddKeyChange(&changes->first_key_sym,&changes->num_key_syms,
- key);
- }
- else {
- changes->changed|= XkbKeySymsMask;
- changes->first_key_sym= key;
- changes->num_key_syms= 1;
- }
- }
- return Success;
-}
-
-/***====================================================================***/
-
-Bool
-XkbVirtualModsToReal(XkbDescPtr xkb,unsigned virtual_mask,unsigned *mask_rtrn)
-{
-register int i,bit;
-register unsigned mask;
-
- if (xkb==NULL)
- return False;
- if (virtual_mask==0) {
- *mask_rtrn= 0;
- return True;
- }
- if (xkb->server==NULL)
- return False;
- for (i=mask=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
- if (virtual_mask&bit)
- mask|= xkb->server->vmods[i];
- }
- *mask_rtrn= mask;
- return True;
-}
-
-/***====================================================================***/
-
-Bool
-XkbUpdateActionVirtualMods(XkbDescPtr xkb,XkbAction *act,unsigned changed)
-{
-unsigned int tmp;
-
- switch (act->type) {
- case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods:
- if (((tmp= XkbModActionVMods(&act->mods))&changed)!=0) {
- XkbVirtualModsToReal(xkb,tmp,&tmp);
- act->mods.mask= act->mods.real_mods;
- act->mods.mask|= tmp;
- return True;
- }
- break;
- case XkbSA_ISOLock:
- if ((((tmp= XkbModActionVMods(&act->iso))!=0)&changed)!=0) {
- XkbVirtualModsToReal(xkb,tmp,&tmp);
- act->iso.mask= act->iso.real_mods;
- act->iso.mask|= tmp;
- return True;
- }
- break;
- }
- return False;
-}
-
-void
-XkbUpdateKeyTypeVirtualMods( XkbDescPtr xkb,
- XkbKeyTypePtr type,
- unsigned int changed,
- XkbChangesPtr changes)
-{
-register unsigned int i;
-unsigned int mask;
-
- XkbVirtualModsToReal(xkb,type->mods.vmods,&mask);
- type->mods.mask= type->mods.real_mods|mask;
- if ((type->map_count>0)&&(type->mods.vmods!=0)) {
- XkbKTMapEntryPtr entry;
- for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
- if (entry->mods.vmods!=0) {
- XkbVirtualModsToReal(xkb,entry->mods.vmods,&mask);
- entry->mods.mask=entry->mods.real_mods|mask;
- /* entry is active if vmods are bound*/
- entry->active= (mask!=0);
- }
- else entry->active= 1;
- }
- }
- if (changes) {
- int type_ndx;
- type_ndx= type-xkb->map->types;
- if ((type_ndx<0)||(type_ndx>xkb->map->num_types))
- return;
- if (changes->map.changed&XkbKeyTypesMask) {
- int last;
- last= changes->map.first_type+changes->map.num_types-1;
- if (type_ndx<changes->map.first_type) {
- changes->map.first_type= type_ndx;
- changes->map.num_types= (last-type_ndx)+1;
- }
- else if (type_ndx>last) {
- changes->map.num_types= (type_ndx-changes->map.first_type)+1;
- }
- }
- else {
- changes->map.changed|= XkbKeyTypesMask;
- changes->map.first_type= type_ndx;
- changes->map.num_types= 1;
- }
- }
- return;
-}
-
-Bool
-XkbApplyVirtualModChanges(XkbDescPtr xkb,unsigned changed,XkbChangesPtr changes)
-{
-register int i;
-unsigned int checkState = 0;
-
- if ((!xkb) || (!xkb->map) || (changed==0))
- return False;
- for (i=0;i<xkb->map->num_types;i++) {
- if (xkb->map->types[i].mods.vmods & changed)
- XkbUpdateKeyTypeVirtualMods(xkb,&xkb->map->types[i],changed,changes);
- }
- if (changed&xkb->ctrls->internal.vmods) {
- unsigned int newMask;
- XkbVirtualModsToReal(xkb,xkb->ctrls->internal.vmods,&newMask);
- newMask|= xkb->ctrls->internal.real_mods;
- if (xkb->ctrls->internal.mask!=newMask) {
- xkb->ctrls->internal.mask= newMask;
- if (changes) {
- changes->ctrls.changed_ctrls|= XkbInternalModsMask;
- checkState= True;
- }
- }
- }
- if (changed&xkb->ctrls->ignore_lock.vmods) {
- unsigned int newMask;
- XkbVirtualModsToReal(xkb,xkb->ctrls->ignore_lock.vmods,&newMask);
- newMask|= xkb->ctrls->ignore_lock.real_mods;
- if (xkb->ctrls->ignore_lock.mask!=newMask) {
- xkb->ctrls->ignore_lock.mask= newMask;
- if (changes) {
- changes->ctrls.changed_ctrls|= XkbIgnoreLockModsMask;
- checkState= True;
- }
- }
- }
- if (xkb->indicators!=NULL) {
- XkbIndicatorMapPtr map;
- map= &xkb->indicators->maps[0];
- for (i=0;i<XkbNumIndicators;i++,map++) {
- if (map->mods.vmods&changed) {
- unsigned int newMask;
- XkbVirtualModsToReal(xkb,map->mods.vmods,&newMask);
- newMask|= map->mods.real_mods;
- if (newMask!=map->mods.mask) {
- map->mods.mask= newMask;
- if (changes) {
- changes->indicators.map_changes|= (1<<i);
- checkState= True;
- }
- }
- }
- }
- }
- if (xkb->compat!=NULL) {
- XkbCompatMapPtr compat;
- compat= xkb->compat;
- for (i=0;i<XkbNumKbdGroups;i++) {
- unsigned int newMask;
- XkbVirtualModsToReal(xkb,compat->groups[i].vmods,&newMask);
- newMask|= compat->groups[i].real_mods;
- if (compat->groups[i].mask!=newMask) {
- compat->groups[i].mask= newMask;
- if (changes) {
- changes->compat.changed_groups|= (1<<i);
- checkState= True;
- }
- }
- }
- }
- if (xkb->map && xkb->server) {
- int highChange = 0, lowChange = -1;
- for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
- if (XkbKeyHasActions(xkb,i)) {
- register XkbAction *pAct;
- register int n;
-
- pAct= XkbKeyActionsPtr(xkb,i);
- for (n=XkbKeyNumActions(xkb,i);n>0;n--,pAct++) {
- if ((pAct->type!=XkbSA_NoAction)&&
- XkbUpdateActionVirtualMods(xkb,pAct,changed)) {
- if (lowChange<0)
- lowChange= i;
- highChange= i;
- }
- }
- }
- }
- if (changes && (lowChange>0)) { /* something changed */
- if (changes->map.changed&XkbKeyActionsMask) {
- int last;
- if (changes->map.first_key_act<lowChange)
- lowChange= changes->map.first_key_act;
- last= changes->map.first_key_act+changes->map.num_key_acts-1;
- if (last>highChange)
- highChange= last;
- }
- changes->map.changed|= XkbKeyActionsMask;
- changes->map.first_key_act= lowChange;
- changes->map.num_key_acts= (highChange-lowChange)+1;
- }
- }
- return checkState;
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_DIX_CONFIG_H
+#include <dix-config.h>
+#elif defined(HAVE_CONFIG_H)
+#include <config.h>
+#endif
+
+#ifndef XKB_IN_SERVER
+
+#include <stdio.h>
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include <X11/keysym.h>
+#include "XKBlibint.h"
+
+#else
+
+#include <stdio.h>
+#include <X11/X.h>
+#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "inputstr.h"
+#include <X11/keysym.h>
+#define XKBSRV_NEED_FILE_FUNCS
+#include <X11/extensions/XKBsrv.h>
+
+#endif /* XKB_IN_SERVER */
+
+/***====================================================================***/
+
+#define mapSize(m) (sizeof(m)/sizeof(XkbKTMapEntryRec))
+static XkbKTMapEntryRec map2Level[]= {
+ { True, ShiftMask, {1, ShiftMask, 0} }
+};
+
+static XkbKTMapEntryRec mapAlpha[]= {
+ { True, ShiftMask, { 1, ShiftMask, 0 } },
+ { True, LockMask, { 0, LockMask, 0 } }
+};
+
+static XkbModsRec preAlpha[]= {
+ { 0, 0, 0 },
+ { LockMask, LockMask, 0 }
+};
+
+#define NL_VMOD_MASK 0
+static XkbKTMapEntryRec mapKeypad[]= {
+ { True, ShiftMask, { 1, ShiftMask, 0 } },
+ { False, 0, { 1, 0, NL_VMOD_MASK } }
+};
+
+static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = {
+ { { 0, 0, 0 },
+ 1, /* num_levels */
+ 0, /* map_count */
+ NULL, NULL,
+ None, NULL
+ },
+ { { ShiftMask, ShiftMask, 0 },
+ 2, /* num_levels */
+ mapSize(map2Level), /* map_count */
+ map2Level, NULL,
+ None, NULL
+ },
+ { { ShiftMask|LockMask, ShiftMask|LockMask, 0 },
+ 2, /* num_levels */
+ mapSize(mapAlpha), /* map_count */
+ mapAlpha, preAlpha,
+ None, NULL
+ },
+ { { ShiftMask, ShiftMask, NL_VMOD_MASK },
+ 2, /* num_levels */
+ mapSize(mapKeypad), /* map_count */
+ mapKeypad, NULL,
+ None, NULL
+ }
+};
+
+Status
+XkbInitCanonicalKeyTypes(XkbDescPtr xkb,unsigned which,int keypadVMod)
+{
+XkbClientMapPtr map;
+XkbKeyTypePtr from,to;
+Status rtrn;
+
+ if (!xkb)
+ return BadMatch;
+ rtrn= XkbAllocClientMap(xkb,XkbKeyTypesMask,XkbNumRequiredTypes);
+ if (rtrn!=Success)
+ return rtrn;
+ map= xkb->map;
+ if ((which&XkbAllRequiredTypes)==0)
+ return Success;
+ rtrn= Success;
+ from= canonicalTypes;
+ to= map->types;
+ if (which&XkbOneLevelMask)
+ rtrn= XkbCopyKeyType(&from[XkbOneLevelIndex],&to[XkbOneLevelIndex]);
+ if ((which&XkbTwoLevelMask)&&(rtrn==Success))
+ rtrn= XkbCopyKeyType(&from[XkbTwoLevelIndex],&to[XkbTwoLevelIndex]);
+ if ((which&XkbAlphabeticMask)&&(rtrn==Success))
+ rtrn= XkbCopyKeyType(&from[XkbAlphabeticIndex],&to[XkbAlphabeticIndex]);
+ if ((which&XkbKeypadMask)&&(rtrn==Success)) {
+ XkbKeyTypePtr type;
+ rtrn= XkbCopyKeyType(&from[XkbKeypadIndex],&to[XkbKeypadIndex]);
+ type= &to[XkbKeypadIndex];
+ if ((keypadVMod>=0)&&(keypadVMod<XkbNumVirtualMods)&&(rtrn==Success)) {
+ type->mods.vmods= (1<<keypadVMod);
+ type->map[0].active= True;
+ type->map[0].mods.mask= ShiftMask;
+ type->map[0].mods.real_mods= ShiftMask;
+ type->map[0].mods.vmods= 0;
+ type->map[0].level= 1;
+ type->map[1].active= False;
+ type->map[1].mods.mask= 0;
+ type->map[1].mods.real_mods= 0;
+ type->map[1].mods.vmods= (1<<keypadVMod);
+ type->map[1].level= 1;
+ }
+ }
+ return Success;
+}
+
+/***====================================================================***/
+
+#define CORE_SYM(i) (i<map_width?core_syms[i]:NoSymbol)
+#define XKB_OFFSET(g,l) (((g)*groupsWidth)+(l))
+
+int
+XkbKeyTypesForCoreSymbols( XkbDescPtr xkb,
+ int map_width,
+ KeySym * core_syms,
+ unsigned int protected,
+ int * types_inout,
+ KeySym * xkb_syms_rtrn)
+{
+register int i;
+unsigned int empty;
+int nSyms[XkbNumKbdGroups];
+int nGroups,tmp,groupsWidth;
+
+ /* Section 12.2 of the protocol describes this process in more detail */
+ /* Step 1: find the # of symbols in the core mapping per group */
+ groupsWidth= 2;
+ for (i=0;i<XkbNumKbdGroups;i++) {
+ if ((protected&(1<<i))&&(types_inout[i]<xkb->map->num_types)) {
+ nSyms[i]= xkb->map->types[types_inout[i]].num_levels;
+ if (nSyms[i]>groupsWidth)
+ groupsWidth= nSyms[i];
+ }
+ else {
+ types_inout[i]= XkbTwoLevelIndex; /* don't really know, yet */
+ nSyms[i]= 2;
+ }
+ }
+ if (nSyms[XkbGroup1Index]<2)
+ nSyms[XkbGroup1Index]= 2;
+ if (nSyms[XkbGroup2Index]<2)
+ nSyms[XkbGroup2Index]= 2;
+ /* Step 2: Copy the symbols from the core ordering to XKB ordering */
+ /* symbols in the core are in the order: */
+ /* G1L1 G1L2 G2L1 G2L2 [G1L[3-n]] [G2L[3-n]] [G3L*] [G3L*] */
+ xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,0)]= CORE_SYM(0);
+ xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,1)]= CORE_SYM(1);
+ for (i=2;i<nSyms[XkbGroup1Index];i++) {
+ xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,i)]= CORE_SYM(2+i);
+ }
+ xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,0)]= CORE_SYM(2);
+ xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,1)]= CORE_SYM(3);
+ tmp= 2+(nSyms[XkbGroup1Index]-2); /* offset to extra group2 syms */
+ for (i=2;i<nSyms[XkbGroup2Index];i++) {
+ xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,i)]= CORE_SYM(tmp+i);
+ }
+ tmp= nSyms[XkbGroup1Index]+nSyms[XkbGroup2Index];
+ if ((tmp>=map_width)&&
+ ((protected&(XkbExplicitKeyType3Mask|XkbExplicitKeyType4Mask))==0)) {
+ nSyms[XkbGroup3Index]= 0;
+ nSyms[XkbGroup4Index]= 0;
+ nGroups= 2;
+ }
+ else {
+ nGroups= 3;
+ for (i=0;i<nSyms[XkbGroup3Index];i++,tmp++) {
+ xkb_syms_rtrn[XKB_OFFSET(XkbGroup3Index,i)]= CORE_SYM(tmp);
+ }
+ if ((tmp<map_width)||(protected&XkbExplicitKeyType4Mask)) {
+ nGroups= 4;
+ for (i=0;i<nSyms[XkbGroup4Index];i++,tmp++) {
+ xkb_syms_rtrn[XKB_OFFSET(XkbGroup4Index,i)]= CORE_SYM(tmp);
+ }
+ }
+ else {
+ nSyms[XkbGroup4Index]= 0;
+ }
+ }
+ /* steps 3&4: alphanumeric expansion, assign canonical types */
+ empty= 0;
+ for (i=0;i<nGroups;i++) {
+ KeySym *syms;
+ syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)];
+ if ((nSyms[i]>1)&&(syms[1]==NoSymbol)&&(syms[0]!=NoSymbol)) {
+ KeySym upper,lower;
+ XConvertCase(syms[0],&lower,&upper);
+ if (upper!=lower) {
+ xkb_syms_rtrn[XKB_OFFSET(i,0)]= lower;
+ xkb_syms_rtrn[XKB_OFFSET(i,1)]= upper;
+ if ((protected&(1<<i))==0)
+ types_inout[i]= XkbAlphabeticIndex;
+ }
+ else if ((protected&(1<<i))==0) {
+ types_inout[i]= XkbOneLevelIndex;
+ /* nSyms[i]= 1;*/
+ }
+ }
+ if (((protected&(1<<i))==0)&&(types_inout[i]==XkbTwoLevelIndex)) {
+ if (IsKeypadKey(syms[0])||IsKeypadKey(syms[1]))
+ types_inout[i]= XkbKeypadIndex;
+ else {
+ KeySym upper,lower;
+ XConvertCase(syms[0],&lower,&upper);
+ if ((syms[0]==lower)&&(syms[1]==upper))
+ types_inout[i]= XkbAlphabeticIndex;
+ }
+ }
+ if (syms[0]==NoSymbol) {
+ register int n;
+ Bool found;
+ for (n=1,found=False;(!found)&&(n<nSyms[i]);n++) {
+ found= (syms[n]!=NoSymbol);
+ }
+ if (!found)
+ empty|= (1<<i);
+ }
+ }
+ /* step 5: squoosh out empty groups */
+ if (empty) {
+ for (i=nGroups-1;i>=0;i--) {
+ if (((empty&(1<<i))==0)||(protected&(1<<i)))
+ break;
+ nGroups--;
+ }
+ }
+ if (nGroups<1)
+ return 0;
+
+ /* step 6: replicate group 1 into group two, if necessary */
+ if ((nGroups>1)&&((empty&(XkbGroup1Mask|XkbGroup2Mask))==XkbGroup2Mask)) {
+ if ((protected&(XkbExplicitKeyType1Mask|XkbExplicitKeyType2Mask))==0) {
+ nSyms[XkbGroup2Index]= nSyms[XkbGroup1Index];
+ types_inout[XkbGroup2Index]= types_inout[XkbGroup1Index];
+ memcpy((char *)&xkb_syms_rtrn[2],(char *)xkb_syms_rtrn,
+ 2*sizeof(KeySym));
+ }
+ else if (types_inout[XkbGroup1Index]==types_inout[XkbGroup2Index]) {
+ memcpy((char *)&xkb_syms_rtrn[nSyms[XkbGroup1Index]],
+ (char *)xkb_syms_rtrn,
+ nSyms[XkbGroup1Index]*sizeof(KeySym));
+ }
+ }
+
+ /* step 7: check for all groups identical or all width 1 */
+ if (nGroups>1) {
+ Bool sameType,allOneLevel;
+ allOneLevel= (xkb->map->types[types_inout[0]].num_levels==1);
+ for (i=1,sameType=True;(allOneLevel||sameType)&&(i<nGroups);i++) {
+ sameType=(sameType&&(types_inout[i]==types_inout[XkbGroup1Index]));
+ if (allOneLevel)
+ allOneLevel= (xkb->map->types[types_inout[i]].num_levels==1);
+ }
+ if ((sameType)&&
+ (!(protected&(XkbExplicitKeyTypesMask&~XkbExplicitKeyType1Mask)))){
+ register int s;
+ Bool identical;
+ for (i=1,identical=True;identical&&(i<nGroups);i++) {
+ KeySym *syms;
+ syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)];
+ for (s=0;identical&&(s<nSyms[i]);s++) {
+ if (syms[s]!=xkb_syms_rtrn[s])
+ identical= False;
+ }
+ }
+ if (identical)
+ nGroups= 1;
+ }
+ if (allOneLevel && (nGroups>1)) {
+ KeySym *syms;
+ syms= &xkb_syms_rtrn[nSyms[XkbGroup1Index]];
+ nSyms[XkbGroup1Index]= 1;
+ for (i=1;i<nGroups;i++) {
+ xkb_syms_rtrn[i]= syms[0];
+ syms+= nSyms[i];
+ nSyms[i]= 1;
+ }
+ }
+ }
+ return nGroups;
+}
+
+static XkbSymInterpretPtr
+_XkbFindMatchingInterp( XkbDescPtr xkb,
+ KeySym sym,
+ unsigned int real_mods,
+ unsigned int level)
+{
+register unsigned i;
+XkbSymInterpretPtr interp,rtrn;
+CARD8 mods;
+
+ rtrn= NULL;
+ interp= xkb->compat->sym_interpret;
+ for (i=0;i<xkb->compat->num_si;i++,interp++) {
+ if ((interp->sym==NoSymbol)||(sym==interp->sym)) {
+ int match;
+ if ((level==0)||((interp->match&XkbSI_LevelOneOnly)==0))
+ mods= real_mods;
+ else mods= 0;
+ switch (interp->match&XkbSI_OpMask) {
+ case XkbSI_NoneOf:
+ match= ((interp->mods&mods)==0);
+ break;
+ case XkbSI_AnyOfOrNone:
+ match= ((mods==0)||((interp->mods&mods)!=0));
+ break;
+ case XkbSI_AnyOf:
+ match= ((interp->mods&mods)!=0);
+ break;
+ case XkbSI_AllOf:
+ match= ((interp->mods&mods)==interp->mods);
+ break;
+ case XkbSI_Exactly:
+ match= (interp->mods==mods);
+ break;
+ default:
+ match= 0;
+ break;
+ }
+ if (match) {
+ if (interp->sym!=NoSymbol) {
+ return interp;
+ }
+ else if (rtrn==NULL) {
+ rtrn= interp;
+ }
+ }
+ }
+ }
+ return rtrn;
+}
+
+static void
+_XkbAddKeyChange(KeyCode *pFirst,unsigned char *pNum,KeyCode newKey)
+{
+KeyCode last;
+
+ last= (*pFirst)+(*pNum);
+ if (newKey<*pFirst) {
+ *pFirst= newKey;
+ *pNum= (last-newKey)+1;
+ }
+ else if (newKey>last) {
+ *pNum= (last-*pFirst)+1;
+ }
+ return;
+}
+
+static void
+_XkbSetActionKeyMods(XkbDescPtr xkb,XkbAction *act,unsigned mods)
+{
+unsigned tmp;
+
+ switch (act->type) {
+ case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods:
+ if (act->mods.flags&XkbSA_UseModMapMods)
+ act->mods.real_mods= act->mods.mask= mods;
+ if ((tmp= XkbModActionVMods(&act->mods))!=0) {
+ XkbVirtualModsToReal(xkb,tmp,&tmp);
+ act->mods.mask|= tmp;
+ }
+ break;
+ case XkbSA_ISOLock:
+ if (act->iso.flags&XkbSA_UseModMapMods)
+ act->iso.real_mods= act->iso.mask= mods;
+ if ((tmp= XkbModActionVMods(&act->iso))!=0) {
+ XkbVirtualModsToReal(xkb,tmp,&tmp);
+ act->iso.mask|= tmp;
+ }
+ break;
+ }
+ return;
+}
+
+#define IBUF_SIZE 8
+
+Bool
+XkbApplyCompatMapToKey(XkbDescPtr xkb,KeyCode key,XkbChangesPtr changes)
+{
+KeySym * syms;
+unsigned char explicit,mods;
+XkbSymInterpretPtr *interps,ibuf[IBUF_SIZE];
+int n,nSyms,found;
+unsigned changed,tmp;
+
+ if ((!xkb)||(!xkb->map)||(!xkb->map->key_sym_map)||
+ (!xkb->compat)||(!xkb->compat->sym_interpret)||
+ (key<xkb->min_key_code)||(key>xkb->max_key_code)) {
+ return False;
+ }
+ if (((!xkb->server)||(!xkb->server->key_acts))&&
+ (XkbAllocServerMap(xkb,XkbAllServerInfoMask,0)!=Success)) {
+ return False;
+ }
+ changed= 0; /* keeps track of what has changed in _this_ call */
+ explicit= xkb->server->explicit[key];
+ if (explicit&XkbExplicitInterpretMask) /* nothing to do */
+ return True;
+ mods= (xkb->map->modmap?xkb->map->modmap[key]:0);
+ nSyms= XkbKeyNumSyms(xkb,key);
+ syms= XkbKeySymsPtr(xkb,key);
+ if (nSyms>IBUF_SIZE) {
+ interps= _XkbTypedCalloc(nSyms,XkbSymInterpretPtr);
+ if (interps==NULL) {
+ interps= ibuf;
+ nSyms= IBUF_SIZE;
+ }
+ }
+ else {
+ interps= ibuf;
+ }
+ found= 0;
+ for (n=0;n<nSyms;n++) {
+ unsigned level= (n%XkbKeyGroupsWidth(xkb,key));
+ interps[n]= NULL;
+ if (syms[n]!=NoSymbol) {
+ interps[n]= _XkbFindMatchingInterp(xkb,syms[n],mods,level);
+ if (interps[n]&&interps[n]->act.type!=XkbSA_NoAction)
+ found++;
+ else interps[n]= NULL;
+ }
+ }
+ /* 1/28/96 (ef) -- XXX! WORKING HERE */
+ if (!found) {
+ if (xkb->server->key_acts[key]!=0) {
+ xkb->server->key_acts[key]= 0;
+ changed|= XkbKeyActionsMask;
+ }
+ }
+ else {
+ XkbAction *pActs;
+ unsigned int new_vmodmask;
+ changed|= XkbKeyActionsMask;
+ pActs= XkbResizeKeyActions(xkb,key,nSyms);
+ if (!pActs) {
+ if (nSyms > IBUF_SIZE)
+ Xfree(interps);
+ return False;
+ }
+ new_vmodmask= 0;
+ for (n=0;n<nSyms;n++) {
+ if (interps[n]) {
+ unsigned effMods;
+
+ pActs[n]= *((XkbAction *)&interps[n]->act);
+ if ((n==0)||((interps[n]->match&XkbSI_LevelOneOnly)==0)) {
+ effMods= mods;
+ if (interps[n]->virtual_mod!=XkbNoModifier)
+ new_vmodmask|= (1<<interps[n]->virtual_mod);
+ }
+ else effMods= 0;
+ _XkbSetActionKeyMods(xkb,&pActs[n],effMods);
+ }
+ else pActs[n].type= XkbSA_NoAction;
+ }
+ if (((explicit&XkbExplicitVModMapMask)==0)&&
+ (xkb->server->vmodmap[key]!=new_vmodmask)) {
+ changed|= XkbVirtualModMapMask;
+ xkb->server->vmodmap[key]= new_vmodmask;
+ }
+ if (interps[0]) {
+ if ((interps[0]->flags&XkbSI_LockingKey)&&
+ ((explicit&XkbExplicitBehaviorMask)==0)) {
+ xkb->server->behaviors[key].type= XkbKB_Lock;
+ changed|= XkbKeyBehaviorsMask;
+ }
+ if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) {
+ CARD8 old;
+ old= xkb->ctrls->per_key_repeat[key/8];
+ if (interps[0]->flags&XkbSI_AutoRepeat)
+ xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8));
+ else xkb->ctrls->per_key_repeat[key/8]&= ~(1<<(key%8));
+ if (changes && (old!=xkb->ctrls->per_key_repeat[key/8]))
+ changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask;
+ }
+ }
+ }
+ if ((!found)||(interps[0]==NULL)) {
+ if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) {
+ CARD8 old;
+ old= xkb->ctrls->per_key_repeat[key/8];
+#ifdef RETURN_SHOULD_REPEAT
+ if (*XkbKeySymsPtr(xkb,key) != XK_Return)
+#endif
+ xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8));
+ if (changes && (old!=xkb->ctrls->per_key_repeat[key/8]))
+ changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask;
+ }
+ if (((explicit&XkbExplicitBehaviorMask)==0)&&
+ (xkb->server->behaviors[key].type==XkbKB_Lock)) {
+ xkb->server->behaviors[key].type= XkbKB_Default;
+ changed|= XkbKeyBehaviorsMask;
+ }
+ }
+ if (changes) {
+ XkbMapChangesPtr mc;
+ mc= &changes->map;
+ tmp= (changed&mc->changed);
+ if (tmp&XkbKeyActionsMask)
+ _XkbAddKeyChange(&mc->first_key_act,&mc->num_key_acts,key);
+ else if (changed&XkbKeyActionsMask) {
+ mc->changed|= XkbKeyActionsMask;
+ mc->first_key_act= key;
+ mc->num_key_acts= 1;
+ }
+ if (tmp&XkbKeyBehaviorsMask) {
+ _XkbAddKeyChange(&mc->first_key_behavior,&mc->num_key_behaviors,
+ key);
+ }
+ else if (changed&XkbKeyBehaviorsMask) {
+ mc->changed|= XkbKeyBehaviorsMask;
+ mc->first_key_behavior= key;
+ mc->num_key_behaviors= 1;
+ }
+ if (tmp&XkbVirtualModMapMask)
+ _XkbAddKeyChange(&mc->first_vmodmap_key,&mc->num_vmodmap_keys,key);
+ else if (changed&XkbVirtualModMapMask) {
+ mc->changed|= XkbVirtualModMapMask;
+ mc->first_vmodmap_key= key;
+ mc->num_vmodmap_keys= 1;
+ }
+ mc->changed|= changed;
+ }
+ if (interps!=ibuf)
+ _XkbFree(interps);
+ return True;
+}
+
+Bool
+XkbUpdateMapFromCore( XkbDescPtr xkb,
+ KeyCode first_key,
+ int num_keys,
+ int map_width,
+ KeySym * core_keysyms,
+ XkbChangesPtr changes)
+{
+register int key,last_key;
+KeySym * syms;
+
+ syms= &core_keysyms[(first_key-xkb->min_key_code)*map_width];
+ if (changes) {
+ if (changes->map.changed&XkbKeySymsMask) {
+ _XkbAddKeyChange(&changes->map.first_key_sym,
+ &changes->map.num_key_syms,first_key);
+ if (num_keys>1) {
+ _XkbAddKeyChange(&changes->map.first_key_sym,
+ &changes->map.num_key_syms,
+ first_key+num_keys-1);
+ }
+ }
+ else {
+ changes->map.changed|= XkbKeySymsMask;
+ changes->map.first_key_sym= first_key;
+ changes->map.num_key_syms= num_keys;
+ }
+ }
+ last_key= first_key+num_keys-1;
+ for (key=first_key;key<=last_key;key++,syms+= map_width) {
+ XkbMapChangesPtr mc;
+ unsigned explicit;
+ KeySym tsyms[XkbMaxSymsPerKey];
+ int types[XkbNumKbdGroups];
+ int nG;
+
+ explicit= xkb->server->explicit[key]&XkbExplicitKeyTypesMask;
+ types[XkbGroup1Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index);
+ types[XkbGroup2Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup2Index);
+ types[XkbGroup3Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup3Index);
+ types[XkbGroup4Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup4Index);
+ nG= XkbKeyTypesForCoreSymbols(xkb,map_width,syms,explicit,types,tsyms);
+ if (changes)
+ mc= &changes->map;
+ else mc= NULL;
+ XkbChangeTypesOfKey(xkb,key,nG,XkbAllGroupsMask,types,mc);
+ memcpy((char *)XkbKeySymsPtr(xkb,key),(char *)tsyms,
+ XkbKeyNumSyms(xkb,key)*sizeof(KeySym));
+ XkbApplyCompatMapToKey(xkb,key,changes);
+ }
+
+ if ((xkb->server->vmods!=NULL)&&(xkb->map->modmap!=NULL)&&(changes)&&
+ (changes->map.changed&(XkbVirtualModMapMask|XkbModifierMapMask))) {
+ unsigned char newVMods[XkbNumVirtualMods];
+ register unsigned bit,i;
+ unsigned present;
+
+ bzero(newVMods,XkbNumVirtualMods);
+ present= 0;
+ for (key=xkb->min_key_code;key<=xkb->max_key_code;key++) {
+ if (xkb->server->vmodmap[key]==0)
+ continue;
+ for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
+ if (bit&xkb->server->vmodmap[key]) {
+ present|= bit;
+ newVMods[i]|= xkb->map->modmap[key];
+ }
+ }
+ }
+ for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
+ if ((bit&present)&&(newVMods[i]!=xkb->server->vmods[i])) {
+ changes->map.changed|= XkbVirtualModsMask;
+ changes->map.vmods|= bit;
+ xkb->server->vmods[i]= newVMods[i];
+ }
+ }
+ }
+ if (changes && (changes->map.changed&XkbVirtualModsMask))
+ XkbApplyVirtualModChanges(xkb,changes->map.vmods,changes);
+ return True;
+}
+
+Status
+XkbChangeTypesOfKey( XkbDescPtr xkb,
+ int key,
+ int nGroups,
+ unsigned groups,
+ int * newTypesIn,
+ XkbMapChangesPtr changes)
+{
+XkbKeyTypePtr pOldType,pNewType;
+register int i;
+int width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups];
+
+ if ((!xkb) || (!XkbKeycodeInRange(xkb,key)) || (!xkb->map) ||
+ (!xkb->map->types)||((groups&XkbAllGroupsMask)==0)||
+ (nGroups>XkbNumKbdGroups)) {
+ return BadMatch;
+ }
+ if (nGroups==0) {
+ for (i=0;i<XkbNumKbdGroups;i++) {
+ xkb->map->key_sym_map[key].kt_index[i]= XkbOneLevelIndex;
+ }
+ i= xkb->map->key_sym_map[key].group_info;
+ i= XkbSetNumGroups(i,0);
+ xkb->map->key_sym_map[key].group_info= i;
+ XkbResizeKeySyms(xkb,key,0);
+ return Success;
+ }
+
+ nOldGroups= XkbKeyNumGroups(xkb,key);
+ oldWidth= XkbKeyGroupsWidth(xkb,key);
+ for (width=i=0;i<nGroups;i++) {
+ if (groups&(1<<i))
+ newTypes[i]= newTypesIn[i];
+ else if (i<nOldGroups)
+ newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,i);
+ else if (nOldGroups>0)
+ newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index);
+ else newTypes[i]= XkbTwoLevelIndex;
+ if (newTypes[i]>xkb->map->num_types)
+ return BadMatch;
+ pNewType= &xkb->map->types[newTypes[i]];
+ if (pNewType->num_levels>width)
+ width= pNewType->num_levels;
+ }
+ if ((xkb->ctrls)&&(nGroups>xkb->ctrls->num_groups))
+ xkb->ctrls->num_groups= nGroups;
+ if ((width!=oldWidth)||(nGroups!=nOldGroups)) {
+ KeySym oldSyms[XkbMaxSymsPerKey],*pSyms;
+ int nCopy;
+
+ if (nOldGroups==0) {
+ pSyms= XkbResizeKeySyms(xkb,key,width*nGroups);
+ if (pSyms!=NULL) {
+ i= xkb->map->key_sym_map[key].group_info;
+ i= XkbSetNumGroups(i,nGroups);
+ xkb->map->key_sym_map[key].group_info= i;
+ xkb->map->key_sym_map[key].width= width;
+ for (i=0;i<nGroups;i++) {
+ xkb->map->key_sym_map[key].kt_index[i]= newTypes[i];
+ }
+ return Success;
+ }
+ return BadAlloc;
+ }
+ pSyms= XkbKeySymsPtr(xkb,key);
+ memcpy(oldSyms,pSyms,XkbKeyNumSyms(xkb,key)*sizeof(KeySym));
+ pSyms= XkbResizeKeySyms(xkb,key,width*nGroups);
+ if (pSyms==NULL)
+ return BadAlloc;
+ bzero(pSyms,width*nGroups*sizeof(KeySym));
+ for (i=0;(i<nGroups)&&(i<nOldGroups);i++) {
+ pOldType= XkbKeyKeyType(xkb,key,i);
+ pNewType= &xkb->map->types[newTypes[i]];
+ if (pNewType->num_levels>pOldType->num_levels)
+ nCopy= pOldType->num_levels;
+ else nCopy= pNewType->num_levels;
+ memcpy(&pSyms[i*width],&oldSyms[i*oldWidth],nCopy*sizeof(KeySym));
+ }
+ if (XkbKeyHasActions(xkb,key)) {
+ XkbAction oldActs[XkbMaxSymsPerKey],*pActs;
+ pActs= XkbKeyActionsPtr(xkb,key);
+ memcpy(oldActs,pActs,XkbKeyNumSyms(xkb,key)*sizeof(XkbAction));
+ pActs= XkbResizeKeyActions(xkb,key,width*nGroups);
+ if (pActs==NULL)
+ return BadAlloc;
+ bzero(pActs,width*nGroups*sizeof(XkbAction));
+ for (i=0;(i<nGroups)&&(i<nOldGroups);i++) {
+ pOldType= XkbKeyKeyType(xkb,key,i);
+ pNewType= &xkb->map->types[newTypes[i]];
+ if (pNewType->num_levels>pOldType->num_levels)
+ nCopy= pOldType->num_levels;
+ else nCopy= pNewType->num_levels;
+ memcpy(&pActs[i*width],&oldActs[i*oldWidth],
+ nCopy*sizeof(XkbAction));
+ }
+ }
+ i= xkb->map->key_sym_map[key].group_info;
+ i= XkbSetNumGroups(i,nGroups);
+ xkb->map->key_sym_map[key].group_info= i;
+ xkb->map->key_sym_map[key].width= width;
+ }
+ width= 0;
+ for (i=0;i<nGroups;i++) {
+ xkb->map->key_sym_map[key].kt_index[i]= newTypes[i];
+ if (xkb->map->types[newTypes[i]].num_levels>width)
+ width= xkb->map->types[newTypes[i]].num_levels;
+ }
+ xkb->map->key_sym_map[key].width= width;
+ if (changes!=NULL) {
+ if (changes->changed&XkbKeySymsMask) {
+ _XkbAddKeyChange(&changes->first_key_sym,&changes->num_key_syms,
+ key);
+ }
+ else {
+ changes->changed|= XkbKeySymsMask;
+ changes->first_key_sym= key;
+ changes->num_key_syms= 1;
+ }
+ }
+ return Success;
+}
+
+/***====================================================================***/
+
+Bool
+XkbVirtualModsToReal(XkbDescPtr xkb,unsigned virtual_mask,unsigned *mask_rtrn)
+{
+register int i,bit;
+register unsigned mask;
+
+ if (xkb==NULL)
+ return False;
+ if (virtual_mask==0) {
+ *mask_rtrn= 0;
+ return True;
+ }
+ if (xkb->server==NULL)
+ return False;
+ for (i=mask=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
+ if (virtual_mask&bit)
+ mask|= xkb->server->vmods[i];
+ }
+ *mask_rtrn= mask;
+ return True;
+}
+
+/***====================================================================***/
+
+Bool
+XkbUpdateActionVirtualMods(XkbDescPtr xkb,XkbAction *act,unsigned changed)
+{
+unsigned int tmp;
+
+ switch (act->type) {
+ case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods:
+ if (((tmp= XkbModActionVMods(&act->mods))&changed)!=0) {
+ XkbVirtualModsToReal(xkb,tmp,&tmp);
+ act->mods.mask= act->mods.real_mods;
+ act->mods.mask|= tmp;
+ return True;
+ }
+ break;
+ case XkbSA_ISOLock:
+ if ((((tmp= XkbModActionVMods(&act->iso))!=0)&changed)!=0) {
+ XkbVirtualModsToReal(xkb,tmp,&tmp);
+ act->iso.mask= act->iso.real_mods;
+ act->iso.mask|= tmp;
+ return True;
+ }
+ break;
+ }
+ return False;
+}
+
+void
+XkbUpdateKeyTypeVirtualMods( XkbDescPtr xkb,
+ XkbKeyTypePtr type,
+ unsigned int changed,
+ XkbChangesPtr changes)
+{
+register unsigned int i;
+unsigned int mask;
+
+ XkbVirtualModsToReal(xkb,type->mods.vmods,&mask);
+ type->mods.mask= type->mods.real_mods|mask;
+ if ((type->map_count>0)&&(type->mods.vmods!=0)) {
+ XkbKTMapEntryPtr entry;
+ for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
+ if (entry->mods.vmods!=0) {
+ XkbVirtualModsToReal(xkb,entry->mods.vmods,&mask);
+ entry->mods.mask=entry->mods.real_mods|mask;
+ /* entry is active if vmods are bound*/
+ entry->active= (mask!=0);
+ }
+ else entry->active= 1;
+ }
+ }
+ if (changes) {
+ int type_ndx;
+ type_ndx= type-xkb->map->types;
+ if ((type_ndx<0)||(type_ndx>xkb->map->num_types))
+ return;
+ if (changes->map.changed&XkbKeyTypesMask) {
+ int last;
+ last= changes->map.first_type+changes->map.num_types-1;
+ if (type_ndx<changes->map.first_type) {
+ changes->map.first_type= type_ndx;
+ changes->map.num_types= (last-type_ndx)+1;
+ }
+ else if (type_ndx>last) {
+ changes->map.num_types= (type_ndx-changes->map.first_type)+1;
+ }
+ }
+ else {
+ changes->map.changed|= XkbKeyTypesMask;
+ changes->map.first_type= type_ndx;
+ changes->map.num_types= 1;
+ }
+ }
+ return;
+}
+
+Bool
+XkbApplyVirtualModChanges(XkbDescPtr xkb,unsigned changed,XkbChangesPtr changes)
+{
+register int i;
+unsigned int checkState = 0;
+
+ if ((!xkb) || (!xkb->map) || (changed==0))
+ return False;
+ for (i=0;i<xkb->map->num_types;i++) {
+ if (xkb->map->types[i].mods.vmods & changed)
+ XkbUpdateKeyTypeVirtualMods(xkb,&xkb->map->types[i],changed,changes);
+ }
+ if (changed&xkb->ctrls->internal.vmods) {
+ unsigned int newMask;
+ XkbVirtualModsToReal(xkb,xkb->ctrls->internal.vmods,&newMask);
+ newMask|= xkb->ctrls->internal.real_mods;
+ if (xkb->ctrls->internal.mask!=newMask) {
+ xkb->ctrls->internal.mask= newMask;
+ if (changes) {
+ changes->ctrls.changed_ctrls|= XkbInternalModsMask;
+ checkState= True;
+ }
+ }
+ }
+ if (changed&xkb->ctrls->ignore_lock.vmods) {
+ unsigned int newMask;
+ XkbVirtualModsToReal(xkb,xkb->ctrls->ignore_lock.vmods,&newMask);
+ newMask|= xkb->ctrls->ignore_lock.real_mods;
+ if (xkb->ctrls->ignore_lock.mask!=newMask) {
+ xkb->ctrls->ignore_lock.mask= newMask;
+ if (changes) {
+ changes->ctrls.changed_ctrls|= XkbIgnoreLockModsMask;
+ checkState= True;
+ }
+ }
+ }
+ if (xkb->indicators!=NULL) {
+ XkbIndicatorMapPtr map;
+ map= &xkb->indicators->maps[0];
+ for (i=0;i<XkbNumIndicators;i++,map++) {
+ if (map->mods.vmods&changed) {
+ unsigned int newMask;
+ XkbVirtualModsToReal(xkb,map->mods.vmods,&newMask);
+ newMask|= map->mods.real_mods;
+ if (newMask!=map->mods.mask) {
+ map->mods.mask= newMask;
+ if (changes) {
+ changes->indicators.map_changes|= (1<<i);
+ checkState= True;
+ }
+ }
+ }
+ }
+ }
+ if (xkb->compat!=NULL) {
+ XkbCompatMapPtr compat;
+ compat= xkb->compat;
+ for (i=0;i<XkbNumKbdGroups;i++) {
+ unsigned int newMask;
+ XkbVirtualModsToReal(xkb,compat->groups[i].vmods,&newMask);
+ newMask|= compat->groups[i].real_mods;
+ if (compat->groups[i].mask!=newMask) {
+ compat->groups[i].mask= newMask;
+ if (changes) {
+ changes->compat.changed_groups|= (1<<i);
+ checkState= True;
+ }
+ }
+ }
+ }
+ if (xkb->map && xkb->server) {
+ int highChange = 0, lowChange = -1;
+ for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
+ if (XkbKeyHasActions(xkb,i)) {
+ register XkbAction *pAct;
+ register int n;
+
+ pAct= XkbKeyActionsPtr(xkb,i);
+ for (n=XkbKeyNumActions(xkb,i);n>0;n--,pAct++) {
+ if ((pAct->type!=XkbSA_NoAction)&&
+ XkbUpdateActionVirtualMods(xkb,pAct,changed)) {
+ if (lowChange<0)
+ lowChange= i;
+ highChange= i;
+ }
+ }
+ }
+ }
+ if (changes && (lowChange>0)) { /* something changed */
+ if (changes->map.changed&XkbKeyActionsMask) {
+ int last;
+ if (changes->map.first_key_act<lowChange)
+ lowChange= changes->map.first_key_act;
+ last= changes->map.first_key_act+changes->map.num_key_acts-1;
+ if (last>highChange)
+ highChange= last;
+ }
+ changes->map.changed|= XkbKeyActionsMask;
+ changes->map.first_key_act= lowChange;
+ changes->map.num_key_acts= (highChange-lowChange)+1;
+ }
+ }
+ return checkState;
+}
diff --git a/libX11/src/xkb/XKBNames.c b/libX11/src/xkb/XKBNames.c
index b07f73ca5..3cc1f60ed 100644
--- a/libX11/src/xkb/XKBNames.c
+++ b/libX11/src/xkb/XKBNames.c
@@ -1,889 +1,887 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_REPLIES
-#define NEED_EVENTS
-#define NEED_MAP_READERS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-
-static Status
-_XkbReadAtoms( XkbReadBufferPtr buf,
- Atom * atoms,
- int maxAtoms,
- CARD32 present)
-{
-register int i,bit;
-
- for (i=0,bit=1;(i<maxAtoms)&&(present);i++,bit<<=1) {
- if (present&bit) {
- if (!_XkbReadBufferCopy32(buf,(long *)&atoms[i],1))
- return BadLength;
- present&= ~bit;
- }
- }
- return Success;
-}
-
-Status
-_XkbReadGetNamesReply( Display * dpy,
- xkbGetNamesReply * rep,
- XkbDescPtr xkb,
- int * nread_rtrn)
-{
- int i,len;
- XkbReadBufferRec buf;
- register XkbNamesPtr names;
-
- if ( xkb->device_spec == XkbUseCoreKbd )
- xkb->device_spec = rep->deviceID;
-
- if ((xkb->names==NULL)&&
- (XkbAllocNames(xkb,rep->which,
- rep->nRadioGroups,rep->nKeyAliases)!=Success)) {
- return BadAlloc;
- }
- names= xkb->names;
- if (rep->length==0)
- return Success;
-
- if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
- return BadAlloc;
- if (nread_rtrn)
- *nread_rtrn= (int)rep->length*4;
-
- if ((rep->which&XkbKeycodesNameMask)&&
- (!_XkbReadBufferCopy32(&buf,(long *)&names->keycodes,1)))
- goto BAILOUT;
- if ((rep->which&XkbGeometryNameMask)&&
- (!_XkbReadBufferCopy32(&buf,(long *)&names->geometry,1)))
- goto BAILOUT;
- if ((rep->which&XkbSymbolsNameMask)&&
- (!_XkbReadBufferCopy32(&buf,(long *)&names->symbols,1)))
- goto BAILOUT;
- if ((rep->which&XkbPhysSymbolsNameMask)&&
- (!_XkbReadBufferCopy32(&buf,(long *)&names->phys_symbols,1)))
- goto BAILOUT;
- if ((rep->which&XkbTypesNameMask)&&
- (!_XkbReadBufferCopy32(&buf,(long *)&names->types,1)))
- goto BAILOUT;
- if ((rep->which&XkbCompatNameMask)&&
- (!_XkbReadBufferCopy32(&buf,(long *)&names->compat,1)))
- goto BAILOUT;
-
- if ( rep->which & XkbKeyTypeNamesMask ) {
- XkbClientMapPtr map= xkb->map;
- XkbKeyTypePtr type;
-
- len= rep->nTypes*4;
- if (map!=NULL) {
- type= map->types;
- for (i=0;(i<map->num_types)&&(i<rep->nTypes);i++,type++) {
- if (!_XkbReadBufferCopy32(&buf,(long *)&type->name,1))
- goto BAILOUT;
- len-= 4;
- }
- }
- if ((len>0)&&(!_XkbSkipReadBufferData(&buf,len)))
- goto BAILOUT;
- }
- if ( rep->which&XkbKTLevelNamesMask ) {
- CARD8 *nLevels;
- XkbClientMapPtr map= xkb->map;
- XkbKeyTypePtr type;
-
- nLevels=(CARD8*)_XkbGetReadBufferPtr(&buf,XkbPaddedSize(rep->nTypes));
- if (nLevels==NULL)
- goto BAILOUT;
- if (map!=NULL) {
- type= map->types;
- for (i=0;i<(int)rep->nTypes;i++,type++) {
- if (i>=map->num_types) {
- if (!_XkbSkipReadBufferData(&buf,nLevels[i]*4))
- goto BAILOUT;
- continue;
- }
- if ((nLevels[i]>0)&&(nLevels[i]!=type->num_levels)) {
- goto BAILOUT;
- }
- if (type->level_names!=NULL)
- Xfree(type->level_names);
- if (nLevels[i]==0) {
- type->level_names= NULL;
- continue;
- }
- type->level_names= _XkbTypedCalloc(nLevels[i],Atom);
- if (type->level_names!=NULL) {
- if (!_XkbReadBufferCopy32(&buf,(long *)type->level_names,
- nLevels[i]))
- goto BAILOUT;
- }
- else {
- _XkbSkipReadBufferData(&buf,nLevels[i]*4);
- }
- }
- }
- else {
- for (i=0;i<(int)rep->nTypes;i++) {
- _XkbSkipReadBufferData(&buf,nLevels[i]*4);
- }
- }
- }
- if (rep->which & XkbIndicatorNamesMask) {
- if (_XkbReadAtoms(&buf,names->indicators,XkbNumIndicators,
- rep->indicators)!=Success)
- goto BAILOUT;
- }
- if ( rep->which&XkbVirtualModNamesMask ) {
- if (_XkbReadAtoms(&buf,names->vmods,XkbNumVirtualMods,
- (CARD32)rep->virtualMods)!=Success)
- goto BAILOUT;
- }
- if ( rep->which&XkbGroupNamesMask ) {
- if (_XkbReadAtoms(&buf,names->groups,XkbNumKbdGroups,
- (CARD32)rep->groupNames)!=Success)
- goto BAILOUT;
- }
- if ( rep->which&XkbKeyNamesMask ) {
- if (names->keys==NULL) {
- int nKeys;
- if (xkb->max_key_code==0) {
- xkb->min_key_code= rep->minKeyCode;
- xkb->max_key_code= rep->maxKeyCode;
- }
- nKeys= xkb->max_key_code+1;
- names->keys= _XkbTypedCalloc(nKeys,XkbKeyNameRec);
- }
- if (names->keys!=NULL) {
- if (!_XkbCopyFromReadBuffer(&buf,
- (char *)&names->keys[rep->firstKey],
- rep->nKeys*XkbKeyNameLength))
- goto BAILOUT;
- }
- else _XkbSkipReadBufferData(&buf,rep->nKeys*XkbKeyNameLength);
- }
- if ( rep->which&XkbKeyAliasesMask && (rep->nKeyAliases>0) ) {
- if (XkbAllocNames(xkb,XkbKeyAliasesMask,0,rep->nKeyAliases)!=Success)
- goto BAILOUT;
- if (!_XkbCopyFromReadBuffer(&buf,(char *)names->key_aliases,
- rep->nKeyAliases*XkbKeyNameLength*2))
- goto BAILOUT;
- }
- if ( rep->which&XkbRGNamesMask ) {
- if (rep->nRadioGroups>0) {
- Atom *rgNames;
-
- if (names->radio_groups==NULL)
- names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups,Atom);
- else if (names->num_rg<rep->nRadioGroups) {
- names->radio_groups = _XkbTypedRealloc(names->radio_groups,
- rep->nRadioGroups,
- Atom);
- }
- rgNames= names->radio_groups;
- if (!rgNames) {
- goto BAILOUT;
- }
- if (!_XkbReadBufferCopy32(&buf,(long *)rgNames,rep->nRadioGroups))
- goto BAILOUT;
- names->num_rg= rep->nRadioGroups;
- }
- else if (names->num_rg>0) {
- names->num_rg= 0;
- Xfree(names->radio_groups);
- }
- }
- len= _XkbFreeReadBuffer(&buf);
- if (len!=0) return BadLength;
- else return Success;
-BAILOUT:
- _XkbFreeReadBuffer(&buf);
- return BadLength;
-}
-
-Status
-XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb)
-{
- register xkbGetNamesReq *req;
- xkbGetNamesReply rep;
- Status status;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- if (!xkb->names) {
- xkb->names = _XkbTypedCalloc(1,XkbNamesRec);
- if (!xkb->names) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadAlloc;
- }
- }
- GetReq(kbGetNames, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetNames;
- req->deviceSpec = xkb->device_spec;
- req->which = which;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadImplementation;
- }
-
- status = _XkbReadGetNamesReply(dpy,&rep,xkb,NULL);
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-/***====================================================================***/
-
-static int
-_XkbCountBits(int nBitsMax,unsigned long mask)
-{
-register unsigned long y, nBits;
-
- y = (mask >> 1) &033333333333;
- y = mask - y - ((y >>1) & 033333333333);
- nBits = ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
-
- /* nBitsMax really means max+1 */
- return (nBits < nBitsMax) ? nBits : (nBitsMax - 1);
-}
-
-static CARD32
-_XkbCountAtoms(Atom *atoms,int maxAtoms,int *count)
-{
-register unsigned int i,bit,nAtoms;
-register CARD32 atomsPresent;
-
- for (i=nAtoms=atomsPresent=0,bit=1;i<maxAtoms;i++,bit<<=1) {
- if (atoms[i]!=None) {
- atomsPresent|= bit;
- nAtoms++;
- }
- }
- if (count)
- *count= nAtoms;
- return atomsPresent;
-}
-
-static void
-_XkbCopyAtoms(Display *dpy,Atom *atoms,CARD32 mask,int maxAtoms)
-{
-register unsigned int i,bit;
-
- for (i=0,bit=1;i<maxAtoms;i++,bit<<=1) {
- if (mask&bit)
- Data32(dpy,&atoms[i],4);
- }
- return;
-}
-
-Bool
-XkbSetNames( Display * dpy,
- unsigned int which,
- unsigned int firstType,
- unsigned int nTypes,
- XkbDescPtr xkb)
-{
- register xkbSetNamesReq *req;
- int nLvlNames = 0;
- XkbInfoPtr xkbi;
- XkbNamesPtr names;
- unsigned firstLvlType,nLvlTypes;
- int nVMods,nLEDs,nRG,nKA,nGroups;
- int nKeys=0,firstKey=0,nAtoms;
- CARD32 leds,vmods,groups;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- if ((!xkb)||(!xkb->names))
- return False;
- firstLvlType= firstType;
- nLvlTypes= nTypes;
- if (nTypes<1)
- which&= ~(XkbKTLevelNamesMask|XkbKeyTypeNamesMask);
- else if (firstType<=XkbLastRequiredType) {
- int adjust;
- adjust= XkbLastRequiredType-firstType+1;
- firstType+= adjust;
- nTypes-= adjust;
- if (nTypes<1)
- which&= ~XkbKeyTypeNamesMask;
- }
- names= xkb->names;
- if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) {
- register int i;
- XkbKeyTypePtr type;
- if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)||
- (firstType+nTypes>xkb->map->num_types)||
- (firstLvlType+nLvlTypes>xkb->map->num_types))
- return False;
- if (which&XkbKTLevelNamesMask) {
- type= &xkb->map->types[firstLvlType];
- for (i=nLvlNames=0;i<nLvlTypes;i++,type++) {
- if (type->level_names!=NULL)
- nLvlNames+= type->num_levels;
- }
- }
- }
-
- nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetNames, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSetNames;
- req->deviceSpec = xkb->device_spec;
- req->firstType = firstType;
- req->nTypes = nTypes;
- req->firstKey = xkb->min_key_code;
- req->nKeys = xkb->max_key_code-xkb->min_key_code+1;
-
- if (which&XkbKeycodesNameMask)
- nAtoms++;
- if (which&XkbGeometryNameMask)
- nAtoms++;
- if (which&XkbSymbolsNameMask)
- nAtoms++;
- if (which&XkbPhysSymbolsNameMask)
- nAtoms++;
- if (which&XkbTypesNameMask)
- nAtoms++;
- if (which&XkbCompatNameMask)
- nAtoms++;
- if (which&XkbKeyTypeNamesMask)
- nAtoms+= nTypes;
- if (which&XkbKTLevelNamesMask) {
- req->firstKTLevel= firstLvlType;
- req->nKTLevels= nLvlTypes;
- req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */
- nAtoms+= nLvlNames;
- }
- else req->firstKTLevel= req->nKTLevels= 0;
-
- if (which&XkbIndicatorNamesMask) {
- req->indicators= leds=
- _XkbCountAtoms(names->indicators,XkbNumIndicators,&nLEDs);
- if (nLEDs>0)
- nAtoms+= nLEDs;
- else which&= ~XkbIndicatorNamesMask;
- }
- else req->indicators= leds= 0;
-
- if (which&XkbVirtualModNamesMask) {
- vmods= req->virtualMods= (CARD16)
- _XkbCountAtoms(names->vmods,XkbNumVirtualMods,&nVMods);
- if (nVMods>0)
- nAtoms+= nVMods;
- else which&= ~XkbVirtualModNamesMask;
- }
- else vmods= req->virtualMods= 0;
-
- if (which&XkbGroupNamesMask) {
- groups= req->groupNames= (CARD8)
- _XkbCountAtoms(names->groups,XkbNumKbdGroups,&nGroups);
- if (nGroups>0)
- nAtoms+= nGroups;
- else which&= ~XkbGroupNamesMask;
- }
- else groups= req->groupNames= 0;
-
- if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
- firstKey= req->firstKey;
- nKeys= req->nKeys;
- nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */
- }
- else which&= ~XkbKeyNamesMask;
-
- if (which&XkbKeyAliasesMask) {
- nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0);
- if (nKA>0) {
- req->nKeyAliases= nKA;
- nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */
- }
- else {
- which&= ~XkbKeyAliasesMask;
- req->nKeyAliases = 0;
- }
- }
- else req->nKeyAliases= 0;
-
- if (which&XkbRGNamesMask) {
- nRG= names->num_rg;
- if (nRG>0)
- nAtoms+= nRG;
- else which&= ~XkbRGNamesMask;
- }
-
- req->which= which;
- req->nRadioGroups= nRG;
- req->length+= (nAtoms*4)/4;
-
- if (which&XkbKeycodesNameMask)
- Data32(dpy,(long *)&names->keycodes,4);
- if (which&XkbGeometryNameMask)
- Data32(dpy,(long *)&names->geometry,4);
- if (which&XkbSymbolsNameMask)
- Data32(dpy,(long *)&names->symbols,4);
- if (which&XkbPhysSymbolsNameMask)
- Data32(dpy,(long *)&names->phys_symbols,4);
- if (which&XkbTypesNameMask)
- Data32(dpy,(long *)&names->types,4);
- if (which&XkbCompatNameMask)
- Data32(dpy,(long *)&names->compat,4);
- if (which&XkbKeyTypeNamesMask) {
- register int i;
- register XkbKeyTypePtr type;
- type= &xkb->map->types[firstType];
- for (i=0;i<nTypes;i++,type++) {
- Data32(dpy,(long *)&type->name,4);
- }
- }
- if (which&XkbKTLevelNamesMask) {
- XkbKeyTypePtr type;
- int i;
- char *tmp;
-
- BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes));
- type = &xkb->map->types[firstLvlType];
- for (i=0;i<nLvlTypes;i++,type++) {
- *tmp++ = type->num_levels;
- }
- type = &xkb->map->types[firstLvlType];
- for (i=0;i<nLvlTypes;i++,type++) {
- if (type->level_names!=NULL)
- Data32(dpy,(long *)type->level_names,type->num_levels*4);
- }
- }
- if (which&XkbIndicatorNamesMask)
- _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators);
- if (which&XkbVirtualModNamesMask)
- _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods);
- if (which&XkbGroupNamesMask)
- _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups);
- if (which&XkbKeyNamesMask) {
-#ifdef WORD64
- char *tmp;
- register int i;
- BufAlloc(char *,tmp,nKeys*XkbKeyNameLength);
- for (i=0;i<nKeys;i++,tmp+= XkbKeyNameLength) {
- tmp[0]= names->keys[firstKey+i].name[0];
- tmp[1]= names->keys[firstKey+i].name[1];
- tmp[2]= names->keys[firstKey+i].name[2];
- tmp[3]= names->keys[firstKey+i].name[3];
- }
-#else
- Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength);
-#endif
- }
- if (which&XkbKeyAliasesMask) {
-#ifdef WORD64
- char *tmp;
- register int i;
- BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2);
- for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength) {
- tmp[0]= names->key_aliases[i].real[0];
- tmp[1]= names->key_aliases[i].real[1];
- tmp[2]= names->key_aliases[i].real[2];
- tmp[3]= names->key_aliases[i].real[3];
- tmp[4]= names->key_aliases[i].alias[0];
- tmp[5]= names->key_aliases[i].alias[1];
- tmp[6]= names->key_aliases[i].alias[2];
- tmp[7]= names->key_aliases[i].alias[3];
- }
-#else
- Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2);
-#endif
- }
- if (which&XkbRGNamesMask) {
- Data32(dpy,(long *)names->radio_groups,nRG*4);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes)
-{
- register xkbSetNamesReq *req;
- int nLvlNames = 0;
- XkbInfoPtr xkbi;
- XkbNamesPtr names;
- unsigned which,firstType,nTypes;
- unsigned firstLvlType,nLvlTypes;
- int nVMods,nLEDs,nRG,nKA,nGroups;
- int nKeys=0,firstKey=0,nAtoms;
- CARD32 leds=0,vmods=0,groups=0;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- if ((!xkb)||(!xkb->names)||(!changes))
- return False;
- which= changes->changed;
- firstType= changes->first_type;
- nTypes= changes->num_types;
- firstLvlType= changes->first_lvl;;
- nLvlTypes= changes->num_lvls;
- if (which&XkbKeyTypeNamesMask) {
- if (nTypes<1)
- which&= ~XkbKeyTypeNamesMask;
- else if (firstType<=XkbLastRequiredType) {
- int adjust;
- adjust= XkbLastRequiredType-firstType+1;
- firstType+= adjust;
- nTypes-= adjust;
- if (nTypes<1)
- which&= ~XkbKeyTypeNamesMask;
- }
- }
- else firstType= nTypes= 0;
-
- if (which&XkbKTLevelNamesMask) {
- if (nLvlTypes<1)
- which&= ~XkbKTLevelNamesMask;
- }
- else firstLvlType= nLvlTypes= 0;
-
- names= xkb->names;
- if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) {
- register int i;
- XkbKeyTypePtr type;
- if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)||
- (firstType+nTypes>xkb->map->num_types)||
- (firstLvlType+nLvlTypes>xkb->map->num_types))
- return False;
- if (which&XkbKTLevelNamesMask) {
- type= &xkb->map->types[firstLvlType];
- for (i=nLvlNames=0;i<nLvlTypes;i++,type++) {
- if (type->level_names!=NULL)
- nLvlNames+= type->num_levels;
- }
- }
- }
-
- if (changes->num_keys<1)
- which&= ~XkbKeyNamesMask;
- if ((which&XkbKeyNamesMask)==0)
- changes->first_key= changes->num_keys= 0;
- else if ((changes->first_key<xkb->min_key_code)||
- (changes->first_key+changes->num_keys>xkb->max_key_code)) {
- return False;
- }
-
- if ((which&XkbVirtualModNamesMask)==0)
- changes->changed_vmods= 0;
- else if (changes->changed_vmods==0)
- which&= ~XkbVirtualModNamesMask;
-
- if ((which&XkbIndicatorNamesMask)==0)
- changes->changed_indicators= 0;
- else if (changes->changed_indicators==0)
- which&= ~XkbIndicatorNamesMask;
-
- if ((which&XkbGroupNamesMask)==0)
- changes->changed_groups= 0;
- else if (changes->changed_groups==0)
- which&= ~XkbGroupNamesMask;
-
- nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetNames, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSetNames;
- req->deviceSpec = xkb->device_spec;
- req->firstType = firstType;
- req->nTypes = nTypes;
- req->firstKey = changes->first_key;
- req->nKeys = changes->num_keys;
-
- if (which&XkbKeycodesNameMask)
- nAtoms++;
- if (which&XkbGeometryNameMask)
- nAtoms++;
- if (which&XkbSymbolsNameMask)
- nAtoms++;
- if (which&XkbPhysSymbolsNameMask)
- nAtoms++;
- if (which&XkbTypesNameMask)
- nAtoms++;
- if (which&XkbCompatNameMask)
- nAtoms++;
- if (which&XkbKeyTypeNamesMask)
- nAtoms+= nTypes;
- if (which&XkbKTLevelNamesMask) {
- req->firstKTLevel= firstLvlType;
- req->nKTLevels= nLvlTypes;
- req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */
- nAtoms+= nLvlNames;
- }
- else req->firstKTLevel= req->nKTLevels= 0;
-
- if (which&XkbIndicatorNamesMask) {
- leds= req->indicators= (CARD32)changes->changed_indicators;
- nLEDs= _XkbCountBits(XkbNumIndicators,changes->changed_indicators);
- if (nLEDs>0)
- nAtoms+= nLEDs;
- else which&= ~XkbIndicatorNamesMask;
- }
- else req->indicators= 0;
-
- if (which&XkbVirtualModNamesMask) {
- vmods= req->virtualMods= changes->changed_vmods;
- nVMods= _XkbCountBits(XkbNumVirtualMods,
- (unsigned long)changes->changed_vmods);
- if (nVMods>0)
- nAtoms+= nVMods;
- else which&= ~XkbVirtualModNamesMask;
- }
- else req->virtualMods= 0;
-
- if (which&XkbGroupNamesMask) {
- groups= req->groupNames= changes->changed_groups;
- nGroups= _XkbCountBits(XkbNumKbdGroups,
- (unsigned long)changes->changed_groups);
- if (nGroups>0)
- nAtoms+= nGroups;
- else which&= ~XkbGroupNamesMask;
- }
- else req->groupNames= 0;
-
- if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
- firstKey= req->firstKey;
- nKeys= req->nKeys;
- nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */
- }
- else which&= ~XkbKeyNamesMask;
-
- if (which&XkbKeyAliasesMask) {
- nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0);
- if (nKA>0)
- nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */
- else which&= ~XkbKeyAliasesMask;
- }
-
- if (which&XkbRGNamesMask) {
- nRG= names->num_rg;
- if (nRG>0)
- nAtoms+= nRG;
- else which&= ~XkbRGNamesMask;
- }
-
- req->which= which;
- req->nRadioGroups= nRG;
- req->length+= (nAtoms*4)/4;
-
- if (which&XkbKeycodesNameMask)
- Data32(dpy,(long *)&names->keycodes,4);
- if (which&XkbGeometryNameMask)
- Data32(dpy,(long *)&names->geometry,4);
- if (which&XkbSymbolsNameMask)
- Data32(dpy,(long *)&names->symbols,4);
- if (which&XkbPhysSymbolsNameMask)
- Data32(dpy,(long *)&names->phys_symbols,4);
- if (which&XkbTypesNameMask)
- Data32(dpy,(long *)&names->types,4);
- if (which&XkbCompatNameMask)
- Data32(dpy,(long *)&names->compat,4);
- if (which&XkbKeyTypeNamesMask) {
- register int i;
- register XkbKeyTypePtr type;
- type= &xkb->map->types[firstType];
- for (i=0;i<nTypes;i++,type++) {
- Data32(dpy,(long *)&type->name,4);
- }
- }
- if (which&XkbKTLevelNamesMask) {
- XkbKeyTypePtr type;
- int i;
- char *tmp;
-
- BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes));
- type = &xkb->map->types[firstLvlType];
- for (i=0;i<nLvlTypes;i++,type++) {
- *tmp++ = type->num_levels;
- }
- type = &xkb->map->types[firstLvlType];
- for (i=0;i<nLvlTypes;i++,type++) {
- if (type->level_names!=NULL)
- Data32(dpy,(long *)type->level_names,type->num_levels*4);
- }
- }
- if (which&XkbIndicatorNamesMask)
- _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators);
- if (which&XkbVirtualModNamesMask)
- _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods);
- if (which&XkbGroupNamesMask)
- _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups);
- if (which&XkbKeyNamesMask) {
-#ifdef WORD64
- char *tmp;
- register int i;
- BufAlloc(char *,tmp,nKeys*4);
- for (i=0;i<nKeys;i++,tmp+= 4) {
- tmp[0]= names->keys[firstKey+i].name[0];
- tmp[1]= names->keys[firstKey+i].name[1];
- tmp[2]= names->keys[firstKey+i].name[2];
- tmp[3]= names->keys[firstKey+i].name[3];
- }
-#else
- Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength);
-#endif
- }
- if (which&XkbKeyAliasesMask) {
-#ifdef WORD64
- char *tmp;
- register int i;
- BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2);
- for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength) {
- tmp[0]= names->key_aliases[i].real[0];
- tmp[1]= names->key_aliases[i].real[1];
- tmp[2]= names->key_aliases[i].real[2];
- tmp[3]= names->key_aliases[i].real[3];
- tmp[4]= names->key_aliases[i].alias[0];
- tmp[5]= names->key_aliases[i].alias[1];
- tmp[6]= names->key_aliases[i].alias[2];
- tmp[7]= names->key_aliases[i].alias[3];
- }
-#else
- Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2);
-#endif
- }
- if (which&XkbRGNamesMask) {
- Data32(dpy,(long *)names->radio_groups,nRG*4);
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-void
-XkbNoteNameChanges( XkbNameChangesPtr old,
- XkbNamesNotifyEvent * new,
- unsigned int wanted)
-{
-int first,last,old_last,new_last;
-
- wanted&= new->changed;
- if ((old==NULL)||(new==NULL)||(wanted==0))
- return;
- if (wanted&XkbKeyTypeNamesMask) {
- if (old->changed&XkbKeyTypeNamesMask) {
- new_last= (new->first_type+new->num_types-1);
- old_last= (old->first_type+old->num_types-1);
-
- if (new->first_type<old->first_type)
- first= new->first_type;
- else first= old->first_type;
-
- if (old_last>new_last)
- last= old_last;
- else last= new_last;
-
- old->first_type= first;
- old->num_types= (last-first)+1;
- }
- else {
- old->first_type= new->first_type;
- old->num_types= new->num_types;
- }
- }
- if (wanted&XkbKTLevelNamesMask) {
- if (old->changed&XkbKTLevelNamesMask) {
- new_last= (new->first_lvl+new->num_lvls-1);
- old_last= (old->first_lvl+old->num_lvls-1);
-
- if (new->first_lvl<old->first_lvl)
- first= new->first_lvl;
- else first= old->first_lvl;
-
- if (old_last>new_last)
- last= old_last;
- else last= new_last;
-
- old->first_lvl= first;
- old->num_lvls= (last-first)+1;
- }
- else {
- old->first_lvl= new->first_lvl;
- old->num_lvls= new->num_lvls;
- }
- }
- if (wanted&XkbIndicatorNamesMask) {
- if (old->changed&XkbIndicatorNamesMask)
- old->changed_indicators|= new->changed_indicators;
- else old->changed_indicators= new->changed_indicators;
- }
- if (wanted&XkbKeyNamesMask) {
- if (old->changed&XkbKeyNamesMask) {
- new_last= (new->first_key+new->num_keys-1);
- old_last= (old->first_key+old->num_keys-1);
-
- first= old->first_key;
-
- if (new->first_key<old->first_key)
- first= new->first_key;
- if (old_last>new_last)
- new_last= old_last;
-
- old->first_key= first;
- old->num_keys= (new_last-first)+1;
- }
- else {
- old->first_key= new->first_key;
- old->num_keys= new->num_keys;
- }
- }
- if (wanted&XkbVirtualModNamesMask) {
- if (old->changed&XkbVirtualModNamesMask)
- old->changed_vmods|= new->changed_vmods;
- else old->changed_vmods= new->changed_vmods;
- }
- if (wanted&XkbGroupNamesMask) {
- if (old->changed&XkbGroupNamesMask)
- old->changed_groups|= new->changed_groups;
- else old->changed_groups= new->changed_groups;
- }
- if (wanted&XkbRGNamesMask)
- old->num_rg= new->num_radio_groups;
- if (wanted&XkbKeyAliasesMask)
- old->num_aliases= new->num_aliases;
- old->changed|= wanted;
- return;
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_MAP_READERS
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+
+static Status
+_XkbReadAtoms( XkbReadBufferPtr buf,
+ Atom * atoms,
+ int maxAtoms,
+ CARD32 present)
+{
+register int i,bit;
+
+ for (i=0,bit=1;(i<maxAtoms)&&(present);i++,bit<<=1) {
+ if (present&bit) {
+ if (!_XkbReadBufferCopy32(buf,(long *)&atoms[i],1))
+ return BadLength;
+ present&= ~bit;
+ }
+ }
+ return Success;
+}
+
+Status
+_XkbReadGetNamesReply( Display * dpy,
+ xkbGetNamesReply * rep,
+ XkbDescPtr xkb,
+ int * nread_rtrn)
+{
+ int i,len;
+ XkbReadBufferRec buf;
+ register XkbNamesPtr names;
+
+ if ( xkb->device_spec == XkbUseCoreKbd )
+ xkb->device_spec = rep->deviceID;
+
+ if ((xkb->names==NULL)&&
+ (XkbAllocNames(xkb,rep->which,
+ rep->nRadioGroups,rep->nKeyAliases)!=Success)) {
+ return BadAlloc;
+ }
+ names= xkb->names;
+ if (rep->length==0)
+ return Success;
+
+ if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
+ return BadAlloc;
+ if (nread_rtrn)
+ *nread_rtrn= (int)rep->length*4;
+
+ if ((rep->which&XkbKeycodesNameMask)&&
+ (!_XkbReadBufferCopy32(&buf,(long *)&names->keycodes,1)))
+ goto BAILOUT;
+ if ((rep->which&XkbGeometryNameMask)&&
+ (!_XkbReadBufferCopy32(&buf,(long *)&names->geometry,1)))
+ goto BAILOUT;
+ if ((rep->which&XkbSymbolsNameMask)&&
+ (!_XkbReadBufferCopy32(&buf,(long *)&names->symbols,1)))
+ goto BAILOUT;
+ if ((rep->which&XkbPhysSymbolsNameMask)&&
+ (!_XkbReadBufferCopy32(&buf,(long *)&names->phys_symbols,1)))
+ goto BAILOUT;
+ if ((rep->which&XkbTypesNameMask)&&
+ (!_XkbReadBufferCopy32(&buf,(long *)&names->types,1)))
+ goto BAILOUT;
+ if ((rep->which&XkbCompatNameMask)&&
+ (!_XkbReadBufferCopy32(&buf,(long *)&names->compat,1)))
+ goto BAILOUT;
+
+ if ( rep->which & XkbKeyTypeNamesMask ) {
+ XkbClientMapPtr map= xkb->map;
+ XkbKeyTypePtr type;
+
+ len= rep->nTypes*4;
+ if (map!=NULL) {
+ type= map->types;
+ for (i=0;(i<map->num_types)&&(i<rep->nTypes);i++,type++) {
+ if (!_XkbReadBufferCopy32(&buf,(long *)&type->name,1))
+ goto BAILOUT;
+ len-= 4;
+ }
+ }
+ if ((len>0)&&(!_XkbSkipReadBufferData(&buf,len)))
+ goto BAILOUT;
+ }
+ if ( rep->which&XkbKTLevelNamesMask ) {
+ CARD8 *nLevels;
+ XkbClientMapPtr map= xkb->map;
+ XkbKeyTypePtr type;
+
+ nLevels=(CARD8*)_XkbGetReadBufferPtr(&buf,XkbPaddedSize(rep->nTypes));
+ if (nLevels==NULL)
+ goto BAILOUT;
+ if (map!=NULL) {
+ type= map->types;
+ for (i=0;i<(int)rep->nTypes;i++,type++) {
+ if (i>=map->num_types) {
+ if (!_XkbSkipReadBufferData(&buf,nLevels[i]*4))
+ goto BAILOUT;
+ continue;
+ }
+ if ((nLevels[i]>0)&&(nLevels[i]!=type->num_levels)) {
+ goto BAILOUT;
+ }
+ if (type->level_names!=NULL)
+ Xfree(type->level_names);
+ if (nLevels[i]==0) {
+ type->level_names= NULL;
+ continue;
+ }
+ type->level_names= _XkbTypedCalloc(nLevels[i],Atom);
+ if (type->level_names!=NULL) {
+ if (!_XkbReadBufferCopy32(&buf,(long *)type->level_names,
+ nLevels[i]))
+ goto BAILOUT;
+ }
+ else {
+ _XkbSkipReadBufferData(&buf,nLevels[i]*4);
+ }
+ }
+ }
+ else {
+ for (i=0;i<(int)rep->nTypes;i++) {
+ _XkbSkipReadBufferData(&buf,nLevels[i]*4);
+ }
+ }
+ }
+ if (rep->which & XkbIndicatorNamesMask) {
+ if (_XkbReadAtoms(&buf,names->indicators,XkbNumIndicators,
+ rep->indicators)!=Success)
+ goto BAILOUT;
+ }
+ if ( rep->which&XkbVirtualModNamesMask ) {
+ if (_XkbReadAtoms(&buf,names->vmods,XkbNumVirtualMods,
+ (CARD32)rep->virtualMods)!=Success)
+ goto BAILOUT;
+ }
+ if ( rep->which&XkbGroupNamesMask ) {
+ if (_XkbReadAtoms(&buf,names->groups,XkbNumKbdGroups,
+ (CARD32)rep->groupNames)!=Success)
+ goto BAILOUT;
+ }
+ if ( rep->which&XkbKeyNamesMask ) {
+ if (names->keys==NULL) {
+ int nKeys;
+ if (xkb->max_key_code==0) {
+ xkb->min_key_code= rep->minKeyCode;
+ xkb->max_key_code= rep->maxKeyCode;
+ }
+ nKeys= xkb->max_key_code+1;
+ names->keys= _XkbTypedCalloc(nKeys,XkbKeyNameRec);
+ }
+ if (names->keys!=NULL) {
+ if (!_XkbCopyFromReadBuffer(&buf,
+ (char *)&names->keys[rep->firstKey],
+ rep->nKeys*XkbKeyNameLength))
+ goto BAILOUT;
+ }
+ else _XkbSkipReadBufferData(&buf,rep->nKeys*XkbKeyNameLength);
+ }
+ if ( rep->which&XkbKeyAliasesMask && (rep->nKeyAliases>0) ) {
+ if (XkbAllocNames(xkb,XkbKeyAliasesMask,0,rep->nKeyAliases)!=Success)
+ goto BAILOUT;
+ if (!_XkbCopyFromReadBuffer(&buf,(char *)names->key_aliases,
+ rep->nKeyAliases*XkbKeyNameLength*2))
+ goto BAILOUT;
+ }
+ if ( rep->which&XkbRGNamesMask ) {
+ if (rep->nRadioGroups>0) {
+ Atom *rgNames;
+
+ if (names->radio_groups==NULL)
+ names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups,Atom);
+ else if (names->num_rg<rep->nRadioGroups) {
+ names->radio_groups = _XkbTypedRealloc(names->radio_groups,
+ rep->nRadioGroups,
+ Atom);
+ }
+ rgNames= names->radio_groups;
+ if (!rgNames) {
+ goto BAILOUT;
+ }
+ if (!_XkbReadBufferCopy32(&buf,(long *)rgNames,rep->nRadioGroups))
+ goto BAILOUT;
+ names->num_rg= rep->nRadioGroups;
+ }
+ else if (names->num_rg>0) {
+ names->num_rg= 0;
+ Xfree(names->radio_groups);
+ }
+ }
+ len= _XkbFreeReadBuffer(&buf);
+ if (len!=0) return BadLength;
+ else return Success;
+BAILOUT:
+ _XkbFreeReadBuffer(&buf);
+ return BadLength;
+}
+
+Status
+XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb)
+{
+ register xkbGetNamesReq *req;
+ xkbGetNamesReply rep;
+ Status status;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ if (!xkb->names) {
+ xkb->names = _XkbTypedCalloc(1,XkbNamesRec);
+ if (!xkb->names) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadAlloc;
+ }
+ }
+ GetReq(kbGetNames, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetNames;
+ req->deviceSpec = xkb->device_spec;
+ req->which = which;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadImplementation;
+ }
+
+ status = _XkbReadGetNamesReply(dpy,&rep,xkb,NULL);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+/***====================================================================***/
+
+static int
+_XkbCountBits(int nBitsMax,unsigned long mask)
+{
+register unsigned long y, nBits;
+
+ y = (mask >> 1) &033333333333;
+ y = mask - y - ((y >>1) & 033333333333);
+ nBits = ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
+
+ /* nBitsMax really means max+1 */
+ return (nBits < nBitsMax) ? nBits : (nBitsMax - 1);
+}
+
+static CARD32
+_XkbCountAtoms(Atom *atoms,int maxAtoms,int *count)
+{
+register unsigned int i,bit,nAtoms;
+register CARD32 atomsPresent;
+
+ for (i=nAtoms=atomsPresent=0,bit=1;i<maxAtoms;i++,bit<<=1) {
+ if (atoms[i]!=None) {
+ atomsPresent|= bit;
+ nAtoms++;
+ }
+ }
+ if (count)
+ *count= nAtoms;
+ return atomsPresent;
+}
+
+static void
+_XkbCopyAtoms(Display *dpy,Atom *atoms,CARD32 mask,int maxAtoms)
+{
+register unsigned int i,bit;
+
+ for (i=0,bit=1;i<maxAtoms;i++,bit<<=1) {
+ if (mask&bit)
+ Data32(dpy,&atoms[i],4);
+ }
+ return;
+}
+
+Bool
+XkbSetNames( Display * dpy,
+ unsigned int which,
+ unsigned int firstType,
+ unsigned int nTypes,
+ XkbDescPtr xkb)
+{
+ register xkbSetNamesReq *req;
+ int nLvlNames = 0;
+ XkbInfoPtr xkbi;
+ XkbNamesPtr names;
+ unsigned firstLvlType,nLvlTypes;
+ int nVMods,nLEDs,nRG,nKA,nGroups;
+ int nKeys=0,firstKey=0,nAtoms;
+ CARD32 leds,vmods,groups;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ if ((!xkb)||(!xkb->names))
+ return False;
+ firstLvlType= firstType;
+ nLvlTypes= nTypes;
+ if (nTypes<1)
+ which&= ~(XkbKTLevelNamesMask|XkbKeyTypeNamesMask);
+ else if (firstType<=XkbLastRequiredType) {
+ int adjust;
+ adjust= XkbLastRequiredType-firstType+1;
+ firstType+= adjust;
+ nTypes-= adjust;
+ if (nTypes<1)
+ which&= ~XkbKeyTypeNamesMask;
+ }
+ names= xkb->names;
+ if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) {
+ register int i;
+ XkbKeyTypePtr type;
+ if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)||
+ (firstType+nTypes>xkb->map->num_types)||
+ (firstLvlType+nLvlTypes>xkb->map->num_types))
+ return False;
+ if (which&XkbKTLevelNamesMask) {
+ type= &xkb->map->types[firstLvlType];
+ for (i=nLvlNames=0;i<nLvlTypes;i++,type++) {
+ if (type->level_names!=NULL)
+ nLvlNames+= type->num_levels;
+ }
+ }
+ }
+
+ nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetNames, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSetNames;
+ req->deviceSpec = xkb->device_spec;
+ req->firstType = firstType;
+ req->nTypes = nTypes;
+ req->firstKey = xkb->min_key_code;
+ req->nKeys = xkb->max_key_code-xkb->min_key_code+1;
+
+ if (which&XkbKeycodesNameMask)
+ nAtoms++;
+ if (which&XkbGeometryNameMask)
+ nAtoms++;
+ if (which&XkbSymbolsNameMask)
+ nAtoms++;
+ if (which&XkbPhysSymbolsNameMask)
+ nAtoms++;
+ if (which&XkbTypesNameMask)
+ nAtoms++;
+ if (which&XkbCompatNameMask)
+ nAtoms++;
+ if (which&XkbKeyTypeNamesMask)
+ nAtoms+= nTypes;
+ if (which&XkbKTLevelNamesMask) {
+ req->firstKTLevel= firstLvlType;
+ req->nKTLevels= nLvlTypes;
+ req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */
+ nAtoms+= nLvlNames;
+ }
+ else req->firstKTLevel= req->nKTLevels= 0;
+
+ if (which&XkbIndicatorNamesMask) {
+ req->indicators= leds=
+ _XkbCountAtoms(names->indicators,XkbNumIndicators,&nLEDs);
+ if (nLEDs>0)
+ nAtoms+= nLEDs;
+ else which&= ~XkbIndicatorNamesMask;
+ }
+ else req->indicators= leds= 0;
+
+ if (which&XkbVirtualModNamesMask) {
+ vmods= req->virtualMods= (CARD16)
+ _XkbCountAtoms(names->vmods,XkbNumVirtualMods,&nVMods);
+ if (nVMods>0)
+ nAtoms+= nVMods;
+ else which&= ~XkbVirtualModNamesMask;
+ }
+ else vmods= req->virtualMods= 0;
+
+ if (which&XkbGroupNamesMask) {
+ groups= req->groupNames= (CARD8)
+ _XkbCountAtoms(names->groups,XkbNumKbdGroups,&nGroups);
+ if (nGroups>0)
+ nAtoms+= nGroups;
+ else which&= ~XkbGroupNamesMask;
+ }
+ else groups= req->groupNames= 0;
+
+ if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
+ firstKey= req->firstKey;
+ nKeys= req->nKeys;
+ nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */
+ }
+ else which&= ~XkbKeyNamesMask;
+
+ if (which&XkbKeyAliasesMask) {
+ nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0);
+ if (nKA>0) {
+ req->nKeyAliases= nKA;
+ nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */
+ }
+ else {
+ which&= ~XkbKeyAliasesMask;
+ req->nKeyAliases = 0;
+ }
+ }
+ else req->nKeyAliases= 0;
+
+ if (which&XkbRGNamesMask) {
+ nRG= names->num_rg;
+ if (nRG>0)
+ nAtoms+= nRG;
+ else which&= ~XkbRGNamesMask;
+ }
+
+ req->which= which;
+ req->nRadioGroups= nRG;
+ req->length+= (nAtoms*4)/4;
+
+ if (which&XkbKeycodesNameMask)
+ Data32(dpy,(long *)&names->keycodes,4);
+ if (which&XkbGeometryNameMask)
+ Data32(dpy,(long *)&names->geometry,4);
+ if (which&XkbSymbolsNameMask)
+ Data32(dpy,(long *)&names->symbols,4);
+ if (which&XkbPhysSymbolsNameMask)
+ Data32(dpy,(long *)&names->phys_symbols,4);
+ if (which&XkbTypesNameMask)
+ Data32(dpy,(long *)&names->types,4);
+ if (which&XkbCompatNameMask)
+ Data32(dpy,(long *)&names->compat,4);
+ if (which&XkbKeyTypeNamesMask) {
+ register int i;
+ register XkbKeyTypePtr type;
+ type= &xkb->map->types[firstType];
+ for (i=0;i<nTypes;i++,type++) {
+ Data32(dpy,(long *)&type->name,4);
+ }
+ }
+ if (which&XkbKTLevelNamesMask) {
+ XkbKeyTypePtr type;
+ int i;
+ char *tmp;
+
+ BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes));
+ type = &xkb->map->types[firstLvlType];
+ for (i=0;i<nLvlTypes;i++,type++) {
+ *tmp++ = type->num_levels;
+ }
+ type = &xkb->map->types[firstLvlType];
+ for (i=0;i<nLvlTypes;i++,type++) {
+ if (type->level_names!=NULL)
+ Data32(dpy,(long *)type->level_names,type->num_levels*4);
+ }
+ }
+ if (which&XkbIndicatorNamesMask)
+ _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators);
+ if (which&XkbVirtualModNamesMask)
+ _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods);
+ if (which&XkbGroupNamesMask)
+ _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups);
+ if (which&XkbKeyNamesMask) {
+#ifdef WORD64
+ char *tmp;
+ register int i;
+ BufAlloc(char *,tmp,nKeys*XkbKeyNameLength);
+ for (i=0;i<nKeys;i++,tmp+= XkbKeyNameLength) {
+ tmp[0]= names->keys[firstKey+i].name[0];
+ tmp[1]= names->keys[firstKey+i].name[1];
+ tmp[2]= names->keys[firstKey+i].name[2];
+ tmp[3]= names->keys[firstKey+i].name[3];
+ }
+#else
+ Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength);
+#endif
+ }
+ if (which&XkbKeyAliasesMask) {
+#ifdef WORD64
+ char *tmp;
+ register int i;
+ BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2);
+ for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength) {
+ tmp[0]= names->key_aliases[i].real[0];
+ tmp[1]= names->key_aliases[i].real[1];
+ tmp[2]= names->key_aliases[i].real[2];
+ tmp[3]= names->key_aliases[i].real[3];
+ tmp[4]= names->key_aliases[i].alias[0];
+ tmp[5]= names->key_aliases[i].alias[1];
+ tmp[6]= names->key_aliases[i].alias[2];
+ tmp[7]= names->key_aliases[i].alias[3];
+ }
+#else
+ Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2);
+#endif
+ }
+ if (which&XkbRGNamesMask) {
+ Data32(dpy,(long *)names->radio_groups,nRG*4);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes)
+{
+ register xkbSetNamesReq *req;
+ int nLvlNames = 0;
+ XkbInfoPtr xkbi;
+ XkbNamesPtr names;
+ unsigned which,firstType,nTypes;
+ unsigned firstLvlType,nLvlTypes;
+ int nVMods,nLEDs,nRG,nKA,nGroups;
+ int nKeys=0,firstKey=0,nAtoms;
+ CARD32 leds=0,vmods=0,groups=0;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ if ((!xkb)||(!xkb->names)||(!changes))
+ return False;
+ which= changes->changed;
+ firstType= changes->first_type;
+ nTypes= changes->num_types;
+ firstLvlType= changes->first_lvl;;
+ nLvlTypes= changes->num_lvls;
+ if (which&XkbKeyTypeNamesMask) {
+ if (nTypes<1)
+ which&= ~XkbKeyTypeNamesMask;
+ else if (firstType<=XkbLastRequiredType) {
+ int adjust;
+ adjust= XkbLastRequiredType-firstType+1;
+ firstType+= adjust;
+ nTypes-= adjust;
+ if (nTypes<1)
+ which&= ~XkbKeyTypeNamesMask;
+ }
+ }
+ else firstType= nTypes= 0;
+
+ if (which&XkbKTLevelNamesMask) {
+ if (nLvlTypes<1)
+ which&= ~XkbKTLevelNamesMask;
+ }
+ else firstLvlType= nLvlTypes= 0;
+
+ names= xkb->names;
+ if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) {
+ register int i;
+ XkbKeyTypePtr type;
+ if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)||
+ (firstType+nTypes>xkb->map->num_types)||
+ (firstLvlType+nLvlTypes>xkb->map->num_types))
+ return False;
+ if (which&XkbKTLevelNamesMask) {
+ type= &xkb->map->types[firstLvlType];
+ for (i=nLvlNames=0;i<nLvlTypes;i++,type++) {
+ if (type->level_names!=NULL)
+ nLvlNames+= type->num_levels;
+ }
+ }
+ }
+
+ if (changes->num_keys<1)
+ which&= ~XkbKeyNamesMask;
+ if ((which&XkbKeyNamesMask)==0)
+ changes->first_key= changes->num_keys= 0;
+ else if ((changes->first_key<xkb->min_key_code)||
+ (changes->first_key+changes->num_keys>xkb->max_key_code)) {
+ return False;
+ }
+
+ if ((which&XkbVirtualModNamesMask)==0)
+ changes->changed_vmods= 0;
+ else if (changes->changed_vmods==0)
+ which&= ~XkbVirtualModNamesMask;
+
+ if ((which&XkbIndicatorNamesMask)==0)
+ changes->changed_indicators= 0;
+ else if (changes->changed_indicators==0)
+ which&= ~XkbIndicatorNamesMask;
+
+ if ((which&XkbGroupNamesMask)==0)
+ changes->changed_groups= 0;
+ else if (changes->changed_groups==0)
+ which&= ~XkbGroupNamesMask;
+
+ nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetNames, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSetNames;
+ req->deviceSpec = xkb->device_spec;
+ req->firstType = firstType;
+ req->nTypes = nTypes;
+ req->firstKey = changes->first_key;
+ req->nKeys = changes->num_keys;
+
+ if (which&XkbKeycodesNameMask)
+ nAtoms++;
+ if (which&XkbGeometryNameMask)
+ nAtoms++;
+ if (which&XkbSymbolsNameMask)
+ nAtoms++;
+ if (which&XkbPhysSymbolsNameMask)
+ nAtoms++;
+ if (which&XkbTypesNameMask)
+ nAtoms++;
+ if (which&XkbCompatNameMask)
+ nAtoms++;
+ if (which&XkbKeyTypeNamesMask)
+ nAtoms+= nTypes;
+ if (which&XkbKTLevelNamesMask) {
+ req->firstKTLevel= firstLvlType;
+ req->nKTLevels= nLvlTypes;
+ req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */
+ nAtoms+= nLvlNames;
+ }
+ else req->firstKTLevel= req->nKTLevels= 0;
+
+ if (which&XkbIndicatorNamesMask) {
+ leds= req->indicators= (CARD32)changes->changed_indicators;
+ nLEDs= _XkbCountBits(XkbNumIndicators,changes->changed_indicators);
+ if (nLEDs>0)
+ nAtoms+= nLEDs;
+ else which&= ~XkbIndicatorNamesMask;
+ }
+ else req->indicators= 0;
+
+ if (which&XkbVirtualModNamesMask) {
+ vmods= req->virtualMods= changes->changed_vmods;
+ nVMods= _XkbCountBits(XkbNumVirtualMods,
+ (unsigned long)changes->changed_vmods);
+ if (nVMods>0)
+ nAtoms+= nVMods;
+ else which&= ~XkbVirtualModNamesMask;
+ }
+ else req->virtualMods= 0;
+
+ if (which&XkbGroupNamesMask) {
+ groups= req->groupNames= changes->changed_groups;
+ nGroups= _XkbCountBits(XkbNumKbdGroups,
+ (unsigned long)changes->changed_groups);
+ if (nGroups>0)
+ nAtoms+= nGroups;
+ else which&= ~XkbGroupNamesMask;
+ }
+ else req->groupNames= 0;
+
+ if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
+ firstKey= req->firstKey;
+ nKeys= req->nKeys;
+ nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */
+ }
+ else which&= ~XkbKeyNamesMask;
+
+ if (which&XkbKeyAliasesMask) {
+ nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0);
+ if (nKA>0)
+ nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */
+ else which&= ~XkbKeyAliasesMask;
+ }
+
+ if (which&XkbRGNamesMask) {
+ nRG= names->num_rg;
+ if (nRG>0)
+ nAtoms+= nRG;
+ else which&= ~XkbRGNamesMask;
+ }
+
+ req->which= which;
+ req->nRadioGroups= nRG;
+ req->length+= (nAtoms*4)/4;
+
+ if (which&XkbKeycodesNameMask)
+ Data32(dpy,(long *)&names->keycodes,4);
+ if (which&XkbGeometryNameMask)
+ Data32(dpy,(long *)&names->geometry,4);
+ if (which&XkbSymbolsNameMask)
+ Data32(dpy,(long *)&names->symbols,4);
+ if (which&XkbPhysSymbolsNameMask)
+ Data32(dpy,(long *)&names->phys_symbols,4);
+ if (which&XkbTypesNameMask)
+ Data32(dpy,(long *)&names->types,4);
+ if (which&XkbCompatNameMask)
+ Data32(dpy,(long *)&names->compat,4);
+ if (which&XkbKeyTypeNamesMask) {
+ register int i;
+ register XkbKeyTypePtr type;
+ type= &xkb->map->types[firstType];
+ for (i=0;i<nTypes;i++,type++) {
+ Data32(dpy,(long *)&type->name,4);
+ }
+ }
+ if (which&XkbKTLevelNamesMask) {
+ XkbKeyTypePtr type;
+ int i;
+ char *tmp;
+
+ BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes));
+ type = &xkb->map->types[firstLvlType];
+ for (i=0;i<nLvlTypes;i++,type++) {
+ *tmp++ = type->num_levels;
+ }
+ type = &xkb->map->types[firstLvlType];
+ for (i=0;i<nLvlTypes;i++,type++) {
+ if (type->level_names!=NULL)
+ Data32(dpy,(long *)type->level_names,type->num_levels*4);
+ }
+ }
+ if (which&XkbIndicatorNamesMask)
+ _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators);
+ if (which&XkbVirtualModNamesMask)
+ _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods);
+ if (which&XkbGroupNamesMask)
+ _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups);
+ if (which&XkbKeyNamesMask) {
+#ifdef WORD64
+ char *tmp;
+ register int i;
+ BufAlloc(char *,tmp,nKeys*4);
+ for (i=0;i<nKeys;i++,tmp+= 4) {
+ tmp[0]= names->keys[firstKey+i].name[0];
+ tmp[1]= names->keys[firstKey+i].name[1];
+ tmp[2]= names->keys[firstKey+i].name[2];
+ tmp[3]= names->keys[firstKey+i].name[3];
+ }
+#else
+ Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength);
+#endif
+ }
+ if (which&XkbKeyAliasesMask) {
+#ifdef WORD64
+ char *tmp;
+ register int i;
+ BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2);
+ for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength) {
+ tmp[0]= names->key_aliases[i].real[0];
+ tmp[1]= names->key_aliases[i].real[1];
+ tmp[2]= names->key_aliases[i].real[2];
+ tmp[3]= names->key_aliases[i].real[3];
+ tmp[4]= names->key_aliases[i].alias[0];
+ tmp[5]= names->key_aliases[i].alias[1];
+ tmp[6]= names->key_aliases[i].alias[2];
+ tmp[7]= names->key_aliases[i].alias[3];
+ }
+#else
+ Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2);
+#endif
+ }
+ if (which&XkbRGNamesMask) {
+ Data32(dpy,(long *)names->radio_groups,nRG*4);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+void
+XkbNoteNameChanges( XkbNameChangesPtr old,
+ XkbNamesNotifyEvent * new,
+ unsigned int wanted)
+{
+int first,last,old_last,new_last;
+
+ wanted&= new->changed;
+ if ((old==NULL)||(new==NULL)||(wanted==0))
+ return;
+ if (wanted&XkbKeyTypeNamesMask) {
+ if (old->changed&XkbKeyTypeNamesMask) {
+ new_last= (new->first_type+new->num_types-1);
+ old_last= (old->first_type+old->num_types-1);
+
+ if (new->first_type<old->first_type)
+ first= new->first_type;
+ else first= old->first_type;
+
+ if (old_last>new_last)
+ last= old_last;
+ else last= new_last;
+
+ old->first_type= first;
+ old->num_types= (last-first)+1;
+ }
+ else {
+ old->first_type= new->first_type;
+ old->num_types= new->num_types;
+ }
+ }
+ if (wanted&XkbKTLevelNamesMask) {
+ if (old->changed&XkbKTLevelNamesMask) {
+ new_last= (new->first_lvl+new->num_lvls-1);
+ old_last= (old->first_lvl+old->num_lvls-1);
+
+ if (new->first_lvl<old->first_lvl)
+ first= new->first_lvl;
+ else first= old->first_lvl;
+
+ if (old_last>new_last)
+ last= old_last;
+ else last= new_last;
+
+ old->first_lvl= first;
+ old->num_lvls= (last-first)+1;
+ }
+ else {
+ old->first_lvl= new->first_lvl;
+ old->num_lvls= new->num_lvls;
+ }
+ }
+ if (wanted&XkbIndicatorNamesMask) {
+ if (old->changed&XkbIndicatorNamesMask)
+ old->changed_indicators|= new->changed_indicators;
+ else old->changed_indicators= new->changed_indicators;
+ }
+ if (wanted&XkbKeyNamesMask) {
+ if (old->changed&XkbKeyNamesMask) {
+ new_last= (new->first_key+new->num_keys-1);
+ old_last= (old->first_key+old->num_keys-1);
+
+ first= old->first_key;
+
+ if (new->first_key<old->first_key)
+ first= new->first_key;
+ if (old_last>new_last)
+ new_last= old_last;
+
+ old->first_key= first;
+ old->num_keys= (new_last-first)+1;
+ }
+ else {
+ old->first_key= new->first_key;
+ old->num_keys= new->num_keys;
+ }
+ }
+ if (wanted&XkbVirtualModNamesMask) {
+ if (old->changed&XkbVirtualModNamesMask)
+ old->changed_vmods|= new->changed_vmods;
+ else old->changed_vmods= new->changed_vmods;
+ }
+ if (wanted&XkbGroupNamesMask) {
+ if (old->changed&XkbGroupNamesMask)
+ old->changed_groups|= new->changed_groups;
+ else old->changed_groups= new->changed_groups;
+ }
+ if (wanted&XkbRGNamesMask)
+ old->num_rg= new->num_radio_groups;
+ if (wanted&XkbKeyAliasesMask)
+ old->num_aliases= new->num_aliases;
+ old->changed|= wanted;
+ return;
+}
diff --git a/libX11/src/xkb/XKBRdBuf.c b/libX11/src/xkb/XKBRdBuf.c
index 6d1f6724b..fa7fa3af8 100644
--- a/libX11/src/xkb/XKBRdBuf.c
+++ b/libX11/src/xkb/XKBRdBuf.c
@@ -1,232 +1,230 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include "XKBlibint.h"
-#include <X11/extensions/XKBproto.h>
-
-/***====================================================================***/
-
-int
-_XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size)
-{
- if ((dpy!=NULL) && (buf!=NULL) && (size>0)) {
- buf->error= 0;
- buf->size= size;
- buf->start= buf->data= _XkbAlloc(size);
- if (buf->start) {
- _XRead(dpy, buf->start, size);
- return 1;
- }
- }
- return 0;
-}
-
-#define _XkbReadBufferDataLeft(b) (((b)->size)-((b)->data-(b)->start))
-
-int
-_XkbSkipReadBufferData(XkbReadBufferPtr from,int size)
-{
- if (size==0)
- return 1;
- if ((from==NULL)||(from->error)||(size<1)||
- (_XkbReadBufferDataLeft(from)<size))
- return 0;
- from->data+= size;
- return 1;
-}
-
-int
-_XkbCopyFromReadBuffer(XkbReadBufferPtr from,char *to,int size)
-{
- if (size==0)
- return 1;
- if ((from==NULL)||(from->error)||(to==NULL)||(size<1)||
- (_XkbReadBufferDataLeft(from)<size))
- return 0;
- memcpy(to,from->data,size);
- from->data+= size;
- return 1;
-}
-
-#ifdef XKB_FORCE_INT_KEYSYM
-int
-_XkbReadCopyKeySyms(int *wire,KeySym *to,int num_words)
-{
- while (num_words-->0) {
- *to++= *wire++;
- }
- return 1;
-}
-
-int
-_XkbReadBufferCopyKeySyms(XkbReadBufferPtr from,KeySym *to,int num_words)
-{
- if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from))
- return 0;
- _XkbReadCopyKeySyms((int *)from->data,to,num_words);
- from->data+= (4*num_words);
- return True;
-}
-
-int
-_XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len)
-{
-
- while (len-->0) {
- *to++= (CARD32)*from++;
- }
- return True;
-}
-#endif
-
-#ifdef LONG64
-int
-_XkbReadCopyData32(int *wire,long *to,int num_words)
-{
- while (num_words-->0) {
- *to++= *wire++;
- }
- return 1;
-}
-#endif
-#ifdef WORD64
-int
-_XkbReadCopyData32(int *from,long *lp,int num_words)
-{
-long *lpack;
-long mask32 = 0x00000000ffffffff;
-long maskw, i, bits;
-
- lpack = (long *)from;
- bits = 32;
-
- for (i=0;i<num_words;i++) {
- maskw = mask32 << bits;
- *lp++ = (*lpack & maskw) >> bits;
- bits = bits ^ 32;
- if (bits)
- lpack++;
- }
- return 1;
-}
-#endif
-
-#if defined(LONG64) || defined(WORD64)
-int
-_XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words)
-{
- if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from))
- return 0;
- _XkbReadCopyData32((int *)from->data,to,num_words);
- from->data+= (4*num_words);
- return True;
-}
-#endif
-
-#ifdef LONG64
-int
-_XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len)
-{
-
- while (len-->0) {
- *to++= (CARD32)*from++;
- }
- return True;
-}
-#endif /* LONG64 */
-
-#ifdef WORD64
-_XkbWriteCopyData32 Not Implemented Yet for sizeof(int)==8
-#endif
-
-char *
-_XkbPeekAtReadBuffer(XkbReadBufferPtr from,int size)
-{
- if ((from==NULL)||(from->error)||(size<1)||
- (_XkbReadBufferDataLeft(from)<size))
- return NULL;
- return from->data;
-}
-
-char *
-_XkbGetReadBufferPtr(XkbReadBufferPtr from,int size)
-{
-char *ptr;
- if ((from==NULL)||(from->error)||(size<1)||
- (_XkbReadBufferDataLeft(from)<size))
- return NULL;
- ptr= from->data;
- from->data+= size;
- return ptr;
-}
-
-
-int
-_XkbFreeReadBuffer(XkbReadBufferPtr buf)
-{
- if ((buf!=NULL) && (buf->start!=NULL)) {
- int left;
- left= (int)_XkbReadBufferDataLeft(buf);
- if (buf->start!=NULL)
- Xfree(buf->start);
- buf->size= 0;
- buf->start= buf->data= NULL;
- return left;
- }
- return 0;
-}
-
-Bool
-_XkbGetReadBufferCountedString(XkbReadBufferPtr buf,char **rtrn)
-{
-CARD16 len,*pLen;
-int left;
-char * str = NULL;
-
- if ((buf==NULL)||(buf->error)||((left=(int)_XkbReadBufferDataLeft(buf))<4))
- return False;
- pLen= (CARD16 *)buf->data;
- len= *pLen;
- if (len>0) {
- if (XkbPaddedSize(len+2)>left)
- return False;
- str= _XkbAlloc(len+1);
- if (str) {
- memcpy(str,&buf->data[2],len);
- str[len]= '\0';
- }
- }
- buf->data+= XkbPaddedSize(len+2);
- *rtrn= str;
- return True;
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 <stdio.h>
+#include "Xlibint.h"
+#include "XKBlibint.h"
+#include <X11/extensions/XKBproto.h>
+
+/***====================================================================***/
+
+int
+_XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size)
+{
+ if ((dpy!=NULL) && (buf!=NULL) && (size>0)) {
+ buf->error= 0;
+ buf->size= size;
+ buf->start= buf->data= _XkbAlloc(size);
+ if (buf->start) {
+ _XRead(dpy, buf->start, size);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+#define _XkbReadBufferDataLeft(b) (((b)->size)-((b)->data-(b)->start))
+
+int
+_XkbSkipReadBufferData(XkbReadBufferPtr from,int size)
+{
+ if (size==0)
+ return 1;
+ if ((from==NULL)||(from->error)||(size<1)||
+ (_XkbReadBufferDataLeft(from)<size))
+ return 0;
+ from->data+= size;
+ return 1;
+}
+
+int
+_XkbCopyFromReadBuffer(XkbReadBufferPtr from,char *to,int size)
+{
+ if (size==0)
+ return 1;
+ if ((from==NULL)||(from->error)||(to==NULL)||(size<1)||
+ (_XkbReadBufferDataLeft(from)<size))
+ return 0;
+ memcpy(to,from->data,size);
+ from->data+= size;
+ return 1;
+}
+
+#ifdef XKB_FORCE_INT_KEYSYM
+int
+_XkbReadCopyKeySyms(int *wire,KeySym *to,int num_words)
+{
+ while (num_words-->0) {
+ *to++= *wire++;
+ }
+ return 1;
+}
+
+int
+_XkbReadBufferCopyKeySyms(XkbReadBufferPtr from,KeySym *to,int num_words)
+{
+ if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from))
+ return 0;
+ _XkbReadCopyKeySyms((int *)from->data,to,num_words);
+ from->data+= (4*num_words);
+ return True;
+}
+
+int
+_XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len)
+{
+
+ while (len-->0) {
+ *to++= (CARD32)*from++;
+ }
+ return True;
+}
+#endif
+
+#ifdef LONG64
+int
+_XkbReadCopyData32(int *wire,long *to,int num_words)
+{
+ while (num_words-->0) {
+ *to++= *wire++;
+ }
+ return 1;
+}
+#endif
+#ifdef WORD64
+int
+_XkbReadCopyData32(int *from,long *lp,int num_words)
+{
+long *lpack;
+long mask32 = 0x00000000ffffffff;
+long maskw, i, bits;
+
+ lpack = (long *)from;
+ bits = 32;
+
+ for (i=0;i<num_words;i++) {
+ maskw = mask32 << bits;
+ *lp++ = (*lpack & maskw) >> bits;
+ bits = bits ^ 32;
+ if (bits)
+ lpack++;
+ }
+ return 1;
+}
+#endif
+
+#if defined(LONG64) || defined(WORD64)
+int
+_XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words)
+{
+ if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from))
+ return 0;
+ _XkbReadCopyData32((int *)from->data,to,num_words);
+ from->data+= (4*num_words);
+ return True;
+}
+#endif
+
+#ifdef LONG64
+int
+_XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len)
+{
+
+ while (len-->0) {
+ *to++= (CARD32)*from++;
+ }
+ return True;
+}
+#endif /* LONG64 */
+
+#ifdef WORD64
+_XkbWriteCopyData32 Not Implemented Yet for sizeof(int)==8
+#endif
+
+char *
+_XkbPeekAtReadBuffer(XkbReadBufferPtr from,int size)
+{
+ if ((from==NULL)||(from->error)||(size<1)||
+ (_XkbReadBufferDataLeft(from)<size))
+ return NULL;
+ return from->data;
+}
+
+char *
+_XkbGetReadBufferPtr(XkbReadBufferPtr from,int size)
+{
+char *ptr;
+ if ((from==NULL)||(from->error)||(size<1)||
+ (_XkbReadBufferDataLeft(from)<size))
+ return NULL;
+ ptr= from->data;
+ from->data+= size;
+ return ptr;
+}
+
+
+int
+_XkbFreeReadBuffer(XkbReadBufferPtr buf)
+{
+ if ((buf!=NULL) && (buf->start!=NULL)) {
+ int left;
+ left= (int)_XkbReadBufferDataLeft(buf);
+ if (buf->start!=NULL)
+ Xfree(buf->start);
+ buf->size= 0;
+ buf->start= buf->data= NULL;
+ return left;
+ }
+ return 0;
+}
+
+Bool
+_XkbGetReadBufferCountedString(XkbReadBufferPtr buf,char **rtrn)
+{
+CARD16 len,*pLen;
+int left;
+char * str = NULL;
+
+ if ((buf==NULL)||(buf->error)||((left=(int)_XkbReadBufferDataLeft(buf))<4))
+ return False;
+ pLen= (CARD16 *)buf->data;
+ len= *pLen;
+ if (len>0) {
+ if (XkbPaddedSize(len+2)>left)
+ return False;
+ str= _XkbAlloc(len+1);
+ if (str) {
+ memcpy(str,&buf->data[2],len);
+ str[len]= '\0';
+ }
+ }
+ buf->data+= XkbPaddedSize(len+2);
+ *rtrn= str;
+ return True;
+}
diff --git a/libX11/src/xkb/XKBSetGeom.c b/libX11/src/xkb/XKBSetGeom.c
index 4c632fdcf..5b9f5887c 100644
--- a/libX11/src/xkb/XKBSetGeom.c
+++ b/libX11/src/xkb/XKBSetGeom.c
@@ -1,464 +1,462 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 DEBUG
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#endif
-
-#define NEED_EVENTS
-#define NEED_REPLIES
-#include "Xlibint.h"
-#include "XKBlibint.h"
-#include <X11/extensions/XKBgeom.h>
-#include <X11/extensions/XKBproto.h>
-
-#define MINSHORT -32768
-#define MAXSHORT 32767
-
-/***====================================================================***/
-
-#define _SizeCountedString(s) ((s)?XkbPaddedSize(2+strlen(s)):4)
-
-static char *
-_WriteCountedString(char *wire,char *str)
-{
-CARD16 len,*pLen;
-
- len= (str?strlen(str):0);
- pLen= (CARD16 *)wire;
- *pLen= len;
- if (len && str)
- memcpy(&wire[2],str,len);
- wire+= XkbPaddedSize(len+2);
- return wire;
-}
-
-static int
-_SizeGeomProperties(XkbGeometryPtr geom)
-{
-register int i,size;
-XkbPropertyPtr prop;
-
- for (size=i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
- size+= _SizeCountedString(prop->name);
- size+= _SizeCountedString(prop->value);
- }
- return size;
-}
-
-static int
-_SizeGeomColors(XkbGeometryPtr geom)
-{
-register int i,size;
-register XkbColorPtr color;
-
- for (i=size=0,color=geom->colors;i<geom->num_colors;i++,color++) {
- size+= _SizeCountedString(color->spec);
- }
- return size;
-}
-
-static int
-_SizeGeomShapes(XkbGeometryPtr geom)
-{
-register int i,size;
-register XkbShapePtr shape;
-
- for (i=size=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) {
- register int n;
- register XkbOutlinePtr ol;
- size+= SIZEOF(xkbShapeWireDesc);
- for (n=0,ol=shape->outlines;n<shape->num_outlines;n++,ol++) {
- size+= SIZEOF(xkbOutlineWireDesc);
- size+= ol->num_points*SIZEOF(xkbPointWireDesc);
- }
- }
- return size;
-}
-
-static int
-_SizeGeomDoodads(int num_doodads,XkbDoodadPtr doodad)
-{
-register int i,size;
-
- for (i=size=0;i<num_doodads;i++,doodad++) {
- size+= SIZEOF(xkbAnyDoodadWireDesc);
- if (doodad->any.type==XkbTextDoodad) {
- size+= _SizeCountedString(doodad->text.text);
- size+= _SizeCountedString(doodad->text.font);
- }
- else if (doodad->any.type==XkbLogoDoodad) {
- size+= _SizeCountedString(doodad->logo.logo_name);
- }
- }
- return size;
-}
-
-static int
-_SizeGeomSections(XkbGeometryPtr geom)
-{
-register int i,size;
-XkbSectionPtr section;
-
- for (i=size=0,section=geom->sections;i<geom->num_sections;i++,section++) {
- size+= SIZEOF(xkbSectionWireDesc);
- if (section->rows) {
- int r;
- XkbRowPtr row;
- for (r=0,row=section->rows;r<section->num_rows;row++,r++) {
- size+= SIZEOF(xkbRowWireDesc);
- size+= row->num_keys*SIZEOF(xkbKeyWireDesc);
- }
- }
- if (section->doodads)
- size+= _SizeGeomDoodads(section->num_doodads,section->doodads);
- if (section->overlays) {
- int o;
- XkbOverlayPtr ol;
- for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) {
- int r;
- XkbOverlayRowPtr row;
- size+= SIZEOF(xkbOverlayWireDesc);
- for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
- size+= SIZEOF(xkbOverlayRowWireDesc);
- size+= row->num_keys*SIZEOF(xkbOverlayKeyWireDesc);
- }
- }
- }
- }
- return size;
-}
-
-static int
-_SizeGeomKeyAliases(XkbGeometryPtr geom)
-{
- return geom->num_key_aliases*(2*XkbKeyNameLength);
-}
-
-/***====================================================================***/
-
-static char *
-_WriteGeomProperties(char *wire,XkbGeometryPtr geom)
-{
-register int i;
-register XkbPropertyPtr prop;
-
- for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
- wire= _WriteCountedString(wire,prop->name);
- wire= _WriteCountedString(wire,prop->value);
- }
- return wire;
-}
-
-static char *
-_WriteGeomColors(char *wire,XkbGeometryPtr geom)
-{
-register int i;
-register XkbColorPtr color;
-
- for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) {
- wire= _WriteCountedString(wire,color->spec);
- }
- return wire;
-}
-
-static char *
-_WriteGeomShapes(char *wire,XkbGeometryPtr geom)
-{
-int i;
-XkbShapePtr shape;
-xkbShapeWireDesc * shapeWire;
-
- for (i=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) {
- register int o;
- XkbOutlinePtr ol;
- xkbOutlineWireDesc * olWire;
- shapeWire= (xkbShapeWireDesc *)wire;
- shapeWire->name= shape->name;
- shapeWire->nOutlines= shape->num_outlines;
- if (shape->primary!=NULL)
- shapeWire->primaryNdx= XkbOutlineIndex(shape,shape->primary);
- else shapeWire->primaryNdx= XkbNoShape;
- if (shape->approx!=NULL)
- shapeWire->approxNdx= XkbOutlineIndex(shape,shape->approx);
- else shapeWire->approxNdx= XkbNoShape;
- wire= (char *)&shapeWire[1];
- for (o=0,ol=shape->outlines;o<shape->num_outlines;o++,ol++) {
- register int p;
- XkbPointPtr pt;
- xkbPointWireDesc * ptWire;
- olWire= (xkbOutlineWireDesc *)wire;
- olWire->nPoints= ol->num_points;
- olWire->cornerRadius= ol->corner_radius;
- wire= (char *)&olWire[1];
- ptWire= (xkbPointWireDesc *)wire;
- for (p=0,pt=ol->points;p<ol->num_points;p++,pt++) {
- ptWire[p].x= pt->x;
- ptWire[p].y= pt->y;
- }
- wire= (char *)&ptWire[ol->num_points];
- }
- }
- return wire;
-}
-
-static char *
-_WriteGeomDoodads(char *wire,int num_doodads,XkbDoodadPtr doodad)
-{
-register int i;
-xkbDoodadWireDesc * doodadWire;
-
- for (i=0;i<num_doodads;i++,doodad++) {
- doodadWire= (xkbDoodadWireDesc *)wire;
- wire= (char *)&doodadWire[1];
- bzero(doodadWire,SIZEOF(xkbDoodadWireDesc));
- doodadWire->any.name= doodad->any.name;
- doodadWire->any.type= doodad->any.type;
- doodadWire->any.priority= doodad->any.priority;
- doodadWire->any.top= doodad->any.top;
- doodadWire->any.left= doodad->any.left;
- doodadWire->any.angle= doodad->any.angle;
- switch (doodad->any.type) {
- case XkbOutlineDoodad:
- case XkbSolidDoodad:
- doodadWire->shape.colorNdx= doodad->shape.color_ndx;
- doodadWire->shape.shapeNdx= doodad->shape.shape_ndx;
- break;
- case XkbTextDoodad:
- doodadWire->text.width= doodad->text.width;
- doodadWire->text.height= doodad->text.height;
- doodadWire->text.colorNdx= doodad->text.color_ndx;
- wire= _WriteCountedString(wire,doodad->text.text);
- wire= _WriteCountedString(wire,doodad->text.font);
- break;
- case XkbIndicatorDoodad:
- doodadWire->indicator.shapeNdx= doodad->indicator.shape_ndx;
- doodadWire->indicator.onColorNdx=doodad->indicator.on_color_ndx;
- doodadWire->indicator.offColorNdx=
- doodad->indicator.off_color_ndx;
- break;
- case XkbLogoDoodad:
- doodadWire->logo.colorNdx= doodad->logo.color_ndx;
- doodadWire->logo.shapeNdx= doodad->logo.shape_ndx;
- wire= _WriteCountedString(wire,doodad->logo.logo_name);
- break;
- default:
- break;
- }
- }
- return wire;
-}
-
-static char *
-_WriteGeomOverlay(char *wire,XkbOverlayPtr ol)
-{
-register int r;
-XkbOverlayRowPtr row;
-xkbOverlayWireDesc * olWire;
-
- olWire= (xkbOverlayWireDesc *)wire;
- olWire->name= ol->name;
- olWire->nRows= ol->num_rows;
- wire= (char *)&olWire[1];
- for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
- unsigned int k;
- XkbOverlayKeyPtr key;
- xkbOverlayRowWireDesc * rowWire;
- rowWire= (xkbOverlayRowWireDesc *)wire;
- rowWire->rowUnder= row->row_under;
- rowWire->nKeys= row->num_keys;
- wire= (char *)&rowWire[1];
- for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
- xkbOverlayKeyWireDesc * keyWire;
- keyWire= (xkbOverlayKeyWireDesc *)wire;
- memcpy(keyWire->over,key->over.name,XkbKeyNameLength);
- memcpy(keyWire->under,key->under.name,XkbKeyNameLength);
- wire= (char *)&keyWire[1];
- }
- }
- return wire;
-}
-
-static char *
-_WriteGeomSections(char *wire,XkbGeometryPtr geom)
-{
-register int i;
-XkbSectionPtr section;
-xkbSectionWireDesc * sectionWire;
-
- for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) {
- sectionWire= (xkbSectionWireDesc *)wire;
- sectionWire->name= section->name;
- sectionWire->top= section->top;
- sectionWire->left= section->left;
- sectionWire->width= section->width;
- sectionWire->height= section->height;
- sectionWire->angle= section->angle;
- sectionWire->priority= section->priority;
- sectionWire->nRows= section->num_rows;
- sectionWire->nDoodads= section->num_doodads;
- sectionWire->nOverlays= section->num_overlays;
- sectionWire->pad= 0;
- wire= (char *)&sectionWire[1];
- if (section->rows) {
- int r;
- XkbRowPtr row;
- xkbRowWireDesc * rowWire;
- for (r=0,row=section->rows;r<section->num_rows;r++,row++) {
- rowWire= (xkbRowWireDesc *)wire;
- rowWire->top= row->top;
- rowWire->left= row->left;
- rowWire->nKeys= row->num_keys;
- rowWire->vertical= row->vertical;
- rowWire->pad= 0;
- wire= (char *)&rowWire[1];
- if (row->keys) {
- int k;
- XkbKeyPtr key;
- xkbKeyWireDesc * keyWire;
- keyWire= (xkbKeyWireDesc *)wire;
- for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
- memcpy(keyWire[k].name,key->name.name,XkbKeyNameLength);
- keyWire[k].gap= key->gap;
- keyWire[k].shapeNdx= key->shape_ndx;
- keyWire[k].colorNdx= key->color_ndx;
- }
- wire= (char *)&keyWire[row->num_keys];
- }
- }
- }
- if (section->doodads) {
- wire= _WriteGeomDoodads(wire,
- section->num_doodads,section->doodads);
- }
- if (section->overlays) {
- register int o;
- for (o=0;o<section->num_overlays;o++) {
- wire= _WriteGeomOverlay(wire,&section->overlays[o]);
- }
- }
- }
- return wire;
-}
-
-static char *
-_WriteGeomKeyAliases(char *wire,XkbGeometryPtr geom)
-{
-register int sz;
-
- sz= geom->num_key_aliases*(XkbKeyNameLength*2);
- if (sz>0) {
- memcpy(wire,(char *)geom->key_aliases,sz);
- wire+= sz;
- }
- return wire;
-}
-
-/***====================================================================***/
-
-static Status
-_SendSetGeometry(Display *dpy,XkbGeometryPtr geom,xkbSetGeometryReq *req)
-{
-int sz;
-char * wire,*tbuf;
-
- sz= 0;
- sz+= _SizeCountedString(geom->label_font);
- sz+= _SizeGeomProperties(geom);
- sz+= _SizeGeomColors(geom);
- sz+= _SizeGeomShapes(geom);
- sz+= _SizeGeomSections(geom);
- sz+= _SizeGeomDoodads(geom->num_doodads,geom->doodads);
- sz+= _SizeGeomKeyAliases(geom);
- req->length+= (sz/4);
- if (sz < (dpy->bufmax - dpy->buffer)) {
- BufAlloc(char *,wire,sz);
- tbuf= NULL;
- }
- else {
- tbuf= _XAllocTemp(dpy,sz);
- if (!tbuf)
- return BadAlloc;
- wire= tbuf;
- }
- wire= _WriteCountedString(wire,geom->label_font);
- if (geom->num_properties>0)
- wire= _WriteGeomProperties(wire,geom);
- if (geom->num_colors>0)
- wire= _WriteGeomColors(wire,geom);
- if (geom->num_shapes>0)
- wire= _WriteGeomShapes(wire,geom);
- if (geom->num_sections>0)
- wire= _WriteGeomSections(wire,geom);
- if (geom->num_doodads>0)
- wire= _WriteGeomDoodads(wire,geom->num_doodads,geom->doodads);
- if (geom->num_key_aliases>0)
- wire= _WriteGeomKeyAliases(wire,geom);
- if (tbuf!=NULL) {
- Data(dpy,tbuf,sz);
- _XFreeTemp(dpy,tbuf,sz);
- }
- return Success;
-}
-
-/***====================================================================***/
-
-Status
-XkbSetGeometry(Display *dpy,unsigned deviceSpec,XkbGeometryPtr geom)
-{
-xkbSetGeometryReq *req;
-Status ret;
-
- if ( (!geom) || (dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
-
- LockDisplay(dpy);
- GetReq(kbSetGeometry, req);
- req->reqType = dpy->xkb_info->codes->major_opcode;
- req->xkbReqType = X_kbSetGeometry;
- req->deviceSpec = deviceSpec;
- req->nShapes= geom->num_shapes;
- req->nSections= geom->num_sections;
- req->name= geom->name;
- req->widthMM= geom->width_mm;
- req->heightMM= geom->height_mm;
- req->nProperties= geom->num_properties;
- req->nColors= geom->num_colors;
- req->nDoodads= geom->num_doodads;
- req->nKeyAliases= geom->num_key_aliases;
- req->baseColorNdx= (geom->base_color-geom->colors);
- req->labelColorNdx= (geom->label_color-geom->colors);
-
- ret = _SendSetGeometry(dpy,geom,req);
- UnlockDisplay(dpy);
- SyncHandle();
- return ret;
-}
-
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 DEBUG
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#endif
+
+#include "Xlibint.h"
+#include "XKBlibint.h"
+#include <X11/extensions/XKBgeom.h>
+#include <X11/extensions/XKBproto.h>
+
+#define MINSHORT -32768
+#define MAXSHORT 32767
+
+/***====================================================================***/
+
+#define _SizeCountedString(s) ((s)?XkbPaddedSize(2+strlen(s)):4)
+
+static char *
+_WriteCountedString(char *wire,char *str)
+{
+CARD16 len,*pLen;
+
+ len= (str?strlen(str):0);
+ pLen= (CARD16 *)wire;
+ *pLen= len;
+ if (len && str)
+ memcpy(&wire[2],str,len);
+ wire+= XkbPaddedSize(len+2);
+ return wire;
+}
+
+static int
+_SizeGeomProperties(XkbGeometryPtr geom)
+{
+register int i,size;
+XkbPropertyPtr prop;
+
+ for (size=i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
+ size+= _SizeCountedString(prop->name);
+ size+= _SizeCountedString(prop->value);
+ }
+ return size;
+}
+
+static int
+_SizeGeomColors(XkbGeometryPtr geom)
+{
+register int i,size;
+register XkbColorPtr color;
+
+ for (i=size=0,color=geom->colors;i<geom->num_colors;i++,color++) {
+ size+= _SizeCountedString(color->spec);
+ }
+ return size;
+}
+
+static int
+_SizeGeomShapes(XkbGeometryPtr geom)
+{
+register int i,size;
+register XkbShapePtr shape;
+
+ for (i=size=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) {
+ register int n;
+ register XkbOutlinePtr ol;
+ size+= SIZEOF(xkbShapeWireDesc);
+ for (n=0,ol=shape->outlines;n<shape->num_outlines;n++,ol++) {
+ size+= SIZEOF(xkbOutlineWireDesc);
+ size+= ol->num_points*SIZEOF(xkbPointWireDesc);
+ }
+ }
+ return size;
+}
+
+static int
+_SizeGeomDoodads(int num_doodads,XkbDoodadPtr doodad)
+{
+register int i,size;
+
+ for (i=size=0;i<num_doodads;i++,doodad++) {
+ size+= SIZEOF(xkbAnyDoodadWireDesc);
+ if (doodad->any.type==XkbTextDoodad) {
+ size+= _SizeCountedString(doodad->text.text);
+ size+= _SizeCountedString(doodad->text.font);
+ }
+ else if (doodad->any.type==XkbLogoDoodad) {
+ size+= _SizeCountedString(doodad->logo.logo_name);
+ }
+ }
+ return size;
+}
+
+static int
+_SizeGeomSections(XkbGeometryPtr geom)
+{
+register int i,size;
+XkbSectionPtr section;
+
+ for (i=size=0,section=geom->sections;i<geom->num_sections;i++,section++) {
+ size+= SIZEOF(xkbSectionWireDesc);
+ if (section->rows) {
+ int r;
+ XkbRowPtr row;
+ for (r=0,row=section->rows;r<section->num_rows;row++,r++) {
+ size+= SIZEOF(xkbRowWireDesc);
+ size+= row->num_keys*SIZEOF(xkbKeyWireDesc);
+ }
+ }
+ if (section->doodads)
+ size+= _SizeGeomDoodads(section->num_doodads,section->doodads);
+ if (section->overlays) {
+ int o;
+ XkbOverlayPtr ol;
+ for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) {
+ int r;
+ XkbOverlayRowPtr row;
+ size+= SIZEOF(xkbOverlayWireDesc);
+ for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
+ size+= SIZEOF(xkbOverlayRowWireDesc);
+ size+= row->num_keys*SIZEOF(xkbOverlayKeyWireDesc);
+ }
+ }
+ }
+ }
+ return size;
+}
+
+static int
+_SizeGeomKeyAliases(XkbGeometryPtr geom)
+{
+ return geom->num_key_aliases*(2*XkbKeyNameLength);
+}
+
+/***====================================================================***/
+
+static char *
+_WriteGeomProperties(char *wire,XkbGeometryPtr geom)
+{
+register int i;
+register XkbPropertyPtr prop;
+
+ for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
+ wire= _WriteCountedString(wire,prop->name);
+ wire= _WriteCountedString(wire,prop->value);
+ }
+ return wire;
+}
+
+static char *
+_WriteGeomColors(char *wire,XkbGeometryPtr geom)
+{
+register int i;
+register XkbColorPtr color;
+
+ for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) {
+ wire= _WriteCountedString(wire,color->spec);
+ }
+ return wire;
+}
+
+static char *
+_WriteGeomShapes(char *wire,XkbGeometryPtr geom)
+{
+int i;
+XkbShapePtr shape;
+xkbShapeWireDesc * shapeWire;
+
+ for (i=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) {
+ register int o;
+ XkbOutlinePtr ol;
+ xkbOutlineWireDesc * olWire;
+ shapeWire= (xkbShapeWireDesc *)wire;
+ shapeWire->name= shape->name;
+ shapeWire->nOutlines= shape->num_outlines;
+ if (shape->primary!=NULL)
+ shapeWire->primaryNdx= XkbOutlineIndex(shape,shape->primary);
+ else shapeWire->primaryNdx= XkbNoShape;
+ if (shape->approx!=NULL)
+ shapeWire->approxNdx= XkbOutlineIndex(shape,shape->approx);
+ else shapeWire->approxNdx= XkbNoShape;
+ wire= (char *)&shapeWire[1];
+ for (o=0,ol=shape->outlines;o<shape->num_outlines;o++,ol++) {
+ register int p;
+ XkbPointPtr pt;
+ xkbPointWireDesc * ptWire;
+ olWire= (xkbOutlineWireDesc *)wire;
+ olWire->nPoints= ol->num_points;
+ olWire->cornerRadius= ol->corner_radius;
+ wire= (char *)&olWire[1];
+ ptWire= (xkbPointWireDesc *)wire;
+ for (p=0,pt=ol->points;p<ol->num_points;p++,pt++) {
+ ptWire[p].x= pt->x;
+ ptWire[p].y= pt->y;
+ }
+ wire= (char *)&ptWire[ol->num_points];
+ }
+ }
+ return wire;
+}
+
+static char *
+_WriteGeomDoodads(char *wire,int num_doodads,XkbDoodadPtr doodad)
+{
+register int i;
+xkbDoodadWireDesc * doodadWire;
+
+ for (i=0;i<num_doodads;i++,doodad++) {
+ doodadWire= (xkbDoodadWireDesc *)wire;
+ wire= (char *)&doodadWire[1];
+ bzero(doodadWire,SIZEOF(xkbDoodadWireDesc));
+ doodadWire->any.name= doodad->any.name;
+ doodadWire->any.type= doodad->any.type;
+ doodadWire->any.priority= doodad->any.priority;
+ doodadWire->any.top= doodad->any.top;
+ doodadWire->any.left= doodad->any.left;
+ doodadWire->any.angle= doodad->any.angle;
+ switch (doodad->any.type) {
+ case XkbOutlineDoodad:
+ case XkbSolidDoodad:
+ doodadWire->shape.colorNdx= doodad->shape.color_ndx;
+ doodadWire->shape.shapeNdx= doodad->shape.shape_ndx;
+ break;
+ case XkbTextDoodad:
+ doodadWire->text.width= doodad->text.width;
+ doodadWire->text.height= doodad->text.height;
+ doodadWire->text.colorNdx= doodad->text.color_ndx;
+ wire= _WriteCountedString(wire,doodad->text.text);
+ wire= _WriteCountedString(wire,doodad->text.font);
+ break;
+ case XkbIndicatorDoodad:
+ doodadWire->indicator.shapeNdx= doodad->indicator.shape_ndx;
+ doodadWire->indicator.onColorNdx=doodad->indicator.on_color_ndx;
+ doodadWire->indicator.offColorNdx=
+ doodad->indicator.off_color_ndx;
+ break;
+ case XkbLogoDoodad:
+ doodadWire->logo.colorNdx= doodad->logo.color_ndx;
+ doodadWire->logo.shapeNdx= doodad->logo.shape_ndx;
+ wire= _WriteCountedString(wire,doodad->logo.logo_name);
+ break;
+ default:
+ break;
+ }
+ }
+ return wire;
+}
+
+static char *
+_WriteGeomOverlay(char *wire,XkbOverlayPtr ol)
+{
+register int r;
+XkbOverlayRowPtr row;
+xkbOverlayWireDesc * olWire;
+
+ olWire= (xkbOverlayWireDesc *)wire;
+ olWire->name= ol->name;
+ olWire->nRows= ol->num_rows;
+ wire= (char *)&olWire[1];
+ for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
+ unsigned int k;
+ XkbOverlayKeyPtr key;
+ xkbOverlayRowWireDesc * rowWire;
+ rowWire= (xkbOverlayRowWireDesc *)wire;
+ rowWire->rowUnder= row->row_under;
+ rowWire->nKeys= row->num_keys;
+ wire= (char *)&rowWire[1];
+ for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
+ xkbOverlayKeyWireDesc * keyWire;
+ keyWire= (xkbOverlayKeyWireDesc *)wire;
+ memcpy(keyWire->over,key->over.name,XkbKeyNameLength);
+ memcpy(keyWire->under,key->under.name,XkbKeyNameLength);
+ wire= (char *)&keyWire[1];
+ }
+ }
+ return wire;
+}
+
+static char *
+_WriteGeomSections(char *wire,XkbGeometryPtr geom)
+{
+register int i;
+XkbSectionPtr section;
+xkbSectionWireDesc * sectionWire;
+
+ for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) {
+ sectionWire= (xkbSectionWireDesc *)wire;
+ sectionWire->name= section->name;
+ sectionWire->top= section->top;
+ sectionWire->left= section->left;
+ sectionWire->width= section->width;
+ sectionWire->height= section->height;
+ sectionWire->angle= section->angle;
+ sectionWire->priority= section->priority;
+ sectionWire->nRows= section->num_rows;
+ sectionWire->nDoodads= section->num_doodads;
+ sectionWire->nOverlays= section->num_overlays;
+ sectionWire->pad= 0;
+ wire= (char *)&sectionWire[1];
+ if (section->rows) {
+ int r;
+ XkbRowPtr row;
+ xkbRowWireDesc * rowWire;
+ for (r=0,row=section->rows;r<section->num_rows;r++,row++) {
+ rowWire= (xkbRowWireDesc *)wire;
+ rowWire->top= row->top;
+ rowWire->left= row->left;
+ rowWire->nKeys= row->num_keys;
+ rowWire->vertical= row->vertical;
+ rowWire->pad= 0;
+ wire= (char *)&rowWire[1];
+ if (row->keys) {
+ int k;
+ XkbKeyPtr key;
+ xkbKeyWireDesc * keyWire;
+ keyWire= (xkbKeyWireDesc *)wire;
+ for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
+ memcpy(keyWire[k].name,key->name.name,XkbKeyNameLength);
+ keyWire[k].gap= key->gap;
+ keyWire[k].shapeNdx= key->shape_ndx;
+ keyWire[k].colorNdx= key->color_ndx;
+ }
+ wire= (char *)&keyWire[row->num_keys];
+ }
+ }
+ }
+ if (section->doodads) {
+ wire= _WriteGeomDoodads(wire,
+ section->num_doodads,section->doodads);
+ }
+ if (section->overlays) {
+ register int o;
+ for (o=0;o<section->num_overlays;o++) {
+ wire= _WriteGeomOverlay(wire,&section->overlays[o]);
+ }
+ }
+ }
+ return wire;
+}
+
+static char *
+_WriteGeomKeyAliases(char *wire,XkbGeometryPtr geom)
+{
+register int sz;
+
+ sz= geom->num_key_aliases*(XkbKeyNameLength*2);
+ if (sz>0) {
+ memcpy(wire,(char *)geom->key_aliases,sz);
+ wire+= sz;
+ }
+ return wire;
+}
+
+/***====================================================================***/
+
+static Status
+_SendSetGeometry(Display *dpy,XkbGeometryPtr geom,xkbSetGeometryReq *req)
+{
+int sz;
+char * wire,*tbuf;
+
+ sz= 0;
+ sz+= _SizeCountedString(geom->label_font);
+ sz+= _SizeGeomProperties(geom);
+ sz+= _SizeGeomColors(geom);
+ sz+= _SizeGeomShapes(geom);
+ sz+= _SizeGeomSections(geom);
+ sz+= _SizeGeomDoodads(geom->num_doodads,geom->doodads);
+ sz+= _SizeGeomKeyAliases(geom);
+ req->length+= (sz/4);
+ if (sz < (dpy->bufmax - dpy->buffer)) {
+ BufAlloc(char *,wire,sz);
+ tbuf= NULL;
+ }
+ else {
+ tbuf= _XAllocTemp(dpy,sz);
+ if (!tbuf)
+ return BadAlloc;
+ wire= tbuf;
+ }
+ wire= _WriteCountedString(wire,geom->label_font);
+ if (geom->num_properties>0)
+ wire= _WriteGeomProperties(wire,geom);
+ if (geom->num_colors>0)
+ wire= _WriteGeomColors(wire,geom);
+ if (geom->num_shapes>0)
+ wire= _WriteGeomShapes(wire,geom);
+ if (geom->num_sections>0)
+ wire= _WriteGeomSections(wire,geom);
+ if (geom->num_doodads>0)
+ wire= _WriteGeomDoodads(wire,geom->num_doodads,geom->doodads);
+ if (geom->num_key_aliases>0)
+ wire= _WriteGeomKeyAliases(wire,geom);
+ if (tbuf!=NULL) {
+ Data(dpy,tbuf,sz);
+ _XFreeTemp(dpy,tbuf,sz);
+ }
+ return Success;
+}
+
+/***====================================================================***/
+
+Status
+XkbSetGeometry(Display *dpy,unsigned deviceSpec,XkbGeometryPtr geom)
+{
+xkbSetGeometryReq *req;
+Status ret;
+
+ if ( (!geom) || (dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+
+ LockDisplay(dpy);
+ GetReq(kbSetGeometry, req);
+ req->reqType = dpy->xkb_info->codes->major_opcode;
+ req->xkbReqType = X_kbSetGeometry;
+ req->deviceSpec = deviceSpec;
+ req->nShapes= geom->num_shapes;
+ req->nSections= geom->num_sections;
+ req->name= geom->name;
+ req->widthMM= geom->width_mm;
+ req->heightMM= geom->height_mm;
+ req->nProperties= geom->num_properties;
+ req->nColors= geom->num_colors;
+ req->nDoodads= geom->num_doodads;
+ req->nKeyAliases= geom->num_key_aliases;
+ req->baseColorNdx= (geom->base_color-geom->colors);
+ req->labelColorNdx= (geom->label_color-geom->colors);
+
+ ret = _SendSetGeometry(dpy,geom,req);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return ret;
+}
+
diff --git a/libX11/src/xkb/XKBSetMap.c b/libX11/src/xkb/XKBSetMap.c
index bd46e1fc7..8adfe5446 100644
--- a/libX11/src/xkb/XKBSetMap.c
+++ b/libX11/src/xkb/XKBSetMap.c
@@ -1,593 +1,591 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 <stdio.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-static int
-_XkbSizeKeyTypes(XkbDescPtr xkb,xkbSetMapReq *req)
-{
- XkbKeyTypePtr map;
- int i,len;
-
- if (((req->present&XkbKeyTypesMask)==0)||(req->nTypes==0)) {
- req->present&= ~XkbKeyTypesMask;
- req->firstType= req->nTypes= 0;
- return 0;
- }
- len= 0;
- map= &xkb->map->types[req->firstType];
- for (i=0;i<req->nTypes;i++,map++){
- len+= SIZEOF(xkbKeyTypeWireDesc);
- len+= map->map_count*SIZEOF(xkbKTSetMapEntryWireDesc);
- if (map->preserve)
- len+= map->map_count*SIZEOF(xkbModsWireDesc);
- }
- return len;
-}
-
-static void
-_XkbWriteKeyTypes(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
-{
- char * buf;
- XkbKeyTypePtr type;
- int i,n,sz;
- xkbKeyTypeWireDesc *desc;
-
- if ((req->present&XkbKeyTypesMask)==0)
- return;
- type= &xkb->map->types[req->firstType];
- for (i=0;i<req->nTypes;i++,type++) {
- sz= SIZEOF(xkbKeyTypeWireDesc);
- sz+= type->map_count*SIZEOF(xkbKTSetMapEntryWireDesc);
- if (type->preserve)
- sz+= type->map_count*SIZEOF(xkbModsWireDesc);
- BufAlloc(xkbKeyTypeWireDesc *,desc,sz);
- desc->mask = type->mods.mask;
- desc->realMods = type->mods.real_mods;
- desc->virtualMods = type->mods.vmods;
- desc->numLevels = type->num_levels;
- desc->nMapEntries = type->map_count;
- desc->preserve = (type->preserve!=NULL);
- buf= (char *)&desc[1];
- if (desc->nMapEntries>0) {
- xkbKTSetMapEntryWireDesc *wire;
- wire= (xkbKTSetMapEntryWireDesc *)buf;
- for (n=0;n<type->map_count;n++,wire++) {
- wire->level= type->map[n].level;
- wire->realMods= type->map[n].mods.real_mods;
- wire->virtualMods= type->map[n].mods.vmods;
- }
- buf= (char *)wire;
- if (type->preserve) {
- xkbModsWireDesc *pwire;
- pwire= (xkbModsWireDesc *)buf;
- for (n=0;n<type->map_count;n++,pwire++) {
- pwire->realMods= type->preserve[n].real_mods;
- pwire->virtualMods= type->preserve[n].vmods;
- }
- }
- }
- }
- return;
-}
-
-static int
-_XkbSizeKeySyms(XkbDescPtr xkb,xkbSetMapReq *req)
-{
- int i,len;
- unsigned nSyms;
-
- if (((req->present&XkbKeySymsMask)==0)||(req->nKeySyms==0)) {
- req->present&= ~XkbKeySymsMask;
- req->firstKeySym= req->nKeySyms= 0;
- req->totalSyms= 0;
- return 0;
- }
- len= (int)(req->nKeySyms*sizeof(XkbSymMapRec));
- for (i=nSyms=0;i<req->nKeySyms;i++) {
- nSyms+= XkbKeyNumSyms(xkb,i+req->firstKeySym);
- }
- len+= nSyms*sizeof(CARD32);
- req->totalSyms= nSyms;
- return len;
-}
-
-static void
-_XkbWriteKeySyms(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register KeySym * pSym;
-CARD32 * outSym;
-XkbSymMapPtr symMap;
-xkbSymMapWireDesc *desc;
-register int i;
-
- if ((req->present&XkbKeySymsMask)==0)
- return;
- symMap = &xkb->map->key_sym_map[req->firstKeySym];
- for (i=0;i<req->nKeySyms;i++,symMap++) {
- BufAlloc(xkbSymMapWireDesc *,desc,
- SIZEOF(xkbSymMapWireDesc)+
- (XkbKeyNumSyms(xkb,i+req->firstKeySym)*sizeof(CARD32)));
- desc->ktIndex[0] = symMap->kt_index[0];
- desc->ktIndex[1] = symMap->kt_index[1];
- desc->ktIndex[2] = symMap->kt_index[2];
- desc->ktIndex[3] = symMap->kt_index[3];
- desc->groupInfo = symMap->group_info;
- desc->width = symMap->width;
- desc->nSyms = XkbKeyNumSyms(xkb,i+req->firstKeySym);
- outSym = (CARD32 *)&desc[1];
- if (desc->nSyms>0) {
- pSym = XkbKeySymsPtr(xkb,i+req->firstKeySym);
- _XkbWriteCopyKeySyms(pSym,outSym,desc->nSyms);
- }
- }
- return;
-}
-
-static int
-_XkbSizeKeyActions(XkbDescPtr xkb,xkbSetMapReq *req)
-{
- int i,len,nActs;
-
- if (((req->present&XkbKeyActionsMask)==0)||(req->nKeyActs==0)) {
- req->present&= ~XkbKeyActionsMask;
- req->firstKeyAct= req->nKeyActs= 0;
- req->totalActs= 0;
- return 0;
- }
- for (nActs=i=0;i<req->nKeyActs;i++) {
- if (xkb->server->key_acts[i+req->firstKeyAct]!=0)
- nActs+= XkbKeyNumActions(xkb,i+req->firstKeyAct);
- }
- len= XkbPaddedSize(req->nKeyActs)+(nActs*SIZEOF(xkbActionWireDesc));
- req->totalActs= nActs;
- return len;
-}
-
-static void
-_XkbWriteKeyActions(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
-{
- register int i;
- int n;
- CARD8 *numDesc;
- XkbAction *actDesc;
-
- if ((req->present&XkbKeyActionsMask)==0)
- return;
- n = XkbPaddedSize(req->nKeyActs);
- n+= (req->totalActs*SIZEOF(xkbActionWireDesc));
-
- BufAlloc(CARD8 *,numDesc,n);
- for (i=0;i<req->nKeyActs;i++) {
- if (xkb->server->key_acts[i+req->firstKeyAct]==0)
- numDesc[i] = 0;
- else numDesc[i] = XkbKeyNumActions(xkb,(i+req->firstKeyAct));
- }
- actDesc = (XkbAction *)&numDesc[XkbPaddedSize(req->nKeyActs)];
- for (i=0;i<req->nKeyActs;i++) {
- if (xkb->server->key_acts[i+req->firstKeyAct]!=0) {
- n = XkbKeyNumActions(xkb,(i+req->firstKeyAct));
- memcpy(actDesc,XkbKeyActionsPtr(xkb,(i+req->firstKeyAct)),
- n*SIZEOF(xkbActionWireDesc));
- actDesc+= n;
- }
- }
- return;
-}
-
-static int
-_XkbSizeKeyBehaviors(XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register int i,first,last,nFound;
-
- if (((req->present&XkbKeyBehaviorsMask)==0)||(req->nKeyBehaviors<1)) {
- req->present&= ~XkbKeyBehaviorsMask;
- req->firstKeyBehavior= req->nKeyBehaviors= 0;
- req->totalKeyBehaviors= 0;
- return 0;
- }
- first= req->firstKeyBehavior;
- last= first+req->nKeyBehaviors-1;
- for (i=first,nFound=0;i<=last;i++) {
- if (xkb->server->behaviors[i].type!=XkbKB_Default)
- nFound++;
- }
- req->totalKeyBehaviors= nFound;
- return (nFound*SIZEOF(xkbBehaviorWireDesc));
-}
-
-static void
-_XkbWriteKeyBehaviors(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register int i,first,last;
-xkbBehaviorWireDesc * wire;
-char * buf;
-
- if ((req->present&XkbKeyBehaviorsMask)==0)
- return;
- first= req->firstKeyBehavior;
- last= first+req->nKeyBehaviors-1;
-
- i= req->totalKeyBehaviors*SIZEOF(xkbBehaviorWireDesc);
- BufAlloc(char *,buf,i);
- wire= (xkbBehaviorWireDesc *)buf;
- for (i=first;i<=last;i++) {
- if (xkb->server->behaviors[i].type!=XkbKB_Default) {
- wire->key= i;
- wire->type= xkb->server->behaviors[i].type;
- wire->data= xkb->server->behaviors[i].data;
- buf+= SIZEOF(xkbBehaviorWireDesc);
- wire= (xkbBehaviorWireDesc *)buf;
- }
- }
- return;
-}
-
-static unsigned
-_XkbSizeVirtualMods(xkbSetMapReq *req)
-{
-register int i,bit,nMods;
-
- if (((req->present&XkbVirtualModsMask)==0)||(req->virtualMods==0)) {
- req->present&= ~XkbVirtualModsMask;
- req->virtualMods= 0;
- return 0;
- }
- for (i=nMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
- if (req->virtualMods&bit)
- nMods++;
- }
- return XkbPaddedSize(nMods);
-}
-
-static void
-_XkbWriteVirtualMods( Display * dpy,
- XkbDescPtr xkb,
- xkbSetMapReq * req,
- unsigned size)
-{
- register int i,bit;
- CARD8 *vmods;
-
- /* This was req->present&XkbVirtualModsMask==0, and '==' beats '&' */
- if (((req->present & XkbVirtualModsMask) == 0) || (size < 1))
- return;
- BufAlloc(CARD8 *,vmods,size);
- for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
- if (req->virtualMods&bit)
- *vmods++= xkb->server->vmods[i];
- }
- return;
-}
-
-static int
-_XkbSizeKeyExplicit(XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register int i,first,last,nFound;
-
- if (((req->present&XkbExplicitComponentsMask)==0)||(req->nKeyExplicit==0)) {
- req->present&= ~XkbExplicitComponentsMask;
- req->firstKeyExplicit= req->nKeyExplicit= 0;
- req->totalKeyExplicit= 0;
- return 0;
- }
- first= req->firstKeyExplicit;
- last= first+req->nKeyExplicit-1;
-
- for (i=first,nFound=0;i<=last;i++) {
- if (xkb->server->explicit[i]!=0)
- nFound++;
- }
- req->totalKeyExplicit= nFound;
- return XkbPaddedSize((nFound*2));
-}
-
-static void
-_XkbWriteKeyExplicit(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register int i,first,last;
-CARD8 * wire;
-
- if ((req->present&XkbExplicitComponentsMask)==0)
- return;
- first= req->firstKeyExplicit;
- last= first+req->nKeyExplicit - 1;
- i= XkbPaddedSize((req->totalKeyExplicit*2));
- BufAlloc(CARD8 *,wire,i);
- for (i=first;i<=last;i++) {
- if (xkb->server->explicit[i]!=0) {
- wire[0]= i;
- wire[1]= xkb->server->explicit[i];
- wire+= 2;
- }
- }
- return;
-}
-
-static int
-_XkbSizeModifierMap(XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register int i,first,last,nFound;
-
- if (((req->present&XkbModifierMapMask)==0)||(req->nModMapKeys==0)) {
- req->present&= ~XkbModifierMapMask;
- req->firstModMapKey= req->nModMapKeys= 0;
- req->totalModMapKeys= 0;
- return 0;
- }
- first= req->firstModMapKey;
- last= first+req->nModMapKeys-1;
-
- for (i=first,nFound=0;i<=last;i++) {
- if (xkb->map->modmap[i]!=0)
- nFound++;
- }
- req->totalModMapKeys= nFound;
- return XkbPaddedSize((nFound*2));
-}
-
-static void
-_XkbWriteModifierMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register int i,first,last;
-CARD8 * wire;
-
- if ((req->present&XkbModifierMapMask)==0)
- return;
- first= req->firstModMapKey;
- last= first+req->nModMapKeys-1;
- if (req->totalModMapKeys>0) {
- i= XkbPaddedSize((req->totalModMapKeys*2));
- BufAlloc(CARD8 *,wire,i);
- for (i=first;i<=last;i++) {
- if (xkb->map->modmap[i]!=0) {
- wire[0]= i;
- wire[1]= xkb->map->modmap[i];
- wire+= 2;
- }
- }
- }
- return;
-}
-
-static int
-_XkbSizeVirtualModMap(XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register int i,first,last,nFound;
-
- if (((req->present&XkbVirtualModMapMask)==0)||(req->nVModMapKeys==0)) {
- req->present&= ~XkbVirtualModMapMask;
- req->firstVModMapKey= req->nVModMapKeys= 0;
- req->totalVModMapKeys= 0;
- return 0;
- }
- first= req->firstVModMapKey;
- last= first+req->nVModMapKeys-1;
-
- for (i=first,nFound=0;i<=last;i++) {
- if (xkb->server->vmodmap[i]!=0)
- nFound++;
- }
- req->totalVModMapKeys= nFound;
- return nFound*SIZEOF(xkbVModMapWireDesc);
-}
-
-static void
-_XkbWriteVirtualModMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
-{
-register int i,first,last;
-xkbVModMapWireDesc * wire;
-
- if ((req->present&XkbVirtualModMapMask)==0)
- return;
- first= req->firstVModMapKey;
- last= first+req->nVModMapKeys-1;
- if (req->totalVModMapKeys>0) {
- i= req->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc);
- BufAlloc(xkbVModMapWireDesc *,wire,i);
- for (i=first;i<=last;i++) {
- if (xkb->server->vmodmap[i]!=0) {
- wire->key= i;
- wire->vmods= xkb->server->vmodmap[i];
- wire++;
- }
- }
- }
- return;
-}
-
-static void
-SendSetMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
-{
-xkbSetMapReq tmp;
-unsigned szMods;
-
- req->length+= _XkbSizeKeyTypes(xkb,req)/4;
- req->length+= _XkbSizeKeySyms(xkb,req)/4;
- req->length+= _XkbSizeKeyActions(xkb,req)/4;
- req->length+= _XkbSizeKeyBehaviors(xkb,req)/4;
- szMods= _XkbSizeVirtualMods(req);
- req->length+= szMods/4;
- req->length+= _XkbSizeKeyExplicit(xkb,req)/4;
- req->length+= _XkbSizeModifierMap(xkb,req)/4;
- req->length+= _XkbSizeVirtualModMap(xkb,req)/4;
-
- tmp= *req;
- if ( tmp.nTypes>0 )
- _XkbWriteKeyTypes(dpy,xkb,&tmp);
- if ( tmp.nKeySyms>0 )
- _XkbWriteKeySyms(dpy,xkb,&tmp);
- if ( tmp.nKeyActs )
- _XkbWriteKeyActions(dpy,xkb,&tmp);
- if ( tmp.totalKeyBehaviors>0 )
- _XkbWriteKeyBehaviors(dpy,xkb,&tmp);
- if ( tmp.virtualMods )
- _XkbWriteVirtualMods(dpy,xkb,&tmp,szMods);
- if ( tmp.totalKeyExplicit>0)
- _XkbWriteKeyExplicit(dpy,xkb,&tmp);
- if ( tmp.totalModMapKeys>0)
- _XkbWriteModifierMap(dpy,xkb,&tmp);
- if ( tmp.totalVModMapKeys>0)
- _XkbWriteVirtualModMap(dpy,xkb,&tmp);
- return;
-}
-
-Bool
-XkbSetMap(Display *dpy,unsigned which,XkbDescPtr xkb)
-{
-register xkbSetMapReq * req;
-XkbInfoPtr xkbi;
-XkbServerMapPtr srv;
-XkbClientMapPtr map;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))||
- (!xkb))
- return False;
- map= xkb->map;
- srv= xkb->server;
-
- if (((which&XkbKeyTypesMask)&&((!map)||(!map->types)))||
- ((which&XkbKeySymsMask)&&((!map)||(!map->syms)||(!map->key_sym_map)))||
- ((which&XkbKeyActionsMask)&&((!srv)||(!srv->key_acts)))||
- ((which&XkbKeyBehaviorsMask)&&((!srv)||(!srv->behaviors)))||
- ((which&XkbVirtualModsMask)&&(!srv))||
- ((which&XkbExplicitComponentsMask)&&((!srv)||(!srv->explicit)))||
- ((which&XkbModifierMapMask)&&((!map)||(!map->modmap)))||
- ((which&XkbVirtualModMapMask)&&((!srv)||(!srv->vmodmap))))
- return False;
-
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetMap, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSetMap;
- req->deviceSpec = xkb->device_spec;
- req->present = which;
- req->flags = XkbSetMapAllFlags;
- req->minKeyCode= xkb->min_key_code;
- req->maxKeyCode= xkb->max_key_code;
- req->firstType = 0;
- if (which&XkbKeyTypesMask) req->nTypes = map->num_types;
- else req->nTypes = 0;
- if (which&XkbKeySymsMask) {
- req->firstKeySym = xkb->min_key_code;
- req->nKeySyms = XkbNumKeys(xkb);
- }
- if (which&XkbKeyActionsMask) {
- req->firstKeyAct = xkb->min_key_code;
- req->nKeyActs = XkbNumKeys(xkb);
- }
- if (which&XkbKeyBehaviorsMask) {
- req->firstKeyBehavior = xkb->min_key_code;
- req->nKeyBehaviors = XkbNumKeys(xkb);
- }
- if (which&XkbVirtualModsMask)
- req->virtualMods= ~0;
- if (which&XkbExplicitComponentsMask) {
- req->firstKeyExplicit= xkb->min_key_code;
- req->nKeyExplicit = XkbNumKeys(xkb);
- }
- if (which&XkbModifierMapMask) {
- req->firstModMapKey= xkb->min_key_code;
- req->nModMapKeys = XkbNumKeys(xkb);
- }
- if (which&XkbVirtualModMapMask) {
- req->firstVModMapKey= xkb->min_key_code;
- req->nVModMapKeys = XkbNumKeys(xkb);
- }
- SendSetMap(dpy,xkb,req);
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbChangeMap(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes)
-{
-register xkbSetMapReq * req;
-XkbInfoPtr xkbi;
-XkbServerMapPtr srv;
-XkbClientMapPtr map;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))||
- (!xkb)||(!changes))
- return False;
- srv= xkb->server;
- map= xkb->map;
-
- if (((changes->changed&XkbKeyTypesMask)&&((!map)||(!map->types)))||
- ((changes->changed&XkbKeySymsMask)&&((!map)||(!map->syms)||
- (!map->key_sym_map)))||
- ((changes->changed&XkbKeyActionsMask)&&((!srv)||(!srv->key_acts)))||
- ((changes->changed&XkbKeyBehaviorsMask)&&((!srv)||(!srv->behaviors)))||
- ((changes->changed&XkbVirtualModsMask)&&(!srv))||
- ((changes->changed&XkbExplicitComponentsMask)&&
- ((!srv)||(!srv->explicit)))||
- ((changes->changed&XkbModifierMapMask)&&((!map)||(!map->modmap)))||
- ((changes->changed&XkbVirtualModMapMask)&&((!srv)||(!srv->vmodmap))))
- return False;
-
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetMap, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSetMap;
- req->deviceSpec = xkb->device_spec;
- req->present = changes->changed;
- req->flags = XkbSetMapRecomputeActions;
- req->minKeyCode= xkb->min_key_code;
- req->maxKeyCode= xkb->max_key_code;
- req->firstType = changes->first_type;
- req->nTypes = changes->num_types;
- req->firstKeySym = changes->first_key_sym;
- req->nKeySyms = changes->num_key_syms;
- req->firstKeyAct = changes->first_key_act;
- req->nKeyActs = changes->num_key_acts;
- req->firstKeyBehavior = changes->first_key_behavior;
- req->nKeyBehaviors = changes->num_key_behaviors;
- req->virtualMods = changes->vmods;
- req->firstKeyExplicit = changes->first_key_explicit;
- req->nKeyExplicit = changes->num_key_explicit;
- req->firstModMapKey = changes->first_modmap_key;
- req->nModMapKeys = changes->num_modmap_keys;
- req->firstVModMapKey = changes->first_vmodmap_key;
- req->nVModMapKeys = changes->num_vmodmap_keys;
- SendSetMap(dpy,xkb,req);
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 <stdio.h>
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+static int
+_XkbSizeKeyTypes(XkbDescPtr xkb,xkbSetMapReq *req)
+{
+ XkbKeyTypePtr map;
+ int i,len;
+
+ if (((req->present&XkbKeyTypesMask)==0)||(req->nTypes==0)) {
+ req->present&= ~XkbKeyTypesMask;
+ req->firstType= req->nTypes= 0;
+ return 0;
+ }
+ len= 0;
+ map= &xkb->map->types[req->firstType];
+ for (i=0;i<req->nTypes;i++,map++){
+ len+= SIZEOF(xkbKeyTypeWireDesc);
+ len+= map->map_count*SIZEOF(xkbKTSetMapEntryWireDesc);
+ if (map->preserve)
+ len+= map->map_count*SIZEOF(xkbModsWireDesc);
+ }
+ return len;
+}
+
+static void
+_XkbWriteKeyTypes(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
+{
+ char * buf;
+ XkbKeyTypePtr type;
+ int i,n,sz;
+ xkbKeyTypeWireDesc *desc;
+
+ if ((req->present&XkbKeyTypesMask)==0)
+ return;
+ type= &xkb->map->types[req->firstType];
+ for (i=0;i<req->nTypes;i++,type++) {
+ sz= SIZEOF(xkbKeyTypeWireDesc);
+ sz+= type->map_count*SIZEOF(xkbKTSetMapEntryWireDesc);
+ if (type->preserve)
+ sz+= type->map_count*SIZEOF(xkbModsWireDesc);
+ BufAlloc(xkbKeyTypeWireDesc *,desc,sz);
+ desc->mask = type->mods.mask;
+ desc->realMods = type->mods.real_mods;
+ desc->virtualMods = type->mods.vmods;
+ desc->numLevels = type->num_levels;
+ desc->nMapEntries = type->map_count;
+ desc->preserve = (type->preserve!=NULL);
+ buf= (char *)&desc[1];
+ if (desc->nMapEntries>0) {
+ xkbKTSetMapEntryWireDesc *wire;
+ wire= (xkbKTSetMapEntryWireDesc *)buf;
+ for (n=0;n<type->map_count;n++,wire++) {
+ wire->level= type->map[n].level;
+ wire->realMods= type->map[n].mods.real_mods;
+ wire->virtualMods= type->map[n].mods.vmods;
+ }
+ buf= (char *)wire;
+ if (type->preserve) {
+ xkbModsWireDesc *pwire;
+ pwire= (xkbModsWireDesc *)buf;
+ for (n=0;n<type->map_count;n++,pwire++) {
+ pwire->realMods= type->preserve[n].real_mods;
+ pwire->virtualMods= type->preserve[n].vmods;
+ }
+ }
+ }
+ }
+ return;
+}
+
+static int
+_XkbSizeKeySyms(XkbDescPtr xkb,xkbSetMapReq *req)
+{
+ int i,len;
+ unsigned nSyms;
+
+ if (((req->present&XkbKeySymsMask)==0)||(req->nKeySyms==0)) {
+ req->present&= ~XkbKeySymsMask;
+ req->firstKeySym= req->nKeySyms= 0;
+ req->totalSyms= 0;
+ return 0;
+ }
+ len= (int)(req->nKeySyms*sizeof(XkbSymMapRec));
+ for (i=nSyms=0;i<req->nKeySyms;i++) {
+ nSyms+= XkbKeyNumSyms(xkb,i+req->firstKeySym);
+ }
+ len+= nSyms*sizeof(CARD32);
+ req->totalSyms= nSyms;
+ return len;
+}
+
+static void
+_XkbWriteKeySyms(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register KeySym * pSym;
+CARD32 * outSym;
+XkbSymMapPtr symMap;
+xkbSymMapWireDesc *desc;
+register int i;
+
+ if ((req->present&XkbKeySymsMask)==0)
+ return;
+ symMap = &xkb->map->key_sym_map[req->firstKeySym];
+ for (i=0;i<req->nKeySyms;i++,symMap++) {
+ BufAlloc(xkbSymMapWireDesc *,desc,
+ SIZEOF(xkbSymMapWireDesc)+
+ (XkbKeyNumSyms(xkb,i+req->firstKeySym)*sizeof(CARD32)));
+ desc->ktIndex[0] = symMap->kt_index[0];
+ desc->ktIndex[1] = symMap->kt_index[1];
+ desc->ktIndex[2] = symMap->kt_index[2];
+ desc->ktIndex[3] = symMap->kt_index[3];
+ desc->groupInfo = symMap->group_info;
+ desc->width = symMap->width;
+ desc->nSyms = XkbKeyNumSyms(xkb,i+req->firstKeySym);
+ outSym = (CARD32 *)&desc[1];
+ if (desc->nSyms>0) {
+ pSym = XkbKeySymsPtr(xkb,i+req->firstKeySym);
+ _XkbWriteCopyKeySyms(pSym,outSym,desc->nSyms);
+ }
+ }
+ return;
+}
+
+static int
+_XkbSizeKeyActions(XkbDescPtr xkb,xkbSetMapReq *req)
+{
+ int i,len,nActs;
+
+ if (((req->present&XkbKeyActionsMask)==0)||(req->nKeyActs==0)) {
+ req->present&= ~XkbKeyActionsMask;
+ req->firstKeyAct= req->nKeyActs= 0;
+ req->totalActs= 0;
+ return 0;
+ }
+ for (nActs=i=0;i<req->nKeyActs;i++) {
+ if (xkb->server->key_acts[i+req->firstKeyAct]!=0)
+ nActs+= XkbKeyNumActions(xkb,i+req->firstKeyAct);
+ }
+ len= XkbPaddedSize(req->nKeyActs)+(nActs*SIZEOF(xkbActionWireDesc));
+ req->totalActs= nActs;
+ return len;
+}
+
+static void
+_XkbWriteKeyActions(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
+{
+ register int i;
+ int n;
+ CARD8 *numDesc;
+ XkbAction *actDesc;
+
+ if ((req->present&XkbKeyActionsMask)==0)
+ return;
+ n = XkbPaddedSize(req->nKeyActs);
+ n+= (req->totalActs*SIZEOF(xkbActionWireDesc));
+
+ BufAlloc(CARD8 *,numDesc,n);
+ for (i=0;i<req->nKeyActs;i++) {
+ if (xkb->server->key_acts[i+req->firstKeyAct]==0)
+ numDesc[i] = 0;
+ else numDesc[i] = XkbKeyNumActions(xkb,(i+req->firstKeyAct));
+ }
+ actDesc = (XkbAction *)&numDesc[XkbPaddedSize(req->nKeyActs)];
+ for (i=0;i<req->nKeyActs;i++) {
+ if (xkb->server->key_acts[i+req->firstKeyAct]!=0) {
+ n = XkbKeyNumActions(xkb,(i+req->firstKeyAct));
+ memcpy(actDesc,XkbKeyActionsPtr(xkb,(i+req->firstKeyAct)),
+ n*SIZEOF(xkbActionWireDesc));
+ actDesc+= n;
+ }
+ }
+ return;
+}
+
+static int
+_XkbSizeKeyBehaviors(XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register int i,first,last,nFound;
+
+ if (((req->present&XkbKeyBehaviorsMask)==0)||(req->nKeyBehaviors<1)) {
+ req->present&= ~XkbKeyBehaviorsMask;
+ req->firstKeyBehavior= req->nKeyBehaviors= 0;
+ req->totalKeyBehaviors= 0;
+ return 0;
+ }
+ first= req->firstKeyBehavior;
+ last= first+req->nKeyBehaviors-1;
+ for (i=first,nFound=0;i<=last;i++) {
+ if (xkb->server->behaviors[i].type!=XkbKB_Default)
+ nFound++;
+ }
+ req->totalKeyBehaviors= nFound;
+ return (nFound*SIZEOF(xkbBehaviorWireDesc));
+}
+
+static void
+_XkbWriteKeyBehaviors(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register int i,first,last;
+xkbBehaviorWireDesc * wire;
+char * buf;
+
+ if ((req->present&XkbKeyBehaviorsMask)==0)
+ return;
+ first= req->firstKeyBehavior;
+ last= first+req->nKeyBehaviors-1;
+
+ i= req->totalKeyBehaviors*SIZEOF(xkbBehaviorWireDesc);
+ BufAlloc(char *,buf,i);
+ wire= (xkbBehaviorWireDesc *)buf;
+ for (i=first;i<=last;i++) {
+ if (xkb->server->behaviors[i].type!=XkbKB_Default) {
+ wire->key= i;
+ wire->type= xkb->server->behaviors[i].type;
+ wire->data= xkb->server->behaviors[i].data;
+ buf+= SIZEOF(xkbBehaviorWireDesc);
+ wire= (xkbBehaviorWireDesc *)buf;
+ }
+ }
+ return;
+}
+
+static unsigned
+_XkbSizeVirtualMods(xkbSetMapReq *req)
+{
+register int i,bit,nMods;
+
+ if (((req->present&XkbVirtualModsMask)==0)||(req->virtualMods==0)) {
+ req->present&= ~XkbVirtualModsMask;
+ req->virtualMods= 0;
+ return 0;
+ }
+ for (i=nMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
+ if (req->virtualMods&bit)
+ nMods++;
+ }
+ return XkbPaddedSize(nMods);
+}
+
+static void
+_XkbWriteVirtualMods( Display * dpy,
+ XkbDescPtr xkb,
+ xkbSetMapReq * req,
+ unsigned size)
+{
+ register int i,bit;
+ CARD8 *vmods;
+
+ /* This was req->present&XkbVirtualModsMask==0, and '==' beats '&' */
+ if (((req->present & XkbVirtualModsMask) == 0) || (size < 1))
+ return;
+ BufAlloc(CARD8 *,vmods,size);
+ for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
+ if (req->virtualMods&bit)
+ *vmods++= xkb->server->vmods[i];
+ }
+ return;
+}
+
+static int
+_XkbSizeKeyExplicit(XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register int i,first,last,nFound;
+
+ if (((req->present&XkbExplicitComponentsMask)==0)||(req->nKeyExplicit==0)) {
+ req->present&= ~XkbExplicitComponentsMask;
+ req->firstKeyExplicit= req->nKeyExplicit= 0;
+ req->totalKeyExplicit= 0;
+ return 0;
+ }
+ first= req->firstKeyExplicit;
+ last= first+req->nKeyExplicit-1;
+
+ for (i=first,nFound=0;i<=last;i++) {
+ if (xkb->server->explicit[i]!=0)
+ nFound++;
+ }
+ req->totalKeyExplicit= nFound;
+ return XkbPaddedSize((nFound*2));
+}
+
+static void
+_XkbWriteKeyExplicit(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register int i,first,last;
+CARD8 * wire;
+
+ if ((req->present&XkbExplicitComponentsMask)==0)
+ return;
+ first= req->firstKeyExplicit;
+ last= first+req->nKeyExplicit - 1;
+ i= XkbPaddedSize((req->totalKeyExplicit*2));
+ BufAlloc(CARD8 *,wire,i);
+ for (i=first;i<=last;i++) {
+ if (xkb->server->explicit[i]!=0) {
+ wire[0]= i;
+ wire[1]= xkb->server->explicit[i];
+ wire+= 2;
+ }
+ }
+ return;
+}
+
+static int
+_XkbSizeModifierMap(XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register int i,first,last,nFound;
+
+ if (((req->present&XkbModifierMapMask)==0)||(req->nModMapKeys==0)) {
+ req->present&= ~XkbModifierMapMask;
+ req->firstModMapKey= req->nModMapKeys= 0;
+ req->totalModMapKeys= 0;
+ return 0;
+ }
+ first= req->firstModMapKey;
+ last= first+req->nModMapKeys-1;
+
+ for (i=first,nFound=0;i<=last;i++) {
+ if (xkb->map->modmap[i]!=0)
+ nFound++;
+ }
+ req->totalModMapKeys= nFound;
+ return XkbPaddedSize((nFound*2));
+}
+
+static void
+_XkbWriteModifierMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register int i,first,last;
+CARD8 * wire;
+
+ if ((req->present&XkbModifierMapMask)==0)
+ return;
+ first= req->firstModMapKey;
+ last= first+req->nModMapKeys-1;
+ if (req->totalModMapKeys>0) {
+ i= XkbPaddedSize((req->totalModMapKeys*2));
+ BufAlloc(CARD8 *,wire,i);
+ for (i=first;i<=last;i++) {
+ if (xkb->map->modmap[i]!=0) {
+ wire[0]= i;
+ wire[1]= xkb->map->modmap[i];
+ wire+= 2;
+ }
+ }
+ }
+ return;
+}
+
+static int
+_XkbSizeVirtualModMap(XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register int i,first,last,nFound;
+
+ if (((req->present&XkbVirtualModMapMask)==0)||(req->nVModMapKeys==0)) {
+ req->present&= ~XkbVirtualModMapMask;
+ req->firstVModMapKey= req->nVModMapKeys= 0;
+ req->totalVModMapKeys= 0;
+ return 0;
+ }
+ first= req->firstVModMapKey;
+ last= first+req->nVModMapKeys-1;
+
+ for (i=first,nFound=0;i<=last;i++) {
+ if (xkb->server->vmodmap[i]!=0)
+ nFound++;
+ }
+ req->totalVModMapKeys= nFound;
+ return nFound*SIZEOF(xkbVModMapWireDesc);
+}
+
+static void
+_XkbWriteVirtualModMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
+{
+register int i,first,last;
+xkbVModMapWireDesc * wire;
+
+ if ((req->present&XkbVirtualModMapMask)==0)
+ return;
+ first= req->firstVModMapKey;
+ last= first+req->nVModMapKeys-1;
+ if (req->totalVModMapKeys>0) {
+ i= req->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc);
+ BufAlloc(xkbVModMapWireDesc *,wire,i);
+ for (i=first;i<=last;i++) {
+ if (xkb->server->vmodmap[i]!=0) {
+ wire->key= i;
+ wire->vmods= xkb->server->vmodmap[i];
+ wire++;
+ }
+ }
+ }
+ return;
+}
+
+static void
+SendSetMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req)
+{
+xkbSetMapReq tmp;
+unsigned szMods;
+
+ req->length+= _XkbSizeKeyTypes(xkb,req)/4;
+ req->length+= _XkbSizeKeySyms(xkb,req)/4;
+ req->length+= _XkbSizeKeyActions(xkb,req)/4;
+ req->length+= _XkbSizeKeyBehaviors(xkb,req)/4;
+ szMods= _XkbSizeVirtualMods(req);
+ req->length+= szMods/4;
+ req->length+= _XkbSizeKeyExplicit(xkb,req)/4;
+ req->length+= _XkbSizeModifierMap(xkb,req)/4;
+ req->length+= _XkbSizeVirtualModMap(xkb,req)/4;
+
+ tmp= *req;
+ if ( tmp.nTypes>0 )
+ _XkbWriteKeyTypes(dpy,xkb,&tmp);
+ if ( tmp.nKeySyms>0 )
+ _XkbWriteKeySyms(dpy,xkb,&tmp);
+ if ( tmp.nKeyActs )
+ _XkbWriteKeyActions(dpy,xkb,&tmp);
+ if ( tmp.totalKeyBehaviors>0 )
+ _XkbWriteKeyBehaviors(dpy,xkb,&tmp);
+ if ( tmp.virtualMods )
+ _XkbWriteVirtualMods(dpy,xkb,&tmp,szMods);
+ if ( tmp.totalKeyExplicit>0)
+ _XkbWriteKeyExplicit(dpy,xkb,&tmp);
+ if ( tmp.totalModMapKeys>0)
+ _XkbWriteModifierMap(dpy,xkb,&tmp);
+ if ( tmp.totalVModMapKeys>0)
+ _XkbWriteVirtualModMap(dpy,xkb,&tmp);
+ return;
+}
+
+Bool
+XkbSetMap(Display *dpy,unsigned which,XkbDescPtr xkb)
+{
+register xkbSetMapReq * req;
+XkbInfoPtr xkbi;
+XkbServerMapPtr srv;
+XkbClientMapPtr map;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))||
+ (!xkb))
+ return False;
+ map= xkb->map;
+ srv= xkb->server;
+
+ if (((which&XkbKeyTypesMask)&&((!map)||(!map->types)))||
+ ((which&XkbKeySymsMask)&&((!map)||(!map->syms)||(!map->key_sym_map)))||
+ ((which&XkbKeyActionsMask)&&((!srv)||(!srv->key_acts)))||
+ ((which&XkbKeyBehaviorsMask)&&((!srv)||(!srv->behaviors)))||
+ ((which&XkbVirtualModsMask)&&(!srv))||
+ ((which&XkbExplicitComponentsMask)&&((!srv)||(!srv->explicit)))||
+ ((which&XkbModifierMapMask)&&((!map)||(!map->modmap)))||
+ ((which&XkbVirtualModMapMask)&&((!srv)||(!srv->vmodmap))))
+ return False;
+
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetMap, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSetMap;
+ req->deviceSpec = xkb->device_spec;
+ req->present = which;
+ req->flags = XkbSetMapAllFlags;
+ req->minKeyCode= xkb->min_key_code;
+ req->maxKeyCode= xkb->max_key_code;
+ req->firstType = 0;
+ if (which&XkbKeyTypesMask) req->nTypes = map->num_types;
+ else req->nTypes = 0;
+ if (which&XkbKeySymsMask) {
+ req->firstKeySym = xkb->min_key_code;
+ req->nKeySyms = XkbNumKeys(xkb);
+ }
+ if (which&XkbKeyActionsMask) {
+ req->firstKeyAct = xkb->min_key_code;
+ req->nKeyActs = XkbNumKeys(xkb);
+ }
+ if (which&XkbKeyBehaviorsMask) {
+ req->firstKeyBehavior = xkb->min_key_code;
+ req->nKeyBehaviors = XkbNumKeys(xkb);
+ }
+ if (which&XkbVirtualModsMask)
+ req->virtualMods= ~0;
+ if (which&XkbExplicitComponentsMask) {
+ req->firstKeyExplicit= xkb->min_key_code;
+ req->nKeyExplicit = XkbNumKeys(xkb);
+ }
+ if (which&XkbModifierMapMask) {
+ req->firstModMapKey= xkb->min_key_code;
+ req->nModMapKeys = XkbNumKeys(xkb);
+ }
+ if (which&XkbVirtualModMapMask) {
+ req->firstVModMapKey= xkb->min_key_code;
+ req->nVModMapKeys = XkbNumKeys(xkb);
+ }
+ SendSetMap(dpy,xkb,req);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbChangeMap(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes)
+{
+register xkbSetMapReq * req;
+XkbInfoPtr xkbi;
+XkbServerMapPtr srv;
+XkbClientMapPtr map;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))||
+ (!xkb)||(!changes))
+ return False;
+ srv= xkb->server;
+ map= xkb->map;
+
+ if (((changes->changed&XkbKeyTypesMask)&&((!map)||(!map->types)))||
+ ((changes->changed&XkbKeySymsMask)&&((!map)||(!map->syms)||
+ (!map->key_sym_map)))||
+ ((changes->changed&XkbKeyActionsMask)&&((!srv)||(!srv->key_acts)))||
+ ((changes->changed&XkbKeyBehaviorsMask)&&((!srv)||(!srv->behaviors)))||
+ ((changes->changed&XkbVirtualModsMask)&&(!srv))||
+ ((changes->changed&XkbExplicitComponentsMask)&&
+ ((!srv)||(!srv->explicit)))||
+ ((changes->changed&XkbModifierMapMask)&&((!map)||(!map->modmap)))||
+ ((changes->changed&XkbVirtualModMapMask)&&((!srv)||(!srv->vmodmap))))
+ return False;
+
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetMap, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSetMap;
+ req->deviceSpec = xkb->device_spec;
+ req->present = changes->changed;
+ req->flags = XkbSetMapRecomputeActions;
+ req->minKeyCode= xkb->min_key_code;
+ req->maxKeyCode= xkb->max_key_code;
+ req->firstType = changes->first_type;
+ req->nTypes = changes->num_types;
+ req->firstKeySym = changes->first_key_sym;
+ req->nKeySyms = changes->num_key_syms;
+ req->firstKeyAct = changes->first_key_act;
+ req->nKeyActs = changes->num_key_acts;
+ req->firstKeyBehavior = changes->first_key_behavior;
+ req->nKeyBehaviors = changes->num_key_behaviors;
+ req->virtualMods = changes->vmods;
+ req->firstKeyExplicit = changes->first_key_explicit;
+ req->nKeyExplicit = changes->num_key_explicit;
+ req->firstModMapKey = changes->first_modmap_key;
+ req->nModMapKeys = changes->num_modmap_keys;
+ req->firstVModMapKey = changes->first_vmodmap_key;
+ req->nVModMapKeys = changes->num_vmodmap_keys;
+ SendSetMap(dpy,xkb,req);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
diff --git a/libX11/src/xkb/XKBUse.c b/libX11/src/xkb/XKBUse.c
index 4b6c1daa8..a16d6963a 100644
--- a/libX11/src/xkb/XKBUse.c
+++ b/libX11/src/xkb/XKBUse.c
@@ -1,827 +1,825 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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 <stdio.h>
-#include <ctype.h>
-#define NEED_REPLIES
-#define NEED_EVENTS
-
-#ifdef XKB_IN_SERVER
-#define XkbAllocClientMap SrvXkbAllocClientMap
-#define XkbAllocServerMap SrvXkbAllocServerMap
-#define XkbChangeTypesOfKey SrvXkbChangeTypesOfKey
-#define XkbCopyKeyTypes SrvXkbCopyKeyTypes
-#define XkbFreeClientMap SrvXkbFreeClientMap
-#define XkbFreeServerMap SrvXkbFreeServerMap
-#define XkbKeyTypesForCoreSymbols SrvXkbKeyTypesForCoreSymbols
-#define XkbApplyCompatMapToKey SrvXkbApplyCompatMapToKey
-#define XkbResizeKeyActions SrvXkbResizeKeyActions
-#define XkbResizeKeySyms SrvXkbResizeKeySyms
-#define XkbResizeKeyType SrvXkbResizeKeyType
-#define XkbAllocCompatMap SrvXkbAllocCompatMap
-#define XkbAllocControls SrvXkbAllocControls
-#define XkbAllocIndicatorMaps SrvXkbAllocIndicatorMaps
-#define XkbAllocKeyboard SrvXkbAllocKeyboard
-#define XkbAllocNames SrvXkbAllocNames
-#define XkbFreeCompatMap SrvXkbFreeCompatMap
-#define XkbFreeKeyboard SrvXkbFreeKeyboard
-#define XkbFreeNames SrvXkbFreeNames
-#define XkbLatchModifiers SrvXkbLatchModifiers
-#define XkbLatchGroup SrvXkbLatchGroup
-#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
-#define XkbChangeKeycodeRange SrvXkbChangeKeycodeRange
-#define XkbApplyVirtualModChanges SrvXkbApplyVirtualModChanges
-#endif
-
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-static Bool _XkbIgnoreExtension = False;
-
-void
-XkbNoteMapChanges(XkbMapChangesPtr old,XkbMapNotifyEvent *new,unsigned wanted)
-{
- int first,oldLast,newLast;
- wanted&= new->changed;
-
- if (wanted&XkbKeyTypesMask) {
- if (old->changed&XkbKeyTypesMask) {
- first = old->first_type;
- oldLast = old->first_type+old->num_types-1;
- newLast = new->first_type+new->num_types-1;
-
- if (new->first_type<first)
- first = new->first_type;
- if (oldLast>newLast)
- newLast= oldLast;
- old->first_type = first;
- old->num_types = newLast-first+1;
- }
- else {
- old->first_type= new->first_type;
- old->num_types = new->num_types;
- }
- }
- if (wanted&XkbKeySymsMask) {
- if (old->changed&XkbKeySymsMask) {
- first = old->first_key_sym;
- oldLast = old->first_key_sym+old->num_key_syms-1;
- newLast = new->first_key_sym+new->num_key_syms-1;
-
- if (new->first_key_sym<first)
- first = new->first_key_sym;
- if (oldLast>newLast)
- newLast= oldLast;
- old->first_key_sym = first;
- old->num_key_syms = newLast-first+1;
- }
- else {
- old->first_key_sym = new->first_key_sym;
- old->num_key_syms = new->num_key_syms;
- }
- }
- if (wanted&XkbKeyActionsMask) {
- if (old->changed&XkbKeyActionsMask) {
- first = old->first_key_act;
- oldLast = old->first_key_act+old->num_key_acts-1;
- newLast = new->first_key_act+new->num_key_acts-1;
-
- if (new->first_key_act<first)
- first = new->first_key_act;
- if (oldLast>newLast)
- newLast= oldLast;
- old->first_key_act = first;
- old->num_key_acts = newLast-first+1;
- }
- else {
- old->first_key_act = new->first_key_act;
- old->num_key_acts = new->num_key_acts;
- }
- }
- if (wanted&XkbKeyBehaviorsMask) {
- if (old->changed&XkbKeyBehaviorsMask) {
- first = old->first_key_behavior;
- oldLast = old->first_key_behavior+old->num_key_behaviors-1;
- newLast = new->first_key_behavior+new->num_key_behaviors-1;
-
- if (new->first_key_behavior<first)
- first = new->first_key_behavior;
- if (oldLast>newLast)
- newLast= oldLast;
- old->first_key_behavior = first;
- old->num_key_behaviors = newLast-first+1;
- }
- else {
- old->first_key_behavior = new->first_key_behavior;
- old->num_key_behaviors = new->num_key_behaviors;
- }
- }
- if (wanted&XkbVirtualModsMask) {
- old->vmods|= new->vmods;
- }
- if (wanted&XkbExplicitComponentsMask) {
- if (old->changed&XkbExplicitComponentsMask) {
- first = old->first_key_explicit;
- oldLast = old->first_key_explicit+old->num_key_explicit-1;
- newLast = new->first_key_explicit+new->num_key_explicit-1;
-
- if (new->first_key_explicit<first)
- first = new->first_key_explicit;
- if (oldLast>newLast)
- newLast= oldLast;
- old->first_key_explicit = first;
- old->num_key_explicit = newLast-first+1;
- }
- else {
- old->first_key_explicit = new->first_key_explicit;
- old->num_key_explicit = new->num_key_explicit;
- }
- }
- if (wanted&XkbModifierMapMask) {
- if (old->changed&XkbModifierMapMask) {
- first = old->first_modmap_key;
- oldLast = old->first_modmap_key+old->num_modmap_keys-1;
- newLast = new->first_modmap_key+new->num_modmap_keys-1;
-
- if (new->first_modmap_key<first)
- first = new->first_modmap_key;
- if (oldLast>newLast)
- newLast= oldLast;
- old->first_modmap_key = first;
- old->num_modmap_keys = newLast-first+1;
- }
- else {
- old->first_modmap_key = new->first_modmap_key;
- old->num_modmap_keys = new->num_modmap_keys;
- }
- }
- if (wanted&XkbVirtualModMapMask) {
- if (old->changed&XkbVirtualModMapMask) {
- first = old->first_vmodmap_key;
- oldLast = old->first_vmodmap_key+old->num_vmodmap_keys-1;
- newLast = new->first_vmodmap_key+new->num_vmodmap_keys-1;
-
- if (new->first_vmodmap_key<first)
- first = new->first_vmodmap_key;
- if (oldLast>newLast)
- newLast= oldLast;
- old->first_vmodmap_key = first;
- old->num_vmodmap_keys = newLast-first+1;
- }
- else {
- old->first_vmodmap_key = new->first_vmodmap_key;
- old->num_vmodmap_keys = new->num_vmodmap_keys;
- }
- }
- old->changed|= wanted;
- return;
-}
-
-void
-_XkbNoteCoreMapChanges( XkbMapChangesPtr old,
- XMappingEvent * new,
- unsigned int wanted)
-{
- int first,oldLast,newLast;
-
- if ((new->request==MappingKeyboard)&&(wanted&XkbKeySymsMask)) {
- if (old->changed&XkbKeySymsMask) {
- first = old->first_key_sym;
- oldLast = old->first_key_sym+old->num_key_syms-1;
- newLast = new->first_keycode+new->count-1;
-
- if (new->first_keycode<first)
- first = new->first_keycode;
- if (oldLast>newLast)
- newLast= oldLast;
- old->first_key_sym = first;
- old->num_key_syms = newLast-first+1;
- }
- else {
- old->changed|= XkbKeySymsMask;
- old->first_key_sym = new->first_keycode;
- old->num_key_syms = new->count;
- }
- }
- return;
-}
-
-static Bool
-wire_to_event(Display *dpy,XEvent *re,xEvent *event)
-{
- xkbEvent *xkbevent= (xkbEvent *)event;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- xkbi = dpy->xkb_info;
- if (((event->u.u.type&0x7f)-xkbi->codes->first_event)!=XkbEventCode)
- return False;
-
- switch (xkbevent->u.any.xkbType) {
- case XkbStateNotify:
- {
- xkbStateNotify *sn = (xkbStateNotify *)event;
- if ( xkbi->selected_events&XkbStateNotifyMask ) {
- XkbStateNotifyEvent *sev=(XkbStateNotifyEvent *)re;
- sev->type = XkbEventCode+xkbi->codes->first_event;
- sev->xkb_type = XkbStateNotify;
- sev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- sev->send_event = ((event->u.u.type & 0x80) != 0);
- sev->display = dpy;
- sev->time = sn->time;
- sev->device = sn->deviceID;
- sev->keycode = sn->keycode;
- sev->event_type = sn->eventType;
- sev->req_major = sn->requestMajor;
- sev->req_minor = sn->requestMinor;
- sev->changed = sn->changed;
- sev->group = sn->group;
- sev->base_group = sn->baseGroup;
- sev->latched_group = sn->latchedGroup;
- sev->locked_group = sn->lockedGroup;
- sev->mods = sn->mods;
- sev->base_mods = sn->baseMods;
- sev->latched_mods = sn->latchedMods;
- sev->locked_mods = sn->lockedMods;
- sev->compat_state = sn->compatState;
- sev->grab_mods = sn->grabMods;
- sev->compat_grab_mods = sn->compatGrabMods;
- sev->lookup_mods = sn->lookupMods;
- sev->compat_lookup_mods = sn->compatLookupMods;
- sev->ptr_buttons = sn->ptrBtnState;
- return True;
- }
- }
- break;
- case XkbMapNotify:
- {
- xkbMapNotify *mn = (xkbMapNotify *)event;
- if ((xkbi->selected_events&XkbMapNotifyMask)&&
- (xkbi->selected_map_details&mn->changed)) {
- XkbMapNotifyEvent *mev;
- mev =(XkbMapNotifyEvent *)re;
- mev->type = XkbEventCode+xkbi->codes->first_event;
- mev->xkb_type = XkbMapNotify;
- mev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- mev->send_event = ((event->u.u.type&0x80)!=0);
- mev->display = dpy;
- mev->time = mn->time;
- mev->device = mn->deviceID;
- mev->changed = mn->changed;
- mev->min_key_code = mn->minKeyCode;
- mev->max_key_code = mn->maxKeyCode;
- mev->first_type = mn->firstType;
- mev->num_types = mn->nTypes;
- mev->first_key_sym = mn->firstKeySym;
- mev->num_key_syms = mn->nKeySyms;
- mev->first_key_act = mn->firstKeyAct;
- mev->num_key_acts = mn->nKeyActs;
- mev->first_key_behavior = mn->firstKeyBehavior;
- mev->num_key_behaviors = mn->nKeyBehaviors;
- mev->vmods = mn->virtualMods;
- mev->first_key_explicit = mn->firstKeyExplicit;
- mev->num_key_explicit = mn->nKeyExplicit;
- mev->first_modmap_key = mn->firstModMapKey;
- mev->num_modmap_keys = mn->nModMapKeys;
- mev->first_vmodmap_key = mn->firstVModMapKey;
- mev->num_vmodmap_keys = mn->nVModMapKeys;
- XkbNoteMapChanges(&xkbi->changes,mev,XKB_XLIB_MAP_MASK);
- if (xkbi->changes.changed)
- xkbi->flags|= XkbMapPending;
- return True;
- }
- else if (mn->nKeySyms>0) {
- register XMappingEvent *ev = (XMappingEvent *)re;
- ev->type = MappingNotify;
- ev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- ev->send_event = ((event->u.u.type&0x80)!=0);
- ev->display = dpy;
- ev->window = 0;
- ev->first_keycode = mn->firstKeySym;
- ev->request = MappingKeyboard;
- ev->count = mn->nKeySyms;
- _XkbNoteCoreMapChanges(&xkbi->changes,ev,XKB_XLIB_MAP_MASK);
- if (xkbi->changes.changed)
- xkbi->flags|= XkbMapPending;
- return True;
- }
- }
- break;
- case XkbControlsNotify:
- {
- if (xkbi->selected_events&XkbControlsNotifyMask) {
- xkbControlsNotify *cn =(xkbControlsNotify *)event;
- XkbControlsNotifyEvent *cev;
- cev =(XkbControlsNotifyEvent *)re;
- cev->type = XkbEventCode+xkbi->codes->first_event;
- cev->xkb_type = XkbControlsNotify;
- cev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- cev->send_event = ((event->u.u.type&0x80)!=0);
- cev->display = dpy;
- cev->time = cn->time;
- cev->device = cn->deviceID;
- cev->changed_ctrls = cn->changedControls;
- cev->enabled_ctrls = cn->enabledControls;
- cev->enabled_ctrl_changes = cn->enabledControlChanges;
- cev->keycode = cn->keycode;
- cev->num_groups = cn->numGroups;
- cev->event_type = cn->eventType;
- cev->req_major = cn->requestMajor;
- cev->req_minor = cn->requestMinor;
- return True;
- }
- }
- break;
- case XkbIndicatorMapNotify:
- {
- if (xkbi->selected_events&XkbIndicatorMapNotifyMask) {
- xkbIndicatorNotify *in =(xkbIndicatorNotify *)event;
- XkbIndicatorNotifyEvent *iev;
- iev =(XkbIndicatorNotifyEvent *)re;
- iev->type = XkbEventCode+xkbi->codes->first_event;
- iev->xkb_type = XkbIndicatorMapNotify;
- iev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- iev->send_event = ((event->u.u.type&0x80)!=0);
- iev->display = dpy;
- iev->time = in->time;
- iev->device = in->deviceID;
- iev->changed = in->changed;
- iev->state= in->state;
- return True;
- }
- }
- break;
- case XkbIndicatorStateNotify:
- {
- if (xkbi->selected_events&XkbIndicatorStateNotifyMask) {
- xkbIndicatorNotify *in =(xkbIndicatorNotify *)event;
- XkbIndicatorNotifyEvent *iev;
- iev =(XkbIndicatorNotifyEvent *)re;
- iev->type = XkbEventCode+xkbi->codes->first_event;
- iev->xkb_type = XkbIndicatorStateNotify;
- iev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- iev->send_event = ((event->u.u.type&0x80)!=0);
- iev->display = dpy;
- iev->time = in->time;
- iev->device = in->deviceID;
- iev->changed = in->changed;
- iev->state= in->state;
- return True;
- }
- }
- break;
- case XkbBellNotify:
- {
- if (xkbi->selected_events&XkbBellNotifyMask) {
- xkbBellNotify *bn =(xkbBellNotify *)event;
- XkbBellNotifyEvent *bev;
- bev =(XkbBellNotifyEvent *)re;
- bev->type = XkbEventCode+xkbi->codes->first_event;
- bev->xkb_type = XkbBellNotify;
- bev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- bev->send_event = ((event->u.u.type&0x80)!=0);
- bev->display = dpy;
- bev->time = bn->time;
- bev->device = bn->deviceID;
- bev->percent = bn->percent;
- bev->pitch = bn->pitch;
- bev->duration = bn->duration;
- bev->bell_class = bn->bellClass;
- bev->bell_id = bn->bellID;
- bev->name = bn->name;
- bev->window = bn->window;
- bev->event_only = bn->eventOnly;
- return True;
- }
- }
- break;
- case XkbAccessXNotify:
- {
- if (xkbi->selected_events&XkbAccessXNotifyMask) {
- xkbAccessXNotify *axn =(xkbAccessXNotify *)event;
- XkbAccessXNotifyEvent *axev;
- axev =(XkbAccessXNotifyEvent *)re;
- axev->type = XkbEventCode+xkbi->codes->first_event;
- axev->xkb_type = XkbAccessXNotify;
- axev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- axev->send_event = ((event->u.u.type&0x80)!=0);
- axev->display = dpy;
- axev->time = axn->time;
- axev->device = axn->deviceID;
- axev->detail = axn->detail;
- axev->keycode = axn->keycode;
- axev->sk_delay = axn->slowKeysDelay;
- axev->debounce_delay = axn->debounceDelay;
- return True;
- }
- }
- break;
- case XkbNamesNotify:
- {
- if (xkbi->selected_events&XkbNamesNotifyMask) {
- xkbNamesNotify *nn =(xkbNamesNotify *)event;
- XkbNamesNotifyEvent *nev;
- nev =(XkbNamesNotifyEvent *)re;
- nev->type = XkbEventCode+xkbi->codes->first_event;
- nev->xkb_type = XkbNamesNotify;
- nev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- nev->send_event = ((event->u.u.type&0x80)!=0);
- nev->display = dpy;
- nev->time = nn->time;
- nev->device = nn->deviceID;
- nev->changed = nn->changed;
- nev->first_type = nn->firstType;
- nev->num_types = nn->nTypes;
- nev->first_lvl = nn->firstLevelName;
- nev->num_lvls = nn->nLevelNames;
- nev->num_aliases = nn->nAliases;
- nev->num_radio_groups = nn->nRadioGroups;
- nev->changed_vmods = nn->changedVirtualMods;
- nev->changed_groups = nn->changedGroupNames;
- nev->changed_indicators = nn->changedIndicators;
- nev->first_key = nn->firstKey;
- nev->num_keys = nn->nKeys;
- return True;
- }
- }
- break;
- case XkbCompatMapNotify:
- {
- if (xkbi->selected_events&XkbCompatMapNotifyMask) {
- xkbCompatMapNotify *cmn =(xkbCompatMapNotify *)event;
- XkbCompatMapNotifyEvent *cmev;
- cmev =(XkbCompatMapNotifyEvent *)re;
- cmev->type = XkbEventCode+xkbi->codes->first_event;
- cmev->xkb_type = XkbCompatMapNotify;
- cmev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- cmev->send_event = ((event->u.u.type&0x80)!=0);
- cmev->display = dpy;
- cmev->time = cmn->time;
- cmev->device = cmn->deviceID;
- cmev->changed_groups = cmn->changedGroups;
- cmev->first_si = cmn->firstSI;
- cmev->num_si = cmn->nSI;
- cmev->num_total_si = cmn->nTotalSI;
- return True;
- }
- }
- break;
- case XkbActionMessage:
- {
- if (xkbi->selected_events&XkbActionMessageMask) {
- xkbActionMessage *am= (xkbActionMessage *)event;
- XkbActionMessageEvent *amev;
- amev= (XkbActionMessageEvent *)re;
- amev->type = XkbEventCode+xkbi->codes->first_event;
- amev->xkb_type = XkbActionMessage;
- amev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- amev->send_event = ((event->u.u.type&0x80)!=0);
- amev->display = dpy;
- amev->time = am->time;
- amev->device = am->deviceID;
- amev->keycode = am->keycode;
- amev->press = am->press;
- amev->key_event_follows = am->keyEventFollows;
- amev->group = am->group;
- amev->mods = am->mods;
- memcpy(amev->message,am->message,XkbActionMessageLength);
- amev->message[XkbActionMessageLength]= '\0';
- return True;
- }
- }
- break;
- case XkbExtensionDeviceNotify:
- {
- if (xkbi->selected_events&XkbExtensionDeviceNotifyMask) {
- xkbExtensionDeviceNotify *ed=
- (xkbExtensionDeviceNotify *)event;
- XkbExtensionDeviceNotifyEvent *edev;
- edev= (XkbExtensionDeviceNotifyEvent *)re;
- edev->type= XkbEventCode+xkbi->codes->first_event;
- edev->xkb_type= XkbExtensionDeviceNotify;
- edev->serial= _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- edev->send_event= ((event->u.u.type&0x80)!=0);
- edev->display= dpy;
- edev->time= ed->time;
- edev->device= ed->deviceID;
- edev->led_class= ed->ledClass;
- edev->led_id= ed->ledID;
- edev->reason= ed->reason;
- edev->supported= ed->supported;
- edev->leds_defined= ed->ledsDefined;
- edev->led_state= ed->ledState;
- edev->first_btn= ed->firstBtn;
- edev->num_btns= ed->nBtns;
- edev->unsupported= ed->unsupported;
- return True;
- }
- }
- break;
- case XkbNewKeyboardNotify:
- {
- xkbNewKeyboardNotify *nkn = (xkbNewKeyboardNotify *)event;
- if ((xkbi->selected_events&XkbNewKeyboardNotifyMask)&&
- (xkbi->selected_nkn_details&nkn->changed)) {
- XkbNewKeyboardNotifyEvent *nkev;
- nkev =(XkbNewKeyboardNotifyEvent *)re;
- nkev->type = XkbEventCode+xkbi->codes->first_event;
- nkev->xkb_type = XkbNewKeyboardNotify;
- nkev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- nkev->send_event = ((event->u.u.type&0x80)!=0);
- nkev->display = dpy;
- nkev->time = nkn->time;
- nkev->device = nkn->deviceID;
- nkev->old_device = nkn->oldDeviceID;
- nkev->min_key_code = nkn->minKeyCode;
- nkev->max_key_code = nkn->maxKeyCode;
- nkev->old_min_key_code = nkn->oldMinKeyCode;
- nkev->old_max_key_code = nkn->oldMaxKeyCode;
- nkev->req_major = nkn->requestMajor;
- nkev->req_minor = nkn->requestMinor;
- nkev->changed = nkn->changed;
- if ((xkbi->desc)&&(nkev->send_event==0)&&
- ((xkbi->desc->device_spec==nkev->old_device)||
- (nkev->device!=nkev->old_device))) {
- xkbi->flags= XkbMapPending|XkbXlibNewKeyboard;
- }
- return True;
- }
- else if(nkn->changed&(XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask)){
- register XMappingEvent *ev = (XMappingEvent *)re;
- ev->type = MappingNotify;
- ev->serial = _XSetLastRequestRead(dpy,
- (xGenericReply *)event);
- ev->send_event = ((event->u.u.type&0x80)!=0);
- ev->display = dpy;
- ev->window = 0;
- ev->first_keycode = dpy->min_keycode;
- ev->request = MappingKeyboard;
- ev->count = (dpy->max_keycode-dpy->min_keycode)+1;
- if ((xkbi->desc)&&(ev->send_event==0)&&
- ((xkbi->desc->device_spec==nkn->oldDeviceID)||
- (nkn->deviceID!=nkn->oldDeviceID))) {
- xkbi->flags|= XkbMapPending|XkbXlibNewKeyboard;
- }
- return True;
- }
- }
- break;
- default:
-#ifdef DEBUG
- fprintf(stderr,"Got unknown XKEYBOARD event (%d, base=%d)\n",
- re->type,
- xkbi->codes->first_event);
-#endif
- break;
- }
- return False;
-}
-
-Bool
-XkbIgnoreExtension(Bool ignore)
-{
- if (getenv("XKB_FORCE")!=NULL) {
-#ifdef DEBUG
- fprintf(stderr,"Forcing use of XKEYBOARD (overriding an IgnoreExtensions)\n");
-#endif
- return False;
- }
-#ifdef DEBUG
- else if (getenv("XKB_DEBUG")!=NULL) {
- fprintf(stderr,"Explicitly %signoring XKEYBOARD\n",ignore?"":"not ");
- }
-#endif
- _XkbIgnoreExtension = ignore;
- return True;
-}
-
-static void
-_XkbFreeInfo(Display *dpy)
-{
- XkbInfoPtr xkbi = dpy->xkb_info;
- if (xkbi) {
- if (xkbi->desc)
- XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True);
- Xfree(xkbi);
- }
-}
-
-Bool
-XkbUseExtension(Display *dpy,int *major_rtrn,int *minor_rtrn)
-{
- xkbUseExtensionReply rep;
- register xkbUseExtensionReq *req;
- XExtCodes *codes;
- int ev_base,forceIgnore;
- XkbInfoPtr xkbi;
- char * str;
- static int debugMsg;
- static int been_here= 0;
-
- if ( dpy->xkb_info && !(dpy->flags & XlibDisplayNoXkb)) {
- if (major_rtrn) *major_rtrn= dpy->xkb_info->srv_major;
- if (minor_rtrn) *minor_rtrn= dpy->xkb_info->srv_minor;
- return True;
- }
- if (!been_here) {
- debugMsg= (getenv("XKB_DEBUG")!=NULL);
- been_here= 1;
- }
-
- if (major_rtrn) *major_rtrn= 0;
- if (minor_rtrn) *minor_rtrn= 0;
-
- if (!dpy->xkb_info) {
- xkbi = _XkbTypedCalloc(1, XkbInfoRec);
- if ( !xkbi )
- return False;
- dpy->xkb_info = xkbi;
- dpy->free_funcs->xkb = _XkbFreeInfo;
-
- xkbi->xlib_ctrls|= (XkbLC_ControlFallback|XkbLC_ConsumeLookupMods);
- if ((str=getenv("_XKB_OPTIONS_ENABLE"))!=NULL) {
- if ((str=getenv("_XKB_LATIN1_LOOKUP"))!=NULL) {
- if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
- xkbi->xlib_ctrls&= ~XkbLC_ForceLatin1Lookup;
- else xkbi->xlib_ctrls|= XkbLC_ForceLatin1Lookup;
- }
- if ((str=getenv("_XKB_CONSUME_LOOKUP_MODS"))!=NULL) {
- if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
- xkbi->xlib_ctrls&= ~XkbLC_ConsumeLookupMods;
- else xkbi->xlib_ctrls|= XkbLC_ConsumeLookupMods;
- }
- if ((str=getenv("_XKB_CONSUME_SHIFT_AND_LOCK"))!=NULL) {
- if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
- xkbi->xlib_ctrls&= ~XkbLC_AlwaysConsumeShiftAndLock;
- else xkbi->xlib_ctrls|= XkbLC_AlwaysConsumeShiftAndLock;
- }
- if ((str=getenv("_XKB_IGNORE_NEW_KEYBOARDS"))!=NULL) {
- if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
- xkbi->xlib_ctrls&= ~XkbLC_IgnoreNewKeyboards;
- else xkbi->xlib_ctrls|= XkbLC_IgnoreNewKeyboards;
- }
- if ((str=getenv("_XKB_CONTROL_FALLBACK"))!=NULL) {
- if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
- xkbi->xlib_ctrls&= ~XkbLC_ControlFallback;
- else xkbi->xlib_ctrls|= XkbLC_ControlFallback;
- }
- if ((str=getenv("_XKB_COMP_LED"))!=NULL) {
- if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
- xkbi->xlib_ctrls&= ~XkbLC_ComposeLED;
- else {
- xkbi->xlib_ctrls|= XkbLC_ComposeLED;
- if (strlen(str)>0)
- xkbi->composeLED= XInternAtom(dpy,str,False);
- }
- }
- if ((str=getenv("_XKB_COMP_FAIL_BEEP"))!=NULL) {
- if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
- xkbi->xlib_ctrls&= ~XkbLC_BeepOnComposeFail;
- else xkbi->xlib_ctrls|= XkbLC_BeepOnComposeFail;
- }
- }
- if ((xkbi->composeLED==None)&&((xkbi->xlib_ctrls&XkbLC_ComposeLED)!=0))
- xkbi->composeLED= XInternAtom(dpy,"Compose",False);
-#ifdef DEBUG
- if (debugMsg) {
- register unsigned c= xkbi->xlib_ctrls;
- fprintf(stderr,"XKEYBOARD compose: beep on failure is %s, LED is %s\n",
- ((c&XkbLC_BeepOnComposeFail)?"on":"off"),
- ((c&XkbLC_ComposeLED)?"on":"off"));
- fprintf(stderr,"XKEYBOARD XLookupString: %slatin-1, %s lookup modifiers\n",
- ((c&XkbLC_ForceLatin1Lookup)?"allow non-":"force "),
- ((c&XkbLC_ConsumeLookupMods)?"consume":"re-use"));
- fprintf(stderr,
- "XKEYBOARD XLookupString: %sconsume shift and lock, %scontrol fallback\n",
- ((c&XkbLC_AlwaysConsumeShiftAndLock)?"always ":"don't "),
- ((c&XkbLC_ControlFallback)?"":"no "));
-
- }
-#endif
- } else
- xkbi = dpy->xkb_info;
-
- forceIgnore= (dpy->flags&XlibDisplayNoXkb)||dpy->keysyms;
- forceIgnore= forceIgnore&&(major_rtrn==NULL)&&(minor_rtrn==NULL);
- if ( forceIgnore || _XkbIgnoreExtension || getenv("XKB_DISABLE")) {
- LockDisplay(dpy);
- dpy->flags |= XlibDisplayNoXkb;
- UnlockDisplay(dpy);
- if (debugMsg)
- fprintf(stderr,"XKEYBOARD extension disabled or missing\n");
- return False;
- }
-
- if ( (codes=XInitExtension(dpy,XkbName))==NULL ) {
- LockDisplay(dpy);
- dpy->flags |= XlibDisplayNoXkb;
- UnlockDisplay(dpy);
- if (debugMsg)
- fprintf(stderr,"XKEYBOARD extension not present\n");
- return False;
- }
- xkbi->codes = codes;
- LockDisplay(dpy);
-
- GetReq(kbUseExtension, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbUseExtension;
- req->wantedMajor = XkbMajorVersion;
- req->wantedMinor = XkbMinorVersion;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.supported ) {
- Bool fail;
- fail= True;
- if (debugMsg)
- fprintf(stderr,
- "XKEYBOARD version mismatch (want %d.%02d, got %d.%02d)\n",
- XkbMajorVersion,XkbMinorVersion,
- rep.serverMajor, rep.serverMinor);
-
- /* pre-release 0.65 is very close to 1.00 */
- if ((rep.serverMajor==0)&&(rep.serverMinor==65)) {
- if (debugMsg)
- fprintf(stderr,"Trying to fall back to version 0.65...");
- GetReq(kbUseExtension, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbUseExtension;
- req->wantedMajor = 0;
- req->wantedMinor = 65;
- if ( _XReply(dpy, (xReply *)&rep, 0, xFalse) && rep.supported ) {
- if (debugMsg)
- fprintf(stderr,"succeeded\n");
- fail= False;
- }
- else if (debugMsg) fprintf(stderr,"failed\n");
- }
- if (fail) {
- dpy->flags |= XlibDisplayNoXkb;
- UnlockDisplay(dpy);
- SyncHandle();
- if (major_rtrn) *major_rtrn= rep.serverMajor;
- if (minor_rtrn) *minor_rtrn= rep.serverMinor;
- return False;
- }
- }
-#ifdef DEBUG
- else if ( forceIgnore ) {
- fprintf(stderr,"Internal Error! XkbUseExtension succeeded with forceIgnore set\n");
- }
-#endif
- UnlockDisplay(dpy);
- xkbi->srv_major= rep.serverMajor;
- xkbi->srv_minor= rep.serverMinor;
- if (major_rtrn) *major_rtrn= rep.serverMajor;
- if (minor_rtrn) *minor_rtrn= rep.serverMinor;
- if (debugMsg)
- fprintf(stderr,"XKEYBOARD (version %d.%02d/%d.%02d) OK!\n",
- XkbMajorVersion,XkbMinorVersion,
- rep.serverMajor,rep.serverMinor);
-
- ev_base = codes->first_event;
- XESetWireToEvent(dpy,ev_base+XkbEventCode,wire_to_event);
- SyncHandle();
- return True;
-}
-
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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 <stdio.h>
+#include <ctype.h>
+
+#ifdef XKB_IN_SERVER
+#define XkbAllocClientMap SrvXkbAllocClientMap
+#define XkbAllocServerMap SrvXkbAllocServerMap
+#define XkbChangeTypesOfKey SrvXkbChangeTypesOfKey
+#define XkbCopyKeyTypes SrvXkbCopyKeyTypes
+#define XkbFreeClientMap SrvXkbFreeClientMap
+#define XkbFreeServerMap SrvXkbFreeServerMap
+#define XkbKeyTypesForCoreSymbols SrvXkbKeyTypesForCoreSymbols
+#define XkbApplyCompatMapToKey SrvXkbApplyCompatMapToKey
+#define XkbResizeKeyActions SrvXkbResizeKeyActions
+#define XkbResizeKeySyms SrvXkbResizeKeySyms
+#define XkbResizeKeyType SrvXkbResizeKeyType
+#define XkbAllocCompatMap SrvXkbAllocCompatMap
+#define XkbAllocControls SrvXkbAllocControls
+#define XkbAllocIndicatorMaps SrvXkbAllocIndicatorMaps
+#define XkbAllocKeyboard SrvXkbAllocKeyboard
+#define XkbAllocNames SrvXkbAllocNames
+#define XkbFreeCompatMap SrvXkbFreeCompatMap
+#define XkbFreeKeyboard SrvXkbFreeKeyboard
+#define XkbFreeNames SrvXkbFreeNames
+#define XkbLatchModifiers SrvXkbLatchModifiers
+#define XkbLatchGroup SrvXkbLatchGroup
+#define XkbVirtualModsToReal SrvXkbVirtualModsToReal
+#define XkbChangeKeycodeRange SrvXkbChangeKeycodeRange
+#define XkbApplyVirtualModChanges SrvXkbApplyVirtualModChanges
+#endif
+
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+static Bool _XkbIgnoreExtension = False;
+
+void
+XkbNoteMapChanges(XkbMapChangesPtr old,XkbMapNotifyEvent *new,unsigned wanted)
+{
+ int first,oldLast,newLast;
+ wanted&= new->changed;
+
+ if (wanted&XkbKeyTypesMask) {
+ if (old->changed&XkbKeyTypesMask) {
+ first = old->first_type;
+ oldLast = old->first_type+old->num_types-1;
+ newLast = new->first_type+new->num_types-1;
+
+ if (new->first_type<first)
+ first = new->first_type;
+ if (oldLast>newLast)
+ newLast= oldLast;
+ old->first_type = first;
+ old->num_types = newLast-first+1;
+ }
+ else {
+ old->first_type= new->first_type;
+ old->num_types = new->num_types;
+ }
+ }
+ if (wanted&XkbKeySymsMask) {
+ if (old->changed&XkbKeySymsMask) {
+ first = old->first_key_sym;
+ oldLast = old->first_key_sym+old->num_key_syms-1;
+ newLast = new->first_key_sym+new->num_key_syms-1;
+
+ if (new->first_key_sym<first)
+ first = new->first_key_sym;
+ if (oldLast>newLast)
+ newLast= oldLast;
+ old->first_key_sym = first;
+ old->num_key_syms = newLast-first+1;
+ }
+ else {
+ old->first_key_sym = new->first_key_sym;
+ old->num_key_syms = new->num_key_syms;
+ }
+ }
+ if (wanted&XkbKeyActionsMask) {
+ if (old->changed&XkbKeyActionsMask) {
+ first = old->first_key_act;
+ oldLast = old->first_key_act+old->num_key_acts-1;
+ newLast = new->first_key_act+new->num_key_acts-1;
+
+ if (new->first_key_act<first)
+ first = new->first_key_act;
+ if (oldLast>newLast)
+ newLast= oldLast;
+ old->first_key_act = first;
+ old->num_key_acts = newLast-first+1;
+ }
+ else {
+ old->first_key_act = new->first_key_act;
+ old->num_key_acts = new->num_key_acts;
+ }
+ }
+ if (wanted&XkbKeyBehaviorsMask) {
+ if (old->changed&XkbKeyBehaviorsMask) {
+ first = old->first_key_behavior;
+ oldLast = old->first_key_behavior+old->num_key_behaviors-1;
+ newLast = new->first_key_behavior+new->num_key_behaviors-1;
+
+ if (new->first_key_behavior<first)
+ first = new->first_key_behavior;
+ if (oldLast>newLast)
+ newLast= oldLast;
+ old->first_key_behavior = first;
+ old->num_key_behaviors = newLast-first+1;
+ }
+ else {
+ old->first_key_behavior = new->first_key_behavior;
+ old->num_key_behaviors = new->num_key_behaviors;
+ }
+ }
+ if (wanted&XkbVirtualModsMask) {
+ old->vmods|= new->vmods;
+ }
+ if (wanted&XkbExplicitComponentsMask) {
+ if (old->changed&XkbExplicitComponentsMask) {
+ first = old->first_key_explicit;
+ oldLast = old->first_key_explicit+old->num_key_explicit-1;
+ newLast = new->first_key_explicit+new->num_key_explicit-1;
+
+ if (new->first_key_explicit<first)
+ first = new->first_key_explicit;
+ if (oldLast>newLast)
+ newLast= oldLast;
+ old->first_key_explicit = first;
+ old->num_key_explicit = newLast-first+1;
+ }
+ else {
+ old->first_key_explicit = new->first_key_explicit;
+ old->num_key_explicit = new->num_key_explicit;
+ }
+ }
+ if (wanted&XkbModifierMapMask) {
+ if (old->changed&XkbModifierMapMask) {
+ first = old->first_modmap_key;
+ oldLast = old->first_modmap_key+old->num_modmap_keys-1;
+ newLast = new->first_modmap_key+new->num_modmap_keys-1;
+
+ if (new->first_modmap_key<first)
+ first = new->first_modmap_key;
+ if (oldLast>newLast)
+ newLast= oldLast;
+ old->first_modmap_key = first;
+ old->num_modmap_keys = newLast-first+1;
+ }
+ else {
+ old->first_modmap_key = new->first_modmap_key;
+ old->num_modmap_keys = new->num_modmap_keys;
+ }
+ }
+ if (wanted&XkbVirtualModMapMask) {
+ if (old->changed&XkbVirtualModMapMask) {
+ first = old->first_vmodmap_key;
+ oldLast = old->first_vmodmap_key+old->num_vmodmap_keys-1;
+ newLast = new->first_vmodmap_key+new->num_vmodmap_keys-1;
+
+ if (new->first_vmodmap_key<first)
+ first = new->first_vmodmap_key;
+ if (oldLast>newLast)
+ newLast= oldLast;
+ old->first_vmodmap_key = first;
+ old->num_vmodmap_keys = newLast-first+1;
+ }
+ else {
+ old->first_vmodmap_key = new->first_vmodmap_key;
+ old->num_vmodmap_keys = new->num_vmodmap_keys;
+ }
+ }
+ old->changed|= wanted;
+ return;
+}
+
+void
+_XkbNoteCoreMapChanges( XkbMapChangesPtr old,
+ XMappingEvent * new,
+ unsigned int wanted)
+{
+ int first,oldLast,newLast;
+
+ if ((new->request==MappingKeyboard)&&(wanted&XkbKeySymsMask)) {
+ if (old->changed&XkbKeySymsMask) {
+ first = old->first_key_sym;
+ oldLast = old->first_key_sym+old->num_key_syms-1;
+ newLast = new->first_keycode+new->count-1;
+
+ if (new->first_keycode<first)
+ first = new->first_keycode;
+ if (oldLast>newLast)
+ newLast= oldLast;
+ old->first_key_sym = first;
+ old->num_key_syms = newLast-first+1;
+ }
+ else {
+ old->changed|= XkbKeySymsMask;
+ old->first_key_sym = new->first_keycode;
+ old->num_key_syms = new->count;
+ }
+ }
+ return;
+}
+
+static Bool
+wire_to_event(Display *dpy,XEvent *re,xEvent *event)
+{
+ xkbEvent *xkbevent= (xkbEvent *)event;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ xkbi = dpy->xkb_info;
+ if (((event->u.u.type&0x7f)-xkbi->codes->first_event)!=XkbEventCode)
+ return False;
+
+ switch (xkbevent->u.any.xkbType) {
+ case XkbStateNotify:
+ {
+ xkbStateNotify *sn = (xkbStateNotify *)event;
+ if ( xkbi->selected_events&XkbStateNotifyMask ) {
+ XkbStateNotifyEvent *sev=(XkbStateNotifyEvent *)re;
+ sev->type = XkbEventCode+xkbi->codes->first_event;
+ sev->xkb_type = XkbStateNotify;
+ sev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ sev->send_event = ((event->u.u.type & 0x80) != 0);
+ sev->display = dpy;
+ sev->time = sn->time;
+ sev->device = sn->deviceID;
+ sev->keycode = sn->keycode;
+ sev->event_type = sn->eventType;
+ sev->req_major = sn->requestMajor;
+ sev->req_minor = sn->requestMinor;
+ sev->changed = sn->changed;
+ sev->group = sn->group;
+ sev->base_group = sn->baseGroup;
+ sev->latched_group = sn->latchedGroup;
+ sev->locked_group = sn->lockedGroup;
+ sev->mods = sn->mods;
+ sev->base_mods = sn->baseMods;
+ sev->latched_mods = sn->latchedMods;
+ sev->locked_mods = sn->lockedMods;
+ sev->compat_state = sn->compatState;
+ sev->grab_mods = sn->grabMods;
+ sev->compat_grab_mods = sn->compatGrabMods;
+ sev->lookup_mods = sn->lookupMods;
+ sev->compat_lookup_mods = sn->compatLookupMods;
+ sev->ptr_buttons = sn->ptrBtnState;
+ return True;
+ }
+ }
+ break;
+ case XkbMapNotify:
+ {
+ xkbMapNotify *mn = (xkbMapNotify *)event;
+ if ((xkbi->selected_events&XkbMapNotifyMask)&&
+ (xkbi->selected_map_details&mn->changed)) {
+ XkbMapNotifyEvent *mev;
+ mev =(XkbMapNotifyEvent *)re;
+ mev->type = XkbEventCode+xkbi->codes->first_event;
+ mev->xkb_type = XkbMapNotify;
+ mev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ mev->send_event = ((event->u.u.type&0x80)!=0);
+ mev->display = dpy;
+ mev->time = mn->time;
+ mev->device = mn->deviceID;
+ mev->changed = mn->changed;
+ mev->min_key_code = mn->minKeyCode;
+ mev->max_key_code = mn->maxKeyCode;
+ mev->first_type = mn->firstType;
+ mev->num_types = mn->nTypes;
+ mev->first_key_sym = mn->firstKeySym;
+ mev->num_key_syms = mn->nKeySyms;
+ mev->first_key_act = mn->firstKeyAct;
+ mev->num_key_acts = mn->nKeyActs;
+ mev->first_key_behavior = mn->firstKeyBehavior;
+ mev->num_key_behaviors = mn->nKeyBehaviors;
+ mev->vmods = mn->virtualMods;
+ mev->first_key_explicit = mn->firstKeyExplicit;
+ mev->num_key_explicit = mn->nKeyExplicit;
+ mev->first_modmap_key = mn->firstModMapKey;
+ mev->num_modmap_keys = mn->nModMapKeys;
+ mev->first_vmodmap_key = mn->firstVModMapKey;
+ mev->num_vmodmap_keys = mn->nVModMapKeys;
+ XkbNoteMapChanges(&xkbi->changes,mev,XKB_XLIB_MAP_MASK);
+ if (xkbi->changes.changed)
+ xkbi->flags|= XkbMapPending;
+ return True;
+ }
+ else if (mn->nKeySyms>0) {
+ register XMappingEvent *ev = (XMappingEvent *)re;
+ ev->type = MappingNotify;
+ ev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ ev->send_event = ((event->u.u.type&0x80)!=0);
+ ev->display = dpy;
+ ev->window = 0;
+ ev->first_keycode = mn->firstKeySym;
+ ev->request = MappingKeyboard;
+ ev->count = mn->nKeySyms;
+ _XkbNoteCoreMapChanges(&xkbi->changes,ev,XKB_XLIB_MAP_MASK);
+ if (xkbi->changes.changed)
+ xkbi->flags|= XkbMapPending;
+ return True;
+ }
+ }
+ break;
+ case XkbControlsNotify:
+ {
+ if (xkbi->selected_events&XkbControlsNotifyMask) {
+ xkbControlsNotify *cn =(xkbControlsNotify *)event;
+ XkbControlsNotifyEvent *cev;
+ cev =(XkbControlsNotifyEvent *)re;
+ cev->type = XkbEventCode+xkbi->codes->first_event;
+ cev->xkb_type = XkbControlsNotify;
+ cev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ cev->send_event = ((event->u.u.type&0x80)!=0);
+ cev->display = dpy;
+ cev->time = cn->time;
+ cev->device = cn->deviceID;
+ cev->changed_ctrls = cn->changedControls;
+ cev->enabled_ctrls = cn->enabledControls;
+ cev->enabled_ctrl_changes = cn->enabledControlChanges;
+ cev->keycode = cn->keycode;
+ cev->num_groups = cn->numGroups;
+ cev->event_type = cn->eventType;
+ cev->req_major = cn->requestMajor;
+ cev->req_minor = cn->requestMinor;
+ return True;
+ }
+ }
+ break;
+ case XkbIndicatorMapNotify:
+ {
+ if (xkbi->selected_events&XkbIndicatorMapNotifyMask) {
+ xkbIndicatorNotify *in =(xkbIndicatorNotify *)event;
+ XkbIndicatorNotifyEvent *iev;
+ iev =(XkbIndicatorNotifyEvent *)re;
+ iev->type = XkbEventCode+xkbi->codes->first_event;
+ iev->xkb_type = XkbIndicatorMapNotify;
+ iev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ iev->send_event = ((event->u.u.type&0x80)!=0);
+ iev->display = dpy;
+ iev->time = in->time;
+ iev->device = in->deviceID;
+ iev->changed = in->changed;
+ iev->state= in->state;
+ return True;
+ }
+ }
+ break;
+ case XkbIndicatorStateNotify:
+ {
+ if (xkbi->selected_events&XkbIndicatorStateNotifyMask) {
+ xkbIndicatorNotify *in =(xkbIndicatorNotify *)event;
+ XkbIndicatorNotifyEvent *iev;
+ iev =(XkbIndicatorNotifyEvent *)re;
+ iev->type = XkbEventCode+xkbi->codes->first_event;
+ iev->xkb_type = XkbIndicatorStateNotify;
+ iev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ iev->send_event = ((event->u.u.type&0x80)!=0);
+ iev->display = dpy;
+ iev->time = in->time;
+ iev->device = in->deviceID;
+ iev->changed = in->changed;
+ iev->state= in->state;
+ return True;
+ }
+ }
+ break;
+ case XkbBellNotify:
+ {
+ if (xkbi->selected_events&XkbBellNotifyMask) {
+ xkbBellNotify *bn =(xkbBellNotify *)event;
+ XkbBellNotifyEvent *bev;
+ bev =(XkbBellNotifyEvent *)re;
+ bev->type = XkbEventCode+xkbi->codes->first_event;
+ bev->xkb_type = XkbBellNotify;
+ bev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ bev->send_event = ((event->u.u.type&0x80)!=0);
+ bev->display = dpy;
+ bev->time = bn->time;
+ bev->device = bn->deviceID;
+ bev->percent = bn->percent;
+ bev->pitch = bn->pitch;
+ bev->duration = bn->duration;
+ bev->bell_class = bn->bellClass;
+ bev->bell_id = bn->bellID;
+ bev->name = bn->name;
+ bev->window = bn->window;
+ bev->event_only = bn->eventOnly;
+ return True;
+ }
+ }
+ break;
+ case XkbAccessXNotify:
+ {
+ if (xkbi->selected_events&XkbAccessXNotifyMask) {
+ xkbAccessXNotify *axn =(xkbAccessXNotify *)event;
+ XkbAccessXNotifyEvent *axev;
+ axev =(XkbAccessXNotifyEvent *)re;
+ axev->type = XkbEventCode+xkbi->codes->first_event;
+ axev->xkb_type = XkbAccessXNotify;
+ axev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ axev->send_event = ((event->u.u.type&0x80)!=0);
+ axev->display = dpy;
+ axev->time = axn->time;
+ axev->device = axn->deviceID;
+ axev->detail = axn->detail;
+ axev->keycode = axn->keycode;
+ axev->sk_delay = axn->slowKeysDelay;
+ axev->debounce_delay = axn->debounceDelay;
+ return True;
+ }
+ }
+ break;
+ case XkbNamesNotify:
+ {
+ if (xkbi->selected_events&XkbNamesNotifyMask) {
+ xkbNamesNotify *nn =(xkbNamesNotify *)event;
+ XkbNamesNotifyEvent *nev;
+ nev =(XkbNamesNotifyEvent *)re;
+ nev->type = XkbEventCode+xkbi->codes->first_event;
+ nev->xkb_type = XkbNamesNotify;
+ nev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ nev->send_event = ((event->u.u.type&0x80)!=0);
+ nev->display = dpy;
+ nev->time = nn->time;
+ nev->device = nn->deviceID;
+ nev->changed = nn->changed;
+ nev->first_type = nn->firstType;
+ nev->num_types = nn->nTypes;
+ nev->first_lvl = nn->firstLevelName;
+ nev->num_lvls = nn->nLevelNames;
+ nev->num_aliases = nn->nAliases;
+ nev->num_radio_groups = nn->nRadioGroups;
+ nev->changed_vmods = nn->changedVirtualMods;
+ nev->changed_groups = nn->changedGroupNames;
+ nev->changed_indicators = nn->changedIndicators;
+ nev->first_key = nn->firstKey;
+ nev->num_keys = nn->nKeys;
+ return True;
+ }
+ }
+ break;
+ case XkbCompatMapNotify:
+ {
+ if (xkbi->selected_events&XkbCompatMapNotifyMask) {
+ xkbCompatMapNotify *cmn =(xkbCompatMapNotify *)event;
+ XkbCompatMapNotifyEvent *cmev;
+ cmev =(XkbCompatMapNotifyEvent *)re;
+ cmev->type = XkbEventCode+xkbi->codes->first_event;
+ cmev->xkb_type = XkbCompatMapNotify;
+ cmev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ cmev->send_event = ((event->u.u.type&0x80)!=0);
+ cmev->display = dpy;
+ cmev->time = cmn->time;
+ cmev->device = cmn->deviceID;
+ cmev->changed_groups = cmn->changedGroups;
+ cmev->first_si = cmn->firstSI;
+ cmev->num_si = cmn->nSI;
+ cmev->num_total_si = cmn->nTotalSI;
+ return True;
+ }
+ }
+ break;
+ case XkbActionMessage:
+ {
+ if (xkbi->selected_events&XkbActionMessageMask) {
+ xkbActionMessage *am= (xkbActionMessage *)event;
+ XkbActionMessageEvent *amev;
+ amev= (XkbActionMessageEvent *)re;
+ amev->type = XkbEventCode+xkbi->codes->first_event;
+ amev->xkb_type = XkbActionMessage;
+ amev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ amev->send_event = ((event->u.u.type&0x80)!=0);
+ amev->display = dpy;
+ amev->time = am->time;
+ amev->device = am->deviceID;
+ amev->keycode = am->keycode;
+ amev->press = am->press;
+ amev->key_event_follows = am->keyEventFollows;
+ amev->group = am->group;
+ amev->mods = am->mods;
+ memcpy(amev->message,am->message,XkbActionMessageLength);
+ amev->message[XkbActionMessageLength]= '\0';
+ return True;
+ }
+ }
+ break;
+ case XkbExtensionDeviceNotify:
+ {
+ if (xkbi->selected_events&XkbExtensionDeviceNotifyMask) {
+ xkbExtensionDeviceNotify *ed=
+ (xkbExtensionDeviceNotify *)event;
+ XkbExtensionDeviceNotifyEvent *edev;
+ edev= (XkbExtensionDeviceNotifyEvent *)re;
+ edev->type= XkbEventCode+xkbi->codes->first_event;
+ edev->xkb_type= XkbExtensionDeviceNotify;
+ edev->serial= _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ edev->send_event= ((event->u.u.type&0x80)!=0);
+ edev->display= dpy;
+ edev->time= ed->time;
+ edev->device= ed->deviceID;
+ edev->led_class= ed->ledClass;
+ edev->led_id= ed->ledID;
+ edev->reason= ed->reason;
+ edev->supported= ed->supported;
+ edev->leds_defined= ed->ledsDefined;
+ edev->led_state= ed->ledState;
+ edev->first_btn= ed->firstBtn;
+ edev->num_btns= ed->nBtns;
+ edev->unsupported= ed->unsupported;
+ return True;
+ }
+ }
+ break;
+ case XkbNewKeyboardNotify:
+ {
+ xkbNewKeyboardNotify *nkn = (xkbNewKeyboardNotify *)event;
+ if ((xkbi->selected_events&XkbNewKeyboardNotifyMask)&&
+ (xkbi->selected_nkn_details&nkn->changed)) {
+ XkbNewKeyboardNotifyEvent *nkev;
+ nkev =(XkbNewKeyboardNotifyEvent *)re;
+ nkev->type = XkbEventCode+xkbi->codes->first_event;
+ nkev->xkb_type = XkbNewKeyboardNotify;
+ nkev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ nkev->send_event = ((event->u.u.type&0x80)!=0);
+ nkev->display = dpy;
+ nkev->time = nkn->time;
+ nkev->device = nkn->deviceID;
+ nkev->old_device = nkn->oldDeviceID;
+ nkev->min_key_code = nkn->minKeyCode;
+ nkev->max_key_code = nkn->maxKeyCode;
+ nkev->old_min_key_code = nkn->oldMinKeyCode;
+ nkev->old_max_key_code = nkn->oldMaxKeyCode;
+ nkev->req_major = nkn->requestMajor;
+ nkev->req_minor = nkn->requestMinor;
+ nkev->changed = nkn->changed;
+ if ((xkbi->desc)&&(nkev->send_event==0)&&
+ ((xkbi->desc->device_spec==nkev->old_device)||
+ (nkev->device!=nkev->old_device))) {
+ xkbi->flags= XkbMapPending|XkbXlibNewKeyboard;
+ }
+ return True;
+ }
+ else if(nkn->changed&(XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask)){
+ register XMappingEvent *ev = (XMappingEvent *)re;
+ ev->type = MappingNotify;
+ ev->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *)event);
+ ev->send_event = ((event->u.u.type&0x80)!=0);
+ ev->display = dpy;
+ ev->window = 0;
+ ev->first_keycode = dpy->min_keycode;
+ ev->request = MappingKeyboard;
+ ev->count = (dpy->max_keycode-dpy->min_keycode)+1;
+ if ((xkbi->desc)&&(ev->send_event==0)&&
+ ((xkbi->desc->device_spec==nkn->oldDeviceID)||
+ (nkn->deviceID!=nkn->oldDeviceID))) {
+ xkbi->flags|= XkbMapPending|XkbXlibNewKeyboard;
+ }
+ return True;
+ }
+ }
+ break;
+ default:
+#ifdef DEBUG
+ fprintf(stderr,"Got unknown XKEYBOARD event (%d, base=%d)\n",
+ re->type,
+ xkbi->codes->first_event);
+#endif
+ break;
+ }
+ return False;
+}
+
+Bool
+XkbIgnoreExtension(Bool ignore)
+{
+ if (getenv("XKB_FORCE")!=NULL) {
+#ifdef DEBUG
+ fprintf(stderr,"Forcing use of XKEYBOARD (overriding an IgnoreExtensions)\n");
+#endif
+ return False;
+ }
+#ifdef DEBUG
+ else if (getenv("XKB_DEBUG")!=NULL) {
+ fprintf(stderr,"Explicitly %signoring XKEYBOARD\n",ignore?"":"not ");
+ }
+#endif
+ _XkbIgnoreExtension = ignore;
+ return True;
+}
+
+static void
+_XkbFreeInfo(Display *dpy)
+{
+ XkbInfoPtr xkbi = dpy->xkb_info;
+ if (xkbi) {
+ if (xkbi->desc)
+ XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True);
+ Xfree(xkbi);
+ }
+}
+
+Bool
+XkbUseExtension(Display *dpy,int *major_rtrn,int *minor_rtrn)
+{
+ xkbUseExtensionReply rep;
+ register xkbUseExtensionReq *req;
+ XExtCodes *codes;
+ int ev_base,forceIgnore;
+ XkbInfoPtr xkbi;
+ char * str;
+ static int debugMsg;
+ static int been_here= 0;
+
+ if ( dpy->xkb_info && !(dpy->flags & XlibDisplayNoXkb)) {
+ if (major_rtrn) *major_rtrn= dpy->xkb_info->srv_major;
+ if (minor_rtrn) *minor_rtrn= dpy->xkb_info->srv_minor;
+ return True;
+ }
+ if (!been_here) {
+ debugMsg= (getenv("XKB_DEBUG")!=NULL);
+ been_here= 1;
+ }
+
+ if (major_rtrn) *major_rtrn= 0;
+ if (minor_rtrn) *minor_rtrn= 0;
+
+ if (!dpy->xkb_info) {
+ xkbi = _XkbTypedCalloc(1, XkbInfoRec);
+ if ( !xkbi )
+ return False;
+ dpy->xkb_info = xkbi;
+ dpy->free_funcs->xkb = _XkbFreeInfo;
+
+ xkbi->xlib_ctrls|= (XkbLC_ControlFallback|XkbLC_ConsumeLookupMods);
+ if ((str=getenv("_XKB_OPTIONS_ENABLE"))!=NULL) {
+ if ((str=getenv("_XKB_LATIN1_LOOKUP"))!=NULL) {
+ if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
+ xkbi->xlib_ctrls&= ~XkbLC_ForceLatin1Lookup;
+ else xkbi->xlib_ctrls|= XkbLC_ForceLatin1Lookup;
+ }
+ if ((str=getenv("_XKB_CONSUME_LOOKUP_MODS"))!=NULL) {
+ if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
+ xkbi->xlib_ctrls&= ~XkbLC_ConsumeLookupMods;
+ else xkbi->xlib_ctrls|= XkbLC_ConsumeLookupMods;
+ }
+ if ((str=getenv("_XKB_CONSUME_SHIFT_AND_LOCK"))!=NULL) {
+ if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
+ xkbi->xlib_ctrls&= ~XkbLC_AlwaysConsumeShiftAndLock;
+ else xkbi->xlib_ctrls|= XkbLC_AlwaysConsumeShiftAndLock;
+ }
+ if ((str=getenv("_XKB_IGNORE_NEW_KEYBOARDS"))!=NULL) {
+ if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
+ xkbi->xlib_ctrls&= ~XkbLC_IgnoreNewKeyboards;
+ else xkbi->xlib_ctrls|= XkbLC_IgnoreNewKeyboards;
+ }
+ if ((str=getenv("_XKB_CONTROL_FALLBACK"))!=NULL) {
+ if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
+ xkbi->xlib_ctrls&= ~XkbLC_ControlFallback;
+ else xkbi->xlib_ctrls|= XkbLC_ControlFallback;
+ }
+ if ((str=getenv("_XKB_COMP_LED"))!=NULL) {
+ if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
+ xkbi->xlib_ctrls&= ~XkbLC_ComposeLED;
+ else {
+ xkbi->xlib_ctrls|= XkbLC_ComposeLED;
+ if (strlen(str)>0)
+ xkbi->composeLED= XInternAtom(dpy,str,False);
+ }
+ }
+ if ((str=getenv("_XKB_COMP_FAIL_BEEP"))!=NULL) {
+ if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0))
+ xkbi->xlib_ctrls&= ~XkbLC_BeepOnComposeFail;
+ else xkbi->xlib_ctrls|= XkbLC_BeepOnComposeFail;
+ }
+ }
+ if ((xkbi->composeLED==None)&&((xkbi->xlib_ctrls&XkbLC_ComposeLED)!=0))
+ xkbi->composeLED= XInternAtom(dpy,"Compose",False);
+#ifdef DEBUG
+ if (debugMsg) {
+ register unsigned c= xkbi->xlib_ctrls;
+ fprintf(stderr,"XKEYBOARD compose: beep on failure is %s, LED is %s\n",
+ ((c&XkbLC_BeepOnComposeFail)?"on":"off"),
+ ((c&XkbLC_ComposeLED)?"on":"off"));
+ fprintf(stderr,"XKEYBOARD XLookupString: %slatin-1, %s lookup modifiers\n",
+ ((c&XkbLC_ForceLatin1Lookup)?"allow non-":"force "),
+ ((c&XkbLC_ConsumeLookupMods)?"consume":"re-use"));
+ fprintf(stderr,
+ "XKEYBOARD XLookupString: %sconsume shift and lock, %scontrol fallback\n",
+ ((c&XkbLC_AlwaysConsumeShiftAndLock)?"always ":"don't "),
+ ((c&XkbLC_ControlFallback)?"":"no "));
+
+ }
+#endif
+ } else
+ xkbi = dpy->xkb_info;
+
+ forceIgnore= (dpy->flags&XlibDisplayNoXkb)||dpy->keysyms;
+ forceIgnore= forceIgnore&&(major_rtrn==NULL)&&(minor_rtrn==NULL);
+ if ( forceIgnore || _XkbIgnoreExtension || getenv("XKB_DISABLE")) {
+ LockDisplay(dpy);
+ dpy->flags |= XlibDisplayNoXkb;
+ UnlockDisplay(dpy);
+ if (debugMsg)
+ fprintf(stderr,"XKEYBOARD extension disabled or missing\n");
+ return False;
+ }
+
+ if ( (codes=XInitExtension(dpy,XkbName))==NULL ) {
+ LockDisplay(dpy);
+ dpy->flags |= XlibDisplayNoXkb;
+ UnlockDisplay(dpy);
+ if (debugMsg)
+ fprintf(stderr,"XKEYBOARD extension not present\n");
+ return False;
+ }
+ xkbi->codes = codes;
+ LockDisplay(dpy);
+
+ GetReq(kbUseExtension, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbUseExtension;
+ req->wantedMajor = XkbMajorVersion;
+ req->wantedMinor = XkbMinorVersion;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.supported ) {
+ Bool fail;
+ fail= True;
+ if (debugMsg)
+ fprintf(stderr,
+ "XKEYBOARD version mismatch (want %d.%02d, got %d.%02d)\n",
+ XkbMajorVersion,XkbMinorVersion,
+ rep.serverMajor, rep.serverMinor);
+
+ /* pre-release 0.65 is very close to 1.00 */
+ if ((rep.serverMajor==0)&&(rep.serverMinor==65)) {
+ if (debugMsg)
+ fprintf(stderr,"Trying to fall back to version 0.65...");
+ GetReq(kbUseExtension, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbUseExtension;
+ req->wantedMajor = 0;
+ req->wantedMinor = 65;
+ if ( _XReply(dpy, (xReply *)&rep, 0, xFalse) && rep.supported ) {
+ if (debugMsg)
+ fprintf(stderr,"succeeded\n");
+ fail= False;
+ }
+ else if (debugMsg) fprintf(stderr,"failed\n");
+ }
+ if (fail) {
+ dpy->flags |= XlibDisplayNoXkb;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if (major_rtrn) *major_rtrn= rep.serverMajor;
+ if (minor_rtrn) *minor_rtrn= rep.serverMinor;
+ return False;
+ }
+ }
+#ifdef DEBUG
+ else if ( forceIgnore ) {
+ fprintf(stderr,"Internal Error! XkbUseExtension succeeded with forceIgnore set\n");
+ }
+#endif
+ UnlockDisplay(dpy);
+ xkbi->srv_major= rep.serverMajor;
+ xkbi->srv_minor= rep.serverMinor;
+ if (major_rtrn) *major_rtrn= rep.serverMajor;
+ if (minor_rtrn) *minor_rtrn= rep.serverMinor;
+ if (debugMsg)
+ fprintf(stderr,"XKEYBOARD (version %d.%02d/%d.%02d) OK!\n",
+ XkbMajorVersion,XkbMinorVersion,
+ rep.serverMajor,rep.serverMinor);
+
+ ev_base = codes->first_event;
+ XESetWireToEvent(dpy,ev_base+XkbEventCode,wire_to_event);
+ SyncHandle();
+ return True;
+}
+
diff --git a/libX11/src/xkb/XKBleds.c b/libX11/src/xkb/XKBleds.c
index 24a42c337..47811a5c7 100644
--- a/libX11/src/xkb/XKBleds.c
+++ b/libX11/src/xkb/XKBleds.c
@@ -1,335 +1,333 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-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 Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS 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_REPLIES
-#define NEED_EVENTS
-#define NEED_MAP_READERS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include <X11/extensions/XKBproto.h>
-#include "XKBlibint.h"
-
-Status
-XkbGetIndicatorState(Display *dpy,unsigned deviceSpec,unsigned *pStateRtrn)
-{
- register xkbGetIndicatorStateReq *req;
- xkbGetIndicatorStateReply rep;
- XkbInfoPtr xkbi;
- Bool ok;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbGetIndicatorState, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetIndicatorState;
- req->deviceSpec = deviceSpec;
- ok=_XReply(dpy, (xReply *)&rep, 0, xFalse);
- if (ok && (pStateRtrn!=NULL))
- *pStateRtrn= rep.state;
- UnlockDisplay(dpy);
- SyncHandle();
- return (ok?Success:BadImplementation);
-}
-
-Status
-_XkbReadGetIndicatorMapReply( Display * dpy,
- xkbGetIndicatorMapReply * rep,
- XkbDescPtr xkb,
- int * nread_rtrn)
-{
-XkbIndicatorPtr leds;
-XkbReadBufferRec buf;
-
- if ((!xkb->indicators)&&(XkbAllocIndicatorMaps(xkb)!=Success))
- return BadAlloc;
- leds= xkb->indicators;
-
- leds->phys_indicators = rep->realIndicators;
- if (rep->length>0) {
- register int left;
- if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
- return BadAlloc;
- if (nread_rtrn)
- *nread_rtrn= (int)rep->length*4;
- if (rep->which) {
- register int i,bit;
- left= (int)rep->which;
- for (i=0,bit=1;(i<XkbNumIndicators)&&(left);i++,bit<<=1) {
- if (left&bit) {
- xkbIndicatorMapWireDesc *wire;
- wire= (xkbIndicatorMapWireDesc *)
- _XkbGetReadBufferPtr(&buf,
- SIZEOF(xkbIndicatorMapWireDesc));
- if (wire==NULL) {
- _XkbFreeReadBuffer(&buf);
- return BadAlloc;
- }
- leds->maps[i].flags= wire->flags;
- leds->maps[i].which_groups= wire->whichGroups;
- leds->maps[i].groups= wire->groups;
- leds->maps[i].which_mods= wire->whichMods;
- leds->maps[i].mods.mask= wire->mods;
- leds->maps[i].mods.real_mods= wire->realMods;
- leds->maps[i].mods.vmods= wire->virtualMods;
- leds->maps[i].ctrls= wire->ctrls;
- left&= ~bit;
- }
- }
- }
- left= _XkbFreeReadBuffer(&buf);
- }
- return Success;
-}
-
-Bool
-XkbGetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
-{
- register xkbGetIndicatorMapReq * req;
- xkbGetIndicatorMapReply rep;
- XkbInfoPtr xkbi;
- Status status;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return BadAccess;
- if ((!which)||(!xkb))
- return BadValue;
-
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- if (!xkb->indicators) {
- xkb->indicators = _XkbTypedCalloc(1,XkbIndicatorRec);
- if (!xkb->indicators) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadAlloc;
- }
- }
- GetReq(kbGetIndicatorMap, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetIndicatorMap;
- req->deviceSpec = xkb->device_spec;
- req->which = (CARD32)which;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return BadValue;
- }
- status= _XkbReadGetIndicatorMapReply(dpy,&rep,xkb,NULL);
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-Bool
-XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
-{
- register xkbSetIndicatorMapReq *req;
- register int i,bit;
- int nMaps;
- xkbIndicatorMapWireDesc *wire;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- if ((!xkb)||(!which)||(!xkb->indicators))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetIndicatorMap, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSetIndicatorMap;
- req->deviceSpec = xkb->device_spec;
- req->which = (CARD32)which;
- for (i=nMaps=0,bit=1;i<32;i++,bit<<=1) {
- if (which&bit)
- nMaps++;
- }
- req->length+= (nMaps*sizeof(XkbIndicatorMapRec))/4;
- BufAlloc(xkbIndicatorMapWireDesc *,wire,
- (nMaps*SIZEOF(xkbIndicatorMapWireDesc)));
- for (i=0,bit=1;i<32;i++,bit<<=1) {
- if (which&bit) {
- wire->flags= xkb->indicators->maps[i].flags;
- wire->whichGroups= xkb->indicators->maps[i].which_groups;
- wire->groups= xkb->indicators->maps[i].groups;
- wire->whichMods= xkb->indicators->maps[i].which_mods;
- wire->mods= xkb->indicators->maps[i].mods.real_mods;
- wire->virtualMods= xkb->indicators->maps[i].mods.vmods;
- wire->ctrls= xkb->indicators->maps[i].ctrls;
- wire++;
- }
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbGetNamedDeviceIndicator( Display * dpy,
- unsigned device,
- unsigned class,
- unsigned id,
- Atom name,
- int * pNdxRtrn,
- Bool * pStateRtrn,
- XkbIndicatorMapPtr pMapRtrn,
- Bool * pRealRtrn)
-{
- register xkbGetNamedIndicatorReq *req;
- xkbGetNamedIndicatorReply rep;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbGetNamedIndicator, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbGetNamedIndicator;
- req->deviceSpec = device;
- req->ledClass = class;
- req->ledID = id;
- req->indicator = (CARD32)name;
- if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- if ((!rep.found)||(!rep.supported))
- return False;
- if (pNdxRtrn!=NULL)
- *pNdxRtrn= rep.ndx;
- if (pStateRtrn!=NULL)
- *pStateRtrn= rep.on;
- if (pMapRtrn!=NULL) {
- pMapRtrn->flags= rep.flags;
- pMapRtrn->which_groups= rep.whichGroups;
- pMapRtrn->groups= rep.groups;
- pMapRtrn->which_mods= rep.whichMods;
- pMapRtrn->mods.mask= rep.mods;
- pMapRtrn->mods.real_mods= rep.realMods;
- pMapRtrn->mods.vmods= rep.virtualMods;
- pMapRtrn->ctrls= rep.ctrls;
- }
- if (pRealRtrn!=NULL)
- *pRealRtrn= rep.realIndicator;
- return True;
-}
-
-Bool
-XkbGetNamedIndicator( Display * dpy,
- Atom name,
- int * pNdxRtrn,
- Bool * pStateRtrn,
- XkbIndicatorMapPtr pMapRtrn,
- Bool * pRealRtrn)
-{
- return XkbGetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
- XkbDfltXIClass,XkbDfltXIId,
- name,pNdxRtrn,pStateRtrn,
- pMapRtrn,pRealRtrn);
-}
-
-Bool
-XkbSetNamedDeviceIndicator( Display * dpy,
- unsigned device,
- unsigned class,
- unsigned id,
- Atom name,
- Bool changeState,
- Bool state,
- Bool createNewMap,
- XkbIndicatorMapPtr pMap)
-{
- register xkbSetNamedIndicatorReq *req;
- XkbInfoPtr xkbi;
-
- if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
- (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
- return False;
- LockDisplay(dpy);
- xkbi = dpy->xkb_info;
- GetReq(kbSetNamedIndicator, req);
- req->reqType = xkbi->codes->major_opcode;
- req->xkbReqType = X_kbSetNamedIndicator;
- req->deviceSpec = device;
- req->ledClass = class;
- req->ledID = id;
- req->indicator= (CARD32)name;
- req->setState= changeState;
- if (req->setState)
- req->on= state;
- else req->on= False;
- if (pMap!=NULL) {
- req->setMap= True;
- req->createMap= createNewMap;
- req->flags= pMap->flags;
- req->whichGroups= pMap->which_groups;
- req->groups= pMap->groups;
- req->whichMods= pMap->which_mods;
- req->realMods= pMap->mods.real_mods;
- req->virtualMods= pMap->mods.vmods;
- req->ctrls= pMap->ctrls;
- }
- else {
- req->setMap= False;
- req->createMap= False;
- req->flags= 0;
- req->whichGroups= 0;
- req->groups= 0;
- req->whichMods= 0;
- req->realMods= 0;
- req->virtualMods= 0;
- req->ctrls= 0;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XkbSetNamedIndicator( Display * dpy,
- Atom name,
- Bool changeState,
- Bool state,
- Bool createNewMap,
- XkbIndicatorMapPtr pMap)
-{
- return XkbSetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
- XkbDfltXIClass,XkbDfltXIId,
- name,changeState,state,
- createNewMap,pMap);
-}
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+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 Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS 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_MAP_READERS
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include <X11/extensions/XKBproto.h>
+#include "XKBlibint.h"
+
+Status
+XkbGetIndicatorState(Display *dpy,unsigned deviceSpec,unsigned *pStateRtrn)
+{
+ register xkbGetIndicatorStateReq *req;
+ xkbGetIndicatorStateReply rep;
+ XkbInfoPtr xkbi;
+ Bool ok;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbGetIndicatorState, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetIndicatorState;
+ req->deviceSpec = deviceSpec;
+ ok=_XReply(dpy, (xReply *)&rep, 0, xFalse);
+ if (ok && (pStateRtrn!=NULL))
+ *pStateRtrn= rep.state;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (ok?Success:BadImplementation);
+}
+
+Status
+_XkbReadGetIndicatorMapReply( Display * dpy,
+ xkbGetIndicatorMapReply * rep,
+ XkbDescPtr xkb,
+ int * nread_rtrn)
+{
+XkbIndicatorPtr leds;
+XkbReadBufferRec buf;
+
+ if ((!xkb->indicators)&&(XkbAllocIndicatorMaps(xkb)!=Success))
+ return BadAlloc;
+ leds= xkb->indicators;
+
+ leds->phys_indicators = rep->realIndicators;
+ if (rep->length>0) {
+ register int left;
+ if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
+ return BadAlloc;
+ if (nread_rtrn)
+ *nread_rtrn= (int)rep->length*4;
+ if (rep->which) {
+ register int i,bit;
+ left= (int)rep->which;
+ for (i=0,bit=1;(i<XkbNumIndicators)&&(left);i++,bit<<=1) {
+ if (left&bit) {
+ xkbIndicatorMapWireDesc *wire;
+ wire= (xkbIndicatorMapWireDesc *)
+ _XkbGetReadBufferPtr(&buf,
+ SIZEOF(xkbIndicatorMapWireDesc));
+ if (wire==NULL) {
+ _XkbFreeReadBuffer(&buf);
+ return BadAlloc;
+ }
+ leds->maps[i].flags= wire->flags;
+ leds->maps[i].which_groups= wire->whichGroups;
+ leds->maps[i].groups= wire->groups;
+ leds->maps[i].which_mods= wire->whichMods;
+ leds->maps[i].mods.mask= wire->mods;
+ leds->maps[i].mods.real_mods= wire->realMods;
+ leds->maps[i].mods.vmods= wire->virtualMods;
+ leds->maps[i].ctrls= wire->ctrls;
+ left&= ~bit;
+ }
+ }
+ }
+ left= _XkbFreeReadBuffer(&buf);
+ }
+ return Success;
+}
+
+Bool
+XkbGetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
+{
+ register xkbGetIndicatorMapReq * req;
+ xkbGetIndicatorMapReply rep;
+ XkbInfoPtr xkbi;
+ Status status;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return BadAccess;
+ if ((!which)||(!xkb))
+ return BadValue;
+
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ if (!xkb->indicators) {
+ xkb->indicators = _XkbTypedCalloc(1,XkbIndicatorRec);
+ if (!xkb->indicators) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadAlloc;
+ }
+ }
+ GetReq(kbGetIndicatorMap, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetIndicatorMap;
+ req->deviceSpec = xkb->device_spec;
+ req->which = (CARD32)which;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return BadValue;
+ }
+ status= _XkbReadGetIndicatorMapReply(dpy,&rep,xkb,NULL);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return status;
+}
+
+Bool
+XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
+{
+ register xkbSetIndicatorMapReq *req;
+ register int i,bit;
+ int nMaps;
+ xkbIndicatorMapWireDesc *wire;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ if ((!xkb)||(!which)||(!xkb->indicators))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetIndicatorMap, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSetIndicatorMap;
+ req->deviceSpec = xkb->device_spec;
+ req->which = (CARD32)which;
+ for (i=nMaps=0,bit=1;i<32;i++,bit<<=1) {
+ if (which&bit)
+ nMaps++;
+ }
+ req->length+= (nMaps*sizeof(XkbIndicatorMapRec))/4;
+ BufAlloc(xkbIndicatorMapWireDesc *,wire,
+ (nMaps*SIZEOF(xkbIndicatorMapWireDesc)));
+ for (i=0,bit=1;i<32;i++,bit<<=1) {
+ if (which&bit) {
+ wire->flags= xkb->indicators->maps[i].flags;
+ wire->whichGroups= xkb->indicators->maps[i].which_groups;
+ wire->groups= xkb->indicators->maps[i].groups;
+ wire->whichMods= xkb->indicators->maps[i].which_mods;
+ wire->mods= xkb->indicators->maps[i].mods.real_mods;
+ wire->virtualMods= xkb->indicators->maps[i].mods.vmods;
+ wire->ctrls= xkb->indicators->maps[i].ctrls;
+ wire++;
+ }
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbGetNamedDeviceIndicator( Display * dpy,
+ unsigned device,
+ unsigned class,
+ unsigned id,
+ Atom name,
+ int * pNdxRtrn,
+ Bool * pStateRtrn,
+ XkbIndicatorMapPtr pMapRtrn,
+ Bool * pRealRtrn)
+{
+ register xkbGetNamedIndicatorReq *req;
+ xkbGetNamedIndicatorReply rep;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbGetNamedIndicator, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbGetNamedIndicator;
+ req->deviceSpec = device;
+ req->ledClass = class;
+ req->ledID = id;
+ req->indicator = (CARD32)name;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if ((!rep.found)||(!rep.supported))
+ return False;
+ if (pNdxRtrn!=NULL)
+ *pNdxRtrn= rep.ndx;
+ if (pStateRtrn!=NULL)
+ *pStateRtrn= rep.on;
+ if (pMapRtrn!=NULL) {
+ pMapRtrn->flags= rep.flags;
+ pMapRtrn->which_groups= rep.whichGroups;
+ pMapRtrn->groups= rep.groups;
+ pMapRtrn->which_mods= rep.whichMods;
+ pMapRtrn->mods.mask= rep.mods;
+ pMapRtrn->mods.real_mods= rep.realMods;
+ pMapRtrn->mods.vmods= rep.virtualMods;
+ pMapRtrn->ctrls= rep.ctrls;
+ }
+ if (pRealRtrn!=NULL)
+ *pRealRtrn= rep.realIndicator;
+ return True;
+}
+
+Bool
+XkbGetNamedIndicator( Display * dpy,
+ Atom name,
+ int * pNdxRtrn,
+ Bool * pStateRtrn,
+ XkbIndicatorMapPtr pMapRtrn,
+ Bool * pRealRtrn)
+{
+ return XkbGetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
+ XkbDfltXIClass,XkbDfltXIId,
+ name,pNdxRtrn,pStateRtrn,
+ pMapRtrn,pRealRtrn);
+}
+
+Bool
+XkbSetNamedDeviceIndicator( Display * dpy,
+ unsigned device,
+ unsigned class,
+ unsigned id,
+ Atom name,
+ Bool changeState,
+ Bool state,
+ Bool createNewMap,
+ XkbIndicatorMapPtr pMap)
+{
+ register xkbSetNamedIndicatorReq *req;
+ XkbInfoPtr xkbi;
+
+ if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
+ (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
+ return False;
+ LockDisplay(dpy);
+ xkbi = dpy->xkb_info;
+ GetReq(kbSetNamedIndicator, req);
+ req->reqType = xkbi->codes->major_opcode;
+ req->xkbReqType = X_kbSetNamedIndicator;
+ req->deviceSpec = device;
+ req->ledClass = class;
+ req->ledID = id;
+ req->indicator= (CARD32)name;
+ req->setState= changeState;
+ if (req->setState)
+ req->on= state;
+ else req->on= False;
+ if (pMap!=NULL) {
+ req->setMap= True;
+ req->createMap= createNewMap;
+ req->flags= pMap->flags;
+ req->whichGroups= pMap->which_groups;
+ req->groups= pMap->groups;
+ req->whichMods= pMap->which_mods;
+ req->realMods= pMap->mods.real_mods;
+ req->virtualMods= pMap->mods.vmods;
+ req->ctrls= pMap->ctrls;
+ }
+ else {
+ req->setMap= False;
+ req->createMap= False;
+ req->flags= 0;
+ req->whichGroups= 0;
+ req->groups= 0;
+ req->whichMods= 0;
+ req->realMods= 0;
+ req->virtualMods= 0;
+ req->ctrls= 0;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XkbSetNamedIndicator( Display * dpy,
+ Atom name,
+ Bool changeState,
+ Bool state,
+ Bool createNewMap,
+ XkbIndicatorMapPtr pMap)
+{
+ return XkbSetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
+ XkbDfltXIClass,XkbDfltXIId,
+ name,changeState,state,
+ createNewMap,pMap);
+}
diff --git a/libX11/src/xlibi18n/ICWrap.c b/libX11/src/xlibi18n/ICWrap.c
index 018f89a6b..d0161d2eb 100644
--- a/libX11/src/xlibi18n/ICWrap.c
+++ b/libX11/src/xlibi18n/ICWrap.c
@@ -1,430 +1,429 @@
-/*
- * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation,
- * and Nippon Telegraph and Telephone Corporation
- * Copyright 1991 by the Open Software Foundation
- * Copyright 1993 by the 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 names of OMRON, NTT Software, NTT, and
- * Open Software Foundation not be used in advertising or publicity
- * pertaining to distribution of the software without specific,
- * written prior permission. OMRON, NTT Software, NTT, and Open Software
- * Foundation make no representations about the suitability of this
- * software for any purpose. It is provided "as is" without express or
- * implied warranty.
- *
- * OMRON, NTT SOFTWARE, NTT, AND OPEN SOFTWARE FOUNDATION
- * DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
- * SHALL OMRON, NTT SOFTWARE, NTT, OR OPEN SOFTWARE FOUNDATION 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.
- *
- * Authors: Li Yuhong OMRON Corporation
- * Tatsuya Kato NTT Software Corporation
- * Hiroshi Kuribayashi OMRON Coproration
- * Muneiyoshi Suzuki Nippon Telegraph and Telephone Co.
- *
- * M. Collins OSF
- * Takashi Fujiwara FUJITSU LIMITED
- */
-/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice 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 OPEN GROUP 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.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#define NEED_EVENTS
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xlcint.h"
-
-static int
-_XIMNestedListToNestedList(
- XIMArg *nlist, /* This is the new list */
- XIMArg *list) /* The original list */
-{
- register XIMArg *ptr = list;
-
- while (ptr->name) {
- if (!strcmp(ptr->name, XNVaNestedList)) {
- nlist += _XIMNestedListToNestedList(nlist, (XIMArg *)ptr->value);
- } else {
- nlist->name = ptr->name;
- nlist->value = ptr->value;
- ptr++;
- nlist++;
- }
- }
- return ptr - list;
-}
-
-static void
-_XIMCountNestedList(
- XIMArg *args,
- int *total_count)
-{
- for (; args->name; args++) {
- if (!strcmp(args->name, XNVaNestedList))
- _XIMCountNestedList((XIMArg *)args->value, total_count);
- else
- ++(*total_count);
- }
-}
-
-static void
-_XIMCountVaList(va_list var, int *total_count)
-{
- char *attr;
-
- *total_count = 0;
-
- for (attr = va_arg(var, char*); attr; attr = va_arg(var, char*)) {
- if (!strcmp(attr, XNVaNestedList)) {
- _XIMCountNestedList(va_arg(var, XIMArg*), total_count);
- } else {
- (void)va_arg(var, XIMArg*);
- ++(*total_count);
- }
- }
-}
-
-static void
-_XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
-{
- XIMArg *args;
- char *attr;
-
- if (max_count <= 0) {
- *args_return = (XIMArg *)NULL;
- return;
- }
-
- args = (XIMArg *)Xmalloc((unsigned)(max_count + 1) * sizeof(XIMArg));
- *args_return = args;
- if (!args) return;
-
- for (attr = va_arg(var, char*); attr; attr = va_arg(var, char*)) {
- if (!strcmp(attr, XNVaNestedList)) {
- args += _XIMNestedListToNestedList(args, va_arg(var, XIMArg*));
- } else {
- args->name = attr;
- args->value = va_arg(var, XPointer);
- args++;
- }
- }
- args->name = (char*)NULL;
-}
-
-/*ARGSUSED*/
-XVaNestedList
-XVaCreateNestedList(int dummy, ...)
-{
- va_list var;
- XIMArg *args = NULL;
- int total_count;
-
- va_start(var, dummy);
- _XIMCountVaList(var, &total_count);
- va_end(var);
-
- va_start(var, dummy);
- _XIMVaToNestedList(var, total_count, &args);
- va_end(var);
-
- return (XVaNestedList)args;
-}
-
-char *
-XSetIMValues(XIM im, ...)
-{
- va_list var;
- int total_count;
- XIMArg *args;
- char *ret;
-
- /*
- * so count the stuff dangling here
- */
- va_start(var, im);
- _XIMCountVaList(var, &total_count);
- va_end(var);
-
- /*
- * now package it up so we can send it along
- */
- va_start(var, im);
- _XIMVaToNestedList(var, total_count, &args);
- va_end(var);
-
- ret = (*im->methods->set_values) (im, args);
- if (args) Xfree((char *)args);
- return ret;
-}
-
-char *
-XGetIMValues(XIM im, ...)
-{
- va_list var;
- int total_count;
- XIMArg *args;
- char *ret;
-
- /*
- * so count the stuff dangling here
- */
- va_start(var, im);
- _XIMCountVaList(var, &total_count);
- va_end(var);
-
- /*
- * now package it up so we can send it along
- */
- va_start(var, im);
- _XIMVaToNestedList(var, total_count, &args);
- va_end(var);
-
- ret = (*im->methods->get_values) (im, args);
- if (args) Xfree((char *)args);
- return ret;
-}
-
-/*
- * Create an input context within the input method,
- * and return a pointer to the input context.
- */
-
-XIC
-XCreateIC(XIM im, ...)
-{
- va_list var;
- int total_count;
- XIMArg *args;
- XIC ic;
-
- /*
- * so count the stuff dangling here
- */
- va_start(var, im);
- _XIMCountVaList(var, &total_count);
- va_end(var);
-
- /*
- * now package it up so we can send it along
- */
- va_start(var, im);
- _XIMVaToNestedList(var, total_count, &args);
- va_end(var);
-
- ic = (XIC) (*im->methods->create_ic) (im, args);
- if (args) Xfree((char *)args);
- if (ic) {
- ic->core.next = im->core.ic_chain;
- im->core.ic_chain = ic;
- }
- return ic;
-}
-
-/*
- * Free the input context.
- */
-void
-XDestroyIC(XIC ic)
-{
- XIM im = ic->core.im;
- XIC *prev;
-
- (*ic->methods->destroy) (ic);
- if (im) {
- for (prev = &im->core.ic_chain; *prev; prev = &(*prev)->core.next) {
- if (*prev == ic) {
- *prev = ic->core.next;
- break;
- }
- }
- }
- Xfree ((char *) ic);
-}
-
-char *
-XGetICValues(XIC ic, ...)
-{
- va_list var;
- int total_count;
- XIMArg *args;
- char *ret;
-
- if (!ic->core.im)
- return (char *) NULL;
-
- /*
- * so count the stuff dangling here
- */
- va_start(var, ic);
- _XIMCountVaList(var, &total_count);
- va_end(var);
-
- /*
- * now package it up so we can send it along
- */
- va_start(var, ic);
- _XIMVaToNestedList(var, total_count, &args);
- va_end(var);
-
- ret = (*ic->methods->get_values) (ic, args);
- if (args) Xfree((char *)args);
- return ret;
-}
-
-char *
-XSetICValues(XIC ic, ...)
-{
- va_list var;
- int total_count;
- XIMArg *args;
- char *ret;
-
- if (!ic->core.im)
- return (char *) NULL;
-
- /*
- * so count the stuff dangling here
- */
- va_start(var, ic);
- _XIMCountVaList(var, &total_count);
- va_end(var);
-
- /*
- * now package it up so we can send it along
- */
- va_start(var, ic);
- _XIMVaToNestedList(var, total_count, &args);
- va_end(var);
-
- ret = (*ic->methods->set_values) (ic, args);
- if (args) Xfree((char *)args);
- return ret;
-}
-
-/*
- * Require the input manager to focus the focus window attached to the ic
- * argument.
- */
-void
-XSetICFocus(XIC ic)
-{
- if (ic && ic->core.im)
- (*ic->methods->set_focus) (ic);
-}
-
-/*
- * Require the input manager to unfocus the focus window attached to the ic
- * argument.
- */
-void
-XUnsetICFocus(XIC ic)
-{
- if (ic->core.im)
- (*ic->methods->unset_focus) (ic);
-}
-
-/*
- * Return the XIM associated with the input context.
- */
-XIM
-XIMOfIC(XIC ic)
-{
- return ic->core.im;
-}
-
-char *
-XmbResetIC(XIC ic)
-{
- if (ic->core.im)
- return (*ic->methods->mb_reset)(ic);
- return (char *)NULL;
-}
-
-wchar_t *
-XwcResetIC(XIC ic)
-{
- if (ic->core.im)
- return (*ic->methods->wc_reset)(ic);
- return (wchar_t *)NULL;
-}
-
-char *
-Xutf8ResetIC(XIC ic)
-{
- if (ic->core.im) {
- if (ic->methods->utf8_reset)
- return (*ic->methods->utf8_reset)(ic);
- else if (ic->methods->mb_reset)
- return (*ic->methods->mb_reset)(ic);
- }
- return (char *)NULL;
-}
-
-int
-XmbLookupString(XIC ic, XKeyEvent *ev, char *buffer, int nbytes,
- KeySym *keysym, Status *status)
-{
- if (ic->core.im)
- return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
- keysym, status);
- return XLookupNone;
-}
-
-int
-XwcLookupString(XIC ic, XKeyEvent *ev, wchar_t *buffer, int nchars,
- KeySym *keysym, Status *status)
-{
- if (ic->core.im)
- return (*ic->methods->wc_lookup_string) (ic, ev, buffer, nchars,
- keysym, status);
- return XLookupNone;
-}
-
-int
-Xutf8LookupString(XIC ic, XKeyEvent *ev, char *buffer, int nbytes,
- KeySym *keysym, Status *status)
-{
- if (ic->core.im) {
- if (ic->methods->utf8_lookup_string)
- return (*ic->methods->utf8_lookup_string) (ic, ev, buffer, nbytes,
- keysym, status);
- else if (ic->methods->mb_lookup_string)
- return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
- keysym, status);
- }
- return XLookupNone;
-}
+/*
+ * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation,
+ * and Nippon Telegraph and Telephone Corporation
+ * Copyright 1991 by the Open Software Foundation
+ * Copyright 1993 by the 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 names of OMRON, NTT Software, NTT, and
+ * Open Software Foundation not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. OMRON, NTT Software, NTT, and Open Software
+ * Foundation make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OMRON, NTT SOFTWARE, NTT, AND OPEN SOFTWARE FOUNDATION
+ * DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
+ * SHALL OMRON, NTT SOFTWARE, NTT, OR OPEN SOFTWARE FOUNDATION 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.
+ *
+ * Authors: Li Yuhong OMRON Corporation
+ * Tatsuya Kato NTT Software Corporation
+ * Hiroshi Kuribayashi OMRON Coproration
+ * Muneiyoshi Suzuki Nippon Telegraph and Telephone Co.
+ *
+ * M. Collins OSF
+ * Takashi Fujiwara FUJITSU LIMITED
+ */
+/*
+
+Copyright 1991, 1998 The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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 OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xlcint.h"
+
+static int
+_XIMNestedListToNestedList(
+ XIMArg *nlist, /* This is the new list */
+ XIMArg *list) /* The original list */
+{
+ register XIMArg *ptr = list;
+
+ while (ptr->name) {
+ if (!strcmp(ptr->name, XNVaNestedList)) {
+ nlist += _XIMNestedListToNestedList(nlist, (XIMArg *)ptr->value);
+ } else {
+ nlist->name = ptr->name;
+ nlist->value = ptr->value;
+ ptr++;
+ nlist++;
+ }
+ }
+ return ptr - list;
+}
+
+static void
+_XIMCountNestedList(
+ XIMArg *args,
+ int *total_count)
+{
+ for (; args->name; args++) {
+ if (!strcmp(args->name, XNVaNestedList))
+ _XIMCountNestedList((XIMArg *)args->value, total_count);
+ else
+ ++(*total_count);
+ }
+}
+
+static void
+_XIMCountVaList(va_list var, int *total_count)
+{
+ char *attr;
+
+ *total_count = 0;
+
+ for (attr = va_arg(var, char*); attr; attr = va_arg(var, char*)) {
+ if (!strcmp(attr, XNVaNestedList)) {
+ _XIMCountNestedList(va_arg(var, XIMArg*), total_count);
+ } else {
+ (void)va_arg(var, XIMArg*);
+ ++(*total_count);
+ }
+ }
+}
+
+static void
+_XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
+{
+ XIMArg *args;
+ char *attr;
+
+ if (max_count <= 0) {
+ *args_return = (XIMArg *)NULL;
+ return;
+ }
+
+ args = (XIMArg *)Xmalloc((unsigned)(max_count + 1) * sizeof(XIMArg));
+ *args_return = args;
+ if (!args) return;
+
+ for (attr = va_arg(var, char*); attr; attr = va_arg(var, char*)) {
+ if (!strcmp(attr, XNVaNestedList)) {
+ args += _XIMNestedListToNestedList(args, va_arg(var, XIMArg*));
+ } else {
+ args->name = attr;
+ args->value = va_arg(var, XPointer);
+ args++;
+ }
+ }
+ args->name = (char*)NULL;
+}
+
+/*ARGSUSED*/
+XVaNestedList
+XVaCreateNestedList(int dummy, ...)
+{
+ va_list var;
+ XIMArg *args = NULL;
+ int total_count;
+
+ va_start(var, dummy);
+ _XIMCountVaList(var, &total_count);
+ va_end(var);
+
+ va_start(var, dummy);
+ _XIMVaToNestedList(var, total_count, &args);
+ va_end(var);
+
+ return (XVaNestedList)args;
+}
+
+char *
+XSetIMValues(XIM im, ...)
+{
+ va_list var;
+ int total_count;
+ XIMArg *args;
+ char *ret;
+
+ /*
+ * so count the stuff dangling here
+ */
+ va_start(var, im);
+ _XIMCountVaList(var, &total_count);
+ va_end(var);
+
+ /*
+ * now package it up so we can send it along
+ */
+ va_start(var, im);
+ _XIMVaToNestedList(var, total_count, &args);
+ va_end(var);
+
+ ret = (*im->methods->set_values) (im, args);
+ if (args) Xfree((char *)args);
+ return ret;
+}
+
+char *
+XGetIMValues(XIM im, ...)
+{
+ va_list var;
+ int total_count;
+ XIMArg *args;
+ char *ret;
+
+ /*
+ * so count the stuff dangling here
+ */
+ va_start(var, im);
+ _XIMCountVaList(var, &total_count);
+ va_end(var);
+
+ /*
+ * now package it up so we can send it along
+ */
+ va_start(var, im);
+ _XIMVaToNestedList(var, total_count, &args);
+ va_end(var);
+
+ ret = (*im->methods->get_values) (im, args);
+ if (args) Xfree((char *)args);
+ return ret;
+}
+
+/*
+ * Create an input context within the input method,
+ * and return a pointer to the input context.
+ */
+
+XIC
+XCreateIC(XIM im, ...)
+{
+ va_list var;
+ int total_count;
+ XIMArg *args;
+ XIC ic;
+
+ /*
+ * so count the stuff dangling here
+ */
+ va_start(var, im);
+ _XIMCountVaList(var, &total_count);
+ va_end(var);
+
+ /*
+ * now package it up so we can send it along
+ */
+ va_start(var, im);
+ _XIMVaToNestedList(var, total_count, &args);
+ va_end(var);
+
+ ic = (XIC) (*im->methods->create_ic) (im, args);
+ if (args) Xfree((char *)args);
+ if (ic) {
+ ic->core.next = im->core.ic_chain;
+ im->core.ic_chain = ic;
+ }
+ return ic;
+}
+
+/*
+ * Free the input context.
+ */
+void
+XDestroyIC(XIC ic)
+{
+ XIM im = ic->core.im;
+ XIC *prev;
+
+ (*ic->methods->destroy) (ic);
+ if (im) {
+ for (prev = &im->core.ic_chain; *prev; prev = &(*prev)->core.next) {
+ if (*prev == ic) {
+ *prev = ic->core.next;
+ break;
+ }
+ }
+ }
+ Xfree ((char *) ic);
+}
+
+char *
+XGetICValues(XIC ic, ...)
+{
+ va_list var;
+ int total_count;
+ XIMArg *args;
+ char *ret;
+
+ if (!ic->core.im)
+ return (char *) NULL;
+
+ /*
+ * so count the stuff dangling here
+ */
+ va_start(var, ic);
+ _XIMCountVaList(var, &total_count);
+ va_end(var);
+
+ /*
+ * now package it up so we can send it along
+ */
+ va_start(var, ic);
+ _XIMVaToNestedList(var, total_count, &args);
+ va_end(var);
+
+ ret = (*ic->methods->get_values) (ic, args);
+ if (args) Xfree((char *)args);
+ return ret;
+}
+
+char *
+XSetICValues(XIC ic, ...)
+{
+ va_list var;
+ int total_count;
+ XIMArg *args;
+ char *ret;
+
+ if (!ic->core.im)
+ return (char *) NULL;
+
+ /*
+ * so count the stuff dangling here
+ */
+ va_start(var, ic);
+ _XIMCountVaList(var, &total_count);
+ va_end(var);
+
+ /*
+ * now package it up so we can send it along
+ */
+ va_start(var, ic);
+ _XIMVaToNestedList(var, total_count, &args);
+ va_end(var);
+
+ ret = (*ic->methods->set_values) (ic, args);
+ if (args) Xfree((char *)args);
+ return ret;
+}
+
+/*
+ * Require the input manager to focus the focus window attached to the ic
+ * argument.
+ */
+void
+XSetICFocus(XIC ic)
+{
+ if (ic && ic->core.im)
+ (*ic->methods->set_focus) (ic);
+}
+
+/*
+ * Require the input manager to unfocus the focus window attached to the ic
+ * argument.
+ */
+void
+XUnsetICFocus(XIC ic)
+{
+ if (ic->core.im)
+ (*ic->methods->unset_focus) (ic);
+}
+
+/*
+ * Return the XIM associated with the input context.
+ */
+XIM
+XIMOfIC(XIC ic)
+{
+ return ic->core.im;
+}
+
+char *
+XmbResetIC(XIC ic)
+{
+ if (ic->core.im)
+ return (*ic->methods->mb_reset)(ic);
+ return (char *)NULL;
+}
+
+wchar_t *
+XwcResetIC(XIC ic)
+{
+ if (ic->core.im)
+ return (*ic->methods->wc_reset)(ic);
+ return (wchar_t *)NULL;
+}
+
+char *
+Xutf8ResetIC(XIC ic)
+{
+ if (ic->core.im) {
+ if (ic->methods->utf8_reset)
+ return (*ic->methods->utf8_reset)(ic);
+ else if (ic->methods->mb_reset)
+ return (*ic->methods->mb_reset)(ic);
+ }
+ return (char *)NULL;
+}
+
+int
+XmbLookupString(XIC ic, XKeyEvent *ev, char *buffer, int nbytes,
+ KeySym *keysym, Status *status)
+{
+ if (ic->core.im)
+ return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
+ keysym, status);
+ return XLookupNone;
+}
+
+int
+XwcLookupString(XIC ic, XKeyEvent *ev, wchar_t *buffer, int nchars,
+ KeySym *keysym, Status *status)
+{
+ if (ic->core.im)
+ return (*ic->methods->wc_lookup_string) (ic, ev, buffer, nchars,
+ keysym, status);
+ return XLookupNone;
+}
+
+int
+Xutf8LookupString(XIC ic, XKeyEvent *ev, char *buffer, int nbytes,
+ KeySym *keysym, Status *status)
+{
+ if (ic->core.im) {
+ if (ic->methods->utf8_lookup_string)
+ return (*ic->methods->utf8_lookup_string) (ic, ev, buffer, nbytes,
+ keysym, status);
+ else if (ic->methods->mb_lookup_string)
+ return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
+ keysym, status);
+ }
+ return XLookupNone;
+}
diff --git a/libX11/src/xlibi18n/XDefaultIMIF.c b/libX11/src/xlibi18n/XDefaultIMIF.c
index de17d20c6..c6f3f2e37 100644
--- a/libX11/src/xlibi18n/XDefaultIMIF.c
+++ b/libX11/src/xlibi18n/XDefaultIMIF.c
@@ -1,472 +1,471 @@
-/*
-Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
-
-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 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
-OPEN GROUP 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
-EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
-
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-X Window System is a trademark of The Open Group
-
-OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
-logo, LBX, X Window System, and Xinerama are trademarks of the Open
-Group. All other trademarks and registered trademarks mentioned herein
-are the property of their respective owners. No right, title or
-interest in or to any trademark, service mark, logo or trade name of
-Sun Microsystems, Inc. or its licensors is granted.
-
-*/
-/*
- * Copyright 2000 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.
- */
-
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#define NEED_EVENTS
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcGeneric.h"
-
-#ifndef MAXINT
-#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1))
-#endif /* !MAXINT */
-
-typedef struct _StaticXIM *StaticXIM;
-
-typedef struct _XIMStaticXIMRec {
- /* for CT => MB,WC converter */
- XlcConv ctom_conv;
- XlcConv ctow_conv;
-} XIMStaticXIMRec;
-
-typedef enum {
- CREATE_IC = 1,
- SET_ICVAL = 2,
- GET_ICVAL = 3
-} XICOp_t;
-
-typedef struct _StaticXIM {
- XIMMethods methods;
- XIMCoreRec core;
- XIMStaticXIMRec *private;
-} StaticXIMRec;
-
-static Status _CloseIM(
- XIM
-);
-
-static char *_SetIMValues(
- XIM, XIMArg *
-);
-
-static char *_GetIMValues(
- XIM, XIMArg*
-);
-
-static XIC _CreateIC(
- XIM, XIMArg*
-);
-
-static _Xconst XIMMethodsRec local_im_methods = {
- _CloseIM, /* close */
- _SetIMValues, /* set_values */
- _GetIMValues, /* get_values */
- _CreateIC, /* create_ic */
- NULL, /* ctstombs */
- NULL /* ctstowcs */
-};
-
-static void _DestroyIC(
- XIC
-);
-static void _SetFocus(
- XIC
-);
-static void _UnsetFocus(
- XIC
-);
-static char* _SetICValues(
- XIC, XIMArg *
-);
-static char* _GetICValues(
- XIC, XIMArg *
-);
-static char *_MbReset(
- XIC
-);
-static wchar_t *_WcReset(
- XIC
-);
-static int _MbLookupString(
- XIC, XKeyEvent *, char *, int, KeySym *, Status *
-);
-static int _WcLookupString(
- XIC, XKeyEvent *, wchar_t *, int, KeySym *, Status *
-);
-
-static _Xconst XICMethodsRec local_ic_methods = {
- _DestroyIC, /* destroy */
- _SetFocus, /* set_focus */
- _UnsetFocus, /* unset_focus */
- _SetICValues, /* set_values */
- _GetICValues, /* get_values */
- _MbReset, /* mb_reset */
- _WcReset, /* wc_reset */
- NULL, /* utf8_reset */ /* ??? */
- _MbLookupString, /* mb_lookup_string */
- _WcLookupString, /* wc_lookup_string */
- NULL /* utf8_lookup_string */ /* ??? */
-};
-
-XIM
-_XDefaultOpenIM(
- XLCd lcd,
- Display *dpy,
- XrmDatabase rdb,
- char *res_name,
- char *res_class)
-{
- StaticXIM im;
- XIMStaticXIMRec *local_impart;
- XlcConv ctom_conv, ctow_conv;
- int i;
- char *mod;
- char buf[BUFSIZ];
-
- if (!(ctom_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNMultiByte))) {
- return((XIM)NULL);
- }
-
- if (!(ctow_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNWideChar))) {
- return((XIM)NULL);
- }
-
- if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) {
- return((XIM)NULL);
- }
- if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec)))
- == (XIMStaticXIMRec *)NULL) {
- Xfree(im);
- return((XIM)NULL);
- }
- memset(im, 0, sizeof(StaticXIMRec));
- memset(local_impart, 0, sizeof(XIMStaticXIMRec));
-
- buf[0] = '\0';
- i = 0;
- if ((lcd->core->modifiers) && (*lcd->core->modifiers)) {
-#define MODIFIER "@im="
- mod = strstr(lcd->core->modifiers, MODIFIER);
- if (mod) {
- mod += strlen(MODIFIER);
- while (*mod && *mod != '@' && i < BUFSIZ - 1) {
- buf[i++] = *mod++;
- }
- buf[i] = '\0';
- }
- }
-#undef MODIFIER
- if ((im->core.im_name = Xmalloc(i+1)) == NULL)
- goto Error2;
- strcpy(im->core.im_name, buf);
-
- im->private = local_impart;
- im->methods = (XIMMethods)&local_im_methods;
- im->core.lcd = lcd;
- im->core.ic_chain = (XIC)NULL;
- im->core.display = dpy;
- im->core.rdb = rdb;
- im->core.res_name = NULL;
- im->core.res_class = NULL;
-
- local_impart->ctom_conv = ctom_conv;
- local_impart->ctow_conv = ctow_conv;
-
- if ((res_name != NULL) && (*res_name != '\0')){
- im->core.res_name = (char *)Xmalloc(strlen(res_name)+1);
- strcpy(im->core.res_name,res_name);
- }
- if ((res_class != NULL) && (*res_class != '\0')){
- im->core.res_class = (char *)Xmalloc(strlen(res_class)+1);
- strcpy(im->core.res_class,res_class);
- }
-
- return (XIM)im;
-Error2 :
- Xfree(im->private);
- Xfree(im->core.im_name);
- Xfree(im);
- _XlcCloseConverter(ctom_conv);
- _XlcCloseConverter(ctow_conv);
- return(NULL);
-}
-
-static Status
-_CloseIM(XIM xim)
-{
- StaticXIM im = (StaticXIM)xim;
- _XlcCloseConverter(im->private->ctom_conv);
- _XlcCloseConverter(im->private->ctow_conv);
- XFree(im->private);
- XFree(im->core.im_name);
- if (im->core.res_name) XFree(im->core.res_name);
- if (im->core.res_class) XFree(im->core.res_class);
- return 1; /*bugID 4163122*/
-}
-
-static char *
-_SetIMValues(
- XIM xim,
- XIMArg *arg)
-{
- return(arg->name); /* evil */
-}
-
-static char *
-_GetIMValues(
- XIM xim,
- XIMArg *values)
-{
- XIMArg *p;
- XIMStyles *styles;
-
- for (p = values; p->name != NULL; p++) {
- if (strcmp(p->name, XNQueryInputStyle) == 0) {
- styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles));
- *(XIMStyles **)p->value = styles;
- styles->count_styles = 1;
- styles->supported_styles =
- (XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle));
- styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone);
- } else {
- break;
- }
- }
- return (p->name);
-}
-
-static char*
-_SetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
-{
- XIMArg *p;
- char *return_name = NULL;
-
- for (p = values; p != NULL && p->name != NULL; p++) {
- if(strcmp(p->name, XNInputStyle) == 0) {
- if (mode == CREATE_IC)
- ic->core.input_style = (XIMStyle)p->value;
- } else if (strcmp(p->name, XNClientWindow) == 0) {
- ic->core.client_window = (Window)p->value ;
- } else if (strcmp(p->name, XNFocusWindow) == 0) {
- ic->core.focus_window = (Window)p->value ;
- } else if (strcmp(p->name, XNPreeditAttributes) == 0
- || strcmp(p->name, XNStatusAttributes) == 0) {
- return_name = _SetICValueData(ic, (XIMArg*)p->value, mode);
- if (return_name) break;
- } else {
- return_name = p->name;
- break;
- }
- }
- return(return_name);
-}
-
-static char*
-_GetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
-{
- XIMArg *p;
- char *return_name = NULL;
-
- for (p = values; p->name != NULL; p++) {
- if(strcmp(p->name, XNInputStyle) == 0) {
- *((XIMStyle *)(p->value)) = ic->core.input_style;
- } else if (strcmp(p->name, XNClientWindow) == 0) {
- *((Window *)(p->value)) = ic->core.client_window;
- } else if (strcmp(p->name, XNFocusWindow) == 0) {
- *((Window *)(p->value)) = ic->core.focus_window;
- } else if (strcmp(p->name, XNFilterEvents) == 0) {
- *((unsigned long *)(p->value))= ic->core.filter_events;
- } else if (strcmp(p->name, XNPreeditAttributes) == 0
- || strcmp(p->name, XNStatusAttributes) == 0) {
- return_name = _GetICValueData(ic, (XIMArg*)p->value, mode);
- if (return_name) break;
- } else {
- return_name = p->name;
- break;
- }
- }
- return(return_name);
-}
-
-static XIC
-_CreateIC(XIM im, XIMArg *arg)
-{
- XIC ic;
-
- if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) {
- return ((XIC)NULL);
- }
- memset(ic, 0, sizeof(XICRec));
-
- ic->methods = (XICMethods)&local_ic_methods;
- ic->core.im = im;
- ic->core.filter_events = KeyPressMask;
-
- if (_SetICValueData(ic, arg, CREATE_IC) != NULL)
- goto err_return;
- if (!(ic->core.input_style))
- goto err_return;
-
- return (XIC)ic;
-err_return:
- XFree(ic);
- return ((XIC)NULL);
-}
-
-static void
-_DestroyIC(XIC ic)
-{
-/*BugId4255571. This Xfree() should be removed because XDestroyIC() still need ic after invoking _DestroyIC() and there is a XFree(ic) at the end of XDestroyIC() already.
- if(ic)
- XFree(ic); */
-}
-
-static void
-_SetFocus(XIC ic)
-{
-}
-
-static void
-_UnsetFocus(XIC ic)
-{
-}
-
-static char*
-_SetICValues(XIC ic, XIMArg *args)
-{
- char *ret = NULL;
- if (!ic) {
- return (args->name);
- }
- ret = _SetICValueData(ic, args, SET_ICVAL);
- return(ret);
-}
-
-static char*
-_GetICValues(XIC ic, XIMArg *args)
-{
- char *ret = NULL;
- if (!ic) {
- return (args->name);
- }
- ret = _GetICValueData(ic, args, GET_ICVAL);
- return(ret);
-}
-
-static char *
-_MbReset(XIC xic)
-{
- return(NULL);
-}
-
-static wchar_t *
-_WcReset(XIC xic)
-{
- return(NULL);
-}
-
-static int
-_MbLookupString(
- XIC xic,
- XKeyEvent *ev,
- char * buffer,
- int bytes,
- KeySym *keysym,
- Status *status)
-{
- XComposeStatus NotSupportedYet ;
- int length;
-
- length = XLookupString(ev, buffer, bytes, keysym, &NotSupportedYet);
-
- if (keysym && *keysym == NoSymbol){
- *status = XLookupNone;
- } else if (length > 0) {
- *status = XLookupBoth;
- } else {
- *status = XLookupKeySym;
- }
- return(length);
-}
-
-static int
-_WcLookupString(
- XIC xic,
- XKeyEvent *ev,
- wchar_t * buffer,
- int wlen,
- KeySym *keysym,
- Status *status)
-{
- XComposeStatus NotSupportedYet ;
- int length;
- /* In single-byte, mb_len = wc_len */
- char *mb_buf = (char *)Xmalloc(wlen);
-
- length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet);
-
- if (keysym && *keysym == NoSymbol){
- *status = XLookupNone;
- } else if (length > 0) {
- *status = XLookupBoth;
- } else {
- *status = XLookupKeySym;
- }
- mbstowcs(buffer, mb_buf, length);
- XFree(mb_buf);
- return(length);
-}
+/*
+Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
+
+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 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
+OPEN GROUP 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
+EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
+
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+X Window System is a trademark of The Open Group
+
+OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
+logo, LBX, X Window System, and Xinerama are trademarks of the Open
+Group. All other trademarks and registered trademarks mentioned herein
+are the property of their respective owners. No right, title or
+interest in or to any trademark, service mark, logo or trade name of
+Sun Microsystems, Inc. or its licensors is granted.
+
+*/
+/*
+ * Copyright 2000 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.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcGeneric.h"
+
+#ifndef MAXINT
+#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1))
+#endif /* !MAXINT */
+
+typedef struct _StaticXIM *StaticXIM;
+
+typedef struct _XIMStaticXIMRec {
+ /* for CT => MB,WC converter */
+ XlcConv ctom_conv;
+ XlcConv ctow_conv;
+} XIMStaticXIMRec;
+
+typedef enum {
+ CREATE_IC = 1,
+ SET_ICVAL = 2,
+ GET_ICVAL = 3
+} XICOp_t;
+
+typedef struct _StaticXIM {
+ XIMMethods methods;
+ XIMCoreRec core;
+ XIMStaticXIMRec *private;
+} StaticXIMRec;
+
+static Status _CloseIM(
+ XIM
+);
+
+static char *_SetIMValues(
+ XIM, XIMArg *
+);
+
+static char *_GetIMValues(
+ XIM, XIMArg*
+);
+
+static XIC _CreateIC(
+ XIM, XIMArg*
+);
+
+static _Xconst XIMMethodsRec local_im_methods = {
+ _CloseIM, /* close */
+ _SetIMValues, /* set_values */
+ _GetIMValues, /* get_values */
+ _CreateIC, /* create_ic */
+ NULL, /* ctstombs */
+ NULL /* ctstowcs */
+};
+
+static void _DestroyIC(
+ XIC
+);
+static void _SetFocus(
+ XIC
+);
+static void _UnsetFocus(
+ XIC
+);
+static char* _SetICValues(
+ XIC, XIMArg *
+);
+static char* _GetICValues(
+ XIC, XIMArg *
+);
+static char *_MbReset(
+ XIC
+);
+static wchar_t *_WcReset(
+ XIC
+);
+static int _MbLookupString(
+ XIC, XKeyEvent *, char *, int, KeySym *, Status *
+);
+static int _WcLookupString(
+ XIC, XKeyEvent *, wchar_t *, int, KeySym *, Status *
+);
+
+static _Xconst XICMethodsRec local_ic_methods = {
+ _DestroyIC, /* destroy */
+ _SetFocus, /* set_focus */
+ _UnsetFocus, /* unset_focus */
+ _SetICValues, /* set_values */
+ _GetICValues, /* get_values */
+ _MbReset, /* mb_reset */
+ _WcReset, /* wc_reset */
+ NULL, /* utf8_reset */ /* ??? */
+ _MbLookupString, /* mb_lookup_string */
+ _WcLookupString, /* wc_lookup_string */
+ NULL /* utf8_lookup_string */ /* ??? */
+};
+
+XIM
+_XDefaultOpenIM(
+ XLCd lcd,
+ Display *dpy,
+ XrmDatabase rdb,
+ char *res_name,
+ char *res_class)
+{
+ StaticXIM im;
+ XIMStaticXIMRec *local_impart;
+ XlcConv ctom_conv, ctow_conv;
+ int i;
+ char *mod;
+ char buf[BUFSIZ];
+
+ if (!(ctom_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNMultiByte))) {
+ return((XIM)NULL);
+ }
+
+ if (!(ctow_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNWideChar))) {
+ return((XIM)NULL);
+ }
+
+ if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) {
+ return((XIM)NULL);
+ }
+ if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec)))
+ == (XIMStaticXIMRec *)NULL) {
+ Xfree(im);
+ return((XIM)NULL);
+ }
+ memset(im, 0, sizeof(StaticXIMRec));
+ memset(local_impart, 0, sizeof(XIMStaticXIMRec));
+
+ buf[0] = '\0';
+ i = 0;
+ if ((lcd->core->modifiers) && (*lcd->core->modifiers)) {
+#define MODIFIER "@im="
+ mod = strstr(lcd->core->modifiers, MODIFIER);
+ if (mod) {
+ mod += strlen(MODIFIER);
+ while (*mod && *mod != '@' && i < BUFSIZ - 1) {
+ buf[i++] = *mod++;
+ }
+ buf[i] = '\0';
+ }
+ }
+#undef MODIFIER
+ if ((im->core.im_name = Xmalloc(i+1)) == NULL)
+ goto Error2;
+ strcpy(im->core.im_name, buf);
+
+ im->private = local_impart;
+ im->methods = (XIMMethods)&local_im_methods;
+ im->core.lcd = lcd;
+ im->core.ic_chain = (XIC)NULL;
+ im->core.display = dpy;
+ im->core.rdb = rdb;
+ im->core.res_name = NULL;
+ im->core.res_class = NULL;
+
+ local_impart->ctom_conv = ctom_conv;
+ local_impart->ctow_conv = ctow_conv;
+
+ if ((res_name != NULL) && (*res_name != '\0')){
+ im->core.res_name = (char *)Xmalloc(strlen(res_name)+1);
+ strcpy(im->core.res_name,res_name);
+ }
+ if ((res_class != NULL) && (*res_class != '\0')){
+ im->core.res_class = (char *)Xmalloc(strlen(res_class)+1);
+ strcpy(im->core.res_class,res_class);
+ }
+
+ return (XIM)im;
+Error2 :
+ Xfree(im->private);
+ Xfree(im->core.im_name);
+ Xfree(im);
+ _XlcCloseConverter(ctom_conv);
+ _XlcCloseConverter(ctow_conv);
+ return(NULL);
+}
+
+static Status
+_CloseIM(XIM xim)
+{
+ StaticXIM im = (StaticXIM)xim;
+ _XlcCloseConverter(im->private->ctom_conv);
+ _XlcCloseConverter(im->private->ctow_conv);
+ XFree(im->private);
+ XFree(im->core.im_name);
+ if (im->core.res_name) XFree(im->core.res_name);
+ if (im->core.res_class) XFree(im->core.res_class);
+ return 1; /*bugID 4163122*/
+}
+
+static char *
+_SetIMValues(
+ XIM xim,
+ XIMArg *arg)
+{
+ return(arg->name); /* evil */
+}
+
+static char *
+_GetIMValues(
+ XIM xim,
+ XIMArg *values)
+{
+ XIMArg *p;
+ XIMStyles *styles;
+
+ for (p = values; p->name != NULL; p++) {
+ if (strcmp(p->name, XNQueryInputStyle) == 0) {
+ styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles));
+ *(XIMStyles **)p->value = styles;
+ styles->count_styles = 1;
+ styles->supported_styles =
+ (XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle));
+ styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone);
+ } else {
+ break;
+ }
+ }
+ return (p->name);
+}
+
+static char*
+_SetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
+{
+ XIMArg *p;
+ char *return_name = NULL;
+
+ for (p = values; p != NULL && p->name != NULL; p++) {
+ if(strcmp(p->name, XNInputStyle) == 0) {
+ if (mode == CREATE_IC)
+ ic->core.input_style = (XIMStyle)p->value;
+ } else if (strcmp(p->name, XNClientWindow) == 0) {
+ ic->core.client_window = (Window)p->value ;
+ } else if (strcmp(p->name, XNFocusWindow) == 0) {
+ ic->core.focus_window = (Window)p->value ;
+ } else if (strcmp(p->name, XNPreeditAttributes) == 0
+ || strcmp(p->name, XNStatusAttributes) == 0) {
+ return_name = _SetICValueData(ic, (XIMArg*)p->value, mode);
+ if (return_name) break;
+ } else {
+ return_name = p->name;
+ break;
+ }
+ }
+ return(return_name);
+}
+
+static char*
+_GetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
+{
+ XIMArg *p;
+ char *return_name = NULL;
+
+ for (p = values; p->name != NULL; p++) {
+ if(strcmp(p->name, XNInputStyle) == 0) {
+ *((XIMStyle *)(p->value)) = ic->core.input_style;
+ } else if (strcmp(p->name, XNClientWindow) == 0) {
+ *((Window *)(p->value)) = ic->core.client_window;
+ } else if (strcmp(p->name, XNFocusWindow) == 0) {
+ *((Window *)(p->value)) = ic->core.focus_window;
+ } else if (strcmp(p->name, XNFilterEvents) == 0) {
+ *((unsigned long *)(p->value))= ic->core.filter_events;
+ } else if (strcmp(p->name, XNPreeditAttributes) == 0
+ || strcmp(p->name, XNStatusAttributes) == 0) {
+ return_name = _GetICValueData(ic, (XIMArg*)p->value, mode);
+ if (return_name) break;
+ } else {
+ return_name = p->name;
+ break;
+ }
+ }
+ return(return_name);
+}
+
+static XIC
+_CreateIC(XIM im, XIMArg *arg)
+{
+ XIC ic;
+
+ if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) {
+ return ((XIC)NULL);
+ }
+ memset(ic, 0, sizeof(XICRec));
+
+ ic->methods = (XICMethods)&local_ic_methods;
+ ic->core.im = im;
+ ic->core.filter_events = KeyPressMask;
+
+ if (_SetICValueData(ic, arg, CREATE_IC) != NULL)
+ goto err_return;
+ if (!(ic->core.input_style))
+ goto err_return;
+
+ return (XIC)ic;
+err_return:
+ XFree(ic);
+ return ((XIC)NULL);
+}
+
+static void
+_DestroyIC(XIC ic)
+{
+/*BugId4255571. This Xfree() should be removed because XDestroyIC() still need ic after invoking _DestroyIC() and there is a XFree(ic) at the end of XDestroyIC() already.
+ if(ic)
+ XFree(ic); */
+}
+
+static void
+_SetFocus(XIC ic)
+{
+}
+
+static void
+_UnsetFocus(XIC ic)
+{
+}
+
+static char*
+_SetICValues(XIC ic, XIMArg *args)
+{
+ char *ret = NULL;
+ if (!ic) {
+ return (args->name);
+ }
+ ret = _SetICValueData(ic, args, SET_ICVAL);
+ return(ret);
+}
+
+static char*
+_GetICValues(XIC ic, XIMArg *args)
+{
+ char *ret = NULL;
+ if (!ic) {
+ return (args->name);
+ }
+ ret = _GetICValueData(ic, args, GET_ICVAL);
+ return(ret);
+}
+
+static char *
+_MbReset(XIC xic)
+{
+ return(NULL);
+}
+
+static wchar_t *
+_WcReset(XIC xic)
+{
+ return(NULL);
+}
+
+static int
+_MbLookupString(
+ XIC xic,
+ XKeyEvent *ev,
+ char * buffer,
+ int bytes,
+ KeySym *keysym,
+ Status *status)
+{
+ XComposeStatus NotSupportedYet ;
+ int length;
+
+ length = XLookupString(ev, buffer, bytes, keysym, &NotSupportedYet);
+
+ if (keysym && *keysym == NoSymbol){
+ *status = XLookupNone;
+ } else if (length > 0) {
+ *status = XLookupBoth;
+ } else {
+ *status = XLookupKeySym;
+ }
+ return(length);
+}
+
+static int
+_WcLookupString(
+ XIC xic,
+ XKeyEvent *ev,
+ wchar_t * buffer,
+ int wlen,
+ KeySym *keysym,
+ Status *status)
+{
+ XComposeStatus NotSupportedYet ;
+ int length;
+ /* In single-byte, mb_len = wc_len */
+ char *mb_buf = (char *)Xmalloc(wlen);
+
+ length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet);
+
+ if (keysym && *keysym == NoSymbol){
+ *status = XLookupNone;
+ } else if (length > 0) {
+ *status = XLookupBoth;
+ } else {
+ *status = XLookupKeySym;
+ }
+ mbstowcs(buffer, mb_buf, length);
+ XFree(mb_buf);
+ return(length);
+}