1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | #ifdef HAVE_CONFIG_H1 |
64 | #include <config.h> |
65 | #endif |
66 | #include <stdio.h> |
67 | #include "Xlibint.h" |
68 | #include "Xlcint.h" |
69 | #include "XlcGeneric.h" |
70 | |
71 | #ifndef MAXINT(~((unsigned int)1 << (8 * sizeof(int)) - 1)) |
72 | #define MAXINT(~((unsigned int)1 << (8 * sizeof(int)) - 1)) (~((unsigned int)1 << (8 * sizeof(int)) - 1)) |
73 | #endif /* !MAXINT */ |
74 | |
75 | typedef struct _StaticXIM *StaticXIM; |
76 | |
77 | typedef struct _XIMStaticXIMRec { |
78 | |
79 | XlcConv ctom_conv; |
80 | XlcConv ctow_conv; |
81 | } XIMStaticXIMRec; |
82 | |
83 | typedef enum { |
84 | CREATE_IC = 1, |
85 | SET_ICVAL = 2, |
86 | GET_ICVAL = 3 |
87 | } XICOp_t; |
88 | |
89 | typedef struct _StaticXIM { |
90 | XIMMethods methods; |
91 | XIMCoreRec core; |
92 | XIMStaticXIMRec *private; |
93 | } StaticXIMRec; |
94 | |
95 | static Statusint _CloseIM( |
96 | XIM |
97 | ); |
98 | |
99 | static char *_SetIMValues( |
100 | XIM, XIMArg * |
101 | ); |
102 | |
103 | static char *_GetIMValues( |
104 | XIM, XIMArg* |
105 | ); |
106 | |
107 | static XIC _CreateIC( |
108 | XIM, XIMArg* |
109 | ); |
110 | |
111 | static _Xconstconst XIMMethodsRec local_im_methods = { |
112 | _CloseIM, |
113 | _SetIMValues, |
114 | _GetIMValues, |
115 | _CreateIC, |
116 | NULL((void*)0), |
117 | NULL((void*)0) |
118 | }; |
119 | |
120 | static void _DestroyIC( |
121 | XIC |
122 | ); |
123 | static void _SetFocus( |
124 | XIC |
125 | ); |
126 | static void _UnsetFocus( |
127 | XIC |
128 | ); |
129 | static char* _SetICValues( |
130 | XIC, XIMArg * |
131 | ); |
132 | static char* _GetICValues( |
133 | XIC, XIMArg * |
134 | ); |
135 | static char *_MbReset( |
136 | XIC |
137 | ); |
138 | static wchar_t *_WcReset( |
139 | XIC |
140 | ); |
141 | static int _MbLookupString( |
142 | XIC, XKeyEvent *, char *, int, KeySym *, Statusint * |
143 | ); |
144 | static int _WcLookupString( |
145 | XIC, XKeyEvent *, wchar_t *, int, KeySym *, Statusint * |
146 | ); |
147 | |
148 | static _Xconstconst XICMethodsRec local_ic_methods = { |
149 | _DestroyIC, |
150 | _SetFocus, |
151 | _UnsetFocus, |
152 | _SetICValues, |
153 | _GetICValues, |
154 | _MbReset, |
155 | _WcReset, |
156 | NULL((void*)0), |
157 | _MbLookupString, |
158 | _WcLookupString, |
159 | NULL((void*)0) |
160 | }; |
161 | |
162 | XIM |
163 | _XDefaultOpenIM( |
164 | XLCd lcd, |
165 | Display *dpy, |
166 | XrmDatabase rdb, |
167 | char *res_name, |
168 | char *res_class) |
169 | { |
170 | StaticXIM im; |
171 | int i; |
172 | char *mod; |
173 | char buf[BUFSIZ1024]; |
174 | |
175 | if ((im = Xcalloc(1, sizeof(StaticXIMRec))calloc(((1) == 0 ? 1 : (1)), (sizeof(StaticXIMRec)))) == NULL((void*)0)) |
| |
176 | return NULL((void*)0); |
177 | |
178 | if ((im->private = Xcalloc(1, sizeof(XIMStaticXIMRec))calloc(((1) == 0 ? 1 : (1)), (sizeof(XIMStaticXIMRec)))) == NULL((void*)0)) |
| 2 | | Value assigned to field 'private' | |
|
| 3 | | Assuming pointer value is null | |
|
| |
179 | goto Error; |
| 5 | | Control jumps to line 226 | |
|
180 | |
181 | if ((im->private->ctom_conv = _XlcOpenConverter(lcd, XlcNCompoundText"compoundText", |
182 | lcd, XlcNMultiByte"multiByte")) |
183 | == NULL((void*)0)) |
184 | goto Error; |
185 | |
186 | if ((im->private->ctow_conv = _XlcOpenConverter(lcd, XlcNCompoundText"compoundText", |
187 | lcd, XlcNWideChar"wideChar")) |
188 | == NULL((void*)0)) |
189 | goto Error; |
190 | |
191 | buf[0] = '\0'; |
192 | i = 0; |
193 | if ((lcd->core->modifiers) && (*lcd->core->modifiers)) { |
194 | #define MODIFIER "@im=" |
195 | mod = strstr(lcd->core->modifiers, MODIFIER); |
196 | if (mod) { |
197 | mod += strlen(MODIFIER); |
198 | while (*mod && *mod != '@' && i < BUFSIZ1024 - 1) { |
199 | buf[i++] = *mod++; |
200 | } |
201 | buf[i] = '\0'; |
202 | } |
203 | } |
204 | #undef MODIFIER |
205 | if ((im->core.im_name = strdup(buf)) == NULL((void*)0)) |
206 | goto Error; |
207 | |
208 | im->methods = (XIMMethods)&local_im_methods; |
209 | im->core.lcd = lcd; |
210 | im->core.ic_chain = (XIC)NULL((void*)0); |
211 | im->core.display = dpy; |
212 | im->core.rdb = rdb; |
213 | im->core.res_name = NULL((void*)0); |
214 | im->core.res_class = NULL((void*)0); |
215 | |
216 | if ((res_name != NULL((void*)0)) && (*res_name != '\0')){ |
217 | im->core.res_name = strdup(res_name); |
218 | } |
219 | if ((res_class != NULL((void*)0)) && (*res_class != '\0')){ |
220 | im->core.res_class = strdup(res_class); |
221 | } |
222 | |
223 | return (XIM)im; |
224 | |
225 | Error: |
226 | _CloseIM((XIM)im); |
| |
227 | Xfree(im)free((im)); |
228 | return(NULL((void*)0)); |
229 | } |
230 | |
231 | static Statusint |
232 | _CloseIM(XIM xim) |
233 | { |
234 | StaticXIM im = (StaticXIM)xim; |
235 | |
236 | if (im->private->ctom_conv != NULL((void*)0)) |
| 7 | | Access to field 'ctom_conv' results in a dereference of a null pointer (loaded from field 'private') |
|
237 | _XlcCloseConverter(im->private->ctom_conv); |
238 | if (im->private->ctow_conv != NULL((void*)0)) |
239 | _XlcCloseConverter(im->private->ctow_conv); |
240 | XFree(im->private); |
241 | XFree(im->core.im_name); |
242 | XFree(im->core.res_name); |
243 | XFree(im->core.res_class); |
244 | return 1; |
245 | } |
246 | |
247 | static char * |
248 | _SetIMValues( |
249 | XIM xim, |
250 | XIMArg *arg) |
251 | { |
252 | return(arg->name); |
253 | } |
254 | |
255 | static char * |
256 | _GetIMValues( |
257 | XIM xim, |
258 | XIMArg *values) |
259 | { |
260 | XIMArg *p; |
261 | XIMStyles *styles; |
262 | |
263 | for (p = values; p->name != NULL((void*)0); p++) { |
264 | if (strcmp(p->name, XNQueryInputStyle"queryInputStyle") == 0) { |
265 | styles = Xmalloc(sizeof(XIMStyles))malloc(((sizeof(XIMStyles)) == 0 ? 1 : (sizeof(XIMStyles)))); |
266 | *(XIMStyles **)p->value = styles; |
267 | styles->count_styles = 1; |
268 | styles->supported_styles = |
269 | Xmalloc(styles->count_styles * sizeof(XIMStyle))malloc(((styles->count_styles * sizeof(XIMStyle)) == 0 ? 1 : (styles->count_styles * sizeof(XIMStyle)))); |
270 | styles->supported_styles[0] = (XIMPreeditNone0x0010L | XIMStatusNone0x0800L); |
271 | } else { |
272 | break; |
273 | } |
274 | } |
275 | return (p->name); |
276 | } |
277 | |
278 | static char* |
279 | _SetICValueData(XIC ic, XIMArg *values, XICOp_t mode) |
280 | { |
281 | XIMArg *p; |
282 | char *return_name = NULL((void*)0); |
283 | |
284 | for (p = values; p != NULL((void*)0) && p->name != NULL((void*)0); p++) { |
285 | if(strcmp(p->name, XNInputStyle"inputStyle") == 0) { |
286 | if (mode == CREATE_IC) |
287 | ic->core.input_style = (XIMStyle)p->value; |
288 | } else if (strcmp(p->name, XNClientWindow"clientWindow") == 0) { |
289 | ic->core.client_window = (Window)p->value ; |
290 | } else if (strcmp(p->name, XNFocusWindow"focusWindow") == 0) { |
291 | ic->core.focus_window = (Window)p->value ; |
292 | } else if (strcmp(p->name, XNPreeditAttributes"preeditAttributes") == 0 |
293 | || strcmp(p->name, XNStatusAttributes"statusAttributes") == 0) { |
294 | return_name = _SetICValueData(ic, (XIMArg*)p->value, mode); |
295 | if (return_name) break; |
296 | } else { |
297 | return_name = p->name; |
298 | break; |
299 | } |
300 | } |
301 | return(return_name); |
302 | } |
303 | |
304 | static char* |
305 | _GetICValueData(XIC ic, XIMArg *values, XICOp_t mode) |
306 | { |
307 | XIMArg *p; |
308 | char *return_name = NULL((void*)0); |
309 | |
310 | for (p = values; p->name != NULL((void*)0); p++) { |
311 | if(strcmp(p->name, XNInputStyle"inputStyle") == 0) { |
312 | *((XIMStyle *)(p->value)) = ic->core.input_style; |
313 | } else if (strcmp(p->name, XNClientWindow"clientWindow") == 0) { |
314 | *((Window *)(p->value)) = ic->core.client_window; |
315 | } else if (strcmp(p->name, XNFocusWindow"focusWindow") == 0) { |
316 | *((Window *)(p->value)) = ic->core.focus_window; |
317 | } else if (strcmp(p->name, XNFilterEvents"filterEvents") == 0) { |
318 | *((unsigned long *)(p->value))= ic->core.filter_events; |
319 | } else if (strcmp(p->name, XNPreeditAttributes"preeditAttributes") == 0 |
320 | || strcmp(p->name, XNStatusAttributes"statusAttributes") == 0) { |
321 | return_name = _GetICValueData(ic, (XIMArg*)p->value, mode); |
322 | if (return_name) break; |
323 | } else { |
324 | return_name = p->name; |
325 | break; |
326 | } |
327 | } |
328 | return(return_name); |
329 | } |
330 | |
331 | static XIC |
332 | _CreateIC(XIM im, XIMArg *arg) |
333 | { |
334 | XIC ic; |
335 | |
336 | if ((ic = Xcalloc(1, sizeof(XICRec))calloc(((1) == 0 ? 1 : (1)), (sizeof(XICRec)))) == (XIC)NULL((void*)0)) { |
337 | return ((XIC)NULL((void*)0)); |
338 | } |
339 | |
340 | ic->methods = (XICMethods)&local_ic_methods; |
341 | ic->core.im = im; |
342 | ic->core.filter_events = KeyPressMask(1L<<0); |
343 | |
344 | if (_SetICValueData(ic, arg, CREATE_IC) != NULL((void*)0)) |
345 | goto err_return; |
346 | if (!(ic->core.input_style)) |
347 | goto err_return; |
348 | |
349 | return (XIC)ic; |
350 | err_return: |
351 | XFree(ic); |
352 | return ((XIC)NULL((void*)0)); |
353 | } |
354 | |
355 | static void |
356 | _DestroyIC(XIC ic) |
357 | { |
358 | |
359 | |
360 | |
361 | } |
362 | |
363 | static void |
364 | _SetFocus(XIC ic) |
365 | { |
366 | } |
367 | |
368 | static void |
369 | _UnsetFocus(XIC ic) |
370 | { |
371 | } |
372 | |
373 | static char* |
374 | _SetICValues(XIC ic, XIMArg *args) |
375 | { |
376 | char *ret = NULL((void*)0); |
377 | if (!ic) { |
378 | return (args->name); |
379 | } |
380 | ret = _SetICValueData(ic, args, SET_ICVAL); |
381 | return(ret); |
382 | } |
383 | |
384 | static char* |
385 | _GetICValues(XIC ic, XIMArg *args) |
386 | { |
387 | char *ret = NULL((void*)0); |
388 | if (!ic) { |
389 | return (args->name); |
390 | } |
391 | ret = _GetICValueData(ic, args, GET_ICVAL); |
392 | return(ret); |
393 | } |
394 | |
395 | static char * |
396 | _MbReset(XIC xic) |
397 | { |
398 | return(NULL((void*)0)); |
399 | } |
400 | |
401 | static wchar_t * |
402 | _WcReset(XIC xic) |
403 | { |
404 | return(NULL((void*)0)); |
405 | } |
406 | |
407 | static int |
408 | _MbLookupString( |
409 | XIC xic, |
410 | XKeyEvent *ev, |
411 | char * buffer, |
412 | int bytes, |
413 | KeySym *keysym, |
414 | Statusint *status) |
415 | { |
416 | XComposeStatus NotSupportedYet ; |
417 | int length; |
418 | |
419 | length = XLookupString(ev, buffer, bytes, keysym, &NotSupportedYet); |
420 | |
421 | if (keysym && *keysym == NoSymbol0L){ |
422 | *status = XLookupNone1; |
423 | } else if (length > 0) { |
424 | *status = XLookupBoth4; |
425 | } else { |
426 | *status = XLookupKeySym3; |
427 | } |
428 | return(length); |
429 | } |
430 | |
431 | static int |
432 | _WcLookupString( |
433 | XIC xic, |
434 | XKeyEvent *ev, |
435 | wchar_t * buffer, |
436 | int wlen, |
437 | KeySym *keysym, |
438 | Statusint *status) |
439 | { |
440 | XComposeStatus NotSupportedYet ; |
441 | int length; |
442 | |
443 | char *mb_buf = Xmalloc(wlen)malloc(((wlen) == 0 ? 1 : (wlen))); |
444 | |
445 | length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet); |
446 | |
447 | if (keysym && *keysym == NoSymbol0L){ |
448 | *status = XLookupNone1; |
449 | } else if (length > 0) { |
450 | *status = XLookupBoth4; |
451 | } else { |
452 | *status = XLookupKeySym3; |
453 | } |
454 | mbstowcs(buffer, mb_buf, length); |
455 | XFree(mb_buf); |
456 | return(length); |
457 | } |