#include "debug.h"
#include <io.h>	// unlink
#include <stdio.h>
#include <stdarg.h>
#include <time.h>

const char * DebugDevice = "debug.log";

void
debugger_print(	char *msg )
{
	static int firstrun	= 1;
	FILE * h;

	if(firstrun)
		unlink(DebugDevice);
	h =	fopen(DebugDevice,"a+t");
	if(h !=	NULL)
	{
		if(firstrun)
		{
			time_t t;
			time(&t);
			fputs(ctime(&t),h);
			firstrun = 0;
		}
		fputs(msg,h);
		fflush(h);
		fclose(h);
	}
}

void
MDEBUG_print(char *modname)
{
	debugger_print(modname);
	debugger_print(": ");
}

void
DEBUG_printf(char *fmt,...)
{
	char buf[256];
	va_list	ap;

	va_start(ap,fmt);
	vsprintf(buf,fmt,ap);
	va_end(ap);

	debugger_print(buf);
	debugger_print("\n");
}
