/* Startup.c
 *
 * Random Workbench/Opus background picture selector.
 *
 * Public domain in 1996-97 by Magnus Holmgren.
 */

#include "RndPat.h"


/* ----- Startup code ----------------------------------------------------- */


SAVEDS LONG
Startup( VOID )
{
	LONG	rc = RETURN_FAIL;

	SysBase = *( ( struct ExecBase ** ) 4 );

	if( DOSBase = ( struct DosLibrary * ) OpenLibrary( "dos.library", 39 ) )
	{
		if( IntuitionBase = OpenLib( "intuition.library", 39 ) )
		{
			if( UtilityBase = OpenLib( "utility.library", 39 ) )
			{
				rc = Main();

				CloseLib( UtilityBase );
			} /* if */

			CloseLib( IntuitionBase );
		} /* if */

		CloseLib( DOSBase );
	} /* if */

	return( rc );
} /* Startup */


APTR
OpenLib( const STRPTR name, const LONG version )
{
	APTR	lib;

	if( !( lib = OpenLibrary( name, version ) ) )
	{
		Printf( "%s: Couldn't open %s version %ld or higher\n", ProgramName, name, version );
	} /* if */

	return( lib );
} /* OpenLib */


VOID
PrintfFault( ULONG err, const STRPTR msg, ... )
{
	Printf( msg, &msg + 1 );
	PutStr( ": " );
	PrintFault( err, NULL );
}


/* ----- Global variables ------------------------------------------------- */


struct DosLibrary	*DOSBase;
struct IntuitionBase	*IntuitionBase;
struct ExecBase		*SysBase;
struct Library		*UtilityBase;
