aboutsummaryrefslogtreecommitdiff
path: root/src/util.cc
blob: 4f74c80a0885e280135a5ec35d07bfb3c4eae8b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "main.hh"

static void (*ErrorFunction)(const char *Text) = NULL;
static void (*PrintFunction)(int Level, const char *Text) = NULL;

void SetErrorFunction(TErrorFunction *Function){
	ErrorFunction = Function;
}

void SetPrintFunction(TPrintFunction *Function){
	PrintFunction = Function;
}

void error(char *Text, ...){
	char s[1024];

	va_list ap;
	va_start(ap, Text);
	vsnprintf(s, sizeof(s), Text, ap);
	va_end(ap);

	if(ErrorFunction){
		ErrorFunction(s);
	}else{
		printf("%s", s);
	}
}

void print(int Level, char *Text, ...){
	char s[1024];

	va_list ap;
	va_start(ap, Text);
	vsnprintf(s, sizeof(s), Text, ap);
	va_end(ap);

	if(PrintFunction){
		PrintFunction(Level, s);
	}else{
		printf("%s", s);
	}
}