Blame tests/Auto/lib/Create/resources/mvsCpRsc.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
*/ 
Packit b099d7
/* 
Packit b099d7
 * HISTORY
Packit b099d7
*/ 
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: mvsCpRsc.c /main/7 1995/07/14 11:20:13 drk $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
/***********************************************************************
Packit b099d7
  	@(#)mvsCpRsc.c	1.6.1.1	Date:1/22/91
Packit b099d7
  	Author: TAT
Packit b099d7
	History:
Packit b099d7
	   03/30/90 SJS Add to sccs tree.
Packit b099d7
	   05/29/90 SJS changes for composites
Packit b099d7
	   07/29/90 PSN parameter changes, memory fixes
Packit b099d7
	Calls:
Packit b099d7
Packit b099d7
	Summary:
Packit b099d7
		This file contains function which copy resources.
Packit b099d7
	The method of copying is based on the type of each resource and
Packit b099d7
	a pointer/value is returned based on this type.
Packit b099d7
************************************************************************/
Packit b099d7
Packit b099d7
#include "mvslib.h"
Packit b099d7
Packit b099d7
/************************************************************************
Packit b099d7
*   This function copies One resource. The resource is copied           *
Packit b099d7
*   based on its type and a pointer/value is returned.                  *
Packit b099d7
************************************************************************/
Packit b099d7
MvsArgVal mvsCopyResource(widget_class_info, src_resource, i) 
Packit b099d7
MvsWidgetClassInfo *widget_class_info;
Packit b099d7
MvsArgVal src_resource; 
Packit b099d7
int i;
Packit b099d7
{ 
Packit b099d7
    MvsArgVal dst_resource;
Packit b099d7
    MvsResourceInfoRecord *resource_info;
Packit b099d7
Packit b099d7
    resource_info = widget_class_info->resource_info;
Packit b099d7
Packit b099d7
    switch (mvsTypeInfo[resource_info[i].type_code].ref_type) {
Packit b099d7
Packit b099d7
	    case RefXmStringTable: /* Here until handling of compound strings */
Packit b099d7
	                           /* becomes clear */
Packit b099d7
	    case RefValue: 	 
Packit b099d7
            case RefGeneric:
Packit b099d7
            case RefBoolean: 
Packit b099d7
                dst_resource = src_resource; 
Packit b099d7
                break;
Packit b099d7
Packit b099d7
	    case RefXmString:
Packit b099d7
	    case RefString: 
Packit b099d7
            { 
Packit b099d7
                char *str = (char *)src_resource; 
Packit b099d7
                if (str != NULL) { 
Packit b099d7
                    dst_resource = (MvsArgVal)XtMalloc(strlen(str)+1);
Packit b099d7
                    strcpy((char *)dst_resource,str); 
Packit b099d7
                } 
Packit b099d7
                else dst_resource = 0L; 
Packit b099d7
                break; 	 
Packit b099d7
            }
Packit b099d7
Packit b099d7
	    case RefCallbackList: 	 
Packit b099d7
            { 
Packit b099d7
                XtCallbackList cb_list = (XtCallbackList)src_resource; 
Packit b099d7
                int j=0; 
Packit b099d7
                if (cb_list != NULL) { 
Packit b099d7
                    while (cb_list->callback != NULL) { 
Packit b099d7
                        cb_list++; j++; 
Packit b099d7
                    } 
Packit b099d7
                    cb_list = (XtCallbackList)src_resource; 
Packit b099d7
                    dst_resource = (MvsArgVal)XtMalloc(sizeof(XtCallbackRec)*(j+1));
Packit b099d7
                    memcpy((char *)dst_resource,cb_list,sizeof(XtCallbackRec)*(j+1));
Packit b099d7
                }
Packit b099d7
                else dst_resource = 0L;
Packit b099d7
                break;
Packit b099d7
   	    } 
Packit b099d7
Packit b099d7
	    default: 
Packit b099d7
                dst_resource = src_resource; 
Packit b099d7
                msg_error("bad resource type code=%d in mvsCopyResource\n",
Packit b099d7
                          mvsTypeInfo[resource_info[i].type_code].ref_type);
Packit b099d7
                break;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    return (dst_resource);
Packit b099d7
} /* End mvsCopyResource() */
Packit b099d7
Packit b099d7

Packit b099d7
/*************************************************************************
Packit b099d7
*  This function copies all resources. The entire list of resources is   *
Packit b099d7
* looped through and each resource is copied using mvsCopyResource().    *
Packit b099d7
*************************************************************************/
Packit b099d7
void mvsCopyResources(widget_class_info, dst_resource,src_resource)
Packit b099d7
MvsWidgetClassInfo *widget_class_info;
Packit b099d7
MvsArgVal dst_resource[],
Packit b099d7
src_resource[]; 
Packit b099d7
{ 
Packit b099d7
    int i;
Packit b099d7
Packit b099d7
    for (i=0; i<widget_class_info->num_resources; i++)
Packit b099d7
        dst_resource[i] = mvsCopyResource(widget_class_info, src_resource[i],i);
Packit b099d7
Packit b099d7
} /* End mvsCopyResource() */
Packit b099d7