From 96d6df5da9cddedf4931bf8e17f96e242467c661 Mon Sep 17 00:00:00 2001 From: marha Date: Wed, 27 Apr 2011 06:58:32 +0000 Subject: xserver libX11 libxtrans mesa pixman xkeyboard-config git update 27 Apr 2011 --- libX11/modules/im/ximcp/imDefIc.c | 3 +- libX11/modules/im/ximcp/imInt.c | 9 +- libX11/modules/im/ximcp/imLcIc.c | 3 +- libX11/modules/im/ximcp/imRm.c | 37 +-- libX11/modules/im/ximcp/imRmAttr.c | 15 +- libX11/modules/im/ximcp/imThaiIc.c | 3 +- libX11/modules/im/ximcp/imTrX.c | 3 +- libX11/modules/im/ximcp/imTrans.c | 629 ++++++++++++++++++------------------- 8 files changed, 336 insertions(+), 366 deletions(-) (limited to 'libX11/modules/im') diff --git a/libX11/modules/im/ximcp/imDefIc.c b/libX11/modules/im/ximcp/imDefIc.c index 9283c49c3..a962c1b0f 100644 --- a/libX11/modules/im/ximcp/imDefIc.c +++ b/libX11/modules/im/ximcp/imDefIc.c @@ -1425,10 +1425,9 @@ _XimProtoCreateIC( if (!(_XimGetInputStyle(arg, &input_style))) return (XIC)NULL; - if ((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) + if ((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) return (XIC)NULL; - bzero((char *)ic, sizeof(XicRec)); ic->methods = &ic_methods; ic->core.im = (XIM)im; ic->core.input_style = input_style; diff --git a/libX11/modules/im/ximcp/imInt.c b/libX11/modules/im/ximcp/imInt.c index b19809237..26f4991a2 100644 --- a/libX11/modules/im/ximcp/imInt.c +++ b/libX11/modules/im/ximcp/imInt.c @@ -204,9 +204,8 @@ _XimOpenIM( Xim im; register int i; - if (!(im = (Xim)Xmalloc(sizeof(XimRec)))) + if (!(im = Xcalloc(1, sizeof(XimRec)))) return (XIM)NULL; - bzero(im, sizeof(XimRec)); im->core.lcd = lcd; im->core.ic_chain = (XIC)NULL; @@ -215,14 +214,12 @@ _XimOpenIM( im->core.res_name = NULL; im->core.res_class = NULL; if((res_name != NULL) && (*res_name != '\0')){ - if(!(im->core.res_name = (char *)Xmalloc(strlen(res_name)+1))) + if(!(im->core.res_name = strdup(res_name))) goto Error1; - strcpy(im->core.res_name,res_name); } if((res_class != NULL) && (*res_class != '\0')){ - if(!(im->core.res_class = (char *)Xmalloc(strlen(res_class)+1))) + if(!(im->core.res_class = strdup(res_class))) goto Error2; - strcpy(im->core.res_class,res_class); } if(!(im->core.im_name = _XimMakeImName(lcd))) goto Error3; diff --git a/libX11/modules/im/ximcp/imLcIc.c b/libX11/modules/im/ximcp/imLcIc.c index c0728084f..49338853c 100644 --- a/libX11/modules/im/ximcp/imLcIc.c +++ b/libX11/modules/im/ximcp/imLcIc.c @@ -143,10 +143,9 @@ _XimLocalCreateIC( unsigned int num; int len; - if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) { + if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) { return ((XIC)NULL); } - bzero((char *)ic, sizeof(XicRec)); ic->methods = &Local_ic_methods; ic->core.im = im; diff --git a/libX11/modules/im/ximcp/imRm.c b/libX11/modules/im/ximcp/imRm.c index 3d09b8136..da1207ca1 100644 --- a/libX11/modules/im/ximcp/imRm.c +++ b/libX11/modules/im/ximcp/imRm.c @@ -360,10 +360,9 @@ _XimDefaultStyles( n = XIMNumber(supported_local_styles) - 1; len = sizeof(XIMStyles) + sizeof(XIMStyle) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); styles = (XIMStyles *)tmp; if (n > 0) { @@ -396,10 +395,9 @@ _XimDefaultIMValues( n = XIMNumber(supported_local_im_values_list); len = sizeof(XIMValuesList) + sizeof(char **) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); values_list = (XIMValuesList *)tmp; if (n > 0) { @@ -433,10 +431,9 @@ _XimDefaultICValues( n = XIMNumber(supported_local_ic_values_list); len = sizeof(XIMValuesList) + sizeof(char **) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); values_list = (XIMValuesList *)tmp; if (n > 0) { @@ -796,19 +793,15 @@ _XimEncodeString( XPointer top, XPointer val) { - int len; char *string; char **out; if(val == (XPointer)NULL) { return False; } - len = strlen((char *)val); - if(!(string = (char *)Xmalloc(len + 1))) { + if (!(string = strdup((char *)val))) { return False; } - (void)strcpy(string, (char *)val); - string[len] = '\0'; out = (char **)((char *)top + info->offset); if(*out) { @@ -1085,10 +1078,9 @@ _XimDecodeStyles( num = styles->count_styles; len = sizeof(XIMStyles) + sizeof(XIMStyle) * num; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); out = (XIMStyles *)tmp; if(num >0) { @@ -1124,10 +1116,9 @@ _XimDecodeValues( num = values_list->count_values; len = sizeof(XIMValuesList) + sizeof(char **) * num; - if(!(tmp = (char *)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); out = (XIMValuesList *)tmp; if(num) { @@ -1168,21 +1159,18 @@ _XimDecodeString( XPointer top, XPointer val) { - int len = 0; char *in; char *string; in = *((char **)((char *)top + info->offset)); - if(in != (char *)NULL) { - len = strlen(in); + if (in != NULL) { + string = strdup(in); + } else { + string = Xcalloc(1, 1); /* strdup("") */ } - if(!(string = (char *)Xmalloc(len + 1))) { + if (string == NULL) { return False; } - if(in != (char *)NULL) { - (void)strcpy(string, in); - } - string[len] = '\0'; *((char **)val) = string; return True; } @@ -2143,10 +2131,9 @@ _XimSetResourceList( XIMResourceList res; len = sizeof(XIMResource) * num_resource; - if(!(res = (XIMResourceList)Xmalloc(len))) { + if(!(res = Xcalloc(1, len))) { return False; } - bzero((char *)res, len); for(i = 0; i < num_resource; i++, id++) { res[i] = resource[i]; diff --git a/libX11/modules/im/ximcp/imRmAttr.c b/libX11/modules/im/ximcp/imRmAttr.c index 27dcbc9cd..2e732658a 100644 --- a/libX11/modules/im/ximcp/imRmAttr.c +++ b/libX11/modules/im/ximcp/imRmAttr.c @@ -1408,7 +1408,6 @@ _XimGetAttributeID( { unsigned int n; XIMResourceList res; - int res_len; char *names; int names_len; XPointer tmp; @@ -1426,18 +1425,15 @@ _XimGetAttributeID( if (!(n = _XimCountNumberOfAttr(buf[0], &buf[1], &names_len))) return False; - res_len = sizeof(XIMResource) * n; - if (!(res = (XIMResourceList)Xmalloc(res_len))) + if (!(res = Xcalloc(n, sizeof(XIMResource)))) return False; - bzero((char *)res, res_len); values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) { + if (!(tmp = Xcalloc(1, values_len))) { Xfree(res); return False; } - bzero(tmp, values_len); values_list = (XIMValuesList *)tmp; values = (char **)((char *)tmp + sizeof(XIMValuesList)); @@ -1475,18 +1471,15 @@ _XimGetAttributeID( if (!(n = _XimCountNumberOfAttr(buf[0], &buf[2], &names_len))) return False; - res_len = sizeof(XIMResource) * n; - if (!(res = (XIMResourceList)Xmalloc(res_len))) + if (!(res = Xcalloc(n, sizeof(XIMResource)))) return False; - bzero((char *)res, res_len); values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) { + if (!(tmp = Xcalloc(1, values_len))) { Xfree(res); return False; } - bzero(tmp, values_len); values_list = (XIMValuesList *)tmp; values = (char **)((char *)tmp + sizeof(XIMValuesList)); diff --git a/libX11/modules/im/ximcp/imThaiIc.c b/libX11/modules/im/ximcp/imThaiIc.c index d1cb22a5e..95433f3d7 100644 --- a/libX11/modules/im/ximcp/imThaiIc.c +++ b/libX11/modules/im/ximcp/imThaiIc.c @@ -157,10 +157,9 @@ _XimThaiCreateIC( int len; DefTree *tree; - if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) { + if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) { return ((XIC)NULL); } - bzero((char *)ic, sizeof(XicRec)); ic->methods = &Thai_ic_methods; ic->core.im = im; diff --git a/libX11/modules/im/ximcp/imTrX.c b/libX11/modules/im/ximcp/imTrX.c index edcaf0852..d85d1d114 100644 --- a/libX11/modules/im/ximcp/imTrX.c +++ b/libX11/modules/im/ximcp/imTrX.c @@ -496,9 +496,8 @@ _XimXConf(Xim im, char *address) { XSpecRec *spec; - if (!(spec = (XSpecRec *)Xmalloc(sizeof(XSpecRec)))) + if (!(spec = Xcalloc(1, 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); diff --git a/libX11/modules/im/ximcp/imTrans.c b/libX11/modules/im/ximcp/imTrans.c index 7673279c6..0ac08aa60 100644 --- a/libX11/modules/im/ximcp/imTrans.c +++ b/libX11/modules/im/ximcp/imTrans.c @@ -1,316 +1,313 @@ -/* - * Copyright 1992 Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ -/****************************************************************** - - Copyright 1992, 1993, 1994 by FUJITSU LIMITED - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear -in supporting documentation, and that the name of FUJITSU LIMITED -not be used in advertising or publicity pertaining to distribution -of the software without specific, written prior permission. -FUJITSU LIMITED makes no representations about the suitability of -this software for any purpose. -It is provided "as is" without express or implied warranty. - -FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - - Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc. - Takashi Fujiwara FUJITSU LIMITED - fujiwara@a80.tech.yk.fujitsu.co.jp - -******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include "Xlibint.h" -#include -#include "Xlcint.h" -#include "Ximint.h" -#include "XimTrans.h" -#include "XimTrInt.h" - -#ifdef WIN32 -#include -#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 Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +/****************************************************************** + + Copyright 1992, 1993, 1994 by FUJITSU LIMITED + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear +in supporting documentation, and that the name of FUJITSU LIMITED +not be used in advertising or publicity pertaining to distribution +of the software without specific, written prior permission. +FUJITSU LIMITED makes no representations about the suitability of +this software for any purpose. +It is provided "as is" without express or implied warranty. + +FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. + + Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc. + Takashi Fujiwara FUJITSU LIMITED + fujiwara@a80.tech.yk.fujitsu.co.jp + +******************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include "Xlibint.h" +#include +#include "Xlcint.h" +#include "Ximint.h" +#include "XimTrans.h" +#include "XimTrInt.h" + +#ifdef WIN32 +#include +#endif + + +#ifndef XIM_CONNECTION_RETRIES +#define XIM_CONNECTION_RETRIES 5 +#endif + + +Private Bool +_XimTransConnect( + Xim im) +{ + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + int connect_stat, retry; + Window window; + + for (retry = XIM_CONNECTION_RETRIES; retry >= 0; retry--) + { + if ((spec->trans_conn = _XimXTransOpenCOTSClient ( + spec->address)) == NULL) + { + break; + } + + if ((connect_stat = _XimXTransConnect ( + spec->trans_conn, spec->address)) < 0) + { + _XimXTransClose (spec->trans_conn); + spec->trans_conn = NULL; + + if (connect_stat == TRANS_TRY_CONNECT_AGAIN) + continue; + else + break; + } + else + break; + } + + if (spec->trans_conn == NULL) + return False; + + spec->fd = _XimXTransGetConnectionNumber (spec->trans_conn); + + if (!(window = XCreateSimpleWindow(im->core.display, + DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0))) + return False; + spec->window = window; + + _XRegisterFilterByType(im->core.display, window, KeyPress, KeyPress, + _XimTransFilterWaitEvent, (XPointer)im); + + return _XRegisterInternalConnection(im->core.display, spec->fd, + (_XInternalConnectionProc)_XimTransInternalConnection, + (XPointer)im); +} + + +Private Bool +_XimTransShutdown( + Xim im) +{ + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + + _XimXTransDisconnect(spec->trans_conn); + (void)_XimXTransClose(spec->trans_conn); + _XimFreeTransIntrCallback(im); + _XUnregisterInternalConnection(im->core.display, spec->fd); + _XUnregisterFilter(im->core.display, spec->window, + _XimTransFilterWaitEvent, (XPointer)im); + XDestroyWindow(im->core.display, spec->window); + Xfree(spec->address); + Xfree(spec); + return True; +} + + + +Public Bool +_XimTransRegisterDispatcher( + Xim im, + Bool (*callback)( + Xim, INT16, XPointer, XPointer + ), + XPointer call_data) +{ + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + TransIntrCallbackPtr rec; + + if (!(rec = (TransIntrCallbackPtr)Xmalloc(sizeof(TransIntrCallbackRec)))) + return False; + + rec->func = callback; + rec->call_data = call_data; + rec->next = spec->intr_cb; + spec->intr_cb = rec; + return True; +} + + +Public void +_XimFreeTransIntrCallback( + Xim im) +{ + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + register TransIntrCallbackPtr rec, next; + + for (rec = spec->intr_cb; rec;) { + next = rec->next; + Xfree(rec); + rec = next; + } + return; +} + + +Public Bool +_XimTransCallDispatcher(Xim im, INT16 len, XPointer data) +{ + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + TransIntrCallbackRec *rec; + + for (rec = spec->intr_cb; rec; rec = rec->next) { + if ((*rec->func)(im, len, data, rec->call_data)) + return True; + } + return False; +} + + +Public Bool +_XimTransFilterWaitEvent( + Display *d, + Window w, + XEvent *ev, + XPointer arg) +{ + Xim im = (Xim)arg; + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + + spec->is_putback = False; + return _XimFilterWaitEvent(im); +} + + +Public void +_XimTransInternalConnection( + Display *d, + int fd, + XPointer arg) +{ + Xim im = (Xim)arg; + XEvent ev; + XKeyEvent *kev; + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + + if (spec->is_putback) + return; + kev = (XKeyEvent *)&ev; + kev->type = KeyPress; + kev->send_event = False; + kev->display = im->core.display; + kev->window = spec->window; + kev->keycode = 0; + XPutBackEvent(im->core.display, &ev); + XFlush(im->core.display); + spec->is_putback = True; + return; +} + + +Public Bool +_XimTransWrite(Xim im, INT16 len, XPointer data) +{ + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + char *buf = (char *)data; + register int nbyte; + + while (len > 0) { + if ((nbyte = _XimXTransWrite(spec->trans_conn, buf, len)) <= 0) + return False; + len -= nbyte; + buf += nbyte; + } + return True; +} + + +Public Bool +_XimTransRead( + Xim im, + XPointer recv_buf, + int buf_len, + int *ret_len) +{ + TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; + int len; + + if (buf_len == 0) { + *ret_len = 0; + return True; + } + if ((len = _XimXTransRead(spec->trans_conn, recv_buf, buf_len)) <= 0) + return False; + *ret_len = len; + return True; +} + + +Public void +_XimTransFlush( + Xim im) +{ + return; +} + + + +Public Bool +_XimTransConf( + Xim im, + char *address) +{ + char *paddr; + TransSpecRec *spec; + + if (!(paddr = strdup(address))) + return False; + + if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) { + Xfree(paddr); + return False; + } + + spec->address = paddr; + + im->private.proto.spec = (XPointer)spec; + im->private.proto.connect = _XimTransConnect; + im->private.proto.shutdown = _XimTransShutdown; + im->private.proto.write = _XimTransWrite; + im->private.proto.read = _XimTransRead; + im->private.proto.flush = _XimTransFlush; + im->private.proto.register_dispatcher = _XimTransRegisterDispatcher; + im->private.proto.call_dispatcher = _XimTransCallDispatcher; + + return True; +} -- cgit v1.2.3