home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / utility / clonetagitems.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  3.1 KB  |  119 lines

  1. /*
  2.     $Id: clonetagitems.c,v 1.3 1996/10/24 15:51:35 aros Exp $
  3.     $Log: clonetagitems.c,v $
  4.     Revision 1.3  1996/10/24 15:51:35  aros
  5.     Use the official AROS macros over the __AROS versions.
  6.  
  7.     Revision 1.2  1996/10/23 14:08:28  aros
  8.     Formatted
  9.  
  10.     Added parens to all assignments which are used truth expressions
  11.  
  12.     Revision 1.1  1996/10/22 04:45:59  aros
  13.     Some more utility.library functions.
  14.  
  15.     Desc: CloneTagItems()
  16.     Lang: english
  17. */
  18. #include "utility_intern.h"
  19.  
  20. /*****************************************************************************
  21.  
  22.     NAME */
  23.     #include <utility/tagitem.h>
  24.     #include <clib/utility_protos.h>
  25.  
  26.     AROS_LH1(struct TagItem *, CloneTagItems,
  27.  
  28. /*  SYNOPSIS */
  29.     AROS_LHA(struct TagItem *, tagList, A0),
  30.  
  31. /*  LOCATION */
  32.     struct UtilityBase *, UtilityBase, 12, Utility)
  33.  
  34. /*  FUNCTION
  35.     Duplicates a TagList
  36.  
  37.     INPUTS
  38.     tagList     -    The TagList that you want to clone
  39.  
  40.     RESULT
  41.     A TagList which contains a copy of the TagItems contained in the
  42.     original list. The list is cloned so that calling FindTagItem()
  43.     on a tag in the clone will return the same value as that in the
  44.     original list (assuming the original has not been modified).
  45.  
  46.     NOTES
  47.     If the original TagList is NULL, then no cloning will take place.
  48.  
  49.     EXAMPLE
  50.     struct TagItem *tagList, *tagListClone;
  51.  
  52.     \* Set up the original taglist tagList *\
  53.  
  54.     tagListClone = CloneTagItems( tagList );
  55.  
  56.     \* Do what you want with your TagList here *\
  57.  
  58.     FreeTagItems( tagListClone );
  59.  
  60.     BUGS
  61.  
  62.     SEE ALSO
  63.     <utility/tagitem.h>, AllocateTagItems(), FreeTagItems(),
  64.     RefreshTagItemClones()
  65.  
  66.     INTERNALS
  67.  
  68.     HISTORY
  69.     29-10-95    digulla automatically created from
  70.                 utility_lib.fd and clib/utility_protos.h
  71.     11-08-96    iaint   Implemented as AROS function.
  72.     01-09-96    iaint   Updated the docs to give the same warnings
  73.                 as the autodocs.
  74.     05-09-96    iaint   Bit of optimisation (one variable :( )
  75.  
  76. *****************************************************************************/
  77. {
  78.     AROS_LIBFUNC_INIT
  79.  
  80.     struct TagItem *newList,
  81.            *ti;
  82.     LONG numTags = 1;
  83.  
  84.     /* Make sure we actually have some valid input here... */
  85.     if (!tagList)
  86.     return NULL;
  87.  
  88.     /*
  89.     We start the counter at 1 since this count will not include the
  90.     TAG_DONE TagItem
  91.  
  92.     newList is used here to save a variable. We don't need to do
  93.     anything to the value of newList afterwards, since AllocateTagitems()
  94.     will take care of setting it to NULL if the allocation fails.
  95.     */
  96.     newList = tagList;
  97.     while ((ti = NextTagItem (&newList)))
  98.     numTags++;
  99.  
  100.     /*
  101.     Then we shall allocate the TagList.
  102.     If we can actually allocate a clone tag list, then we shall copy
  103.     the tag values from one tag to another, the function
  104.     "RefreshTagItemClones()" is used here to help re-use code.
  105.  
  106.     Of course we don't have to worry about the if statement, since
  107.     the original is guaranteed to have not been changed since
  108.     CloneTagItems() :)
  109.     */
  110.  
  111.     if ((newList = AllocateTagItems (numTags)))
  112.     RefreshTagItemClones (newList, tagList);
  113.  
  114.     /* newList == 0 when allocation failed - AllocateTagItems handles this*/
  115.     return newList;
  116.  
  117.     AROS_LIBFUNC_EXIT
  118. } /* CloneTagItems */
  119.