/* Includes and other common stuff for MUI.
 * This is modified from the file "demo.h" that comes with the example MUI
 * programs.
 */

#ifdef __GNUC__
#define NO_INLINE_STDARG
#endif

/* MUI */
#include <libraries/mui.h>

/* System */
//#include <dos/dos.h>
//#include <graphics/gfxmacros.h>
//#include <workbench/workbench.h>

/* Prototypes */
#include <clib/alib_protos.h>
/*#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/icon_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/utility_protos.h>
#include <clib/asl_protos.h>*/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/icon.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include <proto/utility.h>
#include <proto/asl.h>

#include <proto/muimaster.h>
/*
#include <clib/muimaster_protos.h>
*/
/*
#ifndef __GNUC__
#include <clib/muimaster_protos.h>
#else
#include <inline/muimaster.h>
#endif
*/

/* ANSI C */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/* Compiler specific stuff */

#ifdef _DCC

#define REG(x) __ ## x
#define ASM
#define SAVEDS __geta4

#else

#define REG(x) register __## x
#define ASM
#define SAVEDS

#ifdef __SASC
#include <pragmas/exec_sysbase_pragmas.h>
/*#else
#ifndef __GNUC__
#include <pragmas/exec_pragmas.h>
#endif*/ /* ifndef __GNUC__ */
#endif /* ifdef SASC      */

/*#ifndef __GNUC__

#include <pragmas/dos_pragmas.h>
#include <pragmas/icon_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/gadtools_pragmas.h>
#include <pragmas/utility_pragmas.h>
#include <pragmas/asl_pragmas.h>

#endif*/ /* ifndef __GNUC__ */

//extern struct Library *SysBase,*IntuitionBase,*UtilityBase,*GfxBase,*DOSBase,*IconBase;
// must have a 'struct Library *MUIMasterBase' in one file

#endif /* ifdef _DCC */

/*************************/
/* Init & Fail Functions */
/*************************/

static VOID fail(Object *app,char *str) {
	if(str != NULL && *str != NULL)
		printf("FAIL! : %s",str);
	if (app)
		MUI_DisposeObject(app);
	if (MUIMasterBase)
		CloseLibrary(MUIMasterBase);
}


static VOID init(VOID) {
	if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
		fail(NULL,"Failed to open "MUIMASTER_NAME".");
}

/*#ifndef __SASC
static VOID stccpy(char *dest,char *source,int len) {
        strncpy(dest,source,len);
        dest[len-1]='\0';
}
#endif*/

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

#define BetterString(contents,maxlen)\
   BetterStringObject,\
      StringFrame,\
      MUIA_String_MaxLen  , maxlen,\
      MUIA_String_Contents, contents,\
      MUIA_CycleChain, 1, \
      End
