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 ++- libX11/modules/lc/gen/lcGenConv.c | 3 +- libX11/modules/lc/xlocale/lcJis.c | 3 +- libX11/modules/om/generic/omGeneric.c | 59 +- libX11/specs/libX11/CH02.xml | 6983 ++++++++++++++++----------------- libX11/src/FSWrap.c | 3 +- libX11/src/InitExt.c | 3 +- libX11/src/Quarks.c | 3 +- libX11/src/SetLocale.c | 3 +- libX11/src/Xrm.c | 6 +- libX11/src/xcms/PrOfId.c | 11 +- libX11/src/xkb/XKBGAlloc.c | 2027 +++++----- libX11/src/xlibi18n/XDefaultIMIF.c | 940 +++-- libX11/src/xlibi18n/XDefaultOMIF.c | 41 +- libX11/src/xlibi18n/XlcDL.c | 1264 +++--- libX11/src/xlibi18n/lcCharSet.c | 3 +- libX11/src/xlibi18n/lcDB.c | 18 +- libX11/src/xlibi18n/lcFile.c | 14 +- libX11/src/xlibi18n/lcGeneric.c | 33 +- libX11/src/xlibi18n/lcPublic.c | 9 +- 27 files changed, 5984 insertions(+), 6144 deletions(-) (limited to 'libX11') 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; +} diff --git a/libX11/modules/lc/gen/lcGenConv.c b/libX11/modules/lc/gen/lcGenConv.c index baac73a39..7a113a78a 100644 --- a/libX11/modules/lc/gen/lcGenConv.c +++ b/libX11/modules/lc/gen/lcGenConv.c @@ -2660,10 +2660,9 @@ create_conv( *conv->methods = *methods; conv->methods->reset = init_state; - conv->state = (XPointer) Xmalloc(sizeof(StateRec)); + conv->state = Xcalloc(1, sizeof(StateRec)); if (conv->state == NULL) goto err; - bzero((char *) conv->state, sizeof(StateRec)); state = (State) conv->state; state->lcd = lcd; diff --git a/libX11/modules/lc/xlocale/lcJis.c b/libX11/modules/lc/xlocale/lcJis.c index 594e6363c..551862d9b 100644 --- a/libX11/modules/lc/xlocale/lcJis.c +++ b/libX11/modules/lc/xlocale/lcJis.c @@ -545,10 +545,9 @@ create_conv( if (XLC_PUBLIC(lcd, is_state_depend)) conv->methods->reset = init_state; - conv->state = (XPointer) Xmalloc(sizeof(StateRec)); + conv->state = Xcalloc(1, sizeof(StateRec)); if (conv->state == NULL) goto err; - bzero((char *) conv->state, sizeof(StateRec)); state = (State) conv->state; state->lcd = lcd; diff --git a/libX11/modules/om/generic/omGeneric.c b/libX11/modules/om/generic/omGeneric.c index 44143ac2e..7f02c8565 100644 --- a/libX11/modules/om/generic/omGeneric.c +++ b/libX11/modules/om/generic/omGeneric.c @@ -523,9 +523,7 @@ get_font_name( if (list == NULL) return NULL; - name = (char *) Xmalloc(strlen(*list) + 1); - if (name) - strcpy(name, *list); + name = strdup(*list); XFreeFontNames(list); @@ -549,10 +547,9 @@ get_rotate_fontname( || len > XLFD_MAX_LEN) return NULL; - pattern = (char *)Xmalloc(len + 1); + pattern = strdup(font_name); if(!pattern) return NULL; - strcpy(pattern, font_name); memset(fields, 0, sizeof(char *) * 14); ptr = pattern; @@ -661,10 +658,8 @@ get_font_name_from_list( for (i = 0; i < count; i++) { fname = list[i]; if(is_match_charset(font_data, fname) == True) { - name = (char *) Xmalloc(strlen(fname) + 1); - if (name) - strcpy(name, fname); - break; + name = strdup(fname); + break; } } @@ -685,11 +680,10 @@ parse_all_name( if(is_match_charset(font_data, pattern) != True) return False; - font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1); + font_data->xlfd_name = strdup(pattern); if(font_data->xlfd_name == NULL) return (-1); - strcpy(font_data->xlfd_name, pattern); return True; #else /* OLDCODE */ Display *dpy = oc->core.om->core.display; @@ -723,11 +717,10 @@ parse_all_name( } } - font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1); + font_data->xlfd_name = strdup(pattern); if(font_data->xlfd_name == NULL) return (-1); - strcpy(font_data->xlfd_name, pattern); return True; #endif /* OLDCODE */ } @@ -946,12 +939,9 @@ parse_fontdata( * -- jjw/pma (HP) */ if (font_data_return) { - font_data_return->xlfd_name = (char *)Xmalloc - (strlen(font_data->xlfd_name) + 1); + font_data_return->xlfd_name = strdup(font_data->xlfd_name); if (!font_data_return->xlfd_name) return -1; - strcpy (font_data_return->xlfd_name, font_data->xlfd_name); - font_data_return->side = font_data->side; } #ifdef FONTDEBUG @@ -996,11 +986,9 @@ parse_fontdata( #ifdef FONTDEBUG fprintf(stderr,"XLFD name: %s\n",font_data->xlfd_name); #endif - font_data_return->xlfd_name = (char *)Xmalloc - (strlen(font_data->xlfd_name) + 1); + font_data_return->xlfd_name = strdup(font_data->xlfd_name); if (!font_data_return->xlfd_name) return -1; - strcpy (font_data_return->xlfd_name, font_data->xlfd_name); font_data_return->side = font_data->side; } @@ -1192,11 +1180,10 @@ parse_fontname( * be matched. It returns the required information in * font_data_return. */ - font_set->font_name = (char *)Xmalloc - (strlen(font_data_return.xlfd_name) + 1); + font_set->font_name = strdup(font_data_return.xlfd_name); if(font_set->font_name == (char *) NULL) goto err; - strcpy(font_set->font_name, font_data_return.xlfd_name); + font_set->side = font_data_return.side; Xfree (font_data_return.xlfd_name); @@ -1223,11 +1210,10 @@ parse_fontname( break; } } - font_set->font_name = (char *)Xmalloc - (strlen(font_set->substitute[i].xlfd_name) + 1); + font_set->font_name = strdup(font_set->substitute[i].xlfd_name); if(font_set->font_name == (char *) NULL) goto err; - strcpy(font_set->font_name,font_set->substitute[i].xlfd_name); + font_set->side = font_set->substitute[i].side; if(parse_vw(oc, font_set, name_list, count) == -1) goto err; @@ -1237,11 +1223,10 @@ parse_fontname( } } - base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1); + base_name = strdup(oc->core.base_name_list); if (base_name == NULL) goto err; - strcpy(base_name, oc->core.base_name_list); oc->core.base_name_list = base_name; XFreeStringList(name_list); @@ -1654,10 +1639,9 @@ create_oc( XOCMethodsList methods_list = oc_methods_list; int count; - oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + oc = Xcalloc(1, sizeof(XOCGenericRec)); if (oc == NULL) return (XOC) NULL; - bzero((char *) oc, sizeof(XOCGenericRec)); oc->core.om = om; @@ -1842,26 +1826,23 @@ create_om( { XOM om; - om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + om = Xcalloc(1, sizeof(XOMGenericRec)); if (om == NULL) return (XOM) NULL; - bzero((char *) om, sizeof(XOMGenericRec)); om->methods = &methods; om->core.lcd = lcd; om->core.display = dpy; om->core.rdb = rdb; if (res_name) { - om->core.res_name = (char *) Xmalloc(strlen(res_name) + 1); + om->core.res_name = strdup(res_name); if (om->core.res_name == NULL) goto err; - strcpy(om->core.res_name, res_name); } if (res_class) { - om->core.res_class = (char *) Xmalloc(strlen(res_class) + 1); + om->core.res_class = strdup(res_class); if (om->core.res_class == NULL) goto err; - strcpy(om->core.res_class, res_class); } if (om_resources[0].xrm_name == NULLQUARK) @@ -1913,10 +1894,9 @@ read_EncodingInfo( FontData font_data,ret; char *buf, *bufptr,*scp; int len; - font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return NULL; - bzero((char *) font_data, sizeof(FontDataRec) * count); ret = font_data; for ( ; count-- > 0; font_data++) { @@ -2017,10 +1997,9 @@ init_om( _XlcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count); if (count > 0) { - gen->object_name = (char *) Xmalloc(strlen(*value) + 1); + gen->object_name = strdup(*value); if (gen->object_name == NULL) return False; - strcpy(gen->object_name, *value); } for (num = 0; ; num++) { diff --git a/libX11/specs/libX11/CH02.xml b/libX11/specs/libX11/CH02.xml index a00b7c283..f4ef1bcd8 100644 --- a/libX11/specs/libX11/CH02.xml +++ b/libX11/specs/libX11/CH02.xml @@ -1,3494 +1,3489 @@ - - - -Display Functions - -Before your program can use a display, you must establish a connection -to the X server. -Once you have established a connection, -you then can use the Xlib macros and functions discussed in this chapter -to return information about the display. -This chapter discusses how to: - - - - -Open (connect to) the display - - - - -Obtain information about the display, image formats, or screens - - - - -Generate a -NoOperation -protocol request - - - - -Free client-created data - - - - -Close (disconnect from) a display - - - - -Use X Server connection close operations - - - - -Use Xlib with threads - - - - -Use internal connections - - - - -Opening the Display - - - - - -To open a connection to the X server that controls a display, use -XOpenDisplay. -XOpenDisplay - - - - - - -AllPlanes() - - -XAllPlanes - - - - - - display_name - - - -Specifies the hardware display name, which determines the display -and communications domain to be used. -On a POSIX-conformant system, if the display_name is NULL, -it defaults to the value of the DISPLAY environment variable. -EnvironmentDISPLAY - - - - - - - -The encoding and interpretation of the display name are -implementation-dependent. -Strings in the Host Portable Character Encoding are supported; -support for other characters is implementation-dependent. -On POSIX-conformant systems, -the display name or DISPLAY environment variable can be a string in the format: - - - - - - - protocol/hostname:number.screen_number - - - - - protocol - - - -Specifies a protocol family or an alias for a protocol family. Supported -protocol families are implementation dependent. The protocol entry is -optional. If protocol is not specified, the / separating protocol and -hostname must also not be specified. - - - - - - hostname - - - -Specifies the name of the host machine on which the display is physically -attached. -You follow the hostname with either a single colon (:) or a double colon (::). - - - - - - number - - - -Specifies the number of the display server on that host machine. -You may optionally follow this display number with a period (.). -A single CPU can have more than one display. -Multiple displays are usually numbered starting with zero. -Screen - - - - - - screen_number - - - -Specifies the screen to be used on that server. -Multiple screens can be controlled by a single X server. -The screen_number sets an internal variable that can be accessed by -using the -DefaultScreen -macro or the -XDefaultScreen -function if you are using languages other than C (see section 2.2.1). - - - - - - - -For example, the following would specify screen 1 of display 0 on the -machine named ``dual-headed'': - - - - -dual-headed:0.1 - - - - -The -XOpenDisplay -function returns a -Display -structure that serves as the -connection to the X server and that contains all the information -about that X server. -XOpenDisplay -connects your application to the X server through TCP -or DECnet communications protocols, -or through some local inter-process communication protocol. -ProtocolTCP -ProtocolDECnet -If the protocol is specified as "tcp", "inet", or "inet6", or -if no protocol is specified and the hostname is a host machine name and a single colon (:) -separates the hostname and display number, -XOpenDisplay -connects using TCP streams. (If the protocol is specified as "inet", TCP over -IPv4 is used. If the protocol is specified as "inet6", TCP over IPv6 is used. -Otherwise, the implementation determines which IP version is used.) -If the hostname and protocol are both not specified, -Xlib uses whatever it believes is the fastest transport. -If the hostname is a host machine name and a double colon (::) -separates the hostname and display number, -XOpenDisplay -connects using DECnet. -A single X server can support any or all of these transport mechanisms -simultaneously. -A particular Xlib implementation can support many more of these transport -mechanisms. - - - -Display -If successful, -XOpenDisplay -returns a pointer to a -Display -structure, -which is defined in -<X11/Xlib.h>. -X11/Xlib.h -Files<X11/Xlib.h> -Headers<X11/Xlib.h> -If -XOpenDisplay -does not succeed, it returns NULL. -After a successful call to -XOpenDisplay, -all of the screens in the display can be used by the client. -The screen number specified in the display_name argument is returned -by the -DefaultScreen -macro (or the -XDefaultScreen -function). -You can access elements of the -Display -and -Screen -structures only by using the information macros or functions. -For information about using macros and functions to obtain information from -the -Display -structure, -see section 2.2.1. - - - -X servers may implement various types of access control mechanisms -(see section 9.8). - - - -Obtaining Information about the Display, Image Formats, or Screens - - - - - -The Xlib library provides a number of useful macros -and corresponding functions that return data from the -Display -structure. -The macros are used for C programming, -and their corresponding function equivalents are for other language bindings. -This section discusses the: - - - - -Display macros - - - - -Image format functions and macros - - - - -Screen information macros - - - - - -Displaydata structure -All other members of the -Display -structure (that is, those for which no macros are defined) are private to Xlib -and must not be used. -Applications must never directly modify or inspect these private members of the -Display -structure. - -The -XDisplayWidth, -XDisplayHeight, -XDisplayCells, -XDisplayPlanes, -XDisplayWidthMM, -and -XDisplayHeightMM -functions in the next sections are misnamed. -These functions really should be named Screenwhatever -and XScreenwhatever, not Displaywhatever or XDisplaywhatever. -Our apologies for the resulting confusion. - - - -Display Macros - - - - - -Applications should not directly modify any part of the -Display -and -Screen -structures. -The members should be considered read-only, -although they may change as the result of other operations on the display. - - - -The following lists the C language macros, -their corresponding function equivalents that are for other language bindings, -and what data both can return. - -AllPlanes() -XAllPlanes() - - - -AllPlanes -XAllPlanes -Both return a value with all bits set to 1 suitable for use in a plane argument to -a procedure. - - - - -Both -BlackPixel -and -WhitePixel -can be used in implementing a monochrome application. -These pixel values are for permanently allocated entries in the default -colormap. -The actual RGB (red, green, and blue) values are settable on some screens -and, in any case, may not actually be black or white. -The names are intended to convey the expected relative intensity of the colors. - - - -BlackPixel(display, screen_number) - - - - unsigned long XBlackPixel - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -BlackPixel -XBlackPixel -Both return the black pixel value for the specified screen. - - - - - - - -WhitePixel(display, screen_number) - - - - unsigned long XWhitePixel - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -WhitePixel -XWhitePixel -Both return the white pixel value for the specified screen. - - - - - - - -ConnectionNumber(display) - - - - int XConnectionNumber - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - - -ConnectionNumber -XConnectionNumber -Both return a connection number for the specified display. -On a POSIX-conformant system, -this is the file descriptor of the connection. - - - - - - - -DefaultColormap(display, screen_number) - - - - Colormap XDefaultColormap - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DefaultColormap -XDefaultColormap -Both return the default colormap ID for allocation on the specified screen. -Most routine allocations of color should be made out of this colormap. - - - - - - - -DefaultDepth(display, screen_number) - - - - int XDefaultDepth - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DefaultDepth -XDefaultDepth -Both return the depth (number of planes) of the default root window for the -specified screen. -Other depths may also be supported on this screen (see -XMatchVisualInfo). - - - - -XListDepths -To determine the number of depths that are available on a given screen, use -XListDepths. - - - -DefaultGC(display, screen_number) - - - - GC XDefaultGC - Display *display - int screen_number - int *count_return - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - count_return - - - -Returns the number of (Cn. - - - - - - - -The -XListDepths -function returns the array of depths -that are available on the specified screen. -If the specified screen_number is valid and sufficient memory for the array -can be allocated, -XListDepths -sets count_return to the number of available depths. -Otherwise, it does not set count_return and returns NULL. -To release the memory allocated for the array of depths, use -XFree. - - - - - - - -DefaultGC(display, screen_number) - - - - GC XDefaultGC - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DefaultGC -XDefaultGC -Both return the default graphics context for the root window of the -specified screen. -This GC is created for the convenience of simple applications -and contains the default GC components with the foreground and -background pixel values initialized to the black and white -pixels for the screen, respectively. -You can modify its contents freely because it is not used in any Xlib -function. -This GC should never be freed. - - - - - - - -DefaultRootWindow(display) - - - - Window XDefaultRootWindow - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -DefaultRootWindow -XDefaultRootWindow -Both return the root window for the default screen. - - - - - - - -DefaultScreenOfDisplay(display) - - - - Screen *XDefaultScreenOfDisplay - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -DefaultScreenOfDisplay -XDefaultScreenOfDisplay -Both return a pointer to the default screen. - - - - - - - -ScreenOfDisplay(display, screen_number) - - - - Screen *XScreenOfDisplay - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -ScreenOfDisplay -XScreenOfDisplay -Both return a pointer to the indicated screen. - - - - - - - -DefaultScreen(display) - - - - int XDefaultScreen - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -DefaultScreen -XDefaultScreen -Both return the default screen number referenced by the -XOpenDisplay -function. -This macro or function should be used to retrieve the screen number -in applications that will use only a single screen. - - - - - - - -DefaultVisual(display, screen_number) - - - - Visual *XDefaultVisual - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DefaultVisual -XDefaultVisual -Both return the default visual type for the specified screen. -For further information about visual types, -see section 3.1. - - - - - - - -DisplayCells(display, screen_number) - - - - int XDisplayCells - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DisplayCells -XDisplayCells -Both return the number of entries in the default colormap. - - - - - - - -DisplayPlanes(display, screen_number) - - - - int XDisplayPlanes - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DisplayPlanes -XDisplayPlanes -Both return the depth of the root window of the specified screen. -For an explanation of depth, -see the glossary. - - - - - - - -DisplayString(display) - - - - char *XDisplayString - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -DisplayString -XDisplayString -Both return the string that was passed to -XOpenDisplay -when the current display was opened. -On POSIX-conformant systems, -if the passed string was NULL, these return the value of -the DISPLAY environment variable when the current display was opened. -POSIX System Callfork -These are useful to applications that invoke the -fork -system call and want to open a new connection to the same display from the -child process as well as for printing error messages. - - - - - - - -LastKnownRequestProcessed(display) - - - - unsigned long XLastKnownRequestProcessed - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -XExtendedMaxRequestSize -The -XExtendedMaxRequestSize -function returns zero if the specified display does not support an -extended-length protocol encoding; otherwise, -it returns the maximum request size (in 4-byte units) supported -by the server using the extended-length encoding. -The Xlib functions -XDrawLines, -XDrawArcs, -XFillPolygon, -XChangeProperty, -XSetClipRectangles, -and -XSetRegion -will use the extended-length encoding as necessary, if supported -by the server. Use of the extended-length encoding in other Xlib -functions (for example, -XDrawPoints, -XDrawRectangles, -XDrawSegments, -XFillArcs, -XFillRectangles, -XPutImage) -is permitted but not required; an Xlib implementation may choose to -split the data across multiple smaller requests instead. - - - - - - - -LastKnownRequestProcessed(display) - - - - unsigned long XLastKnownRequestProcessed - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -XMaxRequestSize -The -XMaxRequestSize -function returns the maximum request size (in 4-byte units) supported -by the server without using an extended-length protocol encoding. -Single protocol requests to the server can be no larger than this size -unless an extended-length protocol encoding is supported by the server. -The protocol guarantees the size to be no smaller than 4096 units -(16384 bytes). -Xlib automatically breaks data up into multiple protocol requests -as necessary for the following functions: -XDrawPoints, -XDrawRectangles, -XDrawSegments, -XFillArcs, -XFillRectangles, -and -XPutImage. - - - - - - - -LastKnownRequestProcessed(display) - - - - unsigned long XLastKnownRequestProcessed - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -LastKnownRequestProcessed -XLastKnownRequestProcessed -Both extract the full serial number of the last request known by Xlib -to have been processed by the X server. -Xlib automatically sets this number when replies, events, and errors -are received. - - - - - - - -NextRequest(display) - - - - unsigned long XNextRequest - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -NextRequest -XNextRequest -Both extract the full serial number that is to be used for the next -request. -Serial numbers are maintained separately for each display connection. - - - - - - - -ProtocolVersion(display) - - - - int XProtocolVersion - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -ProtocolVersion -XProtocolVersion -Both return the major version number (11) of the X protocol associated with -the connected display. - - - - - - - -ProtocolRevision(display) - - - - int XProtocolRevision - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -ProtocolRevision -XProtocolRevision -Both return the minor protocol revision number of the X server. - - - - - - - -QLength(display) - - - - int XQLength - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -QLength -XQLength -Both return the length of the event queue for the connected display. -Note that there may be more events that have not been read into -the queue yet (see -XEventsQueued). - - - - - - - -RootWindow(display, screen_number) - - - - Window XRootWindow - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -WindowRootWindow -RootWindow -WindowXRootWindow -XRootWindow -Both return the root window. -These are useful with functions that need a drawable of a particular screen -and for creating top-level windows. - - - - - - - -ScreenCount(display) - - - - int XScreenCount - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -ScreenCount -XScreenCount -Both return the number of available screens. - - - - - - - -ServerVendor(display) - - - - char *XServerVendor - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -ServerVendor -XServerVendor -Both return a pointer to a null-terminated string that provides -some identification of the owner of the X server implementation. -If the data returned by the server is in the Latin Portable Character Encoding, -then the string is in the Host Portable Character Encoding. -Otherwise, the contents of the string are implementation-dependent. - - - - - - - -VendorRelease(display) - - - - int XVendorRelease - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -VendorRelease -XVendorRelease -Both return a number related to a vendor's release of the X server. - - - -Image Format Functions and Macros - - - - - -Applications are required to present data to the X server -in a format that the server demands. -To help simplify applications, -most of the work required to convert the data is provided by Xlib -(see sections 8.7 and 16.8). - - - -The -XPixmapFormatValues -structure provides an interface to the pixmap format information -that is returned at the time of a connection setup. -It contains: - - - - - - - -typedef struct { - int depth; - int bits_per_pixel; - int scanline_pad; -} XPixmapFormatValues; - - - - - - -To obtain the pixmap format information for a given display, use -XListPixmapFormats. -XListPixmapFormats - - - -ImageByteOrder(display) - - - - int XImageByteOrder - Display *display - int *count_return - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - count_return - - - -Returns the number of (Cn. - - - - - - - -The -XListPixmapFormats -function returns an array of -XPixmapFormatValues -structures that describe the types of Z format images supported -by the specified display. -If insufficient memory is available, -XListPixmapFormats -returns NULL. -To free the allocated storage for the -XPixmapFormatValues -structures, use -XFree. - - - -The following lists the C language macros, -their corresponding function equivalents that are for other language bindings, -and what data they both return for the specified server and screen. -These are often used by toolkits as well as by simple applications. - - - - - - - -ImageByteOrder(display) - - - - int XImageByteOrder - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -ImageByteOrder -XImageByteOrder -Both specify the required byte order for images for each scanline unit in -XY format (bitmap) or for each pixel value in -Z format. -The macro or function can return either -LSBFirst -or -MSBFirst. - - - - - - - -BitmapUnit(display) - - - - int XBitmapUnit - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -BitmapUnit -XBitmapUnit -Both return the size of a bitmap's scanline unit in bits. -The scanline is calculated in multiples of this value. - - - - - - - -BitmapBitOrder(display) - - - - int XBitmapBitOrder - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -BitmapBitOrder -XBitmapBitOrder -Within each bitmap unit, the left-most bit in the bitmap as displayed -on the screen is either the least significant or most significant bit in the -unit. -This macro or function can return -LSBFirst -or -MSBFirst. - - - - - - - -BitmapPad(display) - - - - int XBitmapPad - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -BitmapPad -XBitmapPad -Each scanline must be padded to a multiple of bits returned -by this macro or function. - - - - - - - -DisplayHeight(display, screen_number) - - - - int XDisplayHeight - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DisplayHeight -XDisplayHeight -Both return an integer that describes the height of the screen -in pixels. - - - - - - - -DisplayHeightMM(display, screen_number) - - - - int XDisplayHeightMM - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DisplayHeightMM -XDisplayHeightMM -Both return the height of the specified screen in millimeters. - - - - - - - -DisplayWidth(display, screen_number) - - - - int XDisplayWidth - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DisplayWidth -XDisplayWidth -Both return the width of the screen in pixels. - - - - - - - -DisplayWidthMM(display, screen_number) - - - - int XDisplayWidthMM - Display *display - int screen_number - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - screen_number - - - -Specifies the appropriate screen number on the host server. - - - - - - - -DisplayWidthMM -XDisplayWidthMM -Both return the width of the specified screen in millimeters. - - - -Screen Information Macros - - - - - -The following lists the C language macros, -their corresponding function equivalents that are for other language bindings, -and what data they both can return. -These macros or functions all take a pointer to the appropriate screen -structure. - - - - - - - -BlackPixelOfScreen(screen) - - - - unsigned long XBlackPixelOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -BlackPixelOfScreen -XBlackPixelOfScreen -Both return the black pixel value of the specified screen. - - - - - - - -WhitePixelOfScreen(screen) - - - - unsigned long XWhitePixelOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -WhitePixelOfScreen -XWhitePixelOfScreen -Both return the white pixel value of the specified screen. - - - - - - - -CellsOfScreen(screen) - - - - int XCellsOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -CellsOfScreen -XCellsOfScreen -Both return the number of colormap cells in the default colormap -of the specified screen. - - - - - - - -DefaultColormapOfScreen(screen) - - - - Colormap XDefaultColormapOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -DefaultColormapOfScreen -XDefaultColormapOfScreen -Both return the default colormap of the specified screen. - - - - - - - -DefaultDepthOfScreen(screen) - - - - int XDefaultDepthOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -DefaultDepthOfScreen -XDefaultDepthOfScreen -Both return the depth of the root window. - - - - - - - -DefaultGCOfScreen(screen) - - - - GC XDefaultGCOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -DefaultGCOfScreen -XDefaultGCOfScreen -Both return a default graphics context (GC) of the specified screen, -which has the same depth as the root window of the screen. -The GC must never be freed. - - - - - - - -DefaultVisualOfScreen(screen) - - - - Visual *XDefaultVisualOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -DefaultVisualOfScreen -XDefaultVisualOfScreen -Both return the default visual of the specified screen. -For information on visual types, -see section 3.1. - - - - - - - -DoesBackingStore(screen) - - - - int XDoesBackingStore - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -DoesBackingStore -XDoesBackingStore -Both return a value indicating whether the screen supports backing -stores. -The value returned can be one of -WhenMapped, -NotUseful, -or -Always -(see section 3.2.4). - - - - - - - -DoesSaveUnders(screen) - - - - Bool XDoesSaveUnders - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -DoesSaveUnders -XDoesSaveUnders -Both return a Boolean value indicating whether the -screen supports save unders. -If -True, -the screen supports save unders. -If -False, -the screen does not support save unders (see section 3.2.5). - - - - - - - -DisplayOfScreen(screen) - - - - Display *XDisplayOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -DisplayOfScreen -XDisplayOfScreen -Both return the display of the specified screen. - - - - - -XScreenNumberOfScreen - - -EventMaskOfScreen(screen) - - - - long XEventMaskOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -The -XScreenNumberOfScreen -function returns the screen index number of the specified screen. - - - - - - - -EventMaskOfScreen(screen) - - - - long XEventMaskOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -EventMaskOfScreen -XEventMaskOfScreen -Both return the event mask of the root window for the specified screen -at connection setup time. - - - - - - - -WidthOfScreen(screen) - - - - int XWidthOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -WidthOfScreen -XWidthOfScreen -Both return the width of the specified screen in pixels. - - - - - - - -HeightOfScreen(screen) - - - - int XHeightOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -HeightOfScreen -XHeightOfScreen -Both return the height of the specified screen in pixels. - - - - - - - -WidthMMOfScreen(screen) - - - - int XWidthMMOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -WidthMMOfScreen -XWidthMMOfScreen -Both return the width of the specified screen in millimeters. - - - - - - - -HeightMMOfScreen(screen) - - - - int XHeightMMOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -HeightMMOfScreen -XHeightMMOfScreen -Both return the height of the specified screen in millimeters. - - - - - - - -MaxCmapsOfScreen(screen) - - - - int XMaxCmapsOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -MaxCmapsOfScreen -XMaxCmapsOfScreen -Both return the maximum number of installed colormaps supported -by the specified screen (see section 9.3). - - - - - - - -MinCmapsOfScreen(screen) - - - - int XMinCmapsOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -MinCmapsOfScreen -XMinCmapsOfScreen -Both return the minimum number of installed colormaps supported -by the specified screen (see section 9.3). - - - - - - - -PlanesOfScreen(screen) - - - - int XPlanesOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -PlanesOfScreen -XPlanesOfScreen -Both return the depth of the root window. - - - - - - - -RootWindowOfScreen(screen) - - - - Window XRootWindowOfScreen - Screen *screen - - - - - - - screen - - - -Specifies the appropriate -Screen -structure. - - - - - - - -RootWindowOfScreen -XRootWindowOfScreen -Both return the root window of the specified screen. - - - - -Generating a NoOperation Protocol Request - - - - - -To execute a -NoOperation -protocol request, use -XNoOp. -XNoOp - - - - - XNoOp - Display *display - - - - - - display - - Specifies the connection to the X server. - - - - - - -The -XNoOp -function sends a -NoOperation -protocol request to the X server, -thereby exercising the connection. - - - -Freeing Client-Created Data - - - - - -To free in-memory data that was created by an Xlib function, use -XFree. -XFree - - - - - XFree - void *data - - - - - - - - data - - - -Specifies the data that is to be freed. - - - - - - - -The -XFree -function is a general-purpose Xlib routine that frees the specified data. -You must use it to free any objects that were allocated by Xlib, -unless an alternate function is explicitly specified for the object. -A NULL pointer cannot be passed to this function. - - - -Closing the Display - - - - - -To close a display or disconnect from the X server, use -XCloseDisplay. -XCloseDisplay - - - - - - - - XCloseDisplay - Display *display - - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -The -XCloseDisplay -function closes the connection to the X server for the display specified in the -Display -structure and destroys all windows, resource IDs -(Window, -Font, -Pixmap, -Colormap, -Cursor, -and -GContext), -or other resources that the client has created -on this display, unless the close-down mode of the resource has been changed -(see -XSetCloseDownMode). -Therefore, these windows, resource IDs, and other resources should never be -referenced again or an error will be generated. -Before exiting, you should call -XCloseDisplay -explicitly so that any pending errors are reported as -XCloseDisplay -performs a final -XSync -operation. -Resource IDs -XCloseDisplay - - - -XCloseDisplay -can generate a -BadGC -error. - - - - -Xlib provides a function to permit the resources owned by a client -to survive after the client's connection is closed. -To change a client's close-down mode, use -XSetCloseDownMode. -XSetCloseDownMode - - - - - XSetCloseDownMode - Display *display - int close_mode - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - close_mode - - - -Specifies the client close-down mode. -You can pass -DestroyAll, -RetainPermanent, -or -RetainTemporary. - - - - - - - -The -XSetCloseDownMode -defines what will happen to the client's resources at connection close. -A connection starts in -DestroyAll -mode. -For information on what happens to the client's resources when the -close_mode argument is -RetainPermanent -or -RetainTemporary, -see section 2.6. - - - -XSetCloseDownMode -can generate a -BadValue -error. - - - -Using X Server Connection Close Operations - - - - - -When the X server's connection to a client is closed -either by an explicit call to -XCloseDisplay -or by a process that exits, the X server performs the following -automatic operations: - - - - -It disowns all selections owned by the client -(see -XSetSelectionOwner). - - - - -It performs an -XUngrabPointer -and -XUngrabKeyboard -if the client has actively grabbed the pointer -or the keyboard. - - - - -It performs an -XUngrabServer -if the client has grabbed the server. - - - - -It releases all passive grabs made by the client. - - - - -It marks all resources (including colormap entries) allocated -by the client either as permanent or temporary, -depending on whether the close-down mode is -RetainPermanent -or -RetainTemporary. -However, this does not prevent other client applications from explicitly -destroying the resources (see -XSetCloseDownMode). - - - - - -When the close-down mode is -DestroyAll, -the X server destroys all of a client's resources as follows: - - - - -It examines each window in the client's save-set to determine if it is an inferior -(subwindow) of a window created by the client. -(The save-set is a list of other clients' windows -that are referred to as save-set windows.) -If so, the X server reparents the save-set window to the closest ancestor so -that the save-set window is not an inferior of a window created by the client. -The reparenting leaves unchanged the absolute coordinates (with respect to -the root window) of the upper-left outer corner of the save-set -window. - - - - -It performs a -MapWindow -request on the save-set window if the save-set window is unmapped. -The X server does this even if the save-set window was not an inferior of -a window created by the client. - - - - -It destroys all windows created by the client. - - - - -It performs the appropriate free request on each nonwindow resource created by -the client in the server (for example, -Font, -Pixmap, -Cursor, -Colormap, -and -GContext). - - - - -It frees all colors and colormap entries allocated by a client application. - - - - - -Additional processing occurs when the last connection to the X server closes. -An X server goes through a cycle of having no connections and having some -connections. -When the last connection to the X server closes as a result of a connection -closing with the close_mode of -DestroyAll, -the X server does the following: - - - - -It resets its state as if it had just been -started. -The X server begins by destroying all lingering resources from -clients that have terminated in -RetainPermanent -or -RetainTemporary -mode. - - - - -It deletes all but the predefined atom identifiers. - - - - -It deletes all properties on all root windows (see section 4.3). - - - - -It resets all device maps and attributes -(for example, key click, bell volume, and acceleration) -as well as the access control list. - - - - -It restores the standard root tiles and cursors. - - - - -It restores the default font path. - - - - -It restores the input focus to state -PointerRoot. - - - - - -However, the X server does not reset if you close a connection with a close-down -mode set to -RetainPermanent -or -RetainTemporary. - - - -Using Xlib with Threads - - - - - -On systems that have threads, support may be provided to permit -multiple threads to use Xlib concurrently. - - - - -To initialize support for concurrent threads, use -XInitThreads. -XInitThreads - - -Status XInitThreads(); - - - - -The -XInitThreads -function initializes Xlib support for concurrent threads. -This function must be the first Xlib function a -multi-threaded program calls, and it must complete -before any other Xlib call is made. -This function returns a nonzero status if initialization was -successful; otherwise, it returns zero. -On systems that do not support threads, this function always returns zero. - - - -It is only necessary to call this function if multiple threads -might use Xlib concurrently. If all calls to Xlib functions -are protected by some other access mechanism (for example, -a mutual exclusion lock in a toolkit or through explicit client -programming), Xlib thread initialization is not required. -It is recommended that single-threaded programs not call this function. - - - - - -To lock a display across several Xlib calls, use -XLockDisplay. -XLockDisplay - - - - - XLockDisplay - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -The -XLockDisplay -function locks out all other threads from using the specified display. -Other threads attempting to use the display will block until -the display is unlocked by this thread. -Nested calls to -XLockDisplay -work correctly; the display will not actually be unlocked until -XUnlockDisplay -has been called the same number of times as -XLockDisplay. -This function has no effect unless Xlib was successfully initialized -for threads using -XInitThreads. - - - - -To unlock a display, use -XUnlockDisplay. -XUnlockDisplay - - - - - XUnlockDisplay - Display *display - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - - -The -XUnlockDisplay -function allows other threads to use the specified display again. -Any threads that have blocked on the display are allowed to continue. -Nested locking works correctly; if -XLockDisplay -has been called multiple times by a thread, then -XUnlockDisplay -must be called an equal number of times before the display is -actually unlocked. -This function has no effect unless Xlib was successfully initialized -for threads using -XInitThreads. - - - -Using Internal Connections - - - - - -In addition to the connection to the X server, an Xlib implementation -may require connections to other kinds of servers (for example, to -input method servers as described in chapter 13). Toolkits and clients -that use multiple displays, or that use displays in combination with -other inputs, need to obtain these additional connections to correctly -block until input is available and need to process that input -when it is available. Simple clients that use a single display and -block for input in an Xlib event function do not need to use these -facilities. - - - -To track internal connections for a display, use -XAddConnectionWatch. - - - - type void XConnectionWatchProc - Display *display - XPointer client_data - int fd - Bool opening - XPointer *watch_data - - - - - - Status XAddConnectionWatch - Display *display - XWatchProc procedure - XPointer client_data - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - procedure - - - -Specifies the procedure to be called. - - - - - - client_data - - - -Specifies the additional client data. - - - - - - - -The -XAddConnectionWatch -function registers a procedure to be called each time Xlib opens or closes an -internal connection for the specified display. The procedure is passed the -display, the specified client_data, the file descriptor for the connection, -a Boolean indicating whether the connection is being opened or closed, and a -pointer to a location for private watch data. If opening is -True, -the procedure can store a pointer to private data in the location pointed -to by watch_data; -when the procedure is later called for this same connection and opening is -False, -the location pointed to by watch_data will hold this same private data pointer. - - - -This function can be called at any time after a display is opened. -If internal connections already exist, the registered procedure will -immediately be called for each of them, before -XAddConnectionWatch -returns. -XAddConnectionWatch -returns a nonzero status if the procedure is successfully registered; -otherwise, it returns zero. - - - -The registered procedure should not call any Xlib functions. -If the procedure directly or indirectly causes the state of internal -connections or watch procedures to change, the result is not defined. -If Xlib has been initialized for threads, the procedure is called with -the display locked and the result of a call by the procedure to any -Xlib function that locks the display is not defined unless the executing -thread has externally locked the display using -XLockDisplay. - - - - -To stop tracking internal connections for a display, use -XRemoveConnectionWatch. -XRemoveConnectionWatch - - - -() - - - - Status XRemoveConnectionWatch - Display *display - XWatchProc procedure - XPointer client_data - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - procedure - - - -Specifies the procedure to be called. - - - - - - client_data - - - -Specifies the additional client data. - - - - - - - -The -XRemoveConnectionWatch -function removes a previously registered connection watch procedure. -The client_data must match the client_data used when the procedure -was initially registered. - - - - - -To process input on an internal connection, use -XProcessInternalConnection. -XProcessInternalConnection - - - -() - - - - void XProcessInternalConnection - Display *display - int fd - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - fd - - - -Specifies the file descriptor. - - - - - - - -The -XProcessInternalConnection -function processes input available on an internal connection. -This function should be called for an internal connection only -after an operating system facility (for example, -select -or -poll) -has indicated that input is available; otherwise, -the effect is not defined. - - - - -To obtain all of the current internal connections for a display, use -XInternalConnectionNumbers. -XInternalConnectionNumbers - - - -() - - - - Status XInternalConnectionNumbers - Display *display - int ** fd - int * count_return - - - - - - - display - - - -Specifies the connection to the X server. - - - - - - fd_return - - - -Returns the file descriptors. - - - - - - - count_return - - - -Returns the number of (Cn. - - - - - - - -The -XInternalConnectionNumbers -function returns a list of the file descriptors for all internal -connections currently open for the specified display. -When the allocated list is no longer needed, -free it by using -XFree. -This functions returns a nonzero status if the list is successfully allocated; -otherwise, it returns zero. - - - + + + +Display Functions + +Before your program can use a display, you must establish a connection +to the X server. +Once you have established a connection, +you then can use the Xlib macros and functions discussed in this chapter +to return information about the display. +This chapter discusses how to: + + + + +Open (connect to) the display + + + + +Obtain information about the display, image formats, or screens + + + + +Generate a +NoOperation +protocol request + + + + +Free client-created data + + + + +Close (disconnect from) a display + + + + +Use X Server connection close operations + + + + +Use Xlib with threads + + + + +Use internal connections + + + + +Opening the Display + + + + + +To open a connection to the X server that controls a display, use +XOpenDisplay. +XOpenDisplay + + + + Display *XOpenDisplay + char *display_name + + + + + + display_name + + + +Specifies the hardware display name, which determines the display +and communications domain to be used. +On a POSIX-conformant system, if the display_name is NULL, +it defaults to the value of the DISPLAY environment variable. +EnvironmentDISPLAY + + + + + + + +The encoding and interpretation of the display name are +implementation-dependent. +Strings in the Host Portable Character Encoding are supported; +support for other characters is implementation-dependent. +On POSIX-conformant systems, +the display name or DISPLAY environment variable can be a string in the format: + + + + + + + protocol/hostname:number.screen_number + + + + + protocol + + + +Specifies a protocol family or an alias for a protocol family. Supported +protocol families are implementation dependent. The protocol entry is +optional. If protocol is not specified, the / separating protocol and +hostname must also not be specified. + + + + + + hostname + + + +Specifies the name of the host machine on which the display is physically +attached. +You follow the hostname with either a single colon (:) or a double colon (::). + + + + + + number + + + +Specifies the number of the display server on that host machine. +You may optionally follow this display number with a period (.). +A single CPU can have more than one display. +Multiple displays are usually numbered starting with zero. +Screen + + + + + + screen_number + + + +Specifies the screen to be used on that server. +Multiple screens can be controlled by a single X server. +The screen_number sets an internal variable that can be accessed by +using the +DefaultScreen +macro or the +XDefaultScreen +function if you are using languages other than C (see section 2.2.1). + + + + + + + +For example, the following would specify screen 1 of display 0 on the +machine named ``dual-headed'': + + + + +dual-headed:0.1 + + + + +The +XOpenDisplay +function returns a +Display +structure that serves as the +connection to the X server and that contains all the information +about that X server. +XOpenDisplay +connects your application to the X server through TCP +or DECnet communications protocols, +or through some local inter-process communication protocol. +ProtocolTCP +ProtocolDECnet +If the protocol is specified as "tcp", "inet", or "inet6", or +if no protocol is specified and the hostname is a host machine name and a single colon (:) +separates the hostname and display number, +XOpenDisplay +connects using TCP streams. (If the protocol is specified as "inet", TCP over +IPv4 is used. If the protocol is specified as "inet6", TCP over IPv6 is used. +Otherwise, the implementation determines which IP version is used.) +If the hostname and protocol are both not specified, +Xlib uses whatever it believes is the fastest transport. +If the hostname is a host machine name and a double colon (::) +separates the hostname and display number, +XOpenDisplay +connects using DECnet. +A single X server can support any or all of these transport mechanisms +simultaneously. +A particular Xlib implementation can support many more of these transport +mechanisms. + + + +Display +If successful, +XOpenDisplay +returns a pointer to a +Display +structure, +which is defined in +<X11/Xlib.h>. +X11/Xlib.h +Files<X11/Xlib.h> +Headers<X11/Xlib.h> +If +XOpenDisplay +does not succeed, it returns NULL. +After a successful call to +XOpenDisplay, +all of the screens in the display can be used by the client. +The screen number specified in the display_name argument is returned +by the +DefaultScreen +macro (or the +XDefaultScreen +function). +You can access elements of the +Display +and +Screen +structures only by using the information macros or functions. +For information about using macros and functions to obtain information from +the +Display +structure, +see section 2.2.1. + + + +X servers may implement various types of access control mechanisms +(see section 9.8). + + + +Obtaining Information about the Display, Image Formats, or Screens + + + + + +The Xlib library provides a number of useful macros +and corresponding functions that return data from the +Display +structure. +The macros are used for C programming, +and their corresponding function equivalents are for other language bindings. +This section discusses the: + + + + +Display macros + + + + +Image format functions and macros + + + + +Screen information macros + + + + + +Displaydata structure +All other members of the +Display +structure (that is, those for which no macros are defined) are private to Xlib +and must not be used. +Applications must never directly modify or inspect these private members of the +Display +structure. + +The +XDisplayWidth, +XDisplayHeight, +XDisplayCells, +XDisplayPlanes, +XDisplayWidthMM, +and +XDisplayHeightMM +functions in the next sections are misnamed. +These functions really should be named Screenwhatever +and XScreenwhatever, not Displaywhatever or XDisplaywhatever. +Our apologies for the resulting confusion. + + + +Display Macros + + + + + +Applications should not directly modify any part of the +Display +and +Screen +structures. +The members should be considered read-only, +although they may change as the result of other operations on the display. + + + +The following lists the C language macros, +their corresponding function equivalents that are for other language bindings, +and what data both can return. + +AllPlanes() +XAllPlanes() + + + +AllPlanes +XAllPlanes +Both return a value with all bits set to 1 suitable for use in a plane argument to +a procedure. + + + + +Both +BlackPixel +and +WhitePixel +can be used in implementing a monochrome application. +These pixel values are for permanently allocated entries in the default +colormap. +The actual RGB (red, green, and blue) values are settable on some screens +and, in any case, may not actually be black or white. +The names are intended to convey the expected relative intensity of the colors. + + + +BlackPixel(display, screen_number) + + + + unsigned long XBlackPixel + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +BlackPixel +XBlackPixel +Both return the black pixel value for the specified screen. + + + + + + + +WhitePixel(display, screen_number) + + + + unsigned long XWhitePixel + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +WhitePixel +XWhitePixel +Both return the white pixel value for the specified screen. + + + + + + + +ConnectionNumber(display) + + + + int XConnectionNumber + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + + +ConnectionNumber +XConnectionNumber +Both return a connection number for the specified display. +On a POSIX-conformant system, +this is the file descriptor of the connection. + + + + + + + +DefaultColormap(display, screen_number) + + + + Colormap XDefaultColormap + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DefaultColormap +XDefaultColormap +Both return the default colormap ID for allocation on the specified screen. +Most routine allocations of color should be made out of this colormap. + + + + + + + +DefaultDepth(display, screen_number) + + + + int XDefaultDepth + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DefaultDepth +XDefaultDepth +Both return the depth (number of planes) of the default root window for the +specified screen. +Other depths may also be supported on this screen (see +XMatchVisualInfo). + + + + +XListDepths +To determine the number of depths that are available on a given screen, use +XListDepths. + + + +DefaultGC(display, screen_number) + + + + GC XDefaultGC + Display *display + int screen_number + int *count_return + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + count_return + + + +Returns the number of (Cn. + + + + + + + +The +XListDepths +function returns the array of depths +that are available on the specified screen. +If the specified screen_number is valid and sufficient memory for the array +can be allocated, +XListDepths +sets count_return to the number of available depths. +Otherwise, it does not set count_return and returns NULL. +To release the memory allocated for the array of depths, use +XFree. + + + + + + + +DefaultGC(display, screen_number) + + + + GC XDefaultGC + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DefaultGC +XDefaultGC +Both return the default graphics context for the root window of the +specified screen. +This GC is created for the convenience of simple applications +and contains the default GC components with the foreground and +background pixel values initialized to the black and white +pixels for the screen, respectively. +You can modify its contents freely because it is not used in any Xlib +function. +This GC should never be freed. + + + + + + + +DefaultRootWindow(display) + + + + Window XDefaultRootWindow + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +DefaultRootWindow +XDefaultRootWindow +Both return the root window for the default screen. + + + + + + + +DefaultScreenOfDisplay(display) + + + + Screen *XDefaultScreenOfDisplay + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +DefaultScreenOfDisplay +XDefaultScreenOfDisplay +Both return a pointer to the default screen. + + + + + + + +ScreenOfDisplay(display, screen_number) + + + + Screen *XScreenOfDisplay + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +ScreenOfDisplay +XScreenOfDisplay +Both return a pointer to the indicated screen. + + + + + + + +DefaultScreen(display) + + + + int XDefaultScreen + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +DefaultScreen +XDefaultScreen +Both return the default screen number referenced by the +XOpenDisplay +function. +This macro or function should be used to retrieve the screen number +in applications that will use only a single screen. + + + + + + + +DefaultVisual(display, screen_number) + + + + Visual *XDefaultVisual + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DefaultVisual +XDefaultVisual +Both return the default visual type for the specified screen. +For further information about visual types, +see section 3.1. + + + + + + + +DisplayCells(display, screen_number) + + + + int XDisplayCells + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DisplayCells +XDisplayCells +Both return the number of entries in the default colormap. + + + + + + + +DisplayPlanes(display, screen_number) + + + + int XDisplayPlanes + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DisplayPlanes +XDisplayPlanes +Both return the depth of the root window of the specified screen. +For an explanation of depth, +see the glossary. + + + + + + + +DisplayString(display) + + + + char *XDisplayString + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +DisplayString +XDisplayString +Both return the string that was passed to +XOpenDisplay +when the current display was opened. +On POSIX-conformant systems, +if the passed string was NULL, these return the value of +the DISPLAY environment variable when the current display was opened. +POSIX System Callfork +These are useful to applications that invoke the +fork +system call and want to open a new connection to the same display from the +child process as well as for printing error messages. + + + + + + + +LastKnownRequestProcessed(display) + + + + unsigned long XLastKnownRequestProcessed + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +XExtendedMaxRequestSize +The +XExtendedMaxRequestSize +function returns zero if the specified display does not support an +extended-length protocol encoding; otherwise, +it returns the maximum request size (in 4-byte units) supported +by the server using the extended-length encoding. +The Xlib functions +XDrawLines, +XDrawArcs, +XFillPolygon, +XChangeProperty, +XSetClipRectangles, +and +XSetRegion +will use the extended-length encoding as necessary, if supported +by the server. Use of the extended-length encoding in other Xlib +functions (for example, +XDrawPoints, +XDrawRectangles, +XDrawSegments, +XFillArcs, +XFillRectangles, +XPutImage) +is permitted but not required; an Xlib implementation may choose to +split the data across multiple smaller requests instead. + + + + + + + +LastKnownRequestProcessed(display) + + + + unsigned long XLastKnownRequestProcessed + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +XMaxRequestSize +The +XMaxRequestSize +function returns the maximum request size (in 4-byte units) supported +by the server without using an extended-length protocol encoding. +Single protocol requests to the server can be no larger than this size +unless an extended-length protocol encoding is supported by the server. +The protocol guarantees the size to be no smaller than 4096 units +(16384 bytes). +Xlib automatically breaks data up into multiple protocol requests +as necessary for the following functions: +XDrawPoints, +XDrawRectangles, +XDrawSegments, +XFillArcs, +XFillRectangles, +and +XPutImage. + + + + + + + +LastKnownRequestProcessed(display) + + + + unsigned long XLastKnownRequestProcessed + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +LastKnownRequestProcessed +XLastKnownRequestProcessed +Both extract the full serial number of the last request known by Xlib +to have been processed by the X server. +Xlib automatically sets this number when replies, events, and errors +are received. + + + + + + + +NextRequest(display) + + + + unsigned long XNextRequest + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +NextRequest +XNextRequest +Both extract the full serial number that is to be used for the next +request. +Serial numbers are maintained separately for each display connection. + + + + + + + +ProtocolVersion(display) + + + + int XProtocolVersion + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +ProtocolVersion +XProtocolVersion +Both return the major version number (11) of the X protocol associated with +the connected display. + + + + + + + +ProtocolRevision(display) + + + + int XProtocolRevision + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +ProtocolRevision +XProtocolRevision +Both return the minor protocol revision number of the X server. + + + + + + + +QLength(display) + + + + int XQLength + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +QLength +XQLength +Both return the length of the event queue for the connected display. +Note that there may be more events that have not been read into +the queue yet (see +XEventsQueued). + + + + + + + +RootWindow(display, screen_number) + + + + Window XRootWindow + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +WindowRootWindow +RootWindow +WindowXRootWindow +XRootWindow +Both return the root window. +These are useful with functions that need a drawable of a particular screen +and for creating top-level windows. + + + + + + + +ScreenCount(display) + + + + int XScreenCount + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +ScreenCount +XScreenCount +Both return the number of available screens. + + + + + + + +ServerVendor(display) + + + + char *XServerVendor + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +ServerVendor +XServerVendor +Both return a pointer to a null-terminated string that provides +some identification of the owner of the X server implementation. +If the data returned by the server is in the Latin Portable Character Encoding, +then the string is in the Host Portable Character Encoding. +Otherwise, the contents of the string are implementation-dependent. + + + + + + + +VendorRelease(display) + + + + int XVendorRelease + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +VendorRelease +XVendorRelease +Both return a number related to a vendor's release of the X server. + + + +Image Format Functions and Macros + + + + + +Applications are required to present data to the X server +in a format that the server demands. +To help simplify applications, +most of the work required to convert the data is provided by Xlib +(see sections 8.7 and 16.8). + + + +The +XPixmapFormatValues +structure provides an interface to the pixmap format information +that is returned at the time of a connection setup. +It contains: + + + + + + + +typedef struct { + int depth; + int bits_per_pixel; + int scanline_pad; +} XPixmapFormatValues; + + + + + + +To obtain the pixmap format information for a given display, use +XListPixmapFormats. +XListPixmapFormats + + + +ImageByteOrder(display) + + + + int XImageByteOrder + Display *display + int *count_return + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + count_return + + + +Returns the number of (Cn. + + + + + + + +The +XListPixmapFormats +function returns an array of +XPixmapFormatValues +structures that describe the types of Z format images supported +by the specified display. +If insufficient memory is available, +XListPixmapFormats +returns NULL. +To free the allocated storage for the +XPixmapFormatValues +structures, use +XFree. + + + +The following lists the C language macros, +their corresponding function equivalents that are for other language bindings, +and what data they both return for the specified server and screen. +These are often used by toolkits as well as by simple applications. + + + + + + + +ImageByteOrder(display) + + + + int XImageByteOrder + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +ImageByteOrder +XImageByteOrder +Both specify the required byte order for images for each scanline unit in +XY format (bitmap) or for each pixel value in +Z format. +The macro or function can return either +LSBFirst +or +MSBFirst. + + + + + + + +BitmapUnit(display) + + + + int XBitmapUnit + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +BitmapUnit +XBitmapUnit +Both return the size of a bitmap's scanline unit in bits. +The scanline is calculated in multiples of this value. + + + + + + + +BitmapBitOrder(display) + + + + int XBitmapBitOrder + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +BitmapBitOrder +XBitmapBitOrder +Within each bitmap unit, the left-most bit in the bitmap as displayed +on the screen is either the least significant or most significant bit in the +unit. +This macro or function can return +LSBFirst +or +MSBFirst. + + + + + + + +BitmapPad(display) + + + + int XBitmapPad + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +BitmapPad +XBitmapPad +Each scanline must be padded to a multiple of bits returned +by this macro or function. + + + + + + + +DisplayHeight(display, screen_number) + + + + int XDisplayHeight + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DisplayHeight +XDisplayHeight +Both return an integer that describes the height of the screen +in pixels. + + + + + + + +DisplayHeightMM(display, screen_number) + + + + int XDisplayHeightMM + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DisplayHeightMM +XDisplayHeightMM +Both return the height of the specified screen in millimeters. + + + + + + + +DisplayWidth(display, screen_number) + + + + int XDisplayWidth + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DisplayWidth +XDisplayWidth +Both return the width of the screen in pixels. + + + + + + + +DisplayWidthMM(display, screen_number) + + + + int XDisplayWidthMM + Display *display + int screen_number + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + screen_number + + + +Specifies the appropriate screen number on the host server. + + + + + + + +DisplayWidthMM +XDisplayWidthMM +Both return the width of the specified screen in millimeters. + + + +Screen Information Macros + + + + + +The following lists the C language macros, +their corresponding function equivalents that are for other language bindings, +and what data they both can return. +These macros or functions all take a pointer to the appropriate screen +structure. + + + + + + + +BlackPixelOfScreen(screen) + + + + unsigned long XBlackPixelOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +BlackPixelOfScreen +XBlackPixelOfScreen +Both return the black pixel value of the specified screen. + + + + + + + +WhitePixelOfScreen(screen) + + + + unsigned long XWhitePixelOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +WhitePixelOfScreen +XWhitePixelOfScreen +Both return the white pixel value of the specified screen. + + + + + + + +CellsOfScreen(screen) + + + + int XCellsOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +CellsOfScreen +XCellsOfScreen +Both return the number of colormap cells in the default colormap +of the specified screen. + + + + + + + +DefaultColormapOfScreen(screen) + + + + Colormap XDefaultColormapOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +DefaultColormapOfScreen +XDefaultColormapOfScreen +Both return the default colormap of the specified screen. + + + + + + + +DefaultDepthOfScreen(screen) + + + + int XDefaultDepthOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +DefaultDepthOfScreen +XDefaultDepthOfScreen +Both return the depth of the root window. + + + + + + + +DefaultGCOfScreen(screen) + + + + GC XDefaultGCOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +DefaultGCOfScreen +XDefaultGCOfScreen +Both return a default graphics context (GC) of the specified screen, +which has the same depth as the root window of the screen. +The GC must never be freed. + + + + + + + +DefaultVisualOfScreen(screen) + + + + Visual *XDefaultVisualOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +DefaultVisualOfScreen +XDefaultVisualOfScreen +Both return the default visual of the specified screen. +For information on visual types, +see section 3.1. + + + + + + + +DoesBackingStore(screen) + + + + int XDoesBackingStore + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +DoesBackingStore +XDoesBackingStore +Both return a value indicating whether the screen supports backing +stores. +The value returned can be one of +WhenMapped, +NotUseful, +or +Always +(see section 3.2.4). + + + + + + + +DoesSaveUnders(screen) + + + + Bool XDoesSaveUnders + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +DoesSaveUnders +XDoesSaveUnders +Both return a Boolean value indicating whether the +screen supports save unders. +If +True, +the screen supports save unders. +If +False, +the screen does not support save unders (see section 3.2.5). + + + + + + + +DisplayOfScreen(screen) + + + + Display *XDisplayOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +DisplayOfScreen +XDisplayOfScreen +Both return the display of the specified screen. + + + + + +XScreenNumberOfScreen + + +EventMaskOfScreen(screen) + + + + long XEventMaskOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +The +XScreenNumberOfScreen +function returns the screen index number of the specified screen. + + + + + + + +EventMaskOfScreen(screen) + + + + long XEventMaskOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +EventMaskOfScreen +XEventMaskOfScreen +Both return the event mask of the root window for the specified screen +at connection setup time. + + + + + + + +WidthOfScreen(screen) + + + + int XWidthOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +WidthOfScreen +XWidthOfScreen +Both return the width of the specified screen in pixels. + + + + + + + +HeightOfScreen(screen) + + + + int XHeightOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +HeightOfScreen +XHeightOfScreen +Both return the height of the specified screen in pixels. + + + + + + + +WidthMMOfScreen(screen) + + + + int XWidthMMOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +WidthMMOfScreen +XWidthMMOfScreen +Both return the width of the specified screen in millimeters. + + + + + + + +HeightMMOfScreen(screen) + + + + int XHeightMMOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +HeightMMOfScreen +XHeightMMOfScreen +Both return the height of the specified screen in millimeters. + + + + + + + +MaxCmapsOfScreen(screen) + + + + int XMaxCmapsOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +MaxCmapsOfScreen +XMaxCmapsOfScreen +Both return the maximum number of installed colormaps supported +by the specified screen (see section 9.3). + + + + + + + +MinCmapsOfScreen(screen) + + + + int XMinCmapsOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +MinCmapsOfScreen +XMinCmapsOfScreen +Both return the minimum number of installed colormaps supported +by the specified screen (see section 9.3). + + + + + + + +PlanesOfScreen(screen) + + + + int XPlanesOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +PlanesOfScreen +XPlanesOfScreen +Both return the depth of the root window. + + + + + + + +RootWindowOfScreen(screen) + + + + Window XRootWindowOfScreen + Screen *screen + + + + + + + screen + + + +Specifies the appropriate +Screen +structure. + + + + + + + +RootWindowOfScreen +XRootWindowOfScreen +Both return the root window of the specified screen. + + + + +Generating a NoOperation Protocol Request + + + + + +To execute a +NoOperation +protocol request, use +XNoOp. +XNoOp + + + + + XNoOp + Display *display + + + + + + display + + Specifies the connection to the X server. + + + + + + +The +XNoOp +function sends a +NoOperation +protocol request to the X server, +thereby exercising the connection. + + + +Freeing Client-Created Data + + + + + +To free in-memory data that was created by an Xlib function, use +XFree. +XFree + + + + + XFree + void *data + + + + + + + + data + + + +Specifies the data that is to be freed. + + + + + + + +The +XFree +function is a general-purpose Xlib routine that frees the specified data. +You must use it to free any objects that were allocated by Xlib, +unless an alternate function is explicitly specified for the object. +A NULL pointer cannot be passed to this function. + + + +Closing the Display + + + + + +To close a display or disconnect from the X server, use +XCloseDisplay. +XCloseDisplay + + + + + + + + XCloseDisplay + Display *display + + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +The +XCloseDisplay +function closes the connection to the X server for the display specified in the +Display +structure and destroys all windows, resource IDs +(Window, +Font, +Pixmap, +Colormap, +Cursor, +and +GContext), +or other resources that the client has created +on this display, unless the close-down mode of the resource has been changed +(see +XSetCloseDownMode). +Therefore, these windows, resource IDs, and other resources should never be +referenced again or an error will be generated. +Before exiting, you should call +XCloseDisplay +explicitly so that any pending errors are reported as +XCloseDisplay +performs a final +XSync +operation. +Resource IDs +XCloseDisplay + + + +XCloseDisplay +can generate a +BadGC +error. + + + + +Xlib provides a function to permit the resources owned by a client +to survive after the client's connection is closed. +To change a client's close-down mode, use +XSetCloseDownMode. +XSetCloseDownMode + + + + + XSetCloseDownMode + Display *display + int close_mode + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + close_mode + + + +Specifies the client close-down mode. +You can pass +DestroyAll, +RetainPermanent, +or +RetainTemporary. + + + + + + + +The +XSetCloseDownMode +defines what will happen to the client's resources at connection close. +A connection starts in +DestroyAll +mode. +For information on what happens to the client's resources when the +close_mode argument is +RetainPermanent +or +RetainTemporary, +see section 2.6. + + + +XSetCloseDownMode +can generate a +BadValue +error. + + + +Using X Server Connection Close Operations + + + + + +When the X server's connection to a client is closed +either by an explicit call to +XCloseDisplay +or by a process that exits, the X server performs the following +automatic operations: + + + + +It disowns all selections owned by the client +(see +XSetSelectionOwner). + + + + +It performs an +XUngrabPointer +and +XUngrabKeyboard +if the client has actively grabbed the pointer +or the keyboard. + + + + +It performs an +XUngrabServer +if the client has grabbed the server. + + + + +It releases all passive grabs made by the client. + + + + +It marks all resources (including colormap entries) allocated +by the client either as permanent or temporary, +depending on whether the close-down mode is +RetainPermanent +or +RetainTemporary. +However, this does not prevent other client applications from explicitly +destroying the resources (see +XSetCloseDownMode). + + + + + +When the close-down mode is +DestroyAll, +the X server destroys all of a client's resources as follows: + + + + +It examines each window in the client's save-set to determine if it is an inferior +(subwindow) of a window created by the client. +(The save-set is a list of other clients' windows +that are referred to as save-set windows.) +If so, the X server reparents the save-set window to the closest ancestor so +that the save-set window is not an inferior of a window created by the client. +The reparenting leaves unchanged the absolute coordinates (with respect to +the root window) of the upper-left outer corner of the save-set +window. + + + + +It performs a +MapWindow +request on the save-set window if the save-set window is unmapped. +The X server does this even if the save-set window was not an inferior of +a window created by the client. + + + + +It destroys all windows created by the client. + + + + +It performs the appropriate free request on each nonwindow resource created by +the client in the server (for example, +Font, +Pixmap, +Cursor, +Colormap, +and +GContext). + + + + +It frees all colors and colormap entries allocated by a client application. + + + + + +Additional processing occurs when the last connection to the X server closes. +An X server goes through a cycle of having no connections and having some +connections. +When the last connection to the X server closes as a result of a connection +closing with the close_mode of +DestroyAll, +the X server does the following: + + + + +It resets its state as if it had just been +started. +The X server begins by destroying all lingering resources from +clients that have terminated in +RetainPermanent +or +RetainTemporary +mode. + + + + +It deletes all but the predefined atom identifiers. + + + + +It deletes all properties on all root windows (see section 4.3). + + + + +It resets all device maps and attributes +(for example, key click, bell volume, and acceleration) +as well as the access control list. + + + + +It restores the standard root tiles and cursors. + + + + +It restores the default font path. + + + + +It restores the input focus to state +PointerRoot. + + + + + +However, the X server does not reset if you close a connection with a close-down +mode set to +RetainPermanent +or +RetainTemporary. + + + +Using Xlib with Threads + + + + + +On systems that have threads, support may be provided to permit +multiple threads to use Xlib concurrently. + + + + +To initialize support for concurrent threads, use +XInitThreads. +XInitThreads + + +Status XInitThreads(); + + + + +The +XInitThreads +function initializes Xlib support for concurrent threads. +This function must be the first Xlib function a +multi-threaded program calls, and it must complete +before any other Xlib call is made. +This function returns a nonzero status if initialization was +successful; otherwise, it returns zero. +On systems that do not support threads, this function always returns zero. + + + +It is only necessary to call this function if multiple threads +might use Xlib concurrently. If all calls to Xlib functions +are protected by some other access mechanism (for example, +a mutual exclusion lock in a toolkit or through explicit client +programming), Xlib thread initialization is not required. +It is recommended that single-threaded programs not call this function. + + + + + +To lock a display across several Xlib calls, use +XLockDisplay. +XLockDisplay + + + + + XLockDisplay + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +The +XLockDisplay +function locks out all other threads from using the specified display. +Other threads attempting to use the display will block until +the display is unlocked by this thread. +Nested calls to +XLockDisplay +work correctly; the display will not actually be unlocked until +XUnlockDisplay +has been called the same number of times as +XLockDisplay. +This function has no effect unless Xlib was successfully initialized +for threads using +XInitThreads. + + + + +To unlock a display, use +XUnlockDisplay. +XUnlockDisplay + + + + + XUnlockDisplay + Display *display + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + + +The +XUnlockDisplay +function allows other threads to use the specified display again. +Any threads that have blocked on the display are allowed to continue. +Nested locking works correctly; if +XLockDisplay +has been called multiple times by a thread, then +XUnlockDisplay +must be called an equal number of times before the display is +actually unlocked. +This function has no effect unless Xlib was successfully initialized +for threads using +XInitThreads. + + + +Using Internal Connections + + + + + +In addition to the connection to the X server, an Xlib implementation +may require connections to other kinds of servers (for example, to +input method servers as described in chapter 13). Toolkits and clients +that use multiple displays, or that use displays in combination with +other inputs, need to obtain these additional connections to correctly +block until input is available and need to process that input +when it is available. Simple clients that use a single display and +block for input in an Xlib event function do not need to use these +facilities. + + + +To track internal connections for a display, use +XAddConnectionWatch. + + + + type void XConnectionWatchProc + Display *display + XPointer client_data + int fd + Bool opening + XPointer *watch_data + + + + + + Status XAddConnectionWatch + Display *display + XWatchProc procedure + XPointer client_data + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + procedure + + + +Specifies the procedure to be called. + + + + + + client_data + + + +Specifies the additional client data. + + + + + + + +The +XAddConnectionWatch +function registers a procedure to be called each time Xlib opens or closes an +internal connection for the specified display. The procedure is passed the +display, the specified client_data, the file descriptor for the connection, +a Boolean indicating whether the connection is being opened or closed, and a +pointer to a location for private watch data. If opening is +True, +the procedure can store a pointer to private data in the location pointed +to by watch_data; +when the procedure is later called for this same connection and opening is +False, +the location pointed to by watch_data will hold this same private data pointer. + + + +This function can be called at any time after a display is opened. +If internal connections already exist, the registered procedure will +immediately be called for each of them, before +XAddConnectionWatch +returns. +XAddConnectionWatch +returns a nonzero status if the procedure is successfully registered; +otherwise, it returns zero. + + + +The registered procedure should not call any Xlib functions. +If the procedure directly or indirectly causes the state of internal +connections or watch procedures to change, the result is not defined. +If Xlib has been initialized for threads, the procedure is called with +the display locked and the result of a call by the procedure to any +Xlib function that locks the display is not defined unless the executing +thread has externally locked the display using +XLockDisplay. + + + + +To stop tracking internal connections for a display, use +XRemoveConnectionWatch. +XRemoveConnectionWatch + + + +() + + + + Status XRemoveConnectionWatch + Display *display + XWatchProc procedure + XPointer client_data + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + procedure + + + +Specifies the procedure to be called. + + + + + + client_data + + + +Specifies the additional client data. + + + + + + + +The +XRemoveConnectionWatch +function removes a previously registered connection watch procedure. +The client_data must match the client_data used when the procedure +was initially registered. + + + + + +To process input on an internal connection, use +XProcessInternalConnection. +XProcessInternalConnection + + + +() + + + + void XProcessInternalConnection + Display *display + int fd + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + fd + + + +Specifies the file descriptor. + + + + + + + +The +XProcessInternalConnection +function processes input available on an internal connection. +This function should be called for an internal connection only +after an operating system facility (for example, +select +or +poll) +has indicated that input is available; otherwise, +the effect is not defined. + + + + +To obtain all of the current internal connections for a display, use +XInternalConnectionNumbers. +XInternalConnectionNumbers + + + +() + + + + Status XInternalConnectionNumbers + Display *display + int ** fd + int * count_return + + + + + + + display + + + +Specifies the connection to the X server. + + + + + + fd_return + + + +Returns the file descriptors. + + + + + + + count_return + + + +Returns the number of (Cn. + + + + + + + +The +XInternalConnectionNumbers +function returns a list of the file descriptors for all internal +connections currently open for the specified display. +When the allocated list is no longer needed, +free it by using +XFree. +This functions returns a nonzero status if the list is successfully allocated; +otherwise, it returns zero. + + + diff --git a/libX11/src/FSWrap.c b/libX11/src/FSWrap.c index 94d94fbe9..45a2c34e3 100644 --- a/libX11/src/FSWrap.c +++ b/libX11/src/FSWrap.c @@ -85,10 +85,9 @@ _XParseBaseFontNameList( if (!*str) return (char **)NULL; - if (!(ptr = Xmalloc((unsigned)strlen(str) + 1))) { + if (!(ptr = strdup(str))) { return (char **)NULL; } - strcpy(ptr, str); psave = ptr; /* somebody who specifies more than XMAXLIST basefontnames will lose */ diff --git a/libX11/src/InitExt.c b/libX11/src/InitExt.c index cb9191de6..19515ccd0 100644 --- a/libX11/src/InitExt.c +++ b/libX11/src/InitExt.c @@ -50,14 +50,13 @@ XExtCodes *XInitExtension ( LockDisplay (dpy); if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension))) || - ! (ext->name = Xmalloc((unsigned) strlen(name) + 1))) { + ! (ext->name = strdup(name))) { if (ext) Xfree((char *) ext); UnlockDisplay(dpy); return (XExtCodes *) NULL; } codes.extension = dpy->ext_number++; ext->codes = codes; - (void) strcpy(ext->name, name); /* chain it onto the display list */ ext->next = dpy->ext_procs; diff --git a/libX11/src/Quarks.c b/libX11/src/Quarks.c index d0eb69018..7a704b101 100644 --- a/libX11/src/Quarks.c +++ b/libX11/src/Quarks.c @@ -210,10 +210,9 @@ ExpandQuarkTable(void) #endif newmask = 0x1ff; } - entries = (Entry *)Xmalloc(sizeof(Entry) * (newmask + 1)); + entries = Xcalloc(newmask + 1, sizeof(Entry)); if (!entries) return False; - bzero((char *)entries, sizeof(Entry) * (newmask + 1)); quarkTable = entries; quarkMask = newmask; quarkRehash = quarkMask - 2; diff --git a/libX11/src/SetLocale.c b/libX11/src/SetLocale.c index 00c76ee45..c49cb2e4e 100644 --- a/libX11/src/SetLocale.c +++ b/libX11/src/SetLocale.c @@ -103,13 +103,12 @@ _Xsetlocale( if (!methods) return NULL; name = (*methods->lcname)(state); - xsl_name = Xmalloc(strlen(name) + 1); + xsl_name = strdup(name); if (!xsl_name) { xsl_name = old_name; (*methods->destroy)(state); return NULL; } - strcpy(xsl_name, name); if (old_name) Xfree(old_name); (*methods->destroy)(state); diff --git a/libX11/src/Xrm.c b/libX11/src/Xrm.c index c466cae7f..53467aedc 100644 --- a/libX11/src/Xrm.c +++ b/libX11/src/Xrm.c @@ -581,23 +581,21 @@ static void GrowTable( ltable = (LTable)table; /* cons up a copy to make MoveValues look symmetric */ otable = *ltable; - ltable->buckets = (VEntry *)Xmalloc(i * sizeof(VEntry)); + ltable->buckets = Xcalloc(i, sizeof(VEntry)); if (!ltable->buckets) { ltable->buckets = otable.buckets; return; } ltable->table.mask = i - 1; - bzero((char *)ltable->buckets, i * sizeof(VEntry)); MoveValues(&otable, ltable); } else { register NTable ntable; - ntable = (NTable)Xmalloc(sizeof(NTableRec) + i * sizeof(NTable)); + ntable = Xcalloc(1, sizeof(NTableRec) + (i * sizeof(NTable))); if (!ntable) return; *ntable = *table; ntable->mask = i - 1; - bzero((char *)NodeBuckets(ntable), i * sizeof(NTable)); *prev = ntable; MoveTables(table, ntable); } diff --git a/libX11/src/xcms/PrOfId.c b/libX11/src/xcms/PrOfId.c index 831f17ab9..a96d28cec 100644 --- a/libX11/src/xcms/PrOfId.c +++ b/libX11/src/xcms/PrOfId.c @@ -66,7 +66,6 @@ XcmsPrefixOfFormat( */ { XcmsColorSpace **papColorSpaces; - char *prefix; /* * First try Device-Independent color spaces @@ -75,10 +74,7 @@ XcmsPrefixOfFormat( if (papColorSpaces != NULL) { while (*papColorSpaces != NULL) { if ((*papColorSpaces)->id == id) { - prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) + - 1) * sizeof(char)); - strcpy(prefix, (*papColorSpaces)->prefix); - return(prefix); + return strdup((*papColorSpaces)->prefix); } papColorSpaces++; } @@ -91,10 +87,7 @@ XcmsPrefixOfFormat( if (papColorSpaces != NULL) { while (*papColorSpaces != NULL) { if ((*papColorSpaces)->id == id) { - prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) + - 1) * sizeof(char)); - strcpy(prefix, (*papColorSpaces)->prefix); - return(prefix); + return strdup((*papColorSpaces)->prefix); } papColorSpaces++; } diff --git a/libX11/src/xkb/XKBGAlloc.c b/libX11/src/xkb/XKBGAlloc.c index 832d28530..7679496e3 100644 --- a/libX11/src/xkb/XKBGAlloc.c +++ b/libX11/src/xkb/XKBGAlloc.c @@ -1,1016 +1,1011 @@ -/************************************************************ -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 -#elif defined(HAVE_CONFIG_H) -#include -#endif - -#ifndef XKB_IN_SERVER - -#include -#include "Xlibint.h" -#include "XKBlibint.h" -#include -#include - -#else - -#include -#include -#include -#include "misc.h" -#include "inputstr.h" -#include -#include - -#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=(*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, - §ion->num_overlays,§ion->sz_overlays, - (char **)§ion->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, - §ion->num_rows,§ion->sz_rows, - (char **)§ion->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;iproperties!=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;inum_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 (!prop->name) - return NULL; - strcpy(prop->name,name); - prop->value= (char *)_XkbAlloc(strlen(value)+1); - if (!prop->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;inum_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;inum_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;inum_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= §ion->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;inum_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;iany.name==name) - return doodad; - } - if (section) { - if ((section->num_doodads>=geom->sz_doodads)&& - (_XkbAllocDoodads(section,1)!=Success)) { - return NULL; - } - doodad= §ion->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= §ion->rows[row->row_under]; - for (i=0,found=False;inum_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;inum_rows;i++) { - if (overlay->rows[i].row_under==row_under) { - row= &overlay->rows[i]; - if ((row->sz_keysrows[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;inum_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= §ion->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 +#elif defined(HAVE_CONFIG_H) +#include +#endif + +#ifndef XKB_IN_SERVER + +#include +#include "Xlibint.h" +#include "XKBlibint.h" +#include +#include + +#else + +#include +#include +#include +#include "misc.h" +#include "inputstr.h" +#include +#include + +#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=(*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, + §ion->num_overlays,§ion->sz_overlays, + (char **)§ion->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, + §ion->num_rows,§ion->sz_rows, + (char **)§ion->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;iproperties!=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;inum_properties;i++,prop++) { + if ((prop->name)&&(strcmp(name,prop->name)==0)) { + if (prop->value) + _XkbFree(prop->value); + prop->value= strdup(value); + return prop; + } + } + if ((geom->num_properties>=geom->sz_properties)&& + (_XkbAllocProps(geom,1)!=Success)) { + return NULL; + } + prop= &geom->properties[geom->num_properties]; + prop->name= strdup(name); + if (!prop->name) + return NULL; + prop->value= strdup(value); + if (!prop->value) { + _XkbFree(prop->name); + prop->name= NULL; + return NULL; + } + 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;inum_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;inum_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= strdup(spec); + if (!color->spec) + return NULL; + 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;inum_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= §ion->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;inum_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;iany.name==name) + return doodad; + } + if (section) { + if ((section->num_doodads>=geom->sz_doodads)&& + (_XkbAllocDoodads(section,1)!=Success)) { + return NULL; + } + doodad= §ion->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= §ion->rows[row->row_under]; + for (i=0,found=False;inum_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;inum_rows;i++) { + if (overlay->rows[i].row_under==row_under) { + row= &overlay->rows[i]; + if ((row->sz_keysrows[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;inum_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= §ion->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/xlibi18n/XDefaultIMIF.c b/libX11/src/xlibi18n/XDefaultIMIF.c index c7a2fe9d3..e97d2f444 100644 --- a/libX11/src/xlibi18n/XDefaultIMIF.c +++ b/libX11/src/xlibi18n/XDefaultIMIF.c @@ -1,471 +1,469 @@ -/* -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 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. - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#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 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. + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#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 = strdup(res_name); + } + if ((res_class != NULL) && (*res_class != '\0')){ + im->core.res_class = strdup(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); +} diff --git a/libX11/src/xlibi18n/XDefaultOMIF.c b/libX11/src/xlibi18n/XDefaultOMIF.c index ae8ac79e4..b1dc66df6 100644 --- a/libX11/src/xlibi18n/XDefaultOMIF.c +++ b/libX11/src/xlibi18n/XDefaultOMIF.c @@ -128,10 +128,9 @@ init_fontset( data = XOM_GENERIC(oc->core.om)->data; - font_set = (FontSet) Xmalloc(sizeof(FontSetRec)); + font_set = Xcalloc(1, sizeof(FontSetRec)); if (font_set == NULL) return False; - bzero((char *) font_set, sizeof(FontSetRec)); gen = XOC_GENERIC(oc); gen->font_set = font_set; @@ -217,9 +216,8 @@ check_fontname( fname = prop_fname; } if (data) { - font_set->font_name = (char *) Xmalloc(strlen(fname) + 1); + font_set->font_name = strdup(fname); if (font_set->font_name) { - strcpy(font_set->font_name, fname); found_num++; } } @@ -388,9 +386,7 @@ get_font_name( list = XListFonts(dpy, pattern, 1, &count); if (list != NULL) { - name = (char *) Xmalloc(strlen(*list) + 1); - if (name) - strcpy(name, *list); + name = strdup(*list); XFreeFontNames(list); } else { @@ -460,13 +456,11 @@ parse_fontname( if (font_data == NULL) continue; - font_set->font_name = (char *) Xmalloc(strlen(font_name) + 1); + font_set->font_name = strdup(font_name); + Xfree(font_name); if (font_set->font_name == NULL) { - Xfree(font_name); goto err; } - strcpy(font_set->font_name, font_name); - Xfree(font_name); found_num++; goto found; } @@ -549,11 +543,10 @@ Limit the length of the string copy to prevent stack corruption. } } found: - base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1); + base_name = strdup(oc->core.base_name_list); if (base_name == NULL) goto err; - strcpy(base_name, oc->core.base_name_list); oc->core.base_name_list = base_name; XFreeStringList(name_list); @@ -1005,10 +998,9 @@ create_oc( { XOC oc; - oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + oc = Xcalloc(1, sizeof(XOCGenericRec)); if (oc == NULL) return (XOC) NULL; - bzero((char *) oc, sizeof(XOCGenericRec)); oc->core.om = om; @@ -1126,15 +1118,13 @@ add_data( XOMGenericPart *gen = XOM_GENERIC(om); OMData new; - new = (OMData) Xmalloc(sizeof(OMDataRec)); + new = Xcalloc(1, sizeof(OMDataRec)); if (new == NULL) return NULL; gen->data = new; - bzero((char *) new, sizeof(OMDataRec)); - return new; } @@ -1168,10 +1158,9 @@ init_om( if (data == NULL) return False; - font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return False; - bzero((char *) font_data, sizeof(FontDataRec) * count); data->font_data = font_data; data->font_data_count = count; @@ -1182,10 +1171,9 @@ This one is fine. *value points to one of the local strings in supported_charset_list[]. */ strcpy(buf, *value++); - font_data->name = (char *) Xmalloc(strlen(buf) + 1); + font_data->name = strdup(buf); if (font_data->name == NULL) return False; - strcpy(font_data->name, buf); } length += strlen(data->font_data->name) + 1; @@ -1237,26 +1225,23 @@ _XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb, { XOM om; - om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + om = Xcalloc(1, sizeof(XOMGenericRec)); if (om == NULL) return (XOM) NULL; - bzero((char *) om, sizeof(XOMGenericRec)); om->methods = (XOMMethods)&methods; om->core.lcd = lcd; om->core.display = dpy; om->core.rdb = rdb; if (res_name) { - om->core.res_name = (char *)Xmalloc(strlen(res_name) + 1); + om->core.res_name = strdup(res_name); if (om->core.res_name == NULL) goto err; - strcpy(om->core.res_name, res_name); } if (res_class) { - om->core.res_class = (char *)Xmalloc(strlen(res_class) + 1); + om->core.res_class = strdup(res_class); if (om->core.res_class == NULL) goto err; - strcpy(om->core.res_class, res_class); } if (om_resources[0].xrm_name == NULLQUARK) diff --git a/libX11/src/xlibi18n/XlcDL.c b/libX11/src/xlibi18n/XlcDL.c index 58e9ade87..75e193c05 100644 --- a/libX11/src/xlibi18n/XlcDL.c +++ b/libX11/src/xlibi18n/XlcDL.c @@ -1,652 +1,612 @@ -/* -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 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. - */ - - -#ifdef HAVE_CONFIG_H -# include -#else -# if defined(hpux) -# define HAVE_DL_H -# else -# define HAVE_DLFCN_H -# endif -#endif - -#include - -#ifdef HAVE_DL_H -#include -#endif - -#ifdef HAVE_DLFCN_H -#include -#endif - -#include - -#include "Xlibint.h" -#include "XlcPublic.h" -#include "XlcPubI.h" - -#if defined(_LP64) && defined(__sparcv9) -# define _MACH64_NAME "sparcv9" -#else -# undef _MACH64_NAME -#endif /* defined(_LP64) && defined(__sparcv9) */ - -#ifdef _MACH64_NAME -# define _MACH64_NAME_LEN (sizeof (_MACH64_NAME) - 1) -#endif - -#define XI18N_DLREL 2 - -#define iscomment(ch) ((ch) == '\0' || (ch) == '#') - -typedef enum { - XLC_OBJECT, - XIM_OBJECT, - XOM_OBJECT -} XI18NDLType; - -typedef struct { - XI18NDLType type; - int locale_name_len; - char *locale_name; - char *dl_name; - char *open; - char *im_register; - char *im_unregister; - int dl_release; - unsigned int refcount; -#if defined(hpux) - shl_t dl_module; -#else - void *dl_module; -#endif -} XI18NObjectsListRec, *XI18NObjectsList; - -#define OBJECT_INIT_LEN 8 -#define OBJECT_INC_LEN 4 -static int lc_len = 0; -static XI18NObjectsListRec *xi18n_objects_list = NULL; -static int lc_count = 0; - -static int -parse_line(char *line, char **argv, int argsize) -{ - int argc = 0; - char *p = line; - - while (argc < argsize) { - while (isspace(*p)) { - ++p; - } - if (iscomment(*p)){ - break; - } - argv[argc++] = p; - while (!isspace(*p)) { - ++p; - } - if (iscomment(*p)) { - break; - } - *p++ = '\0'; - } - return argc; -} - -static char * -strdup_with_underscore(const char *symbol) -{ - char *result; - - if ((result = malloc(strlen(symbol) + 2)) == NULL) - return NULL; - result[0] = '_'; - strcpy(result + 1, symbol); - return result; -} - -#ifndef hpux -static void * -try_both_dlsym (void *handle, char *name) -{ - void *ret; - - ret = dlsym (handle, name); - if (!ret) - { - name = strdup_with_underscore (name); - if (name) - { - ret = dlsym (handle, name); - free (name); - } - } - return ret; -} -#endif - -static void -resolve_object(char *path, const char *lc_name) -{ - char filename[BUFSIZ]; - FILE *fp; - char buf[BUFSIZ]; - - if (lc_len == 0) { /* True only for the 1st time */ - lc_len = OBJECT_INIT_LEN; - xi18n_objects_list = (XI18NObjectsList) - Xmalloc(sizeof(XI18NObjectsListRec) * lc_len); - if (!xi18n_objects_list) return; - } -/* -1266793 -Limit the length of path to prevent stack buffer corruption. - sprintf(filename, "%s/%s", path, "XI18N_OBJS"); -*/ - sprintf(filename, "%.*s/%s", BUFSIZ - 12, path, "XI18N_OBJS"); - fp = fopen(filename, "r"); - if (fp == (FILE *)NULL){ - return; - } - - while (fgets(buf, BUFSIZ, fp) != NULL){ - char *p = buf; - int n; - char *args[6]; - while (isspace(*p)){ - ++p; - } - if (iscomment(*p)){ - continue; - } - - if (lc_count == lc_len) { - lc_len += OBJECT_INC_LEN; - xi18n_objects_list = (XI18NObjectsList) - Xrealloc(xi18n_objects_list, - sizeof(XI18NObjectsListRec) * lc_len); - if (!xi18n_objects_list) return; - } - n = parse_line(p, args, 6); - - if (n == 3 || n == 5) { - if (!strcmp(args[0], "XLC")){ - xi18n_objects_list[lc_count].type = XLC_OBJECT; - } else if (!strcmp(args[0], "XOM")){ - xi18n_objects_list[lc_count].type = XOM_OBJECT; - } else if (!strcmp(args[0], "XIM")){ - xi18n_objects_list[lc_count].type = XIM_OBJECT; - } - xi18n_objects_list[lc_count].dl_name = strdup(args[1]); - xi18n_objects_list[lc_count].open = strdup(args[2]); - xi18n_objects_list[lc_count].dl_release = XI18N_DLREL; - xi18n_objects_list[lc_count].locale_name = strdup(lc_name); - xi18n_objects_list[lc_count].refcount = 0; - xi18n_objects_list[lc_count].dl_module = (void*)NULL; - if (n == 5) { - xi18n_objects_list[lc_count].im_register = strdup(args[3]); - xi18n_objects_list[lc_count].im_unregister = strdup(args[4]); - } else { - xi18n_objects_list[lc_count].im_register = NULL; - xi18n_objects_list[lc_count].im_unregister = NULL; - } - lc_count++; - } - } - fclose(fp); -} - -static char* -__lc_path(const char *dl_name, const char *lc_dir) -{ - char *path; - size_t len; - - /* - * reject this for possible security issue - */ - if (strstr (dl_name, "../")) - return NULL; - -#if defined (_LP64) && defined (_MACH64_NAME) - len = (lc_dir ? strlen(lc_dir) : 0 ) + - (dl_name ? strlen(dl_name) : 0) + _MACH64_NAME_LEN + 10; - path = Xmalloc(len + 1); - - if (strchr(dl_name, '/') != NULL) { - char *tmp = strdup(dl_name); - char *dl_dir, *dl_file; - char *slash_p; - slash_p = strchr(tmp, '/'); - *slash_p = '\0'; - dl_dir = tmp; - dl_file = ++slash_p; - - slash_p = strrchr(lc_dir, '/'); - *slash_p = '\0'; - strcpy(path, lc_dir); strcat(path, "/"); - strcat(path, dl_dir); strcat(path, "/"); - strcat(path, _MACH64_NAME); strcat(path, "/"); - strcat(path, dl_file); strcat(path, ".so.2"); - - *slash_p = '/'; - Xfree(tmp); - } else { - strcpy(path, lc_dir); strcat(path, "/"); - strcat(path, _MACH64_NAME); strcat(path, "/"); - strcat(path, dl_name); strcat(path, ".so.2"); - } -#else - len = (lc_dir ? strlen(lc_dir) : 0 ) + - (dl_name ? strlen(dl_name) : 0) + 10; -#if defined POSTLOCALELIBDIR - len += (strlen(POSTLOCALELIBDIR) + 1); -#endif - path = Xmalloc(len + 1); - - if (strchr(dl_name, '/') != NULL) { - char *slash_p; - slash_p = strrchr(lc_dir, '/'); - *slash_p = '\0'; - strcpy(path, lc_dir); strcat(path, "/"); -#if defined POSTLOCALELIBDIR - strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); -#endif - strcat(path, dl_name); strcat(path, ".so.2"); - *slash_p = '/'; - } else { - strcpy(path, lc_dir); strcat(path, "/"); -#if defined POSTLOCALELIBDIR - strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); -#endif - strcat(path, dl_name); strcat(path, ".so.2"); - } -#endif - return path; -} - -/* We reference count dlopen() and dlclose() of modules; unfortunately, - * since XCloseIM, XCloseOM, XlcClose aren't wrapped, but directly - * call the close method of the object, we leak a reference count every - * time we open then close a module. Fixing this would require - * either creating proxy objects or hooks for close_im/close_om - * in XLCd - */ -static Bool -open_object( - XI18NObjectsList object, - char *lc_dir) -{ - char *path; - - if (object->refcount == 0) { - path = __lc_path(object->dl_name, lc_dir); - if (!path) - return False; -#if defined(hpux) - object->dl_module = shl_load(path, BIND_DEFERRED, 0L); -#else - object->dl_module = dlopen(path, RTLD_LAZY); -#endif - Xfree(path); - - if (!object->dl_module) - return False; - } - - object->refcount++; - return True; -} - -static void * -fetch_symbol( - XI18NObjectsList object, - char *symbol) -{ - void *result = NULL; -#if defined(hpux) - int getsyms_cnt, i; - struct shl_symbol *symbols; -#endif - - if (symbol == NULL) - return NULL; - -#if defined(hpux) - getsyms_cnt = shl_getsymbols(object->dl_module, TYPE_PROCEDURE, - EXPORT_SYMBOLS, malloc, &symbols); - - for(i=0; i 0) { - free(symbols); - } -#else - result = try_both_dlsym(object->dl_module, symbol); -#endif - - return result; -} - -static void -close_object(XI18NObjectsList object) -{ - object->refcount--; - if (object->refcount == 0) - { -#if defined(hpux) - shl_unload(object->dl_module); -#else - dlclose(object->dl_module); -#endif - object->dl_module = NULL; - } -} - - -typedef XLCd (*dynamicLoadProc)(const char *); - -XLCd -_XlcDynamicLoad(const char *lc_name) -{ - XLCd lcd = (XLCd)NULL; - dynamicLoadProc lc_loader = (dynamicLoadProc)NULL; - int count; - XI18NObjectsList objects_list; - char lc_dir[BUFSIZE], lc_lib_dir[BUFSIZE]; - - if (lc_name == NULL) return (XLCd)NULL; - - if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char *)NULL) - return (XLCd)NULL; - if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, (char *)lc_name) == (char*)NULL) - return (XLCd)NULL; - - resolve_object(lc_dir, lc_name); - resolve_object(lc_lib_dir, lc_name); - - objects_list = xi18n_objects_list; - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XLC_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - if (!open_object (objects_list, lc_dir) && \ - !open_object (objects_list, lc_lib_dir)) - continue; - - lc_loader = (dynamicLoadProc)fetch_symbol (objects_list, objects_list->open); - if (!lc_loader) continue; - lcd = (*lc_loader)(lc_name); - if (lcd != (XLCd)NULL) { - break; - } - - close_object (objects_list); - } - return (XLCd)lcd; -} - - -typedef XIM (*dynamicOpenProcp)(XLCd, Display *, XrmDatabase, char *, char *); - -static XIM -_XDynamicOpenIM(XLCd lcd, Display *display, XrmDatabase rdb, - char *res_name, char *res_class) -{ - XIM im = (XIM)NULL; - char lc_dir[BUFSIZE]; - char *lc_name; - dynamicOpenProcp im_openIM = (dynamicOpenProcp)NULL; - int count; - XI18NObjectsList objects_list = xi18n_objects_list; - - lc_name = lcd->core->name; - - if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XIM)0; - - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XIM_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - - if (!open_object (objects_list, lc_dir)) - continue; - - im_openIM = (dynamicOpenProcp)fetch_symbol(objects_list, objects_list->open); - if (!im_openIM) continue; - im = (*im_openIM)(lcd, display, rdb, res_name, res_class); - if (im != (XIM)NULL) { - break; - } - - close_object (objects_list); - } - return (XIM)im; -} - -typedef Bool (*dynamicRegisterCBProcp)( - XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); - -static Bool -_XDynamicRegisterIMInstantiateCallback( - XLCd lcd, - Display *display, - XrmDatabase rdb, - char *res_name, - char *res_class, - XIDProc callback, - XPointer client_data) -{ - char lc_dir[BUFSIZE]; - char *lc_name; - dynamicRegisterCBProcp im_registerIM = (dynamicRegisterCBProcp)NULL; - Bool ret_flag = False; - int count; - XI18NObjectsList objects_list = xi18n_objects_list; -#if defined(hpux) - int getsyms_cnt, i; - struct shl_symbol *symbols; -#endif - - lc_name = lcd->core->name; - - if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; - - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XIM_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - - if (!open_object (objects_list, lc_dir)) - continue; - im_registerIM = (dynamicRegisterCBProcp)fetch_symbol(objects_list, - objects_list->im_register); - if (!im_registerIM) continue; - ret_flag = (*im_registerIM)(lcd, display, rdb, - res_name, res_class, - callback, client_data); - if (ret_flag) break; - - close_object (objects_list); - } - return (Bool)ret_flag; -} - -typedef Bool (*dynamicUnregisterProcp)( - XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); - -static Bool -_XDynamicUnRegisterIMInstantiateCallback( - XLCd lcd, - Display *display, - XrmDatabase rdb, - char *res_name, - char *res_class, - XIDProc callback, - XPointer client_data) -{ - char lc_dir[BUFSIZE]; - char *lc_name; - dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL; - Bool ret_flag = False; - int count; - XI18NObjectsList objects_list = xi18n_objects_list; -#if defined(hpux) - int getsyms_cnt, i; - struct shl_symbol *symbols; -#endif - - lc_name = lcd->core->name; - if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; - - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XIM_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - - if (!objects_list->refcount) /* Must already be opened */ - continue; - - im_unregisterIM = (dynamicUnregisterProcp)fetch_symbol(objects_list, - objects_list->im_unregister); - - if (!im_unregisterIM) continue; - ret_flag = (*im_unregisterIM)(lcd, display, rdb, - res_name, res_class, - callback, client_data); - if (ret_flag) { - close_object (objects_list); /* opened in RegisterIMInstantiateCallback */ - break; - } - } - return (Bool)ret_flag; -} - -Bool -_XInitDynamicIM(XLCd lcd) -{ - if(lcd == (XLCd)NULL) - return False; - lcd->methods->open_im = _XDynamicOpenIM; - lcd->methods->register_callback = _XDynamicRegisterIMInstantiateCallback; - lcd->methods->unregister_callback = _XDynamicUnRegisterIMInstantiateCallback; - return True; -} - - -typedef XOM (*dynamicIOpenProcp)( - XLCd, Display *, XrmDatabase, _Xconst char *, _Xconst char *); - -static XOM -_XDynamicOpenOM(XLCd lcd, Display *display, XrmDatabase rdb, - _Xconst char *res_name, _Xconst char *res_class) -{ - XOM om = (XOM)NULL; - int count; - char lc_dir[BUFSIZE]; - char *lc_name; - dynamicIOpenProcp om_openOM = (dynamicIOpenProcp)NULL; - XI18NObjectsList objects_list = xi18n_objects_list; -#if defined(hpux) - int getsyms_cnt, i; - struct shl_symbol *symbols; -#endif - - lc_name = lcd->core->name; - - if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XOM)0; - - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XOM_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - if (!open_object (objects_list, lc_dir)) - continue; - - om_openOM = (dynamicIOpenProcp)fetch_symbol(objects_list, objects_list->open); - if (!om_openOM) continue; - om = (*om_openOM)(lcd, display, rdb, res_name, res_class); - if (om != (XOM)NULL) { - break; - } - close_object(objects_list); - } - return (XOM)om; -} - -Bool -_XInitDynamicOM(XLCd lcd) -{ - if(lcd == (XLCd)NULL) - return False; - - lcd->methods->open_om = _XDynamicOpenOM; - - return True; -} +/* +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 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. + */ + + +#ifdef HAVE_CONFIG_H +# include +#else +# if defined(hpux) +# define HAVE_DL_H +# else +# define HAVE_DLFCN_H +# endif +#endif + +#include + +#ifdef HAVE_DL_H +#include +#endif + +#ifdef HAVE_DLFCN_H +#include +#endif + +#include + +#include "Xlibint.h" +#include "XlcPublic.h" +#include "XlcPubI.h" + +#define XI18N_DLREL 2 + +#define iscomment(ch) ((ch) == '\0' || (ch) == '#') + +typedef enum { + XLC_OBJECT, + XIM_OBJECT, + XOM_OBJECT +} XI18NDLType; + +typedef struct { + XI18NDLType type; + int locale_name_len; + char *locale_name; + char *dl_name; + char *open; + char *im_register; + char *im_unregister; + int dl_release; + unsigned int refcount; +#if defined(hpux) + shl_t dl_module; +#else + void *dl_module; +#endif +} XI18NObjectsListRec, *XI18NObjectsList; + +#define OBJECT_INIT_LEN 8 +#define OBJECT_INC_LEN 4 +static int lc_len = 0; +static XI18NObjectsListRec *xi18n_objects_list = NULL; +static int lc_count = 0; + +static int +parse_line(char *line, char **argv, int argsize) +{ + int argc = 0; + char *p = line; + + while (argc < argsize) { + while (isspace(*p)) { + ++p; + } + if (iscomment(*p)){ + break; + } + argv[argc++] = p; + while (!isspace(*p)) { + ++p; + } + if (iscomment(*p)) { + break; + } + *p++ = '\0'; + } + return argc; +} + +static char * +strdup_with_underscore(const char *symbol) +{ + char *result; + + if ((result = malloc(strlen(symbol) + 2)) == NULL) + return NULL; + result[0] = '_'; + strcpy(result + 1, symbol); + return result; +} + +#ifndef hpux +static void * +try_both_dlsym (void *handle, char *name) +{ + void *ret; + + ret = dlsym (handle, name); + if (!ret) + { + name = strdup_with_underscore (name); + if (name) + { + ret = dlsym (handle, name); + free (name); + } + } + return ret; +} +#endif + +static void +resolve_object(char *path, const char *lc_name) +{ + char filename[BUFSIZ]; + FILE *fp; + char buf[BUFSIZ]; + + if (lc_len == 0) { /* True only for the 1st time */ + lc_len = OBJECT_INIT_LEN; + xi18n_objects_list = (XI18NObjectsList) + Xmalloc(sizeof(XI18NObjectsListRec) * lc_len); + if (!xi18n_objects_list) return; + } +/* +1266793 +Limit the length of path to prevent stack buffer corruption. + sprintf(filename, "%s/%s", path, "XI18N_OBJS"); +*/ + sprintf(filename, "%.*s/%s", BUFSIZ - 12, path, "XI18N_OBJS"); + fp = fopen(filename, "r"); + if (fp == (FILE *)NULL){ + return; + } + + while (fgets(buf, BUFSIZ, fp) != NULL){ + char *p = buf; + int n; + char *args[6]; + while (isspace(*p)){ + ++p; + } + if (iscomment(*p)){ + continue; + } + + if (lc_count == lc_len) { + lc_len += OBJECT_INC_LEN; + xi18n_objects_list = (XI18NObjectsList) + Xrealloc(xi18n_objects_list, + sizeof(XI18NObjectsListRec) * lc_len); + if (!xi18n_objects_list) return; + } + n = parse_line(p, args, 6); + + if (n == 3 || n == 5) { + if (!strcmp(args[0], "XLC")){ + xi18n_objects_list[lc_count].type = XLC_OBJECT; + } else if (!strcmp(args[0], "XOM")){ + xi18n_objects_list[lc_count].type = XOM_OBJECT; + } else if (!strcmp(args[0], "XIM")){ + xi18n_objects_list[lc_count].type = XIM_OBJECT; + } + xi18n_objects_list[lc_count].dl_name = strdup(args[1]); + xi18n_objects_list[lc_count].open = strdup(args[2]); + xi18n_objects_list[lc_count].dl_release = XI18N_DLREL; + xi18n_objects_list[lc_count].locale_name = strdup(lc_name); + xi18n_objects_list[lc_count].refcount = 0; + xi18n_objects_list[lc_count].dl_module = (void*)NULL; + if (n == 5) { + xi18n_objects_list[lc_count].im_register = strdup(args[3]); + xi18n_objects_list[lc_count].im_unregister = strdup(args[4]); + } else { + xi18n_objects_list[lc_count].im_register = NULL; + xi18n_objects_list[lc_count].im_unregister = NULL; + } + lc_count++; + } + } + fclose(fp); +} + +static char* +__lc_path(const char *dl_name, const char *lc_dir) +{ + char *path; + size_t len; + + /* + * reject this for possible security issue + */ + if (strstr (dl_name, "../")) + return NULL; + + len = (lc_dir ? strlen(lc_dir) : 0 ) + + (dl_name ? strlen(dl_name) : 0) + 10; +#if defined POSTLOCALELIBDIR + len += (strlen(POSTLOCALELIBDIR) + 1); +#endif + path = Xmalloc(len + 1); + + if (strchr(dl_name, '/') != NULL) { + char *slash_p; + slash_p = strrchr(lc_dir, '/'); + *slash_p = '\0'; + strcpy(path, lc_dir); strcat(path, "/"); +#if defined POSTLOCALELIBDIR + strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); +#endif + strcat(path, dl_name); strcat(path, ".so.2"); + *slash_p = '/'; + } else { + strcpy(path, lc_dir); strcat(path, "/"); +#if defined POSTLOCALELIBDIR + strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); +#endif + strcat(path, dl_name); strcat(path, ".so.2"); + } + return path; +} + +/* We reference count dlopen() and dlclose() of modules; unfortunately, + * since XCloseIM, XCloseOM, XlcClose aren't wrapped, but directly + * call the close method of the object, we leak a reference count every + * time we open then close a module. Fixing this would require + * either creating proxy objects or hooks for close_im/close_om + * in XLCd + */ +static Bool +open_object( + XI18NObjectsList object, + char *lc_dir) +{ + char *path; + + if (object->refcount == 0) { + path = __lc_path(object->dl_name, lc_dir); + if (!path) + return False; +#if defined(hpux) + object->dl_module = shl_load(path, BIND_DEFERRED, 0L); +#else + object->dl_module = dlopen(path, RTLD_LAZY); +#endif + Xfree(path); + + if (!object->dl_module) + return False; + } + + object->refcount++; + return True; +} + +static void * +fetch_symbol( + XI18NObjectsList object, + char *symbol) +{ + void *result = NULL; +#if defined(hpux) + int getsyms_cnt, i; + struct shl_symbol *symbols; +#endif + + if (symbol == NULL) + return NULL; + +#if defined(hpux) + getsyms_cnt = shl_getsymbols(object->dl_module, TYPE_PROCEDURE, + EXPORT_SYMBOLS, malloc, &symbols); + + for(i=0; i 0) { + free(symbols); + } +#else + result = try_both_dlsym(object->dl_module, symbol); +#endif + + return result; +} + +static void +close_object(XI18NObjectsList object) +{ + object->refcount--; + if (object->refcount == 0) + { +#if defined(hpux) + shl_unload(object->dl_module); +#else + dlclose(object->dl_module); +#endif + object->dl_module = NULL; + } +} + + +typedef XLCd (*dynamicLoadProc)(const char *); + +XLCd +_XlcDynamicLoad(const char *lc_name) +{ + XLCd lcd = (XLCd)NULL; + dynamicLoadProc lc_loader = (dynamicLoadProc)NULL; + int count; + XI18NObjectsList objects_list; + char lc_dir[BUFSIZE], lc_lib_dir[BUFSIZE]; + + if (lc_name == NULL) return (XLCd)NULL; + + if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char *)NULL) + return (XLCd)NULL; + if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, (char *)lc_name) == (char*)NULL) + return (XLCd)NULL; + + resolve_object(lc_dir, lc_name); + resolve_object(lc_lib_dir, lc_name); + + objects_list = xi18n_objects_list; + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XLC_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + if (!open_object (objects_list, lc_dir) && \ + !open_object (objects_list, lc_lib_dir)) + continue; + + lc_loader = (dynamicLoadProc)fetch_symbol (objects_list, objects_list->open); + if (!lc_loader) continue; + lcd = (*lc_loader)(lc_name); + if (lcd != (XLCd)NULL) { + break; + } + + close_object (objects_list); + } + return (XLCd)lcd; +} + + +typedef XIM (*dynamicOpenProcp)(XLCd, Display *, XrmDatabase, char *, char *); + +static XIM +_XDynamicOpenIM(XLCd lcd, Display *display, XrmDatabase rdb, + char *res_name, char *res_class) +{ + XIM im = (XIM)NULL; + char lc_dir[BUFSIZE]; + char *lc_name; + dynamicOpenProcp im_openIM = (dynamicOpenProcp)NULL; + int count; + XI18NObjectsList objects_list = xi18n_objects_list; + + lc_name = lcd->core->name; + + if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XIM)0; + + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XIM_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + + if (!open_object (objects_list, lc_dir)) + continue; + + im_openIM = (dynamicOpenProcp)fetch_symbol(objects_list, objects_list->open); + if (!im_openIM) continue; + im = (*im_openIM)(lcd, display, rdb, res_name, res_class); + if (im != (XIM)NULL) { + break; + } + + close_object (objects_list); + } + return (XIM)im; +} + +typedef Bool (*dynamicRegisterCBProcp)( + XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); + +static Bool +_XDynamicRegisterIMInstantiateCallback( + XLCd lcd, + Display *display, + XrmDatabase rdb, + char *res_name, + char *res_class, + XIDProc callback, + XPointer client_data) +{ + char lc_dir[BUFSIZE]; + char *lc_name; + dynamicRegisterCBProcp im_registerIM = (dynamicRegisterCBProcp)NULL; + Bool ret_flag = False; + int count; + XI18NObjectsList objects_list = xi18n_objects_list; +#if defined(hpux) + int getsyms_cnt, i; + struct shl_symbol *symbols; +#endif + + lc_name = lcd->core->name; + + if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; + + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XIM_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + + if (!open_object (objects_list, lc_dir)) + continue; + im_registerIM = (dynamicRegisterCBProcp)fetch_symbol(objects_list, + objects_list->im_register); + if (!im_registerIM) continue; + ret_flag = (*im_registerIM)(lcd, display, rdb, + res_name, res_class, + callback, client_data); + if (ret_flag) break; + + close_object (objects_list); + } + return (Bool)ret_flag; +} + +typedef Bool (*dynamicUnregisterProcp)( + XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); + +static Bool +_XDynamicUnRegisterIMInstantiateCallback( + XLCd lcd, + Display *display, + XrmDatabase rdb, + char *res_name, + char *res_class, + XIDProc callback, + XPointer client_data) +{ + char lc_dir[BUFSIZE]; + char *lc_name; + dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL; + Bool ret_flag = False; + int count; + XI18NObjectsList objects_list = xi18n_objects_list; +#if defined(hpux) + int getsyms_cnt, i; + struct shl_symbol *symbols; +#endif + + lc_name = lcd->core->name; + if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; + + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XIM_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + + if (!objects_list->refcount) /* Must already be opened */ + continue; + + im_unregisterIM = (dynamicUnregisterProcp)fetch_symbol(objects_list, + objects_list->im_unregister); + + if (!im_unregisterIM) continue; + ret_flag = (*im_unregisterIM)(lcd, display, rdb, + res_name, res_class, + callback, client_data); + if (ret_flag) { + close_object (objects_list); /* opened in RegisterIMInstantiateCallback */ + break; + } + } + return (Bool)ret_flag; +} + +Bool +_XInitDynamicIM(XLCd lcd) +{ + if(lcd == (XLCd)NULL) + return False; + lcd->methods->open_im = _XDynamicOpenIM; + lcd->methods->register_callback = _XDynamicRegisterIMInstantiateCallback; + lcd->methods->unregister_callback = _XDynamicUnRegisterIMInstantiateCallback; + return True; +} + + +typedef XOM (*dynamicIOpenProcp)( + XLCd, Display *, XrmDatabase, _Xconst char *, _Xconst char *); + +static XOM +_XDynamicOpenOM(XLCd lcd, Display *display, XrmDatabase rdb, + _Xconst char *res_name, _Xconst char *res_class) +{ + XOM om = (XOM)NULL; + int count; + char lc_dir[BUFSIZE]; + char *lc_name; + dynamicIOpenProcp om_openOM = (dynamicIOpenProcp)NULL; + XI18NObjectsList objects_list = xi18n_objects_list; +#if defined(hpux) + int getsyms_cnt, i; + struct shl_symbol *symbols; +#endif + + lc_name = lcd->core->name; + + if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XOM)0; + + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XOM_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + if (!open_object (objects_list, lc_dir)) + continue; + + om_openOM = (dynamicIOpenProcp)fetch_symbol(objects_list, objects_list->open); + if (!om_openOM) continue; + om = (*om_openOM)(lcd, display, rdb, res_name, res_class); + if (om != (XOM)NULL) { + break; + } + close_object(objects_list); + } + return (XOM)om; +} + +Bool +_XInitDynamicOM(XLCd lcd) +{ + if(lcd == (XLCd)NULL) + return False; + + lcd->methods->open_om = _XDynamicOpenOM; + + return True; +} diff --git a/libX11/src/xlibi18n/lcCharSet.c b/libX11/src/xlibi18n/lcCharSet.c index 0fa39d869..5d287811c 100644 --- a/libX11/src/xlibi18n/lcCharSet.c +++ b/libX11/src/xlibi18n/lcCharSet.c @@ -176,10 +176,9 @@ _XlcCreateDefaultCharSet( const char *colon; char *tmp; - charset = (XlcCharSet) Xmalloc(sizeof(XlcCharSetRec)); + charset = Xcalloc(1, sizeof(XlcCharSetRec)); if (charset == NULL) return (XlcCharSet) NULL; - bzero((char *) charset, sizeof(XlcCharSetRec)); name_len = strlen(name); ct_sequence_len = strlen(ct_sequence); diff --git a/libX11/src/xlibi18n/lcDB.c b/libX11/src/xlibi18n/lcDB.c index afff17455..97b22ac44 100644 --- a/libX11/src/xlibi18n/lcDB.c +++ b/libX11/src/xlibi18n/lcDB.c @@ -591,26 +591,23 @@ store_to_database( goto err; } - new = (Database)Xmalloc(sizeof(DatabaseRec)); + new = Xcalloc(1, sizeof(DatabaseRec)); if (new == (Database)NULL) { goto err; } - bzero(new, sizeof(DatabaseRec)); - new->category = (char *)Xmalloc(strlen(parse_info.category) + 1); + new->category = strdup(parse_info.category); if (new->category == NULL) { goto err; } - strcpy(new->category, parse_info.category); if (! construct_name(name, sizeof(name))) { goto err; } - new->name = (char *)Xmalloc(strlen(name) + 1); + new->name = strdup(name); if (new->name == NULL) { goto err; } - strcpy(new->name, name); new->next = *db; new->value = parse_info.value; new->value_num = parse_info.value_num; @@ -944,10 +941,9 @@ f_default( case S_NULL: if (parse_info.category != NULL) goto err; - p = (char *)Xmalloc(strlen(wordp) + 1); + p = strdup(wordp); if (p == NULL) goto err; - strcpy(p, wordp); parse_info.category = p; parse_info.pre_state = S_CATEGORY; break; @@ -961,10 +957,9 @@ f_default( break; } } - p = (char *)Xmalloc(strlen(wordp) + 1); + p = strdup(wordp); if (p == NULL) goto err; - strcpy(p, wordp); if (parse_info.name[parse_info.nest_depth] != NULL) { Xfree(parse_info.name[parse_info.nest_depth]); } @@ -1309,10 +1304,9 @@ _XlcCreateLocaleDataBase( return (XPointer)NULL; } n = CountDatabase(database); - lc_db = (XlcDatabase)Xmalloc(sizeof(XlcDatabaseRec) * (n + 1)); + lc_db = Xcalloc(n + 1, sizeof(XlcDatabaseRec)); if (lc_db == (XlcDatabase)NULL) goto err; - bzero(lc_db, sizeof(XlcDatabaseRec) * (n + 1)); for (p = database, i = 0; p && i < n; p = p->next, ++i) { lc_db[i].category_q = XrmStringToQuark(p->category); lc_db[i].name_q = XrmStringToQuark(p->name); diff --git a/libX11/src/xlibi18n/lcFile.c b/libX11/src/xlibi18n/lcFile.c index 18756c1ca..4e4439773 100644 --- a/libX11/src/xlibi18n/lcFile.c +++ b/libX11/src/xlibi18n/lcFile.c @@ -423,10 +423,7 @@ resolve_name( from = args[1], to = args[0]; /* right to left */ } if (! strcmp(from, lc_name)) { - name = Xmalloc(strlen(to) + 1); - if (name != NULL) { - strcpy(name, to); - } + name = strdup(to); break; } } @@ -579,8 +576,7 @@ _XlcResolveLocaleName( if (name == NULL) { /* vendor locale name == Xlocale name, no expansion of alias */ - pub->siname = Xmalloc (strlen (lc_name) + 1); - strcpy (pub->siname, lc_name); + pub->siname = strdup (lc_name); } else { pub->siname = name; } @@ -729,8 +725,7 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) last_dir_len = strlen (dir_name) + 1; last_dir_name = Xmalloc (last_dir_len); strcpy (last_dir_name, dir_name); - last_lc_name = Xmalloc (strlen (lc_name) + 1); - strcpy (last_lc_name, lc_name); + last_lc_name = strdup (lc_name); return dir_name; } @@ -828,8 +823,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) last_dir_len = strlen (dir_name) + 1; last_dir_name = Xmalloc (last_dir_len); strcpy (last_dir_name, dir_name); - last_lc_name = Xmalloc (strlen (lc_name) + 1); - strcpy (last_lc_name, lc_name); + last_lc_name = strdup (lc_name); return dir_name; } diff --git a/libX11/src/xlibi18n/lcGeneric.c b/libX11/src/xlibi18n/lcGeneric.c index 688a4cfc4..619cb47f9 100644 --- a/libX11/src/xlibi18n/lcGeneric.c +++ b/libX11/src/xlibi18n/lcGeneric.c @@ -60,15 +60,13 @@ create( XLCd lcd; XLCdPublicMethods new; - lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + lcd = Xcalloc(1, sizeof(XLCdRec)); if (lcd == NULL) return (XLCd) NULL; - bzero((char *) lcd, sizeof(XLCdRec)); - lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdGenericRec)); + lcd->core = Xcalloc(1, sizeof(XLCdGenericRec)); if (lcd->core == NULL) goto err; - bzero((char *) lcd->core, sizeof(XLCdGenericRec)); new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) @@ -180,10 +178,9 @@ add_codeset( CodeSet new, *new_list; int num; - new = (CodeSet) Xmalloc(sizeof(CodeSetRec)); + new = Xcalloc(1, sizeof(CodeSetRec)); if (new == NULL) return NULL; - bzero((char *) new, sizeof(CodeSetRec)); if ((num = gen->codeset_num)) new_list = (CodeSet *) Xrealloc(gen->codeset_list, @@ -218,21 +215,18 @@ add_parse_list( unsigned char ch; int num; - str = (char *) Xmalloc(strlen(encoding) + 1); + str = strdup(encoding); if (str == NULL) return False; - strcpy(str, encoding); - new = (ParseInfo) Xmalloc(sizeof(ParseInfoRec)); + new = Xcalloc(1, sizeof(ParseInfoRec)); if (new == NULL) goto err; - bzero((char *) new, sizeof(ParseInfoRec)); if (gen->mb_parse_table == NULL) { - gen->mb_parse_table = (unsigned char *) Xmalloc(256); /* 2^8 */ + gen->mb_parse_table = Xcalloc(1, 256); /* 2^8 */ if (gen->mb_parse_table == NULL) goto err; - bzero((char *) gen->mb_parse_table, 256); } if ((num = gen->mb_parse_list_num)) @@ -468,10 +462,9 @@ read_charset_define( break; } if (new) { - tmp = (char *)Xmalloc(strlen(cset_name)+1); + tmp = strdup(cset_name); if (tmp == NULL) return; - strcpy(tmp,cset_name); charsetd->name = tmp; } /* side */ @@ -527,8 +520,7 @@ read_charset_define( Xfree(charsetd->encoding_name); } */ - tmp = (char *)Xmalloc(strlen(value[0])+1); - strcpy(tmp,value[0]); + tmp = strdup(value[0]); charsetd->encoding_name = tmp; charsetd->xrm_encoding_name = XrmStringToQuark(tmp); } @@ -598,10 +590,9 @@ read_segmentconversion( if (num > 0) { char *tmp; _XlcDbg_printValue(name,value,num); - tmp = (char *)Xmalloc(strlen(value[0])+1); + tmp = strdup(value[0]); if (tmp == NULL) return; - strcpy(tmp,value[0]); conversion->source_encoding = tmp; conversion->source = srch_charset_define(tmp,&new); } @@ -611,10 +602,9 @@ read_segmentconversion( if (num > 0) { char *tmp; _XlcDbg_printValue(name,value,num); - tmp = (char *)Xmalloc(strlen(value[0])+1); + tmp = strdup(value[0]); if (tmp == NULL) return; - strcpy(tmp,value[0]); conversion->destination_encoding = tmp; conversion->dest = srch_charset_define(tmp,&new); } @@ -650,12 +640,11 @@ create_ctextseg( ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec)); if (ret == NULL) return NULL; - ret->name = (char *)Xmalloc(strlen(value[0]) + 1); + ret->name = strdup(value[0]); if (ret->name == NULL) { Xfree (ret); return NULL; } - strcpy(ret->name,value[0]); cset_name = (char*) Xmalloc (strlen(ret->name) + 1); if (cset_name == NULL) { Xfree (ret->name); diff --git a/libX11/src/xlibi18n/lcPublic.c b/libX11/src/xlibi18n/lcPublic.c index 2c02f5fba..1b1fb548a 100644 --- a/libX11/src/xlibi18n/lcPublic.c +++ b/libX11/src/xlibi18n/lcPublic.c @@ -80,15 +80,13 @@ create( XLCd lcd; XLCdPublicMethods new; - lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + lcd = Xcalloc(1, sizeof(XLCdRec)); if (lcd == NULL) return (XLCd) NULL; - bzero((char *) lcd, sizeof(XLCdRec)); - lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec)); + lcd->core = Xcalloc(1, sizeof(XLCdPublicRec)); if (lcd->core == NULL) goto err; - bzero((char *) lcd->core, sizeof(XLCdPublicRec)); new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) @@ -130,10 +128,9 @@ load_public( _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num); str = (num > 0) ? values[0] : "STRING"; - pub->encoding_name = (char*) Xmalloc(strlen(str) + 1); + pub->encoding_name = strdup(str); if (pub->encoding_name == NULL) return False; - strcpy(pub->encoding_name, str); return True; } -- cgit v1.2.3