GetResList.c revision 1477040f
1444c061aSmrg/* $Xorg: GetResList.c,v 1.4 2001/02/09 02:03:55 xorgcvs Exp $ */ 2444c061aSmrg 3444c061aSmrg/*********************************************************** 41477040fSmrgCopyright 1993 Sun Microsystems, Inc. All rights reserved. 51477040fSmrg 61477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a 71477040fSmrgcopy of this software and associated documentation files (the "Software"), 81477040fSmrgto deal in the Software without restriction, including without limitation 91477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense, 101477040fSmrgand/or sell copies of the Software, and to permit persons to whom the 111477040fSmrgSoftware is furnished to do so, subject to the following conditions: 121477040fSmrg 131477040fSmrgThe above copyright notice and this permission notice (including the next 141477040fSmrgparagraph) shall be included in all copies or substantial portions of the 151477040fSmrgSoftware. 161477040fSmrg 171477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 181477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 191477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 201477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 211477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 221477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 231477040fSmrgDEALINGS IN THE SOFTWARE. 241477040fSmrg 251477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 26444c061aSmrg 27444c061aSmrg All Rights Reserved 28444c061aSmrg 29444c061aSmrgPermission to use, copy, modify, and distribute this software and its 30444c061aSmrgdocumentation for any purpose and without fee is hereby granted, 31444c061aSmrgprovided that the above copyright notice appear in all copies and that 32444c061aSmrgboth that copyright notice and this permission notice appear in 331477040fSmrgsupporting documentation, and that the name of Digital not be 34444c061aSmrgused in advertising or publicity pertaining to distribution of the 35444c061aSmrgsoftware without specific, written prior permission. 36444c061aSmrg 37444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 38444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 39444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 40444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 41444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 42444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 43444c061aSmrgSOFTWARE. 44444c061aSmrg 45444c061aSmrg******************************************************************/ 46444c061aSmrg/* $XFree86: xc/lib/Xt/GetResList.c,v 3.5 2001/08/22 22:52:18 dawes Exp $ */ 47444c061aSmrg 48444c061aSmrg/* 49444c061aSmrg 50444c061aSmrgCopyright 1987, 1988, 1998 The Open Group 51444c061aSmrg 52444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its 53444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that 54444c061aSmrgthe above copyright notice appear in all copies and that both that 55444c061aSmrgcopyright notice and this permission notice appear in supporting 56444c061aSmrgdocumentation. 57444c061aSmrg 58444c061aSmrgThe above copyright notice and this permission notice shall be included in 59444c061aSmrgall copies or substantial portions of the Software. 60444c061aSmrg 61444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 62444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 63444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 64444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 65444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 66444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 67444c061aSmrg 68444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be 69444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings 70444c061aSmrgin this Software without prior written authorization from The Open Group. 71444c061aSmrg 72444c061aSmrg*/ 73444c061aSmrg 74444c061aSmrg#ifdef HAVE_CONFIG_H 75444c061aSmrg#include <config.h> 76444c061aSmrg#endif 77444c061aSmrg#include "IntrinsicI.h" 78444c061aSmrg#include "Intrinsic.h" 79444c061aSmrg 80444c061aSmrg/* 81444c061aSmrg * XtGetResourceList(), XtGetConstraintResourceList() 82444c061aSmrg */ 83444c061aSmrg 84444c061aSmrg#define TOXRMQUARK(p) ((XrmQuark)(long)(p)) /* avoid LP64 warnings */ 85444c061aSmrg 86444c061aSmrgvoid XtGetResourceList( 87444c061aSmrg WidgetClass widget_class, 88444c061aSmrg XtResourceList *resources, 89444c061aSmrg Cardinal *num_resources) 90444c061aSmrg{ 91444c061aSmrg int size; 92444c061aSmrg register Cardinal i, dest = 0; 93444c061aSmrg register XtResourceList *list, dlist; 94444c061aSmrg 95444c061aSmrg LOCK_PROCESS; 96444c061aSmrg size = widget_class->core_class.num_resources * sizeof(XtResource); 97444c061aSmrg *resources = (XtResourceList) __XtMalloc((unsigned) size); 98444c061aSmrg 99444c061aSmrg if (!widget_class->core_class.class_inited) { 100444c061aSmrg /* Easy case */ 101444c061aSmrg 102444c061aSmrg (void) memmove((char *) *resources, 103444c061aSmrg (char *)widget_class->core_class.resources, size); 104444c061aSmrg *num_resources = widget_class->core_class.num_resources; 105444c061aSmrg UNLOCK_PROCESS; 106444c061aSmrg return; 107444c061aSmrg } 108444c061aSmrg 109444c061aSmrg /* Nope, it's the hard case */ 110444c061aSmrg 111444c061aSmrg list = (XtResourceList *) widget_class->core_class.resources; 112444c061aSmrg dlist = *resources; 113444c061aSmrg for (i = 0; i < widget_class->core_class.num_resources; i++) { 114444c061aSmrg if (list[i] != NULL) { 115444c061aSmrg dlist[dest].resource_name = (String) 116444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_name)); 117444c061aSmrg dlist[dest].resource_class = (String) 118444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_class)); 119444c061aSmrg dlist[dest].resource_type = (String) 120444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_type)); 121444c061aSmrg dlist[dest].resource_size = list[i]->resource_size; 122444c061aSmrg /* trust that resource_offset isn't that big */ 123444c061aSmrg dlist[dest].resource_offset = (Cardinal) 124444c061aSmrg -((int)(list[i]->resource_offset + 1)); 125444c061aSmrg dlist[dest].default_type = (String) 126444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->default_type)); 127444c061aSmrg dlist[dest].default_addr = list[i]->default_addr; 128444c061aSmrg dest++; 129444c061aSmrg } 130444c061aSmrg } 131444c061aSmrg *num_resources = dest; 132444c061aSmrg UNLOCK_PROCESS; 133444c061aSmrg} 134444c061aSmrg 135444c061aSmrg 136444c061aSmrgstatic Boolean ClassIsSubclassOf(WidgetClass class, WidgetClass superclass) 137444c061aSmrg{ 138444c061aSmrg for (; class != NULL; class = class->core_class.superclass) { 139444c061aSmrg if (class == superclass) return True; 140444c061aSmrg } 141444c061aSmrg return False; 142444c061aSmrg} 143444c061aSmrg 144444c061aSmrgvoid XtGetConstraintResourceList( 145444c061aSmrg WidgetClass widget_class, 146444c061aSmrg XtResourceList *resources, 147444c061aSmrg Cardinal *num_resources) 148444c061aSmrg{ 149444c061aSmrg int size; 150444c061aSmrg register Cardinal i, dest = 0; 151444c061aSmrg register XtResourceList *list, dlist; 152444c061aSmrg ConstraintWidgetClass class = (ConstraintWidgetClass)widget_class; 153444c061aSmrg 154444c061aSmrg LOCK_PROCESS; 155444c061aSmrg if ( (class->core_class.class_inited && 156444c061aSmrg !(class->core_class.class_inited & ConstraintClassFlag)) 157444c061aSmrg || (!class->core_class.class_inited && 158444c061aSmrg !ClassIsSubclassOf(widget_class, constraintWidgetClass)) 159444c061aSmrg || class->constraint_class.num_resources == 0) { 160444c061aSmrg 161444c061aSmrg *resources = NULL; 162444c061aSmrg *num_resources = 0; 163444c061aSmrg UNLOCK_PROCESS; 164444c061aSmrg return; 165444c061aSmrg } 166444c061aSmrg 167444c061aSmrg size = class->constraint_class.num_resources * sizeof(XtResource); 168444c061aSmrg *resources = (XtResourceList) __XtMalloc((unsigned) size); 169444c061aSmrg 170444c061aSmrg if (!class->core_class.class_inited) { 171444c061aSmrg /* Easy case */ 172444c061aSmrg 173444c061aSmrg (void) memmove((char *) *resources, 174444c061aSmrg (char *)class->constraint_class.resources, size); 175444c061aSmrg *num_resources = class->constraint_class.num_resources; 176444c061aSmrg UNLOCK_PROCESS; 177444c061aSmrg return; 178444c061aSmrg } 179444c061aSmrg 180444c061aSmrg /* Nope, it's the hard case */ 181444c061aSmrg 182444c061aSmrg list = (XtResourceList *) class->constraint_class.resources; 183444c061aSmrg dlist = *resources; 184444c061aSmrg for (i = 0; i < class->constraint_class.num_resources; i++) { 185444c061aSmrg if (list[i] != NULL) { 186444c061aSmrg dlist[dest].resource_name = (String) 187444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_name)); 188444c061aSmrg dlist[dest].resource_class = (String) 189444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_class)); 190444c061aSmrg dlist[dest].resource_type = (String) 191444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->resource_type)); 192444c061aSmrg dlist[dest].resource_size = list[i]->resource_size; 193444c061aSmrg /* trust that resource_offset isn't that big */ 194444c061aSmrg dlist[dest].resource_offset = (Cardinal) 195444c061aSmrg -((int)(list[i]->resource_offset + 1)); 196444c061aSmrg dlist[dest].default_type = (String) 197444c061aSmrg XrmQuarkToString(TOXRMQUARK(list[i]->default_type)); 198444c061aSmrg dlist[dest].default_addr = list[i]->default_addr; 199444c061aSmrg dest++; 200444c061aSmrg } 201444c061aSmrg } 202444c061aSmrg *num_resources = dest; 203444c061aSmrg UNLOCK_PROCESS; 204444c061aSmrg} 205