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 | #ifdef HAVE_CONFIG_H1 |
28 | #include <config.h> |
29 | #endif |
30 | #include "IntrinsicI.h" |
31 | #include "VarargsI.h" |
32 | #include "StringDefs.h" |
33 | |
34 | static String XtNxtConvertVarToArgList = "xtConvertVarToArgList"; |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | static void |
42 | _XtCountNestedList( |
43 | XtTypedArgList avlist, |
44 | int *total_count, |
45 | int *typed_count) |
46 | { |
47 | for (; avlist->name != NULL((void*)0); avlist++) { |
48 | if (strcmp(avlist->name, XtVaNestedList"XtVaNestedList") == 0) { |
49 | _XtCountNestedList((XtTypedArgList)avlist->value, total_count, |
50 | typed_count); |
51 | } else { |
52 | if (avlist->type != NULL((void*)0)) { |
53 | ++(*typed_count); |
54 | } |
55 | ++(*total_count); |
56 | } |
57 | } |
58 | } |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | void |
68 | _XtCountVaList(va_list var, int* total_count, int* typed_count) |
69 | { |
70 | String attr; |
71 | |
72 | *total_count = 0; |
73 | *typed_count = 0; |
74 | |
75 | for(attr = va_arg(var, String)__builtin_va_arg(var, String) ; attr != NULL((void*)0); |
76 | attr = va_arg(var, String)__builtin_va_arg(var, String)) { |
77 | if (strcmp(attr, XtVaTypedArg"XtVaTypedArg") == 0) { |
78 | (void)va_arg(var, String)__builtin_va_arg(var, String); |
79 | (void)va_arg(var, String)__builtin_va_arg(var, String); |
80 | (void)va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
81 | (void)va_arg(var, int)__builtin_va_arg(var, int); |
82 | ++(*total_count); |
83 | ++(*typed_count); |
84 | } else if (strcmp(attr, XtVaNestedList"XtVaNestedList") == 0) { |
85 | _XtCountNestedList(va_arg(var, XtTypedArgList)__builtin_va_arg(var, XtTypedArgList), total_count, |
86 | typed_count); |
87 | } else { |
88 | (void)va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
89 | ++(*total_count); |
90 | } |
91 | } |
92 | } |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | XtVarArgsList |
101 | XtVaCreateArgsList(XtPointer unused, ...) |
102 | { |
103 | va_list var; |
104 | XtTypedArgList avlist; |
105 | int count = 0; |
106 | String attr; |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | va_start(var,unused)__builtin_va_start(var, unused); |
114 | for(attr = va_arg(var, String)__builtin_va_arg(var, String) ; attr != NULL((void*)0); |
115 | attr = va_arg(var, String)__builtin_va_arg(var, String)) { |
116 | ++count; |
117 | if (strcmp(attr, XtVaTypedArg"XtVaTypedArg") == 0) { |
118 | (void)va_arg(var, String)__builtin_va_arg(var, String); |
119 | (void)va_arg(var, String)__builtin_va_arg(var, String); |
120 | (void)va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
121 | (void)va_arg(var, int)__builtin_va_arg(var, int); |
122 | } else { |
123 | (void)va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
124 | } |
125 | } |
126 | va_end(var)__builtin_va_end(var); |
127 | |
128 | va_start(var,unused)__builtin_va_start(var, unused); |
129 | avlist = _XtVaCreateTypedArgList(var, count); |
130 | va_end(var)__builtin_va_end(var); |
131 | return (XtVarArgsList)avlist; |
132 | } |
133 | |
134 | |
135 | XtTypedArgList _XtVaCreateTypedArgList(va_list var, register int count) |
136 | { |
137 | String attr; |
138 | XtTypedArgList avlist; |
139 | |
140 | avlist = (XtTypedArgList) |
141 | __XtCalloc((int)count + 1, (unsigned)sizeof(XtTypedArg)); |
142 | |
143 | for(attr = va_arg(var, String)__builtin_va_arg(var, String), count = 0; attr != NULL((void*)0); |
144 | attr = va_arg(var, String)__builtin_va_arg(var, String)) { |
145 | if (strcmp(attr, XtVaTypedArg"XtVaTypedArg") == 0) { |
146 | avlist[count].name = va_arg(var, String)__builtin_va_arg(var, String); |
147 | avlist[count].type = va_arg(var, String)__builtin_va_arg(var, String); |
148 | avlist[count].value = va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
149 | avlist[count].size = va_arg(var, int)__builtin_va_arg(var, int); |
150 | } else { |
151 | avlist[count].name = attr; |
152 | avlist[count].type = NULL((void*)0); |
153 | avlist[count].value = va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
154 | } |
155 | ++count; |
156 | } |
157 | avlist[count].name = NULL((void*)0); |
158 | |
159 | return avlist; |
160 | } |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | static int |
172 | TypedArgToArg( |
173 | Widget widget, |
174 | XtTypedArgList typed_arg, |
175 | ArgList arg_return, |
176 | XtResourceList resources, |
177 | Cardinal num_resources, |
178 | ArgList memory_return) |
179 | { |
180 | String to_type = NULL((void*)0); |
181 | XrmValue from_val, to_val; |
182 | |
183 | |
184 | if (widget == NULL((void*)0)) { |
185 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), |
186 | "nullWidget", XtNxtConvertVarToArgList, XtCXtToolkitError, |
187 | "XtVaTypedArg conversion needs non-NULL widget handle", |
188 | (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); |
189 | return(0); |
190 | } |
191 | |
192 | |
193 | |
194 | for (; num_resources--; resources++) |
195 | if (strcmp(typed_arg->name, resources->resource_name) == 0) { |
196 | to_type = resources->resource_type; |
197 | break; |
198 | } |
199 | |
200 | if (to_type == NULL((void*)0)) { |
201 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), |
202 | "unknownType", XtNxtConvertVarToArgList, XtCXtToolkitError, |
203 | "Unable to find type of resource for conversion", |
204 | (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); |
205 | return(0); |
206 | } |
207 | |
208 | to_val.addr = NULL((void*)0); |
209 | from_val.size = typed_arg->size; |
210 | if ((strcmp(typed_arg->type, XtRString((char*)&XtStrings[1797])) == 0) || |
211 | ((unsigned) typed_arg->size > sizeof(XtArgVal))) { |
212 | from_val.addr = (XPointer)typed_arg->value; |
213 | } else { |
214 | from_val.addr = (XPointer)&typed_arg->value; |
215 | } |
216 | |
217 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
218 | XtConvertAndStore(widget, typed_arg->type, &from_val, to_type, &to_val); |
219 | |
220 | if (to_val.addr == NULL((void*)0)) { |
221 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
222 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), |
223 | "conversionFailed", XtNxtConvertVarToArgList, XtCXtToolkitError, |
224 | "Type conversion failed", (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); |
225 | return(0); |
226 | } |
227 | |
228 | arg_return->name = typed_arg->name; |
229 | memory_return->value = (XtArgVal) NULL((void*)0); |
230 | |
231 | if (strcmp(to_type, XtRString((char*)&XtStrings[1797])) == 0) { |
232 | arg_return->value = (XtArgVal) to_val.addr; |
233 | } |
234 | else { |
235 | if (to_val.size == sizeof(long)) |
236 | arg_return->value = (XtArgVal) *(long *)to_val.addr; |
237 | else if (to_val.size == sizeof(int)) |
238 | arg_return->value = (XtArgVal) *(int *)to_val.addr; |
239 | else if (to_val.size == sizeof(short)) |
240 | arg_return->value = (XtArgVal) *(short *)to_val.addr; |
241 | else if (to_val.size == sizeof(char)) |
242 | arg_return->value = (XtArgVal) *(char *)to_val.addr; |
243 | else if (to_val.size == sizeof(XtArgVal)) |
244 | arg_return->value = *(XtArgVal *)to_val.addr; |
245 | else if (to_val.size > sizeof(XtArgVal)) { |
246 | arg_return->value = (XtArgVal) __XtMalloc(to_val.size); |
247 | memory_return->value = (XtArgVal) |
248 | memcpy((void *)arg_return->value, to_val.addr, to_val.size); |
249 | } |
250 | } |
251 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
252 | |
253 | return(1); |
254 | } |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | static int |
262 | NestedArgtoArg( |
263 | Widget widget, |
264 | XtTypedArgList avlist, |
265 | ArgList args, |
266 | XtResourceList resources, |
267 | Cardinal num_resources, |
268 | ArgList memory_return) |
269 | { |
270 | int count = 0; |
271 | |
272 | for (; avlist->name != NULL((void*)0); avlist++) { |
273 | if (avlist->type != NULL((void*)0)) { |
274 | |
275 | if (widget != NULL((void*)0)) { |
276 | |
277 | count += TypedArgToArg(widget, avlist, (args+count), |
278 | resources, num_resources, |
279 | (memory_return+count)); |
280 | } |
281 | } else if (strcmp(avlist->name, XtVaNestedList"XtVaNestedList") == 0) { |
282 | count += NestedArgtoArg(widget, (XtTypedArgList)avlist->value, |
283 | (args+count), resources, num_resources, |
284 | (memory_return+count)); |
285 | } else { |
286 | (args+count)->name = avlist->name; |
287 | (args+count)->value = avlist->value; |
288 | ++count; |
289 | } |
290 | } |
291 | |
292 | return(count); |
293 | } |
294 | |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | |
307 | |
308 | |
309 | |
310 | |
311 | |
312 | void |
313 | _XtFreeArgList( |
314 | ArgList args, |
315 | int total_count, |
316 | int typed_count) |
317 | { |
318 | ArgList p; |
319 | |
320 | if (args) { |
321 | if (typed_count) |
322 | for (p = args + total_count; total_count--; ++p) { |
323 | XtFree((char *)p->value); |
324 | } |
325 | XtFree((char *)args); |
326 | } |
327 | } |
328 | |
329 | |
330 | static void GetResources(Widget widget, XtResourceList *res_list, |
331 | Cardinal *number); |
332 | |
333 | |
334 | |
335 | |
336 | |
337 | |
338 | |
339 | |
340 | void |
341 | _XtVaToArgList( |
342 | Widget widget, |
343 | va_list var, |
344 | int max_count, |
345 | ArgList *args_return, |
346 | Cardinal *num_args_return) |
347 | { |
348 | String attr; |
349 | int count; |
350 | ArgList args = (ArgList)NULL((void*)0); |
351 | XtTypedArg typed_arg; |
352 | XtResourceList resources = (XtResourceList)NULL((void*)0); |
353 | Cardinal num_resources; |
354 | Boolean fetched_resource_list = False0; |
355 | |
356 | if (max_count == 0) { |
| 1 | Assuming 'max_count' is not equal to 0 |
|
| |
357 | *num_args_return = 0; |
358 | *args_return = (ArgList)NULL((void*)0); |
359 | return; |
360 | } |
361 | |
362 | args = (ArgList)__XtMalloc((unsigned)(max_count * 2 * sizeof(Arg))); |
363 | for (count = max_count * 2; --count >= 0; ) |
| 3 | Loop condition is false. Execution continues on line 365 |
|
364 | args[count].value = (XtArgVal) NULL((void*)0); |
365 | count = 0; |
366 | |
367 | for(attr = va_arg(var, String)__builtin_va_arg(var, String) ; attr != NULL((void*)0); |
| 4 | Assuming 'attr' is not equal to null |
|
| 5 | Loop condition is true. Entering loop body |
|
368 | attr = va_arg(var, String)__builtin_va_arg(var, String)) { |
369 | if (strcmp(attr, XtVaTypedArg"XtVaTypedArg") == 0) { |
| |
370 | typed_arg.name = va_arg(var, String)__builtin_va_arg(var, String); |
371 | typed_arg.type = va_arg(var, String)__builtin_va_arg(var, String); |
372 | typed_arg.value = va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
373 | typed_arg.size = va_arg(var, int)__builtin_va_arg(var, int); |
374 | |
375 | |
376 | if (widget != NULL((void*)0)) { |
377 | if (!fetched_resource_list) { |
378 | GetResources(widget, &resources, &num_resources); |
379 | fetched_resource_list = True1; |
380 | } |
381 | count += TypedArgToArg(widget, &typed_arg, &args[count], |
382 | resources, num_resources, |
383 | &args[max_count + count]); |
384 | } |
385 | } else if (strcmp(attr, XtVaNestedList"XtVaNestedList") == 0) { |
| |
386 | if (widget != NULL((void*)0)) { |
| 8 | Assuming 'widget' is equal to null |
|
| |
387 | if (!fetched_resource_list) { |
388 | GetResources(widget, &resources, &num_resources); |
389 | fetched_resource_list = True1; |
390 | } |
391 | } |
392 | |
393 | count += NestedArgtoArg(widget, va_arg(var, XtTypedArgList)__builtin_va_arg(var, XtTypedArgList), |
| 10 | Function call argument is an uninitialized value |
|
394 | &args[count], resources, num_resources, |
395 | &args[max_count + count]); |
396 | } else { |
397 | args[count].name = attr; |
398 | args[count].value = va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
399 | count ++; |
400 | } |
401 | } |
402 | |
403 | XtFree((XtPointer)resources); |
404 | |
405 | *num_args_return = (Cardinal)count; |
406 | *args_return = (ArgList)args; |
407 | } |
408 | |
409 | |
410 | |
411 | |
412 | |
413 | |
414 | |
415 | |
416 | |
417 | |
418 | static void |
419 | GetResources( |
420 | Widget widget, |
421 | XtResourceList * res_list, |
422 | Cardinal * number) |
423 | { |
424 | Widget parent = XtParent(widget)((widget)->core.parent); |
425 | |
426 | XtInitializeWidgetClass(XtClass(widget)((widget)->core.widget_class)); |
427 | XtGetResourceList(XtClass(widget)((widget)->core.widget_class), res_list, number); |
428 | |
429 | if (!XtIsShell(widget)(((Object)(widget))->object.widget_class->core_class.class_inited & 0x20) && parent && XtIsConstraint(parent)(((Object)(parent))->object.widget_class->core_class.class_inited & 0x10)) { |
430 | XtResourceList res, constraint, cons_top; |
431 | Cardinal num_constraint, temp; |
432 | |
433 | XtGetConstraintResourceList(XtClass(parent)((parent)->core.widget_class), &constraint, |
434 | &num_constraint); |
435 | |
436 | cons_top = constraint; |
437 | *res_list = (XtResourceList) XtRealloc((char*)*res_list, |
438 | ((*number + num_constraint) * |
439 | sizeof(XtResource))); |
440 | |
441 | for (temp= num_constraint, res= *res_list + *number; temp != 0; temp--) |
442 | *res++ = *constraint++; |
443 | |
444 | *number += num_constraint; |
445 | XtFree( (XtPointer) cons_top); |
446 | } |
447 | } |
448 | |
449 | static int NestedArgtoTypedArg( |
450 | XtTypedArgList args, |
451 | XtTypedArgList avlist) |
452 | { |
453 | int count = 0; |
454 | |
455 | for (; avlist->name != NULL((void*)0); avlist++) { |
456 | if (avlist->type != NULL((void*)0)) { |
457 | (args+count)->name = avlist->name; |
458 | (args+count)->type = avlist->type; |
459 | (args+count)->size = avlist->size; |
460 | (args+count)->value = avlist->value; |
461 | ++count; |
462 | } else if(strcmp(avlist->name, XtVaNestedList"XtVaNestedList") == 0) { |
463 | count += NestedArgtoTypedArg((args+count), |
464 | (XtTypedArgList)avlist->value); |
465 | } else { |
466 | (args+count)->name = avlist->name; |
467 | (args+count)->type = NULL((void*)0); |
468 | (args+count)->value = avlist->value; |
469 | ++count; |
470 | } |
471 | } |
472 | return(count); |
473 | } |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | |
481 | |
482 | void |
483 | _XtVaToTypedArgList( |
484 | va_list var, |
485 | int max_count, |
486 | XtTypedArgList *args_return, |
487 | Cardinal *num_args_return) |
488 | { |
489 | XtTypedArgList args = NULL((void*)0); |
490 | String attr; |
491 | int count; |
492 | |
493 | args = (XtTypedArgList) |
494 | __XtMalloc((unsigned)(max_count * sizeof(XtTypedArg))); |
495 | |
496 | for(attr = va_arg(var, String)__builtin_va_arg(var, String), count = 0 ; attr != NULL((void*)0); |
497 | attr = va_arg(var, String)__builtin_va_arg(var, String)) { |
498 | if (strcmp(attr, XtVaTypedArg"XtVaTypedArg") == 0) { |
499 | args[count].name = va_arg(var, String)__builtin_va_arg(var, String); |
500 | args[count].type = va_arg(var, String)__builtin_va_arg(var, String); |
501 | args[count].value = va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
502 | args[count].size = va_arg(var, int)__builtin_va_arg(var, int); |
503 | ++count; |
504 | } else if (strcmp(attr, XtVaNestedList"XtVaNestedList") == 0) { |
505 | count += NestedArgtoTypedArg(&args[count], |
506 | va_arg(var, XtTypedArgList)__builtin_va_arg(var, XtTypedArgList)); |
507 | } else { |
508 | args[count].name = attr; |
509 | args[count].type = NULL((void*)0); |
510 | args[count].value = va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
511 | ++count; |
512 | } |
513 | } |
514 | |
515 | *args_return = args; |
516 | *num_args_return = count; |
517 | } |