//##ex mcpp:cppc -gs -o filereq p:pLib/StartCode.o -pc filereq.c p:pLib/StdIO.o -l pOSxA -l pOSStub -l pOS -l List

/*\
*** 29.01.1997, Michael Christoph, proDAD
*** Example:
\*/

#include <exec/types.h>
#include <exec/libraries.h>
#include <libraries/asl.h>
#include <clib/exec_protos.h>
#include <clib/asl_protos.h>
#include <stdio.h>

#ifdef __pOS__
#include "p:clib/pExec_protos.h"
#endif

#ifdef LATTICE
int CXBRK(void)     { return(0); }  /* Disable Lattice CTRL/C handling */
void chkabort(void) { return; }     /* really */
#endif

UBYTE *vers = "$VER: filereq 1.0 (29.01.1997)  (proDAD, Michael Christoph)";

#define MYLEFTEDGE 0
#define MYTOPEDGE  0
#define MYWIDTH    320
#define MYHEIGHT   400

#ifdef __pOS__
struct pOS_pSLBase *gb_PSLBase;
#else
struct Library *AslBase = NULL;
#endif

struct TagItem frtags[] =
{
    ASL_Hail,       (ULONG)"The RKM file requester",
    ASL_Height,     MYHEIGHT,
    ASL_Width,      MYWIDTH,
    ASL_LeftEdge,   MYLEFTEDGE,
    ASL_TopEdge,    MYTOPEDGE,
    ASL_OKText,     (ULONG)"O KAY",
    ASL_CancelText, (ULONG)"not OK",
    ASL_File,       (ULONG)"asl.library",
    ASL_Dir,        (ULONG)"libs:",
    TAG_DONE
};

void main(int argc, char **argv)
{
    struct FileRequester *fr;

#ifdef __pOS__
    if(gb_PSLBase=(struct pOS_pSLBase*) pOS_OpenLibrary("psl.library",0))
#else
    if(AslBase = OpenLibrary("asl.library", 37L))
#endif
    {
        if (fr = (struct FileRequester *)
            AllocAslRequest(ASL_FileRequest, frtags))
        {
            if (AslRequest(fr, NULL))
            {
                printf("PATH=%s  FILE=%s\n", fr->rf_Dir, fr->rf_File);
                printf("To combine the path and filename, copy the path\n");
                printf("to a buffer, add the filename with Dos AddPart().\n");
            }
            FreeAslRequest(fr);
        }
        else printf("User Cancelled\n");

#ifdef __pOS__
        pOS_CloseLibrary((struct pOS_Library *)gb_PSLBase);
#else
        CloseLibrary(AslBase);
#endif
    }
}
