From d666c271bec412d700298200dbff22102c2bdd63 Mon Sep 17 00:00:00 2001
From: 3gg <3gg@shellblade.net>
Date: Sun, 25 Feb 2024 15:11:23 -0800
Subject: Simpler error logging API.

---
 error/include/error.h | 24 ++++++++++++------------
 error/src/error.c     |  4 ++--
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/error/include/error.h b/error/include/error.h
index 92c06ff..23df5f3 100644
--- a/error/include/error.h
+++ b/error/include/error.h
@@ -6,17 +6,17 @@
 /// Get the last error.
 const char* get_error(void);
 
-extern xlstring gfx_error;
+extern xlstring g_error;
 
-/// Set the last error.
-#define set_error(...) \
-  gfx_error.length = snprintf(gfx_error.str, xlstring_size, __VA_ARGS__)
-
-/// Prepend an error to the last error.
-#define prepend_error(...)                                        \
-  {                                                               \
-    xlstring head;                                                \
-    head.length = snprintf(head.str, xlstring_size, __VA_ARGS__); \
-    xlstring_append(&head, xlstring_make(": "));                  \
-    gfx_error = xlstring_concat(head, gfx_error);                 \
+/// Log an error.
+#define log_error(...)                                                    \
+  {                                                                       \
+    if (g_error.length == 0) {                                            \
+      g_error.length = snprintf(g_error.str, xlstring_size, __VA_ARGS__); \
+    } else {                                                              \
+      xlstring head;                                                      \
+      head.length = snprintf(head.str, xlstring_size, __VA_ARGS__);       \
+      xlstring_append(&head, xlstring_make(": "));                        \
+      g_error = xlstring_concat(head, g_error);                           \
+    }                                                                     \
   }
diff --git a/error/src/error.c b/error/src/error.c
index ccd850d..81fb056 100644
--- a/error/src/error.c
+++ b/error/src/error.c
@@ -1,5 +1,5 @@
 #include "error.h"
 
-xlstring gfx_error;
+xlstring g_error;
 
-const char* get_error(void) { return xlstring_cstr(&gfx_error); }
+const char* get_error(void) { return xlstring_cstr(&g_error); }
-- 
cgit v1.2.3