diff options
Diffstat (limited to 'libX11/modules/im')
-rw-r--r-- | libX11/modules/im/ximcp/imLcFlt.c | 250 | ||||
-rw-r--r-- | libX11/modules/im/ximcp/imLcIc.c | 400 | ||||
-rw-r--r-- | libX11/modules/im/ximcp/imLcLkup.c | 834 | ||||
-rw-r--r-- | libX11/modules/im/ximcp/imRmAttr.c | 3036 | ||||
-rw-r--r-- | libX11/modules/im/ximcp/imTrans.c | 1 | ||||
-rw-r--r-- | libX11/modules/im/ximcp/makefile | 34 |
6 files changed, 2295 insertions, 2260 deletions
diff --git a/libX11/modules/im/ximcp/imLcFlt.c b/libX11/modules/im/ximcp/imLcFlt.c index 06aa9980a..7ab56f8a1 100644 --- a/libX11/modules/im/ximcp/imLcFlt.c +++ b/libX11/modules/im/ximcp/imLcFlt.c @@ -1,125 +1,125 @@ -/****************************************************************** - - Copyright 1992 by Fuji Xerox Co., Ltd. - Copyright 1992, 1994 by FUJITSU LIMITED - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear -in supporting documentation, and that the name of Fuji Xerox, -FUJITSU LIMITED not be used in advertising or publicity pertaining -to distribution of the software without specific, written prior -permission. Fuji Xerox, FUJITSU LIMITED make no representations -about the suitability of this software for any purpose. -It is provided "as is" without express or implied warranty. - -FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX, -FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA -OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - - Author : Kazunori Nishihara Fuji Xerox - Modifier : Takashi Fujiwara FUJITSU LIMITED - fujiwara@a80.tech.yk.fujitsu.co.jp - -******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include <X11/keysym.h> -#include "Xlcint.h" -#include "Ximint.h" - -Bool -_XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data) -{ - Xic ic = (Xic)client_data; - KeySym keysym; - static char buf[256]; - DefTree *b = ic->private.local.base.tree; - DTIndex t; - Bool braille = False; - - if(ev->xkey.keycode == 0) - return (False); - - XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL); - - if(IsModifierKey(keysym)) - return (False); - - if(keysym >= XK_braille_dot_1 && keysym <= XK_braille_dot_8) { - if(ev->type == KeyPress) { - ic->private.local.brl_pressed |= - 1<<(keysym-XK_braille_dot_1); - return(True); - } else { - if(!ic->private.local.brl_committing - || ev->xkey.time - ic->private.local.brl_release_start > 300) { - ic->private.local.brl_committing = ic->private.local.brl_pressed; - ic->private.local.brl_release_start = ev->xkey.time; - } - ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1)); - if(!ic->private.local.brl_pressed && ic->private.local.brl_committing) { - /* Commited a braille pattern, let it go through compose tree */ - keysym = XK_braille_blank | ic->private.local.brl_committing; - ev->type = KeyPress; - braille = True; - } else { - return(True); - } - } - } - - if( (ev->type != KeyPress) - || (((Xim)ic->core.im)->private.local.top == 0 ) ) - goto emit_braille; - - for(t = ic->private.local.context; t; t = b[t].next) { - if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) && - (keysym == b[t].keysym)) - break; - } - - if(t) { /* Matched */ - if(b[t].succession) { /* Intermediate */ - ic->private.local.context = b[t].succession; - return(True); - } else { /* Terminate (reached to leaf) */ - ic->private.local.composed = t; - ic->private.local.brl_committed = 0; - /* return back to client KeyPressEvent keycode == 0 */ - ev->xkey.keycode = 0; - XPutBackEvent(d, ev); - /* initialize internal state for next key sequence */ - ic->private.local.context = ((Xim)ic->core.im)->private.local.top; - return(True); - } - } else { /* Unmatched */ - if(ic->private.local.context == ((Xim)ic->core.im)->private.local.top) { - goto emit_braille; - } - /* Error (Sequence Unmatch occured) */ - /* initialize internal state for next key sequence */ - ic->private.local.context = ((Xim)ic->core.im)->private.local.top; - return(True); - } - -emit_braille: - if(braille) { - /* Braille pattern is not in compose tree, emit alone */ - ic->private.local.brl_committed = ic->private.local.brl_committing; - ic->private.local.composed = 0; - ev->xkey.keycode = 0; - _XPutBackEvent(d, ev); - return(True); - } - return(False); -} +/******************************************************************
+
+ Copyright 1992 by Fuji Xerox Co., Ltd.
+ Copyright 1992, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Fuji Xerox,
+FUJITSU LIMITED not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission. Fuji Xerox, FUJITSU LIMITED make no representations
+about the suitability of this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
+FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author : Kazunori Nishihara Fuji Xerox
+ Modifier : Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include <X11/keysym.h>
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Bool
+_XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
+{
+ Xic ic = (Xic)client_data;
+ KeySym keysym;
+ static char buf[256];
+ DefTree *b = ic->private.local.base.tree;
+ DTIndex t;
+ Bool braille = False;
+
+ if(ev->xkey.keycode == 0)
+ return (False);
+
+ XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL);
+
+ if(IsModifierKey(keysym))
+ return (False);
+
+ if(keysym >= XK_braille_dot_1 && keysym <= XK_braille_dot_8) {
+ if(ev->type == KeyPress) {
+ ic->private.local.brl_pressed |=
+ 1<<(keysym-XK_braille_dot_1);
+ return(True);
+ } else {
+ if(!ic->private.local.brl_committing
+ || ev->xkey.time - ic->private.local.brl_release_start > 300) {
+ ic->private.local.brl_committing = ic->private.local.brl_pressed;
+ ic->private.local.brl_release_start = ev->xkey.time;
+ }
+ ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1));
+ if(!ic->private.local.brl_pressed && ic->private.local.brl_committing) {
+ /* Commited a braille pattern, let it go through compose tree */
+ keysym = XK_braille_blank | ic->private.local.brl_committing;
+ ev->type = KeyPress;
+ braille = True;
+ } else {
+ return(True);
+ }
+ }
+ }
+
+ if( (ev->type != KeyPress)
+ || (((Xim)ic->core.im)->private.local.top == 0 ) )
+ goto emit_braille;
+
+ for(t = ic->private.local.context; t; t = b[t].next) {
+ if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) &&
+ (keysym == b[t].keysym))
+ break;
+ }
+
+ if(t) { /* Matched */
+ if(b[t].succession) { /* Intermediate */
+ ic->private.local.context = b[t].succession;
+ return(True);
+ } else { /* Terminate (reached to leaf) */
+ ic->private.local.composed = t;
+ ic->private.local.brl_committed = 0;
+ /* return back to client KeyPressEvent keycode == 0 */
+ ev->xkey.keycode = 0;
+ XPutBackEvent(d, ev);
+ /* initialize internal state for next key sequence */
+ ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
+ return(True);
+ }
+ } else { /* Unmatched */
+ if(ic->private.local.context == ((Xim)ic->core.im)->private.local.top) {
+ goto emit_braille;
+ }
+ /* Error (Sequence Unmatch occured) */
+ /* initialize internal state for next key sequence */
+ ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
+ return(True);
+ }
+
+emit_braille:
+ if(braille) {
+ /* Braille pattern is not in compose tree, emit alone */
+ ic->private.local.brl_committed = ic->private.local.brl_committing;
+ ic->private.local.composed = 0;
+ ev->xkey.keycode = 0;
+ _XPutBackEvent(d, ev);
+ return(True);
+ }
+ return(False);
+}
diff --git a/libX11/modules/im/ximcp/imLcIc.c b/libX11/modules/im/ximcp/imLcIc.c index c0728084f..04de3c1bd 100644 --- a/libX11/modules/im/ximcp/imLcIc.c +++ b/libX11/modules/im/ximcp/imLcIc.c @@ -1,200 +1,200 @@ -/****************************************************************** - - Copyright 1992,1993, 1994 by FUJITSU LIMITED - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear -in supporting documentation, and that the name of FUJITSU LIMITED -not be used in advertising or publicity pertaining to distribution -of the software without specific, written prior permission. -FUJITSU LIMITED makes no representations about the suitability of -this software for any purpose. -It is provided "as is" without express or implied warranty. - -FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - - Author: Takashi Fujiwara FUJITSU LIMITED - fujiwara@a80.tech.yk.fujitsu.co.jp - -******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <stdio.h> -#include <X11/Xlib.h> -#include <X11/Xmd.h> -#include "Xlibint.h" -#include "Xlcint.h" -#include "Ximint.h" - -Private void -_XimLocalUnSetFocus( - XIC xic) -{ - Xic ic = (Xic)xic; - ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL; - - if (ic->core.focus_window) - _XUnregisterFilter(ic->core.im->core.display, - ic->core.focus_window, _XimLocalFilter, (XPointer)ic); - return; -} - -Private void -_XimLocalDestroyIC( - XIC xic) -{ - Xic ic = (Xic)xic; - - if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) { - ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL; - } - if (ic->core.focus_window) - _XUnregisterFilter(ic->core.im->core.display, - ic->core.focus_window, _XimLocalFilter, (XPointer)ic); - if(ic->private.local.ic_resources) { - Xfree(ic->private.local.ic_resources); - ic->private.local.ic_resources = NULL; - } - return; -} - -Private void -_XimLocalSetFocus( - XIC xic) -{ - Xic ic = (Xic)xic; - XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic; - - if (current_ic == (XIC)ic) - return; - - if (current_ic != (XIC)NULL) { - _XimLocalUnSetFocus(current_ic); - } - ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic; - - if (ic->core.focus_window) - _XRegisterFilterByType(ic->core.im->core.display, - ic->core.focus_window, KeyPress, KeyRelease, - _XimLocalFilter, (XPointer)ic); - return; -} - -Private void -_XimLocalReset( - XIC xic) -{ - Xic ic = (Xic)xic; - ic->private.local.composed = 0; - ic->private.local.context = ((Xim)ic->core.im)->private.local.top; - ic->private.local.brl_pressed = 0; - ic->private.local.brl_committing = 0; - ic->private.local.brl_committed = 0; -} - -Private char * -_XimLocalMbReset( - XIC xic) -{ - _XimLocalReset(xic); - return (char *)NULL; -} - -Private wchar_t * -_XimLocalWcReset( - XIC xic) -{ - _XimLocalReset(xic); - return (wchar_t *)NULL; -} - -Private XICMethodsRec Local_ic_methods = { - _XimLocalDestroyIC, /* destroy */ - _XimLocalSetFocus, /* set_focus */ - _XimLocalUnSetFocus, /* unset_focus */ - _XimLocalSetICValues, /* set_values */ - _XimLocalGetICValues, /* get_values */ - _XimLocalMbReset, /* mb_reset */ - _XimLocalWcReset, /* wc_reset */ - _XimLocalMbReset, /* utf8_reset */ - _XimLocalMbLookupString, /* mb_lookup_string */ - _XimLocalWcLookupString, /* wc_lookup_string */ - _XimLocalUtf8LookupString /* utf8_lookup_string */ -}; - -Public XIC -_XimLocalCreateIC( - XIM im, - XIMArg *values) -{ - Xic ic; - XimDefICValues ic_values; - XIMResourceList res; - unsigned int num; - int len; - - if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) { - return ((XIC)NULL); - } - bzero((char *)ic, sizeof(XicRec)); - - ic->methods = &Local_ic_methods; - ic->core.im = im; - ic->private.local.base = ((Xim)im)->private.local.base; - ic->private.local.context = ((Xim)im)->private.local.top; - ic->private.local.composed = 0; - ic->private.local.brl_pressed = 0; - ic->private.local.brl_committing = 0; - ic->private.local.brl_committed = 0; - - num = im->core.ic_num_resources; - len = sizeof(XIMResource) * num; - if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) { - goto Set_Error; - } - (void)memcpy((char *)res, (char *)im->core.ic_resources, len); - ic->private.local.ic_resources = res; - ic->private.local.ic_num_resources = num; - - bzero((char *)&ic_values, sizeof(XimDefICValues)); - if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values, - im->core.styles, res, num) == False) { - goto Set_Error; - } - - _XimSetICMode(res, num, ic_values.input_style); - - if(_XimSetICValueData(ic, (XPointer)&ic_values, - ic->private.local.ic_resources, - ic->private.local.ic_num_resources, - values, XIM_CREATEIC, True)) { - goto Set_Error; - } - ic_values.filter_events = KeyPressMask | KeyReleaseMask; - _XimSetCurrentICValues(ic, &ic_values); - if(_XimSetICDefaults(ic, (XPointer)&ic_values, - XIM_SETICDEFAULTS, res, num) == False) { - goto Set_Error; - } - _XimSetCurrentICValues(ic, &ic_values); - - return((XIC)ic); - -Set_Error : - if (ic->private.local.ic_resources) { - Xfree(ic->private.local.ic_resources); - ic->private.local.ic_resources = NULL; - } - Xfree(ic); - return((XIC)NULL); -} +/******************************************************************
+
+ Copyright 1992,1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlib.h>
+#include <X11/Xmd.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Private void
+_XimLocalUnSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
+
+ if (ic->core.focus_window)
+ _XUnregisterFilter(ic->core.im->core.display,
+ ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
+ return;
+}
+
+Private void
+_XimLocalDestroyIC(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+
+ if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
+ }
+ if (ic->core.focus_window)
+ _XUnregisterFilter(ic->core.im->core.display,
+ ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
+ if(ic->private.local.ic_resources) {
+ Xfree(ic->private.local.ic_resources);
+ ic->private.local.ic_resources = NULL;
+ }
+ return;
+}
+
+Private void
+_XimLocalSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
+
+ if (current_ic == (XIC)ic)
+ return;
+
+ if (current_ic != (XIC)NULL) {
+ _XimLocalUnSetFocus(current_ic);
+ }
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
+
+ if (ic->core.focus_window)
+ _XRegisterFilterByType(ic->core.im->core.display,
+ ic->core.focus_window, KeyPress, KeyRelease,
+ _XimLocalFilter, (XPointer)ic);
+ return;
+}
+
+Private void
+_XimLocalReset(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ ic->private.local.composed = 0;
+ ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
+ ic->private.local.brl_pressed = 0;
+ ic->private.local.brl_committing = 0;
+ ic->private.local.brl_committed = 0;
+}
+
+Private char *
+_XimLocalMbReset(
+ XIC xic)
+{
+ _XimLocalReset(xic);
+ return (char *)NULL;
+}
+
+Private wchar_t *
+_XimLocalWcReset(
+ XIC xic)
+{
+ _XimLocalReset(xic);
+ return (wchar_t *)NULL;
+}
+
+Private XICMethodsRec Local_ic_methods = {
+ _XimLocalDestroyIC, /* destroy */
+ _XimLocalSetFocus, /* set_focus */
+ _XimLocalUnSetFocus, /* unset_focus */
+ _XimLocalSetICValues, /* set_values */
+ _XimLocalGetICValues, /* get_values */
+ _XimLocalMbReset, /* mb_reset */
+ _XimLocalWcReset, /* wc_reset */
+ _XimLocalMbReset, /* utf8_reset */
+ _XimLocalMbLookupString, /* mb_lookup_string */
+ _XimLocalWcLookupString, /* wc_lookup_string */
+ _XimLocalUtf8LookupString /* utf8_lookup_string */
+};
+
+Public XIC
+_XimLocalCreateIC(
+ XIM im,
+ XIMArg *values)
+{
+ Xic ic;
+ XimDefICValues ic_values;
+ XIMResourceList res;
+ unsigned int num;
+ int len;
+
+ if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) {
+ return ((XIC)NULL);
+ }
+ bzero((char *)ic, sizeof(XicRec));
+
+ ic->methods = &Local_ic_methods;
+ ic->core.im = im;
+ ic->private.local.base = ((Xim)im)->private.local.base;
+ ic->private.local.context = ((Xim)im)->private.local.top;
+ ic->private.local.composed = 0;
+ ic->private.local.brl_pressed = 0;
+ ic->private.local.brl_committing = 0;
+ ic->private.local.brl_committed = 0;
+
+ num = im->core.ic_num_resources;
+ len = sizeof(XIMResource) * num;
+ if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) {
+ goto Set_Error;
+ }
+ (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
+ ic->private.local.ic_resources = res;
+ ic->private.local.ic_num_resources = num;
+
+ bzero((char *)&ic_values, sizeof(XimDefICValues));
+ if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
+ im->core.styles, res, num) == False) {
+ goto Set_Error;
+ }
+
+ _XimSetICMode(res, num, ic_values.input_style);
+
+ if(_XimSetICValueData(ic, (XPointer)&ic_values,
+ ic->private.local.ic_resources,
+ ic->private.local.ic_num_resources,
+ values, XIM_CREATEIC, True)) {
+ goto Set_Error;
+ }
+ ic_values.filter_events = KeyPressMask | KeyReleaseMask;
+ _XimSetCurrentICValues(ic, &ic_values);
+ if(_XimSetICDefaults(ic, (XPointer)&ic_values,
+ XIM_SETICDEFAULTS, res, num) == False) {
+ goto Set_Error;
+ }
+ _XimSetCurrentICValues(ic, &ic_values);
+
+ return((XIC)ic);
+
+Set_Error :
+ if (ic->private.local.ic_resources) {
+ Xfree(ic->private.local.ic_resources);
+ ic->private.local.ic_resources = NULL;
+ }
+ Xfree(ic);
+ return((XIC)NULL);
+}
diff --git a/libX11/modules/im/ximcp/imLcLkup.c b/libX11/modules/im/ximcp/imLcLkup.c index 8e4111a6a..c62a9106c 100644 --- a/libX11/modules/im/ximcp/imLcLkup.c +++ b/libX11/modules/im/ximcp/imLcLkup.c @@ -1,417 +1,417 @@ -/****************************************************************** - - Copyright 1992 by Fuji Xerox Co., Ltd. - Copyright 1992, 1994 by FUJITSU LIMITED - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear -in supporting documentation, and that the name of Fuji Xerox, -FUJITSU LIMITED not be used in advertising or publicity pertaining -to distribution of the software without specific, written prior -permission. Fuji Xerox, FUJITSU LIMITED make no representations -about the suitability of this software for any purpose. -It is provided "as is" without express or implied warranty. - -FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX, -FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA -OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - - Author: Kazunori Nishihara Fuji Xerox - Takashi Fujiwara FUJITSU LIMITED - fujiwara@a80.tech.yk.fujitsu.co.jp - -******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <stdio.h> -#include <X11/Xatom.h> -#include <X11/Xos.h> -#include <X11/Xlib.h> -#include <X11/keysym.h> -#include <X11/Xutil.h> -#include "Xlibint.h" -#include "Xlcint.h" -#include "XlcPubI.h" -#include "Ximint.h" - -Public int -_XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, - KeySym *keysym, Status *status) -{ - Xic ic = (Xic)xic; - int ret; - DefTree *b = ic->private.local.base.tree; - char *mb = ic->private.local.base.mb; - - if(ev->type != KeyPress) { - if(status) *status = XLookupNone; - return(0); - } - if(ev->keycode == 0 && - ( (ic->private.local.composed != 0) - ||(ic->private.local.brl_committed != 0))) { - if (ic->private.local.brl_committed != 0) { /* Braille Event */ - unsigned char pattern = ic->private.local.brl_committed; - char mb[XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max)]; - ret = _Xlcwctomb(ic->core.im->core.lcd, mb, BRL_UC_ROW | pattern); - if(ret > bytes) { - if(status) *status = XBufferOverflow; - return(ret); - } - if(keysym) *keysym = XK_braille_blank | pattern; - if(ret > 0) { - if (keysym) { - if(status) *status = XLookupBoth; - } else { - if(status) *status = XLookupChars; - } - memcpy(buffer, mb, ret); - } else { - if(keysym) { - if(status) *status = XLookupKeySym; - } else { - if(status) *status = XLookupNone; - } - } - } else { /* Composed Event */ - ret = strlen(&mb[b[ic->private.local.composed].mb]); - if(ret > bytes) { - if(status) *status = XBufferOverflow; - return(ret); - } - memcpy(buffer, &mb[b[ic->private.local.composed].mb], ret); - if(keysym) *keysym = b[ic->private.local.composed].ks; - if (ret > 0) { - if (keysym && *keysym != NoSymbol) { - if(status) *status = XLookupBoth; - } else { - if(status) *status = XLookupChars; - } - } else { - if(keysym && *keysym != NoSymbol) { - if(status) *status = XLookupKeySym; - } else { - if(status) *status = XLookupNone; - } - } - } - return (ret); - } else { /* Throughed Event */ - ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL); - if(ret > 0) { - if (ret > bytes) { - if (status) *status = XBufferOverflow; - } else if (keysym && *keysym != NoSymbol) { - if(status) *status = XLookupBoth; - } else { - if(status) *status = XLookupChars; - } - } else { - if(keysym && *keysym != NoSymbol) { - if(status) *status = XLookupKeySym; - } else { - if(status) *status = XLookupNone; - } - } - } - return (ret); -} - -Public int -_XimLocalWcLookupString(XIC xic, XKeyEvent *ev, wchar_t *buffer, int wlen, - KeySym *keysym, Status *status) -{ - Xic ic = (Xic)xic; - int ret; - DefTree *b = ic->private.local.base.tree; - wchar_t *wc = ic->private.local.base.wc; - - if(ev->type != KeyPress) { - if(status) *status = XLookupNone; - return(0); - } - if(ev->keycode == 0) { - if (ic->private.local.brl_committed != 0) { /* Braille Event */ - unsigned char pattern = ic->private.local.brl_committed; - ret = 1; - if (ret > wlen) { - if(status) *status = XBufferOverflow; - return (ret); - } - *buffer = BRL_UC_ROW | pattern; - if(keysym) { - *keysym = XK_braille_blank | pattern; - if(status) *status = XLookupBoth; - } else - if(status) *status = XLookupChars; - } else { /* Composed Event */ - ret = _Xwcslen(&wc[b[ic->private.local.composed].wc]); - if(ret > wlen) { - if(status) *status = XBufferOverflow; - return (ret); - } - memcpy((char *)buffer, (char *)&wc[b[ic->private.local.composed].wc], - ret * sizeof(wchar_t)); - if(keysym) *keysym = b[ic->private.local.composed].ks; - if (ret > 0) { - if (keysym && *keysym != NoSymbol) { - if(status) *status = XLookupBoth; - } else { - if(status) *status = XLookupChars; - } - } else { - if(keysym && *keysym != NoSymbol) { - if(status) *status = XLookupKeySym; - } else { - if(status) *status = XLookupNone; - } - } - } - return (ret); - } else { /* Throughed Event */ - ret = _XimLookupWCText(ic, ev, buffer, wlen, keysym, NULL); - if(ret > 0) { - if (ret > wlen) { - if (status) *status = XBufferOverflow; - } else if (keysym && *keysym != NoSymbol) { - if(status) *status = XLookupBoth; - } else { - if(status) *status = XLookupChars; - } - } else { - if(keysym && *keysym != NoSymbol) { - if(status) *status = XLookupKeySym; - } else { - if(status) *status = XLookupNone; - } - } - } - return (ret); -} - -Public int -_XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, - KeySym *keysym, Status *status) -{ - Xic ic = (Xic)xic; - int ret; - DefTree *b = ic->private.local.base.tree; - char *utf8 = ic->private.local.base.utf8; - - if(ev->type != KeyPress) { - if(status) *status = XLookupNone; - return(0); - } - if(ev->keycode == 0) { - if (ic->private.local.brl_committed != 0) { /* Braille Event */ - unsigned char pattern = ic->private.local.brl_committed; - ret = 3; - if (ret > bytes) { - if(status) *status = XBufferOverflow; - return (ret); - } - buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f); - buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6); - buffer[2] = 0x80 | (pattern & 0x3f); - if(keysym) { - *keysym = XK_braille_blank | pattern; - if(status) *status = XLookupBoth; - } else - if(status) *status = XLookupChars; - } else { /* Composed Event */ - ret = strlen(&utf8[b[ic->private.local.composed].utf8]); - if(ret > bytes) { - if(status) *status = XBufferOverflow; - return (ret); - } - memcpy(buffer, &utf8[b[ic->private.local.composed].utf8], ret); - if(keysym) *keysym = b[ic->private.local.composed].ks; - if (ret > 0) { - if (keysym && *keysym != NoSymbol) { - if(status) *status = XLookupBoth; - } else { - if(status) *status = XLookupChars; - } - } else { - if(keysym && *keysym != NoSymbol) { - if(status) *status = XLookupKeySym; - } else { - if(status) *status = XLookupNone; - } - } - } - return (ret); - } else { /* Throughed Event */ - ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL); - if(ret > 0) { - if (ret > bytes) { - if (status) *status = XBufferOverflow; - } else if (keysym && *keysym != NoSymbol) { - if(status) *status = XLookupBoth; - } else { - if(status) *status = XLookupChars; - } - } else { - if(keysym && *keysym != NoSymbol) { - if(status) *status = XLookupKeySym; - } else { - if(status) *status = XLookupNone; - } - } - } - return (ret); -} - -Private int -_XimLcctsconvert( - XlcConv conv, - char *from, - int from_len, - char *to, - int to_len, - Status *state) -{ - int from_left; - int to_left; - int from_savelen; - int to_savelen; - int from_cnvlen; - int to_cnvlen; - char *from_buf; - char *to_buf; - char scratchbuf[BUFSIZ]; - Status tmp_state; - - if (!state) - state = &tmp_state; - - if (!conv || !from || !from_len) { - *state = XLookupNone; - return 0; - } - - /* Reset the converter. The CompoundText at 'from' starts in - initial state. */ - _XlcResetConverter(conv); - - from_left = from_len; - to_left = BUFSIZ; - from_cnvlen = 0; - to_cnvlen = 0; - for (;;) { - from_buf = &from[from_cnvlen]; - from_savelen = from_left; - to_buf = &scratchbuf[to_cnvlen]; - to_savelen = to_left; - if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left, - (XPointer *)&to_buf, &to_left, NULL, 0) < 0) { - *state = XLookupNone; - return 0; - } - from_cnvlen += (from_savelen - from_left); - to_cnvlen += (to_savelen - to_left); - if (from_left == 0) { - if (!to_cnvlen) { - *state = XLookupNone; - return 0; - } - break; - } - } - - if (!to || !to_len || (to_len < to_cnvlen)) { - *state = XBufferOverflow; - } else { - memcpy(to, scratchbuf, to_cnvlen); - *state = XLookupChars; - } - return to_cnvlen; -} - -Public int -_XimLcctstombs(XIM xim, char *from, int from_len, - char *to, int to_len, Status *state) -{ - return _XimLcctsconvert(((Xim)xim)->private.local.ctom_conv, - from, from_len, to, to_len, state); -} - -Public int -_XimLcctstowcs(XIM xim, char *from, int from_len, - wchar_t *to, int to_len, Status *state) -{ - Xim im = (Xim)xim; - XlcConv conv = im->private.local.ctow_conv; - int from_left; - int to_left; - int from_savelen; - int to_savelen; - int from_cnvlen; - int to_cnvlen; - char *from_buf; - wchar_t *to_buf; - wchar_t scratchbuf[BUFSIZ]; - Status tmp_state; - - if (!state) - state = &tmp_state; - - if (!conv || !from || !from_len) { - *state = XLookupNone; - return 0; - } - - /* Reset the converter. The CompoundText at 'from' starts in - initial state. */ - _XlcResetConverter(conv); - - from_left = from_len; - to_left = BUFSIZ; - from_cnvlen = 0; - to_cnvlen = 0; - for (;;) { - from_buf = &from[from_cnvlen]; - from_savelen = from_left; - to_buf = &scratchbuf[to_cnvlen]; - to_savelen = to_left; - if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left, - (XPointer *)&to_buf, &to_left, NULL, 0) < 0) { - *state = XLookupNone; - return 0; - } - from_cnvlen += (from_savelen - from_left); - to_cnvlen += (to_savelen - to_left); - if (from_left == 0) { - if (!to_cnvlen){ - *state = XLookupNone; - return 0; - } - break; - } - } - - if (!to || !to_len || (to_len < to_cnvlen)) { - *state = XBufferOverflow; - } else { - memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t)); - *state = XLookupChars; - } - return to_cnvlen; -} - -Public int -_XimLcctstoutf8(XIM xim, char *from, int from_len, - char *to, int to_len, Status *state) -{ - return _XimLcctsconvert(((Xim)xim)->private.local.ctoutf8_conv, - from, from_len, to, to_len, state); -} +/******************************************************************
+
+ Copyright 1992 by Fuji Xerox Co., Ltd.
+ Copyright 1992, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Fuji Xerox,
+FUJITSU LIMITED not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission. Fuji Xerox, FUJITSU LIMITED make no representations
+about the suitability of this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
+FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Kazunori Nishihara Fuji Xerox
+ Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xatom.h>
+#include <X11/Xos.h>
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#include <X11/Xutil.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcPubI.h"
+#include "Ximint.h"
+
+Public int
+_XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
+ KeySym *keysym, Status *status)
+{
+ Xic ic = (Xic)xic;
+ int ret;
+ DefTree *b = ic->private.local.base.tree;
+ char *mb = ic->private.local.base.mb;
+
+ if(ev->type != KeyPress) {
+ if(status) *status = XLookupNone;
+ return(0);
+ }
+ if(ev->keycode == 0 &&
+ ( (ic->private.local.composed != 0)
+ ||(ic->private.local.brl_committed != 0))) {
+ if (ic->private.local.brl_committed != 0) { /* Braille Event */
+ unsigned char pattern = ic->private.local.brl_committed;
+ char *mb=alloca(XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max));
+ ret = _Xlcwctomb(ic->core.im->core.lcd, mb, BRL_UC_ROW | pattern);
+ if(ret > bytes) {
+ if(status) *status = XBufferOverflow;
+ return(ret);
+ }
+ if(keysym) *keysym = XK_braille_blank | pattern;
+ if(ret > 0) {
+ if (keysym) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ memcpy(buffer, mb, ret);
+ } else {
+ if(keysym) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ } else { /* Composed Event */
+ ret = strlen(&mb[b[ic->private.local.composed].mb]);
+ if(ret > bytes) {
+ if(status) *status = XBufferOverflow;
+ return(ret);
+ }
+ memcpy(buffer, &mb[b[ic->private.local.composed].mb], ret);
+ if(keysym) *keysym = b[ic->private.local.composed].ks;
+ if (ret > 0) {
+ if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+ } else { /* Throughed Event */
+ ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
+ if(ret > 0) {
+ if (ret > bytes) {
+ if (status) *status = XBufferOverflow;
+ } else if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+}
+
+Public int
+_XimLocalWcLookupString(XIC xic, XKeyEvent *ev, wchar_t *buffer, int wlen,
+ KeySym *keysym, Status *status)
+{
+ Xic ic = (Xic)xic;
+ int ret;
+ DefTree *b = ic->private.local.base.tree;
+ wchar_t *wc = ic->private.local.base.wc;
+
+ if(ev->type != KeyPress) {
+ if(status) *status = XLookupNone;
+ return(0);
+ }
+ if(ev->keycode == 0) {
+ if (ic->private.local.brl_committed != 0) { /* Braille Event */
+ unsigned char pattern = ic->private.local.brl_committed;
+ ret = 1;
+ if (ret > wlen) {
+ if(status) *status = XBufferOverflow;
+ return (ret);
+ }
+ *buffer = BRL_UC_ROW | pattern;
+ if(keysym) {
+ *keysym = XK_braille_blank | pattern;
+ if(status) *status = XLookupBoth;
+ } else
+ if(status) *status = XLookupChars;
+ } else { /* Composed Event */
+ ret = _Xwcslen(&wc[b[ic->private.local.composed].wc]);
+ if(ret > wlen) {
+ if(status) *status = XBufferOverflow;
+ return (ret);
+ }
+ memcpy((char *)buffer, (char *)&wc[b[ic->private.local.composed].wc],
+ ret * sizeof(wchar_t));
+ if(keysym) *keysym = b[ic->private.local.composed].ks;
+ if (ret > 0) {
+ if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+ } else { /* Throughed Event */
+ ret = _XimLookupWCText(ic, ev, buffer, wlen, keysym, NULL);
+ if(ret > 0) {
+ if (ret > wlen) {
+ if (status) *status = XBufferOverflow;
+ } else if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+}
+
+Public int
+_XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
+ KeySym *keysym, Status *status)
+{
+ Xic ic = (Xic)xic;
+ int ret;
+ DefTree *b = ic->private.local.base.tree;
+ char *utf8 = ic->private.local.base.utf8;
+
+ if(ev->type != KeyPress) {
+ if(status) *status = XLookupNone;
+ return(0);
+ }
+ if(ev->keycode == 0) {
+ if (ic->private.local.brl_committed != 0) { /* Braille Event */
+ unsigned char pattern = ic->private.local.brl_committed;
+ ret = 3;
+ if (ret > bytes) {
+ if(status) *status = XBufferOverflow;
+ return (ret);
+ }
+ buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f);
+ buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6);
+ buffer[2] = 0x80 | (pattern & 0x3f);
+ if(keysym) {
+ *keysym = XK_braille_blank | pattern;
+ if(status) *status = XLookupBoth;
+ } else
+ if(status) *status = XLookupChars;
+ } else { /* Composed Event */
+ ret = strlen(&utf8[b[ic->private.local.composed].utf8]);
+ if(ret > bytes) {
+ if(status) *status = XBufferOverflow;
+ return (ret);
+ }
+ memcpy(buffer, &utf8[b[ic->private.local.composed].utf8], ret);
+ if(keysym) *keysym = b[ic->private.local.composed].ks;
+ if (ret > 0) {
+ if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+ } else { /* Throughed Event */
+ ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);
+ if(ret > 0) {
+ if (ret > bytes) {
+ if (status) *status = XBufferOverflow;
+ } else if (keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupBoth;
+ } else {
+ if(status) *status = XLookupChars;
+ }
+ } else {
+ if(keysym && *keysym != NoSymbol) {
+ if(status) *status = XLookupKeySym;
+ } else {
+ if(status) *status = XLookupNone;
+ }
+ }
+ }
+ return (ret);
+}
+
+Private int
+_XimLcctsconvert(
+ XlcConv conv,
+ char *from,
+ int from_len,
+ char *to,
+ int to_len,
+ Status *state)
+{
+ int from_left;
+ int to_left;
+ int from_savelen;
+ int to_savelen;
+ int from_cnvlen;
+ int to_cnvlen;
+ char *from_buf;
+ char *to_buf;
+ char scratchbuf[BUFSIZ];
+ Status tmp_state;
+
+ if (!state)
+ state = &tmp_state;
+
+ if (!conv || !from || !from_len) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ /* Reset the converter. The CompoundText at 'from' starts in
+ initial state. */
+ _XlcResetConverter(conv);
+
+ from_left = from_len;
+ to_left = BUFSIZ;
+ from_cnvlen = 0;
+ to_cnvlen = 0;
+ for (;;) {
+ from_buf = &from[from_cnvlen];
+ from_savelen = from_left;
+ to_buf = &scratchbuf[to_cnvlen];
+ to_savelen = to_left;
+ if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
+ (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
+ *state = XLookupNone;
+ return 0;
+ }
+ from_cnvlen += (from_savelen - from_left);
+ to_cnvlen += (to_savelen - to_left);
+ if (from_left == 0) {
+ if (!to_cnvlen) {
+ *state = XLookupNone;
+ return 0;
+ }
+ break;
+ }
+ }
+
+ if (!to || !to_len || (to_len < to_cnvlen)) {
+ *state = XBufferOverflow;
+ } else {
+ memcpy(to, scratchbuf, to_cnvlen);
+ *state = XLookupChars;
+ }
+ return to_cnvlen;
+}
+
+Public int
+_XimLcctstombs(XIM xim, char *from, int from_len,
+ char *to, int to_len, Status *state)
+{
+ return _XimLcctsconvert(((Xim)xim)->private.local.ctom_conv,
+ from, from_len, to, to_len, state);
+}
+
+Public int
+_XimLcctstowcs(XIM xim, char *from, int from_len,
+ wchar_t *to, int to_len, Status *state)
+{
+ Xim im = (Xim)xim;
+ XlcConv conv = im->private.local.ctow_conv;
+ int from_left;
+ int to_left;
+ int from_savelen;
+ int to_savelen;
+ int from_cnvlen;
+ int to_cnvlen;
+ char *from_buf;
+ wchar_t *to_buf;
+ wchar_t scratchbuf[BUFSIZ];
+ Status tmp_state;
+
+ if (!state)
+ state = &tmp_state;
+
+ if (!conv || !from || !from_len) {
+ *state = XLookupNone;
+ return 0;
+ }
+
+ /* Reset the converter. The CompoundText at 'from' starts in
+ initial state. */
+ _XlcResetConverter(conv);
+
+ from_left = from_len;
+ to_left = BUFSIZ;
+ from_cnvlen = 0;
+ to_cnvlen = 0;
+ for (;;) {
+ from_buf = &from[from_cnvlen];
+ from_savelen = from_left;
+ to_buf = &scratchbuf[to_cnvlen];
+ to_savelen = to_left;
+ if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
+ (XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
+ *state = XLookupNone;
+ return 0;
+ }
+ from_cnvlen += (from_savelen - from_left);
+ to_cnvlen += (to_savelen - to_left);
+ if (from_left == 0) {
+ if (!to_cnvlen){
+ *state = XLookupNone;
+ return 0;
+ }
+ break;
+ }
+ }
+
+ if (!to || !to_len || (to_len < to_cnvlen)) {
+ *state = XBufferOverflow;
+ } else {
+ memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t));
+ *state = XLookupChars;
+ }
+ return to_cnvlen;
+}
+
+Public int
+_XimLcctstoutf8(XIM xim, char *from, int from_len,
+ char *to, int to_len, Status *state)
+{
+ return _XimLcctsconvert(((Xim)xim)->private.local.ctoutf8_conv,
+ from, from_len, to, to_len, state);
+}
diff --git a/libX11/modules/im/ximcp/imRmAttr.c b/libX11/modules/im/ximcp/imRmAttr.c index 7503905b2..f31af79aa 100644 --- a/libX11/modules/im/ximcp/imRmAttr.c +++ b/libX11/modules/im/ximcp/imRmAttr.c @@ -1,1518 +1,1518 @@ -/****************************************************************** - - Copyright 1992, 1993, 1994 by FUJITSU LIMITED - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear -in supporting documentation, and that the name of FUJITSU LIMITED -not be used in advertising or publicity pertaining to distribution -of the software without specific, written prior permission. -FUJITSU LIMITED makes no representations about the suitability of -this software for any purpose. -It is provided "as is" without express or implied warranty. - -FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - - Author: Takashi Fujiwara FUJITSU LIMITED - fujiwara@a80.tech.yk.fujitsu.co.jp - -******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xlcint.h" -#include "Ximint.h" - - -Private XIMResourceList -_XimGetNestedListSeparator( - XIMResourceList res_list, /* LISTofIMATTR or IMATTR */ - unsigned int res_num) -{ - return _XimGetResourceListRec(res_list, res_num, XNSeparatorofNestedList); -} - -Private Bool -_XimCheckInnerIMAttributes( - Xim im, - XIMArg *arg, - unsigned long mode) -{ - XIMResourceList res; - int check; - - if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources, - im->private.proto.im_num_inner_resources, arg->name))) - return False; - - check = _XimCheckIMMode(res, mode); - if(check == XIM_CHECK_INVALID) - return True; - else if(check == XIM_CHECK_ERROR) - return False; - - return True; -} - -Public char * -_XimMakeIMAttrIDList( - Xim im, - XIMResourceList res_list, - unsigned int res_num, - XIMArg *arg, - CARD16 *buf, - INT16 *len, - unsigned long mode) -{ - register XIMArg *p; - XIMResourceList res; - int check; - - *len = 0; - if (!arg) - return (char *)NULL; - - for (p = arg; p->name; p++) { - if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) { - if (_XimCheckInnerIMAttributes(im, p, mode)) - continue; - return p->name; - } - - check = _XimCheckIMMode(res, mode); - if (check == XIM_CHECK_INVALID) - continue; - else if (check == XIM_CHECK_ERROR) - return p->name; - - *buf = res->id; - *len += sizeof(CARD16); - buf++; - } - return (char *)NULL; -} - -Private Bool -_XimCheckInnerICAttributes( - Xic ic, - XIMArg *arg, - unsigned long mode) -{ - XIMResourceList res; - int check; - - if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources, - ic->private.proto.ic_num_inner_resources, arg->name))) - return False; - - check = _XimCheckICMode(res, mode); - if(check == XIM_CHECK_INVALID) - return True; - else if(check == XIM_CHECK_ERROR) - return False; - - return True; -} - -Public char * -_XimMakeICAttrIDList( - Xic ic, - XIMResourceList res_list, - unsigned int res_num, - XIMArg *arg, - CARD16 *buf, - INT16 *len, - unsigned long mode) -{ - register XIMArg *p; - XIMResourceList res; - int check; - XrmQuark pre_quark; - XrmQuark sts_quark; - char *name; - INT16 new_len; - - *len = 0; - if (!arg) - return (char *)NULL; - - pre_quark = XrmStringToQuark(XNPreeditAttributes); - sts_quark = XrmStringToQuark(XNStatusAttributes); - - for (p = arg; p && p->name; p++) { - if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) { - if (_XimCheckInnerICAttributes(ic, p, mode)) - continue; - *len = -1; - return p->name; - } - - check = _XimCheckICMode(res, mode); - if(check == XIM_CHECK_INVALID) - continue; - else if(check == XIM_CHECK_ERROR) { - *len = -1; - return p->name; - } - - *buf = res->id; - *len += sizeof(CARD16); - buf++; - if (res->resource_size == XimType_NEST) { - if (res->xrm_name == pre_quark) { - if ((name = _XimMakeICAttrIDList(ic, res_list, res_num, - (XIMArg *)p->value, buf, &new_len, - (mode | XIM_PREEDIT_ATTR)))) { - if (new_len < 0) *len = -1; - else *len += new_len; - return name; - } - } else if (res->xrm_name == sts_quark) { - if ((name = _XimMakeICAttrIDList(ic, res_list, res_num, - (XIMArg *)p->value, buf, &new_len, - (mode | XIM_STATUS_ATTR)))) { - if (new_len < 0) *len = -1; - else *len += new_len; - return name; - } - } - *len += new_len; - buf = (CARD16 *)((char *)buf + new_len); - if (!(res = _XimGetNestedListSeparator(res_list, res_num))) { - p++; - if (p) { - *len = -1; - return p->name; - } - else { - return (char *)NULL; - } - } - *buf = res->id; - *len += sizeof(CARD16); - buf++; - } - } - return (char *)NULL; -} - -Private Bool -_XimAttributeToValue( - Xic ic, - XIMResourceList res, - CARD16 *data, - INT16 data_len, - XPointer value, - BITMASK32 mode) -{ - switch (res->resource_size) { - case XimType_SeparatorOfNestedList: - case XimType_NEST: - break; - - case XimType_CARD8: - case XimType_CARD16: - case XimType_CARD32: - case XimType_Window: - case XimType_XIMHotKeyState: - _XCopyToArg((XPointer)data, (XPointer *)&value, data_len); - break; - - case XimType_STRING8: - { - char *str; - - if (!(value)) - return False; - - if (!(str = (char *)Xmalloc(data_len + 1))) - return False; - - (void)memcpy(str, (char *)data, data_len); - str[data_len] = '\0'; - - *((char **)value) = str; - break; - } - - case XimType_XIMStyles: - { - INT16 num = data[0]; - register CARD32 *style_list = (CARD32 *)&data[2]; - XIMStyle *style; - XIMStyles *rep; - register int i; - char *p; - int alloc_len; - - if (!(value)) - return False; - - alloc_len = sizeof(XIMStyles) + sizeof(XIMStyle) * num; - if (!(p = (char *)Xmalloc(alloc_len))) - return False; - - rep = (XIMStyles *)p; - style = (XIMStyle *)(p + sizeof(XIMStyles)); - - for (i = 0; i < num; i++) - style[i] = (XIMStyle)style_list[i]; - - rep->count_styles = (unsigned short)num; - rep->supported_styles = style; - *((XIMStyles **)value) = rep; - break; - } - - case XimType_XRectangle: - { - XRectangle *rep; - - if (!(value)) - return False; - - if (!(rep = (XRectangle *)Xmalloc(sizeof(XRectangle)))) - return False; - - rep->x = data[0]; - rep->y = data[1]; - rep->width = data[2]; - rep->height = data[3]; - *((XRectangle **)value) = rep; - break; - } - - case XimType_XPoint: - { - XPoint *rep; - - if (!(value)) - return False; - - if (!(rep = (XPoint *)Xmalloc(sizeof(XPoint)))) - return False; - - rep->x = data[0]; - rep->y = data[1]; - *((XPoint **)value) = rep; - break; - } - - case XimType_XFontSet: - { - INT16 len = data[0]; - char *base_name; - XFontSet rep = (XFontSet)NULL; - char **missing_list = NULL; - int missing_count; - char *def_string; - - if (!(value)) - return False; - if (!ic) - return False; - - if (!(base_name = (char *)Xmalloc(len + 1))) - return False; - - (void)strncpy(base_name, (char *)&data[1], (int)len); - base_name[len] = '\0'; - - if (mode & XIM_PREEDIT_ATTR) { - if (!strcmp(base_name, ic->private.proto.preedit_font)) { - rep = ic->core.preedit_attr.fontset; - } else if (!ic->private.proto.preedit_font_length) { - rep = XCreateFontSet(ic->core.im->core.display, - base_name, &missing_list, - &missing_count, &def_string); - } - } else if (mode & XIM_STATUS_ATTR) { - if (!strcmp(base_name, ic->private.proto.status_font)) { - rep = ic->core.status_attr.fontset; - } else if (!ic->private.proto.status_font_length) { - rep = XCreateFontSet(ic->core.im->core.display, - base_name, &missing_list, - &missing_count, &def_string); - } - } - - Xfree(base_name); - Xfree(missing_list); - *((XFontSet *)value) = rep; - break; - } - - case XimType_XIMHotKeyTriggers: - { - INT32 num = *((CARD32 *)data); - register CARD32 *key_list = (CARD32 *)&data[2]; - XIMHotKeyTrigger *key; - XIMHotKeyTriggers *rep; - register int i; - char *p; - int alloc_len; - - if (!(value)) - return False; - - alloc_len = sizeof(XIMHotKeyTriggers) - + sizeof(XIMHotKeyTrigger) * num; - if (!(p = (char *)Xmalloc(alloc_len))) - return False; - - rep = (XIMHotKeyTriggers *)p; - key = (XIMHotKeyTrigger *)(p + sizeof(XIMHotKeyTriggers)); - - for (i = 0; i < num; i++, key_list += 3) { - key[i].keysym = (KeySym)key_list[0]; /* keysym */ - key[i].modifier = (int)key_list[1]; /* modifier */ - key[i].modifier_mask = (int)key_list[2]; /* modifier_mask */ - } - - rep->num_hot_key = (int)num; - rep->key = key; - *((XIMHotKeyTriggers **)value) = rep; - break; - } - - case XimType_XIMStringConversion: - { - break; - } - - default: - return False; - } - return True; -} - -Private Bool -_XimDecodeInnerIMATTRIBUTE( - Xim im, - XIMArg *arg) -{ - XIMResourceList res; - XimDefIMValues im_values; - - if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources, - im->private.proto.im_num_inner_resources, arg->name))) - return False; - - _XimGetCurrentIMValues(im, &im_values); - return _XimDecodeLocalIMAttr(res, (XPointer)&im_values, arg->value); -} - -Public char * -_XimDecodeIMATTRIBUTE( - Xim im, - XIMResourceList res_list, - unsigned int res_num, - CARD16 *data, - INT16 data_len, - XIMArg *arg, - BITMASK32 mode) -{ - register XIMArg *p; - XIMResourceList res; - int check; - INT16 len; - CARD16 *buf; - INT16 total; - INT16 min_len = sizeof(CARD16) /* sizeof attributeID */ - + sizeof(INT16); /* sizeof length */ - - for (p = arg; p->name; p++) { - if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) { - if (_XimDecodeInnerIMATTRIBUTE(im, p)) - continue; - return p->name; - } - - check = _XimCheckIMMode(res, mode); - if(check == XIM_CHECK_INVALID) - continue; - else if(check == XIM_CHECK_ERROR) - return p->name; - - total = data_len; - buf = data; - while (total >= min_len) { - if (res->id == buf[0]) - break; - - len = buf[1]; - len += XIM_PAD(len) + min_len; - buf = (CARD16 *)((char *)buf + len); - total -= len; - } - if (total < min_len) - return p->name; - - if (!(_XimAttributeToValue((Xic) im->private.local.current_ic, - res, &buf[2], buf[1], p->value, mode))) - return p->name; - } - return (char *)NULL; -} - -Private Bool -_XimDecodeInnerICATTRIBUTE( - Xic ic, - XIMArg *arg, - unsigned long mode) -{ - XIMResourceList res; - XimDefICValues ic_values; - - if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources, - ic->private.proto.ic_num_inner_resources, arg->name))) - return False; - - _XimGetCurrentICValues(ic, &ic_values); - if (!_XimDecodeLocalICAttr(res, (XPointer)&ic_values, arg->value, mode)) - return False; - _XimSetCurrentICValues(ic, &ic_values); - return True; -} - -Public char * -_XimDecodeICATTRIBUTE( - Xic ic, - XIMResourceList res_list, - unsigned int res_num, - CARD16 *data, - INT16 data_len, - XIMArg *arg, - BITMASK32 mode) -{ - register XIMArg *p; - XIMResourceList res; - int check; - INT16 len; - CARD16 *buf; - INT16 total; - char *name; - INT16 min_len = sizeof(CARD16) /* sizeof attributeID */ - + sizeof(INT16); /* sizeof length */ - XrmQuark pre_quark; - XrmQuark sts_quark; - - if (!arg) - return (char *)NULL; - - pre_quark = XrmStringToQuark(XNPreeditAttributes); - sts_quark = XrmStringToQuark(XNStatusAttributes); - - for (p = arg; p->name; p++) { - if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) { - if (_XimDecodeInnerICATTRIBUTE(ic, p, mode)) - continue; - return p->name; - } - - check = _XimCheckICMode(res, mode); - if (check == XIM_CHECK_INVALID) - continue; - else if (check == XIM_CHECK_ERROR) - return p->name; - - total = data_len; - buf = data; - while (total >= min_len) { - if (res->id == buf[0]) - break; - - len = buf[1]; - len += XIM_PAD(len) + min_len; - buf = (CARD16 *)((char *)buf + len); - total -= len; - } - if (total < min_len) - return p->name; - - if (res->resource_size == XimType_NEST) { - if (res->xrm_name == pre_quark) { - if ((name = _XimDecodeICATTRIBUTE(ic, res_list, res_num, - &buf[2], buf[1], (XIMArg *)p->value, - (mode | XIM_PREEDIT_ATTR)))) - return name; - } else if (res->xrm_name == sts_quark) { - if ((name = _XimDecodeICATTRIBUTE(ic, res_list, res_num, - &buf[2], buf[1], (XIMArg *)p->value, - (mode | XIM_STATUS_ATTR)))) - return name; - } - } else { - if (!(_XimAttributeToValue(ic, res, &buf[2], buf[1], - p->value, mode))) - return p->name; - } - } - return (char *)NULL; -} - -Private Bool -_XimValueToAttribute( - XIMResourceList res, - XPointer buf, - int buf_size, - XPointer value, - int *len, - unsigned long mode, - XPointer param) -{ - int ret_len; - - switch (res->resource_size) { - case XimType_SeparatorOfNestedList: - case XimType_NEST: - *len = 0; - break; - - case XimType_CARD8: - ret_len = sizeof(CARD8); - if (buf_size < ret_len + XIM_PAD(ret_len)) { - *len = -1; - return False; - } - - *((CARD8 *)buf) = (CARD8)(long)value; - *len = ret_len; - break; - - case XimType_CARD16: - ret_len = sizeof(CARD16); - if (buf_size < ret_len + XIM_PAD(ret_len)) { - *len = -1; - return False; - } - - *((CARD16 *)buf) = (CARD16)(long)value; - *len = ret_len; - break; - - case XimType_CARD32: - case XimType_Window: - case XimType_XIMHotKeyState: - ret_len = sizeof(CARD32); - if (buf_size < ret_len + XIM_PAD(ret_len)) { - *len = -1; - return False; - } - - *((CARD32 *)buf) = (CARD32)(long)value; - *len = ret_len; - break; - - case XimType_STRING8: - if (!value) { - *len = 0; - return False; - } - - ret_len = strlen((char *)value); - if (buf_size < ret_len + XIM_PAD(ret_len)) { - *len = -1; - return False; - } - - (void)memcpy((char *)buf, (char *)value, ret_len); - *len = ret_len; - break; - - case XimType_XRectangle: - { - XRectangle *rect = (XRectangle *)value; - CARD16 *buf_s = (CARD16 *)buf; - - if (!rect) { - *len = 0; - return False; - } - - ret_len = sizeof(INT16) /* sizeof X */ - + sizeof(INT16) /* sizeof Y */ - + sizeof(CARD16) /* sizeof width */ - + sizeof(CARD16); /* sizeof height */ - if (buf_size < ret_len + XIM_PAD(ret_len)) { - *len = -1; - return False; - } - - buf_s[0] = (CARD16)rect->x; /* X */ - buf_s[1] = (CARD16)rect->y; /* Y */ - buf_s[2] = (CARD16)rect->width; /* width */ - buf_s[3] = (CARD16)rect->height; /* heght */ - *len = ret_len; - break; - } - - case XimType_XPoint: - { - XPoint *point = (XPoint *)value; - CARD16 *buf_s = (CARD16 *)buf; - - if (!point) { - *len = 0; - return False; - } - - ret_len = sizeof(INT16) /* sizeof X */ - + sizeof(INT16); /* sizeof Y */ - if (buf_size < ret_len + XIM_PAD(ret_len)) { - *len = -1; - return False; - } - - buf_s[0] = (CARD16)point->x; /* X */ - buf_s[1] = (CARD16)point->y; /* Y */ - *len = ret_len; - break; - } - - case XimType_XFontSet: - { - XFontSet font = (XFontSet)value; - Xic ic = (Xic)param; - char *base_name = NULL; - int length = 0; - CARD16 *buf_s = (CARD16 *)buf; - - if (!font) { - *len = 0; - return False; - } - - if (mode & XIM_PREEDIT_ATTR) { - base_name = ic->private.proto.preedit_font; - length = ic->private.proto.preedit_font_length; - } else if (mode & XIM_STATUS_ATTR) { - base_name = ic->private.proto.status_font; - length = ic->private.proto.status_font_length; - } - - if (!base_name) { - *len = 0; - return False; - } - - ret_len = sizeof(CARD16) /* sizeof length of Base name */ - + length; /* sizeof Base font name list */ - if (buf_size < ret_len + XIM_PAD(ret_len)) { - *len = -1; - return False; - } - - buf_s[0] = (INT16)length; /* length of Base font name */ - (void)memcpy((char *)&buf_s[1], base_name, length); - /* Base font name list */ - *len = ret_len; - break; - } - - case XimType_XIMHotKeyTriggers: - { - XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)value; - INT32 num; - CARD32 *buf_l = (CARD32 *)buf; - register CARD32 *key = (CARD32 *)&buf_l[1]; - register int i; - - if (!hotkey) { - *len = 0; - return False; - } - num = (INT32)hotkey->num_hot_key; - - ret_len = sizeof(INT32) /* sizeof number of key list */ - + (sizeof(CARD32) /* sizeof keysyn */ - + sizeof(CARD32) /* sizeof modifier */ - + sizeof(CARD32)) /* sizeof modifier_mask */ - * num; /* number of key list */ - if (buf_size < ret_len + XIM_PAD(ret_len)) { - *len = -1; - return False; - } - - buf_l[0] = num; /* number of key list */ - for (i = 0; i < num; i++, key += 3) { - key[0] = (CARD32)(hotkey->key[i].keysym); - /* keysym */ - key[1] = (CARD32)(hotkey->key[i].modifier); - /* modifier */ - key[2] = (CARD32)(hotkey->key[i].modifier_mask); - /* modifier_mask */ - } - *len = ret_len; - break; - } - - case XimType_XIMStringConversion: - { - *len = 0; - break; - } - - default: - return False; - } - return True; -} - -Private Bool -_XimSetInnerIMAttributes( - Xim im, - XPointer top, - XIMArg *arg, - unsigned long mode) -{ - XIMResourceList res; - int check; - - if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources, - im->private.proto.im_num_inner_resources, arg->name))) - return False; - - check = _XimCheckIMMode(res, mode); - if(check == XIM_CHECK_INVALID) - return True; - else if(check == XIM_CHECK_ERROR) - return False; - - return _XimEncodeLocalIMAttr(res, top, arg->value); -} - -Public char * -_XimEncodeIMATTRIBUTE( - Xim im, - XIMResourceList res_list, - unsigned int res_num, - XIMArg *arg, - XIMArg **arg_ret, - char *buf, - int size, - int *ret_len, - XPointer top, - unsigned long mode) -{ - register XIMArg *p; - XIMResourceList res; - int check; - CARD16 *buf_s; - int len; - int min_len = sizeof(CARD16) /* sizeof attribute ID */ - + sizeof(INT16); /* sizeof value length */ - - *ret_len = 0; - for (p = arg; p->name; p++) { - if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) { - if (_XimSetInnerIMAttributes(im, top, p, mode)) - continue; - return p->name; - } - - check = _XimCheckIMMode(res, mode); - if (check == XIM_CHECK_INVALID) - continue; - else if (check == XIM_CHECK_ERROR) - return p->name; - - if (!(_XimEncodeLocalIMAttr(res, top, p->value))) - return p->name; - - buf_s = (CARD16 *)buf; - if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2], (size - min_len), - p->value, &len, mode, (XPointer)NULL))) - return p->name; - - if (len == 0) { - continue; - } else if (len < 0) { - *arg_ret = p; - return (char *)NULL; - } - - buf_s[0] = res->id; /* attribute ID */ - buf_s[1] = len; /* value length */ - XIM_SET_PAD(&buf_s[2], len); /* pad */ - len += min_len; - - buf += len; - *ret_len += len; - size -= len; - } - *arg_ret = (XIMArg *)NULL; - return (char *)NULL; -} - -#ifdef XIM_CONNECTABLE -Public Bool -_XimEncodeSavedIMATTRIBUTE( - Xim im, - XIMResourceList res_list, - unsigned int res_num, - int *idx, - char *buf, - int size, - int *ret_len, - XPointer top, - unsigned long mode) -{ - register int i; - int num = im->private.proto.num_saved_imvalues; - XrmQuark *quark_list = im->private.proto.saved_imvalues; - XIMResourceList res; - XPointer value; - CARD16 *buf_s; - int len; - int min_len = sizeof(CARD16) /* sizeof attribute ID */ - + sizeof(INT16); /* sizeof value length */ - - if (!im->private.proto.saved_imvalues) { - *idx = -1; - *ret_len = 0; - return True; - } - - *ret_len = 0; - for (i = *idx; i < num; i++) { - if (!(res = _XimGetResourceListRecByQuark(res_list, - res_num, quark_list[i]))) - continue; - - if (!_XimDecodeLocalIMAttr(res, top, value)) - return False; - - buf_s = (CARD16 *)buf; - if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2], - (size - min_len), value, &len, mode, (XPointer)NULL))) - return False; - - if (len == 0) { - continue; - } else if (len < 0) { - *idx = i; - return True; - } - - buf_s[0] = res->id; /* attribute ID */ - buf_s[1] = len; /* value length */ - XIM_SET_PAD(&buf_s[2], len); /* pad */ - len += min_len; - - buf += len; - *ret_len += len; - size -= len; - } - *idx = -1; - return True; -} -#endif /* XIM_CONNECTABLE */ - -Private Bool -_XimEncodeTopValue( - Xic ic, - XIMResourceList res, - XIMArg *p) -{ - if (res->xrm_name == XrmStringToQuark(XNClientWindow)) { - ic->core.client_window = (Window)p->value; - if (ic->core.focus_window == (Window)0) - ic->core.focus_window = ic->core.client_window; - _XimRegisterFilter(ic); - - } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) { - if (ic->core.client_window) { - _XimUnregisterFilter(ic); - ic->core.focus_window = (Window)p->value; - _XimRegisterFilter(ic); - } else /* client_window not yet */ - ic->core.focus_window = (Window)p->value; - } - return True; -} - -Private Bool -_XimEncodePreeditValue( - Xic ic, - XIMResourceList res, - XIMArg *p) -{ - if (res->xrm_name == XrmStringToQuark(XNStdColormap)) { - XStandardColormap *colormap_ret; - int count; - - if (!(XGetRGBColormaps(ic->core.im->core.display, - ic->core.focus_window, &colormap_ret, - &count, (Atom)p->value))) - return False; - - XFree(colormap_ret); - } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) { - int list_ret; - XFontStruct **struct_list; - char **name_list; - char *tmp; - int len; - register int i; - - if (!p->value) - return False; - - if (ic->private.proto.preedit_font) - Xfree(ic->private.proto.preedit_font); - - list_ret = XFontsOfFontSet((XFontSet)p->value, - &struct_list, &name_list); - for (i = 0, len = 0; i < list_ret; i++) { - len += (strlen(name_list[i]) + sizeof(char)); - } - if (!(tmp = Xmalloc(len + 1))) { - ic->private.proto.preedit_font = NULL; - return False; - } - - tmp[0] = '\0'; - for (i = 0; i < list_ret; i++) { - strcat(tmp, name_list[i]); - strcat(tmp, ","); - } - tmp[len - 1] = 0; - ic->private.proto.preedit_font = tmp; - ic->private.proto.preedit_font_length = len - 1; - } - return True; -} - -Private Bool -_XimEncodeStatusValue( - Xic ic, - XIMResourceList res, - XIMArg *p) -{ - if (res->xrm_name == XrmStringToQuark(XNStdColormap)) { - XStandardColormap *colormap_ret = NULL; - int count; - - if (!(XGetRGBColormaps(ic->core.im->core.display, - ic->core.focus_window, &colormap_ret, - &count, (Atom)p->value))) - return False; - - XFree(colormap_ret); - } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) { - int list_ret; - XFontStruct **struct_list; - char **name_list; - char *tmp; - int len; - register int i; - - if (!p->value) - return False; - - if (ic->private.proto.status_font) - Xfree(ic->private.proto.status_font); - - list_ret = XFontsOfFontSet((XFontSet)p->value, - &struct_list, &name_list); - for (i = 0, len = 0; i < list_ret; i++) { - len += (strlen(name_list[i]) + sizeof(char)); - } - if (!(tmp = Xmalloc(len+1))) { - ic->private.proto.status_font = NULL; - return False; - } - - tmp[0] = '\0'; - for(i = 0; i < list_ret; i++) { - strcat(tmp, name_list[i]); - strcat(tmp, ","); - } - tmp[len - 1] = 0; - ic->private.proto.status_font = tmp; - ic->private.proto.status_font_length = len - 1; - } - return True; -} - -Private Bool -_XimSetInnerICAttributes( - Xic ic, - XPointer top, - XIMArg *arg, - unsigned long mode) -{ - XIMResourceList res; - int check; - - if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources, - ic->private.proto.ic_num_inner_resources, arg->name))) - return False; - - check = _XimCheckICMode(res, mode); - if(check == XIM_CHECK_INVALID) - return True; - else if(check == XIM_CHECK_ERROR) - return False; - - return _XimEncodeLocalICAttr(ic, res, top, arg, mode); -} - -Public char * -_XimEncodeICATTRIBUTE( - Xic ic, - XIMResourceList res_list, - unsigned int res_num, - XIMArg *arg, - XIMArg **arg_ret, - char *buf, - int size, - int *ret_len, - XPointer top, - BITMASK32 *flag, - unsigned long mode) -{ - register XIMArg *p; - XIMResourceList res; - int check; - CARD16 *buf_s; - int len; - int min_len = sizeof(CARD16) /* sizeof attribute ID */ - + sizeof(INT16); /* sizeof value length */ - XrmQuark pre_quark; - XrmQuark sts_quark; - char *name; - - pre_quark = XrmStringToQuark(XNPreeditAttributes); - sts_quark = XrmStringToQuark(XNStatusAttributes); - - *ret_len = 0; - for (p = arg; p && p->name; p++) { - buf_s = (CARD16 *)buf; - if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) { - if (_XimSetInnerICAttributes(ic, top, p, mode)) - continue; - return p->name; - } - - check = _XimCheckICMode(res, mode); - if (check == XIM_CHECK_INVALID) - continue; - else if (check == XIM_CHECK_ERROR) - return p->name; - - if (mode & XIM_PREEDIT_ATTR) { - if (!(_XimEncodePreeditValue(ic, res, p))) - return p->name; - } else if (mode & XIM_STATUS_ATTR) { - if (!(_XimEncodeStatusValue(ic, res, p))) - return p->name; - } else { - if (!(_XimEncodeTopValue(ic, res, p))) - return p->name; - } - - if (res->resource_size == XimType_NEST) { - XimDefICValues *ic_attr = (XimDefICValues *)top; - - if (res->xrm_name == pre_quark) { - XIMArg *arg_rt; - if ((name = _XimEncodeICATTRIBUTE(ic, res_list, res_num, - (XIMArg *)p->value, &arg_rt, - (char *)&buf_s[2], (size - min_len), - &len, (XPointer)&ic_attr->preedit_attr, flag, - (mode | XIM_PREEDIT_ATTR)))) { - return name; - } - - } else if (res->xrm_name == sts_quark) { - XIMArg *arg_rt; - if ((name = _XimEncodeICATTRIBUTE(ic, res_list, res_num, - (XIMArg *)p->value, &arg_rt, - (char *)&buf_s[2], (size - min_len), - &len, (XPointer)&ic_attr->status_attr, flag, - (mode | XIM_STATUS_ATTR)))) { - return name; - } - } - } else { -#ifdef EXT_MOVE - if (flag) - *flag |= _XimExtenArgCheck(p); -#endif - if (!(_XimEncodeLocalICAttr(ic, res, top, p, mode))) - return p->name; - - if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2], - (size - min_len), p->value, - &len, mode, (XPointer)ic))) - return p->name; - } - - if (len == 0) { - continue; - } else if (len < 0) { - *arg_ret = p; - return (char *)NULL; - } - - buf_s[0] = res->id; /* attribute ID */ - buf_s[1] = len; /* value length */ - XIM_SET_PAD(&buf_s[2], len); /* pad */ - len += min_len; - - buf += len; - *ret_len += len; - size -= len; - } - *arg_ret = (XIMArg *)NULL; - return (char *)NULL; -} - -#ifdef XIM_CONNECTABLE -Private Bool -_XimEncodeSavedPreeditValue( - Xic ic, - XIMResourceList res, - XPointer value) -{ - int list_ret; - XFontStruct **struct_list; - char **name_list; - char *tmp; - int len; - register int i; - - if (res->xrm_name == XrmStringToQuark(XNFontSet)) { - if (!value) - return False; - - if (ic->private.proto.preedit_font) - Xfree(ic->private.proto.preedit_font); - - list_ret = XFontsOfFontSet((XFontSet)value, - &struct_list, &name_list); - for(i = 0, len = 0; i < list_ret; i++) { - len += (strlen(name_list[i]) + sizeof(char)); - } - if(!(tmp = Xmalloc(len + 1))) { - ic->private.proto.preedit_font = NULL; - return False; - } - - tmp[0] = '\0'; - for(i = 0; i < list_ret; i++) { - strcat(tmp, name_list[i]); - strcat(tmp, ","); - } - tmp[len - 1] = 0; - ic->private.proto.preedit_font = tmp; - ic->private.proto.preedit_font_length = len - 1; - } - return True; -} - -Private Bool -_XimEncodeSavedStatusValue( - Xic ic, - XIMResourceList res, - XPointer value) -{ - int list_ret; - XFontStruct **struct_list; - char **name_list; - char *tmp; - int len; - register int i; - - if (res->xrm_name == XrmStringToQuark(XNFontSet)) { - if (!value) - return False; - - if (ic->private.proto.status_font) - Xfree(ic->private.proto.status_font); - - list_ret = XFontsOfFontSet((XFontSet)value, - &struct_list, &name_list); - for(i = 0, len = 0; i < list_ret; i++) { - len += (strlen(name_list[i]) + sizeof(char)); - } - if(!(tmp = Xmalloc(len + 1))) { - ic->private.proto.status_font = NULL; - return False; - } - - tmp[0] = '\0'; - for(i = 0; i < list_ret; i++) { - strcat(tmp, name_list[i]); - strcat(tmp, ","); - } - tmp[len - 1] = 0; - ic->private.proto.status_font = tmp; - ic->private.proto.status_font_length = len - 1; - } - return True; -} - -Public Bool -_XimEncodeSavedICATTRIBUTE( - Xic ic, - XIMResourceList res_list, - unsigned int res_num, - int *idx, - char *buf, - int size, - int *ret_len, - XPointer top, - unsigned long mode) -{ - int i; - int num = ic->private.proto.num_saved_icvalues; - XrmQuark *quark_list = ic->private.proto.saved_icvalues; - XIMResourceList res; - XPointer value; - CARD16 *buf_s; - int len; - int min_len = sizeof(CARD16) /* sizeof attribute ID */ - + sizeof(INT16); /* sizeof value length */ - XrmQuark pre_quark; - XrmQuark sts_quark; - XrmQuark separator; - - if (!ic->private.proto.saved_icvalues) { - *idx = -1; - *ret_len = 0; - return True; - } - - pre_quark = XrmStringToQuark(XNPreeditAttributes); - sts_quark = XrmStringToQuark(XNStatusAttributes); - separator = XrmStringToQuark(XNSeparatorofNestedList); - - *ret_len = 0; - for (i = *idx; i < num; i++) { - if (quark_list[i] == separator) { - *idx = i; - return True; - } - - if (!(res = _XimGetResourceListRecByQuark(res_list, - res_num, quark_list[i]))) - continue; - - if (!_XimDecodeLocalICAttr(res, top,(XPointer)&value, mode)) - return False; - - if (mode & XIM_PREEDIT_ATTR) { - if (!(_XimEncodeSavedPreeditValue(ic, res, value))) { - return False; - } - } else if (mode & XIM_STATUS_ATTR) { - if (!(_XimEncodeSavedStatusValue(ic, res, value))) { - return False; - } - } - - buf_s = (CARD16 *)buf; - if (res->resource_size == XimType_NEST) { - XimDefICValues *ic_attr = (XimDefICValues *)top; - - i++; - if (res->xrm_name == pre_quark) { - if (!_XimEncodeSavedICATTRIBUTE(ic, res_list, res_num, - &i, (char *)&buf_s[2], (size - min_len), - &len, (XPointer)&ic_attr->preedit_attr, - (mode | XIM_PREEDIT_ATTR))) { - return False; - } - - } else if (res->xrm_name == sts_quark) { - if (!_XimEncodeSavedICATTRIBUTE(ic, res_list, res_num, - &i, (char *)&buf_s[2], (size - min_len), - &len, (XPointer)&ic_attr->status_attr, - (mode | XIM_STATUS_ATTR))) { - return False; - } - } - } else { - if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2], - (size - min_len), value, - &len, mode, (XPointer)ic))) { - return False; - } - } - - if (len == 0) { - continue; - } else if (len < 0) { - if (quark_list[i] == separator) - i++; - *idx = i; - return True; - } - - buf_s[0] = res->id; /* attribute ID */ - buf_s[1] = len; /* value length */ - XIM_SET_PAD(&buf_s[2], len); /* pad */ - len += min_len; - - buf += len; - *ret_len += len; - size -= len; - } - *idx = -1; - return True; -} -#endif /* XIM_CONNECTABLE */ - -Private unsigned int -_XimCountNumberOfAttr( - INT16 total, - CARD16 *attr, - int *names_len) -{ - unsigned int n; - INT16 len; - INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */ - + sizeof(CARD16) /* sizeof type of value */ - + sizeof(INT16); /* sizeof length of attribute */ - - n = 0; - *names_len = 0; - while (total > min_len) { - len = attr[2]; - *names_len += (len + 1); - len += (min_len + XIM_PAD(len + 2)); - total -= len; - attr = (CARD16 *)((char *)attr + len); - n++; - } - return n; -} - -Public Bool -_XimGetAttributeID( - Xim im, - CARD16 *buf) -{ - unsigned int n; - XIMResourceList res; - int res_len; - char *names; - int names_len; - XPointer tmp; - XIMValuesList *values_list; - char **values; - int values_len; - register int i; - INT16 len; - INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */ - + sizeof(CARD16) /* sizeof type of value */ - + sizeof(INT16); /* sizeof length of attr */ - /* - * IM attribute ID - */ - - if (!(n = _XimCountNumberOfAttr(buf[0], &buf[1], &names_len))) - return False; - res_len = sizeof(XIMResource) * n; - - if (!(res = (XIMResourceList)Xmalloc(res_len))) - return False; - bzero((char *)res, res_len); - - values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) - return False; - bzero(tmp, values_len); - - values_list = (XIMValuesList *)tmp; - values = (char **)((char *)tmp + sizeof(XIMValuesList)); - names = (char *)((char *)values + (sizeof(char **) * n)); - - values_list->count_values = n; - values_list->supported_values = values; - - buf++; - for (i = 0; i < n; i++) { - len = buf[2]; - (void)memcpy(names, (char *)&buf[3], len); - values[i] = names; - names[len] = '\0'; - res[i].resource_name = names; - res[i].resource_size = buf[1]; - res[i].id = buf[0]; - names += (len + 1); - len += (min_len + XIM_PAD(len + 2)); - buf = (CARD16 *)((char *)buf + len); - } - _XIMCompileResourceList(res, n); - - if (im->core.im_resources) - Xfree(im->core.im_resources); - if (im->core.im_values_list) - Xfree(im->core.im_values_list); - im->core.im_resources = res; - im->core.im_num_resources = n; - im->core.im_values_list = values_list; - - /* - * IC attribute ID - */ - - if (!(n = _XimCountNumberOfAttr(buf[0], &buf[2], &names_len))) - return False; - res_len = sizeof(XIMResource) * n; - - if (!(res = (XIMResourceList)Xmalloc(res_len))) - return False; - bzero((char *)res, res_len); - - values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) - return False; - bzero(tmp, values_len); - - values_list = (XIMValuesList *)tmp; - values = (char **)((char *)tmp + sizeof(XIMValuesList)); - names = (char *)((char *)values + (sizeof(char **) * n)); - - values_list->count_values = n; - values_list->supported_values = values; - - buf += 2; - for (i = 0; i < n; i++) { - len = buf[2]; - (void)memcpy(names, (char *)&buf[3], len); - values[i] = names; - names[len] = '\0'; - res[i].resource_name = names; - res[i].resource_size = buf[1]; - res[i].id = buf[0]; - names += (len + 1); - len += (min_len + XIM_PAD(len + 2)); - buf = (CARD16 *)((char *)buf + len); - } - _XIMCompileResourceList(res, n); - - if (im->core.ic_resources) - Xfree(im->core.ic_resources); - if (im->core.ic_values_list) - Xfree(im->core.ic_values_list); - im->core.ic_resources = res; - im->core.ic_num_resources = n; - im->core.ic_values_list = values_list; - - return True; -} +/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+
+Private XIMResourceList
+_XimGetNestedListSeparator(
+ XIMResourceList res_list, /* LISTofIMATTR or IMATTR */
+ unsigned int res_num)
+{
+ return _XimGetResourceListRec(res_list, res_num, XNSeparatorofNestedList);
+}
+
+Private Bool
+_XimCheckInnerIMAttributes(
+ Xim im,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ int check;
+
+ if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
+ im->private.proto.im_num_inner_resources, arg->name)))
+ return False;
+
+ check = _XimCheckIMMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ return True;
+ else if(check == XIM_CHECK_ERROR)
+ return False;
+
+ return True;
+}
+
+Public char *
+_XimMakeIMAttrIDList(
+ Xim im,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ XIMArg *arg,
+ CARD16 *buf,
+ INT16 *len,
+ unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+
+ *len = 0;
+ if (!arg)
+ return (char *)NULL;
+
+ for (p = arg; p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimCheckInnerIMAttributes(im, p, mode))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckIMMode(res, mode);
+ if (check == XIM_CHECK_INVALID)
+ continue;
+ else if (check == XIM_CHECK_ERROR)
+ return p->name;
+
+ *buf = res->id;
+ *len += sizeof(CARD16);
+ buf++;
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimCheckInnerICAttributes(
+ Xic ic,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ int check;
+
+ if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
+ ic->private.proto.ic_num_inner_resources, arg->name)))
+ return False;
+
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ return True;
+ else if(check == XIM_CHECK_ERROR)
+ return False;
+
+ return True;
+}
+
+Public char *
+_XimMakeICAttrIDList(
+ Xic ic,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ XIMArg *arg,
+ CARD16 *buf,
+ INT16 *len,
+ unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+ char *name;
+ INT16 new_len;
+
+ *len = 0;
+ if (!arg)
+ return (char *)NULL;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ for (p = arg; p && p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimCheckInnerICAttributes(ic, p, mode))
+ continue;
+ *len = -1;
+ return p->name;
+ }
+
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ continue;
+ else if(check == XIM_CHECK_ERROR) {
+ *len = -1;
+ return p->name;
+ }
+
+ *buf = res->id;
+ *len += sizeof(CARD16);
+ buf++;
+ if (res->resource_size == XimType_NEST) {
+ if (res->xrm_name == pre_quark) {
+ if ((name = _XimMakeICAttrIDList(ic, res_list, res_num,
+ (XIMArg *)p->value, buf, &new_len,
+ (mode | XIM_PREEDIT_ATTR)))) {
+ if (new_len < 0) *len = -1;
+ else *len += new_len;
+ return name;
+ }
+ } else if (res->xrm_name == sts_quark) {
+ if ((name = _XimMakeICAttrIDList(ic, res_list, res_num,
+ (XIMArg *)p->value, buf, &new_len,
+ (mode | XIM_STATUS_ATTR)))) {
+ if (new_len < 0) *len = -1;
+ else *len += new_len;
+ return name;
+ }
+ }
+ *len += new_len;
+ buf = (CARD16 *)((char *)buf + new_len);
+ if (!(res = _XimGetNestedListSeparator(res_list, res_num))) {
+ p++;
+ if (p) {
+ *len = -1;
+ return p->name;
+ }
+ else {
+ return (char *)NULL;
+ }
+ }
+ *buf = res->id;
+ *len += sizeof(CARD16);
+ buf++;
+ }
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimAttributeToValue(
+ Xic ic,
+ XIMResourceList res,
+ CARD16 *data,
+ INT16 data_len,
+ XPointer value,
+ BITMASK32 mode)
+{
+ switch (res->resource_size) {
+ case XimType_SeparatorOfNestedList:
+ case XimType_NEST:
+ break;
+
+ case XimType_CARD8:
+ case XimType_CARD16:
+ case XimType_CARD32:
+ case XimType_Window:
+ case XimType_XIMHotKeyState:
+ _XCopyToArg((XPointer)data, (XPointer *)&value, data_len);
+ break;
+
+ case XimType_STRING8:
+ {
+ char *str;
+
+ if (!(value))
+ return False;
+
+ if (!(str = (char *)Xmalloc(data_len + 1)))
+ return False;
+
+ (void)memcpy(str, (char *)data, data_len);
+ str[data_len] = '\0';
+
+ *((char **)value) = str;
+ break;
+ }
+
+ case XimType_XIMStyles:
+ {
+ INT16 num = data[0];
+ register CARD32 *style_list = (CARD32 *)&data[2];
+ XIMStyle *style;
+ XIMStyles *rep;
+ register int i;
+ char *p;
+ int alloc_len;
+
+ if (!(value))
+ return False;
+
+ alloc_len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
+ if (!(p = (char *)Xmalloc(alloc_len)))
+ return False;
+
+ rep = (XIMStyles *)p;
+ style = (XIMStyle *)(p + sizeof(XIMStyles));
+
+ for (i = 0; i < num; i++)
+ style[i] = (XIMStyle)style_list[i];
+
+ rep->count_styles = (unsigned short)num;
+ rep->supported_styles = style;
+ *((XIMStyles **)value) = rep;
+ break;
+ }
+
+ case XimType_XRectangle:
+ {
+ XRectangle *rep;
+
+ if (!(value))
+ return False;
+
+ if (!(rep = (XRectangle *)Xmalloc(sizeof(XRectangle))))
+ return False;
+
+ rep->x = data[0];
+ rep->y = data[1];
+ rep->width = data[2];
+ rep->height = data[3];
+ *((XRectangle **)value) = rep;
+ break;
+ }
+
+ case XimType_XPoint:
+ {
+ XPoint *rep;
+
+ if (!(value))
+ return False;
+
+ if (!(rep = (XPoint *)Xmalloc(sizeof(XPoint))))
+ return False;
+
+ rep->x = data[0];
+ rep->y = data[1];
+ *((XPoint **)value) = rep;
+ break;
+ }
+
+ case XimType_XFontSet:
+ {
+ INT16 len = data[0];
+ char *base_name;
+ XFontSet rep = (XFontSet)NULL;
+ char **missing_list = NULL;
+ int missing_count;
+ char *def_string;
+
+ if (!(value))
+ return False;
+ if (!ic)
+ return False;
+
+ if (!(base_name = (char *)Xmalloc(len + 1)))
+ return False;
+
+ (void)strncpy(base_name, (char *)&data[1], (int)len);
+ base_name[len] = '\0';
+
+ if (mode & XIM_PREEDIT_ATTR) {
+ if (!strcmp(base_name, ic->private.proto.preedit_font)) {
+ rep = ic->core.preedit_attr.fontset;
+ } else if (!ic->private.proto.preedit_font_length) {
+ rep = XCreateFontSet(ic->core.im->core.display,
+ base_name, &missing_list,
+ &missing_count, &def_string);
+ }
+ } else if (mode & XIM_STATUS_ATTR) {
+ if (!strcmp(base_name, ic->private.proto.status_font)) {
+ rep = ic->core.status_attr.fontset;
+ } else if (!ic->private.proto.status_font_length) {
+ rep = XCreateFontSet(ic->core.im->core.display,
+ base_name, &missing_list,
+ &missing_count, &def_string);
+ }
+ }
+
+ Xfree(base_name);
+ Xfree(missing_list);
+ *((XFontSet *)value) = rep;
+ break;
+ }
+
+ case XimType_XIMHotKeyTriggers:
+ {
+ INT32 num = *((CARD32 *)data);
+ register CARD32 *key_list = (CARD32 *)&data[2];
+ XIMHotKeyTrigger *key;
+ XIMHotKeyTriggers *rep;
+ register int i;
+ char *p;
+ int alloc_len;
+
+ if (!(value))
+ return False;
+
+ alloc_len = sizeof(XIMHotKeyTriggers)
+ + sizeof(XIMHotKeyTrigger) * num;
+ if (!(p = (char *)Xmalloc(alloc_len)))
+ return False;
+
+ rep = (XIMHotKeyTriggers *)p;
+ key = (XIMHotKeyTrigger *)(p + sizeof(XIMHotKeyTriggers));
+
+ for (i = 0; i < num; i++, key_list += 3) {
+ key[i].keysym = (KeySym)key_list[0]; /* keysym */
+ key[i].modifier = (int)key_list[1]; /* modifier */
+ key[i].modifier_mask = (int)key_list[2]; /* modifier_mask */
+ }
+
+ rep->num_hot_key = (int)num;
+ rep->key = key;
+ *((XIMHotKeyTriggers **)value) = rep;
+ break;
+ }
+
+ case XimType_XIMStringConversion:
+ {
+ break;
+ }
+
+ default:
+ return False;
+ }
+ return True;
+}
+
+Private Bool
+_XimDecodeInnerIMATTRIBUTE(
+ Xim im,
+ XIMArg *arg)
+{
+ XIMResourceList res;
+ XimDefIMValues im_values;
+
+ if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
+ im->private.proto.im_num_inner_resources, arg->name)))
+ return False;
+
+ _XimGetCurrentIMValues(im, &im_values);
+ return _XimDecodeLocalIMAttr(res, (XPointer)&im_values, arg->value);
+}
+
+Public char *
+_XimDecodeIMATTRIBUTE(
+ Xim im,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ CARD16 *data,
+ INT16 data_len,
+ XIMArg *arg,
+ BITMASK32 mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ INT16 len;
+ CARD16 *buf;
+ INT16 total;
+ INT16 min_len = sizeof(CARD16) /* sizeof attributeID */
+ + sizeof(INT16); /* sizeof length */
+
+ for (p = arg; p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimDecodeInnerIMATTRIBUTE(im, p))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckIMMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ continue;
+ else if(check == XIM_CHECK_ERROR)
+ return p->name;
+
+ total = data_len;
+ buf = data;
+ while (total >= min_len) {
+ if (res->id == buf[0])
+ break;
+
+ len = buf[1];
+ len += XIM_PAD(len) + min_len;
+ buf = (CARD16 *)((char *)buf + len);
+ total -= len;
+ }
+ if (total < min_len)
+ return p->name;
+
+ if (!(_XimAttributeToValue((Xic) im->private.local.current_ic,
+ res, &buf[2], buf[1], p->value, mode)))
+ return p->name;
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimDecodeInnerICATTRIBUTE(
+ Xic ic,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ XimDefICValues ic_values;
+
+ if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
+ ic->private.proto.ic_num_inner_resources, arg->name)))
+ return False;
+
+ _XimGetCurrentICValues(ic, &ic_values);
+ if (!_XimDecodeLocalICAttr(res, (XPointer)&ic_values, arg->value, mode))
+ return False;
+ _XimSetCurrentICValues(ic, &ic_values);
+ return True;
+}
+
+Public char *
+_XimDecodeICATTRIBUTE(
+ Xic ic,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ CARD16 *data,
+ INT16 data_len,
+ XIMArg *arg,
+ BITMASK32 mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ INT16 len;
+ CARD16 *buf;
+ INT16 total;
+ char *name;
+ INT16 min_len = sizeof(CARD16) /* sizeof attributeID */
+ + sizeof(INT16); /* sizeof length */
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+
+ if (!arg)
+ return (char *)NULL;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ for (p = arg; p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimDecodeInnerICATTRIBUTE(ic, p, mode))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckICMode(res, mode);
+ if (check == XIM_CHECK_INVALID)
+ continue;
+ else if (check == XIM_CHECK_ERROR)
+ return p->name;
+
+ total = data_len;
+ buf = data;
+ while (total >= min_len) {
+ if (res->id == buf[0])
+ break;
+
+ len = buf[1];
+ len += XIM_PAD(len) + min_len;
+ buf = (CARD16 *)((char *)buf + len);
+ total -= len;
+ }
+ if (total < min_len)
+ return p->name;
+
+ if (res->resource_size == XimType_NEST) {
+ if (res->xrm_name == pre_quark) {
+ if ((name = _XimDecodeICATTRIBUTE(ic, res_list, res_num,
+ &buf[2], buf[1], (XIMArg *)p->value,
+ (mode | XIM_PREEDIT_ATTR))))
+ return name;
+ } else if (res->xrm_name == sts_quark) {
+ if ((name = _XimDecodeICATTRIBUTE(ic, res_list, res_num,
+ &buf[2], buf[1], (XIMArg *)p->value,
+ (mode | XIM_STATUS_ATTR))))
+ return name;
+ }
+ } else {
+ if (!(_XimAttributeToValue(ic, res, &buf[2], buf[1],
+ p->value, mode)))
+ return p->name;
+ }
+ }
+ return (char *)NULL;
+}
+
+Private Bool
+_XimValueToAttribute(
+ XIMResourceList res,
+ XPointer buf,
+ int buf_size,
+ XPointer value,
+ int *len,
+ unsigned long mode,
+ XPointer param)
+{
+ int ret_len;
+
+ switch (res->resource_size) {
+ case XimType_SeparatorOfNestedList:
+ case XimType_NEST:
+ *len = 0;
+ break;
+
+ case XimType_CARD8:
+ ret_len = sizeof(CARD8);
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ *((CARD8 *)buf) = (CARD8)(long)value;
+ *len = ret_len;
+ break;
+
+ case XimType_CARD16:
+ ret_len = sizeof(CARD16);
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ *((CARD16 *)buf) = (CARD16)(long)value;
+ *len = ret_len;
+ break;
+
+ case XimType_CARD32:
+ case XimType_Window:
+ case XimType_XIMHotKeyState:
+ ret_len = sizeof(CARD32);
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ *((CARD32 *)buf) = (CARD32)(long)value;
+ *len = ret_len;
+ break;
+
+ case XimType_STRING8:
+ if (!value) {
+ *len = 0;
+ return False;
+ }
+
+ ret_len = strlen((char *)value);
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ (void)memcpy((char *)buf, (char *)value, ret_len);
+ *len = ret_len;
+ break;
+
+ case XimType_XRectangle:
+ {
+ XRectangle *rect = (XRectangle *)value;
+ CARD16 *buf_s = (CARD16 *)buf;
+
+ if (!rect) {
+ *len = 0;
+ return False;
+ }
+
+ ret_len = sizeof(INT16) /* sizeof X */
+ + sizeof(INT16) /* sizeof Y */
+ + sizeof(CARD16) /* sizeof width */
+ + sizeof(CARD16); /* sizeof height */
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ buf_s[0] = (CARD16)rect->x; /* X */
+ buf_s[1] = (CARD16)rect->y; /* Y */
+ buf_s[2] = (CARD16)rect->width; /* width */
+ buf_s[3] = (CARD16)rect->height; /* heght */
+ *len = ret_len;
+ break;
+ }
+
+ case XimType_XPoint:
+ {
+ XPoint *point = (XPoint *)value;
+ CARD16 *buf_s = (CARD16 *)buf;
+
+ if (!point) {
+ *len = 0;
+ return False;
+ }
+
+ ret_len = sizeof(INT16) /* sizeof X */
+ + sizeof(INT16); /* sizeof Y */
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ buf_s[0] = (CARD16)point->x; /* X */
+ buf_s[1] = (CARD16)point->y; /* Y */
+ *len = ret_len;
+ break;
+ }
+
+ case XimType_XFontSet:
+ {
+ XFontSet font = (XFontSet)value;
+ Xic ic = (Xic)param;
+ char *base_name = NULL;
+ int length = 0;
+ CARD16 *buf_s = (CARD16 *)buf;
+
+ if (!font) {
+ *len = 0;
+ return False;
+ }
+
+ if (mode & XIM_PREEDIT_ATTR) {
+ base_name = ic->private.proto.preedit_font;
+ length = ic->private.proto.preedit_font_length;
+ } else if (mode & XIM_STATUS_ATTR) {
+ base_name = ic->private.proto.status_font;
+ length = ic->private.proto.status_font_length;
+ }
+
+ if (!base_name) {
+ *len = 0;
+ return False;
+ }
+
+ ret_len = sizeof(CARD16) /* sizeof length of Base name */
+ + length; /* sizeof Base font name list */
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ buf_s[0] = (INT16)length; /* length of Base font name */
+ (void)memcpy((char *)&buf_s[1], base_name, length);
+ /* Base font name list */
+ *len = ret_len;
+ break;
+ }
+
+ case XimType_XIMHotKeyTriggers:
+ {
+ XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)value;
+ INT32 num;
+ CARD32 *buf_l = (CARD32 *)buf;
+ register CARD32 *key = (CARD32 *)&buf_l[1];
+ register int i;
+
+ if (!hotkey) {
+ *len = 0;
+ return False;
+ }
+ num = (INT32)hotkey->num_hot_key;
+
+ ret_len = sizeof(INT32) /* sizeof number of key list */
+ + (sizeof(CARD32) /* sizeof keysyn */
+ + sizeof(CARD32) /* sizeof modifier */
+ + sizeof(CARD32)) /* sizeof modifier_mask */
+ * num; /* number of key list */
+ if (buf_size < ret_len + XIM_PAD(ret_len)) {
+ *len = -1;
+ return False;
+ }
+
+ buf_l[0] = num; /* number of key list */
+ for (i = 0; i < num; i++, key += 3) {
+ key[0] = (CARD32)(hotkey->key[i].keysym);
+ /* keysym */
+ key[1] = (CARD32)(hotkey->key[i].modifier);
+ /* modifier */
+ key[2] = (CARD32)(hotkey->key[i].modifier_mask);
+ /* modifier_mask */
+ }
+ *len = ret_len;
+ break;
+ }
+
+ case XimType_XIMStringConversion:
+ {
+ *len = 0;
+ break;
+ }
+
+ default:
+ return False;
+ }
+ return True;
+}
+
+Private Bool
+_XimSetInnerIMAttributes(
+ Xim im,
+ XPointer top,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ int check;
+
+ if (!(res = _XimGetResourceListRec(im->private.proto.im_inner_resources,
+ im->private.proto.im_num_inner_resources, arg->name)))
+ return False;
+
+ check = _XimCheckIMMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ return True;
+ else if(check == XIM_CHECK_ERROR)
+ return False;
+
+ return _XimEncodeLocalIMAttr(res, top, arg->value);
+}
+
+Public char *
+_XimEncodeIMATTRIBUTE(
+ Xim im,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ XIMArg *arg,
+ XIMArg **arg_ret,
+ char *buf,
+ int size,
+ int *ret_len,
+ XPointer top,
+ unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ CARD16 *buf_s;
+ int len;
+ int min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(INT16); /* sizeof value length */
+
+ *ret_len = 0;
+ for (p = arg; p->name; p++) {
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimSetInnerIMAttributes(im, top, p, mode))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckIMMode(res, mode);
+ if (check == XIM_CHECK_INVALID)
+ continue;
+ else if (check == XIM_CHECK_ERROR)
+ return p->name;
+
+ if (!(_XimEncodeLocalIMAttr(res, top, p->value)))
+ return p->name;
+
+ buf_s = (CARD16 *)buf;
+ if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2], (size - min_len),
+ p->value, &len, mode, (XPointer)NULL)))
+ return p->name;
+
+ if (len == 0) {
+ continue;
+ } else if (len < 0) {
+ *arg_ret = p;
+ return (char *)NULL;
+ }
+
+ buf_s[0] = res->id; /* attribute ID */
+ buf_s[1] = len; /* value length */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += min_len;
+
+ buf += len;
+ *ret_len += len;
+ size -= len;
+ }
+ *arg_ret = (XIMArg *)NULL;
+ return (char *)NULL;
+}
+
+#ifdef XIM_CONNECTABLE
+Public Bool
+_XimEncodeSavedIMATTRIBUTE(
+ Xim im,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ int *idx,
+ char *buf,
+ int size,
+ int *ret_len,
+ XPointer top,
+ unsigned long mode)
+{
+ register int i;
+ int num = im->private.proto.num_saved_imvalues;
+ XrmQuark *quark_list = im->private.proto.saved_imvalues;
+ XIMResourceList res;
+ XPointer value;
+ CARD16 *buf_s;
+ int len;
+ int min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(INT16); /* sizeof value length */
+
+ if (!im->private.proto.saved_imvalues) {
+ *idx = -1;
+ *ret_len = 0;
+ return True;
+ }
+
+ *ret_len = 0;
+ for (i = *idx; i < num; i++) {
+ if (!(res = _XimGetResourceListRecByQuark(res_list,
+ res_num, quark_list[i])))
+ continue;
+
+ if (!_XimDecodeLocalIMAttr(res, top, value))
+ return False;
+
+ buf_s = (CARD16 *)buf;
+ if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
+ (size - min_len), value, &len, mode, (XPointer)NULL)))
+ return False;
+
+ if (len == 0) {
+ continue;
+ } else if (len < 0) {
+ *idx = i;
+ return True;
+ }
+
+ buf_s[0] = res->id; /* attribute ID */
+ buf_s[1] = len; /* value length */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += min_len;
+
+ buf += len;
+ *ret_len += len;
+ size -= len;
+ }
+ *idx = -1;
+ return True;
+}
+#endif /* XIM_CONNECTABLE */
+
+Private Bool
+_XimEncodeTopValue(
+ Xic ic,
+ XIMResourceList res,
+ XIMArg *p)
+{
+ if (res->xrm_name == XrmStringToQuark(XNClientWindow)) {
+ ic->core.client_window = (Window)p->value;
+ if (ic->core.focus_window == (Window)0)
+ ic->core.focus_window = ic->core.client_window;
+ _XimRegisterFilter(ic);
+
+ } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
+ if (ic->core.client_window) {
+ _XimUnregisterFilter(ic);
+ ic->core.focus_window = (Window)p->value;
+ _XimRegisterFilter(ic);
+ } else /* client_window not yet */
+ ic->core.focus_window = (Window)p->value;
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodePreeditValue(
+ Xic ic,
+ XIMResourceList res,
+ XIMArg *p)
+{
+ if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
+ XStandardColormap *colormap_ret;
+ int count;
+
+ if (!(XGetRGBColormaps(ic->core.im->core.display,
+ ic->core.focus_window, &colormap_ret,
+ &count, (Atom)p->value)))
+ return False;
+
+ XFree(colormap_ret);
+ } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
+ int list_ret;
+ XFontStruct **struct_list;
+ char **name_list;
+ char *tmp;
+ int len;
+ register int i;
+
+ if (!p->value)
+ return False;
+
+ if (ic->private.proto.preedit_font)
+ Xfree(ic->private.proto.preedit_font);
+
+ list_ret = XFontsOfFontSet((XFontSet)p->value,
+ &struct_list, &name_list);
+ for (i = 0, len = 0; i < list_ret; i++) {
+ len += (strlen(name_list[i]) + sizeof(char));
+ }
+ if (!(tmp = Xmalloc(len + 1))) {
+ ic->private.proto.preedit_font = NULL;
+ return False;
+ }
+
+ tmp[0] = '\0';
+ for (i = 0; i < list_ret; i++) {
+ strcat(tmp, name_list[i]);
+ strcat(tmp, ",");
+ }
+ tmp[len - 1] = 0;
+ ic->private.proto.preedit_font = tmp;
+ ic->private.proto.preedit_font_length = len - 1;
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeStatusValue(
+ Xic ic,
+ XIMResourceList res,
+ XIMArg *p)
+{
+ if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
+ XStandardColormap *colormap_ret = NULL;
+ int count;
+
+ if (!(XGetRGBColormaps(ic->core.im->core.display,
+ ic->core.focus_window, &colormap_ret,
+ &count, (Atom)p->value)))
+ return False;
+
+ XFree(colormap_ret);
+ } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
+ int list_ret;
+ XFontStruct **struct_list;
+ char **name_list;
+ char *tmp;
+ int len;
+ register int i;
+
+ if (!p->value)
+ return False;
+
+ if (ic->private.proto.status_font)
+ Xfree(ic->private.proto.status_font);
+
+ list_ret = XFontsOfFontSet((XFontSet)p->value,
+ &struct_list, &name_list);
+ for (i = 0, len = 0; i < list_ret; i++) {
+ len += (strlen(name_list[i]) + sizeof(char));
+ }
+ if (!(tmp = Xmalloc(len+1))) {
+ ic->private.proto.status_font = NULL;
+ return False;
+ }
+
+ tmp[0] = '\0';
+ for(i = 0; i < list_ret; i++) {
+ strcat(tmp, name_list[i]);
+ strcat(tmp, ",");
+ }
+ tmp[len - 1] = 0;
+ ic->private.proto.status_font = tmp;
+ ic->private.proto.status_font_length = len - 1;
+ }
+ return True;
+}
+
+Private Bool
+_XimSetInnerICAttributes(
+ Xic ic,
+ XPointer top,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ XIMResourceList res;
+ int check;
+
+ if (!(res = _XimGetResourceListRec(ic->private.proto.ic_inner_resources,
+ ic->private.proto.ic_num_inner_resources, arg->name)))
+ return False;
+
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID)
+ return True;
+ else if(check == XIM_CHECK_ERROR)
+ return False;
+
+ return _XimEncodeLocalICAttr(ic, res, top, arg, mode);
+}
+
+Public char *
+_XimEncodeICATTRIBUTE(
+ Xic ic,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ XIMArg *arg,
+ XIMArg **arg_ret,
+ char *buf,
+ int size,
+ int *ret_len,
+ XPointer top,
+ BITMASK32 *flag,
+ unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+ CARD16 *buf_s;
+ int len;
+ int min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(INT16); /* sizeof value length */
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+ char *name;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ *ret_len = 0;
+ for (p = arg; p && p->name; p++) {
+ buf_s = (CARD16 *)buf;
+ if (!(res = _XimGetResourceListRec(res_list, res_num, p->name))) {
+ if (_XimSetInnerICAttributes(ic, top, p, mode))
+ continue;
+ return p->name;
+ }
+
+ check = _XimCheckICMode(res, mode);
+ if (check == XIM_CHECK_INVALID)
+ continue;
+ else if (check == XIM_CHECK_ERROR)
+ return p->name;
+
+ if (mode & XIM_PREEDIT_ATTR) {
+ if (!(_XimEncodePreeditValue(ic, res, p)))
+ return p->name;
+ } else if (mode & XIM_STATUS_ATTR) {
+ if (!(_XimEncodeStatusValue(ic, res, p)))
+ return p->name;
+ } else {
+ if (!(_XimEncodeTopValue(ic, res, p)))
+ return p->name;
+ }
+
+ if (res->resource_size == XimType_NEST) {
+ XimDefICValues *ic_attr = (XimDefICValues *)top;
+
+ if (res->xrm_name == pre_quark) {
+ XIMArg *arg_rt;
+ if ((name = _XimEncodeICATTRIBUTE(ic, res_list, res_num,
+ (XIMArg *)p->value, &arg_rt,
+ (char *)&buf_s[2], (size - min_len),
+ &len, (XPointer)&ic_attr->preedit_attr, flag,
+ (mode | XIM_PREEDIT_ATTR)))) {
+ return name;
+ }
+
+ } else if (res->xrm_name == sts_quark) {
+ XIMArg *arg_rt;
+ if ((name = _XimEncodeICATTRIBUTE(ic, res_list, res_num,
+ (XIMArg *)p->value, &arg_rt,
+ (char *)&buf_s[2], (size - min_len),
+ &len, (XPointer)&ic_attr->status_attr, flag,
+ (mode | XIM_STATUS_ATTR)))) {
+ return name;
+ }
+ }
+ } else {
+#ifdef EXT_MOVE
+ if (flag)
+ *flag |= _XimExtenArgCheck(p);
+#endif
+ if (!(_XimEncodeLocalICAttr(ic, res, top, p, mode)))
+ return p->name;
+
+ if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
+ (size - min_len), p->value,
+ &len, mode, (XPointer)ic)))
+ return p->name;
+ }
+
+ if (len == 0) {
+ continue;
+ } else if (len < 0) {
+ *arg_ret = p;
+ return (char *)NULL;
+ }
+
+ buf_s[0] = res->id; /* attribute ID */
+ buf_s[1] = len; /* value length */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += min_len;
+
+ buf += len;
+ *ret_len += len;
+ size -= len;
+ }
+ *arg_ret = (XIMArg *)NULL;
+ return (char *)NULL;
+}
+
+#ifdef XIM_CONNECTABLE
+Private Bool
+_XimEncodeSavedPreeditValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer value)
+{
+ int list_ret;
+ XFontStruct **struct_list;
+ char **name_list;
+ char *tmp;
+ int len;
+ register int i;
+
+ if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
+ if (!value)
+ return False;
+
+ if (ic->private.proto.preedit_font)
+ Xfree(ic->private.proto.preedit_font);
+
+ list_ret = XFontsOfFontSet((XFontSet)value,
+ &struct_list, &name_list);
+ for(i = 0, len = 0; i < list_ret; i++) {
+ len += (strlen(name_list[i]) + sizeof(char));
+ }
+ if(!(tmp = Xmalloc(len + 1))) {
+ ic->private.proto.preedit_font = NULL;
+ return False;
+ }
+
+ tmp[0] = '\0';
+ for(i = 0; i < list_ret; i++) {
+ strcat(tmp, name_list[i]);
+ strcat(tmp, ",");
+ }
+ tmp[len - 1] = 0;
+ ic->private.proto.preedit_font = tmp;
+ ic->private.proto.preedit_font_length = len - 1;
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeSavedStatusValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer value)
+{
+ int list_ret;
+ XFontStruct **struct_list;
+ char **name_list;
+ char *tmp;
+ int len;
+ register int i;
+
+ if (res->xrm_name == XrmStringToQuark(XNFontSet)) {
+ if (!value)
+ return False;
+
+ if (ic->private.proto.status_font)
+ Xfree(ic->private.proto.status_font);
+
+ list_ret = XFontsOfFontSet((XFontSet)value,
+ &struct_list, &name_list);
+ for(i = 0, len = 0; i < list_ret; i++) {
+ len += (strlen(name_list[i]) + sizeof(char));
+ }
+ if(!(tmp = Xmalloc(len + 1))) {
+ ic->private.proto.status_font = NULL;
+ return False;
+ }
+
+ tmp[0] = '\0';
+ for(i = 0; i < list_ret; i++) {
+ strcat(tmp, name_list[i]);
+ strcat(tmp, ",");
+ }
+ tmp[len - 1] = 0;
+ ic->private.proto.status_font = tmp;
+ ic->private.proto.status_font_length = len - 1;
+ }
+ return True;
+}
+
+Public Bool
+_XimEncodeSavedICATTRIBUTE(
+ Xic ic,
+ XIMResourceList res_list,
+ unsigned int res_num,
+ int *idx,
+ char *buf,
+ int size,
+ int *ret_len,
+ XPointer top,
+ unsigned long mode)
+{
+ int i;
+ int num = ic->private.proto.num_saved_icvalues;
+ XrmQuark *quark_list = ic->private.proto.saved_icvalues;
+ XIMResourceList res;
+ XPointer value;
+ CARD16 *buf_s;
+ int len;
+ int min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(INT16); /* sizeof value length */
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+ XrmQuark separator;
+
+ if (!ic->private.proto.saved_icvalues) {
+ *idx = -1;
+ *ret_len = 0;
+ return True;
+ }
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+ separator = XrmStringToQuark(XNSeparatorofNestedList);
+
+ *ret_len = 0;
+ for (i = *idx; i < num; i++) {
+ if (quark_list[i] == separator) {
+ *idx = i;
+ return True;
+ }
+
+ if (!(res = _XimGetResourceListRecByQuark(res_list,
+ res_num, quark_list[i])))
+ continue;
+
+ if (!_XimDecodeLocalICAttr(res, top,(XPointer)&value, mode))
+ return False;
+
+ if (mode & XIM_PREEDIT_ATTR) {
+ if (!(_XimEncodeSavedPreeditValue(ic, res, value))) {
+ return False;
+ }
+ } else if (mode & XIM_STATUS_ATTR) {
+ if (!(_XimEncodeSavedStatusValue(ic, res, value))) {
+ return False;
+ }
+ }
+
+ buf_s = (CARD16 *)buf;
+ if (res->resource_size == XimType_NEST) {
+ XimDefICValues *ic_attr = (XimDefICValues *)top;
+
+ i++;
+ if (res->xrm_name == pre_quark) {
+ if (!_XimEncodeSavedICATTRIBUTE(ic, res_list, res_num,
+ &i, (char *)&buf_s[2], (size - min_len),
+ &len, (XPointer)&ic_attr->preedit_attr,
+ (mode | XIM_PREEDIT_ATTR))) {
+ return False;
+ }
+
+ } else if (res->xrm_name == sts_quark) {
+ if (!_XimEncodeSavedICATTRIBUTE(ic, res_list, res_num,
+ &i, (char *)&buf_s[2], (size - min_len),
+ &len, (XPointer)&ic_attr->status_attr,
+ (mode | XIM_STATUS_ATTR))) {
+ return False;
+ }
+ }
+ } else {
+ if (!(_XimValueToAttribute(res, (XPointer)&buf_s[2],
+ (size - min_len), value,
+ &len, mode, (XPointer)ic))) {
+ return False;
+ }
+ }
+
+ if (len == 0) {
+ continue;
+ } else if (len < 0) {
+ if (quark_list[i] == separator)
+ i++;
+ *idx = i;
+ return True;
+ }
+
+ buf_s[0] = res->id; /* attribute ID */
+ buf_s[1] = len; /* value length */
+ XIM_SET_PAD(&buf_s[2], len); /* pad */
+ len += min_len;
+
+ buf += len;
+ *ret_len += len;
+ size -= len;
+ }
+ *idx = -1;
+ return True;
+}
+#endif /* XIM_CONNECTABLE */
+
+Private unsigned int
+_XimCountNumberOfAttr(
+ INT16 total,
+ CARD16 *attr,
+ int *names_len)
+{
+ unsigned int n;
+ INT16 len;
+ INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(CARD16) /* sizeof type of value */
+ + sizeof(INT16); /* sizeof length of attribute */
+
+ n = 0;
+ *names_len = 0;
+ while (total > min_len) {
+ len = attr[2];
+ *names_len += (len + 1);
+ len += (min_len + XIM_PAD(len + 2));
+ total -= len;
+ attr = (CARD16 *)((char *)attr + len);
+ n++;
+ }
+ return n;
+}
+
+Public Bool
+_XimGetAttributeID(
+ Xim im,
+ CARD16 *buf)
+{
+ unsigned int n;
+ XIMResourceList res;
+ int res_len;
+ char *names;
+ int names_len;
+ XPointer tmp;
+ XIMValuesList *values_list;
+ char **values;
+ int values_len;
+ register int i;
+ INT16 len;
+ INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */
+ + sizeof(CARD16) /* sizeof type of value */
+ + sizeof(INT16); /* sizeof length of attr */
+ /*
+ * IM attribute ID
+ */
+
+ if (!(n = _XimCountNumberOfAttr(buf[0], &buf[1], &names_len)))
+ return False;
+ res_len = sizeof(XIMResource) * n;
+
+ if (!(res = (XIMResourceList)Xmalloc(res_len)))
+ return False;
+ bzero((char *)res, res_len);
+
+ values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len;
+ if (!(tmp = (XPointer)Xmalloc(values_len)))
+ return False;
+ bzero(tmp, values_len);
+
+ values_list = (XIMValuesList *)tmp;
+ values = (char **)((char *)tmp + sizeof(XIMValuesList));
+ names = (char *)((char *)values + (sizeof(char **) * n));
+
+ values_list->count_values = n;
+ values_list->supported_values = values;
+
+ buf++;
+ for (i = 0; i < n; i++) {
+ len = buf[2];
+ (void)memcpy(names, (char *)&buf[3], len);
+ values[i] = names;
+ names[len] = '\0';
+ res[i].resource_name = names;
+ res[i].resource_size = buf[1];
+ res[i].id = buf[0];
+ names += (len + 1);
+ len += (min_len + XIM_PAD(len + 2));
+ buf = (CARD16 *)((char *)buf + len);
+ }
+ _XIMCompileResourceList(res, n);
+
+ if (im->core.im_resources)
+ Xfree(im->core.im_resources);
+ if (im->core.im_values_list)
+ Xfree(im->core.im_values_list);
+ im->core.im_resources = res;
+ im->core.im_num_resources = n;
+ im->core.im_values_list = values_list;
+
+ /*
+ * IC attribute ID
+ */
+
+ if (!(n = _XimCountNumberOfAttr(buf[0], &buf[2], &names_len)))
+ return False;
+ res_len = sizeof(XIMResource) * n;
+
+ if (!(res = (XIMResourceList)Xmalloc(res_len)))
+ return False;
+ bzero((char *)res, res_len);
+
+ values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len;
+ if (!(tmp = (XPointer)Xmalloc(values_len)))
+ return False;
+ bzero(tmp, values_len);
+
+ values_list = (XIMValuesList *)tmp;
+ values = (char **)((char *)tmp + sizeof(XIMValuesList));
+ names = (char *)((char *)values + (sizeof(char **) * n));
+
+ values_list->count_values = n;
+ values_list->supported_values = values;
+
+ buf += 2;
+ for (i = 0; i < n; i++) {
+ len = buf[2];
+ (void)memcpy(names, (char *)&buf[3], len);
+ values[i] = names;
+ names[len] = '\0';
+ res[i].resource_name = names;
+ res[i].resource_size = buf[1];
+ res[i].id = buf[0];
+ names += (len + 1);
+ len += (min_len + XIM_PAD(len + 2));
+ buf = (CARD16 *)((char *)buf + len);
+ }
+ _XIMCompileResourceList(res, n);
+
+ if (im->core.ic_resources)
+ Xfree(im->core.ic_resources);
+ if (im->core.ic_values_list)
+ Xfree(im->core.ic_values_list);
+ im->core.ic_resources = res;
+ im->core.ic_num_resources = n;
+ im->core.ic_values_list = values_list;
+
+ return True;
+}
diff --git a/libX11/modules/im/ximcp/imTrans.c b/libX11/modules/im/ximcp/imTrans.c index 7673279c6..d6c5fc6ad 100644 --- a/libX11/modules/im/ximcp/imTrans.c +++ b/libX11/modules/im/ximcp/imTrans.c @@ -56,6 +56,7 @@ PERFORMANCE OF THIS SOFTWARE. #include <X11/Xatom.h>
#include <X11/Xmd.h>
#include "Xlibint.h"
+#include <X11/Xwindows.h>
#include <X11/Xtrans/Xtrans.h>
#include "Xlcint.h"
#include "Ximint.h"
diff --git a/libX11/modules/im/ximcp/makefile b/libX11/modules/im/ximcp/makefile new file mode 100644 index 000000000..ca80ad90e --- /dev/null +++ b/libX11/modules/im/ximcp/makefile @@ -0,0 +1,34 @@ +DEFINES += XIM_t TRANS_CLIENT + +LIBRARY=libximcp + +CSRCS = \ + imCallbk.c \ + imDefFlt.c \ + imDefIc.c \ + imDefIm.c \ + imDefLkup.c \ + imDispch.c \ + imEvToWire.c \ + imExten.c \ + imImSw.c \ + imInsClbk.c \ + imInt.c \ + imLcFlt.c \ + imLcGIc.c \ + imLcIc.c \ + imLcIm.c \ + imLcLkup.c \ + imLcPrs.c \ + imLcSIc.c \ + imRmAttr.c \ + imRm.c \ + imThaiFlt.c \ + imThaiIc.c \ + imThaiIm.c \ + imTrans.c \ + imTransR.c \ + imTrX.c + +INCLUDES += ..\..\..\include\X11 ..\..\..\src\xlibi18n + |