aboutsummaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-05-20 16:41:03 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-05-20 16:41:03 -0300
commit42be37f4ad99fc8580415fed89939e305d56193e (patch)
tree41303aace3c214f925a43fec6a857f313196e38d /src/util.cc
parent7fe30185df21617cf44100f89db462cd4501050e (diff)
downloadgame-42be37f4ad99fc8580415fed89939e305d56193e.tar.gz
game-42be37f4ad99fc8580415fed89939e305d56193e.zip
implement `main.cc`, `shm.cc`, and `time.cc` + overall tweeks
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc42
1 files changed, 42 insertions, 0 deletions
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);
+ }
+}