
/*------- Bad.c ----------------------------------------------------------*
 *
 *  USAGE:
 *  ------
 *  If FCS is already running, please:
 *      - Start the Commodities Exchange - Tool from your
 *        Workbench-Disk and set the "FC Supervisor" INACTIVE.
 *
 *  Now, run this "Bad" program...... a little window will open and after
 *  5 seconds the window will close.
 *  Everything goes well, right?
 *
 *  BUT, this program has a compatibility bug!
 *  Somewhen in the future it will cause a problem..... (maybe a crash !!!)
 *  
 *  If FCS is INACTIVE now, it's time to make it ACTIV or if you
 *  didn't use it before, start FCS now!
 *  If you run this "Bad" program again, FCS will display a message-window,
 *  to inform you that the program has a bug!
 *  
 *  In the other "Good" program, the bug is removed...
 *
 *
 *  Author:   Marcel Hofstetter
 *  Compiler: SAS/C 6.3
 *
 *-----------------------------------------------------------------------*/


/* Function Prototypes */

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/wb.h>
#include <proto/intuition.h>


/* Standard Amiga Version-String
   $VER: name ver.rev (dd.mm.yy) */

static const UBYTE version[] = "$VER: Bad 37.1 (14.2.94)";


void main(void)
{
	
/* Library Bases */

struct DosLibrary *DOSBase;
struct Library *WorkbenchBase;
struct IntuitionBase *IntuitionBase;


struct MsgPort *mymsgport;
struct Window *mywindow;
struct AppWindow *myappwindow;
struct Message *msg;
struct TagItem tags[3];

ULONG id=1, user=0;


    if (DOSBase = (struct DosLibrary *) OpenLibrary(DOSNAME,37)) {

        if (WorkbenchBase = OldOpenLibrary(WORKBENCH_NAME)) {

            if (IntuitionBase = (struct IntuitionBase *)
                OldOpenLibrary("intuition.library")) {

                if (mymsgport = CreateMsgPort()) {

                    tags[0].ti_Tag  = WA_Width;
                    tags[0].ti_Data = 100;
                    tags[1].ti_Tag  = WA_Height;
                    tags[1].ti_Data = 50;
                    tags[2].ti_Tag  = TAG_DONE;

                    if (mywindow = OpenWindowTagList(NULL,tags)) {

                        if (myappwindow = AddAppWindowA(id,user,mywindow,
                            mymsgport,tags)) {

                            Delay(5*50);    /* wait 5 seconds */

                            RemoveAppWindow(myappwindow);
                        }
                        CloseWindow(mywindow);
                    }
                    /* Reply all messages before deleting the port */
                    while (msg = GetMsg(mymsgport)) {
                        ReplyMsg(msg);
                    }
                    DeleteMsgPort(mymsgport);
                }
                CloseLibrary( (struct Library *) IntuitionBase);
            }
            CloseLibrary(WorkbenchBase);
        }
        CloseLibrary( (struct Library *) DOSBase);
    }
}
