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