/* Main-Header File inserted by GenCodeC */
/* Libraries */
#include <libraries/mui.h>
#include <libraries/gadtools.h> /* for BARLABEL in MenuItem */

/* Prototypes */
#ifdef __SASC
#include <clib/muimaster_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#else
#include <proto/muimaster.h>
#include <proto/exec.h>
#include <proto/alib.h>
#include <proto/dos.h>
#endif

/*  Pragmas  */
#include <pragmas/muimaster_pragmas.h>

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

/* Increase stack size */
LONG __stack=8192;
/* GenCodeC header end */

/* Include generated by GenCodeC */
#include "FreeGUI.h"
#include "FreeExtern.h"
#include "Hook_Utility.h"

struct ObjApp * App; /* Object */

/* Declarations for libraries (inserted by GenCodeC) */
struct Library * IntuitionBase;
struct Library * MUIMasterBase;
struct Library * LocaleBase;

/* Init() function */
void init( void )
{
  if (!(IntuitionBase = OpenLibrary("intuition.library",37)))
  {
    printf("Can't Open Intuition Library\n");
    exit(20);
  }
  if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  {
    printf("Can't Open MUIMaster Library\n");
    CloseLibrary(IntuitionBase);
    exit(20);
  }
  if (!(LocaleBase = OpenLibrary("locale.library",38)))
  {
    printf("Can't Open Locale Library\n");
    printf("Built-in Language will be used !!!\n");
  }
  OpenAppCatalog(NULL,NULL);
}
/* GenCodeC init() end */

/* End() function */
void end( void )
{
  CloseAppCatalog();
  if (LocaleBase)
    CloseLibrary(LocaleBase);
  CloseLibrary(MUIMasterBase);
  CloseLibrary(IntuitionBase);
  exit(20);
}
/* GenCodeC end() end */

/* Main Function inserted by GenCodeC */
int main(int argc,char **argv)
{
  BOOL  running = TRUE;
  ULONG signal;
  long startup = 0, menu = 0;

  static struct Hook GeracaoHook;
  static struct Hook CarregaConfiguracaoHook;
  static struct Hook TestaConfiguracaoHook;
  static struct Hook DataAtualHook;

  InstallHook(&GeracaoHook,Geracao,NULL);
  InstallHook(&CarregaConfiguracaoHook,CarregaConfiguracao,NULL);
  InstallHook(&DataAtualHook,DataAtual,NULL);
  InstallHook(&TestaConfiguracaoHook,TestaConfiguracao,NULL);

  /* Program initialisation : generated by GenCodeC */
  init();

  /* Create Object : generated by GenCodeC */
  if (!(App = CreateApp()))
  {
    printf("Can't Create App\n");
    end();
  }

  DoMethod(App->App, MUIM_CallHook, &CarregaConfiguracaoHook);
  DoMethod(App->App, MUIM_CallHook, &DataAtualHook);
  DoMethod(App->App, MUIM_CallHook, &TestaConfiguracaoHook);

  /* CARREGA ALGUNS LABELS PARA NAO SEREM TROCADOS PELO CATALOGO */
  set(App->FreedomLabel, MUIA_Text_Contents, "Freedom Call 1.14");
  set(App->FreedomLabel2, MUIA_Text_Contents, "Freedom Call 1.14");

  /* TESTA O TIPO DE MENU PRINCIPAL A CARREGAR */
  get(App->PrefsComboMenu, MUIA_Cycle_Active, &menu);
  if(menu == 0)
    set(App->JanelaPrincipal2, MUIA_Window_Open, TRUE);
  else
    set(App->JanelaPrincipal, MUIA_Window_Open, TRUE);

  /* TESTA SE TEM QUE IMPORTAR OS DADOS NO INICIO DO FREEDOM */
  get(App->LabelGenerationStartup, MUIA_Selected, &startup);
  if(startup == 1)
    DoMethod(App->App, MUIM_CallHook, &GeracaoHook);

  while (running)
  {
    switch (DoMethod(App->App,MUIM_Application_Input,&signal))
    {
      case MUIV_Application_ReturnID_Quit:
        running = FALSE;
        break;

      /* Insert your code between the "case" statement and comment "end of case ..." */
      /* End computing of IDCMP */

      default:
        break;
    }
    if (running && signal) Wait(signal);
  }
  DisposeApp(App);
  end();
}
