#include <libraries/mui.h>
#include <proto/muimaster.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <exec/memory.h>
#include <stdlib.h>
#include <stdio.h>

#ifndef MAKE_ID
#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
#endif

#ifdef _DCC
#define __inline
#endif

struct Library *MUIMasterBase, *LocaleBase;

/*************************/
/*    Fail Function      */
/*************************/

static VOID fail(APTR app,char *str)
{
        if (app)
                MUI_DisposeObject(app);

#ifndef _DCC
        if (MUIMasterBase)
                CloseLibrary(MUIMasterBase);
#endif
	if (str)
        {
                puts(str);
                exit(20);
        }
        exit(0);
}

/*************************/
/*    Init Function      */
/*************************/

static VOID init(VOID)
{
#ifdef _DCC
        onbreak(brkfunc);
#endif

#ifndef _DCC
        if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
                fail(NULL,"Failed to open "MUIMASTER_NAME".");
#endif
}

/*************************/
/* InitLocale Function   */
/*************************/

static VOID initlocale(VOID)
{
#ifndef _DCC
        LocaleBase = OpenLibrary("Locale.library",38L);
#endif
	/* YOU MUST write this function !!! */
        /* OpenCatalog(NULL,NULL); */
}

/****************************************************************/
/*      ExTended KeyButton ( or Eric Totel KeyButton :-) )      */
/*      to use with localization features                       */
/****************************************************************/

static APTR __inline ETKeyButton(char *text)
{
        return (KeyButton(&text[3], text[1]));
}


