/*	Opening and Closings of diverse librarys	*/
/*	LibBase.c					*/

#include	<libraries/libbase.h>
#include	<intuition/intuition.h>


struct	DosBase 	*DosBase;

LONG	ExecBase,GfxBase,MathBase,IntuitionBase,
	MathTransBase,MathIeeeDoubBasBase,LayerBase,ClistBase,
	DiskfontBase,TimerBase,TranslatorBase,ArpBase;

OpenLibs(Base)  int     Base;
{

if (Base & DOS)         DosBase                 =OpLib("dos");
if (Base & INTUI)       IntuitionBase           =OpLib("intuition");
if (Base & EXEC)        ExecBase                =OpLib("exec");
if (Base & GFX)         GfxBase                 =OpLib("graphics");
if (Base & MATH)        MathBase                =OpLib("mathffp");
if (Base & TRANS)       MathTransBase           =OpLib("mathtrans");
if (Base & IEEE)        MathIeeeDoubBasBase     =OpLib("mathieeedoubbas");
if (Base & LAYER)       LayerBase               =OpLib("layers");
if (Base & CLIST)       ClistBase               =OpLib("clist");
if (Base & FONT)        DiskfontBase            =OpLib("diskfont");
if (Base & TIMER)       TimerBase               =OpLib("timer");
if (Base & SPEECH)      TranslatorBase          =OpLib("translator");
if (Base & ARP)         ArpBase                 =OpLib("arp");

}

LONG	OpLib(f)        char    *f;
{
	LONG	*b;
	char	ln[40];

	strcpy(ln,f);
	strcat(ln,".library");
	if (! (b = OpenLibrary(ln,0) ) )
	{
		printf (" Could not open %s \n ",ln);
		printf (" Aborting ");
		CloseLibs();
		exit();
	}
	return(b);
}

CloseLibs()
{
	if (DosBase)            CloseLibrary(DosBase);
	if (ExecBase)           CloseLibrary(ExecBase);
	if (IntuitionBase)      CloseLibrary(IntuitionBase);
	if (GfxBase)            CloseLibrary(GfxBase);
	if (MathBase)           CloseLibrary(MathBase);
	if (MathTransBase)      CloseLibrary(MathTransBase);
	if (MathIeeeDoubBasBase)CloseLibrary(MathIeeeDoubBasBase);
	if (LayerBase)          CloseLibrary(LayerBase);
	if (ClistBase)          CloseLibrary(ClistBase);
	if (DiskfontBase)       CloseLibrary(DiskfontBase);
	if (TimerBase)          CloseLibrary(TimerBase);
	if (TranslatorBase)     CloseLibrary(TranslatorBase);
	if (ArpBase)            CloseLibrary(ArpBase);
}

main()
{
	int	i;

	OpenLibs( DOS | EXEC | INTUI );
	for (i=0; i<10; i++)
	{
		Delay(10);
		printf("%d \n",i);
		if (i==5) DisplayBeep(NULL);
	}
	CloseLibs();
}

