/* Misc.C - Miscellaneous functions for PP
**
** calcsize() determines the size of a console window, given a text
**	      (possibly containing control sequences and newlines)
**
** stoa()     short to ascii - converts a short to the equivalent string
**
** stricmp()  Case independant string comparator (1 = strings matched)
**
** This file belongs to the Powerpacker Patcher project
**
** Copyright 1991, Michael Berg
*/

void calcsize
(
	register char *msg,

		 short *left,  short *up,
	register short *width, short *height
)
{
	short maxwidth;

	*height = 8;
	*width  = maxwidth = 0;

	while (*msg)
	{
		switch ((unsigned char)*msg++)
		{
			case 155: case 27:
				while (*msg && *msg++ != 'm')
					;
				break;

			case '\n':
				*height += 8;
				if (*width > maxwidth) maxwidth = *width;
				*width = 0;
				break;

			default:
				*width += 8;
		}
	}

	if (*height > 8) *width = maxwidth;

	*height += 20;
	*width  += 32;
	*left    = 318-*width/2;
	*up      = 100-*height/2;
}

char *stoa(register short num, register char *ptr)
{
	short n;
	char *np;

	if (!num)
	{
		*ptr++ = '0';
		return(ptr);
	}

	for (n = num; n; n /= 10)
		ptr++;

	np = ptr;

	while (num)
	{
		*--ptr = (num % 10) + '0';
		num /= 10;
	}

	return(np);
}

int stricmp(char *a,char *b)
{
	while (*a && *b)
		if (toupper(*a++) != toupper(*b++))
			return(0);

	return(1);
}
