/* INCLUDES ********************************************************** */

#include "exec/types.h"
#include "exec/io.h"
#include "exec/memory.h"
#include "libraries/dos.h"
#include "intuition/intuition.h"

        USHORT quit_flag = FALSE;

/* This is for the event handler */
void quit(object)
APTR object;
{
        quit_flag = TRUE;
}

        long IntuitionBase=0;
        long GfxBase=0;

struct Window *OpenWindow();
struct Screen *OpenScreen();

struct NewWindow NewWindowStructure1 = {
        0,0,    /* window XY origin relative to TopLeft of screen */
        640,200,        /* window width and height */
        0,1,    /* detail and block pens */
        CLOSEWINDOW,    /* IDCMP flags */
        WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH, /* other window flags */
        NULL,   /* first gadget in gadget list */
        NULL,   /* custom CHECKMARK imagery */
        "Click on the Close Gadget to Quit",    /* window title */
        NULL,   /* custom screen pointer */
        NULL,   /* custom bitmap */
        5,5,    /* minimum width and height */
        -1,-1,  /* maximum width and height */
        WBENCHSCREEN    /* destination screen type */
};


#include "textfile.c"

main()
{
        UWORD code;
        ULONG class;
        APTR object;

        struct Window *wG;      /* we fetch the RastPort pointer from here */
        struct RastPort *rpG;
        struct IntuiMessage *message;   /* the message the IDCMP sends us */

        IntuitionBase = OpenLibrary("intuition.library", 0);
        if (IntuitionBase == NULL)
        {
                printf("intuition is not here.  where are we?\n");
                goto cleanup1;
        }
        GfxBase = OpenLibrary("graphics.library", 0);


        wG = OpenWindow(&NewWindowStructure1);  /* open the window */
        if ( wG == NULL )
        {
                printf ("open window failed\n");
                goto cleanup1;
        }

        rpG = wG->RPort;        /* get a rastport pointer for the window */

        PrintIText(rpG,&IntuiTextList1,0,0);    /* Print the text */


        do
        {
                WaitPort(wG->UserPort);
                        while( (message = (struct IntuiMessage *)
                                GetMsg(wG->UserPort) ) != NULL)
                        {
                                code = message->Code;  /* MENUNUM */
                                object = message->IAddress;  /* Gadget */
                                class = message->Class;
                                ReplyMsg(message);
                                if ( class == CLOSEWINDOW ) (quit_flag = TRUE);
                        }
        } while (quit_flag == FALSE);

cleanup3:
        CloseWindow(wG);

cleanup1:
        if (GfxBase != NULL) CloseLibrary(GfxBase);
        if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
        return(0);

}
