/************************************************/
/* ML-Support                                   */
/* Freeware                                     */
/* © 1998-99 Christian Hattemer                 */
/* email: chris@mail.riednet.wh.tu-darmstadt.de */
/* 16.03.99 16:40                               */
/************************************************/

#define VERSIONSTRING "$VER: ML-Support 1.6 (16.03.99)"

/* stormamiga.lib */
#ifdef USESTORMAMIGA
   #define STORMAMIGA
   #define STORMAMIGA_STACK 15000
   #include <stormamiga.h>
   #define main main__
   char __stdiowin[] = "CON:/11/400/100/ML-Support/AUTO/CLOSE/WAIT";
#endif

/* Ansi */
#include <stdio.h>

/* ML-Support */
#include "GUI.h"
#include "Mainwin.h"
#include "ML_Support_Cat.h"

/* Functions */
ULONG        DoSuperNew(Class *cl, Object *obj, ULONG Tag1, ...);
static void  Quit(Object *App, STRPTR Msg);

/* Structures */
       struct Library *MUIMasterBase;
static struct MUI_CustomClass *CL_Mainwin;

/* main function */
void main()
{
   Object *App, *WI_Main;
   ULONG Sigs = 0UL;

   /* Program initialisation */
   if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME, 14)))
   {
      Quit(NULL, "Failed to open muimaster.library V14+");
   }

   if (!(CL_Mainwin = CreateMainwinClass()))
   {
      Quit(NULL, "Failed to init Classes");
   }

   OpenML_SupportCatalog();

   /* Create Application */
   App = ApplicationObject,
      MUIA_Application_Author, "Christian Hattemer",
      MUIA_Application_Base, "ML-SUPPORT",
      MUIA_Application_Title, TITLE_MAINWIN,
      MUIA_Application_Version, VERSIONSTRING,
      MUIA_Application_Copyright, "© 1998-99 Christian Hattemer",
      MUIA_Application_Description, MSG_APP_DESCRIPTION,
      MUIA_Application_SingleTask, TRUE,
      SubWindow, WI_Main = MainwinObject,
      End,
   End;

   if (App)
   {
      set(WI_Main, MUIA_Window_Open, TRUE);
      if (!(xget(WI_Main, MUIA_Window_Open)))
      {
         Quit(App, "Failed to open Mainwindow");
      }

      while (DoMethod(App, MUIM_Application_NewInput, &Sigs) !=
             MUIV_Application_ReturnID_Quit
            )
      {
         if (Sigs)
         {
            Sigs = Wait(Sigs | SIGBREAKF_CTRL_C);
            if (Sigs & SIGBREAKF_CTRL_C)
               break;
         }
      }

      set(WI_Main, MUIA_Window_Open, FALSE);
      Quit(App, NULL);
   }
   else
   {
      Quit(NULL, "Failed to create Application");
   }
}

ULONG DoSuperNew(Class *cl, Object *obj, ULONG Tag1, ...)
{
   return(DoSuperMethod(cl, obj, OM_NEW, &Tag1, NULL));
}

static void Quit(Object *App, STRPTR Msg)
{
   if (App)
   {
      MUI_DisposeObject(App);
   }

   CloseML_SupportCatalog();

   if (CL_Mainwin)
   {
      DeleteMainwinClass(CL_Mainwin);
   }

   if (MUIMasterBase)
   {
      CloseLibrary(MUIMasterBase);
   }

   if (Msg)
   {
      puts(Msg);
      exit(20);
   }

   exit(0);
}

