summaryrefslogtreecommitdiff
path: root/src/c_fl_error.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2024-11-30 15:13:42 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2024-11-30 15:13:42 +1300
commitba29d58fb21f0f376dd4c09df61b4e1d38cb1226 (patch)
tree81676cf559a9bb1c9a02ee82e004a23a28c54681 /src/c_fl_error.cpp
parente3655d5d9f49e325bda4c9cf99d579bc89355a14 (diff)
Error/Warning/Fatal added to FLTK.Errors
Diffstat (limited to 'src/c_fl_error.cpp')
-rw-r--r--src/c_fl_error.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/c_fl_error.cpp b/src/c_fl_error.cpp
new file mode 100644
index 0000000..17c45a0
--- /dev/null
+++ b/src/c_fl_error.cpp
@@ -0,0 +1,87 @@
+
+
+// Programmed by Jedidiah Barber
+// Released into the public domain
+
+
+#include <FL/Fl.H>
+#include <stdarg.h>
+#include "c_fl_error.h"
+
+
+
+
+// Exports from Ada
+
+extern "C" void error_warning_hook(const char * m);
+extern "C" void error_error_hook(const char * m);
+extern "C" void error_fatal_hook(const char * m);
+
+
+// This is the size used internally in FLTK anyway
+const int bsize = 1024;
+
+
+// Some prep needed to convert vargs to a single char*
+
+void warning_hook_prep(const char * m, ...) {
+ va_list args;
+ char buf[bsize];
+ va_start(args, m);
+ vsnprintf(buf, bsize, m, args);
+ va_end(args);
+ error_warning_hook(buf);
+}
+
+void error_hook_prep(const char * m, ...) {
+ va_list args;
+ char buf[bsize];
+ va_start(args, m);
+ vsnprintf(buf, bsize, m, args);
+ va_end(args);
+ error_error_hook(buf);
+}
+
+void fatal_hook_prep(const char * m, ...) {
+ va_list args;
+ char buf[bsize];
+ va_start(args, m);
+ vsnprintf(buf, bsize, m, args);
+ va_end(args);
+ error_fatal_hook(buf);
+}
+
+
+
+
+// Original function pointers
+
+void (*original_warning)(const char *, ...) = Fl::warning;
+void (*original_error)(const char *, ...) = Fl::error;
+void (*original_fatal)(const char *, ...) = Fl::fatal;
+
+
+void fl_error_default_warning(const char * m) {
+ (*original_warning)(m);
+}
+
+void fl_error_default_error(const char * m) {
+ (*original_error)(m);
+}
+
+void fl_error_default_fatal(const char * m) {
+ (*original_fatal)(m);
+}
+
+
+
+
+// Tying it all together
+
+void fl_error_set_hooks() {
+ Fl::warning = &warning_hook_prep;
+ Fl::error = &error_hook_prep;
+ Fl::fatal = &fatal_hook_prep;
+}
+
+