/*
    (C) 1995-97 AROS - The Amiga Replacement OS
    $Id: isdosentrya.c,v 1.1 1997/07/27 13:42:46 laguest Exp $

    Desc:
    Lang: english
*/

#include <proto/arossupport.h>
#include <proto/dos.h>
#include <proto/utility.h>

#include <aros/system.h>
#include <dos/dos.h>

#define dol_OldName dol_Name

#include <dos/dosextens.h>
#include <exec/types.h>
#include <utility/utility.h>

extern struct UtilityBase * UtilityBase;

#define BUFFER_SIZE   100

/*****************************************************************************

    NAME */

        BOOL IsDosEntryA(

/*  SYNOPSIS */

        char  * Name,
        ULONG   Flags)

/*  LOCATION */

/*  FUNCTION

        There is a need in file/directory proecessing where an application
        may need to determine whether a path is just a volume/device or
        assignment name.

    INPUTS

        Name  - The path to test.

        Flags - Any combination of the following:

                LDF_ASSIGNS
                LDF_DEVICES
                LDF_VOLUMES

    RESULT

        Boolean True or False.

    NOTES

        Requires the programmer to open the utility.library and initialise
        UtilityBase.

        In future releases the buffer size will be set via a taglist.

    EXAMPLE

        BOOL Success;

        ...

        Success = IsDosEntryA("Work:", LDF_VOLUMES)
        if (Success == TRUE)
        {
          ...
        }  

    BUGS

    SEE ALSO

        <dos/dosextens.h>

    INTERNALS

    HISTORY

        27-Jul-1997     laguest     Initial inclusion into the AROS tree

******************************************************************************/
{
  struct DosList *DList;
  char           *DLName;
  int             Position;
  int             Success;
  BOOL            ReturnValue;
  char            Buffer[BUFFER_SIZE + 1];

  ReturnValue = FALSE;

  Position = SplitName(Name, ':', &Buffer[0], 0, BUFFER_SIZE + 1);
  if (Position != -1 && Name[Position] == NULL)
  {
    DList = AttemptLockDosList(Flags | LDF_READ);
    if (DList != NULL)
    {
      DList = NextDosEntry(DList, Flags);
      while (DList != NULL && ReturnValue == FALSE)
      {
        DLName = (char *)BADDR(DList->dol_OldName);
        DLName++;

        Success = Strnicmp(DLName, &Buffer[0], Position - 1);
        if (Success == 0)
        {
          ReturnValue = TRUE;
        }
        
        DList = NextDosEntry(DList, Flags);
      }
      
      UnLockDosList(Flags | LDF_READ);
    }
  }

  return (ReturnValue);

} /* IsDosEntry */
