Resources.c revision a3bd7f05
1444c061aSmrg/***********************************************************
2249c3046SmrgCopyright (c) 1993, Oracle and/or its affiliates. All rights reserved.
31477040fSmrg
41477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
51477040fSmrgcopy of this software and associated documentation files (the "Software"),
61477040fSmrgto deal in the Software without restriction, including without limitation
71477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
81477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
91477040fSmrgSoftware is furnished to do so, subject to the following conditions:
101477040fSmrg
111477040fSmrgThe above copyright notice and this permission notice (including the next
121477040fSmrgparagraph) shall be included in all copies or substantial portions of the
131477040fSmrgSoftware.
141477040fSmrg
151477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211477040fSmrgDEALINGS IN THE SOFTWARE.
221477040fSmrg
231477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
24444c061aSmrg
25444c061aSmrg                        All Rights Reserved
26444c061aSmrg
271477040fSmrgPermission to use, copy, modify, and distribute this software and its
281477040fSmrgdocumentation for any purpose and without fee is hereby granted,
29444c061aSmrgprovided that the above copyright notice appear in all copies and that
301477040fSmrgboth that copyright notice and this permission notice appear in
311477040fSmrgsupporting documentation, and that the name of Digital not be
32444c061aSmrgused in advertising or publicity pertaining to distribution of the
331477040fSmrgsoftware without specific, written prior permission.
34444c061aSmrg
35444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41444c061aSmrgSOFTWARE.
42444c061aSmrg
43444c061aSmrg******************************************************************/
44444c061aSmrg
45444c061aSmrg/*
46444c061aSmrg
47444c061aSmrgCopyright 1987, 1988, 1994, 1998  The Open Group
48444c061aSmrg
49444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
50444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
51444c061aSmrgthe above copyright notice appear in all copies and that both that
52444c061aSmrgcopyright notice and this permission notice appear in supporting
53444c061aSmrgdocumentation.
54444c061aSmrg
55444c061aSmrgThe above copyright notice and this permission notice shall be included in
56444c061aSmrgall copies or substantial portions of the Software.
57444c061aSmrg
58444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
61444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
62444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
63444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64444c061aSmrg
65444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
66444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
67444c061aSmrgin this Software without prior written authorization from The Open Group.
68444c061aSmrg
69444c061aSmrg*/
70444c061aSmrg
71444c061aSmrg#ifdef HAVE_CONFIG_H
72444c061aSmrg#include <config.h>
73444c061aSmrg#endif
74444c061aSmrg#include "IntrinsicI.h"
75444c061aSmrg#include "VarargsI.h"
76444c061aSmrg#include "Shell.h"
77444c061aSmrg#include "ShellP.h"
78444c061aSmrg#include "StringDefs.h"
79444c061aSmrg#include <stdio.h>
80444c061aSmrg
81a3bd7f05Smrgstatic XrmClass QBoolean, QString, QCallProc, QImmediate;
82444c061aSmrgstatic XrmName QinitialResourcesPersistent, QInitialResourcesPersistent;
83444c061aSmrgstatic XrmClass QTranslations, QTranslationTable;
84444c061aSmrgstatic XrmName Qtranslations, QbaseTranslations;
85444c061aSmrgstatic XrmName Qscreen;
86444c061aSmrgstatic XrmClass QScreen;
87444c061aSmrg
88a3bd7f05Smrgvoid
89a3bd7f05Smrg_XtCopyFromParent(Widget widget, int offset, XrmValue *value)
90444c061aSmrg{
91444c061aSmrg    if (widget->core.parent == NULL) {
92a3bd7f05Smrg        XtAppWarningMsg(XtWidgetToApplicationContext(widget),
93a3bd7f05Smrg                        "invalidParent", "xtCopyFromParent", XtCXtToolkitError,
94a3bd7f05Smrg                        "CopyFromParent must have non-NULL parent", NULL, NULL);
95444c061aSmrg        value->addr = NULL;
96444c061aSmrg        return;
97444c061aSmrg    }
98a3bd7f05Smrg    value->addr = (XPointer) (((char *) widget->core.parent) + offset);
99a3bd7f05Smrg}                               /* _XtCopyFromParent */
100444c061aSmrg
101a3bd7f05Smrgvoid
102a3bd7f05Smrg_XtCopyFromArg(XtArgVal src, char *dst, register unsigned int size)
103444c061aSmrg{
104444c061aSmrg    if (size > sizeof(XtArgVal))
105a3bd7f05Smrg        (void) memmove((char *) dst, (char *) src, (size_t) size);
106444c061aSmrg    else {
107a3bd7f05Smrg        union {
108a3bd7f05Smrg            long longval;
109444c061aSmrg#ifdef LONG64
110a3bd7f05Smrg            int intval;
111444c061aSmrg#endif
112a3bd7f05Smrg            short shortval;
113a3bd7f05Smrg            char charval;
114a3bd7f05Smrg            char *charptr;
115a3bd7f05Smrg            XtPointer ptr;
116a3bd7f05Smrg        } u;
117a3bd7f05Smrg        char *p = (char *) &u;
118a3bd7f05Smrg
119a3bd7f05Smrg        if (size == sizeof(long))
120a3bd7f05Smrg            u.longval = (long) src;
121444c061aSmrg#ifdef LONG64
122a3bd7f05Smrg        else if (size == sizeof(int))
123a3bd7f05Smrg            u.intval = (int) src;
124444c061aSmrg#endif
125a3bd7f05Smrg        else if (size == sizeof(short))
126a3bd7f05Smrg            u.shortval = (short) src;
127a3bd7f05Smrg        else if (size == sizeof(char))
128a3bd7f05Smrg            u.charval = (char) src;
129a3bd7f05Smrg        else if (size == sizeof(XtPointer))
130a3bd7f05Smrg            u.ptr = (XtPointer) src;
131a3bd7f05Smrg        else if (size == sizeof(char *))
132a3bd7f05Smrg            u.charptr = (char *) src;
133a3bd7f05Smrg        else
134a3bd7f05Smrg            p = (char *) &src;
135a3bd7f05Smrg
136a3bd7f05Smrg        (void) memmove(dst, p, (size_t) size);
137444c061aSmrg    }
138a3bd7f05Smrg}                               /* _XtCopyFromArg */
139444c061aSmrg
140a3bd7f05Smrgvoid
141a3bd7f05Smrg_XtCopyToArg(char *src, XtArgVal *dst, register unsigned int size)
142444c061aSmrg{
143444c061aSmrg    if (!*dst) {
144444c061aSmrg#ifdef GETVALUES_BUG
145a3bd7f05Smrg        /* old GetValues semantics (storing directly into arglists) are bad,
146a3bd7f05Smrg         * but preserve for compatibility as long as arglist contains NULL.
147a3bd7f05Smrg         */
148a3bd7f05Smrg        union {
149a3bd7f05Smrg            long longval;
150444c061aSmrg#ifdef LONG64
151a3bd7f05Smrg            int intval;
152444c061aSmrg#endif
153a3bd7f05Smrg            short shortval;
154a3bd7f05Smrg            char charval;
155a3bd7f05Smrg            char *charptr;
156a3bd7f05Smrg            XtPointer ptr;
157a3bd7f05Smrg        } u;
158a3bd7f05Smrg
159a3bd7f05Smrg        if (size <= sizeof(XtArgVal)) {
160a3bd7f05Smrg            (void) memmove((char *) &u, (char *) src, (size_t) size);
161a3bd7f05Smrg            if (size == sizeof(long))
162a3bd7f05Smrg                *dst = (XtArgVal) u.longval;
163444c061aSmrg#ifdef LONG64
164a3bd7f05Smrg            else if (size == sizeof(int))
165a3bd7f05Smrg                *dst = (XtArgVal) u.intval;
166444c061aSmrg#endif
167a3bd7f05Smrg            else if (size == sizeof(short))
168a3bd7f05Smrg                *dst = (XtArgVal) u.shortval;
169a3bd7f05Smrg            else if (size == sizeof(char))
170a3bd7f05Smrg                *dst = (XtArgVal) u.charval;
171a3bd7f05Smrg            else if (size == sizeof(char *))
172a3bd7f05Smrg                *dst = (XtArgVal) u.charptr;
173a3bd7f05Smrg            else if (size == sizeof(XtPointer))
174a3bd7f05Smrg                *dst = (XtArgVal) u.ptr;
175a3bd7f05Smrg            else
176a3bd7f05Smrg                (void) memmove((char *) dst, (char *) src, (size_t) size);
177a3bd7f05Smrg        }
178a3bd7f05Smrg        else
179a3bd7f05Smrg            (void) memmove((char *) dst, (char *) src, (size_t) size);
180444c061aSmrg#else
181a3bd7f05Smrg        XtErrorMsg("invalidGetValues", "xtGetValues", XtCXtToolkitError,
182a3bd7f05Smrg                   "NULL ArgVal in XtGetValues", NULL, NULL);
183444c061aSmrg#endif
184444c061aSmrg    }
185444c061aSmrg    else {
186a3bd7f05Smrg        /* proper GetValues semantics: argval is pointer to destination */
187a3bd7f05Smrg        (void) memmove((char *) *dst, (char *) src, (size_t) size);
188444c061aSmrg    }
189a3bd7f05Smrg}                               /* _XtCopyToArg */
190444c061aSmrg
191a3bd7f05Smrgstatic void
192a3bd7f05SmrgCopyToArg(char *src, XtArgVal *dst, register unsigned int size)
193444c061aSmrg{
194444c061aSmrg    if (!*dst) {
195a3bd7f05Smrg        /* old GetValues semantics (storing directly into arglists) are bad,
196a3bd7f05Smrg         * but preserve for compatibility as long as arglist contains NULL.
197a3bd7f05Smrg         */
198a3bd7f05Smrg        union {
199a3bd7f05Smrg            long longval;
200444c061aSmrg#ifdef LONG64
201a3bd7f05Smrg            int intval;
202444c061aSmrg#endif
203a3bd7f05Smrg            short shortval;
204a3bd7f05Smrg            char charval;
205a3bd7f05Smrg            char *charptr;
206a3bd7f05Smrg            XtPointer ptr;
207a3bd7f05Smrg        } u;
208a3bd7f05Smrg
209a3bd7f05Smrg        if (size <= sizeof(XtArgVal)) {
210a3bd7f05Smrg            (void) memmove((char *) &u, (char *) src, (size_t) size);
211a3bd7f05Smrg            if (size == sizeof(long))
212a3bd7f05Smrg                *dst = (XtArgVal) u.longval;
213444c061aSmrg#ifdef LONG64
214a3bd7f05Smrg            else if (size == sizeof(int))
215a3bd7f05Smrg                *dst = (XtArgVal) u.intval;
216444c061aSmrg#endif
217a3bd7f05Smrg            else if (size == sizeof(short))
218a3bd7f05Smrg                *dst = (XtArgVal) u.shortval;
219a3bd7f05Smrg            else if (size == sizeof(char))
220a3bd7f05Smrg                *dst = (XtArgVal) u.charval;
221a3bd7f05Smrg            else if (size == sizeof(char *))
222a3bd7f05Smrg                *dst = (XtArgVal) u.charptr;
223a3bd7f05Smrg            else if (size == sizeof(XtPointer))
224a3bd7f05Smrg                *dst = (XtArgVal) u.ptr;
225a3bd7f05Smrg            else
226a3bd7f05Smrg                (void) memmove((char *) dst, (char *) src, (size_t) size);
227a3bd7f05Smrg        }
228a3bd7f05Smrg        else
229a3bd7f05Smrg            (void) memmove((char *) dst, (char *) src, (size_t) size);
230444c061aSmrg    }
231444c061aSmrg    else {
232a3bd7f05Smrg        /* proper GetValues semantics: argval is pointer to destination */
233a3bd7f05Smrg        (void) memmove((char *) *dst, (char *) src, (size_t) size);
234444c061aSmrg    }
235a3bd7f05Smrg}                               /* CopyToArg */
236444c061aSmrg
237a3bd7f05Smrgstatic Cardinal
238a3bd7f05SmrgCountTreeDepth(Widget w)
239444c061aSmrg{
240444c061aSmrg    Cardinal count;
241444c061aSmrg
2429e7bcd65Smrg    for (count = 1; w != NULL; w = (Widget) w->core.parent)
243a3bd7f05Smrg        count++;
244444c061aSmrg
245444c061aSmrg    return count;
246444c061aSmrg}
247444c061aSmrg
248a3bd7f05Smrgstatic void
249a3bd7f05SmrgGetNamesAndClasses(register Widget w,
250a3bd7f05Smrg                   register XrmNameList names,
251a3bd7f05Smrg                   register XrmClassList classes)
252444c061aSmrg{
253444c061aSmrg    register Cardinal length, j;
254444c061aSmrg    register XrmQuark t;
255444c061aSmrg    WidgetClass class;
256444c061aSmrg
257444c061aSmrg    /* Return null-terminated quark arrays, with length the number of
258444c061aSmrg       quarks (not including NULL) */
259444c061aSmrg
260444c061aSmrg    LOCK_PROCESS;
261444c061aSmrg    for (length = 0; w != NULL; w = (Widget) w->core.parent) {
262a3bd7f05Smrg        names[length] = w->core.xrm_name;
263a3bd7f05Smrg        class = XtClass(w);
264a3bd7f05Smrg        /* KLUDGE KLUDGE KLUDGE KLUDGE */
265a3bd7f05Smrg        if (w->core.parent == NULL && XtIsApplicationShell(w)) {
266a3bd7f05Smrg            classes[length] =
267a3bd7f05Smrg                ((ApplicationShellWidget) w)->application.xrm_class;
268a3bd7f05Smrg        }
269a3bd7f05Smrg        else
270a3bd7f05Smrg            classes[length] = class->core_class.xrm_class;
271a3bd7f05Smrg        length++;
272a3bd7f05Smrg    }
273444c061aSmrg    UNLOCK_PROCESS;
274444c061aSmrg    /* They're in backwards order, flop them around */
275a3bd7f05Smrg    for (j = 0; j < length / 2; j++) {
276a3bd7f05Smrg        t = names[j];
277a3bd7f05Smrg        names[j] = names[length - j - 1];
278a3bd7f05Smrg        names[length - j - 1] = t;
279444c061aSmrg        t = classes[j];
280a3bd7f05Smrg        classes[j] = classes[length - j - 1];
281a3bd7f05Smrg        classes[length - j - 1] = t;
282444c061aSmrg    }
283444c061aSmrg    names[length] = NULLQUARK;
284444c061aSmrg    classes[length] = NULLQUARK;
285a3bd7f05Smrg}                               /* GetNamesAndClasses */
286444c061aSmrg
287a3bd7f05Smrg/* Spiffy fast compiled form of resource list.                          */
288a3bd7f05Smrg/* XtResourceLists are compiled in-place into XrmResourceLists          */
289a3bd7f05Smrg/* All atoms are replaced by quarks, and offsets are -offset-1 to       */
290a3bd7f05Smrg/* indicate that this list has been compiled already                    */
291444c061aSmrg
292a3bd7f05Smrgvoid
293a3bd7f05Smrg_XtCompileResourceList(register XtResourceList resources,
294a3bd7f05Smrg                       Cardinal num_resources)
295444c061aSmrg{
296444c061aSmrg    register Cardinal count;
297444c061aSmrg
298444c061aSmrg#define xrmres  ((XrmResourceList) resources)
299444c061aSmrg#define PSToQ   XrmPermStringToQuark
300444c061aSmrg
301444c061aSmrg    for (count = 0; count < num_resources; resources++, count++) {
302a3bd7f05Smrg        xrmres->xrm_name = PSToQ(resources->resource_name);
303a3bd7f05Smrg        xrmres->xrm_class = PSToQ(resources->resource_class);
304a3bd7f05Smrg        xrmres->xrm_type = PSToQ(resources->resource_type);
305a3bd7f05Smrg        xrmres->xrm_offset = (int)
306a3bd7f05Smrg            (-(int) resources->resource_offset - 1);
307a3bd7f05Smrg        xrmres->xrm_default_type = PSToQ(resources->default_type);
308444c061aSmrg    }
309444c061aSmrg#undef PSToQ
310444c061aSmrg#undef xrmres
311a3bd7f05Smrg}                               /* _XtCompileResourceList */
312444c061aSmrg
313444c061aSmrg/* Like _XtCompileResourceList, but strings are not permanent */
314a3bd7f05Smrgstatic void
315a3bd7f05SmrgXrmCompileResourceListEphem(register XtResourceList resources,
316a3bd7f05Smrg                            Cardinal num_resources)
317444c061aSmrg{
318444c061aSmrg    register Cardinal count;
319444c061aSmrg
320444c061aSmrg#define xrmres  ((XrmResourceList) resources)
321444c061aSmrg
322444c061aSmrg    for (count = 0; count < num_resources; resources++, count++) {
323a3bd7f05Smrg        xrmres->xrm_name = StringToName(resources->resource_name);
324a3bd7f05Smrg        xrmres->xrm_class = StringToClass(resources->resource_class);
325a3bd7f05Smrg        xrmres->xrm_type = StringToQuark(resources->resource_type);
326a3bd7f05Smrg        xrmres->xrm_offset = (int)
327a3bd7f05Smrg            (-(int) resources->resource_offset - 1);
328a3bd7f05Smrg        xrmres->xrm_default_type = StringToQuark(resources->default_type);
329444c061aSmrg    }
330444c061aSmrg#undef xrmres
331a3bd7f05Smrg}                               /* XrmCompileResourceListEphem */
332444c061aSmrg
333a3bd7f05Smrgstatic void
334a3bd7f05SmrgBadSize(Cardinal size, XrmQuark name)
335444c061aSmrg{
336444c061aSmrg    String params[2];
337444c061aSmrg    Cardinal num_params = 2;
338444c061aSmrg
339a3bd7f05Smrg    params[0] = (String) (long) size;
340444c061aSmrg    params[1] = XrmQuarkToString(name);
341444c061aSmrg    XtWarningMsg("invalidSizeOverride", "xtDependencies", XtCXtToolkitError,
342a3bd7f05Smrg                 "Representation size %d must match superclass's to override %s",
343a3bd7f05Smrg                 params, &num_params);
344a3bd7f05Smrg}                               /* BadType */
345444c061aSmrg
346444c061aSmrg/*
347444c061aSmrg * Create a new resource list, with the class resources following the
348444c061aSmrg * superclass's resources.  If a resource in the class list overrides
349444c061aSmrg * a superclass resource, then just replace the superclass entry in place.
350444c061aSmrg *
351444c061aSmrg * At the same time, add a level of indirection to the XtResourceList to
352444c061aSmrg * create and XrmResourceList.
353444c061aSmrg */
354a3bd7f05Smrgvoid
355a3bd7f05Smrg_XtDependencies(XtResourceList *class_resp,    /* VAR */
356a3bd7f05Smrg                Cardinal *class_num_resp,      /* VAR */
357a3bd7f05Smrg                XrmResourceList *super_res,
358a3bd7f05Smrg                Cardinal super_num_res,
359a3bd7f05Smrg                Cardinal super_widget_size)
360444c061aSmrg{
361444c061aSmrg    register XrmResourceList *new_res;
362a3bd7f05Smrg    Cardinal new_num_res;
363a3bd7f05Smrg    XrmResourceList class_res = (XrmResourceList) *class_resp;
364a3bd7f05Smrg    Cardinal class_num_res = *class_num_resp;
365a3bd7f05Smrg    register Cardinal i, j;
366a3bd7f05Smrg    Cardinal new_next;
367444c061aSmrg
368444c061aSmrg    if (class_num_res == 0) {
369a3bd7f05Smrg        /* Just point to superclass resource list */
370a3bd7f05Smrg        *class_resp = (XtResourceList) super_res;
371a3bd7f05Smrg        *class_num_resp = super_num_res;
372a3bd7f05Smrg        return;
373444c061aSmrg    }
374444c061aSmrg
375444c061aSmrg    /* Allocate and initialize new_res with superclass resource pointers */
376444c061aSmrg    new_num_res = super_num_res + class_num_res;
377a3bd7f05Smrg    new_res = (XrmResourceList *)
378a3bd7f05Smrg        __XtMalloc((Cardinal) (new_num_res * sizeof(XrmResourceList)));
379444c061aSmrg    if (super_num_res > 0)
380a3bd7f05Smrg        XtMemmove(new_res, super_res, super_num_res * sizeof(XrmResourceList));
3819e7bcd65Smrg
382444c061aSmrg    /* Put pointers to class resource entries into new_res */
383444c061aSmrg    new_next = super_num_res;
384444c061aSmrg    for (i = 0; i < class_num_res; i++) {
385a3bd7f05Smrg        if ((Cardinal) (-class_res[i].xrm_offset - 1) < super_widget_size) {
386a3bd7f05Smrg            /* Probably an override of superclass resources--look for overlap */
387a3bd7f05Smrg            for (j = 0; j < super_num_res; j++) {
388a3bd7f05Smrg                if (class_res[i].xrm_offset == new_res[j]->xrm_offset) {
389a3bd7f05Smrg                    /* Spec is silent on what fields subclass can override.
390a3bd7f05Smrg                     * The only two of real concern are type & size.
391a3bd7f05Smrg                     * Although allowing type to be over-ridden introduces
392a3bd7f05Smrg                     * the possibility of errors, it's at present the only
393a3bd7f05Smrg                     * reasonable way to allow a subclass to force a private
394a3bd7f05Smrg                     * converter to be invoked for a subset of fields.
395a3bd7f05Smrg                     */
396a3bd7f05Smrg                    /* We do insist that size be identical to superclass */
397a3bd7f05Smrg                    if (class_res[i].xrm_size != new_res[j]->xrm_size) {
398a3bd7f05Smrg                        BadSize(class_res[i].xrm_size,
399a3bd7f05Smrg                                (XrmQuark) class_res[i].xrm_name);
400a3bd7f05Smrg                        class_res[i].xrm_size = new_res[j]->xrm_size;
401a3bd7f05Smrg                    }
402a3bd7f05Smrg                    new_res[j] = &(class_res[i]);
403a3bd7f05Smrg                    new_num_res--;
404a3bd7f05Smrg                    goto NextResource;
405a3bd7f05Smrg                }
406a3bd7f05Smrg            }                   /* for j */
407a3bd7f05Smrg        }
408a3bd7f05Smrg        /* Not an overlap, add an entry to new_res */
409a3bd7f05Smrg        new_res[new_next++] = &(class_res[i]);
410a3bd7f05Smrg NextResource:;
411a3bd7f05Smrg    }                           /* for i */
412444c061aSmrg
413444c061aSmrg    /* Okay, stuff new resources back into class record */
414444c061aSmrg    *class_resp = (XtResourceList) new_res;
415444c061aSmrg    *class_num_resp = new_num_res;
416a3bd7f05Smrg}                               /* _XtDependencies */
417444c061aSmrg
418a3bd7f05Smrgvoid
419a3bd7f05Smrg_XtResourceDependencies(WidgetClass wc)
420444c061aSmrg{
421444c061aSmrg    WidgetClass sc;
422444c061aSmrg
423444c061aSmrg    sc = wc->core_class.superclass;
424444c061aSmrg    if (sc == NULL) {
425a3bd7f05Smrg        _XtDependencies(&(wc->core_class.resources),
426a3bd7f05Smrg                        &(wc->core_class.num_resources),
427a3bd7f05Smrg                        (XrmResourceList *) NULL, (unsigned) 0, (unsigned) 0);
428a3bd7f05Smrg    }
429a3bd7f05Smrg    else {
430a3bd7f05Smrg        _XtDependencies(&(wc->core_class.resources),
431a3bd7f05Smrg                        &(wc->core_class.num_resources),
432a3bd7f05Smrg                        (XrmResourceList *) sc->core_class.resources,
433a3bd7f05Smrg                        sc->core_class.num_resources,
434a3bd7f05Smrg                        sc->core_class.widget_size);
435444c061aSmrg    }
436a3bd7f05Smrg}                               /* _XtResourceDependencies */
437444c061aSmrg
438a3bd7f05Smrgvoid
439a3bd7f05Smrg_XtConstraintResDependencies(ConstraintWidgetClass wc)
440444c061aSmrg{
441444c061aSmrg    if (wc == (ConstraintWidgetClass) constraintWidgetClass) {
442a3bd7f05Smrg        _XtDependencies(&(wc->constraint_class.resources),
443a3bd7f05Smrg                        &(wc->constraint_class.num_resources),
444a3bd7f05Smrg                        (XrmResourceList *) NULL, (unsigned) 0, (unsigned) 0);
445444c061aSmrg    }
446a3bd7f05Smrg    else {
447a3bd7f05Smrg        ConstraintWidgetClass sc;
448a3bd7f05Smrg
449a3bd7f05Smrg        sc = (ConstraintWidgetClass) wc->core_class.superclass;
450a3bd7f05Smrg        _XtDependencies(&(wc->constraint_class.resources),
451a3bd7f05Smrg                        &(wc->constraint_class.num_resources),
452a3bd7f05Smrg                        (XrmResourceList *) sc->constraint_class.resources,
453a3bd7f05Smrg                        sc->constraint_class.num_resources,
454a3bd7f05Smrg                        sc->constraint_class.constraint_size);
455a3bd7f05Smrg    }
456a3bd7f05Smrg}                               /* _XtConstraintResDependencies */
4579e7bcd65Smrg
458a3bd7f05SmrgXrmResourceList *
459a3bd7f05Smrg_XtCreateIndirectionTable(XtResourceList resources, Cardinal num_resources)
460444c061aSmrg{
461444c061aSmrg    register Cardinal idx;
462a3bd7f05Smrg    XrmResourceList *table;
463444c061aSmrg
464a3bd7f05Smrg    table = (XrmResourceList *)
465a3bd7f05Smrg        __XtMalloc((Cardinal) (num_resources * sizeof(XrmResourceList)));
466444c061aSmrg    for (idx = 0; idx < num_resources; idx++)
467a3bd7f05Smrg        table[idx] = (XrmResourceList) (&(resources[idx]));
468444c061aSmrg    return table;
469444c061aSmrg}
470444c061aSmrg
471a3bd7f05Smrgstatic XtCacheRef *
472a3bd7f05SmrgGetResources(Widget widget,             /* Widget resources are associated with */
473a3bd7f05Smrg             char *base,                /* Base address of memory to write to */
474a3bd7f05Smrg             XrmNameList names,         /* Full inheritance name of widget */
475a3bd7f05Smrg             XrmClassList classes,      /* Full inheritance class of widget     */
476a3bd7f05Smrg             XrmResourceList *table,    /* The list of resources required.      */
477a3bd7f05Smrg             unsigned num_resources,    /* number of items in resource list     */
478a3bd7f05Smrg             XrmQuarkList quark_args,   /* Arg names quarkified                 */
479a3bd7f05Smrg             ArgList args,              /* ArgList to override resources */
480a3bd7f05Smrg             unsigned num_args,         /* number of items in arg list  */
481a3bd7f05Smrg             XtTypedArgList typed_args, /* Typed arg list to override resources */
482a3bd7f05Smrg             Cardinal *pNumTypedArgs,   /* number of items in typed arg list    */
483a3bd7f05Smrg             Boolean tm_hack)           /* do baseTranslations                  */
484a3bd7f05Smrg{
485444c061aSmrg/*
486444c061aSmrg * assert: *pNumTypedArgs == 0 if num_args > 0
487444c061aSmrg * assert: num_args == 0 if *pNumTypedArgs > 0
488444c061aSmrg */
489444c061aSmrg#define SEARCHLISTLEN 100
490444c061aSmrg#define MAXRESOURCES  400
491444c061aSmrg
492a3bd7f05Smrg    XrmValue value;
493a3bd7f05Smrg    XrmQuark rawType;
494a3bd7f05Smrg    XrmValue convValue;
495a3bd7f05Smrg    XrmHashTable stackSearchList[SEARCHLISTLEN];
496a3bd7f05Smrg    XrmHashTable *searchList = stackSearchList;
497a3bd7f05Smrg    unsigned int searchListSize = SEARCHLISTLEN;
498a3bd7f05Smrg    Boolean found[MAXRESOURCES];
499a3bd7f05Smrg    int typed[MAXRESOURCES];
500a3bd7f05Smrg    XtCacheRef cache_ref[MAXRESOURCES];
501a3bd7f05Smrg    XtCacheRef *cache_ptr, *cache_base;
502a3bd7f05Smrg    Boolean persistent_resources = True;
503a3bd7f05Smrg    Boolean found_persistence = False;
504a3bd7f05Smrg    int num_typed_args = (int) *pNumTypedArgs;
505a3bd7f05Smrg    XrmDatabase db;
506a3bd7f05Smrg    Boolean do_tm_hack = False;
507444c061aSmrg
508444c061aSmrg    if ((args == NULL) && (num_args != 0)) {
509a3bd7f05Smrg        XtAppWarningMsg(XtWidgetToApplicationContext(widget),
510a3bd7f05Smrg                        "invalidArgCount", "getResources", XtCXtToolkitError,
511a3bd7f05Smrg                        "argument count > 0 on NULL argument list", NULL, NULL);
512a3bd7f05Smrg        num_args = 0;
513444c061aSmrg    }
514444c061aSmrg    if (num_resources == 0) {
515a3bd7f05Smrg        return NULL;
516a3bd7f05Smrg    }
517a3bd7f05Smrg    else if (num_resources >= MAXRESOURCES) {
518a3bd7f05Smrg        XtAppWarningMsg(XtWidgetToApplicationContext(widget),
519a3bd7f05Smrg                        "invalidResourceCount", "getResources",
520a3bd7f05Smrg                        XtCXtToolkitError, "too many resources", NULL, NULL);
521a3bd7f05Smrg        return NULL;
522a3bd7f05Smrg    }
523a3bd7f05Smrg    else if (table == NULL) {
524a3bd7f05Smrg        XtAppWarningMsg(XtWidgetToApplicationContext(widget),
525a3bd7f05Smrg                        "invalidResourceCount", "getResources",
526a3bd7f05Smrg                        XtCXtToolkitError,
527a3bd7f05Smrg                        "resource count > 0 on NULL resource list", NULL, NULL);
528a3bd7f05Smrg        return NULL;
529444c061aSmrg    }
530444c061aSmrg
531444c061aSmrg    /* Mark each resource as not found on arg list */
5320568f49bSmrg    memset((void *) found, 0, (size_t) (num_resources * sizeof(Boolean)));
5330568f49bSmrg    memset((void *) typed, 0, (size_t) (num_resources * sizeof(int)));
534444c061aSmrg
535444c061aSmrg    /* Copy the args into the resources, mark each as found */
536444c061aSmrg    {
537a3bd7f05Smrg        register ArgList arg;
538a3bd7f05Smrg        register XtTypedArgList typed_arg;
539a3bd7f05Smrg        register XrmName argName;
540a3bd7f05Smrg        register Cardinal j;
541a3bd7f05Smrg        register int i;
542a3bd7f05Smrg        register XrmResourceList rx;
543a3bd7f05Smrg        register XrmResourceList *res;
544a3bd7f05Smrg
545a3bd7f05Smrg        for (arg = args, i = 0; (Cardinal) i < num_args; i++, arg++) {
546a3bd7f05Smrg            argName = quark_args[i];
547a3bd7f05Smrg            if (argName == QinitialResourcesPersistent) {
548a3bd7f05Smrg                persistent_resources = (Boolean) arg->value;
549a3bd7f05Smrg                found_persistence = True;
550a3bd7f05Smrg                continue;
551a3bd7f05Smrg            }
552a3bd7f05Smrg            for (j = 0, res = table; j < num_resources; j++, res++) {
553a3bd7f05Smrg                rx = *res;
554a3bd7f05Smrg                if (argName == rx->xrm_name) {
555a3bd7f05Smrg                    _XtCopyFromArg(arg->value,
556a3bd7f05Smrg                                   base - rx->xrm_offset - 1, rx->xrm_size);
557a3bd7f05Smrg                    found[j] = TRUE;
558a3bd7f05Smrg                    break;
559a3bd7f05Smrg                }
560a3bd7f05Smrg            }
561a3bd7f05Smrg        }
562a3bd7f05Smrg        for (typed_arg = typed_args, i = 0; i < num_typed_args;
563a3bd7f05Smrg             i++, typed_arg++) {
564a3bd7f05Smrg            register XrmRepresentation argType;
565a3bd7f05Smrg
566a3bd7f05Smrg            argName = quark_args[i];
567a3bd7f05Smrg            argType = (typed_arg->type == NULL) ? NULLQUARK
568a3bd7f05Smrg                : XrmStringToRepresentation(typed_arg->type);
569a3bd7f05Smrg            if (argName == QinitialResourcesPersistent) {
570a3bd7f05Smrg                persistent_resources = (Boolean) typed_arg->value;
571a3bd7f05Smrg                found_persistence = True;
572a3bd7f05Smrg                break;
573a3bd7f05Smrg            }
574a3bd7f05Smrg            for (j = 0, res = table; j < num_resources; j++, res++) {
575a3bd7f05Smrg                rx = *res;
576a3bd7f05Smrg                if (argName == rx->xrm_name) {
577a3bd7f05Smrg                    if (argType != NULLQUARK && argType != rx->xrm_type) {
578a3bd7f05Smrg                        typed[j] = i + 1;
579a3bd7f05Smrg                    }
580a3bd7f05Smrg                    else {
581a3bd7f05Smrg                        _XtCopyFromArg(typed_arg->value,
582a3bd7f05Smrg                                       base - rx->xrm_offset - 1, rx->xrm_size);
583a3bd7f05Smrg                    }
584a3bd7f05Smrg                    found[j] = TRUE;
585a3bd7f05Smrg                    break;
586a3bd7f05Smrg                }
587a3bd7f05Smrg            }
588a3bd7f05Smrg        }
589444c061aSmrg    }
590444c061aSmrg
591444c061aSmrg    /* Ask resource manager for a list of database levels that we can
592444c061aSmrg       do a single-level search on each resource */
593444c061aSmrg
594444c061aSmrg    db = XtScreenDatabase(XtScreenOfObject(widget));
595444c061aSmrg    while (!XrmQGetSearchList(db, names, classes,
596a3bd7f05Smrg                              searchList, (int) searchListSize)) {
597a3bd7f05Smrg        if (searchList == stackSearchList)
598a3bd7f05Smrg            searchList = NULL;
599a3bd7f05Smrg        searchList = (XrmHashTable *) XtRealloc((char *) searchList,
600a3bd7f05Smrg                                                (Cardinal) (sizeof(XrmHashTable)
601a3bd7f05Smrg                                                            * (searchListSize *=
602a3bd7f05Smrg                                                               2)));
603444c061aSmrg    }
6049e7bcd65Smrg
605444c061aSmrg    if (persistent_resources)
606a3bd7f05Smrg        cache_base = NULL;
607444c061aSmrg    else
608a3bd7f05Smrg        cache_base = cache_ref;
609444c061aSmrg    /* geez, this is an ugly mess */
610444c061aSmrg    if (XtIsShell(widget)) {
611a3bd7f05Smrg        register XrmResourceList *res;
612a3bd7f05Smrg        register Cardinal j;
613a3bd7f05Smrg        Screen *oldscreen = widget->core.screen;
614a3bd7f05Smrg
615a3bd7f05Smrg        /* look up screen resource first, since real rdb depends on it */
616a3bd7f05Smrg        for (res = table, j = 0; j < num_resources; j++, res++) {
617a3bd7f05Smrg            if ((*res)->xrm_name != Qscreen)
618a3bd7f05Smrg                continue;
619a3bd7f05Smrg            if (typed[j]) {
620a3bd7f05Smrg                register XtTypedArg *arg = typed_args + typed[j] - 1;
621a3bd7f05Smrg                XrmQuark from_type;
622a3bd7f05Smrg                XrmValue from_val, to_val;
623a3bd7f05Smrg
624a3bd7f05Smrg                from_type = StringToQuark(arg->type);
625a3bd7f05Smrg                from_val.size = (Cardinal) arg->size;
626a3bd7f05Smrg                if ((from_type == QString) ||
627a3bd7f05Smrg                    ((unsigned) arg->size > sizeof(XtArgVal)))
628a3bd7f05Smrg                    from_val.addr = (XPointer) arg->value;
629a3bd7f05Smrg                else
630a3bd7f05Smrg                    from_val.addr = (XPointer) &arg->value;
631a3bd7f05Smrg                to_val.size = sizeof(Screen *);
632a3bd7f05Smrg                to_val.addr = (XPointer) &widget->core.screen;
633a3bd7f05Smrg                found[j] = _XtConvert(widget, from_type, &from_val,
634a3bd7f05Smrg                                      QScreen, &to_val, cache_base);
635a3bd7f05Smrg                if (cache_base && *cache_base)
636a3bd7f05Smrg                    cache_base++;
637a3bd7f05Smrg            }
638a3bd7f05Smrg            if (!found[j]) {
639a3bd7f05Smrg                if (XrmQGetSearchResource(searchList, Qscreen, QScreen,
640a3bd7f05Smrg                                          &rawType, &value)) {
641a3bd7f05Smrg                    if (rawType != QScreen) {
642a3bd7f05Smrg                        convValue.size = sizeof(Screen *);
643a3bd7f05Smrg                        convValue.addr = (XPointer) &widget->core.screen;
644a3bd7f05Smrg                        (void) _XtConvert(widget, rawType, &value,
645a3bd7f05Smrg                                          QScreen, &convValue, cache_base);
646a3bd7f05Smrg                        if (cache_base && *cache_base)
647a3bd7f05Smrg                            cache_base++;
648a3bd7f05Smrg                    }
649a3bd7f05Smrg                    else {
650a3bd7f05Smrg                        widget->core.screen = *((Screen **) value.addr);
651a3bd7f05Smrg                    }
652a3bd7f05Smrg                }
653a3bd7f05Smrg            }
654a3bd7f05Smrg            break;
655a3bd7f05Smrg        }
656a3bd7f05Smrg        /* now get the database to use for the rest of the resources */
657a3bd7f05Smrg        if (widget->core.screen != oldscreen) {
658a3bd7f05Smrg            db = XtScreenDatabase(widget->core.screen);
659a3bd7f05Smrg            while (!XrmQGetSearchList(db, names, classes,
660a3bd7f05Smrg                                      searchList, (int) searchListSize)) {
661a3bd7f05Smrg                if (searchList == stackSearchList)
662a3bd7f05Smrg                    searchList = NULL;
663a3bd7f05Smrg                searchList = (XrmHashTable *) XtRealloc((char *) searchList,
664a3bd7f05Smrg                                                        (Cardinal) (sizeof
665a3bd7f05Smrg                                                                    (XrmHashTable)
666a3bd7f05Smrg                                                                    *
667a3bd7f05Smrg                                                                    (searchListSize
668a3bd7f05Smrg                                                                     *= 2)));
669a3bd7f05Smrg            }
670a3bd7f05Smrg        }
671444c061aSmrg    }
672444c061aSmrg
673444c061aSmrg    /* go to the resource manager for those resources not found yet */
674444c061aSmrg    /* if it's not in the resource database use the default value   */
675444c061aSmrg
676444c061aSmrg    {
677a3bd7f05Smrg        register XrmResourceList rx;
678a3bd7f05Smrg        register XrmResourceList *res;
679a3bd7f05Smrg        register Cardinal j;
680a3bd7f05Smrg        register XrmRepresentation xrm_type;
681a3bd7f05Smrg        register XrmRepresentation xrm_default_type;
682a3bd7f05Smrg        char char_val;
683a3bd7f05Smrg        short short_val;
684a3bd7f05Smrg        int int_val;
685a3bd7f05Smrg        long long_val;
686a3bd7f05Smrg        char *char_ptr;
687a3bd7f05Smrg
688a3bd7f05Smrg        if (!found_persistence) {
689a3bd7f05Smrg            if (XrmQGetSearchResource(searchList, QinitialResourcesPersistent,
690a3bd7f05Smrg                                      QInitialResourcesPersistent, &rawType,
691a3bd7f05Smrg                                      &value)) {
692a3bd7f05Smrg                if (rawType != QBoolean) {
693a3bd7f05Smrg                    convValue.size = sizeof(Boolean);
694a3bd7f05Smrg                    convValue.addr = (XPointer) &persistent_resources;
695a3bd7f05Smrg                    (void) _XtConvert(widget, rawType, &value, QBoolean,
696a3bd7f05Smrg                                      &convValue, NULL);
697a3bd7f05Smrg                }
698a3bd7f05Smrg                else
699a3bd7f05Smrg                    persistent_resources = *(Boolean *) value.addr;
700a3bd7f05Smrg            }
701a3bd7f05Smrg        }
702a3bd7f05Smrg        if (persistent_resources)
703a3bd7f05Smrg            cache_ptr = NULL;
704a3bd7f05Smrg        else if (cache_base)
705a3bd7f05Smrg            cache_ptr = cache_base;
706a3bd7f05Smrg        else
707a3bd7f05Smrg            cache_ptr = cache_ref;
708a3bd7f05Smrg
709a3bd7f05Smrg        for (res = table, j = 0; j < num_resources; j++, res++) {
710a3bd7f05Smrg            rx = *res;
711a3bd7f05Smrg            xrm_type = (XrmRepresentation) rx->xrm_type;
712a3bd7f05Smrg            if (typed[j]) {
713a3bd7f05Smrg                register XtTypedArg *arg = typed_args + typed[j] - 1;
714a3bd7f05Smrg
715a3bd7f05Smrg                /*
7169e7bcd65Smrg                 * This resource value has been specified as a typed arg and
717a3bd7f05Smrg                 * has to be converted. Typed arg conversions are done here
718a3bd7f05Smrg                 * to correctly interpose them with normal resource conversions.
719444c061aSmrg                 */
720a3bd7f05Smrg                XrmQuark from_type;
721a3bd7f05Smrg                XrmValue from_val, to_val;
722a3bd7f05Smrg                Boolean converted;
723a3bd7f05Smrg
724a3bd7f05Smrg                from_type = StringToQuark(arg->type);
725a3bd7f05Smrg                from_val.size = (Cardinal) arg->size;
726a3bd7f05Smrg                if ((from_type == QString) ||
727a3bd7f05Smrg                    ((unsigned) arg->size > sizeof(XtArgVal)))
728a3bd7f05Smrg                    from_val.addr = (XPointer) arg->value;
729a3bd7f05Smrg                else
730a3bd7f05Smrg                    from_val.addr = (XPointer) &arg->value;
731a3bd7f05Smrg                to_val.size = rx->xrm_size;
732a3bd7f05Smrg                to_val.addr = base - rx->xrm_offset - 1;
733a3bd7f05Smrg                converted = _XtConvert(widget, from_type, &from_val,
734a3bd7f05Smrg                                       xrm_type, &to_val, cache_ptr);
735a3bd7f05Smrg                if (converted) {
736a3bd7f05Smrg
737a3bd7f05Smrg                    /* Copy the converted value back into the typed argument.
738a3bd7f05Smrg                     * normally the data should be <= sizeof(XtArgVal) and
739a3bd7f05Smrg                     * is stored directly into the 'value' field .... BUT
740a3bd7f05Smrg                     * if the resource size is greater than sizeof(XtArgVal)
741a3bd7f05Smrg                     * then we dynamically alloc a block of store to hold the
742a3bd7f05Smrg                     * data and zap a copy in there !!! .... freeing it later
743a3bd7f05Smrg                     * the size field in the typed arg is negated to indicate
744a3bd7f05Smrg                     * that the store pointed to by the value field is
745a3bd7f05Smrg                     * dynamic .......
746a3bd7f05Smrg                     * "freeing" happens in the case of _XtCreate after the
747a3bd7f05Smrg                     * CallInitialize ..... other clients of GetResources
748a3bd7f05Smrg                     * using typed args should be aware of the need to free
749a3bd7f05Smrg                     * this store .....
750a3bd7f05Smrg                     */
751a3bd7f05Smrg
752a3bd7f05Smrg                    if (rx->xrm_size > sizeof(XtArgVal)) {
753a3bd7f05Smrg                        arg->value =
754a3bd7f05Smrg                            (XtArgVal) (void *) __XtMalloc(rx->xrm_size);
755a3bd7f05Smrg                        arg->size = -(arg->size);
756a3bd7f05Smrg                    }
757a3bd7f05Smrg                    else {      /* will fit - copy directly into value field */
758a3bd7f05Smrg                        arg->value = (XtArgVal) NULL;
759a3bd7f05Smrg                    }
760a3bd7f05Smrg                    CopyToArg((char *) (base - rx->xrm_offset - 1),
761a3bd7f05Smrg                              &arg->value, rx->xrm_size);
762a3bd7f05Smrg
763a3bd7f05Smrg                }
764a3bd7f05Smrg                else {
765a3bd7f05Smrg                    /* Conversion failed. Get default value. */
766a3bd7f05Smrg                    found[j] = False;
767a3bd7f05Smrg                }
768a3bd7f05Smrg
769a3bd7f05Smrg                if (cache_ptr && *cache_ptr)
770a3bd7f05Smrg                    cache_ptr++;
771a3bd7f05Smrg            }
772a3bd7f05Smrg
773a3bd7f05Smrg            if (!found[j]) {
774a3bd7f05Smrg                Boolean already_copied = False;
775a3bd7f05Smrg                Boolean have_value = False;
776a3bd7f05Smrg
777a3bd7f05Smrg                if (XrmQGetSearchResource(searchList,
778a3bd7f05Smrg                                          (XrmName) rx->xrm_name,
779a3bd7f05Smrg                                          (XrmClass) rx->xrm_class, &rawType,
780a3bd7f05Smrg                                          &value)) {
781a3bd7f05Smrg                    if (rawType != xrm_type) {
782a3bd7f05Smrg                        convValue.size = rx->xrm_size;
783a3bd7f05Smrg                        convValue.addr = (XPointer) (base - rx->xrm_offset - 1);
784a3bd7f05Smrg                        already_copied = have_value =
785a3bd7f05Smrg                            _XtConvert(widget, rawType, &value,
786a3bd7f05Smrg                                       xrm_type, &convValue, cache_ptr);
787a3bd7f05Smrg                        if (cache_ptr && *cache_ptr)
788a3bd7f05Smrg                            cache_ptr++;
789a3bd7f05Smrg                    }
790a3bd7f05Smrg                    else
791a3bd7f05Smrg                        have_value = True;
792a3bd7f05Smrg                    if (have_value && rx->xrm_name == Qtranslations)
793a3bd7f05Smrg                        do_tm_hack = True;
794a3bd7f05Smrg                }
795a3bd7f05Smrg                LOCK_PROCESS;
796a3bd7f05Smrg                if (!have_value && ((rx->xrm_default_type == QImmediate)
797a3bd7f05Smrg                                    || (rx->xrm_default_type == xrm_type)
798a3bd7f05Smrg                                    || (rx->xrm_default_addr != NULL))) {
799a3bd7f05Smrg                    /* Convert default value to proper type */
800a3bd7f05Smrg                    xrm_default_type = (XrmRepresentation) rx->xrm_default_type;
801a3bd7f05Smrg                    if (xrm_default_type == QCallProc) {
802a3bd7f05Smrg                        (*(XtResourceDefaultProc) (rx->xrm_default_addr))
803a3bd7f05Smrg                            (widget, -(rx->xrm_offset + 1), &value);
804a3bd7f05Smrg
805a3bd7f05Smrg                    }
806a3bd7f05Smrg                    else if (xrm_default_type == QImmediate) {
807a3bd7f05Smrg                        /* XtRImmediate == XtRString for type XtRString */
808a3bd7f05Smrg                        if (xrm_type == QString) {
809a3bd7f05Smrg                            value.addr = rx->xrm_default_addr;
810a3bd7f05Smrg                        }
811a3bd7f05Smrg                        else if (rx->xrm_size == sizeof(int)) {
812a3bd7f05Smrg                            int_val = (int) (long) rx->xrm_default_addr;
813a3bd7f05Smrg                            value.addr = (XPointer) &int_val;
814a3bd7f05Smrg                        }
815a3bd7f05Smrg                        else if (rx->xrm_size == sizeof(short)) {
816a3bd7f05Smrg                            short_val = (short) (long) rx->xrm_default_addr;
817a3bd7f05Smrg                            value.addr = (XPointer) &short_val;
818a3bd7f05Smrg                        }
819a3bd7f05Smrg                        else if (rx->xrm_size == sizeof(char)) {
820a3bd7f05Smrg                            char_val = (char) (long) rx->xrm_default_addr;
821a3bd7f05Smrg                            value.addr = (XPointer) &char_val;
822a3bd7f05Smrg                        }
823a3bd7f05Smrg                        else if (rx->xrm_size == sizeof(long)) {
824a3bd7f05Smrg                            long_val = (long) rx->xrm_default_addr;
825a3bd7f05Smrg                            value.addr = (XPointer) &long_val;
826a3bd7f05Smrg                        }
827a3bd7f05Smrg                        else if (rx->xrm_size == sizeof(char *)) {
828a3bd7f05Smrg                            char_ptr = (char *) rx->xrm_default_addr;
829a3bd7f05Smrg                            value.addr = (XPointer) &char_ptr;
830a3bd7f05Smrg                        }
831a3bd7f05Smrg                        else {
832a3bd7f05Smrg                            value.addr = (XPointer) &(rx->xrm_default_addr);
833a3bd7f05Smrg                        }
834a3bd7f05Smrg                    }
835a3bd7f05Smrg                    else if (xrm_default_type == xrm_type) {
836a3bd7f05Smrg                        value.addr = rx->xrm_default_addr;
837a3bd7f05Smrg                    }
838a3bd7f05Smrg                    else {
839a3bd7f05Smrg                        value.addr = rx->xrm_default_addr;
840a3bd7f05Smrg                        if (xrm_default_type == QString) {
841a3bd7f05Smrg                            value.size =
842a3bd7f05Smrg                                (unsigned) strlen((char *) value.addr) + 1;
843a3bd7f05Smrg                        }
844a3bd7f05Smrg                        else {
845a3bd7f05Smrg                            value.size = sizeof(XtPointer);
846a3bd7f05Smrg                        }
847a3bd7f05Smrg                        convValue.size = rx->xrm_size;
848a3bd7f05Smrg                        convValue.addr = (XPointer) (base - rx->xrm_offset - 1);
849a3bd7f05Smrg                        already_copied =
850a3bd7f05Smrg                            _XtConvert(widget, xrm_default_type, &value,
851a3bd7f05Smrg                                       xrm_type, &convValue, cache_ptr);
852a3bd7f05Smrg                        if (!already_copied)
853a3bd7f05Smrg                            value.addr = NULL;
854a3bd7f05Smrg                        if (cache_ptr && *cache_ptr)
855a3bd7f05Smrg                            cache_ptr++;
856a3bd7f05Smrg                    }
857a3bd7f05Smrg                }
858a3bd7f05Smrg                if (!already_copied) {
859a3bd7f05Smrg                    if (xrm_type == QString) {
860a3bd7f05Smrg                        *((String *) (base - rx->xrm_offset - 1)) = value.addr;
861a3bd7f05Smrg                    }
862a3bd7f05Smrg                    else {
863a3bd7f05Smrg                        if (value.addr != NULL) {
864a3bd7f05Smrg                            XtMemmove(base - rx->xrm_offset - 1,
865a3bd7f05Smrg                                      value.addr, rx->xrm_size);
866a3bd7f05Smrg                        }
867a3bd7f05Smrg                        else {
868a3bd7f05Smrg                            /* didn't get value, initialize to NULL... */
869a3bd7f05Smrg                            XtBZero(base - rx->xrm_offset - 1, rx->xrm_size);
870a3bd7f05Smrg                        }
871a3bd7f05Smrg                    }
872a3bd7f05Smrg                }
873a3bd7f05Smrg                UNLOCK_PROCESS;
874a3bd7f05Smrg            }
875a3bd7f05Smrg        }
876a3bd7f05Smrg        for (res = table, j = 0; j < num_resources; j++, res++) {
877a3bd7f05Smrg            if (!found[j] && typed[j]) {
878a3bd7f05Smrg                /*
879a3bd7f05Smrg                 * This resource value was specified as a typed arg.
880a3bd7f05Smrg                 * However, the default value is being used here since
881a3bd7f05Smrg                 * type type conversion failed, so we compress the list.
882a3bd7f05Smrg                 */
883a3bd7f05Smrg                register XtTypedArg *arg = typed_args + typed[j] - 1;
884a3bd7f05Smrg                register int i;
885a3bd7f05Smrg
886a3bd7f05Smrg                for (i = num_typed_args - typed[j]; i > 0; i--, arg++) {
887a3bd7f05Smrg                    *arg = *(arg + 1);
888a3bd7f05Smrg                }
889a3bd7f05Smrg                num_typed_args--;
890a3bd7f05Smrg            }
891a3bd7f05Smrg        }
892a3bd7f05Smrg        if (tm_hack)
893a3bd7f05Smrg            widget->core.tm.current_state = NULL;
894a3bd7f05Smrg        if (tm_hack &&
895a3bd7f05Smrg            (!widget->core.tm.translations ||
896a3bd7f05Smrg             (do_tm_hack &&
897a3bd7f05Smrg              widget->core.tm.translations->operation != XtTableReplace)) &&
898a3bd7f05Smrg            XrmQGetSearchResource(searchList, QbaseTranslations,
899a3bd7f05Smrg                                  QTranslations, &rawType, &value)) {
900a3bd7f05Smrg            if (rawType != QTranslationTable) {
901a3bd7f05Smrg                convValue.size = sizeof(XtTranslations);
902a3bd7f05Smrg                convValue.addr = (XPointer) &widget->core.tm.current_state;
903a3bd7f05Smrg                (void) _XtConvert(widget, rawType, &value,
904a3bd7f05Smrg                                  QTranslationTable, &convValue, cache_ptr);
905a3bd7f05Smrg                if (cache_ptr && *cache_ptr)
906a3bd7f05Smrg                    cache_ptr++;
907a3bd7f05Smrg            }
908a3bd7f05Smrg            else {
909a3bd7f05Smrg                /* value.addr can be NULL see: !already_copied */
910a3bd7f05Smrg                if (value.addr)
911a3bd7f05Smrg                    *((XtTranslations *) &widget->core.tm.current_state) =
912a3bd7f05Smrg                        *((XtTranslations *) value.addr);
913a3bd7f05Smrg            }
914a3bd7f05Smrg        }
915444c061aSmrg    }
916a3bd7f05Smrg    if ((Cardinal) num_typed_args != *pNumTypedArgs)
917a3bd7f05Smrg        *pNumTypedArgs = (Cardinal) num_typed_args;
918a3bd7f05Smrg    if (searchList != stackSearchList)
919a3bd7f05Smrg        XtFree((char *) searchList);
920444c061aSmrg    if (!cache_ptr)
921a3bd7f05Smrg        cache_ptr = cache_base;
922444c061aSmrg    if (cache_ptr && cache_ptr != cache_ref) {
923a3bd7f05Smrg        int cache_ref_size = (int) (cache_ptr - cache_ref);
924a3bd7f05Smrg        XtCacheRef *refs = (XtCacheRef *)
925a3bd7f05Smrg            __XtMalloc((Cardinal)
926a3bd7f05Smrg                       (sizeof(XtCacheRef) * (size_t) (cache_ref_size + 1)));
927a3bd7f05Smrg
928a3bd7f05Smrg        (void) memmove(refs, cache_ref,
929a3bd7f05Smrg                       sizeof(XtCacheRef) * (size_t) cache_ref_size);
930a3bd7f05Smrg        refs[cache_ref_size] = NULL;
931a3bd7f05Smrg        return refs;
932444c061aSmrg    }
933a3bd7f05Smrg    return (XtCacheRef *) NULL;
934444c061aSmrg}
935444c061aSmrg
936a3bd7f05Smrgstatic void
937a3bd7f05SmrgCacheArgs(ArgList args,
938a3bd7f05Smrg          Cardinal num_args,
939a3bd7f05Smrg          XtTypedArgList typed_args,
940a3bd7f05Smrg          Cardinal num_typed_args,
941a3bd7f05Smrg          XrmQuarkList quark_cache,
942a3bd7f05Smrg          Cardinal num_quarks,
943a3bd7f05Smrg          XrmQuarkList *pQuarks)        /* RETURN */
944a3bd7f05Smrg{
945a3bd7f05Smrg    register XrmQuarkList quarks;
946a3bd7f05Smrg    register Cardinal i;
947a3bd7f05Smrg    register Cardinal count;
948444c061aSmrg
949444c061aSmrg    count = (args != NULL) ? num_args : num_typed_args;
950444c061aSmrg
951444c061aSmrg    if (num_quarks < count) {
952a3bd7f05Smrg        quarks =
953a3bd7f05Smrg            (XrmQuarkList) __XtMalloc((Cardinal) (count * sizeof(XrmQuark)));
954a3bd7f05Smrg    }
955a3bd7f05Smrg    else {
956a3bd7f05Smrg        quarks = quark_cache;
957444c061aSmrg    }
958444c061aSmrg    *pQuarks = quarks;
959444c061aSmrg
960444c061aSmrg    if (args != NULL) {
961a3bd7f05Smrg        for (i = count; i; i--)
962a3bd7f05Smrg            *quarks++ = StringToQuark((args++)->name);
963444c061aSmrg    }
964444c061aSmrg    else {
965a3bd7f05Smrg        for (i = count; i; i--)
966a3bd7f05Smrg            *quarks++ = StringToQuark((typed_args++)->name);
967444c061aSmrg    }
968444c061aSmrg}
969444c061aSmrg
970444c061aSmrg#define FreeCache(cache, pointer) \
971a3bd7f05Smrg          if (cache != pointer) XtFree((char *)pointer)
972a3bd7f05Smrg
973a3bd7f05SmrgXtCacheRef *
974a3bd7f05Smrg_XtGetResources(register Widget w,
975a3bd7f05Smrg                ArgList args,
976a3bd7f05Smrg                Cardinal num_args,
977a3bd7f05Smrg                XtTypedArgList typed_args,
978a3bd7f05Smrg                Cardinal *num_typed_args)
979444c061aSmrg{
980a3bd7f05Smrg    XrmName *names, names_s[50];
981a3bd7f05Smrg    XrmClass *classes, classes_s[50];
982a3bd7f05Smrg    XrmQuark quark_cache[100];
983a3bd7f05Smrg    XrmQuarkList quark_args;
984a3bd7f05Smrg    WidgetClass wc;
985a3bd7f05Smrg    XtCacheRef *cache_refs = NULL;
986a3bd7f05Smrg    Cardinal count;
987444c061aSmrg
988444c061aSmrg    wc = XtClass(w);
989444c061aSmrg
990444c061aSmrg    count = CountTreeDepth(w);
991a3bd7f05Smrg    names = (XrmName *) XtStackAlloc(count * sizeof(XrmName), names_s);
992a3bd7f05Smrg    classes = (XrmClass *) XtStackAlloc(count * sizeof(XrmClass), classes_s);
9930568f49bSmrg    if (names == NULL || classes == NULL) {
994a3bd7f05Smrg        _XtAllocError(NULL);
995a3bd7f05Smrg    }
996a3bd7f05Smrg    else {
997a3bd7f05Smrg
998a3bd7f05Smrg        /* Get names, classes for widget and ancestors */
999a3bd7f05Smrg        GetNamesAndClasses(w, names, classes);
1000a3bd7f05Smrg
1001a3bd7f05Smrg        /* Compile arg list into quarks */
1002a3bd7f05Smrg        CacheArgs(args, num_args, typed_args, *num_typed_args, quark_cache,
1003a3bd7f05Smrg                  XtNumber(quark_cache), &quark_args);
1004a3bd7f05Smrg
1005a3bd7f05Smrg        /* Get normal resources */
1006a3bd7f05Smrg        LOCK_PROCESS;
1007a3bd7f05Smrg        cache_refs = GetResources(w, (char *) w, names, classes,
1008a3bd7f05Smrg                                  (XrmResourceList *) wc->core_class.resources,
1009a3bd7f05Smrg                                  wc->core_class.num_resources, quark_args,
1010a3bd7f05Smrg                                  args, num_args, typed_args, num_typed_args,
1011a3bd7f05Smrg                                  XtIsWidget(w));
1012a3bd7f05Smrg
1013a3bd7f05Smrg        if (w->core.constraints != NULL) {
1014a3bd7f05Smrg            ConstraintWidgetClass cwc;
1015a3bd7f05Smrg            XtCacheRef *cache_refs_core;
1016a3bd7f05Smrg
1017a3bd7f05Smrg            cwc = (ConstraintWidgetClass) XtClass(w->core.parent);
1018a3bd7f05Smrg            cache_refs_core =
1019a3bd7f05Smrg                GetResources(w, (char *) w->core.constraints, names, classes,
1020a3bd7f05Smrg                             (XrmResourceList *) cwc->constraint_class.
1021a3bd7f05Smrg                             resources, cwc->constraint_class.num_resources,
1022a3bd7f05Smrg                             quark_args, args, num_args, typed_args,
1023a3bd7f05Smrg                             num_typed_args, False);
1024a3bd7f05Smrg            XtFree((char *) cache_refs_core);
1025a3bd7f05Smrg        }
1026a3bd7f05Smrg        FreeCache(quark_cache, quark_args);
1027a3bd7f05Smrg        UNLOCK_PROCESS;
1028a3bd7f05Smrg        XtStackFree((XtPointer) names, names_s);
1029a3bd7f05Smrg        XtStackFree((XtPointer) classes, classes_s);
1030444c061aSmrg    }
1031444c061aSmrg    return cache_refs;
1032a3bd7f05Smrg}                               /* _XtGetResources */
1033a3bd7f05Smrg
1034a3bd7f05Smrgvoid
1035a3bd7f05Smrg_XtGetSubresources(Widget w,                    /* Widget "parent" of subobject */
1036a3bd7f05Smrg                   XtPointer base,              /* Base address to write to */
1037a3bd7f05Smrg                   const char *name,            /* name of subobject        */
1038a3bd7f05Smrg                   const char *class,           /* class of subobject       */
1039a3bd7f05Smrg                   XtResourceList resources,    /* resource list for subobject    */
1040a3bd7f05Smrg                   Cardinal num_resources,
1041a3bd7f05Smrg                   ArgList args,                /* arg list to override resources */
1042a3bd7f05Smrg                   Cardinal num_args,
1043a3bd7f05Smrg                   XtTypedArgList typed_args,
1044a3bd7f05Smrg                   Cardinal num_typed_args)
1045444c061aSmrg{
1046a3bd7f05Smrg    XrmName *names, names_s[50];
1047a3bd7f05Smrg    XrmClass *classes, classes_s[50];
1048a3bd7f05Smrg    XrmQuark quark_cache[100];
1049a3bd7f05Smrg    XrmQuarkList quark_args;
1050a3bd7f05Smrg    XrmResourceList *table;
1051a3bd7f05Smrg    Cardinal count, ntyped_args = num_typed_args;
1052a3bd7f05Smrg    XtCacheRef *Resrc = NULL;
1053a3bd7f05Smrg
1054444c061aSmrg    WIDGET_TO_APPCON(w);
1055444c061aSmrg
1056a3bd7f05Smrg    if (num_resources == 0)
1057a3bd7f05Smrg        return;
1058444c061aSmrg
1059444c061aSmrg    LOCK_APP(app);
1060444c061aSmrg    count = CountTreeDepth(w);
1061a3bd7f05Smrg    count++;                    /* make sure there's enough room for name and class */
1062a3bd7f05Smrg    names = (XrmName *) XtStackAlloc(count * sizeof(XrmName), names_s);
1063a3bd7f05Smrg    classes = (XrmClass *) XtStackAlloc(count * sizeof(XrmClass), classes_s);
10640568f49bSmrg    if (names == NULL || classes == NULL) {
1065a3bd7f05Smrg        _XtAllocError(NULL);
1066a3bd7f05Smrg    }
1067a3bd7f05Smrg    else {
1068a3bd7f05Smrg        /* Get full name, class of subobject */
1069a3bd7f05Smrg        GetNamesAndClasses(w, names, classes);
1070a3bd7f05Smrg        count -= 2;
1071a3bd7f05Smrg        names[count] = StringToName(name);
1072a3bd7f05Smrg        classes[count] = StringToClass(class);
1073a3bd7f05Smrg        count++;
1074a3bd7f05Smrg        names[count] = NULLQUARK;
1075a3bd7f05Smrg        classes[count] = NULLQUARK;
1076a3bd7f05Smrg
1077a3bd7f05Smrg        /* Compile arg list into quarks */
1078a3bd7f05Smrg        CacheArgs(args, num_args, typed_args, num_typed_args,
1079a3bd7f05Smrg                  quark_cache, XtNumber(quark_cache), &quark_args);
1080a3bd7f05Smrg
1081a3bd7f05Smrg        /* Compile resource list if needed */
1082a3bd7f05Smrg        if (((int) resources->resource_offset) >= 0) {
1083a3bd7f05Smrg            XrmCompileResourceListEphem(resources, num_resources);
1084a3bd7f05Smrg        }
1085a3bd7f05Smrg        table = _XtCreateIndirectionTable(resources, num_resources);
1086a3bd7f05Smrg        Resrc =
1087a3bd7f05Smrg            GetResources(w, (char *) base, names, classes, table, num_resources,
1088a3bd7f05Smrg                         quark_args, args, num_args, typed_args, &ntyped_args,
1089a3bd7f05Smrg                         False);
1090a3bd7f05Smrg        FreeCache(quark_cache, quark_args);
1091a3bd7f05Smrg        XtFree((char *) table);
1092a3bd7f05Smrg        XtFree((char *) Resrc);
1093a3bd7f05Smrg        XtStackFree((XtPointer) names, names_s);
1094a3bd7f05Smrg        XtStackFree((XtPointer) classes, classes_s);
1095a3bd7f05Smrg        UNLOCK_APP(app);
1096444c061aSmrg    }
1097444c061aSmrg}
1098444c061aSmrg
1099a3bd7f05Smrgvoid
1100a3bd7f05SmrgXtGetSubresources(Widget w,                     /* Widget "parent" of subobject */
1101a3bd7f05Smrg                  XtPointer base,               /* Base address to write to */
1102a3bd7f05Smrg                  _Xconst char *name,           /* name of subobject        */
1103a3bd7f05Smrg                  _Xconst char *class,          /* class of subobject       */
1104a3bd7f05Smrg                  XtResourceList resources,     /* resource list for subobject    */
1105a3bd7f05Smrg                  Cardinal num_resources,
1106a3bd7f05Smrg                  ArgList args,                 /* arg list to override resources */
1107a3bd7f05Smrg                  Cardinal num_args)
1108444c061aSmrg{
1109a3bd7f05Smrg    _XtGetSubresources(w, base, name, class, resources, num_resources, args,
1110a3bd7f05Smrg                       num_args, NULL, 0);
1111444c061aSmrg}
1112444c061aSmrg
1113a3bd7f05Smrgvoid
1114a3bd7f05Smrg_XtGetApplicationResources(Widget w,            /* Application shell widget */
1115a3bd7f05Smrg                           XtPointer base,      /* Base address to write to       */
1116a3bd7f05Smrg                           XtResourceList resources,    /* resource list for subobject    */
1117a3bd7f05Smrg                           Cardinal num_resources,
1118a3bd7f05Smrg                           ArgList args,        /* arg list to override resources */
1119a3bd7f05Smrg                           Cardinal num_args,
1120a3bd7f05Smrg                           XtTypedArgList typed_args,
1121a3bd7f05Smrg                           Cardinal num_typed_args)
1122444c061aSmrg{
1123a3bd7f05Smrg    XrmName *names, names_s[50];
1124a3bd7f05Smrg    XrmClass *classes, classes_s[50];
1125a3bd7f05Smrg    XrmQuark quark_cache[100];
1126a3bd7f05Smrg    XrmQuarkList quark_args;
1127a3bd7f05Smrg    XrmResourceList *table;
1128a3bd7f05Smrg    Cardinal ntyped_args = num_typed_args;
1129a3bd7f05Smrg
1130444c061aSmrg#ifdef XTHREADS
1131a3bd7f05Smrg    XtAppContext app;
1132444c061aSmrg#endif
1133a3bd7f05Smrg    XtCacheRef *Resrc = NULL;
1134444c061aSmrg
1135a3bd7f05Smrg    if (num_resources == 0)
1136a3bd7f05Smrg        return;
1137444c061aSmrg
1138444c061aSmrg#ifdef XTHREADS
1139a3bd7f05Smrg    if (w == NULL)
1140a3bd7f05Smrg        app = _XtDefaultAppContext();
1141a3bd7f05Smrg    else
1142a3bd7f05Smrg        app = XtWidgetToApplicationContext(w);
1143444c061aSmrg#endif
1144444c061aSmrg
1145444c061aSmrg    LOCK_APP(app);
1146444c061aSmrg    /* Get full name, class of application */
1147444c061aSmrg    if (w == NULL) {
1148a3bd7f05Smrg        /* hack for R2 compatibility */
1149a3bd7f05Smrg        XtPerDisplay pd = _XtGetPerDisplay(_XtDefaultAppContext()->list[0]);
1150a3bd7f05Smrg
1151a3bd7f05Smrg        names = (XrmName *) XtStackAlloc(2 * sizeof(XrmName), names_s);
1152a3bd7f05Smrg        classes = (XrmClass *) XtStackAlloc(2 * sizeof(XrmClass), classes_s);
1153a3bd7f05Smrg        if (names == NULL || classes == NULL) {
1154a3bd7f05Smrg            _XtAllocError(NULL);
1155a3bd7f05Smrg        }
1156a3bd7f05Smrg        else {
1157a3bd7f05Smrg            names[0] = pd->name;
1158a3bd7f05Smrg            names[1] = NULLQUARK;
1159a3bd7f05Smrg            classes[0] = pd->class;
1160a3bd7f05Smrg            classes[1] = NULLQUARK;
1161a3bd7f05Smrg        }
1162444c061aSmrg    }
1163444c061aSmrg    else {
1164a3bd7f05Smrg        Cardinal count = CountTreeDepth(w);
1165a3bd7f05Smrg
1166a3bd7f05Smrg        names = (XrmName *) XtStackAlloc(count * sizeof(XrmName), names_s);
1167a3bd7f05Smrg        classes =
1168a3bd7f05Smrg            (XrmClass *) XtStackAlloc(count * sizeof(XrmClass), classes_s);
1169a3bd7f05Smrg        if (names == NULL || classes == NULL) {
1170a3bd7f05Smrg            _XtAllocError(NULL);
1171a3bd7f05Smrg        }
1172a3bd7f05Smrg        else {
1173a3bd7f05Smrg            GetNamesAndClasses(w, names, classes);
1174a3bd7f05Smrg        }
1175444c061aSmrg    }
1176444c061aSmrg
1177444c061aSmrg    /* Compile arg list into quarks */
1178a3bd7f05Smrg    CacheArgs(args, num_args, typed_args, num_typed_args, quark_cache,
1179a3bd7f05Smrg              XtNumber(quark_cache), &quark_args);
1180444c061aSmrg    /* Compile resource list if needed */
1181444c061aSmrg    if (((int) resources->resource_offset) >= 0) {
1182a3bd7f05Smrg        XrmCompileResourceListEphem(resources, num_resources);
1183444c061aSmrg    }
1184a3bd7f05Smrg    table = _XtCreateIndirectionTable(resources, num_resources);
1185444c061aSmrg
1186a3bd7f05Smrg    Resrc = GetResources(w, (char *) base, names, classes, table, num_resources,
1187a3bd7f05Smrg                         quark_args, args, num_args,
1188a3bd7f05Smrg                         typed_args, &ntyped_args, False);
1189444c061aSmrg    FreeCache(quark_cache, quark_args);
1190a3bd7f05Smrg    XtFree((char *) table);
1191a3bd7f05Smrg    XtFree((char *) Resrc);
1192444c061aSmrg    if (w != NULL) {
1193a3bd7f05Smrg        XtStackFree((XtPointer) names, names_s);
1194a3bd7f05Smrg        XtStackFree((XtPointer) classes, classes_s);
1195444c061aSmrg    }
1196444c061aSmrg    UNLOCK_APP(app);
1197444c061aSmrg}
1198444c061aSmrg
1199a3bd7f05Smrgvoid
1200a3bd7f05SmrgXtGetApplicationResources(Widget w,     /* Application shell widget       */
1201a3bd7f05Smrg                          XtPointer base,       /* Base address to write to       */
1202a3bd7f05Smrg                          XtResourceList resources,     /* resource list for subobject    */
1203a3bd7f05Smrg                          Cardinal num_resources,
1204a3bd7f05Smrg                          ArgList args, /* arg list to override resources */
1205a3bd7f05Smrg                          Cardinal num_args)
1206444c061aSmrg{
1207a3bd7f05Smrg    _XtGetApplicationResources(w, base, resources, num_resources, args,
1208a3bd7f05Smrg                               num_args, NULL, 0);
1209444c061aSmrg}
1210444c061aSmrg
1211444c061aSmrgstatic Boolean initialized = FALSE;
1212444c061aSmrg
1213a3bd7f05Smrgvoid
1214a3bd7f05Smrg_XtResourceListInitialize(void)
1215444c061aSmrg{
1216444c061aSmrg    LOCK_PROCESS;
1217444c061aSmrg    if (initialized) {
1218a3bd7f05Smrg        XtWarningMsg("initializationError", "xtInitialize", XtCXtToolkitError,
1219a3bd7f05Smrg                     "Initializing Resource Lists twice", NULL, NULL);
1220a3bd7f05Smrg        UNLOCK_PROCESS;
1221a3bd7f05Smrg        return;
1222444c061aSmrg    }
1223444c061aSmrg    initialized = TRUE;
1224444c061aSmrg    UNLOCK_PROCESS;
1225444c061aSmrg
1226444c061aSmrg    QBoolean = XrmPermStringToQuark(XtCBoolean);
1227444c061aSmrg    QString = XrmPermStringToQuark(XtCString);
1228444c061aSmrg    QCallProc = XrmPermStringToQuark(XtRCallProc);
1229444c061aSmrg    QImmediate = XrmPermStringToQuark(XtRImmediate);
1230a3bd7f05Smrg    QinitialResourcesPersistent =
1231a3bd7f05Smrg        XrmPermStringToQuark(XtNinitialResourcesPersistent);
1232a3bd7f05Smrg    QInitialResourcesPersistent =
1233a3bd7f05Smrg        XrmPermStringToQuark(XtCInitialResourcesPersistent);
1234444c061aSmrg    Qtranslations = XrmPermStringToQuark(XtNtranslations);
1235444c061aSmrg    QbaseTranslations = XrmPermStringToQuark("baseTranslations");
1236444c061aSmrg    QTranslations = XrmPermStringToQuark(XtCTranslations);
1237444c061aSmrg    QTranslationTable = XrmPermStringToQuark(XtRTranslationTable);
1238444c061aSmrg    Qscreen = XrmPermStringToQuark(XtNscreen);
1239444c061aSmrg    QScreen = XrmPermStringToQuark(XtCScreen);
1240444c061aSmrg}
1241