#ifndef LIBRARIES_ARPBASE_H
#define LIBRARIES_ARPBASE_H     1
/**
*
*   This is a partial ARPbase.h. See ARPBase.h for the full thing.
*   Created to be able to coexist with 2.0
*
**/
#ifndef EXEC_TYPES_H
#include        <EXEC/Types.h>
#endif  // EXEC_TYPES_H

#ifndef EXEC_LISTS_H
#include        <EXEC/Lists.h>
#endif  // EXEC_LISTS_H

#ifndef EXEC_ALERTS_H
#include        <EXEC/Alerts.h>
#endif  // EXEC_ALERTS_H

#ifndef EXEC_LIBRARIES_H
#include        <EXEC/Libraries.h>
#endif  // EXEC_LIBRARIES_H

#ifndef EXEC_SEMAPHORES_H
#include        <EXEC/Semaphores.h>
#endif  // EXEC_SEMAPHORES_H

#ifndef LIBRARIES_DOS_H
#include        <Libraries/DOS.h>
#endif  // LIBRARIES_DOS_H

/*
*   Assume SAS C
*/

/*
 ************************************************************************
 *      Standard definitions for arp library information                *
 ************************************************************************
 */
#define ArpName         "arp.library"   /* Name of library... */
#define ArpVersion      39L             /* Current version... */

/*
 ************************************************************************
 *      The current ARP library node...                                 *
 ************************************************************************
 */
struct  ArpBase
{
        struct  Library                  LibNode;        /* Standard library node               */
        APTR                             DosRootNode;    /* Copy of dl_Root                     */
        UBYTE                            Flags;          /* See bitdefs below                   */
        UBYTE                            ESCChar;        /* Character to be used for escaping   */
        LONG                             ArpReserved1;   /* ArpLib's use only!!                 */
        struct  Library                 *EnvBase;        /* Dummy library for MANX compatibility*/
        struct  Library                 *DosBase;        /* Cached DosBase                      */
        struct  Library                 *GfxBase;        /* Cached GfxBase                      */
        struct  Library                 *IntuiBase;      /* Cached IntuitionBase                */
        struct  MinList                  ResLists;       /* Resource trackers                   */
        struct  ResidentProgramNode     *ResidentPrgList;/* Resident Programs.                  */
        struct  SignalSemaphore          ResPrgProtection;/* protection for above                */
        BPTR                             SegList;         /* Pointer to loaded libcode (a BPTR). */
};

/*
 ************************************************************************
 *      These are used in release 33.4 but not by the library code.     *
 *      Instead, individual programs check for these flags.             *
 ************************************************************************
 */
#define ARPB_WILD_WORLD 0L              ; Mixed BCPL/Normal wildcards.
#define ARPB_WILD_BCPL  1L              ; Pure BCPL wildcards.

#define ARPF_WILD_WORLD (1L << ARPB_WILD_WORLD)
#define ARPF_WILD_BCPL  (1L << ARPB_WILD_BCPL)

/*
 ************************************************************************
 *      The ARP file requester data structure...                        *
 ************************************************************************
 */
struct ARPFileRequester
{
                BYTE            *fr_Hail;               /* Hailing text                 */
                BYTE            *fr_File;               /* Filename array (FCHARS + 1)  */
                BYTE            *fr_Dir;                /* Directory array (DSIZE + 1)  */
                struct  Window  *fr_Window;             /* Window requesting or NULL    */
                UBYTE            fr_FuncFlags;          /* Set bitdef's below           */
                UBYTE            fr_Flags2;             /* New flags...                 */
                VOID           (*fr_Function)();        /* Your function, see bitdef's  */
                WORD             fr_LeftEdge;           /* To be used later...          */
                WORD             fr_TopEdge;
};

/*
 ************************************************************************
 * The following are the defines for fr_FuncFlags.  These bits tell     *
 * FileRequest() what your fr_UserFunc is expecting, and what           *
 * FileRequest() should call it for.                                    *
 *                                                                      *
 * You are called like so:                                              *
 * fr_Function(Mask, Object)                                            *
 * ULONG        Mask;                                                   *
 * CPTR         *Object;                                                *
 *                                                                      *
 * The Mask is a copy of the flag value that caused FileRequest() to    *
 * call your function. You can use this to determine what action you    *
 * need to perform, and exactly what Object is, so you know what to do  *
 * and what to return.                                                  *
 ************************************************************************
 */
#define FRB_DoWildFunc  7L /* Call me with a FIB and a name, ZERO return accepts.       */
#define FRB_DoMsgFunc   6L /* You get all IDCMP messages not for FileRequest()          */
#define FRB_DoColor     5L /* Set this bit for that new and different look              */
#define FRB_NewIDCMP    4L /* Force a new IDCMP (only if fr_Window != NULL)             */
#define FRB_NewWindFunc 3L /* You get to modify the newwindow structure.                */
#define FRB_AddGadFunc  2L /* You get to add gadgets.                                   */
#define FRB_GEventFunc  1L /* Function to call if one of your gadgets is selected.      */
#define FRB_ListFunc    0L /* Not implemented yet.                                      */

