#include "stdafx.h"

//#include <windows.h>
//#include <cstdio>

#define _DEBUGPRINT
#ifdef _DEBUGPRINT

namespace {
	CRITICAL_SECTION cs;
	char *buf;
}

void
init_debug(int bufsize)
{
	InitializeCriticalSection(&cs);
	buf = new char[bufsize];
}

void
dprint(const char *fmt, ...)
{
	va_list argp;

	EnterCriticalSection(&cs);
	va_start(argp, fmt);
	vsprintf(buf, fmt, argp);
	OutputDebugString(buf);
	va_end(argp);
	LeaveCriticalSection(&cs);
}

void
end_debug(void)
{
	delete [] buf;
	DeleteCriticalSection(&cs);
}

#else

void init_debug(int bufsize) {}
void dprint(const char *fmt, ...) {}
void end_debug(void) {}

#endif
