#include <v_lib.h>
#include "phasesp.h"
#include "icond.h"
#include "ms_wr.h"
#include "psys.h"
#include "psdl.h"
#include "util.h"

vhandle_t rhandle = LIBV_INVALID_HANDLE;

int seed = 1;

int util_init(void)
{
	if(seed < 1)
		seed = timeTickCount();
	rhandle = ranCreateGenerator(seed);
	return 0;
}

void util_shutdown(void)
{
	if(rhandle != LIBV_INVALID_HANDLE)
		ranDestroyGenerator(rhandle);
	rhandle = LIBV_INVALID_HANDLE;
}

void
tok_print_what_expected(char *caller,vhandle_t sc,
	char *filename,char *expected)
{
	if(filename)
	{
		conlPrintf(LOG_ERROR,"%s(%s:line %u): expected '%s', got '%s'.\n",
			strSafe(caller),filename,lexLastLine(sc),
			strSafe(expected),strSafe(lexLast(sc)));
	}
	else
	{
		conlPrintf(LOG_ERROR,"%s(line %u): expected '%s', got '%s'.\n",
			strSafe(caller),lexLastLine(sc),
			strSafe(expected),strSafe(lexLast(sc)));
	}
}
