From c6d44836fd8ed1442e01825cb0f9f97e7bf11515 Mon Sep 17 00:00:00 2001 From: David Moc Date: Wed, 3 Jun 2026 02:26:11 +0200 Subject: Harden editor logging and packaging --- src/log.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/log.c') diff --git a/src/log.c b/src/log.c index 7dec534..78c384a 100644 --- a/src/log.c +++ b/src/log.c @@ -31,6 +31,22 @@ static char ecex_frame_group_start[1024]; static char ecex_frame_repeat_start[1024]; static char ecex_frame_repeat_end[1024]; static unsigned long ecex_frame_repeat_count = 0; +static ecex_log_sink_fn ecex_log_sink = NULL; +static void *ecex_log_sink_userdata = NULL; +static int ecex_log_sink_active = 0; + +void ecex_log_set_sink(ecex_log_sink_fn fn, void *userdata) { + ecex_log_sink = fn; + ecex_log_sink_userdata = userdata; +} + +void ecex_log_clear_sink(void *userdata) { + if (!userdata || userdata == ecex_log_sink_userdata) { + ecex_log_sink = NULL; + ecex_log_sink_userdata = NULL; + ecex_log_sink_active = 0; + } +} static size_t ecex_strn_copy(char *out, size_t out_cap, const char *in) { size_t i = 0; @@ -157,6 +173,12 @@ static void ecex_log_emit_raw_depth(const char *line, int depth) { } ecex_write_all(line ? line : "(null)", line ? len : 6); ecex_write_all("\n", 1); + + if (ecex_log_sink && !ecex_log_sink_active) { + ecex_log_sink_active = 1; + ecex_log_sink(line ? line : "(null)", depth, ecex_log_sink_userdata); + ecex_log_sink_active = 0; + } } static void ecex_log_emit_raw_counted(const char *line, int depth, unsigned long count) { -- cgit v1.2.3