/*	Send messages to user either in Workbench or CLI.
	Martin J. Round.	15-Oct-1989
	Many thanks to Ali T. Ozer for his IFF2PCS program which this
	routine is based on.
*/

extern int runningfromcli;

extern BPTR _Backstdout;

void print(char *s)
	{
	if (_Backstdout)
		Write(_Backstdout, s, strlen(s));
	}

int Min (int a, int b)
	{
	return ((a > b) ? b : a);
	}


int Max (int a, int b)
	{
	return ((a > b) ? a : b);
	}

void message (UBYTE *m)
	{
	static struct IntuiText negtxt  =
		{0,1,COMPLEMENT,4,4,NULL,(UBYTE *)" O.K.",NULL};
	static struct IntuiText bodytxt =
		{0,1,COMPLEMENT,10,6,NULL,NULL,NULL};

	if (m) 
		{
		if (runningfromcli)
			{
			print (m);
			print ("\n");
			}
		else
			{
			bodytxt.IText = m;
			WBenchToFront ();
			AutoRequest 
				(
				NULL,
				&bodytxt,
				NULL,
				&negtxt,
				0L,
				0L,
				(long)(Max(Min(strlen(m)*10+50,625),200)),
				54L
				);
			}
		}
	}
