aboutsummaryrefslogtreecommitdiff
path: root/src/warnings.c
diff options
context:
space:
mode:
authorMarvin Borner2021-04-20 00:54:43 +0200
committerMarvin Borner2021-04-20 00:54:43 +0200
commitaac2dae5cfcd360ad48f265910511c98decbf9e7 (patch)
tree45b7d421d2ff3d3db390f0c7fd969e4d8a58cd65 /src/warnings.c
parent3ecfdb1064f7c4f45f53c415a77803ce2153d04d (diff)
Beautiful blub blabs
Diffstat (limited to 'src/warnings.c')
-rw-r--r--src/warnings.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/warnings.c b/src/warnings.c
new file mode 100644
index 0000000..fd11264
--- /dev/null
+++ b/src/warnings.c
@@ -0,0 +1,56 @@
+#include <assert.h>
+#include <def.h>
+#include <gui.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <warnings.h>
+
+#define WARNING_COUNT 1024 // Well, something went horribly wrong I guess
+#define WARNING_LENGTH 64
+
+struct warning {
+ u8 exists;
+ u32 line;
+ char text[WARNING_LENGTH];
+};
+
+static struct warning warnings[WARNING_COUNT] = { 0 };
+static u32 warning_index = 0;
+void warnings_add(u32 line, const char *fmt, ...)
+{
+ assert(warning_index + 1 < WARNING_COUNT);
+
+ warnings[warning_index].exists = 1;
+ warnings[warning_index].line = line;
+
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(warnings[warning_index].text, WARNING_LENGTH, fmt, ap);
+ va_end(ap);
+
+ warning_index++;
+}
+
+// TODO: Print somewhere else (e.g. next to line)
+void warnings_print(void)
+{
+ for (u32 i = 0; i < WARNING_COUNT; i++) {
+ if (!warnings[i].exists)
+ continue;
+
+ /* gui_show_warning(warnings[i].text); */
+ printf("Line %d: %s\n", warnings[i].line, warnings[i].text);
+ }
+}
+
+u8 warnings_exist(void)
+{
+ return warning_index > 0;
+}
+
+void warnings_clear(void)
+{
+ if (warning_index)
+ memset(warnings, 0, sizeof(warnings));
+}