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