File: | src/Resources.c |
Location: | line 1021, column 18 |
Description: | Array access (from variable 'names') results in a null pointer dereference |
1 | /*********************************************************** | |||
2 | Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved. | |||
3 | ||||
4 | Permission is hereby granted, free of charge, to any person obtaining a | |||
5 | copy of this software and associated documentation files (the "Software"), | |||
6 | to deal in the Software without restriction, including without limitation | |||
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
8 | and/or sell copies of the Software, and to permit persons to whom the | |||
9 | Software is furnished to do so, subject to the following conditions: | |||
10 | ||||
11 | The above copyright notice and this permission notice (including the next | |||
12 | paragraph) shall be included in all copies or substantial portions of the | |||
13 | Software. | |||
14 | ||||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
21 | DEALINGS IN THE SOFTWARE. | |||
22 | ||||
23 | Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. | |||
24 | ||||
25 | All Rights Reserved | |||
26 | ||||
27 | Permission to use, copy, modify, and distribute this software and its | |||
28 | documentation for any purpose and without fee is hereby granted, | |||
29 | provided that the above copyright notice appear in all copies and that | |||
30 | both that copyright notice and this permission notice appear in | |||
31 | supporting documentation, and that the name of Digital not be | |||
32 | used in advertising or publicity pertaining to distribution of the | |||
33 | software without specific, written prior permission. | |||
34 | ||||
35 | DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |||
36 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |||
37 | DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR | |||
38 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |||
39 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |||
40 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |||
41 | SOFTWARE. | |||
42 | ||||
43 | ******************************************************************/ | |||
44 | ||||
45 | /* | |||
46 | ||||
47 | Copyright 1987, 1988, 1994, 1998 The Open Group | |||
48 | ||||
49 | Permission to use, copy, modify, distribute, and sell this software and its | |||
50 | documentation for any purpose is hereby granted without fee, provided that | |||
51 | the above copyright notice appear in all copies and that both that | |||
52 | copyright notice and this permission notice appear in supporting | |||
53 | documentation. | |||
54 | ||||
55 | The above copyright notice and this permission notice shall be included in | |||
56 | all copies or substantial portions of the Software. | |||
57 | ||||
58 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
59 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
60 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
61 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |||
62 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
63 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
64 | ||||
65 | Except as contained in this notice, the name of The Open Group shall not be | |||
66 | used in advertising or otherwise to promote the sale, use or other dealings | |||
67 | in this Software without prior written authorization from The Open Group. | |||
68 | ||||
69 | */ | |||
70 | ||||
71 | /*LINTLIBRARY*/ | |||
72 | #ifdef HAVE_CONFIG_H1 | |||
73 | #include <config.h> | |||
74 | #endif | |||
75 | #include "IntrinsicI.h" | |||
76 | #include "VarargsI.h" | |||
77 | #include "Shell.h" | |||
78 | #include "ShellP.h" | |||
79 | #include "StringDefs.h" | |||
80 | #include <stdio.h> | |||
81 | ||||
82 | static XrmClass QBoolean, QString, QCallProc, QImmediate; | |||
83 | static XrmName QinitialResourcesPersistent, QInitialResourcesPersistent; | |||
84 | static XrmClass QTranslations, QTranslationTable; | |||
85 | static XrmName Qtranslations, QbaseTranslations; | |||
86 | static XrmName Qscreen; | |||
87 | static XrmClass QScreen; | |||
88 | ||||
89 | ||||
90 | void _XtCopyFromParent( | |||
91 | Widget widget, | |||
92 | int offset, | |||
93 | XrmValue *value) | |||
94 | { | |||
95 | if (widget->core.parent == NULL((void*)0)) { | |||
96 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), | |||
97 | "invalidParent","xtCopyFromParent",XtCXtToolkitError, | |||
98 | "CopyFromParent must have non-NULL parent", | |||
99 | (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); | |||
100 | value->addr = NULL((void*)0); | |||
101 | return; | |||
102 | } | |||
103 | value->addr = (XPointer)(((char *)widget->core.parent) + offset); | |||
104 | } /* _XtCopyFromParent */ | |||
105 | ||||
106 | ||||
107 | void _XtCopyFromArg( | |||
108 | XtArgVal src, | |||
109 | char* dst, | |||
110 | register unsigned int size) | |||
111 | { | |||
112 | if (size > sizeof(XtArgVal)) | |||
113 | (void) memmove((char *) dst, (char *) src, (int) size)__builtin___memmove_chk ((char *) dst, (char *) src, (int) size , __builtin_object_size ((char *) dst, 0)); | |||
114 | else { | |||
115 | union { | |||
116 | long longval; | |||
117 | #ifdef LONG64 | |||
118 | int intval; | |||
119 | #endif | |||
120 | short shortval; | |||
121 | char charval; | |||
122 | char* charptr; | |||
123 | XtPointer ptr; | |||
124 | } u; | |||
125 | char *p = (char*)&u; | |||
126 | if (size == sizeof(long)) u.longval = (long)src; | |||
127 | #ifdef LONG64 | |||
128 | else if (size == sizeof(int)) u.intval = (int)src; | |||
129 | #endif | |||
130 | else if (size == sizeof(short)) u.shortval = (short)src; | |||
131 | else if (size == sizeof(char)) u.charval = (char)src; | |||
132 | else if (size == sizeof(XtPointer)) u.ptr = (XtPointer)src; | |||
133 | else if (size == sizeof(char*)) u.charptr = (char*)src; | |||
134 | else p = (char*)&src; | |||
135 | ||||
136 | (void) memmove(dst, p, (int) size)__builtin___memmove_chk (dst, p, (int) size, __builtin_object_size (dst, 0)); | |||
137 | } | |||
138 | } /* _XtCopyFromArg */ | |||
139 | ||||
140 | void _XtCopyToArg( | |||
141 | char* src, | |||
142 | XtArgVal *dst, | |||
143 | register unsigned int size) | |||
144 | { | |||
145 | if (!*dst) { | |||
146 | #ifdef GETVALUES_BUG | |||
147 | /* old GetValues semantics (storing directly into arglists) are bad, | |||
148 | * but preserve for compatibility as long as arglist contains NULL. | |||
149 | */ | |||
150 | union { | |||
151 | long longval; | |||
152 | #ifdef LONG64 | |||
153 | int intval; | |||
154 | #endif | |||
155 | short shortval; | |||
156 | char charval; | |||
157 | char* charptr; | |||
158 | XtPointer ptr; | |||
159 | } u; | |||
160 | if (size <= sizeof(XtArgVal)) { | |||
161 | (void) memmove((char*)&u, (char*)src, (int)size )__builtin___memmove_chk ((char*)&u, (char*)src, (int)size , __builtin_object_size ((char*)&u, 0)); | |||
162 | if (size == sizeof(long)) *dst = (XtArgVal)u.longval; | |||
163 | #ifdef LONG64 | |||
164 | else if (size == sizeof(int)) *dst = (XtArgVal)u.intval; | |||
165 | #endif | |||
166 | else if (size == sizeof(short)) *dst = (XtArgVal)u.shortval; | |||
167 | else if (size == sizeof(char)) *dst = (XtArgVal)u.charval; | |||
168 | else if (size == sizeof(char*)) *dst = (XtArgVal)u.charptr; | |||
169 | else if (size == sizeof(XtPointer)) *dst = (XtArgVal)u.ptr; | |||
170 | else (void) memmove((char*)dst, (char*)src, (int)size )__builtin___memmove_chk ((char*)dst, (char*)src, (int)size, __builtin_object_size ((char*)dst, 0)); | |||
171 | } | |||
172 | else | |||
173 | (void) memmove((char*)dst, (char*)src, (int)size )__builtin___memmove_chk ((char*)dst, (char*)src, (int)size, __builtin_object_size ((char*)dst, 0)); | |||
174 | #else | |||
175 | XtErrorMsg("invalidGetValues", "xtGetValues", XtCXtToolkitError, | |||
176 | "NULL ArgVal in XtGetValues", (String*) NULL((void*)0), (Cardinal*) NULL((void*)0)); | |||
177 | #endif | |||
178 | } | |||
179 | else { | |||
180 | /* proper GetValues semantics: argval is pointer to destination */ | |||
181 | (void) memmove((char*)*dst, (char*)src, (int)size )__builtin___memmove_chk ((char*)*dst, (char*)src, (int)size, __builtin_object_size ((char*)*dst, 0)); | |||
182 | } | |||
183 | } /* _XtCopyToArg */ | |||
184 | ||||
185 | static void CopyToArg( | |||
186 | char* src, | |||
187 | XtArgVal *dst, | |||
188 | register unsigned int size) | |||
189 | { | |||
190 | if (!*dst) { | |||
191 | /* old GetValues semantics (storing directly into arglists) are bad, | |||
192 | * but preserve for compatibility as long as arglist contains NULL. | |||
193 | */ | |||
194 | union { | |||
195 | long longval; | |||
196 | #ifdef LONG64 | |||
197 | int intval; | |||
198 | #endif | |||
199 | short shortval; | |||
200 | char charval; | |||
201 | char* charptr; | |||
202 | XtPointer ptr; | |||
203 | } u; | |||
204 | if (size <= sizeof(XtArgVal)) { | |||
205 | (void) memmove((char*)&u, (char*)src, (int)size )__builtin___memmove_chk ((char*)&u, (char*)src, (int)size , __builtin_object_size ((char*)&u, 0)); | |||
206 | if (size == sizeof(long)) *dst = (XtArgVal)u.longval; | |||
207 | #ifdef LONG64 | |||
208 | else if (size == sizeof(int)) *dst = (XtArgVal)u.intval; | |||
209 | #endif | |||
210 | else if (size == sizeof(short)) *dst = (XtArgVal)u.shortval; | |||
211 | else if (size == sizeof(char)) *dst = (XtArgVal)u.charval; | |||
212 | else if (size == sizeof(char*)) *dst = (XtArgVal)u.charptr; | |||
213 | else if (size == sizeof(XtPointer)) *dst = (XtArgVal)u.ptr; | |||
214 | else (void) memmove((char*)dst, (char*)src, (int)size )__builtin___memmove_chk ((char*)dst, (char*)src, (int)size, __builtin_object_size ((char*)dst, 0)); | |||
215 | } | |||
216 | else | |||
217 | (void) memmove((char*)dst, (char*)src, (int)size )__builtin___memmove_chk ((char*)dst, (char*)src, (int)size, __builtin_object_size ((char*)dst, 0)); | |||
218 | } | |||
219 | else { | |||
220 | /* proper GetValues semantics: argval is pointer to destination */ | |||
221 | (void) memmove((char*)*dst, (char*)src, (int)size )__builtin___memmove_chk ((char*)*dst, (char*)src, (int)size, __builtin_object_size ((char*)*dst, 0)); | |||
222 | } | |||
223 | } /* CopyToArg */ | |||
224 | ||||
225 | ||||
226 | static Cardinal CountTreeDepth( | |||
227 | Widget w) | |||
228 | { | |||
229 | Cardinal count; | |||
230 | ||||
231 | for (count = 1; w != NULL((void*)0); w = (Widget) w->core.parent) | |||
232 | count++; | |||
233 | ||||
234 | return count; | |||
235 | } | |||
236 | ||||
237 | static void GetNamesAndClasses( | |||
238 | register Widget w, | |||
239 | register XrmNameList names, | |||
240 | register XrmClassList classes) | |||
241 | { | |||
242 | register Cardinal length, j; | |||
243 | register XrmQuark t; | |||
244 | WidgetClass class; | |||
245 | ||||
246 | /* Return null-terminated quark arrays, with length the number of | |||
247 | quarks (not including NULL) */ | |||
248 | ||||
249 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); | |||
250 | for (length = 0; w != NULL((void*)0); w = (Widget) w->core.parent) { | |||
251 | names[length] = w->core.xrm_name; | |||
252 | class = XtClass(w)((w)->core.widget_class); | |||
253 | /* KLUDGE KLUDGE KLUDGE KLUDGE */ | |||
254 | if (w->core.parent == NULL((void*)0) && XtIsApplicationShell(w)(_XtIsSubclassOf(w, (WidgetClass)applicationShellWidgetClass, (WidgetClass)topLevelShellWidgetClass, (XtEnum)0x80))) { | |||
255 | classes[length] = | |||
256 | ((ApplicationShellWidget) w)->application.xrm_class; | |||
257 | } else classes[length] = class->core_class.xrm_class; | |||
258 | length++; | |||
259 | } | |||
260 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); | |||
261 | /* They're in backwards order, flop them around */ | |||
262 | for (j = 0; j < length/2; j++) { | |||
263 | t = names[j]; | |||
264 | names[j] = names[length-j-1]; | |||
265 | names[length-j-1] = t; | |||
266 | t = classes[j]; | |||
267 | classes[j] = classes[length-j-1]; | |||
268 | classes[length-j-1] = t; | |||
269 | } | |||
270 | names[length] = NULLQUARK((XrmQuark) 0); | |||
271 | classes[length] = NULLQUARK((XrmQuark) 0); | |||
272 | } /* GetNamesAndClasses */ | |||
273 | ||||
274 | ||||
275 | /* Spiffy fast compiled form of resource list. */ | |||
276 | /* XtResourceLists are compiled in-place into XrmResourceLists */ | |||
277 | /* All atoms are replaced by quarks, and offsets are -offset-1 to */ | |||
278 | /* indicate that this list has been compiled already */ | |||
279 | ||||
280 | void _XtCompileResourceList( | |||
281 | register XtResourceList resources, | |||
282 | Cardinal num_resources) | |||
283 | { | |||
284 | register Cardinal count; | |||
285 | ||||
286 | #define xrmres ((XrmResourceList) resources) | |||
287 | #define PSToQ XrmPermStringToQuark | |||
288 | ||||
289 | for (count = 0; count < num_resources; resources++, count++) { | |||
290 | xrmres->xrm_name = PSToQ(resources->resource_name); | |||
291 | xrmres->xrm_class = PSToQ(resources->resource_class); | |||
292 | xrmres->xrm_type = PSToQ(resources->resource_type); | |||
293 | xrmres->xrm_offset = (Cardinal) | |||
294 | (-(int)resources->resource_offset - 1); | |||
295 | xrmres->xrm_default_type = PSToQ(resources->default_type); | |||
296 | } | |||
297 | #undef PSToQ | |||
298 | #undef xrmres | |||
299 | } /* _XtCompileResourceList */ | |||
300 | ||||
301 | /* Like _XtCompileResourceList, but strings are not permanent */ | |||
302 | static void XrmCompileResourceListEphem( | |||
303 | register XtResourceList resources, | |||
304 | Cardinal num_resources) | |||
305 | { | |||
306 | register Cardinal count; | |||
307 | ||||
308 | #define xrmres ((XrmResourceList) resources) | |||
309 | ||||
310 | for (count = 0; count < num_resources; resources++, count++) { | |||
311 | xrmres->xrm_name = StringToName(resources->resource_name)XrmStringToQuark(resources->resource_name); | |||
312 | xrmres->xrm_class = StringToClass(resources->resource_class)XrmStringToQuark(resources->resource_class); | |||
313 | xrmres->xrm_type = StringToQuark(resources->resource_type)XrmStringToQuark(resources->resource_type); | |||
314 | xrmres->xrm_offset = (Cardinal) | |||
315 | (-(int)resources->resource_offset - 1); | |||
316 | xrmres->xrm_default_type = StringToQuark(resources->default_type)XrmStringToQuark(resources->default_type); | |||
317 | } | |||
318 | #undef xrmres | |||
319 | } /* XrmCompileResourceListEphem */ | |||
320 | ||||
321 | static void BadSize( | |||
322 | Cardinal size, | |||
323 | XrmQuark name) | |||
324 | { | |||
325 | String params[2]; | |||
326 | Cardinal num_params = 2; | |||
327 | ||||
328 | params[0] = (String)(long) size; | |||
329 | params[1] = XrmQuarkToString(name); | |||
330 | XtWarningMsg("invalidSizeOverride", "xtDependencies", XtCXtToolkitError, | |||
331 | "Representation size %d must match superclass's to override %s", | |||
332 | params, &num_params); | |||
333 | } /* BadType */ | |||
334 | ||||
335 | /* | |||
336 | * Create a new resource list, with the class resources following the | |||
337 | * superclass's resources. If a resource in the class list overrides | |||
338 | * a superclass resource, then just replace the superclass entry in place. | |||
339 | * | |||
340 | * At the same time, add a level of indirection to the XtResourceList to | |||
341 | * create and XrmResourceList. | |||
342 | */ | |||
343 | void _XtDependencies( | |||
344 | XtResourceList *class_resp, /* VAR */ | |||
345 | Cardinal *class_num_resp, /* VAR */ | |||
346 | XrmResourceList *super_res, | |||
347 | Cardinal super_num_res, | |||
348 | Cardinal super_widget_size) | |||
349 | { | |||
350 | register XrmResourceList *new_res; | |||
351 | Cardinal new_num_res; | |||
352 | XrmResourceList class_res = (XrmResourceList) *class_resp; | |||
353 | Cardinal class_num_res = *class_num_resp; | |||
354 | register Cardinal i, j; | |||
355 | Cardinal new_next; | |||
356 | ||||
357 | if (class_num_res == 0) { | |||
358 | /* Just point to superclass resource list */ | |||
359 | *class_resp = (XtResourceList) super_res; | |||
360 | *class_num_resp = super_num_res; | |||
361 | return; | |||
362 | } | |||
363 | ||||
364 | /* Allocate and initialize new_res with superclass resource pointers */ | |||
365 | new_num_res = super_num_res + class_num_res; | |||
366 | new_res = (XrmResourceList *) __XtMalloc(new_num_res*sizeof(XrmResourceList)); | |||
367 | if (super_num_res > 0) | |||
368 | XtMemmove(new_res, super_res, super_num_res * sizeof(XrmResourceList))if ((char *)(new_res) != (char *)(super_res)) { (void) __builtin___memcpy_chk ((char *) (new_res), (char *) (super_res), (int) (super_num_res * sizeof(XrmResourceList)), __builtin_object_size ((char *) ( new_res), 0)); }; | |||
369 | ||||
370 | /* Put pointers to class resource entries into new_res */ | |||
371 | new_next = super_num_res; | |||
372 | for (i = 0; i < class_num_res; i++) { | |||
373 | if ((Cardinal)(-class_res[i].xrm_offset-1) < super_widget_size) { | |||
374 | /* Probably an override of superclass resources--look for overlap */ | |||
375 | for (j = 0; j < super_num_res; j++) { | |||
376 | if (class_res[i].xrm_offset == new_res[j]->xrm_offset) { | |||
377 | /* Spec is silent on what fields subclass can override. | |||
378 | * The only two of real concern are type & size. | |||
379 | * Although allowing type to be over-ridden introduces | |||
380 | * the possibility of errors, it's at present the only | |||
381 | * reasonable way to allow a subclass to force a private | |||
382 | * converter to be invoked for a subset of fields. | |||
383 | */ | |||
384 | /* We do insist that size be identical to superclass */ | |||
385 | if (class_res[i].xrm_size != new_res[j]->xrm_size) { | |||
386 | BadSize(class_res[i].xrm_size, | |||
387 | (XrmQuark) class_res[i].xrm_name); | |||
388 | class_res[i].xrm_size = new_res[j]->xrm_size; | |||
389 | } | |||
390 | new_res[j] = &(class_res[i]); | |||
391 | new_num_res--; | |||
392 | goto NextResource; | |||
393 | } | |||
394 | } /* for j */ | |||
395 | } | |||
396 | /* Not an overlap, add an entry to new_res */ | |||
397 | new_res[new_next++] = &(class_res[i]); | |||
398 | NextResource:; | |||
399 | } /* for i */ | |||
400 | ||||
401 | /* Okay, stuff new resources back into class record */ | |||
402 | *class_resp = (XtResourceList) new_res; | |||
403 | *class_num_resp = new_num_res; | |||
404 | } /* _XtDependencies */ | |||
405 | ||||
406 | ||||
407 | void _XtResourceDependencies( | |||
408 | WidgetClass wc) | |||
409 | { | |||
410 | WidgetClass sc; | |||
411 | ||||
412 | sc = wc->core_class.superclass; | |||
413 | if (sc == NULL((void*)0)) { | |||
414 | _XtDependencies(&(wc->core_class.resources), | |||
415 | &(wc->core_class.num_resources), | |||
416 | (XrmResourceList *) NULL((void*)0), (unsigned)0, (unsigned)0); | |||
417 | } else { | |||
418 | _XtDependencies(&(wc->core_class.resources), | |||
419 | &(wc->core_class.num_resources), | |||
420 | (XrmResourceList *) sc->core_class.resources, | |||
421 | sc->core_class.num_resources, | |||
422 | sc->core_class.widget_size); | |||
423 | } | |||
424 | } /* _XtResourceDependencies */ | |||
425 | ||||
426 | void _XtConstraintResDependencies( | |||
427 | ConstraintWidgetClass wc) | |||
428 | { | |||
429 | ConstraintWidgetClass sc; | |||
430 | ||||
431 | if (wc == (ConstraintWidgetClass) constraintWidgetClass) { | |||
432 | _XtDependencies(&(wc->constraint_class.resources), | |||
433 | &(wc->constraint_class.num_resources), | |||
434 | (XrmResourceList *)NULL((void*)0), (unsigned)0, (unsigned)0); | |||
435 | } else { | |||
436 | sc = (ConstraintWidgetClass) wc->core_class.superclass; | |||
437 | _XtDependencies(&(wc->constraint_class.resources), | |||
438 | &(wc->constraint_class.num_resources), | |||
439 | (XrmResourceList *) sc->constraint_class.resources, | |||
440 | sc->constraint_class.num_resources, | |||
441 | sc->constraint_class.constraint_size); | |||
442 | } | |||
443 | } /* _XtConstraintResDependencies */ | |||
444 | ||||
445 | ||||
446 | ||||
447 | ||||
448 | XrmResourceList* _XtCreateIndirectionTable ( | |||
449 | XtResourceList resources, | |||
450 | Cardinal num_resources) | |||
451 | { | |||
452 | register Cardinal idx; | |||
453 | XrmResourceList* table; | |||
454 | ||||
455 | table = (XrmResourceList*)__XtMalloc(num_resources * sizeof(XrmResourceList)); | |||
456 | for (idx = 0; idx < num_resources; idx++) | |||
457 | table[idx] = (XrmResourceList)(&(resources[idx])); | |||
458 | return table; | |||
459 | } | |||
460 | ||||
461 | static XtCacheRef *GetResources( | |||
462 | Widget widget, /* Widget resources are associated with */ | |||
463 | char* base, /* Base address of memory to write to */ | |||
464 | XrmNameList names, /* Full inheritance name of widget */ | |||
465 | XrmClassList classes, /* Full inheritance class of widget */ | |||
466 | XrmResourceList* table, /* The list of resources required. */ | |||
467 | unsigned num_resources, /* number of items in resource list */ | |||
468 | XrmQuarkList quark_args, /* Arg names quarkified */ | |||
469 | ArgList args, /* ArgList to override resources */ | |||
470 | unsigned num_args, /* number of items in arg list */ | |||
471 | XtTypedArgList typed_args, /* Typed arg list to override resources */ | |||
472 | Cardinal* pNumTypedArgs, /* number of items in typed arg list */ | |||
473 | Boolean tm_hack) /* do baseTranslations */ | |||
474 | { | |||
475 | /* | |||
476 | * assert: *pNumTypedArgs == 0 if num_args > 0 | |||
477 | * assert: num_args == 0 if *pNumTypedArgs > 0 | |||
478 | */ | |||
479 | #define SEARCHLISTLEN100 100 | |||
480 | #define MAXRESOURCES400 400 | |||
481 | ||||
482 | XrmValue value; | |||
483 | XrmQuark rawType; | |||
484 | XrmValue convValue; | |||
485 | XrmHashTable stackSearchList[SEARCHLISTLEN100]; | |||
486 | XrmHashTable *searchList = stackSearchList; | |||
487 | unsigned int searchListSize = SEARCHLISTLEN100; | |||
488 | Boolean found[MAXRESOURCES400]; | |||
489 | int typed[MAXRESOURCES400]; | |||
490 | XtCacheRef cache_ref[MAXRESOURCES400]; | |||
491 | XtCacheRef *cache_ptr, *cache_base; | |||
492 | Boolean persistent_resources = True1; | |||
493 | Boolean found_persistence = False0; | |||
494 | int num_typed_args = *pNumTypedArgs; | |||
495 | XrmDatabase db; | |||
496 | Boolean do_tm_hack = False0; | |||
497 | ||||
498 | if ((args == NULL((void*)0)) && (num_args != 0)) { | |||
499 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), | |||
500 | "invalidArgCount","getResources",XtCXtToolkitError, | |||
501 | "argument count > 0 on NULL argument list", | |||
502 | (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); | |||
503 | num_args = 0; | |||
504 | } | |||
505 | if (num_resources == 0) { | |||
506 | return NULL((void*)0); | |||
507 | } else if (num_resources >= MAXRESOURCES400) { | |||
508 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), | |||
509 | "invalidResourceCount","getResources",XtCXtToolkitError, | |||
510 | "too many resources", | |||
511 | (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); | |||
512 | return NULL((void*)0); | |||
513 | } else if (table == NULL((void*)0)) { | |||
514 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), | |||
515 | "invalidResourceCount","getResources",XtCXtToolkitError, | |||
516 | "resource count > 0 on NULL resource list", | |||
517 | (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); | |||
518 | return NULL((void*)0); | |||
519 | } | |||
520 | ||||
521 | /* Mark each resource as not found on arg list */ | |||
522 | bzero((char *) found, (int) (num_resources * sizeof(Boolean)))__builtin___memset_chk ((char *) found, 0, (int) (num_resources * sizeof(Boolean)), __builtin_object_size ((char *) found, 0 )); | |||
523 | bzero((char *) typed, (int) (num_resources * sizeof(int)))__builtin___memset_chk ((char *) typed, 0, (int) (num_resources * sizeof(int)), __builtin_object_size ((char *) typed, 0)); | |||
524 | ||||
525 | /* Copy the args into the resources, mark each as found */ | |||
526 | { | |||
527 | register ArgList arg; | |||
528 | register XtTypedArgList typed_arg; | |||
529 | register XrmName argName; | |||
530 | register Cardinal j; | |||
531 | register int i; | |||
532 | register XrmResourceList rx; | |||
533 | register XrmResourceList *res; | |||
534 | for (arg = args, i = 0; (Cardinal)i < num_args; i++, arg++) { | |||
535 | argName = quark_args[i]; | |||
536 | if (argName == QinitialResourcesPersistent) { | |||
537 | persistent_resources = (Boolean)arg->value; | |||
538 | found_persistence = True1; | |||
539 | continue; | |||
540 | } | |||
541 | for (j = 0, res = table; j < num_resources; j++, res++) { | |||
542 | rx = *res; | |||
543 | if (argName == rx->xrm_name) { | |||
544 | _XtCopyFromArg( | |||
545 | arg->value, | |||
546 | base - rx->xrm_offset - 1, | |||
547 | rx->xrm_size); | |||
548 | found[j] = TRUE1; | |||
549 | break; | |||
550 | } | |||
551 | } | |||
552 | } | |||
553 | for (typed_arg = typed_args, i = 0; i < num_typed_args; | |||
554 | i++, typed_arg++) { | |||
555 | register XrmRepresentation argType; | |||
556 | argName = quark_args[i]; | |||
557 | argType = (typed_arg->type == NULL((void*)0)) ? NULLQUARK((XrmQuark) 0) | |||
558 | : XrmStringToRepresentation(typed_arg->type)XrmStringToQuark(typed_arg->type); | |||
559 | if (argName == QinitialResourcesPersistent) { | |||
560 | persistent_resources = (Boolean)typed_arg->value; | |||
561 | found_persistence = True1; | |||
562 | break; | |||
563 | } | |||
564 | for (j = 0, res = table; j < num_resources; j++, res++) { | |||
565 | rx = *res; | |||
566 | if (argName == rx->xrm_name) { | |||
567 | if (argType != NULLQUARK((XrmQuark) 0) && argType != rx->xrm_type) { | |||
568 | typed[j] = i + 1; | |||
569 | } else { | |||
570 | _XtCopyFromArg( | |||
571 | typed_arg->value, | |||
572 | base - rx->xrm_offset - 1, | |||
573 | rx->xrm_size); | |||
574 | } | |||
575 | found[j] = TRUE1; | |||
576 | break; | |||
577 | } | |||
578 | } | |||
579 | } | |||
580 | } | |||
581 | ||||
582 | /* Ask resource manager for a list of database levels that we can | |||
583 | do a single-level search on each resource */ | |||
584 | ||||
585 | db = XtScreenDatabase(XtScreenOfObject(widget)((((Object)(widget))->object.widget_class->core_class.class_inited & 0x04) ? (widget)->core.screen : _XtIsHookObject(widget ) ? ((HookObject)(widget))->hooks.screen : _XtWindowedAncestor (widget)->core.screen)); | |||
586 | while (!XrmQGetSearchList(db, names, classes, | |||
587 | searchList, searchListSize)) { | |||
588 | if (searchList == stackSearchList) | |||
589 | searchList = NULL((void*)0); | |||
590 | searchList = (XrmHashTable*)XtRealloc((char*)searchList, | |||
591 | sizeof(XrmHashTable) * | |||
592 | (searchListSize *= 2)); | |||
593 | } | |||
594 | ||||
595 | if (persistent_resources) | |||
596 | cache_base = NULL((void*)0); | |||
597 | else | |||
598 | cache_base = cache_ref; | |||
599 | /* geez, this is an ugly mess */ | |||
600 | if (XtIsShell(widget)(((Object)(widget))->object.widget_class->core_class.class_inited & 0x20)) { | |||
601 | register XrmResourceList *res; | |||
602 | register Cardinal j; | |||
603 | Screen *oldscreen = widget->core.screen; | |||
604 | ||||
605 | /* look up screen resource first, since real rdb depends on it */ | |||
606 | for (res = table, j = 0; j < num_resources; j++, res++) { | |||
607 | if ((*res)->xrm_name != Qscreen) | |||
608 | continue; | |||
609 | if (typed[j]) { | |||
610 | register XtTypedArg* arg = typed_args + typed[j] - 1; | |||
611 | XrmQuark from_type; | |||
612 | XrmValue from_val, to_val; | |||
613 | ||||
614 | from_type = StringToQuark(arg->type)XrmStringToQuark(arg->type); | |||
615 | from_val.size = arg->size; | |||
616 | if ((from_type == QString) || ((unsigned) arg->size > sizeof(XtArgVal))) | |||
617 | from_val.addr = (XPointer)arg->value; | |||
618 | else | |||
619 | from_val.addr = (XPointer)&arg->value; | |||
620 | to_val.size = sizeof(Screen*); | |||
621 | to_val.addr = (XPointer)&widget->core.screen; | |||
622 | found[j] = _XtConvert(widget, from_type, &from_val, | |||
623 | QScreen, &to_val, cache_base); | |||
624 | if (cache_base && *cache_base) | |||
625 | cache_base++; | |||
626 | } | |||
627 | if (!found[j]) { | |||
628 | if (XrmQGetSearchResource(searchList, Qscreen, QScreen, | |||
629 | &rawType, &value)) { | |||
630 | if (rawType != QScreen) { | |||
631 | convValue.size = sizeof(Screen*); | |||
632 | convValue.addr = (XPointer)&widget->core.screen; | |||
633 | (void)_XtConvert(widget, rawType, &value, | |||
634 | QScreen, &convValue, cache_base); | |||
635 | if (cache_base && *cache_base) | |||
636 | cache_base++; | |||
637 | } else { | |||
638 | widget->core.screen = *((Screen **)value.addr); | |||
639 | } | |||
640 | } | |||
641 | } | |||
642 | break; | |||
643 | } | |||
644 | /* now get the database to use for the rest of the resources */ | |||
645 | if (widget->core.screen != oldscreen) { | |||
646 | db = XtScreenDatabase(widget->core.screen); | |||
647 | while (!XrmQGetSearchList(db, names, classes, | |||
648 | searchList, searchListSize)) { | |||
649 | if (searchList == stackSearchList) | |||
650 | searchList = NULL((void*)0); | |||
651 | searchList = (XrmHashTable*)XtRealloc((char*)searchList, | |||
652 | sizeof(XrmHashTable) * | |||
653 | (searchListSize *= 2)); | |||
654 | } | |||
655 | } | |||
656 | } | |||
657 | ||||
658 | /* go to the resource manager for those resources not found yet */ | |||
659 | /* if it's not in the resource database use the default value */ | |||
660 | ||||
661 | { | |||
662 | register XrmResourceList rx; | |||
663 | register XrmResourceList *res; | |||
664 | register Cardinal j; | |||
665 | register XrmRepresentation xrm_type; | |||
666 | register XrmRepresentation xrm_default_type; | |||
667 | char char_val; | |||
668 | short short_val; | |||
669 | int int_val; | |||
670 | long long_val; | |||
671 | char* char_ptr; | |||
672 | ||||
673 | if (!found_persistence) { | |||
674 | if (XrmQGetSearchResource(searchList, QinitialResourcesPersistent, | |||
675 | QInitialResourcesPersistent, &rawType, &value)) { | |||
676 | if (rawType != QBoolean) { | |||
677 | convValue.size = sizeof(Boolean); | |||
678 | convValue.addr = (XPointer)&persistent_resources; | |||
679 | (void)_XtConvert(widget, rawType, &value, QBoolean, | |||
680 | &convValue, NULL((void*)0)); | |||
681 | } | |||
682 | else | |||
683 | persistent_resources = *(Boolean*)value.addr; | |||
684 | } | |||
685 | } | |||
686 | if (persistent_resources) | |||
687 | cache_ptr = NULL((void*)0); | |||
688 | else if (cache_base) | |||
689 | cache_ptr = cache_base; | |||
690 | else | |||
691 | cache_ptr = cache_ref; | |||
692 | ||||
693 | for (res = table, j = 0; j < num_resources; j++, res++) { | |||
694 | rx = *res; | |||
695 | xrm_type = rx->xrm_type; | |||
696 | if (typed[j]) { | |||
697 | register XtTypedArg* arg = typed_args + typed[j] - 1; | |||
698 | ||||
699 | /* | |||
700 | * This resource value has been specified as a typed arg and | |||
701 | * has to be converted. Typed arg conversions are done here | |||
702 | * to correctly interpose them with normal resource conversions. | |||
703 | */ | |||
704 | XrmQuark from_type; | |||
705 | XrmValue from_val, to_val; | |||
706 | Boolean converted; | |||
707 | ||||
708 | from_type = StringToQuark(arg->type)XrmStringToQuark(arg->type); | |||
709 | from_val.size = arg->size; | |||
710 | if ((from_type == QString) || ((unsigned) arg->size > sizeof(XtArgVal))) | |||
711 | from_val.addr = (XPointer)arg->value; | |||
712 | else | |||
713 | from_val.addr = (XPointer)&arg->value; | |||
714 | to_val.size = rx->xrm_size; | |||
715 | to_val.addr = base - rx->xrm_offset - 1; | |||
716 | converted = _XtConvert(widget, from_type, &from_val, | |||
717 | xrm_type, &to_val, cache_ptr); | |||
718 | if (converted) { | |||
719 | ||||
720 | /* Copy the converted value back into the typed argument. | |||
721 | * normally the data should be <= sizeof(XtArgVal) and | |||
722 | * is stored directly into the 'value' field .... BUT | |||
723 | * if the resource size is greater than sizeof(XtArgVal) | |||
724 | * then we dynamically alloc a block of store to hold the | |||
725 | * data and zap a copy in there !!! .... freeing it later | |||
726 | * the size field in the typed arg is negated to indicate | |||
727 | * that the store pointed to by the value field is | |||
728 | * dynamic ....... | |||
729 | * "freeing" happens in the case of _XtCreate after the | |||
730 | * CallInitialize ..... other clients of GetResources | |||
731 | * using typed args should be aware of the need to free | |||
732 | * this store ..... | |||
733 | */ | |||
734 | ||||
735 | if(rx->xrm_size > sizeof(XtArgVal)) { | |||
736 | arg->value = (XtArgVal) __XtMalloc(rx->xrm_size); | |||
737 | arg->size = -(arg->size); | |||
738 | } else { /* will fit - copy directly into value field */ | |||
739 | arg->value = (XtArgVal) NULL((void*)0); | |||
740 | } | |||
741 | CopyToArg((char *)(base - rx->xrm_offset - 1), | |||
742 | &arg->value, rx->xrm_size); | |||
743 | ||||
744 | } else { | |||
745 | /* Conversion failed. Get default value. */ | |||
746 | found[j] = False0; | |||
747 | } | |||
748 | ||||
749 | if (cache_ptr && *cache_ptr) | |||
750 | cache_ptr++; | |||
751 | } | |||
752 | ||||
753 | if (!found[j]) { | |||
754 | Boolean already_copied = False0; | |||
755 | Boolean have_value = False0; | |||
756 | ||||
757 | if (XrmQGetSearchResource(searchList, | |||
758 | rx->xrm_name, rx->xrm_class, &rawType, &value)) { | |||
759 | if (rawType != xrm_type) { | |||
760 | convValue.size = rx->xrm_size; | |||
761 | convValue.addr = (XPointer)(base - rx->xrm_offset - 1); | |||
762 | already_copied = have_value = | |||
763 | _XtConvert(widget, rawType, &value, | |||
764 | xrm_type, &convValue, cache_ptr); | |||
765 | if (cache_ptr && *cache_ptr) | |||
766 | cache_ptr++; | |||
767 | } else have_value = True1; | |||
768 | if (have_value && rx->xrm_name == Qtranslations) | |||
769 | do_tm_hack = True1; | |||
770 | } | |||
771 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); | |||
772 | if (!have_value | |||
773 | && ((rx->xrm_default_type == QImmediate) | |||
774 | || (rx->xrm_default_type == xrm_type) | |||
775 | || (rx->xrm_default_addr != NULL((void*)0)))) { | |||
776 | /* Convert default value to proper type */ | |||
777 | xrm_default_type = rx->xrm_default_type; | |||
778 | if (xrm_default_type == QCallProc) { | |||
779 | (*(XtResourceDefaultProc)(rx->xrm_default_addr))( | |||
780 | widget,-(rx->xrm_offset+1), &value); | |||
781 | ||||
782 | } else if (xrm_default_type == QImmediate) { | |||
783 | /* XtRImmediate == XtRString for type XtRString */ | |||
784 | if (xrm_type == QString) { | |||
785 | value.addr = rx->xrm_default_addr; | |||
786 | } else if (rx->xrm_size == sizeof(int)) { | |||
787 | int_val = (int)(long)rx->xrm_default_addr; | |||
788 | value.addr = (XPointer) &int_val; | |||
789 | } else if (rx->xrm_size == sizeof(short)) { | |||
790 | short_val = (short)(long)rx->xrm_default_addr; | |||
791 | value.addr = (XPointer) &short_val; | |||
792 | } else if (rx->xrm_size == sizeof(char)) { | |||
793 | char_val = (char)(long)rx->xrm_default_addr; | |||
794 | value.addr = (XPointer) &char_val; | |||
795 | } else if (rx->xrm_size == sizeof(long)) { | |||
796 | long_val = (long)rx->xrm_default_addr; | |||
797 | value.addr = (XPointer) &long_val; | |||
798 | } else if (rx->xrm_size == sizeof(char*)) { | |||
799 | char_ptr = (char*)rx->xrm_default_addr; | |||
800 | value.addr = (XPointer) &char_ptr; | |||
801 | } else { | |||
802 | value.addr = (XPointer) &(rx->xrm_default_addr); | |||
803 | } | |||
804 | } else if (xrm_default_type == xrm_type) { | |||
805 | value.addr = rx->xrm_default_addr; | |||
806 | } else { | |||
807 | value.addr = rx->xrm_default_addr; | |||
808 | if (xrm_default_type == QString) { | |||
809 | value.size = strlen((char *)value.addr) + 1; | |||
810 | } else { | |||
811 | value.size = sizeof(XtPointer); | |||
812 | } | |||
813 | convValue.size = rx->xrm_size; | |||
814 | convValue.addr = (XPointer)(base - rx->xrm_offset - 1); | |||
815 | already_copied = | |||
816 | _XtConvert(widget, xrm_default_type, &value, | |||
817 | xrm_type, &convValue, cache_ptr); | |||
818 | if (!already_copied) | |||
819 | value.addr = NULL((void*)0); | |||
820 | if (cache_ptr && *cache_ptr) | |||
821 | cache_ptr++; | |||
822 | } | |||
823 | } | |||
824 | if (!already_copied) { | |||
825 | if (xrm_type == QString) { | |||
826 | *((String*)(base - rx->xrm_offset - 1)) = value.addr; | |||
827 | } else { | |||
828 | if (value.addr != NULL((void*)0)) { | |||
829 | XtMemmove(base - rx->xrm_offset - 1,if ((char *)(base - rx->xrm_offset - 1) != (char *)(value. addr)) { (void) __builtin___memcpy_chk ((char *) (base - rx-> xrm_offset - 1), (char *) (value.addr), (int) (rx->xrm_size ), __builtin_object_size ((char *) (base - rx->xrm_offset - 1), 0)); } | |||
830 | value.addr, rx->xrm_size)if ((char *)(base - rx->xrm_offset - 1) != (char *)(value. addr)) { (void) __builtin___memcpy_chk ((char *) (base - rx-> xrm_offset - 1), (char *) (value.addr), (int) (rx->xrm_size ), __builtin_object_size ((char *) (base - rx->xrm_offset - 1), 0)); }; | |||
831 | } else { | |||
832 | /* didn't get value, initialize to NULL... */ | |||
833 | XtBZero(base - rx->xrm_offset - 1, rx->xrm_size)__builtin___memset_chk ((char *) (base - rx->xrm_offset - 1 ), 0, (int) (rx->xrm_size), __builtin_object_size ((char * ) (base - rx->xrm_offset - 1), 0)); | |||
834 | } | |||
835 | } | |||
836 | } | |||
837 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); | |||
838 | } | |||
839 | } | |||
840 | for (res = table, j = 0; j < num_resources; j++, res++) { | |||
841 | if (!found[j] && typed[j]) { | |||
842 | /* | |||
843 | * This resource value was specified as a typed arg. | |||
844 | * However, the default value is being used here since | |||
845 | * type type conversion failed, so we compress the list. | |||
846 | */ | |||
847 | register XtTypedArg* arg = typed_args + typed[j] - 1; | |||
848 | register int i; | |||
849 | ||||
850 | for (i = num_typed_args - typed[j]; i > 0; i--, arg++) { | |||
851 | *arg = *(arg+1); | |||
852 | } | |||
853 | num_typed_args--; | |||
854 | } | |||
855 | } | |||
856 | if (tm_hack) | |||
857 | widget->core.tm.current_state = NULL((void*)0); | |||
858 | if (tm_hack && | |||
859 | (!widget->core.tm.translations || | |||
860 | (do_tm_hack && | |||
861 | widget->core.tm.translations->operation != XtTableReplace0)) && | |||
862 | XrmQGetSearchResource(searchList, QbaseTranslations, | |||
863 | QTranslations, &rawType, &value)) { | |||
864 | if (rawType != QTranslationTable) { | |||
865 | convValue.size = sizeof(XtTranslations); | |||
866 | convValue.addr = (XPointer)&widget->core.tm.current_state; | |||
867 | (void)_XtConvert(widget, rawType, &value, | |||
868 | QTranslationTable, &convValue, cache_ptr); | |||
869 | if (cache_ptr && *cache_ptr) | |||
870 | cache_ptr++; | |||
871 | } else { | |||
872 | /* value.addr can be NULL see: !already_copied */ | |||
873 | if (value.addr) | |||
874 | *((XtTranslations *)&widget->core.tm.current_state) = | |||
875 | *((XtTranslations *)value.addr); | |||
876 | } | |||
877 | } | |||
878 | } | |||
879 | if ((Cardinal)num_typed_args != *pNumTypedArgs) *pNumTypedArgs = num_typed_args; | |||
880 | if (searchList != stackSearchList) XtFree((char*)searchList); | |||
881 | if (!cache_ptr) | |||
882 | cache_ptr = cache_base; | |||
883 | if (cache_ptr && cache_ptr != cache_ref) { | |||
884 | int cache_ref_size = cache_ptr - cache_ref; | |||
885 | XtCacheRef *refs = (XtCacheRef*) | |||
886 | __XtMalloc((unsigned)sizeof(XtCacheRef)*(cache_ref_size + 1)); | |||
887 | (void) memmove(refs, cache_ref, sizeof(XtCacheRef)*cache_ref_size )__builtin___memmove_chk (refs, cache_ref, sizeof(XtCacheRef)* cache_ref_size, __builtin_object_size (refs, 0)); | |||
888 | refs[cache_ref_size] = NULL((void*)0); | |||
889 | return refs; | |||
890 | } | |||
891 | return (XtCacheRef*)NULL((void*)0); | |||
892 | } | |||
893 | ||||
894 | ||||
895 | ||||
896 | static void CacheArgs( | |||
897 | ArgList args, | |||
898 | Cardinal num_args, | |||
899 | XtTypedArgList typed_args, | |||
900 | Cardinal num_typed_args, | |||
901 | XrmQuarkList quark_cache, | |||
902 | Cardinal num_quarks, | |||
903 | XrmQuarkList *pQuarks) /* RETURN */ | |||
904 | { | |||
905 | register XrmQuarkList quarks; | |||
906 | register Cardinal i; | |||
907 | register Cardinal count; | |||
908 | ||||
909 | count = (args != NULL((void*)0)) ? num_args : num_typed_args; | |||
910 | ||||
911 | if (num_quarks < count) { | |||
912 | quarks = (XrmQuarkList) __XtMalloc(count * sizeof(XrmQuark)); | |||
913 | } else { | |||
914 | quarks = quark_cache; | |||
915 | } | |||
916 | *pQuarks = quarks; | |||
917 | ||||
918 | if (args != NULL((void*)0)) { | |||
919 | for (i = count; i; i--) | |||
920 | *quarks++ = StringToQuark((args++)->name)XrmStringToQuark((args++)->name); | |||
921 | } | |||
922 | else { | |||
923 | for (i = count; i; i--) | |||
924 | *quarks++ = StringToQuark((typed_args++)->name)XrmStringToQuark((typed_args++)->name); | |||
925 | } | |||
926 | } | |||
927 | ||||
928 | #define FreeCache(cache, pointer)if (cache != pointer) XtFree((char *)pointer) \ | |||
929 | if (cache != pointer) XtFree((char *)pointer) | |||
930 | ||||
931 | ||||
932 | XtCacheRef *_XtGetResources( | |||
933 | register Widget w, | |||
934 | ArgList args, | |||
935 | Cardinal num_args, | |||
936 | XtTypedArgList typed_args, | |||
937 | Cardinal* num_typed_args) | |||
938 | { | |||
939 | XrmName *names, names_s[50]; | |||
940 | XrmClass *classes, classes_s[50]; | |||
941 | XrmQuark quark_cache[100]; | |||
942 | XrmQuarkList quark_args; | |||
943 | WidgetClass wc; | |||
944 | ConstraintWidgetClass cwc; | |||
945 | XtCacheRef *cache_refs, *cache_refs_core; | |||
946 | Cardinal count; | |||
947 | ||||
948 | wc = XtClass(w)((w)->core.widget_class); | |||
949 | ||||
950 | count = CountTreeDepth(w); | |||
951 | names = (XrmName*) XtStackAlloc (count * sizeof(XrmName), names_s)((count * sizeof(XrmName)) <= sizeof(names_s) ? (XtPointer )(names_s) : XtMalloc((unsigned)(count * sizeof(XrmName)))); | |||
952 | classes = (XrmClass*) XtStackAlloc (count * sizeof(XrmClass), classes_s)((count * sizeof(XrmClass)) <= sizeof(classes_s) ? (XtPointer )(classes_s) : XtMalloc((unsigned)(count * sizeof(XrmClass))) ); | |||
953 | if (names == NULL((void*)0) || classes == NULL((void*)0)) _XtAllocError(NULL((void*)0)); | |||
954 | ||||
955 | /* Get names, classes for widget and ancestors */ | |||
956 | GetNamesAndClasses(w, names, classes); | |||
957 | ||||
958 | /* Compile arg list into quarks */ | |||
959 | CacheArgs(args, num_args, typed_args, *num_typed_args, quark_cache, | |||
960 | XtNumber(quark_cache)((Cardinal) (sizeof(quark_cache) / sizeof(quark_cache[0]))), &quark_args); | |||
961 | ||||
962 | /* Get normal resources */ | |||
963 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); | |||
964 | cache_refs = GetResources(w, (char*)w, names, classes, | |||
965 | (XrmResourceList *) wc->core_class.resources, | |||
966 | wc->core_class.num_resources, quark_args, args, num_args, | |||
967 | typed_args, num_typed_args, XtIsWidget(w)(((Object)(w))->object.widget_class->core_class.class_inited & 0x04)); | |||
968 | ||||
969 | if (w->core.constraints != NULL((void*)0)) { | |||
970 | cwc = (ConstraintWidgetClass) XtClass(w->core.parent)((w->core.parent)->core.widget_class); | |||
971 | cache_refs_core = | |||
972 | GetResources(w, (char*)w->core.constraints, names, classes, | |||
973 | (XrmResourceList *) cwc->constraint_class.resources, | |||
974 | cwc->constraint_class.num_resources, | |||
975 | quark_args, args, num_args, typed_args, num_typed_args, False0); | |||
976 | if (cache_refs_core) { | |||
977 | XtFree((char *)cache_refs_core); | |||
978 | } | |||
979 | } | |||
980 | FreeCache(quark_cache, quark_args)if (quark_cache != quark_args) XtFree((char *)quark_args); | |||
981 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); | |||
982 | XtStackFree((XtPointer)names, names_s){ if (((XtPointer)names) != ((XtPointer)(names_s))) XtFree((XtPointer )names); }; | |||
983 | XtStackFree((XtPointer)classes, classes_s){ if (((XtPointer)classes) != ((XtPointer)(classes_s))) XtFree ((XtPointer)classes); }; | |||
984 | return cache_refs; | |||
985 | } /* _XtGetResources */ | |||
986 | ||||
987 | ||||
988 | void _XtGetSubresources ( | |||
989 | Widget w, /* Widget "parent" of subobject */ | |||
990 | XtPointer base, /* Base address to write to */ | |||
991 | const char* name, /* name of subobject */ | |||
992 | const char* class, /* class of subobject */ | |||
993 | XtResourceList resources, /* resource list for subobject */ | |||
994 | Cardinal num_resources, | |||
995 | ArgList args, /* arg list to override resources */ | |||
996 | Cardinal num_args, | |||
997 | XtTypedArgList typed_args, | |||
998 | Cardinal num_typed_args) | |||
999 | { | |||
1000 | XrmName *names, names_s[50]; | |||
1001 | XrmClass *classes, classes_s[50]; | |||
1002 | XrmQuark quark_cache[100]; | |||
1003 | XrmQuarkList quark_args; | |||
1004 | XrmResourceList* table; | |||
1005 | Cardinal count, ntyped_args = num_typed_args; | |||
1006 | XtCacheRef *Resrc = NULL((void*)0); | |||
1007 | WIDGET_TO_APPCON(w)XtAppContext app = (w && _XtProcessLock ? XtWidgetToApplicationContext (w) : ((void*)0)); | |||
1008 | ||||
1009 | if (num_resources == 0) return; | |||
1010 | ||||
1011 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); | |||
1012 | count = CountTreeDepth(w); | |||
1013 | count++; /* make sure there's enough room for name and class */ | |||
1014 | names = (XrmName*) XtStackAlloc(count * sizeof(XrmName), names_s)((count * sizeof(XrmName)) <= sizeof(names_s) ? (XtPointer )(names_s) : XtMalloc((unsigned)(count * sizeof(XrmName)))); | |||
1015 | classes = (XrmClass*) XtStackAlloc(count * sizeof(XrmClass), classes_s)((count * sizeof(XrmClass)) <= sizeof(classes_s) ? (XtPointer )(classes_s) : XtMalloc((unsigned)(count * sizeof(XrmClass))) ); | |||
1016 | if (names == NULL((void*)0) || classes == NULL((void*)0)) _XtAllocError(NULL((void*)0)); | |||
1017 | ||||
1018 | /* Get full name, class of subobject */ | |||
1019 | GetNamesAndClasses(w, names, classes); | |||
1020 | count -= 2; | |||
1021 | names[count] = StringToName(name)XrmStringToQuark(name); | |||
| ||||
1022 | classes[count] = StringToClass(class)XrmStringToQuark(class); | |||
1023 | count++; | |||
1024 | names[count] = NULLQUARK((XrmQuark) 0); | |||
1025 | classes[count] = NULLQUARK((XrmQuark) 0); | |||
1026 | ||||
1027 | /* Compile arg list into quarks */ | |||
1028 | CacheArgs(args, num_args, typed_args, num_typed_args, | |||
1029 | quark_cache, XtNumber(quark_cache)((Cardinal) (sizeof(quark_cache) / sizeof(quark_cache[0]))), &quark_args); | |||
1030 | ||||
1031 | /* Compile resource list if needed */ | |||
1032 | if (((int) resources->resource_offset) >= 0) { | |||
1033 | XrmCompileResourceListEphem(resources, num_resources); | |||
1034 | } | |||
1035 | table = _XtCreateIndirectionTable(resources, num_resources); | |||
1036 | Resrc = GetResources(w, (char*)base, names, classes, table, num_resources, | |||
1037 | quark_args, args, num_args, | |||
1038 | typed_args, &ntyped_args, False0); | |||
1039 | FreeCache(quark_cache, quark_args)if (quark_cache != quark_args) XtFree((char *)quark_args); | |||
1040 | XtFree((char *)table); | |||
1041 | XtFree((char *)Resrc); | |||
1042 | XtStackFree((XtPointer)names, names_s){ if (((XtPointer)names) != ((XtPointer)(names_s))) XtFree((XtPointer )names); }; | |||
1043 | XtStackFree((XtPointer)classes, classes_s){ if (((XtPointer)classes) != ((XtPointer)(classes_s))) XtFree ((XtPointer)classes); }; | |||
1044 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); | |||
1045 | } | |||
1046 | ||||
1047 | void XtGetSubresources ( | |||
1048 | Widget w, /* Widget "parent" of subobject */ | |||
1049 | XtPointer base, /* Base address to write to */ | |||
1050 | _Xconstconst char* name, /* name of subobject */ | |||
1051 | _Xconstconst char* class, /* class of subobject */ | |||
1052 | XtResourceList resources, /* resource list for subobject */ | |||
1053 | Cardinal num_resources, | |||
1054 | ArgList args, /* arg list to override resources */ | |||
1055 | Cardinal num_args) | |||
1056 | { | |||
1057 | _XtGetSubresources (w, base, name, class, resources, num_resources, args, num_args, NULL((void*)0), 0); | |||
| ||||
1058 | } | |||
1059 | ||||
1060 | ||||
1061 | void _XtGetApplicationResources ( | |||
1062 | Widget w, /* Application shell widget */ | |||
1063 | XtPointer base, /* Base address to write to */ | |||
1064 | XtResourceList resources, /* resource list for subobject */ | |||
1065 | Cardinal num_resources, | |||
1066 | ArgList args, /* arg list to override resources */ | |||
1067 | Cardinal num_args, | |||
1068 | XtTypedArgList typed_args, | |||
1069 | Cardinal num_typed_args) | |||
1070 | { | |||
1071 | XrmName *names, names_s[50]; | |||
1072 | XrmClass *classes, classes_s[50]; | |||
1073 | XrmQuark quark_cache[100]; | |||
1074 | XrmQuarkList quark_args; | |||
1075 | XrmResourceList* table; | |||
1076 | Cardinal count, ntyped_args = num_typed_args; | |||
1077 | #ifdef XTHREADS1 | |||
1078 | XtAppContext app; | |||
1079 | #endif | |||
1080 | XtCacheRef *Resrc = NULL((void*)0); | |||
1081 | ||||
1082 | if (num_resources == 0) return; | |||
1083 | ||||
1084 | #ifdef XTHREADS1 | |||
1085 | if (w == NULL((void*)0)) app = _XtDefaultAppContext(); | |||
1086 | else app = XtWidgetToApplicationContext(w); | |||
1087 | #endif | |||
1088 | ||||
1089 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); | |||
1090 | /* Get full name, class of application */ | |||
1091 | if (w == NULL((void*)0)) { | |||
1092 | /* hack for R2 compatibility */ | |||
1093 | XtPerDisplay pd = _XtGetPerDisplay(_XtDefaultAppContext()->list[0]); | |||
1094 | names = (XrmName*) XtStackAlloc (2 * sizeof(XrmName), names_s)((2 * sizeof(XrmName)) <= sizeof(names_s) ? (XtPointer)(names_s ) : XtMalloc((unsigned)(2 * sizeof(XrmName)))); | |||
1095 | classes = (XrmClass*) XtStackAlloc (2 * sizeof(XrmClass), classes_s)((2 * sizeof(XrmClass)) <= sizeof(classes_s) ? (XtPointer) (classes_s) : XtMalloc((unsigned)(2 * sizeof(XrmClass)))); | |||
1096 | names[0] = pd->name; | |||
1097 | names[1] = NULLQUARK((XrmQuark) 0); | |||
1098 | classes[0] = pd->class; | |||
1099 | classes[1] = NULLQUARK((XrmQuark) 0); | |||
1100 | } | |||
1101 | else { | |||
1102 | count = CountTreeDepth(w); | |||
1103 | names = (XrmName*) XtStackAlloc(count * sizeof(XrmName), names_s)((count * sizeof(XrmName)) <= sizeof(names_s) ? (XtPointer )(names_s) : XtMalloc((unsigned)(count * sizeof(XrmName)))); | |||
1104 | classes = (XrmClass*) XtStackAlloc(count * sizeof(XrmClass), classes_s)((count * sizeof(XrmClass)) <= sizeof(classes_s) ? (XtPointer )(classes_s) : XtMalloc((unsigned)(count * sizeof(XrmClass))) ); | |||
1105 | if (names == NULL((void*)0) || classes == NULL((void*)0)) _XtAllocError(NULL((void*)0)); | |||
1106 | GetNamesAndClasses(w, names, classes); | |||
1107 | } | |||
1108 | ||||
1109 | /* Compile arg list into quarks */ | |||
1110 | CacheArgs(args, num_args, typed_args, num_typed_args, quark_cache, | |||
1111 | XtNumber(quark_cache)((Cardinal) (sizeof(quark_cache) / sizeof(quark_cache[0]))), &quark_args); | |||
1112 | /* Compile resource list if needed */ | |||
1113 | if (((int) resources->resource_offset) >= 0) { | |||
1114 | XrmCompileResourceListEphem(resources, num_resources); | |||
1115 | } | |||
1116 | table = _XtCreateIndirectionTable(resources,num_resources); | |||
1117 | ||||
1118 | Resrc = GetResources(w, (char*)base, names, classes, table, num_resources, | |||
1119 | quark_args, args, num_args, | |||
1120 | typed_args, &ntyped_args, False0); | |||
1121 | FreeCache(quark_cache, quark_args)if (quark_cache != quark_args) XtFree((char *)quark_args); | |||
1122 | XtFree((char *)table); | |||
1123 | XtFree((char *)Resrc); | |||
1124 | if (w != NULL((void*)0)) { | |||
1125 | XtStackFree((XtPointer)names, names_s){ if (((XtPointer)names) != ((XtPointer)(names_s))) XtFree((XtPointer )names); }; | |||
1126 | XtStackFree((XtPointer)classes, classes_s){ if (((XtPointer)classes) != ((XtPointer)(classes_s))) XtFree ((XtPointer)classes); }; | |||
1127 | } | |||
1128 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); | |||
1129 | } | |||
1130 | ||||
1131 | void XtGetApplicationResources ( | |||
1132 | Widget w, /* Application shell widget */ | |||
1133 | XtPointer base, /* Base address to write to */ | |||
1134 | XtResourceList resources, /* resource list for subobject */ | |||
1135 | Cardinal num_resources, | |||
1136 | ArgList args, /* arg list to override resources */ | |||
1137 | Cardinal num_args) | |||
1138 | { | |||
1139 | _XtGetApplicationResources(w, base, resources, num_resources, args, num_args, NULL((void*)0), 0); | |||
1140 | } | |||
1141 | ||||
1142 | static Boolean initialized = FALSE0; | |||
1143 | ||||
1144 | void _XtResourceListInitialize(void) | |||
1145 | { | |||
1146 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); | |||
1147 | if (initialized) { | |||
1148 | XtWarningMsg("initializationError","xtInitialize",XtCXtToolkitError, | |||
1149 | "Initializing Resource Lists twice", | |||
1150 | (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); | |||
1151 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); | |||
1152 | return; | |||
1153 | } | |||
1154 | initialized = TRUE1; | |||
1155 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); | |||
1156 | ||||
1157 | QBoolean = XrmPermStringToQuark(XtCBoolean((char*)&XtStrings[920])); | |||
1158 | QString = XrmPermStringToQuark(XtCString((char*)&XtStrings[1416])); | |||
1159 | QCallProc = XrmPermStringToQuark(XtRCallProc((char*)&XtStrings[1578])); | |||
1160 | QImmediate = XrmPermStringToQuark(XtRImmediate((char*)&XtStrings[1695])); | |||
1161 | QinitialResourcesPersistent = XrmPermStringToQuark(XtNinitialResourcesPersistent((char*)&XtStrings[264])); | |||
1162 | QInitialResourcesPersistent = XrmPermStringToQuark(XtCInitialResourcesPersistent((char*)&XtStrings[1071])); | |||
1163 | Qtranslations = XrmPermStringToQuark(XtNtranslations((char*)&XtStrings[802])); | |||
1164 | QbaseTranslations = XrmPermStringToQuark("baseTranslations"); | |||
1165 | QTranslations = XrmPermStringToQuark(XtCTranslations((char*)&XtStrings[1484])); | |||
1166 | QTranslationTable = XrmPermStringToQuark(XtRTranslationTable((char*)&XtStrings[1841])); | |||
1167 | Qscreen = XrmPermStringToQuark(XtNscreen((char*)&XtStrings[584])); | |||
1168 | QScreen = XrmPermStringToQuark(XtCScreen((char*)&XtStrings[1273])); | |||
1169 | } |