GetResList.c revision 1477040f
1/* $Xorg: GetResList.c,v 1.4 2001/02/09 02:03:55 xorgcvs Exp $ */
2
3/***********************************************************
4Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
5
6Permission is hereby granted, free of charge, to any person obtaining a
7copy of this software and associated documentation files (the "Software"),
8to deal in the Software without restriction, including without limitation
9the rights to use, copy, modify, merge, publish, distribute, sublicense,
10and/or sell copies of the Software, and to permit persons to whom the
11Software is furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice (including the next
14paragraph) shall be included in all copies or substantial portions of the
15Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23DEALINGS IN THE SOFTWARE.
24
25Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
26
27                        All Rights Reserved
28
29Permission to use, copy, modify, and distribute this software and its
30documentation for any purpose and without fee is hereby granted,
31provided that the above copyright notice appear in all copies and that
32both that copyright notice and this permission notice appear in
33supporting documentation, and that the name of Digital not be
34used in advertising or publicity pertaining to distribution of the
35software without specific, written prior permission.
36
37DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43SOFTWARE.
44
45******************************************************************/
46/* $XFree86: xc/lib/Xt/GetResList.c,v 3.5 2001/08/22 22:52:18 dawes Exp $ */
47
48/*
49
50Copyright 1987, 1988, 1998  The Open Group
51
52Permission to use, copy, modify, distribute, and sell this software and its
53documentation for any purpose is hereby granted without fee, provided that
54the above copyright notice appear in all copies and that both that
55copyright notice and this permission notice appear in supporting
56documentation.
57
58The above copyright notice and this permission notice shall be included in
59all copies or substantial portions of the Software.
60
61THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
64OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
65AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
66CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67
68Except as contained in this notice, the name of The Open Group shall not be
69used in advertising or otherwise to promote the sale, use or other dealings
70in this Software without prior written authorization from The Open Group.
71
72*/
73
74#ifdef HAVE_CONFIG_H
75#include <config.h>
76#endif
77#include "IntrinsicI.h"
78#include "Intrinsic.h"
79
80/*
81 * XtGetResourceList(), XtGetConstraintResourceList()
82 */
83
84#define	TOXRMQUARK(p) ((XrmQuark)(long)(p))	/* avoid LP64 warnings */
85
86void XtGetResourceList(
87	WidgetClass widget_class,
88	XtResourceList *resources,
89	Cardinal *num_resources)
90{
91	int size;
92	register Cardinal i, dest = 0;
93	register XtResourceList *list, dlist;
94
95	LOCK_PROCESS;
96	size = widget_class->core_class.num_resources * sizeof(XtResource);
97	*resources = (XtResourceList) __XtMalloc((unsigned) size);
98
99	if (!widget_class->core_class.class_inited) {
100	    /* Easy case */
101
102	    (void) memmove((char *) *resources,
103			   (char *)widget_class->core_class.resources, size);
104	    *num_resources = widget_class->core_class.num_resources;
105	    UNLOCK_PROCESS;
106	    return;
107	}
108
109	/* Nope, it's the hard case */
110
111	list = (XtResourceList *) widget_class->core_class.resources;
112	dlist = *resources;
113	for (i = 0; i < widget_class->core_class.num_resources; i++) {
114	    if (list[i] != NULL) {
115		dlist[dest].resource_name = (String)
116			XrmQuarkToString(TOXRMQUARK(list[i]->resource_name));
117		dlist[dest].resource_class = (String)
118			XrmQuarkToString(TOXRMQUARK(list[i]->resource_class));
119		dlist[dest].resource_type = (String)
120			XrmQuarkToString(TOXRMQUARK(list[i]->resource_type));
121		dlist[dest].resource_size = list[i]->resource_size;
122		/* trust that resource_offset isn't that big */
123		dlist[dest].resource_offset = (Cardinal)
124			-((int)(list[i]->resource_offset + 1));
125		dlist[dest].default_type = (String)
126			XrmQuarkToString(TOXRMQUARK(list[i]->default_type));
127		dlist[dest].default_addr = list[i]->default_addr;
128		dest++;
129	    }
130	}
131	*num_resources = dest;
132	UNLOCK_PROCESS;
133}
134
135
136static Boolean ClassIsSubclassOf(WidgetClass class, WidgetClass superclass)
137{
138    for (; class != NULL; class = class->core_class.superclass) {
139	if (class == superclass) return True;
140    }
141    return False;
142}
143
144void XtGetConstraintResourceList(
145	WidgetClass widget_class,
146	XtResourceList *resources,
147	Cardinal *num_resources)
148{
149	int size;
150	register Cardinal i, dest = 0;
151	register XtResourceList *list, dlist;
152	ConstraintWidgetClass class = (ConstraintWidgetClass)widget_class;
153
154	LOCK_PROCESS;
155	if (   (class->core_class.class_inited &&
156		!(class->core_class.class_inited & ConstraintClassFlag))
157	    || (!class->core_class.class_inited &&
158		!ClassIsSubclassOf(widget_class, constraintWidgetClass))
159	    || class->constraint_class.num_resources == 0) {
160
161	    *resources = NULL;
162	    *num_resources = 0;
163	    UNLOCK_PROCESS;
164	    return;
165	}
166
167	size = class->constraint_class.num_resources * sizeof(XtResource);
168	*resources = (XtResourceList) __XtMalloc((unsigned) size);
169
170	if (!class->core_class.class_inited) {
171	    /* Easy case */
172
173	    (void) memmove((char *) *resources,
174			   (char *)class->constraint_class.resources, size);
175	    *num_resources = class->constraint_class.num_resources;
176	    UNLOCK_PROCESS;
177	    return;
178	}
179
180	/* Nope, it's the hard case */
181
182	list = (XtResourceList *) class->constraint_class.resources;
183	dlist = *resources;
184	for (i = 0; i < class->constraint_class.num_resources; i++) {
185	    if (list[i] != NULL) {
186		dlist[dest].resource_name = (String)
187			XrmQuarkToString(TOXRMQUARK(list[i]->resource_name));
188		dlist[dest].resource_class = (String)
189			XrmQuarkToString(TOXRMQUARK(list[i]->resource_class));
190		dlist[dest].resource_type = (String)
191			XrmQuarkToString(TOXRMQUARK(list[i]->resource_type));
192		dlist[dest].resource_size = list[i]->resource_size;
193		/* trust that resource_offset isn't that big */
194		dlist[dest].resource_offset = (Cardinal)
195			-((int)(list[i]->resource_offset + 1));
196		dlist[dest].default_type = (String)
197			XrmQuarkToString(TOXRMQUARK(list[i]->default_type));
198		dlist[dest].default_addr = list[i]->default_addr;
199		dest++;
200	    }
201	}
202	*num_resources = dest;
203	UNLOCK_PROCESS;
204}
205