/*
 *	File:					MyAlert().h
 *	Description:	Displays texts in an alert.  Automaticall centers the
 *								lines and adjusts the frame.  Returns TRUE or FALSE if
 *								successfull, and -1 if not.
 *
 *	(C) 1993, Ketil Hunn
 *
 */

#include <stdlib.h>
#include <string.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <clib/intuition_protos.h>

int MyAlert(unsigned long alertNumber, char *message)
{
register	char	*alertMsg, *tmp;
register	UBYTE	*p, *c;
register	int		ypos=14, result;
register	BOOL	more=TRUE;
register	const size=strlen(message)+250;

	if(alertMsg=AllocMem(size, MEMF_ANY))
	{
		c=alertMsg;
		while(more)
		{
			tmp=message;
			message=stpchr(message,'\n');
			if(message==NULL)
				more=FALSE;
			++message;

			for(p=tmp; *p!='\n'; ++p);
			*p='\0';

			*((USHORT *)c)=(80-strlen(tmp))<<2;
			c+=2;
			*c++=ypos;
			while(*tmp!='\0')
				*c++=*tmp++;
			*c++=0;
			*c++=1;
			ypos+=11;
		}
		*(c-1)=0;
		result=DisplayAlert(RECOVERY_ALERT, alertMsg, ypos);
		FreeMem(alertMsg, size);
	}
	else
		result=-1;

	return result;
}
