if (num_resources == 0) {
if (num_resources == 0 || num_resources >= MAXRESOURCES) {
static XtCacheRef *GetResources(widget, base, names, classes,	table, num_resources, quark_args, args, num_args,	typed_args, pNumTypedArgs, tm_hack)    Widget	    widget;	    /* Widget resources are associated with */    char*	    base;	    /* Base address of memory to write to   */    XrmNameList     names;	    /* Full inheritance name of widget      */    XrmClassList    classes;	    /* Full inheritance class of widget     */    XrmResourceList*  table;	    /* The list of resources required.      */    Cardinal	    num_resources;  /* number of items in resource list     */    XrmQuarkList    quark_args;     /* Arg names quarkified		    */    ArgList	    args;	    /* ArgList to override resources	    */    Cardinal	    num_args;       /* number of items in arg list	    */    XtTypedArgList  typed_args;	    /* Typed arg list to override resources */    Cardinal*	    pNumTypedArgs;  /* number of items in typed arg list    */    Boolean	    tm_hack;	    /* do baseTranslations		    */{/* * assert: *pNumTypedArgs == 0 if num_args > 0 * assert: num_args == 0 if *pNumTypedArgs > 0 */#define SEARCHLISTLEN 100    XrmValue	    value;    XrmQuark	    rawType;    XrmValue	    convValue;    XrmHashTable    stackSearchList[SEARCHLISTLEN];    XrmHashTable    *searchList = stackSearchList;    unsigned int    searchListSize = SEARCHLISTLEN;    Boolean	    found[400];    int		    typed[400];    XtCacheRef	    cache_ref[400];    XtCacheRef      *cache_ptr, *cache_base;    Boolean	    persistent_resources = True;    Boolean	    found_persistence = False;    int		    num_typed_args = *pNumTypedArgs;    XrmDatabase     db;    Boolean	    do_tm_hack = False;    if ((args == NULL) && (num_args != 0)) {    	XtAppWarningMsg(XtWidgetToApplicationContext(widget),		"invalidArgCount","getResources",XtCXtToolkitError,                 "argument count > 0 on NULL argument list",                   (String *)NULL, (Cardinal *)NULL);	num_args = 0;    }    if (num_resources == 0) {	return NULL;    } else if (table == NULL) {    	XtAppWarningMsg(XtWidgetToApplicationContext(widget),		"invalidResourceCount","getResources",XtCXtToolkitError,              "resource count > 0 on NULL resource list",	      (String *)NULL, (Cardinal *)NULL);	return NULL;    }    /* Mark each resource as not found on arg list */    bzero((char *) found, (int) (num_resources * sizeof(Boolean)));    bzero((char *) typed, (int) (num_resources * sizeof(int)));    /* Copy the args into the resources, mark each as found */    {	register ArgList	    arg;	register XtTypedArgList	    typed_arg;	register XrmName	    argName;	register int	    j;	register int	    i;	register XrmResourceList rx;	register XrmResourceList *res;	for (arg = args, i = 0; i < num_args; i++, arg++) {	    argName = quark_args[i];	    if (argName == QinitialResourcesPersistent) {		persistent_resources = (Boolean)arg->value;		found_persistence = True;		continue;	    }	    for (j = 0, res = table; j < num_resources; j++, res++) {		rx = *res;		if (argName == rx->xrm_name) {		    _XtCopyFromArg(			arg->value,			base - rx->xrm_offset - 1,			rx->xrm_size);		    found[j] = TRUE;		    break;		}	    }	}	for (typed_arg = typed_args, i = 0; i < num_typed_args;	     i++, typed_arg++) {	    register XrmRepresentation argType;	    argName = quark_args[i];	    argType = (typed_arg->type == NULL) ? NULLQUARK 		: XrmStringToRepresentation(typed_arg->type);	    if (argName == QinitialResourcesPersistent) {		persistent_resources = (Boolean)typed_arg->value;		found_persistence = True;   		break;	    }	    for (j = 0, res = table; j < num_resources; j++, res++) {		rx = *res;		if (argName == rx->xrm_name) {		    if (argType != NULLQUARK && argType != rx->xrm_type) {			typed[j] = i + 1;		    } else {			_XtCopyFromArg(				       typed_arg->value,				       base - rx->xrm_offset - 1,				       rx->xrm_size);		    }		    found[j] = TRUE;		    break;		}   	    }	}    }    /* Ask resource manager for a list of database levels that we can       do a single-level search on each resource */    db = XtScreenDatabase(XtScreenOfObject(widget));    while (!XrmQGetSearchList(db, names, classes,			      searchList, searchListSize)) {	if (searchList == stackSearchList)	    searchList = NULL;	searchList = (XrmHashTable*)XtRealloc((char*)searchList,					      sizeof(XrmHashTable) *					      (searchListSize *= 2));    }        if (persistent_resources)	cache_base = NULL;    else	cache_base = cache_ref;    /* geez, this is an ugly mess */    if (XtIsShell(widget)) {	register XrmResourceList  *res;	register int		  j;	Screen *oldscreen = widget->core.screen;	/* look up screen resource first, since real rdb depends on it */	for (res = table, j = 0; j < num_resources; j++, res++) {	    if ((*res)->xrm_name != Qscreen)		continue;	    if (typed[j]) {		register XtTypedArg* arg = typed_args + typed[j] - 1;		XrmQuark from_type;		XrmValue from_val, to_val;		from_type = StringToQuark(arg->type);		from_val.size = arg->size;		if ((from_type == QString) || (arg->size > sizeof(XtArgVal)))		    from_val.addr = (XPointer)arg->value;		else		    from_val.addr = (XPointer)&arg->value;		to_val.size = sizeof(Screen*);		to_val.addr = (XPointer)&widget->core.screen;		found[j] = _XtConvert(widget, from_type, &from_val,				      QScreen, &to_val, cache_base);		if (cache_base && *cache_base)		    cache_base++;	    }	    if (!found[j]) {		if (XrmQGetSearchResource(searchList, Qscreen, QScreen,				      &rawType, &value)) {		    if (rawType != QScreen) {			convValue.size = sizeof(Screen*);			convValue.addr = (XPointer)&widget->core.screen;			(void)_XtConvert(widget, rawType, &value,					 QScreen, &convValue, cache_base);			if (cache_base && *cache_base)			    cache_base++;		    } else {			widget->core.screen = *((Screen **)value.addr);		    }		}	    }	    break;	}	/* now get the database to use for the rest of the resources */	if (widget->core.screen != oldscreen) {	    db = XtScreenDatabase(widget->core.screen);	    while (!XrmQGetSearchList(db, names, classes,				      searchList, searchListSize)) {		if (searchList == stackSearchList)		    searchList = NULL;		searchList = (XrmHashTable*)XtRealloc((char*)searchList,						      sizeof(XrmHashTable) *						      (searchListSize *= 2));	    }	}    }    /* go to the resource manager for those resources not found yet */    /* if it's not in the resource database use the default value   */    {	register XrmResourceList  rx;	register XrmResourceList  *res;	register int		  j;	register XrmRepresentation xrm_type;	register XrmRepresentation xrm_default_type;	char	char_val;	short	short_val;	int	int_val;	long	long_val;	char*	char_ptr;	if (!found_persistence) {	    if (XrmQGetSearchResource(searchList, QinitialResourcesPersistent,			QInitialResourcesPersistent, &rawType, &value)) {		if (rawType != QBoolean) {		    convValue.size = sizeof(Boolean);		    convValue.addr = (XPointer)&persistent_resources;		    (void)_XtConvert(widget, rawType, &value, QBoolean,				     &convValue, NULL);		}		else		    persistent_resources = *(Boolean*)value.addr;	    }	}	if (persistent_resources)	    cache_ptr = NULL;	else if (cache_base)	    cache_ptr = cache_base;	else	    cache_ptr = cache_ref;	for (res = table, j = 0; j < num_resources; j++, res++) {	    rx = *res;	    xrm_type = rx->xrm_type;	    if (typed[j]) {		register XtTypedArg* arg = typed_args + typed[j] - 1;		/*                 * This resource value has been specified as a typed arg and 		 * has to be converted. Typed arg conversions are done here 		 * to correctly interpose them with normal resource conversions.                 */		XrmQuark	    from_type;		XrmValue            from_val, to_val;		Boolean		    converted;                 		from_type = StringToQuark(arg->type);    		from_val.size = arg->size;		if ((from_type == QString) || (arg->size > sizeof(XtArgVal)))        	    from_val.addr = (XPointer)arg->value;	        else            	    from_val.addr = (XPointer)&arg->value;		to_val.size = rx->xrm_size;		to_val.addr = base - rx->xrm_offset - 1;		converted = _XtConvert(widget, from_type, &from_val,				       xrm_type, &to_val, cache_ptr);		if (converted) {		    /* Copy the converted value back into the typed argument.		     * normally the data should be <= sizeof(XtArgVal) and		     * is stored directly into the 'value' field .... BUT		     * if the resource size is greater than sizeof(XtArgVal)		     * then we dynamically alloc a block of store to hold the		     * data and zap a copy in there !!! .... freeing it later		     * the size field in the typed arg is negated to indicate		     * that the store pointed to by the value field is		     * dynamic .......		     * "freeing" happens in the case of _XtCreate after the		     * CallInitialize ..... other clients of GetResources		     * using typed args should be aware of the need to free		     * this store .....		     */		    if(rx->xrm_size > sizeof(XtArgVal)) {			arg->value = (XtArgVal) __XtMalloc(rx->xrm_size);			arg->size = -(arg->size);		    } else { /* will fit - copy directly into value field */			arg->value = (XtArgVal) NULL;		    }		    CopyToArg((char *)(base - rx->xrm_offset - 1),				 &arg->value, rx->xrm_size);		} else {		   /* Conversion failed. Get default value. */		   found[j] = False;		}		if (cache_ptr && *cache_ptr)		    cache_ptr++;	    }	    if (!found[j]) {		Boolean	already_copied = False;		Boolean have_value = False;		if (XrmQGetSearchResource(searchList,			rx->xrm_name, rx->xrm_class, &rawType, &value)) {		    if (rawType != xrm_type) {			convValue.size = rx->xrm_size;			convValue.addr = (XPointer)(base - rx->xrm_offset - 1);			already_copied = have_value =			    _XtConvert(widget, rawType, &value,				       xrm_type, &convValue, cache_ptr);			if (cache_ptr && *cache_ptr)			    cache_ptr++;		    } else have_value = True;		    if (have_value && rx->xrm_name == Qtranslations)			do_tm_hack = True;		}		LOCK_PROCESS;		if (!have_value		    && ((rx->xrm_default_type == QImmediate)			|| (rx->xrm_default_type == xrm_type)			|| (rx->xrm_default_addr != NULL))) {		    /* Convert default value to proper type */		    xrm_default_type = rx->xrm_default_type;		    if (xrm_default_type == QCallProc) {#ifdef CRAY 			if ( (int) Cjumpp != (int) Cjump) 			    (*(XtResourceDefaultProc)			      (((int)(rx->xrm_default_addr))<<2))( 				 widget,-(rx->xrm_offset+1), &value);			else#endif			(*(XtResourceDefaultProc)(rx->xrm_default_addr))(			      widget,-(rx->xrm_offset+1), &value);		    } else if (xrm_default_type == QImmediate) {			/* XtRImmediate == XtRString for type XtRString */			if (xrm_type == QString) {			    value.addr = rx->xrm_default_addr;			} else if (rx->xrm_size == sizeof(int)) {			    int_val = (int)(long)rx->xrm_default_addr;			    value.addr = (XPointer) &int_val;			} else if (rx->xrm_size == sizeof(short)) {			    short_val = (short)(long)rx->xrm_default_addr;			    value.addr = (XPointer) &short_val;			} else if (rx->xrm_size == sizeof(char)) {			    char_val = (char)(long)rx->xrm_default_addr;			    value.addr = (XPointer) &char_val;			} else if (rx->xrm_size == sizeof(long)) {			    long_val = (long)rx->xrm_default_addr;			    value.addr = (XPointer) &long_val;			} else if (rx->xrm_size == sizeof(char*)) {			    char_ptr = (char*)rx->xrm_default_addr;			    value.addr = (XPointer) &char_ptr;			} else {			    value.addr = (XPointer) &(rx->xrm_default_addr);			}		    } else if (xrm_default_type == xrm_type) {			value.addr = rx->xrm_default_addr;		    } else {			value.addr = rx->xrm_default_addr;			if (xrm_default_type == QString) {			    value.size = strlen((char *)value.addr) + 1;			} else {			    value.size = sizeof(XtPointer);			}			convValue.size = rx->xrm_size;			convValue.addr = (XPointer)(base - rx->xrm_offset - 1);			already_copied =			    _XtConvert(widget, xrm_default_type, &value,				       xrm_type, &convValue, cache_ptr);			if (!already_copied)			    value.addr = NULL;			if (cache_ptr && *cache_ptr)			    cache_ptr++;		    }		}		if (!already_copied) {		    if (xrm_type == QString) {			*((String*)(base - rx->xrm_offset - 1)) = value.addr;		    } else {			if (value.addr != NULL) {			    XtMemmove(base - rx->xrm_offset - 1,				      value.addr, rx->xrm_size);			} else {			    /* didn't get value, initialize to NULL... */			    XtBZero(base - rx->xrm_offset - 1, rx->xrm_size);			}		    }		}		UNLOCK_PROCESS;		if (typed[j]) {		    /*		     * This resource value was specified as a typed arg.		     * However, the default value is being used here since		     * type type conversion failed, so we compress the list.		     */		    register XtTypedArg* arg = typed_args + typed[j] - 1;		    register int i;		    for (i = num_typed_args - typed[j]; i; i--, arg++) {			*arg = *(arg+1);		    }		    num_typed_args--;		}	    } 	}	if (tm_hack)	    widget->core.tm.current_state = NULL;	if (tm_hack &&	    (!widget->core.tm.translations ||	     (do_tm_hack &&	      widget->core.tm.translations->operation != XtTableReplace)) &&	    XrmQGetSearchResource(searchList, QbaseTranslations,				  QTranslations, &rawType, &value)) {	    if (rawType != QTranslationTable) {		convValue.size = sizeof(XtTranslations);		convValue.addr = (XPointer)&widget->core.tm.current_state;		(void)_XtConvert(widget, rawType, &value,				 QTranslationTable, &convValue, cache_ptr);		if (cache_ptr && *cache_ptr)		    cache_ptr++;	    } else {		*((XtTranslations *)&widget->core.tm.current_state) =		    *((XtTranslations *)value.addr);	    }	}    }    if (num_typed_args != *pNumTypedArgs) *pNumTypedArgs = num_typed_args;    if (searchList != stackSearchList) XtFree((char*)searchList);    if (!cache_ptr)	cache_ptr = cache_base;    if (cache_ptr && cache_ptr != cache_ref) {	int cache_ref_size = cache_ptr - cache_ref;	XtCacheRef *refs = (XtCacheRef*)	    __XtMalloc((unsigned)sizeof(XtCacheRef)*(cache_ref_size + 1));	(void) memmove(refs, cache_ref, sizeof(XtCacheRef)*cache_ref_size );	refs[cache_ref_size] = NULL;	return refs;    }    return (XtCacheRef*)NULL;}