#include <9pm/u.h>
#include <9pm/libc.h>

static struct {
	char c;
	int v;
} tab[] = {
	'a',	~0,
	'n',	PmDebugNs,
	'f',	PmDebugFd,
	'F',	PmDebugFs,
	's',	PmDebugStartup,
	'x',	PmDebugExit,
	'X',	PmDebugExec,
	'N',	PmDebugNote,
	'w',	PmDebugWait,
};

int	pm_debug = PmDebugPanic;

void
pm_setdebug(char *s)
{
	int i;

	if(s == nil)
		return;

	for(; *s; s++)
		for(i=0; i<nelem(tab); i++)
			if(*s == tab[i].c)
				pm_debug |= tab[i].v;
}

void
pm_dprint(int level, char *fmt, ...)
{
	char buf[128];
	va_list arg;

	if(!(pm_debug&level))
		return;

	va_start(arg, fmt);
	doprint(buf, buf+sizeof buf, fmt, arg);
	va_end(arg);
	pm_dwrite(buf);
}
