/*                      QBCC Project

This source file is licensed under the GNU Lesser Public Licence which should be 
included with the distribution of this source.

*/
// PRINT function


#include "../include/conlib.h"
#include "../include/stringh.h"

/* Standard Print Function */
void PRINT(char *fmt,...)
{
	char PrintStr[4096];
	char buf[128];
	va_list p;
	string *sTmp;
	int *Integer;
	float *Single;

	strcpy(PrintStr,"");		

	va_start(p, fmt);

	do {    
		// BASIC style string
		if(*fmt == 's')
		{
			sTmp = (string *)va_arg(p, string *);
			if(sTmp->ptr)		
				strcat(PrintStr,sTmp->ptr);
		}

		// Integers
		if(*fmt == 'i')
		{
			Integer = (int *)va_arg(p,int *);
			sprintf(buf,"%d",*Integer);
			strcat(PrintStr,buf);
		}

		// Singles (float)
		if(*fmt == 'f')
		{
			Single = (float *)va_arg(p,double *);
			sprintf(buf,"%.2f",*Single);
			strcat(PrintStr,buf);
		}

		// Newlines
		if(*fmt == '\n')		
			strcat(PrintStr,"\n");

		// Tabs
		if(*fmt == '\t')
			strcat(PrintStr,"\t");

 } while (*(++fmt) != '\0');

	printf("%s",PrintStr);
}