#define FRF_DoWildFunc  (1L << FRB_DoWildFunc)
#define FRF_DoMsgFunc   (1L << FRB_DoMsgFunc)
#define FRF_DoColor     (1L << FRB_DoColor)
#define FRF_NewIDCMP    (1L << FRB_NewIDCMP)
#define FRF_NewWindFunc (1L << FRB_NewWindFunc)
#define FRF_AddGadFunc  (1L << FRB_AddGadFunc)
#define FRF_GEventFunc  (1L << FRB_GEventFunc)
#define FRF_ListFunc    (1L << FRB_ListFunc)

/*
 ************************************************************************
 * The FR2B_ bits are for fr_Flags2 in the file requester structure     *
 ************************************************************************
 */
#define FR2B_LongPath   0L /* Specify the fr_Dir buffer is 256 bytes long */

#define FR2F_LongPath   (1L << FR2B_LongPath)

/*
 ************************************************************************
 *      The sizes of the different buffers...                           *
 ************************************************************************
 */
#define FCHARS          32L     /* Filename size                                */
#define DSIZE           33L     /* Directory name size if not FR2B_LongPath     */

#define LONG_DSIZE      254L    /* If FR2B_LongPath is set, use LONG_DSIZE      */
#define LONG_FSIZE      126L    /* For compatibility with ARPbase.i             */

#define FR_FIRST_GADGET 0x7680L /* User gadgetID's must be less than this value */

/*
 ************************************************************************
 * Structure expected by FindFirst()/FindNext()                         *
 *                                                                      *
 * You need to allocate this structure and initialize it as follows:    *
 *                                                                      *
 * Set ap_BreakBits to the signal bits (CDEF) that you want to take a   *
 * break on, or NULL, if you don't want to convenience the user.        *
 *                                                                      *
 * if you want to have the FULL PATH NAME of the files you found,       *
 * allocate a buffer at the END of this structure, and put the size of  *
 * it into ap_StrLen.  If you don't want the full path name, make sure  *
 * you set ap_StrLen to zero.  In this case, the name of the file, and  *
 * stats are available in the ap_Info, as per usual.                    *
 *                                                                      *
 * Then call FindFirst() and then afterwards, FindNext() with this      *
 * structure.  You should check the return value each time (see below)  *
 * and take the appropriate action, ultimately calling                  *
 * FreeAnchorChain() when there are no more files and you are done.     *
 * You can tell when you are done by checking for the normal AmigaDOS   *
 * return code ERROR_NO_MORE_ENTRIES.                                   *
 *                                                                      *
 * You will also have to check the DirEntryType variable in the ap_Info *
 * structure to determine what exactly you have received.               *
 ************************************************************************
 */
struct  ARPAnchorPath
{
                struct  AChain          *ap_Base;       /* Pointer to first anchor                      */
                struct  AChain          *ap_Last;       /* Pointer to last anchor                       */
                LONG                     ap_BreakBits;  /* Bits to break on                             */
                LONG                     ap_FoundBreak; /* Bits we broke on. Also returns ERROR_BREAK   */
                BYTE                     ap_Flags;      /* New use for the extra word...                */
                BYTE                     ap_Reserved;   /* To fill it out...                            */
                WORD                     ap_StrLen;     /* This is what used to be ap_Length            */
                struct  FileInfoBlock    ap_Info;
                BYTE                     ap_Buf[1];     /* Allocate a buffer here, if desired           */
};


ULONG           EscapeString    (char *);
BYTE            *Getenv         (char *, char *, LONG);
BOOL            Setenv          (char *, char *);
BYTE            *ARPFileRequest (struct ARPFileRequester *);
ULONG           PathName        (BPTR, char *,LONG);
LONG            FindFirst       (char *, struct ARPAnchorPath *);
LONG            FindNext        (struct ARPAnchorPath *);
VOID __stdargs *ArpAlloc        (LONG);
VOID            FreeAnchorChain (struct ARPAnchorPath *);

#pragma libcall ArpBase EscapeString            0108    801
#pragma libcall ArpBase Getenv                  011A    09803
#pragma libcall ArpBase Setenv                  0120    9802
#pragma libcall ArpBase ARPFileRequest          0126    801
#pragma libcall ArpBase PathName                014A    18003
#pragma libcall ArpBase FindFirst               01B6    8002
#pragma libcall ArpBase FindNext                01BC    801
#pragma libcall ArpBase ArpAlloc                0180    001
#pragma libcall ArpBase FreeAnchorChain         01C2    801


#endif  //LIBRARIES_ARPBASE_H
