From 42be37f4ad99fc8580415fed89939e305d56193e Mon Sep 17 00:00:00 2001 From: fusion32 Date: Tue, 20 May 2025 16:41:03 -0300 Subject: implement `main.cc`, `shm.cc`, and `time.cc` + overall tweeks --- src/util.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/util.cc (limited to 'src/util.cc') diff --git a/src/util.cc b/src/util.cc new file mode 100644 index 0000000..f2ebc48 --- /dev/null +++ b/src/util.cc @@ -0,0 +1,42 @@ +#include "util.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); + } +} -- cgit v1.2.3