summaryrefslogtreecommitdiff
path: root/libfmt/libmisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libfmt/libmisc.c')
-rw-r--r--libfmt/libmisc.c73
1 files changed, 0 insertions, 73 deletions
diff --git a/libfmt/libmisc.c b/libfmt/libmisc.c
deleted file mode 100644
index 134b9f0..0000000
--- a/libfmt/libmisc.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/* libfmt/libmisc.c - Integrate pico-fmt with libmisc
- *
- * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-#include <stdarg.h> /* for va_list, va_start(), va_end() */
-#include <stdio.h> /* for vprintf(), putchar(), fflush() */
-#if LIB_PICO_STDIO
-#include <pico/stdio.h> /* for stdio_putchar_raw() */
-#endif
-
-#include <libmisc/macro.h> /* for LM_UNUSED() */
-#include <libmisc/_intercept.h> /* for __lm_printf() and __lm_light_printf() */
-
-#include <libfmt/fmt.h> /* for fmt_vfctprintf() */
-
-#if LIB_PICO_STDIO
-static void libfmt_light_fct(char character, void *LM_UNUSED(arg)) {
- if (character == '\n')
- stdio_putchar_raw('\r');
- stdio_putchar_raw(character);
-}
-#else
-static void libfmt_libc_fct(char character, void *LM_UNUSED(arg)) {
- putchar(character);
-}
-#endif
-
-int __lm_printf(const char *format, ...) {
- va_list va;
- va_start(va, format);
-#if LIB_PICO_STDIO
- /* pico_stdio has already intercepted vprintf for us, and
- * their stdio_buffered_printer() is better than our
- * libfmt_libc_fct() because buffering. */
- int ret = vprintf(format, va);
-#else
- int ret = fmt_vfctprintf(libfmt_libc_fct, NULL, format, va);
- fflush(stdout);
-#endif
- va_end(va);
- return ret;
-}
-
-int __lm_light_printf(const char *format, ...) {
- va_list va;
- va_start(va, format);
-#if LIB_PICO_STDIO
- /* libfmt_light_fct() and stdio_buffered_printer() both use 68
- * bytes of stack; but the buffer lives on the stack of
- * stdio.c:__wrap_vprintf(); so that's where you'll see the
- * numbers be different if you're analyzing it. (Also, being
- * able to skip the stdio_stack_buffer_flush() call.) */
- int ret = fmt_vfctprintf(libfmt_light_fct, NULL, format, va);
- stdio_flush();
-#else
- int ret = fmt_vfctprintf(libfmt_libc_fct, NULL, format, va);
- fflush(stdout);
-#endif
- va_end(va);
- return ret;
-}
-
-static void libfmt_conv_formatter(struct fmt_state *state) {
- lo_interface fmt_formatter obj = va_arg(*state->args, lo_interface fmt_formatter);
- LO_CALL(obj, format, state);
-}
-
-[[gnu::constructor]]
-static void libfmt_install_formatter(void) {
- fmt_install('v', libfmt_conv_formatter);
-}