/****************************************************************************
	This is an example application to test the C "simple.library". Make the
	glue code with LibTool (-c option). (This can be made when the library is
	made by using the LibTool option -cmho).

Manx 5.0d

cc -mcd -ff AWlib_App.c					;large code and data
LibTool -cho glue.asm AWlib.fd		;C function code, create header file
as -cd glue.asm							;large code and data
ln AWlib_App.o glue.o -lmfl -lcl		;large, 32 bit lib

****************************************************************************/

#include "exec/types.h"
#include "math.h"
#include "awlib.h"

ULONG  argcount;  /* Saves argc from main(). if argcount==0, then run from WB. */
struct MathBase *MathBase = 0L;
struct MathTransBase *MathTransBase = 0L;

VOID exit_program( error_words, error_code )	/* All exits through here. */
char  *error_words;
ULONG error_code;
{
	if( argcount && error_words ) puts( error_words );

	CloseAWBase();	/* This is always safe to call */

	if( MathBase ) 		CloseLibrary( MathBase );
	if( MathTransBase )	CloseLibrary( MathTransBase );

	exit( error_code );
}


VOID open_all()
{
	/* actually, this program doesn't make any calls to these math libraries in
		the main section, so they really don't need to be opened by the
		application. Mostly likely, though, the application would need them in
		a real world case. */

	if( !(MathBase = (struct MathBase *)OpenLibrary("mathffp.library", 0L )) )
		exit_program("Can't open mathffp.library.\n", 10L);

	if( !(MathTransBase = (struct MathTransBase *)OpenLibrary("mathtrans.library", 0L )) )
		exit_program("Can't open mathtrans.library.\n", 10L);

	if( !(OpenAWBase()) )
		exit_program("Can't open aw.library.\n", 10L);
}


/************************ MAIN ROUTINE *****************************/

VOID main(argc, argv)
LONG argc;
char **argv;
{
	double result;

	argcount = argc;

	open_all();

	result = Mag( 10.0, 20.0 );
	printf("Magnitude of 10 + j20 = %lf\n", result );

	result = Ang( 10.0, 20.0 );
	printf("Angle of 10 + j20 = %lf\n", result );

	result = Real( 10.0, 60.0 );
	printf("Real component of 10 at 60 degrees = %lf\n", result );

	result = Imaj( 10.0, 60.0 );
	printf("Imaginary component of 10 at 60 degrees = %lf\n", result );

	exit_program(0L,0L);
}

