home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / utility / findnamedobject.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  3.2 KB  |  117 lines

  1. /*
  2.     $Id: findnamedobject.c,v 1.3 1997/01/27 13:17:13 digulla Exp $
  3.     $Log: findnamedobject.c,v $
  4.     Revision 1.3  1997/01/27 13:17:13  digulla
  5.     Added #include <proto/exec.h>
  6.  
  7.     Revision 1.2  1997/01/27 00:32:30  ldp
  8.     Polish
  9.  
  10.     Revision 1.1  1996/12/18 01:27:35  iaint
  11.     NamedObjects
  12.  
  13.     Desc: FindNamedObject() - find a NamedObject in a given NameSpace.
  14.     Lang: english
  15. */
  16. #include <proto/exec.h>
  17. #include "utility_intern.h"
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <utility/name.h>
  23.     #include <proto/utility.h>
  24.  
  25.     AROS_LH3(struct NamedObject *, FindNamedObject,
  26.  
  27. /*  SYNOPSIS */
  28.     AROS_LHA(struct NamedObject *, nameSpace, A0),
  29.     AROS_LHA(STRPTR              , name, A1),
  30.     AROS_LHA(struct NamedObject *, lastObject, A2),
  31.  
  32. /*  LOCATION */
  33.     struct UtilityBase *, UtilityBase, 40, Utility)
  34.  
  35. /*  FUNCTION
  36.     This function will search through a given NameSpace, or the
  37.     system global NameSpace to find a NamedObject with the name
  38.     requested. Optionally you can have the search start from a
  39.     specific NamedObject. This way you can look for each occurence
  40.     of a specifically named NamedObject in a NameSpace that allows
  41.     for duplicates.
  42.  
  43.     INPUTS
  44.     nameSpace   -    The NameSpace to search through. If NULL will use
  45.             the system default NameSpace.
  46.     name        -    The name of the object to search for.
  47.     lastObject  -    The (optional) last NamedObject to start the search
  48.             from.
  49.  
  50.     RESULT
  51.     If a NamedObject with the name supplied exists, it will be returned.
  52.     Otherwise will return NULL.
  53.  
  54.     When you have finised with this NamedObject, you should call
  55.     ReleaseNamedObject( NamedObject ).
  56.  
  57.     NOTES
  58.     If you are going to use a returned NamedObject to be the starting
  59.     point for another search you must call ReleaseNamedObject() AFTER
  60.     searching, as the ReleaseNamedObject() call can cause the NamedObject
  61.     to be freed, leaving you with an invalid pointer.
  62.  
  63.     EXAMPLE
  64.  
  65.     BUGS
  66.  
  67.     SEE ALSO
  68.     utility/name.h ReleaseNamedObject() "Utility: Named Objects"
  69.  
  70.     INTERNALS
  71.     Could we implement named objects with hash chains perhaps?
  72.  
  73.     HISTORY
  74.     29-10-95    digulla automatically created from
  75.                 utility_lib.fd and clib/utility_protos.h
  76.     11-08-96    iaint   Wrote based on AmigaOS 3.0 function.
  77.  
  78.  
  79. *****************************************************************************/
  80. {
  81.     AROS_LIBFUNC_INIT
  82.  
  83.     struct NamedObject        *foundObj = NULL;
  84.     struct IntNamedObject   *no;
  85.     struct Node         *StartObj;
  86.     struct NameSpace        *ns;
  87.  
  88.     /* It is a bit stupid to do something with a NULL name */
  89.     if( name )
  90.     {
  91.     ns = GetNameSpace( nameSpace, UtilityBase);
  92.     ObtainSemaphore( &ns->ns_Lock );
  93.  
  94.     /*
  95.         if the user supplied a lastObject, then we shall use that
  96.         to get the index of the starting object. Otherwise we shall
  97.         extract the address of the first node in the NameSpace.
  98.     */
  99.     if(lastObject)
  100.         StartObj = (GetIntNamedObject(lastObject))->no_Node.ln_Succ;
  101.     else
  102.         StartObj = (struct Node *)ns->ns_List.mlh_Head;
  103.  
  104.     if((no = IntFindNamedObj(ns, StartObj, name, UtilityBase)))
  105.     {
  106.         no->no_UseCount++;
  107.         foundObj = GetNamedObject(no);
  108.     }
  109.     ReleaseSemaphore( &ns->ns_Lock );
  110.  
  111.     } /* if( name ) */
  112.     return foundObj;
  113.  
  114.     AROS_LIBFUNC_EXIT
  115.  
  116. } /* FindNamedObject */
  117.