| File: | modules/im/ximcp/imDefLkup.c |
| Location: | line 561, column 28 |
| Description: | The left operand of '==' is a garbage value |
| 1 | /****************************************************************** | |||
| 2 | ||||
| 3 | Copyright 1992, 1993, 1994 by FUJITSU LIMITED | |||
| 4 | ||||
| 5 | Permission to use, copy, modify, distribute, and sell this software | |||
| 6 | and its documentation for any purpose is hereby granted without fee, | |||
| 7 | provided that the above copyright notice appear in all copies and | |||
| 8 | that both that copyright notice and this permission notice appear | |||
| 9 | in supporting documentation, and that the name of FUJITSU LIMITED | |||
| 10 | not be used in advertising or publicity pertaining to distribution | |||
| 11 | of the software without specific, written prior permission. | |||
| 12 | FUJITSU LIMITED makes no representations about the suitability of | |||
| 13 | this software for any purpose. | |||
| 14 | It is provided "as is" without express or implied warranty. | |||
| 15 | ||||
| 16 | FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |||
| 17 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | |||
| 18 | EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |||
| 19 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF | |||
| 20 | USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | |||
| 21 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |||
| 22 | PERFORMANCE OF THIS SOFTWARE. | |||
| 23 | ||||
| 24 | Author: Takashi Fujiwara FUJITSU LIMITED | |||
| 25 | fujiwara@a80.tech.yk.fujitsu.co.jp | |||
| 26 | ||||
| 27 | ******************************************************************/ | |||
| 28 | ||||
| 29 | #ifdef HAVE_CONFIG_H1 | |||
| 30 | #include <config.h> | |||
| 31 | #endif | |||
| 32 | #include <X11/Xatom.h> | |||
| 33 | #include "Xlibint.h" | |||
| 34 | #include "Xlcint.h" | |||
| 35 | #include "Ximint.h" | |||
| 36 | ||||
| 37 | Xic | |||
| 38 | _XimICOfXICID( | |||
| 39 | Xim im, | |||
| 40 | XICID icid) | |||
| 41 | { | |||
| 42 | Xic pic; | |||
| 43 | ||||
| 44 | for (pic = (Xic)im->core.ic_chain; pic; pic = (Xic)pic->core.next) { | |||
| 45 | if (pic->private.proto.icid == icid) | |||
| 46 | return pic; | |||
| 47 | } | |||
| 48 | return (Xic)0; | |||
| 49 | } | |||
| 50 | ||||
| 51 | static void | |||
| 52 | _XimProcIMSetEventMask( | |||
| 53 | Xim im, | |||
| 54 | XPointer buf) | |||
| 55 | { | |||
| 56 | EVENTMASK *buf_l = (EVENTMASK *)buf; | |||
| 57 | ||||
| 58 | im->private.proto.forward_event_mask = buf_l[0]; | |||
| 59 | im->private.proto.synchronous_event_mask = buf_l[1]; | |||
| 60 | return; | |||
| 61 | } | |||
| 62 | ||||
| 63 | static void | |||
| 64 | _XimProcICSetEventMask( | |||
| 65 | Xic ic, | |||
| 66 | XPointer buf) | |||
| 67 | { | |||
| 68 | EVENTMASK *buf_l = (EVENTMASK *)buf; | |||
| 69 | ||||
| 70 | ic->private.proto.forward_event_mask = buf_l[0]; | |||
| 71 | ic->private.proto.synchronous_event_mask = buf_l[1]; | |||
| 72 | _XimReregisterFilter(ic); | |||
| 73 | return; | |||
| 74 | } | |||
| 75 | ||||
| 76 | Boolint | |||
| 77 | _XimSetEventMaskCallback( | |||
| 78 | Xim xim, | |||
| 79 | INT16 len, | |||
| 80 | XPointer data, | |||
| 81 | XPointer call_data) | |||
| 82 | { | |||
| 83 | CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 84 | XIMID imid = buf_s[0]; | |||
| 85 | XICID icid = buf_s[1]; | |||
| 86 | Xim im = (Xim)call_data; | |||
| 87 | Xic ic; | |||
| 88 | ||||
| 89 | if (imid == im->private.proto.imid) { | |||
| 90 | if (icid) { | |||
| 91 | ic = _XimICOfXICID(im, icid); | |||
| 92 | _XimProcICSetEventMask(ic, (XPointer)&buf_s[2]); | |||
| 93 | } else { | |||
| 94 | _XimProcIMSetEventMask(im, (XPointer)&buf_s[2]); | |||
| 95 | } | |||
| 96 | return True1; | |||
| 97 | } | |||
| 98 | return False0; | |||
| 99 | } | |||
| 100 | ||||
| 101 | static Boolint | |||
| 102 | _XimSyncCheck( | |||
| 103 | Xim im, | |||
| 104 | INT16 len, | |||
| 105 | XPointer data, | |||
| 106 | XPointer arg) | |||
| 107 | { | |||
| 108 | Xic ic = (Xic)arg; | |||
| 109 | CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 110 | CARD8 major_opcode = *((CARD8 *)data); | |||
| 111 | CARD8 minor_opcode = *((CARD8 *)data + 1); | |||
| 112 | XIMID imid = buf_s[0]; | |||
| 113 | XICID icid = buf_s[1]; | |||
| 114 | ||||
| 115 | if ((major_opcode == XIM_SYNC_REPLY62) | |||
| 116 | && (minor_opcode == 0) | |||
| 117 | && (imid == im->private.proto.imid) | |||
| 118 | && (icid == ic->private.proto.icid)) | |||
| 119 | return True1; | |||
| 120 | if ((major_opcode == XIM_ERROR20) | |||
| 121 | && (minor_opcode == 0) | |||
| 122 | && (buf_s[2] & XIM_IMID_VALID0x0001) | |||
| 123 | && (imid == im->private.proto.imid) | |||
| 124 | && (buf_s[2] & XIM_ICID_VALID0x0002) | |||
| 125 | && (icid == ic->private.proto.icid)) | |||
| 126 | return True1; | |||
| 127 | return False0; | |||
| 128 | } | |||
| 129 | ||||
| 130 | Boolint | |||
| 131 | _XimSync( | |||
| 132 | Xim im, | |||
| 133 | Xic ic) | |||
| 134 | { | |||
| 135 | CARD32 buf32[BUFSIZE2048/4]; | |||
| 136 | CARD8 *buf = (CARD8 *)buf32; | |||
| 137 | CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)]; | |||
| 138 | INT16 len; | |||
| 139 | CARD32 reply32[BUFSIZE2048/4]; | |||
| 140 | char *reply = (char *)reply32; | |||
| 141 | XPointer preply; | |||
| 142 | int buf_size; | |||
| 143 | int ret_code; | |||
| 144 | ||||
| 145 | buf_s[0] = im->private.proto.imid; /* imid */ | |||
| 146 | buf_s[1] = ic->private.proto.icid; /* icid */ | |||
| 147 | ||||
| 148 | len = sizeof(CARD16) /* sizeof imid */ | |||
| 149 | + sizeof(CARD16); /* sizeof icid */ | |||
| 150 | ||||
| 151 | _XimSetHeader((XPointer)buf, XIM_SYNC61, 0, &len); | |||
| 152 | if (!(_XimWrite(im, len, (XPointer)buf))) | |||
| 153 | return False0; | |||
| 154 | _XimFlush(im); | |||
| 155 | buf_size = BUFSIZE2048; | |||
| 156 | ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, | |||
| 157 | _XimSyncCheck, (XPointer)ic); | |||
| 158 | if(ret_code == XIM_TRUE1) { | |||
| 159 | preply = reply; | |||
| 160 | } else if(ret_code == XIM_OVERFLOW(-1)) { | |||
| 161 | if(len <= 0) { | |||
| 162 | preply = reply; | |||
| 163 | } else { | |||
| 164 | buf_size = len; | |||
| 165 | preply = Xmalloc(len)malloc(((len) == 0 ? 1 : (len))); | |||
| 166 | ret_code = _XimRead(im, &len, preply, buf_size, | |||
| 167 | _XimSyncCheck, (XPointer)ic); | |||
| 168 | if(ret_code != XIM_TRUE1) { | |||
| 169 | Xfree(preply)free((preply)); | |||
| 170 | return False0; | |||
| 171 | } | |||
| 172 | } | |||
| 173 | } else { | |||
| 174 | return False0; | |||
| 175 | } | |||
| 176 | buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 177 | if (*((CARD8 *)preply) == XIM_ERROR20) { | |||
| 178 | _XimProcError(im, 0, (XPointer)&buf_s[3]); | |||
| 179 | if(reply != preply) | |||
| 180 | Xfree(preply)free((preply)); | |||
| 181 | return False0; | |||
| 182 | } | |||
| 183 | if(reply != preply) | |||
| 184 | Xfree(preply)free((preply)); | |||
| 185 | return True1; | |||
| 186 | } | |||
| 187 | ||||
| 188 | Boolint | |||
| 189 | _XimProcSyncReply( | |||
| 190 | Xim im, | |||
| 191 | Xic ic) | |||
| 192 | { | |||
| 193 | CARD32 buf32[BUFSIZE2048/4]; | |||
| 194 | CARD8 *buf = (CARD8 *)buf32; | |||
| 195 | CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)]; | |||
| 196 | INT16 len; | |||
| 197 | ||||
| 198 | buf_s[0] = im->private.proto.imid; /* imid */ | |||
| 199 | buf_s[1] = ic->private.proto.icid; /* icid */ | |||
| 200 | ||||
| 201 | len = sizeof(CARD16) /* sizeof imid */ | |||
| 202 | + sizeof(CARD16); /* sizeof icid */ | |||
| 203 | ||||
| 204 | _XimSetHeader((XPointer)buf, XIM_SYNC_REPLY62, 0, &len); | |||
| 205 | if (!(_XimWrite(im, len, (XPointer)buf))) | |||
| 206 | return False0; | |||
| 207 | _XimFlush(im); | |||
| 208 | return True1; | |||
| 209 | } | |||
| 210 | ||||
| 211 | Boolint | |||
| 212 | _XimRespSyncReply( | |||
| 213 | Xic ic, | |||
| 214 | BITMASK16 mode) | |||
| 215 | { | |||
| 216 | if (mode & XimSYNCHRONUS0x0001) /* SYNC Request */ | |||
| 217 | MARK_NEED_SYNC_REPLY(ic->core.im)(((Xim)ic->core.im)->private.proto.flag |= (1L << 6)); | |||
| 218 | ||||
| 219 | return True1; | |||
| 220 | } | |||
| 221 | ||||
| 222 | Boolint | |||
| 223 | _XimSyncCallback( | |||
| 224 | Xim xim, | |||
| 225 | INT16 len, | |||
| 226 | XPointer data, | |||
| 227 | XPointer call_data) | |||
| 228 | { | |||
| 229 | CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 230 | XIMID imid = buf_s[0]; | |||
| 231 | XICID icid = buf_s[1]; | |||
| 232 | Xim im = (Xim)call_data; | |||
| 233 | Xic ic; | |||
| 234 | ||||
| 235 | if ((imid == im->private.proto.imid) | |||
| 236 | && (ic = _XimICOfXICID(im, icid))) { | |||
| 237 | (void)_XimProcSyncReply(im, ic); | |||
| 238 | return True1; | |||
| 239 | } | |||
| 240 | return False0; | |||
| 241 | } | |||
| 242 | ||||
| 243 | static INT16 | |||
| 244 | _XimSetEventToWire( | |||
| 245 | XEvent *ev, | |||
| 246 | xEvent *event) | |||
| 247 | { | |||
| 248 | if (!(_XimProtoEventToWire(ev, event, False0))) | |||
| 249 | return 0; | |||
| 250 | event->u.u.sequenceNumber = | |||
| 251 | ((XAnyEvent *)ev)->serial & (unsigned long)0xffff; | |||
| 252 | return sz_xEvent32; | |||
| 253 | } | |||
| 254 | ||||
| 255 | static Boolint | |||
| 256 | _XimForwardEventCore( | |||
| 257 | Xic ic, | |||
| 258 | XEvent *ev, | |||
| 259 | Boolint sync) | |||
| 260 | { | |||
| 261 | Xim im = (Xim)ic->core.im; | |||
| 262 | CARD32 buf32[BUFSIZE2048/4]; | |||
| 263 | CARD8 *buf = (CARD8 *)buf32; | |||
| 264 | CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)]; | |||
| 265 | CARD32 reply32[BUFSIZE2048/4]; | |||
| 266 | char *reply = (char *)reply32; | |||
| 267 | XPointer preply; | |||
| 268 | int buf_size; | |||
| 269 | int ret_code; | |||
| 270 | INT16 len; | |||
| 271 | ||||
| 272 | bzero(buf32, sizeof(buf32))__builtin___memset_chk (buf32, 0, sizeof(buf32), __builtin_object_size (buf32, 0)); /* valgrind noticed uninitialized memory use! */ | |||
| 273 | ||||
| 274 | if (!(len = _XimSetEventToWire(ev, (xEvent *)&buf_s[4]))) | |||
| 275 | return False0; /* X event */ | |||
| 276 | ||||
| 277 | buf_s[0] = im->private.proto.imid; /* imid */ | |||
| 278 | buf_s[1] = ic->private.proto.icid; /* icid */ | |||
| 279 | buf_s[2] = sync ? XimSYNCHRONUS0x0001 : 0; /* flag */ | |||
| 280 | buf_s[3] = | |||
| 281 | (CARD16)((((XAnyEvent *)ev)->serial & ~((unsigned long)0xffff)) >> 16); | |||
| 282 | /* serial number */ | |||
| 283 | ||||
| 284 | len += sizeof(CARD16) /* sizeof imid */ | |||
| 285 | + sizeof(CARD16) /* sizeof icid */ | |||
| 286 | + sizeof(BITMASK16) /* sizeof flag */ | |||
| 287 | + sizeof(CARD16); /* sizeof serila number */ | |||
| 288 | ||||
| 289 | _XimSetHeader((XPointer)buf, XIM_FORWARD_EVENT60, 0, &len); | |||
| 290 | if (!(_XimWrite(im, len, (XPointer)buf))) | |||
| 291 | return False0; | |||
| 292 | _XimFlush(im); | |||
| 293 | ||||
| 294 | if (sync) { | |||
| 295 | buf_size = BUFSIZE2048; | |||
| 296 | ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, | |||
| 297 | _XimSyncCheck, (XPointer)ic); | |||
| 298 | if(ret_code == XIM_TRUE1) { | |||
| 299 | preply = reply; | |||
| 300 | } else if(ret_code == XIM_OVERFLOW(-1)) { | |||
| 301 | if(len <= 0) { | |||
| 302 | preply = reply; | |||
| 303 | } else { | |||
| 304 | buf_size = len; | |||
| 305 | preply = Xmalloc(len)malloc(((len) == 0 ? 1 : (len))); | |||
| 306 | ret_code = _XimRead(im, &len, preply, buf_size, | |||
| 307 | _XimSyncCheck, (XPointer)ic); | |||
| 308 | if(ret_code != XIM_TRUE1) { | |||
| 309 | Xfree(preply)free((preply)); | |||
| 310 | return False0; | |||
| 311 | } | |||
| 312 | } | |||
| 313 | } else { | |||
| 314 | return False0; | |||
| 315 | } | |||
| 316 | buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 317 | if (*((CARD8 *)preply) == XIM_ERROR20) { | |||
| 318 | _XimProcError(im, 0, (XPointer)&buf_s[3]); | |||
| 319 | if(reply != preply) | |||
| 320 | Xfree(preply)free((preply)); | |||
| 321 | return False0; | |||
| 322 | } | |||
| 323 | if(reply != preply) | |||
| 324 | Xfree(preply)free((preply)); | |||
| 325 | } | |||
| 326 | return True1; | |||
| 327 | } | |||
| 328 | ||||
| 329 | Boolint | |||
| 330 | _XimForwardEvent( | |||
| 331 | Xic ic, | |||
| 332 | XEvent *ev, | |||
| 333 | Boolint sync) | |||
| 334 | { | |||
| 335 | #ifdef EXT_FORWARD | |||
| 336 | if (((ev->type == KeyPress2) || (ev->type == KeyRelease3))) | |||
| 337 | if (_XimExtForwardKeyEvent(ic, (XKeyEvent *)ev, sync)) | |||
| 338 | return True1; | |||
| 339 | #endif | |||
| 340 | return _XimForwardEventCore(ic, ev, sync); | |||
| 341 | } | |||
| 342 | ||||
| 343 | static void | |||
| 344 | _XimProcEvent( | |||
| 345 | Display *d, | |||
| 346 | Xic ic, | |||
| 347 | XEvent *ev, | |||
| 348 | CARD16 *buf) | |||
| 349 | { | |||
| 350 | INT16 serial = buf[0]; | |||
| 351 | xEvent *xev = (xEvent *)&buf[1]; | |||
| 352 | ||||
| 353 | _XimProtoWireToEvent(ev, xev, False0); | |||
| 354 | ev->xany.serial |= serial << 16; | |||
| 355 | ev->xany.send_event = False0; | |||
| 356 | ev->xany.display = d; | |||
| 357 | MARK_FABRICATED(ic->core.im)(((Xim)ic->core.im)->private.proto.flag |= (1L << 5)); | |||
| 358 | return; | |||
| 359 | } | |||
| 360 | ||||
| 361 | static Boolint | |||
| 362 | _XimForwardEventRecv( | |||
| 363 | Xim im, | |||
| 364 | Xic ic, | |||
| 365 | XPointer buf) | |||
| 366 | { | |||
| 367 | CARD16 *buf_s = (CARD16 *)buf; | |||
| 368 | Display *d = im->core.display; | |||
| 369 | XEvent ev; | |||
| 370 | ||||
| 371 | _XimProcEvent(d, ic, &ev, &buf_s[1]); | |||
| 372 | ||||
| 373 | (void)_XimRespSyncReply(ic, buf_s[0]); | |||
| 374 | ||||
| 375 | XPutBackEvent(d, &ev); | |||
| 376 | ||||
| 377 | return True1; | |||
| 378 | } | |||
| 379 | ||||
| 380 | Boolint | |||
| 381 | _XimForwardEventCallback( | |||
| 382 | Xim xim, | |||
| 383 | INT16 len, | |||
| 384 | XPointer data, | |||
| 385 | XPointer call_data) | |||
| 386 | { | |||
| 387 | CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 388 | XIMID imid = buf_s[0]; | |||
| 389 | XICID icid = buf_s[1]; | |||
| 390 | Xim im = (Xim)call_data; | |||
| 391 | Xic ic; | |||
| 392 | ||||
| 393 | if ((imid == im->private.proto.imid) | |||
| 394 | && (ic = _XimICOfXICID(im, icid))) { | |||
| 395 | (void)_XimForwardEventRecv(im, ic, (XPointer)&buf_s[2]); | |||
| 396 | return True1; | |||
| 397 | } | |||
| 398 | return False0; | |||
| 399 | } | |||
| 400 | ||||
| 401 | static Boolint | |||
| 402 | _XimRegisterTriggerkey( | |||
| 403 | Xim im, | |||
| 404 | XPointer buf) | |||
| 405 | { | |||
| 406 | CARD32 *buf_l = (CARD32 *)buf; | |||
| 407 | CARD32 len; | |||
| 408 | CARD32 *key; | |||
| 409 | ||||
| 410 | if (IS_DYNAMIC_EVENT_FLOW(im)(((Xim)im)->private.proto.flag & (1L << 1))) /* already Dynamic event flow mode */ | |||
| 411 | return True1; | |||
| 412 | ||||
| 413 | /* | |||
| 414 | * register onkeylist | |||
| 415 | */ | |||
| 416 | ||||
| 417 | len = buf_l[0]; /* length of on-keys */ | |||
| 418 | len += sizeof(INT32); /* sizeof length of on-keys */ | |||
| 419 | ||||
| 420 | if (!(key = Xmalloc(len)malloc(((len) == 0 ? 1 : (len))))) { | |||
| 421 | _XimError(im, 0, XIM_BadAlloc1, (INT16)0, (CARD16)0, (char *)NULL((void*)0)); | |||
| 422 | return False0; | |||
| 423 | } | |||
| 424 | memcpy((char *)key, (char *)buf_l, len)__builtin___memcpy_chk ((char *)key, (char *)buf_l, len, __builtin_object_size ((char *)key, 0)); | |||
| 425 | im->private.proto.im_onkeylist = key; | |||
| 426 | ||||
| 427 | MARK_DYNAMIC_EVENT_FLOW(im)(((Xim)im)->private.proto.flag |= (1L << 1)); | |||
| 428 | ||||
| 429 | /* | |||
| 430 | * register offkeylist | |||
| 431 | */ | |||
| 432 | ||||
| 433 | buf_l = (CARD32 *)((char *)buf + len); | |||
| 434 | len = buf_l[0]; /* length of off-keys */ | |||
| 435 | len += sizeof(INT32); /* sizeof length of off-keys */ | |||
| 436 | ||||
| 437 | if (!(key = Xmalloc(len)malloc(((len) == 0 ? 1 : (len))))) { | |||
| 438 | _XimError(im, 0, XIM_BadAlloc1, (INT16)0, (CARD16)0, (char *)NULL((void*)0)); | |||
| 439 | return False0; | |||
| 440 | } | |||
| 441 | ||||
| 442 | memcpy((char *)key, (char *)buf_l, len)__builtin___memcpy_chk ((char *)key, (char *)buf_l, len, __builtin_object_size ((char *)key, 0)); | |||
| 443 | im->private.proto.im_offkeylist = key; | |||
| 444 | ||||
| 445 | return True1; | |||
| 446 | } | |||
| 447 | ||||
| 448 | Boolint | |||
| 449 | _XimRegisterTriggerKeysCallback( | |||
| 450 | Xim xim, | |||
| 451 | INT16 len, | |||
| 452 | XPointer data, | |||
| 453 | XPointer call_data) | |||
| 454 | { | |||
| 455 | CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 456 | Xim im = (Xim)call_data; | |||
| 457 | ||||
| 458 | (void )_XimRegisterTriggerkey(im, (XPointer)&buf_s[2]); | |||
| 459 | return True1; | |||
| 460 | } | |||
| 461 | ||||
| 462 | EVENTMASK | |||
| 463 | _XimGetWindowEventmask( | |||
| 464 | Xic ic) | |||
| 465 | { | |||
| 466 | Xim im = (Xim )ic->core.im; | |||
| 467 | XWindowAttributes atr; | |||
| 468 | ||||
| 469 | if (!XGetWindowAttributes(im->core.display, ic->core.focus_window, &atr)) | |||
| 470 | return 0; | |||
| 471 | return (EVENTMASK)atr.your_event_mask; | |||
| 472 | } | |||
| 473 | ||||
| 474 | ||||
| 475 | static Boolint | |||
| 476 | _XimTriggerNotifyCheck( | |||
| 477 | Xim im, | |||
| 478 | INT16 len, | |||
| 479 | XPointer data, | |||
| 480 | XPointer arg) | |||
| 481 | { | |||
| 482 | Xic ic = (Xic)arg; | |||
| 483 | CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 484 | CARD8 major_opcode = *((CARD8 *)data); | |||
| 485 | CARD8 minor_opcode = *((CARD8 *)data + 1); | |||
| 486 | XIMID imid = buf_s[0]; | |||
| 487 | XICID icid = buf_s[1]; | |||
| 488 | ||||
| 489 | if ((major_opcode == XIM_TRIGGER_NOTIFY_REPLY36) | |||
| 490 | && (minor_opcode == 0) | |||
| 491 | && (imid == im->private.proto.imid) | |||
| 492 | && (icid == ic->private.proto.icid)) | |||
| 493 | return True1; | |||
| 494 | if ((major_opcode == XIM_ERROR20) | |||
| 495 | && (minor_opcode == 0) | |||
| 496 | && (buf_s[2] & XIM_IMID_VALID0x0001) | |||
| 497 | && (imid == im->private.proto.imid) | |||
| 498 | && (buf_s[2] & XIM_ICID_VALID0x0002) | |||
| 499 | && (icid == ic->private.proto.icid)) | |||
| 500 | return True1; | |||
| 501 | return False0; | |||
| 502 | } | |||
| 503 | ||||
| 504 | Boolint | |||
| 505 | _XimTriggerNotify( | |||
| 506 | Xim im, | |||
| 507 | Xic ic, | |||
| 508 | int mode, | |||
| 509 | CARD32 idx) | |||
| 510 | { | |||
| 511 | CARD32 buf32[BUFSIZE2048/4]; | |||
| 512 | CARD8 *buf = (CARD8 *)buf32; | |||
| 513 | CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)]; | |||
| 514 | CARD32 *buf_l = (CARD32 *)&buf[XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)]; | |||
| 515 | CARD32 reply32[BUFSIZE2048/4]; | |||
| 516 | char *reply = (char *)reply32; | |||
| 517 | XPointer preply; | |||
| 518 | int buf_size; | |||
| 519 | int ret_code; | |||
| 520 | INT16 len; | |||
| 521 | EVENTMASK mask = _XimGetWindowEventmask(ic); | |||
| 522 | ||||
| 523 | buf_s[0] = im->private.proto.imid; /* imid */ | |||
| 524 | buf_s[1] = ic->private.proto.icid; /* icid */ | |||
| 525 | buf_l[1] = mode; /* flag */ | |||
| 526 | buf_l[2] = idx; /* index of keys list */ | |||
| 527 | buf_l[3] = mask; /* select-event-mask */ | |||
| 528 | ||||
| 529 | len = sizeof(CARD16) /* sizeof imid */ | |||
| 530 | + sizeof(CARD16) /* sizeof icid */ | |||
| 531 | + sizeof(CARD32) /* sizeof flag */ | |||
| 532 | + sizeof(CARD32) /* sizeof index of key list */ | |||
| 533 | + sizeof(EVENTMASK); /* sizeof select-event-mask */ | |||
| 534 | ||||
| 535 | _XimSetHeader((XPointer)buf, XIM_TRIGGER_NOTIFY35, 0, &len); | |||
| 536 | if (!(_XimWrite(im, len, (XPointer)buf))) | |||
| ||||
| 537 | return False0; | |||
| 538 | _XimFlush(im); | |||
| 539 | buf_size = BUFSIZE2048; | |||
| 540 | ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, | |||
| 541 | _XimTriggerNotifyCheck, (XPointer)ic); | |||
| 542 | if(ret_code == XIM_TRUE1) { | |||
| 543 | preply = reply; | |||
| 544 | } else if(ret_code == XIM_OVERFLOW(-1)) { | |||
| 545 | if(len <= 0) { | |||
| 546 | preply = reply; | |||
| 547 | } else { | |||
| 548 | buf_size = len; | |||
| 549 | preply = Xmalloc(len)malloc(((len) == 0 ? 1 : (len))); | |||
| 550 | ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, | |||
| 551 | _XimTriggerNotifyCheck, (XPointer)ic); | |||
| 552 | if(ret_code != XIM_TRUE1) { | |||
| 553 | Xfree(preply)free((preply)); | |||
| 554 | return False0; | |||
| 555 | } | |||
| 556 | } | |||
| 557 | } else { | |||
| 558 | return False0; | |||
| 559 | } | |||
| 560 | buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 561 | if (*((CARD8 *)preply) == XIM_ERROR20) { | |||
| ||||
| 562 | _XimProcError(im, 0, (XPointer)&buf_s[3]); | |||
| 563 | if(reply != preply) | |||
| 564 | Xfree(preply)free((preply)); | |||
| 565 | return False0; | |||
| 566 | } | |||
| 567 | if(reply != preply) | |||
| 568 | Xfree(preply)free((preply)); | |||
| 569 | return True1; | |||
| 570 | } | |||
| 571 | ||||
| 572 | static Boolint | |||
| 573 | _XimRegCommitInfo( | |||
| 574 | Xic ic, | |||
| 575 | char *string, | |||
| 576 | int string_len, | |||
| 577 | KeySym *keysym, | |||
| 578 | int keysym_len) | |||
| 579 | { | |||
| 580 | XimCommitInfo info; | |||
| 581 | ||||
| 582 | if (!(info = Xmalloc(sizeof(XimCommitInfoRec))malloc(((sizeof(XimCommitInfoRec)) == 0 ? 1 : (sizeof(XimCommitInfoRec )))))) | |||
| 583 | return False0; | |||
| 584 | info->string = string; | |||
| 585 | info->string_len = string_len; | |||
| 586 | info->keysym = keysym; | |||
| 587 | info->keysym_len = keysym_len; | |||
| 588 | info->next = ic->private.proto.commit_info; | |||
| 589 | ic->private.proto.commit_info = info; | |||
| 590 | return True1; | |||
| 591 | } | |||
| 592 | ||||
| 593 | static void | |||
| 594 | _XimUnregCommitInfo( | |||
| 595 | Xic ic) | |||
| 596 | { | |||
| 597 | XimCommitInfo info; | |||
| 598 | ||||
| 599 | if (!(info = ic->private.proto.commit_info)) | |||
| 600 | return; | |||
| 601 | ||||
| 602 | ||||
| 603 | Xfree(info->string)free((info->string)); | |||
| 604 | Xfree(info->keysym)free((info->keysym)); | |||
| 605 | ic->private.proto.commit_info = info->next; | |||
| 606 | Xfree(info)free((info)); | |||
| 607 | return; | |||
| 608 | } | |||
| 609 | ||||
| 610 | void | |||
| 611 | _XimFreeCommitInfo( | |||
| 612 | Xic ic) | |||
| 613 | { | |||
| 614 | while (ic->private.proto.commit_info) | |||
| 615 | _XimUnregCommitInfo(ic); | |||
| 616 | return; | |||
| 617 | } | |||
| 618 | ||||
| 619 | static Boolint | |||
| 620 | _XimProcKeySym( | |||
| 621 | Xic ic, | |||
| 622 | CARD32 sym, | |||
| 623 | KeySym **xim_keysym, | |||
| 624 | int *xim_keysym_len) | |||
| 625 | { | |||
| 626 | Xim im = (Xim)ic->core.im; | |||
| 627 | ||||
| 628 | if (!(*xim_keysym = Xmalloc(sizeof(KeySym))malloc(((sizeof(KeySym)) == 0 ? 1 : (sizeof(KeySym)))))) { | |||
| 629 | _XimError(im, ic, XIM_BadAlloc1, (INT16)0, (CARD16)0, (char *)NULL((void*)0)); | |||
| 630 | return False0; | |||
| 631 | } | |||
| 632 | ||||
| 633 | **xim_keysym = (KeySym)sym; | |||
| 634 | *xim_keysym_len = 1; | |||
| 635 | ||||
| 636 | return True1; | |||
| 637 | } | |||
| 638 | ||||
| 639 | static Boolint | |||
| 640 | _XimProcCommit( | |||
| 641 | Xic ic, | |||
| 642 | BYTE *buf, | |||
| 643 | int len, | |||
| 644 | char **xim_string, | |||
| 645 | int *xim_string_len) | |||
| 646 | { | |||
| 647 | Xim im = (Xim)ic->core.im; | |||
| 648 | char *string; | |||
| 649 | ||||
| 650 | if (!(string = Xmalloc(len + 1)malloc(((len + 1) == 0 ? 1 : (len + 1))))) { | |||
| 651 | _XimError(im, ic, XIM_BadAlloc1, (INT16)0, (CARD16)0, (char *)NULL((void*)0)); | |||
| 652 | return False0; | |||
| 653 | } | |||
| 654 | ||||
| 655 | (void)memcpy(string, (char *)buf, len)__builtin___memcpy_chk (string, (char *)buf, len, __builtin_object_size (string, 0)); | |||
| 656 | string[len] = '\0'; | |||
| 657 | ||||
| 658 | *xim_string = string; | |||
| 659 | *xim_string_len = len; | |||
| 660 | return True1; | |||
| 661 | } | |||
| 662 | ||||
| 663 | static Boolint | |||
| 664 | _XimCommitRecv( | |||
| 665 | Xim im, | |||
| 666 | Xic ic, | |||
| 667 | XPointer buf) | |||
| 668 | { | |||
| 669 | CARD16 *buf_s = (CARD16 *)buf; | |||
| 670 | BITMASK16 flag = buf_s[0]; | |||
| 671 | XKeyEvent ev; | |||
| 672 | char *string = NULL((void*)0); | |||
| 673 | int string_len = 0; | |||
| 674 | KeySym *keysym = NULL((void*)0); | |||
| 675 | int keysym_len = 0; | |||
| 676 | ||||
| 677 | if ((flag & XimLookupBoth0x0006) == XimLookupChars0x0002) { | |||
| 678 | if (!(_XimProcCommit(ic, (BYTE *)&buf_s[2], | |||
| 679 | (int)buf_s[1], &string, &string_len))) | |||
| 680 | return False0; | |||
| 681 | ||||
| 682 | } else if ((flag & XimLookupBoth0x0006) == XimLookupKeySym0x0004) { | |||
| 683 | if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len))) | |||
| 684 | return False0; | |||
| 685 | ||||
| 686 | } else if ((flag & XimLookupBoth0x0006) == XimLookupBoth0x0006) { | |||
| 687 | if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len))) | |||
| 688 | return False0; | |||
| 689 | ||||
| 690 | if (!(_XimProcCommit(ic, (BYTE *)&buf_s[5], | |||
| 691 | (int)buf_s[4], &string, &string_len))) { | |||
| 692 | Xfree(keysym)free((keysym)); | |||
| 693 | return False0; | |||
| 694 | } | |||
| 695 | } | |||
| 696 | ||||
| 697 | if (!(_XimRegCommitInfo(ic, string, string_len, keysym, keysym_len))) { | |||
| 698 | Xfree(string)free((string)); | |||
| 699 | Xfree(keysym)free((keysym)); | |||
| 700 | _XimError(im, ic, XIM_BadAlloc1, (INT16)0, (CARD16)0, (char *)NULL((void*)0)); | |||
| 701 | return False0; | |||
| 702 | } | |||
| 703 | ||||
| 704 | (void)_XimRespSyncReply(ic, flag); | |||
| 705 | ||||
| 706 | if (ic->private.proto.registed_filter_event | |||
| 707 | & (KEYPRESS_MASK(1L) | KEYRELEASE_MASK(1L << 1))) | |||
| 708 | MARK_FABRICATED(im)(((Xim)im)->private.proto.flag |= (1L << 5)); | |||
| 709 | ||||
| 710 | bzero(&ev, sizeof(ev))__builtin___memset_chk (&ev, 0, sizeof(ev), __builtin_object_size (&ev, 0)); /* uninitialized : found when running kterm under valgrind */ | |||
| 711 | ||||
| 712 | ev.type = KeyPress2; | |||
| 713 | ev.send_event = False0; | |||
| 714 | ev.display = im->core.display; | |||
| 715 | ev.window = ic->core.focus_window; | |||
| 716 | ev.keycode = 0; | |||
| 717 | ev.state = 0; | |||
| 718 | ||||
| 719 | ev.time = 0L; | |||
| 720 | ev.serial = LastKnownRequestProcessed(im->core.display)(((_XPrivDisplay)(im->core.display))->last_request_read ); | |||
| 721 | /* FIXME : | |||
| 722 | I wish there were COMMENTs (!) about the data passed around. | |||
| 723 | */ | |||
| 724 | #if 0 | |||
| 725 | fprintf(stderr__stderrp,"%s,%d: putback k press FIXED ev.time=0 ev.serial=%lu\n", __FILE__"imDefLkup.c", __LINE__725, ev.serial); | |||
| 726 | #endif | |||
| 727 | ||||
| 728 | XPutBackEvent(im->core.display, (XEvent *)&ev); | |||
| 729 | ||||
| 730 | return True1; | |||
| 731 | } | |||
| 732 | ||||
| 733 | Boolint | |||
| 734 | _XimCommitCallback( | |||
| 735 | Xim xim, | |||
| 736 | INT16 len, | |||
| 737 | XPointer data, | |||
| 738 | XPointer call_data) | |||
| 739 | { | |||
| 740 | CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 741 | XIMID imid = buf_s[0]; | |||
| 742 | XICID icid = buf_s[1]; | |||
| 743 | Xim im = (Xim)call_data; | |||
| 744 | Xic ic; | |||
| 745 | ||||
| 746 | if ((imid == im->private.proto.imid) | |||
| 747 | && (ic = _XimICOfXICID(im, icid))) { | |||
| 748 | (void)_XimCommitRecv(im, ic, (XPointer)&buf_s[2]); | |||
| 749 | return True1; | |||
| 750 | } | |||
| 751 | return False0; | |||
| 752 | } | |||
| 753 | ||||
| 754 | void | |||
| 755 | _XimProcError( | |||
| 756 | Xim im, | |||
| 757 | Xic ic, | |||
| 758 | XPointer data) | |||
| 759 | { | |||
| 760 | return; | |||
| 761 | } | |||
| 762 | ||||
| 763 | Boolint | |||
| 764 | _XimErrorCallback( | |||
| 765 | Xim xim, | |||
| 766 | INT16 len, | |||
| 767 | XPointer data, | |||
| 768 | XPointer call_data) | |||
| 769 | { | |||
| 770 | CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)); | |||
| 771 | BITMASK16 flag = buf_s[2]; | |||
| 772 | XIMID imid; | |||
| 773 | XICID icid; | |||
| 774 | Xim im = (Xim)call_data; | |||
| 775 | Xic ic = NULL((void*)0); | |||
| 776 | ||||
| 777 | if (flag & XIM_IMID_VALID0x0001) { | |||
| 778 | imid = buf_s[0]; | |||
| 779 | if (imid != im->private.proto.imid) | |||
| 780 | return False0; | |||
| 781 | } | |||
| 782 | if (flag & XIM_ICID_VALID0x0002) { | |||
| 783 | icid = buf_s[1]; | |||
| 784 | if (!(ic = _XimICOfXICID(im, icid))) | |||
| 785 | return False0; | |||
| 786 | } | |||
| 787 | _XimProcError(im, ic, (XPointer)&buf_s[3]); | |||
| 788 | ||||
| 789 | return True1; | |||
| 790 | } | |||
| 791 | ||||
| 792 | Boolint | |||
| 793 | _XimError( | |||
| 794 | Xim im, | |||
| 795 | Xic ic, | |||
| 796 | CARD16 error_code, | |||
| 797 | INT16 detail_length, | |||
| 798 | CARD16 type, | |||
| 799 | char *detail) | |||
| 800 | { | |||
| 801 | CARD32 buf32[BUFSIZE2048/4]; | |||
| 802 | CARD8 *buf = (CARD8 *)buf32; | |||
| 803 | CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZEsizeof(CARD8) + sizeof(CARD8) + sizeof(INT16)]; | |||
| 804 | INT16 len = 0; | |||
| 805 | ||||
| 806 | buf_s[0] = im->private.proto.imid; /* imid */ | |||
| 807 | buf_s[2] = XIM_IMID_VALID0x0001; /* flag */ | |||
| 808 | if (ic) { | |||
| 809 | buf_s[1] = ic->private.proto.icid; /* icid */ | |||
| 810 | buf_s[2] |= XIM_ICID_VALID0x0002; /* flag */ | |||
| 811 | } | |||
| 812 | buf_s[3] = error_code; /* Error Code */ | |||
| 813 | buf_s[4] = detail_length; /* length of error detail */ | |||
| 814 | buf_s[5] = type; /* type of error detail */ | |||
| 815 | ||||
| 816 | if (detail_length && detail) { | |||
| 817 | len = detail_length; | |||
| 818 | memcpy((char *)&buf_s[6], detail, len)__builtin___memcpy_chk ((char *)&buf_s[6], detail, len, __builtin_object_size ((char *)&buf_s[6], 0)); | |||
| 819 | XIM_SET_PAD(&buf_s[6], len){ register int Counter = ((4 - (((int)len) % 4)) % 4); if (Counter ) { register char *Ptr = (char *)(&buf_s[6]) + (len); len += Counter; for (; Counter; --Counter, ++Ptr) *Ptr = '\0'; } }; | |||
| 820 | } | |||
| 821 | ||||
| 822 | len += sizeof(CARD16) /* sizeof imid */ | |||
| 823 | + sizeof(CARD16) /* sizeof icid */ | |||
| 824 | + sizeof(BITMASK16) /* sizeof flag */ | |||
| 825 | + sizeof(CARD16) /* sizeof error_code */ | |||
| 826 | + sizeof(INT16) /* sizeof length of detail */ | |||
| 827 | + sizeof(CARD16); /* sizeof type */ | |||
| 828 | ||||
| 829 | _XimSetHeader((XPointer)buf, XIM_ERROR20, 0, &len); | |||
| 830 | if (!(_XimWrite(im, len, (XPointer)buf))) | |||
| 831 | return False0; | |||
| 832 | _XimFlush(im); | |||
| 833 | return True1; | |||
| 834 | } | |||
| 835 | ||||
| 836 | static int | |||
| 837 | _Ximctsconvert( | |||
| 838 | XlcConv conv, | |||
| 839 | char *from, | |||
| 840 | int from_len, | |||
| 841 | char *to, | |||
| 842 | int to_len, | |||
| 843 | Statusint *state) | |||
| 844 | { | |||
| 845 | int from_left; | |||
| 846 | int to_left; | |||
| 847 | int from_savelen; | |||
| 848 | int to_savelen; | |||
| 849 | int from_cnvlen; | |||
| 850 | int to_cnvlen; | |||
| 851 | char *from_buf; | |||
| 852 | char *to_buf; | |||
| 853 | char scratchbuf[BUFSIZ1024]; | |||
| 854 | Statusint tmp_state; | |||
| 855 | ||||
| 856 | if (!state) | |||
| 857 | state = &tmp_state; | |||
| 858 | ||||
| 859 | if (!conv || !from || !from_len) { | |||
| 860 | *state = XLookupNone1; | |||
| 861 | return 0; | |||
| 862 | } | |||
| 863 | ||||
| 864 | /* Reset the converter. The CompoundText at 'from' starts in | |||
| 865 | initial state. */ | |||
| 866 | _XlcResetConverter(conv); | |||
| 867 | ||||
| 868 | from_left = from_len; | |||
| 869 | to_left = BUFSIZ1024; | |||
| 870 | from_cnvlen = 0; | |||
| 871 | to_cnvlen = 0; | |||
| 872 | for (;;) { | |||
| 873 | from_buf = &from[from_cnvlen]; | |||
| 874 | from_savelen = from_left; | |||
| 875 | to_buf = &scratchbuf[to_cnvlen]; | |||
| 876 | to_savelen = to_left; | |||
| 877 | if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left, | |||
| 878 | (XPointer *)&to_buf, &to_left, NULL((void*)0), 0) < 0) { | |||
| 879 | *state = XLookupNone1; | |||
| 880 | return 0; | |||
| 881 | } | |||
| 882 | from_cnvlen += (from_savelen - from_left); | |||
| 883 | to_cnvlen += (to_savelen - to_left); | |||
| 884 | if (from_left == 0) { | |||
| 885 | if (!to_cnvlen) { | |||
| 886 | *state = XLookupNone1; | |||
| 887 | return 0; | |||
| 888 | } | |||
| 889 | break; | |||
| 890 | } | |||
| 891 | } | |||
| 892 | ||||
| 893 | if (!to || !to_len || (to_len < to_cnvlen)) { | |||
| 894 | *state = XBufferOverflow-1; | |||
| 895 | } else { | |||
| 896 | memcpy(to, scratchbuf, to_cnvlen)__builtin___memcpy_chk (to, scratchbuf, to_cnvlen, __builtin_object_size (to, 0)); | |||
| 897 | *state = XLookupChars2; | |||
| 898 | } | |||
| 899 | return to_cnvlen; | |||
| 900 | } | |||
| 901 | ||||
| 902 | int | |||
| 903 | _Ximctstombs(XIM xim, char *from, int from_len, | |||
| 904 | char *to, int to_len, Statusint *state) | |||
| 905 | { | |||
| 906 | return _Ximctsconvert(((Xim)xim)->private.proto.ctom_conv, | |||
| 907 | from, from_len, to, to_len, state); | |||
| 908 | } | |||
| 909 | ||||
| 910 | int | |||
| 911 | _Ximctstowcs( | |||
| 912 | XIM xim, | |||
| 913 | char *from, | |||
| 914 | int from_len, | |||
| 915 | wchar_t *to, | |||
| 916 | int to_len, | |||
| 917 | Statusint *state) | |||
| 918 | { | |||
| 919 | Xim im = (Xim)xim; | |||
| 920 | XlcConv conv = im->private.proto.ctow_conv; | |||
| 921 | int from_left; | |||
| 922 | int to_left; | |||
| 923 | int from_savelen; | |||
| 924 | int to_savelen; | |||
| 925 | int from_cnvlen; | |||
| 926 | int to_cnvlen; | |||
| 927 | char *from_buf; | |||
| 928 | wchar_t *to_buf; | |||
| 929 | wchar_t scratchbuf[BUFSIZ1024]; | |||
| 930 | Statusint tmp_state; | |||
| 931 | ||||
| 932 | if (!state) | |||
| 933 | state = &tmp_state; | |||
| 934 | ||||
| 935 | if (!conv || !from || !from_len) { | |||
| 936 | *state = XLookupNone1; | |||
| 937 | return 0; | |||
| 938 | } | |||
| 939 | ||||
| 940 | /* Reset the converter. The CompoundText at 'from' starts in | |||
| 941 | initial state. */ | |||
| 942 | _XlcResetConverter(conv); | |||
| 943 | ||||
| 944 | from_left = from_len; | |||
| 945 | to_left = BUFSIZ1024; | |||
| 946 | from_cnvlen = 0; | |||
| 947 | to_cnvlen = 0; | |||
| 948 | for (;;) { | |||
| 949 | from_buf = &from[from_cnvlen]; | |||
| 950 | from_savelen = from_left; | |||
| 951 | to_buf = &scratchbuf[to_cnvlen]; | |||
| 952 | to_savelen = to_left; | |||
| 953 | if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left, | |||
| 954 | (XPointer *)&to_buf, &to_left, NULL((void*)0), 0) < 0) { | |||
| 955 | *state = XLookupNone1; | |||
| 956 | return 0; | |||
| 957 | } | |||
| 958 | from_cnvlen += (from_savelen - from_left); | |||
| 959 | to_cnvlen += (to_savelen - to_left); | |||
| 960 | if (from_left == 0) { | |||
| 961 | if (!to_cnvlen){ | |||
| 962 | *state = XLookupNone1; | |||
| 963 | return 0; | |||
| 964 | } | |||
| 965 | break; | |||
| 966 | } | |||
| 967 | } | |||
| 968 | ||||
| 969 | if (!to || !to_len || (to_len < to_cnvlen)) { | |||
| 970 | *state = XBufferOverflow-1; | |||
| 971 | } else { | |||
| 972 | memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t))__builtin___memcpy_chk (to, scratchbuf, to_cnvlen * sizeof(wchar_t ), __builtin_object_size (to, 0)); | |||
| 973 | *state = XLookupChars2; | |||
| 974 | } | |||
| 975 | return to_cnvlen; | |||
| 976 | } | |||
| 977 | ||||
| 978 | int | |||
| 979 | _Ximctstoutf8( | |||
| 980 | XIM xim, | |||
| 981 | char *from, | |||
| 982 | int from_len, | |||
| 983 | char *to, | |||
| 984 | int to_len, | |||
| 985 | Statusint *state) | |||
| 986 | { | |||
| 987 | return _Ximctsconvert(((Xim)xim)->private.proto.ctoutf8_conv, | |||
| 988 | from, from_len, to, to_len, state); | |||
| 989 | } | |||
| 990 | ||||
| 991 | int | |||
| 992 | _XimProtoMbLookupString( | |||
| 993 | XIC xic, | |||
| 994 | XKeyEvent *ev, | |||
| 995 | char *buffer, | |||
| 996 | int bytes, | |||
| 997 | KeySym *keysym, | |||
| 998 | Statusint *state) | |||
| 999 | { | |||
| 1000 | Xic ic = (Xic)xic; | |||
| 1001 | Xim im = (Xim)ic->core.im; | |||
| 1002 | int ret; | |||
| 1003 | Statusint tmp_state; | |||
| 1004 | XimCommitInfo info; | |||
| 1005 | ||||
| 1006 | if (!IS_SERVER_CONNECTED(im)((((Xim)im))->private.proto.flag & (1L))) | |||
| 1007 | return 0; | |||
| 1008 | ||||
| 1009 | if (!state) | |||
| 1010 | state = &tmp_state; | |||
| 1011 | ||||
| 1012 | if ((ev->type == KeyPress2) && (ev->keycode == 0)) { /* Filter function */ | |||
| 1013 | if (!(info = ic->private.proto.commit_info)) { | |||
| 1014 | *state = XLookupNone1; | |||
| 1015 | return 0; | |||
| 1016 | } | |||
| 1017 | ||||
| 1018 | ret = im->methods->ctstombs((XIM)im, info->string, | |||
| 1019 | info->string_len, buffer, bytes, state); | |||
| 1020 | if (*state == XBufferOverflow-1) | |||
| 1021 | return ret; | |||
| 1022 | if (keysym && (info->keysym && *(info->keysym))) { | |||
| 1023 | *keysym = *(info->keysym); | |||
| 1024 | if (*state == XLookupChars2) | |||
| 1025 | *state = XLookupBoth4; | |||
| 1026 | else | |||
| 1027 | *state = XLookupKeySym3; | |||
| 1028 | } | |||
| 1029 | _XimUnregCommitInfo(ic); | |||
| 1030 | ||||
| 1031 | } else if (ev->type == KeyPress2) { | |||
| 1032 | ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL((void*)0)); | |||
| 1033 | if (ret > 0) { | |||
| 1034 | if (ret > bytes) | |||
| 1035 | *state = XBufferOverflow-1; | |||
| 1036 | else if (keysym && *keysym != NoSymbol0L) | |||
| 1037 | *state = XLookupBoth4; | |||
| 1038 | else | |||
| 1039 | *state = XLookupChars2; | |||
| 1040 | } else { | |||
| 1041 | if (keysym && *keysym != NoSymbol0L) | |||
| 1042 | *state = XLookupKeySym3; | |||
| 1043 | else | |||
| 1044 | *state = XLookupNone1; | |||
| 1045 | } | |||
| 1046 | } else { | |||
| 1047 | *state = XLookupNone1; | |||
| 1048 | ret = 0; | |||
| 1049 | } | |||
| 1050 | ||||
| 1051 | return ret; | |||
| 1052 | } | |||
| 1053 | ||||
| 1054 | int | |||
| 1055 | _XimProtoWcLookupString( | |||
| 1056 | XIC xic, | |||
| 1057 | XKeyEvent *ev, | |||
| 1058 | wchar_t *buffer, | |||
| 1059 | int bytes, | |||
| 1060 | KeySym *keysym, | |||
| 1061 | Statusint *state) | |||
| 1062 | { | |||
| 1063 | Xic ic = (Xic)xic; | |||
| 1064 | Xim im = (Xim)ic->core.im; | |||
| 1065 | int ret; | |||
| 1066 | Statusint tmp_state; | |||
| 1067 | XimCommitInfo info; | |||
| 1068 | ||||
| 1069 | if (!IS_SERVER_CONNECTED(im)((((Xim)im))->private.proto.flag & (1L))) | |||
| 1070 | return 0; | |||
| 1071 | ||||
| 1072 | if (!state) | |||
| 1073 | state = &tmp_state; | |||
| 1074 | ||||
| 1075 | if (ev->type == KeyPress2 && ev->keycode == 0) { /* Filter function */ | |||
| 1076 | if (!(info = ic->private.proto.commit_info)) { | |||
| 1077 | *state = XLookupNone1; | |||
| 1078 | return 0; | |||
| 1079 | } | |||
| 1080 | ||||
| 1081 | ret = im->methods->ctstowcs((XIM)im, info->string, | |||
| 1082 | info->string_len, buffer, bytes, state); | |||
| 1083 | if (*state == XBufferOverflow-1) | |||
| 1084 | return ret; | |||
| 1085 | if (keysym && (info->keysym && *(info->keysym))) { | |||
| 1086 | *keysym = *(info->keysym); | |||
| 1087 | if (*state == XLookupChars2) | |||
| 1088 | *state = XLookupBoth4; | |||
| 1089 | else | |||
| 1090 | *state = XLookupKeySym3; | |||
| 1091 | } | |||
| 1092 | _XimUnregCommitInfo(ic); | |||
| 1093 | ||||
| 1094 | } else if (ev->type == KeyPress2) { | |||
| 1095 | ret = _XimLookupWCText(ic, ev, buffer, bytes, keysym, NULL((void*)0)); | |||
| 1096 | if (ret > 0) { | |||
| 1097 | if (ret > bytes) | |||
| 1098 | *state = XBufferOverflow-1; | |||
| 1099 | else if (keysym && *keysym != NoSymbol0L) | |||
| 1100 | *state = XLookupBoth4; | |||
| 1101 | else | |||
| 1102 | *state = XLookupChars2; | |||
| 1103 | } else { | |||
| 1104 | if (keysym && *keysym != NoSymbol0L) | |||
| 1105 | *state = XLookupKeySym3; | |||
| 1106 | else | |||
| 1107 | *state = XLookupNone1; | |||
| 1108 | } | |||
| 1109 | } else { | |||
| 1110 | *state = XLookupNone1; | |||
| 1111 | ret = 0; | |||
| 1112 | } | |||
| 1113 | ||||
| 1114 | return ret; | |||
| 1115 | } | |||
| 1116 | ||||
| 1117 | int | |||
| 1118 | _XimProtoUtf8LookupString( | |||
| 1119 | XIC xic, | |||
| 1120 | XKeyEvent *ev, | |||
| 1121 | char *buffer, | |||
| 1122 | int bytes, | |||
| 1123 | KeySym *keysym, | |||
| 1124 | Statusint *state) | |||
| 1125 | { | |||
| 1126 | Xic ic = (Xic)xic; | |||
| 1127 | Xim im = (Xim)ic->core.im; | |||
| 1128 | int ret; | |||
| 1129 | Statusint tmp_state; | |||
| 1130 | XimCommitInfo info; | |||
| 1131 | ||||
| 1132 | if (!IS_SERVER_CONNECTED(im)((((Xim)im))->private.proto.flag & (1L))) | |||
| 1133 | return 0; | |||
| 1134 | ||||
| 1135 | if (!state) | |||
| 1136 | state = &tmp_state; | |||
| 1137 | ||||
| 1138 | if (ev->type == KeyPress2 && ev->keycode == 0) { /* Filter function */ | |||
| 1139 | if (!(info = ic->private.proto.commit_info)) { | |||
| 1140 | *state = XLookupNone1; | |||
| 1141 | return 0; | |||
| 1142 | } | |||
| 1143 | ||||
| 1144 | ret = im->methods->ctstoutf8((XIM)im, info->string, | |||
| 1145 | info->string_len, buffer, bytes, state); | |||
| 1146 | if (*state == XBufferOverflow-1) | |||
| 1147 | return ret; | |||
| 1148 | if (keysym && (info->keysym && *(info->keysym))) { | |||
| 1149 | *keysym = *(info->keysym); | |||
| 1150 | if (*state == XLookupChars2) | |||
| 1151 | *state = XLookupBoth4; | |||
| 1152 | else | |||
| 1153 | *state = XLookupKeySym3; | |||
| 1154 | } | |||
| 1155 | _XimUnregCommitInfo(ic); | |||
| 1156 | ||||
| 1157 | } else if (ev->type == KeyPress2) { | |||
| 1158 | ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL((void*)0)); | |||
| 1159 | if (ret > 0) { | |||
| 1160 | if (ret > bytes) | |||
| 1161 | *state = XBufferOverflow-1; | |||
| 1162 | else if (keysym && *keysym != NoSymbol0L) | |||
| 1163 | *state = XLookupBoth4; | |||
| 1164 | else | |||
| 1165 | *state = XLookupChars2; | |||
| 1166 | } else { | |||
| 1167 | if (keysym && *keysym != NoSymbol0L) | |||
| 1168 | *state = XLookupKeySym3; | |||
| 1169 | else | |||
| 1170 | *state = XLookupNone1; | |||
| 1171 | } | |||
| 1172 | } else { | |||
| 1173 | *state = XLookupNone1; | |||
| 1174 | ret = 0; | |||
| 1175 | } | |||
| 1176 | ||||
| 1177 | return ret; | |||
| 1178 | } |